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
@@ -32,7 +32,7 @@
32
32
  * → engine.applyMergePlan(autoApply) 写入本地
33
33
  * - Phase C: 完整双向 → engine.push() 上传。两处策略:
34
34
  * ① 无冲突且推送被远端推进挡下 → skipped/partial + skipReason='conflict'(等人工);
35
- * ② conflictPolicy='local'(**只有用户显式选过才生效**;缺省 ask)且本轮有冲突 → **不写本地**,
35
+ * ② conflictPolicy='local'(**只有用户显式选过才生效**;缺省 ask)且本轮有冲突**或仍有待裁决存量** → **不写本地**,
36
36
  * 改 engine.push({force:true}) 把本机版本推成新的远端最新(被覆盖的远端旧版本仍在远端历史快照里
37
37
  * 可回滚),状态记 partial + skipReason='conflict-kept-local'(绝不谎报 success);
38
38
  * SYN-05:首轮 / 远端有新快照时即使选了 local 也降级 ask 并记 forced=true(见
@@ -50,6 +50,8 @@ import { engineMsg } from './messages.js';
50
50
  import { readAutosyncConfig, writeAutosyncConfig, clampRemoteCheckMs, DEFAULT_AUTOSYNC_REALTIME, DEFAULT_AUTOSYNC_REMOTE_CHECK_MS, DEFAULT_AUTOSYNC_AUTO_APPLY_TIER, DEFAULT_AUTOSYNC_CONFLICT_POLICY, } from './autosync-config.js';
51
51
  import { readSyncConfigFor, isGitConfig, isWebDavConfig, isS3Config, isGistConfig, SYNC_CHANNELS } from './sync-config.js';
52
52
  import { readSyncHistory, appendAutosyncEntry, markAutosyncNotified } from './sync-history.js';
53
+ import { loadSyncState } from './sync-state.js';
54
+ import { repeatHistorySignature } from './autosync-repeat.js';
53
55
  import { classifyMergePlan } from './risk.js';
54
56
  import { SyncWatcher } from './sync-watcher.js';
55
57
  import { buildWatchTargets } from './watch-scope.js';
@@ -86,7 +88,10 @@ export function shouldTriggerStartupRun(lastRunAt, startupMinIntervalMs, nowMs =
86
88
  * - **首轮**(从未跑过)或**远端有新快照**:即使显式选了 'local' 也强制降级 ask(forcedAsk)——
87
89
  * 这两个时刻正是「远端最新改动只在历史快照里」的事故现场,静默覆盖等于替用户丢数据;
88
90
  * 降级记 forced,界面才能说清「这次没按你的 local 走」;
89
- * - 只有「显式 local + 非高危时刻 + 真有冲突」才 force。
91
+ * - 只有「显式 local + 非高危时刻 + 真有冲突」才 force;
92
+ * - 「真有冲突」= **本轮新判出的冲突** ∪ **磁盘上仍在等裁决的分区**(`held`,issue #146 F9):
93
+ * local 是用户的**长期决定**,不能只对本轮新冲突生效 —— 否则上一轮攒下的待裁决永远等不到结论,
94
+ * 每轮都「不推也不报错」地空转(用户明明选了「本机优先」)。只读条数、不读内容,判定仍是纯函数。
90
95
  *
91
96
  * 纯函数(无状态、无 I/O):调度层与单测共用同一份判定,避免两处各写一遍阈值。
92
97
  */
@@ -95,7 +100,8 @@ export function resolveConflictPushPolicy(args) {
95
100
  // forcedAsk 只描述「用户选了 local,但本轮被降级」——缺省 ask 不算被强制(那不是用户的决定被推翻)。
96
101
  const forcedAsk = configured === 'local' && (args.firstRun || args.remoteNew);
97
102
  const policy = forcedAsk ? 'ask' : configured;
98
- return { policy, force: policy === 'local' && args.conflicted > 0, forcedAsk };
103
+ const outstanding = args.conflicted + (args.held ?? 0);
104
+ return { policy, force: policy === 'local' && outstanding > 0, forcedAsk };
99
105
  }
100
106
  export class AutoSyncScheduler {
101
107
  syncDir;
@@ -139,10 +145,19 @@ export class AutoSyncScheduler {
139
145
  profile;
140
146
  makeWatcher;
141
147
  minTriggerGapMs;
148
+ readPendingMerge;
142
149
  /** SEC-03:已 warn 过的「地址被拒」成因(键 = 通道 + 成因文本),进程内去重。 */
143
150
  reportedConfigIssues = new Set();
144
151
  stopped = false;
145
152
  running = false;
153
+ /**
154
+ * P1(2026-11-14 真机事故):上一轮真正落盘的历史签名,见 autosync-repeat.ts。
155
+ * 与本轮签名相同 → 这一轮不追加历史(同一结论连续播报把 200 条历史刷满、首页变成
156
+ * 每 1 分钟一条的噪音);但 lastRunAt / lastRunStatus / 跳过计数仍逐轮刷新。
157
+ */
158
+ repeatSignature = null;
159
+ /** 本轮历史是否被压掉 —— writeFinalConfig 据此保留上一条真记录的 lastRunHistoryId。 */
160
+ historyDeduped = false;
146
161
  constructor(opts) {
147
162
  this.syncDir = opts.syncDir;
148
163
  this.host = opts.host;
@@ -165,6 +180,14 @@ export class AutoSyncScheduler {
165
180
  this.profile = opts.profile;
166
181
  this.makeWatcher = opts.makeWatcher ?? defaultMakeWatcher;
167
182
  this.minTriggerGapMs = opts.minTriggerGapMs ?? 3000;
183
+ this.readPendingMerge = opts.readPendingMerge ?? (async () => {
184
+ try {
185
+ return (await loadSyncState(this.syncDir)).pendingMerge?.sections ?? [];
186
+ }
187
+ catch {
188
+ return [];
189
+ }
190
+ });
168
191
  }
169
192
  /**
170
193
  * 追加一条自动同步历史(自动带上触发通道;0x 安全:绝不覆盖调用方显式 transport)。
@@ -174,6 +197,16 @@ export class AutoSyncScheduler {
174
197
  * 原样透传(readSyncHistory 逐条 cast),所以运行时可稳定往返;界面按「字段有无」渲染。
175
198
  */
176
199
  async appendHistory(channel, entry) {
200
+ const signature = repeatHistorySignature(channel, entry);
201
+ if (signature !== null && signature === this.repeatSignature) {
202
+ // 同一状态的第 N 轮(典型:远端快照一直比基线新,60s 轮询每轮都撞同一份冲突)。
203
+ // 不写 sync-history、也不写首页统一历史;但这一轮仍要刷新「上次运行」,
204
+ // 否则界面会停在几十分钟前的 lastRunAt,用户以为自动同步停了。
205
+ this.historyDeduped = true;
206
+ return;
207
+ }
208
+ this.repeatSignature = signature;
209
+ this.historyDeduped = false;
177
210
  await this.appendHistoryFn({ ...entry, transport: channel });
178
211
  }
179
212
  /**
@@ -252,36 +285,47 @@ export class AutoSyncScheduler {
252
285
  this.host.log.error(`自动同步触发失败(${channel}/${reason})`, { error: err instanceof Error ? err.message : String(err) });
253
286
  });
254
287
  }
255
- /** 兜底间隔定时器:每个 enabled 通道按各自 interval 排一次性定时器,触发后只重排自己。 */
288
+ /**
289
+ * 兜底间隔定时器:每个 enabled 通道按各自 interval 排一次性定时器,触发后**只重排自己**。
290
+ *
291
+ * 早期实现是「清掉全部通道再统一重排」:webdav 5m 每跑一轮就把 git 30m 的定时器清掉重排,
292
+ * 30m 永远等不到 → 纯定时器模式下慢通道永久饥饿(审计 P5-1,虚拟时钟 180min 实测 git 只跑 1 次)。
293
+ */
256
294
  scheduleIntervalTimers() {
257
295
  for (const timer of this.timers.values())
258
296
  this.clearTimer(timer);
259
297
  this.timers.clear();
260
298
  // 通道清单唯一来源 = SYNC_CHANNELS(此前同一数组在本文件写了两遍:漏改一处即某通道永不排期)
261
- const channels = SYNC_CHANNELS;
262
- for (const channel of channels) {
263
- void this.readConfig(channel).then((cfg) => {
264
- if (this.stopped || !cfg.enabled)
299
+ for (const channel of SYNC_CHANNELS)
300
+ this.scheduleChannelTimer(channel);
301
+ }
302
+ /** 单个通道的一次性 interval 排期(触发后只重排这一个通道)。 */
303
+ scheduleChannelTimer(channel) {
304
+ const existing = this.timers.get(channel);
305
+ if (existing !== undefined)
306
+ this.clearTimer(existing);
307
+ this.timers.delete(channel);
308
+ void this.readConfig(channel).then((cfg) => {
309
+ if (this.stopped || !cfg.enabled)
310
+ return;
311
+ const ms = intervalToMs(cfg.interval);
312
+ const timer = this.setTimer(() => {
313
+ // 一次性定时器:触发后立即从表移除,避免 reload() 清理到已失效的句柄
314
+ this.timers.delete(channel);
315
+ if (this.stopped)
265
316
  return;
266
- const ms = intervalToMs(cfg.interval);
267
- const timer = this.setTimer(() => {
268
- // 一次性定时器:触发后立即从表移除,避免 reload() 清理到已失效的句柄
269
- this.timers.delete(channel);
270
- if (this.stopped)
271
- return;
272
- void this.runOnce(channel, { reason: 'interval' })
273
- .catch((err) => {
274
- this.host.log.error(`自动同步定时触发失败(${channel})`, { error: err instanceof Error ? err.message : String(err) });
275
- })
276
- .then(() => {
277
- // 只重排 interval 定时器(远端轮询有自己的节奏,绝不互相重置)
278
- if (!this.stopped)
279
- this.scheduleIntervalTimers();
280
- });
281
- }, ms);
282
- this.timers.set(channel, timer);
283
- }).catch(() => { });
284
- }
317
+ void this.runOnce(channel, { reason: 'interval' })
318
+ .catch((err) => {
319
+ this.host.log.error(`自动同步定时触发失败(${channel})`, { error: err instanceof Error ? err.message : String(err) });
320
+ })
321
+ .then(() => {
322
+ // 只重排自己的 interval 定时器(远端轮询有自己的节奏,别的通道也不得被本通道重置)
323
+ if (!this.stopped)
324
+ this.scheduleChannelTimer(channel);
325
+ });
326
+ }, ms);
327
+ this.timers.set(channel, timer);
328
+ }).catch(() => { });
285
329
  }
286
330
  /**
287
331
  * realtime 通道的远端轮询:按 remoteCheckMs(缺省 60s)排一次性定时器。
@@ -514,7 +558,12 @@ export class AutoSyncScheduler {
514
558
  try {
515
559
  // 锁内重跑一次检测:预检到写入之间可能被别的进程推进(远端新快照 / 本机配置改动),
516
560
  // 拿过期结论去写等于覆盖别人的成果。无锁环境(测试)直接用预检结果 —— 同一份数据,没有竞态。
517
- const phase = releaseLock === null ? preflight : await this.detectPhase(channel, cfg, nowIso, historyId);
561
+ // P0(2026-11-14 真机事故):锁内重跑必须与预检同口径传 localCheck。
562
+ // 此前这里漏传 → 60s 远端轮询在锁内又跑了一遍全量本地导出(plugins 的 npm pack,
563
+ // 实测单插件 44.7s/轮),预检省下的开销全被这一步还回去。
564
+ const phase = releaseLock === null
565
+ ? preflight
566
+ : await this.detectPhase(channel, cfg, nowIso, historyId, { localCheck: opts.reason !== 'remote-poll' });
518
567
  if (phase.kind === 'skip')
519
568
  return phase.result;
520
569
  const { engine, remoteNew, localDirty, firstRun } = phase;
@@ -528,6 +577,12 @@ export class AutoSyncScheduler {
528
577
  * 真机现场「推本机配置当备份」这条链路被远端冲突连续阻塞,用户却只看到 skipped/conflict。
529
578
  */
530
579
  let conflictedSections = [];
580
+ //
581
+ // issue #136:Phase B 的「成功但没全写进去」必须能被看见 —— 旧实现只看 applyReport.ok,
582
+ // ok 时把 warnings / 待裁决项整包丢掉,于是「patch 行被剥空→守卫保留本机」与
583
+ // 「叶级冲突被扣下」都表现为一轮干净的成功。
584
+ let downlinkWarnings = [];
585
+ let heldLeafSections = [];
531
586
  // Phase A: pull 合并(下载)—— 仅当远端有新快照才拉取(§3.2)。
532
587
  if (remoteNew) {
533
588
  let mergePlan;
@@ -585,6 +640,8 @@ export class AutoSyncScheduler {
585
640
  })).result
586
641
  : await rawApply();
587
642
  appliedSections = applyReport.applied;
643
+ downlinkWarnings = applyReport.warnings;
644
+ heldLeafSections = [...new Set(applyReport.review.map((r) => r.sectionId))];
588
645
  if (!applyReport.ok) {
589
646
  const error = applyReport.warnings.join('; ') || engineMsg('sync.autosyncApplyMergeFailed');
590
647
  const result = {
@@ -615,16 +672,33 @@ export class AutoSyncScheduler {
615
672
  * SYN-05:首轮 / 远端有新快照时即使显式选了 local 也强制降级 ask(forced=true 进结果与
616
673
  * 历史),绝不在这两个高危时刻替用户覆盖远端最新。
617
674
  */
675
+ // issue #146(F9):local 是用户的长期决定 —— 存量待裁决必须能被它消解,否则上一轮攒下的
676
+ // 分区永远等不到结论(每轮"既不推也不报错"地空转)。只在策略是 local 时读一次磁盘,
677
+ // 读失败按 0 处理(退回老口径:只扣不推 + 由下面的 all-conflicted 如实上报)。
678
+ const heldFromState = cfg.conflictPolicy === 'local' ? await this.readPendingMerge() : [];
618
679
  const pushDecision = resolveConflictPushPolicy({
619
680
  ...(cfg.conflictPolicy !== undefined ? { configuredPolicy: cfg.conflictPolicy } : {}),
620
681
  firstRun,
621
682
  remoteNew,
622
683
  conflicted: conflictedSections.length,
684
+ held: heldFromState.length,
623
685
  });
624
686
  const forcePush = pushDecision.force;
625
687
  const forcedMark = pushDecision.forcedAsk ? { forced: true } : {};
688
+ // issue #146:本轮**仍未裁决**的分区(分区级冲突 + 下行被扣下的叶级冲突)绝不上行。
689
+ // 冲突分区在 Phase B 被有意跳过(绝不写本地),但推送侧原本照样导出本机版本 ——
690
+ // 真机事故里 plugins 就这样被 30 → 28 → 26 一路压小。force = 用户明确「用本机覆盖远端」,不扣。
691
+ const heldUp = forcePush ? [] : [...new Set([...conflictedSections, ...heldLeafSections])];
692
+ // 先落盘待裁决:引擎推送成功时只在**已有记录**上保留 since,本轮首次判出的冲突要靠这里写下来。
693
+ const pendingRecorded = heldUp.length > 0;
694
+ if (pendingRecorded)
695
+ await this.recordPendingMerge(engine, heldUp);
626
696
  // Phase C: 完整双向 → engine.push() 上传。P0-A:外部 push 包 intent journal。
627
- const rawPush = async () => engine.push(forcePush ? { force: true } : {});
697
+ const rawPush = async () => engine.push({
698
+ ...(forcePush ? { force: true } : {}),
699
+ // 空数组也传:本轮没判出新冲突时,磁盘上上一轮留下的待裁决仍要扣下(issue #146)。
700
+ skipSections: heldUp,
701
+ });
628
702
  const pushReport = (this.phase3Recovery !== undefined && this.lockCtxForJournal !== null)
629
703
  ? (await this.phase3Recovery.runExternalIntent({
630
704
  operationType: 'autosync-push', lockCtx: this.lockCtxForJournal,
@@ -636,12 +710,18 @@ export class AutoSyncScheduler {
636
710
  // 绝不记 failed(那会累加连续失败计数并对用户发通知,把「需要用『检查远程合并』处理」
637
711
  // 谎报成「同步坏了」);错误摘要保留引擎给出的说明(用户能看见到底为什么没推上去)。
638
712
  const message = pushReport.message ?? engineMsg('sync.autosyncPushFailed');
713
+ // issue #136:下行自身的告警/待裁决与「推送被冲突挡下」合并进同一条记录,
714
+ // 不因上行受阻就把下行的事实抹掉。
715
+ const blockedConflicted = [...new Set([...conflictedSections, ...heldLeafSections])];
716
+ const blockedDegraded = downlinkWarnings.length > 0 || heldLeafSections.length > 0;
639
717
  const conflictResult = {
640
- status: conflictedSections.length > 0 ? 'partial' : 'skipped',
718
+ status: blockedConflicted.length > 0 || blockedDegraded ? 'partial' : 'skipped',
641
719
  direction: appliedSections.length ? 'both' : 'push',
642
720
  skipReason: 'conflict', error: message, historyId,
643
721
  appliedSections,
644
- ...(conflictedSections.length > 0 ? { conflictedSections } : {}),
722
+ ...(blockedConflicted.length > 0 ? { conflictedSections: blockedConflicted } : {}),
723
+ ...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
724
+ ...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
645
725
  consecutiveFailures: 0,
646
726
  ...forcedMark,
647
727
  };
@@ -649,10 +729,16 @@ export class AutoSyncScheduler {
649
729
  direction: appliedSections.length ? 'both' : 'push', status: conflictResult.status,
650
730
  skipReason: 'conflict', error: message,
651
731
  appliedSections,
652
- ...(conflictedSections.length > 0 ? { conflictedSections } : {}),
732
+ ...(blockedConflicted.length > 0 ? { conflictedSections: blockedConflicted } : {}),
733
+ ...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
734
+ ...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
653
735
  createdAt: nowIso, failureCountAtRun: 0,
654
736
  ...forcedMark,
655
737
  });
738
+ // 冲突分区落成待裁决(P2):首页与同步页据此给出裁决入口。推送前已写过就不再写一次
739
+ // (重复写会按 lastMergedRemoteSnapshotId 重算 since,抹掉首次判出冲突的时间)。
740
+ if (!pendingRecorded)
741
+ await this.recordPendingMerge(engine, conflictedSections);
656
742
  await this.writeFinalConfig(cfg, conflictResult, nowIso, historyId, channel);
657
743
  return conflictResult;
658
744
  }
@@ -676,15 +762,27 @@ export class AutoSyncScheduler {
676
762
  // 也绝不因为它报成 failed:网络与凭据都是好的,只是远端有内容要用户确认)。
677
763
  // conflictPolicy='local' 时冲突已被「本机覆盖远端」消解,但远端那一版确实被盖掉了 →
678
764
  // 同样记 partial,skipReason 换成 conflict-kept-local(界面据此说清「本机已覆盖远端」)。
679
- const keptLocal = forcePush && conflictedSections.length > 0;
680
- const partial = conflictedSections.length > 0;
765
+ // force 消解的对象 = 本轮冲突 ∪ 磁盘存量(F9):只覆盖本轮会让台账把「覆盖了远端」这件事
766
+ // 说成一次普通成功 —— 用户从来看不出自己那句「本机优先」到底动过哪些分区。
767
+ const keptLocalSections = forcePush
768
+ ? [...new Set([...conflictedSections, ...heldFromState])]
769
+ : [];
770
+ const keptLocal = keptLocalSections.length > 0;
771
+ const partial = keptLocal || conflictedSections.length > 0;
772
+ // issue #146(follow-up):引擎把「冲突未裁决 ⇒ 本轮一个分区都没上行」回成 skipped:'all-conflicted'。
773
+ // 以前这里只看 ok/conflict,于是整轮被记成「上传·成功」—— 用户从此看不出有分区被扣下,
774
+ // #146 的「显示成已推送」在自动同步路径原地复发。全扣下与部分扣下都必须落到台账。
775
+ const allConflicted = pushReport.skipped === 'all-conflicted';
776
+ const pushWarnings = pushReport.warnings ?? [];
681
777
  const skipReason = keptLocal
682
778
  ? 'conflict-kept-local'
683
779
  : partial
684
780
  ? 'conflict'
685
- : undefined;
781
+ : allConflicted
782
+ ? 'all-conflicted'
783
+ : undefined;
686
784
  const reportedConflicted = keptLocal
687
- ? conflictedSections
785
+ ? keptLocalSections
688
786
  : partial
689
787
  ? conflictedSections
690
788
  : deferredSections;
@@ -692,21 +790,49 @@ export class AutoSyncScheduler {
692
790
  // 如实记一条 skipReason,让历史与首页能说清「这次推上去之前先修好了基线」,
693
791
  // 而不是让用户以为又发生了一次莫名冲突。冲突原因优先(真有冲突时更该被看见)。
694
792
  const adoptedReason = pushReport.adoptedBase !== undefined ? 'baseline-adopted' : undefined;
793
+ // issue #136:下行有告警 / 有待裁决叶级项 → 终态只能是 partial。
794
+ // 「推送成功」不能替下行的未完成背书:用户会从 success 得出「两端一样了」,而实际上
795
+ // 有些叶子被有意扣下(保留本机 / 等待裁决)。
796
+ // 两类降级必须分开说:只有「叶级冲突被扣下」才是冲突待裁决;
797
+ // 纯告警(插件没装上、undo 有残留等)与冲突无关,套上 'conflict' 会让
798
+ // 界面上出现「跳过原因:冲突」「另有 N 个分区待确认」,而 conflictedSections 是空的。
799
+ const heldDegraded = heldLeafSections.length > 0;
800
+ // 引擎告警(分区导出失败 / 非 portable 跳过 / 扣下说明)同样要上屏:静默少推比失败更糟。
801
+ const allWarnings = [...downlinkWarnings, ...pushWarnings];
802
+ // 引擎 push 回传的告警(provider namespace 未配置、目录为空…)是常规事实噪声,只上屏不降级;
803
+ // 状态降级只认「有分区被扣下」与下行冲突 —— 否则每轮都变成 partial,用户就学不会 partial 的含义。
804
+ const degraded = downlinkWarnings.length > 0 || heldDegraded;
805
+ const finalPartial = partial || degraded || allConflicted;
806
+ // 一个分区都没上行 = 「成功但跳过」,不是「成功」也不是「失败」(#146 验收口径②)。
807
+ const finalStatus = allConflicted && appliedSections.length === 0
808
+ ? 'skipped'
809
+ : finalPartial ? 'partial' : 'success';
810
+ const finalSkipReason = skipReason
811
+ ?? (heldDegraded ? 'conflict' : degraded ? 'warning' : undefined);
812
+ // 扣下的叶级冲突所在分区也要出现在「待处理分区」里(与分区级冲突合并去重)
813
+ const finalConflicted = [...new Set([...reportedConflicted, ...heldLeafSections])];
695
814
  const result = {
696
- status: partial ? 'partial' : 'success',
815
+ status: finalStatus,
697
816
  direction: appliedSections.length ? 'both' : 'push',
698
- appliedSections, pushedSnapshotId: pushReport.snapshotId, historyId,
699
- ...(skipReason !== undefined || adoptedReason !== undefined ? { skipReason: skipReason ?? adoptedReason } : {}),
700
- ...(reportedConflicted.length > 0 ? { conflictedSections: reportedConflicted } : {}),
817
+ appliedSections, historyId,
818
+ // issue #146:全扣下时 snapshotId 为空 —— 绝不写空 id(界面会当成「推了某份快照」)。
819
+ ...(pushReport.snapshotId !== '' ? { pushedSnapshotId: pushReport.snapshotId } : {}),
820
+ ...(finalSkipReason !== undefined || adoptedReason !== undefined ? { skipReason: finalSkipReason ?? adoptedReason } : {}),
821
+ ...(finalConflicted.length > 0 ? { conflictedSections: finalConflicted } : {}),
822
+ ...(allWarnings.length > 0 ? { warnings: allWarnings } : {}),
823
+ ...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
701
824
  consecutiveFailures: 0,
702
825
  ...forcedMark,
703
826
  };
704
827
  await this.appendHistory(channel, {
705
828
  direction: appliedSections.length ? 'both' : 'push',
706
- status: partial ? 'partial' : 'success',
707
- appliedSections, pushedSnapshotId: pushReport.snapshotId,
708
- ...(skipReason !== undefined || adoptedReason !== undefined ? { skipReason: skipReason ?? adoptedReason } : {}),
709
- ...(reportedConflicted.length > 0 ? { conflictedSections: reportedConflicted } : {}),
829
+ status: finalStatus,
830
+ appliedSections,
831
+ ...(pushReport.snapshotId !== '' ? { pushedSnapshotId: pushReport.snapshotId } : {}),
832
+ ...(finalSkipReason !== undefined || adoptedReason !== undefined ? { skipReason: finalSkipReason ?? adoptedReason } : {}),
833
+ ...(finalConflicted.length > 0 ? { conflictedSections: finalConflicted } : {}),
834
+ ...(allWarnings.length > 0 ? { warnings: allWarnings } : {}),
835
+ ...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
710
836
  createdAt: nowIso, failureCountAtRun: 0,
711
837
  ...forcedMark,
712
838
  });
@@ -732,28 +858,45 @@ export class AutoSyncScheduler {
732
858
  }
733
859
  // 本轮下行被冲突挡下、且没有可上行内容(startup 变体 / 本地无改动)→ 如实 skipped/conflict。
734
860
  if (conflictedSections.length > 0) {
861
+ // issue #136:被扣下的叶级冲突也算「待处理分区」(与分区级冲突同列)。
862
+ const skipConflicted = [...new Set([...conflictedSections, ...heldLeafSections])];
735
863
  const conflictResult = {
736
864
  status: 'skipped', direction: 'pull', skipReason: 'conflict',
737
- conflictedSections, historyId, consecutiveFailures: 0,
865
+ conflictedSections: skipConflicted, historyId, consecutiveFailures: 0,
866
+ ...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
867
+ ...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
738
868
  };
739
869
  await this.appendHistory(channel, {
740
870
  direction: 'pull', status: 'skipped', skipReason: 'conflict',
741
- conflictedSections, createdAt: nowIso, failureCountAtRun: 0,
871
+ conflictedSections: skipConflicted, createdAt: nowIso, failureCountAtRun: 0,
872
+ ...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
873
+ ...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
742
874
  });
875
+ await this.recordPendingMerge(engine, conflictedSections);
743
876
  await this.writeFinalConfig(cfg, conflictResult, nowIso, historyId, channel);
744
877
  return conflictResult;
745
878
  }
746
879
  // startup 变体 / 仅远端合并:只做 pull 合并(不上传),或远端无新生且本地无改动(已在上方 upToDate 短路上)。
880
+ // issue #136:纯下行的告警/待裁决同样算「没全做完」—— 终态不得写成 success。
881
+ const degraded = downlinkWarnings.length > 0 || heldLeafSections.length > 0;
882
+ const pulledConflicted = [...new Set([...deferredSections, ...heldLeafSections])];
883
+ const pullSkipReason = !degraded && appliedSections.length === 0
884
+ ? 'unchanged'
885
+ : degraded ? 'conflict' : undefined;
747
886
  const result = {
748
- status: 'success', direction: 'pull', appliedSections,
749
- ...(appliedSections.length === 0 ? { skipReason: 'unchanged' } : {}),
750
- ...(deferredSections.length > 0 ? { conflictedSections: deferredSections } : {}),
887
+ status: degraded ? 'partial' : 'success', direction: 'pull', appliedSections,
888
+ ...(pullSkipReason !== undefined ? { skipReason: pullSkipReason } : {}),
889
+ ...(pulledConflicted.length > 0 ? { conflictedSections: pulledConflicted } : {}),
890
+ ...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
891
+ ...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
751
892
  historyId, consecutiveFailures: 0,
752
893
  };
753
894
  await this.appendHistory(channel, {
754
- direction: 'pull', status: 'success', appliedSections,
755
- ...(appliedSections.length === 0 ? { skipReason: 'unchanged' } : {}),
756
- ...(deferredSections.length > 0 ? { conflictedSections: deferredSections } : {}),
895
+ direction: 'pull', status: degraded ? 'partial' : 'success', appliedSections,
896
+ ...(pullSkipReason !== undefined ? { skipReason: pullSkipReason } : {}),
897
+ ...(pulledConflicted.length > 0 ? { conflictedSections: pulledConflicted } : {}),
898
+ ...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
899
+ ...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
757
900
  createdAt: nowIso, failureCountAtRun: 0,
758
901
  });
759
902
  await this.writeFinalConfig(cfg, result, nowIso, historyId, channel);
@@ -893,6 +1036,26 @@ export class AutoSyncScheduler {
893
1036
  }
894
1037
  return { kind: 'work', engine, remoteNew, localDirty, firstRun };
895
1038
  }
1039
+ /**
1040
+ * P2(2026-11-14 真机事故):把「本轮被冲突挡下的分区」写进 sync-state.pendingMerge。
1041
+ *
1042
+ * 过去自动同步只在历史里留一句「冲突」,sync-state 里没有可挂入口的持久对象 ——
1043
+ * 首页「待裁决」徽章于是只有颜色没有去处,用户点不动、也不知道该去哪裁决。
1044
+ * 这里由引擎按**本轮实际合并过的远端快照 id** 落 pendingMerge(同远端快照连续冲突保留首次 since),
1045
+ * 界面据 /sync/status 的 pendingMerge 显示待裁决分区,首页那一行据此跳到同步页。
1046
+ *
1047
+ * 尽力而为:写待裁决失败绝不能把「远端有冲突」这一事实变成 failed(那会累加连续失败计数)。
1048
+ */
1049
+ async recordPendingMerge(engine, sections) {
1050
+ if (sections.length === 0)
1051
+ return;
1052
+ try {
1053
+ await engine.recordPendingMerge(sections);
1054
+ }
1055
+ catch (err) {
1056
+ this.host.log.warn(`自动同步待裁决分区未能落盘:${err instanceof Error ? err.message : String(err)}`);
1057
+ }
1058
+ }
896
1059
  async writeFinalConfig(base, result, nowIso, historyId, channel) {
897
1060
  const skipReason = result.status === 'failed' ? undefined : result.skipReason;
898
1061
  const countsConflicts = skipReason === 'conflict' || skipReason === 'conflict-kept-local';
@@ -904,7 +1067,8 @@ export class AutoSyncScheduler {
904
1067
  lastRunAt: nowIso,
905
1068
  lastRunStatus: result.status,
906
1069
  consecutiveFailures: result.consecutiveFailures,
907
- lastRunHistoryId: historyId,
1070
+ // 历史被压掉的轮次没有新记录 id —— 保留上一条真记录的 id,绝不指向不存在的条目。
1071
+ lastRunHistoryId: this.historyDeduped ? (base.lastRunHistoryId ?? historyId) : historyId,
908
1072
  lastRunMessage: result.error ?? '',
909
1073
  lastRunSkipReason: skipReason,
910
1074
  lastRunSkipCount: skipCount,
@@ -28,6 +28,13 @@ export async function adoptOwnRemoteHead(opts) {
28
28
  continue;
29
29
  state.sections[sid] = { hash, updatedAt: meta.createdAt };
30
30
  }
31
+ // issue #140(G-44):被收养的快照自己就是「远端当前观测」——它的 sections 记进独立字段。
32
+ // 空对象(加密快照)⇒ 删除观测:判定层因此回落 id 比较,绝不拿 state.sections 顶上。
33
+ const remoteHashes = { ...meta.sections };
34
+ if (Object.keys(remoteHashes).length > 0)
35
+ state.lastRemoteSections = remoteHashes;
36
+ else
37
+ delete state.lastRemoteSections;
31
38
  state.transport = opts.transport;
32
39
  await saveSyncState(opts.stateDir, state, opts.fsx);
33
40
  opts.warnings.push(opts.msg(ancestorKnown ? 'sync.pushBaselineAdopted' : 'sync.pushBaselineAdoptedNoAncestor', {
@@ -0,0 +1,67 @@
1
+ /**
2
+ * m-sync-flow:写基线的唯一实现(本地祖先副本 + sync-state)。
3
+ *
4
+ * 为什么单独成模块:这段逻辑是「祖先副本布局 + 远端指针 + 每分区 hash + 裁剪」的完整落盘决策,
5
+ * 不需要引擎的任何其他状态(只吃快照目录、通道身份与时间);留在 SyncEngine 里会顶穿体量棘轮。
6
+ *
7
+ * **两个 id 语义严格分开(P0-7),不要再混用同一个字段**:
8
+ * - `snapshotId`:本次基线的**本地**快照对象 id,同时是本地祖先副本的目录名(写入 `ancestorId`);
9
+ * - `opts.remoteSnapshotId`:该基线在**远端**对应的快照 id(写入 `lastSnapshotId`)。缺省 = snapshotId
10
+ * (push 路径两者天然相同);合并/应用路径**必须显式传**,否则 lastSnapshotId 会退化成「一个远端
11
+ * 并不存在的本地 id」→ hasNewRemoteSnapshot() 恒判「远端有新生」,每轮白跑 list + download + merge。
12
+ * 传入 `''` 表示「远端 id 未知」——宁可留空,也不要把本地 id 冒充成远端 id。
13
+ *
14
+ * **issue #140 / G-44**:`opts.remoteSections` 是**远端观测**(远端快照自己携带的分区哈希),
15
+ * 与传入的 `sections`(本机观测,用来算 hasLocalChanges 的基线)是两个不同来源。
16
+ * 早先的事故正是「一参两用」:拿本机 hash 当远端现状,判定就永远自洽、永远看不出远端真的变了。
17
+ */
18
+ import type { Platform, SectionData, SectionId } from '../schema/types.ts';
19
+ import type { MsgFunc } from '../core/messages.ts';
20
+ import type { SnapshotFs } from './fs.ts';
21
+ import type { PendingMerge, SectionHashes } from './sync-state.ts';
22
+ export interface RecordBaselineOptions {
23
+ writeAncestor?: boolean;
24
+ /** 提供即把祖先副本写成**密文**(密码仅本次内存使用;issue #107) */
25
+ ancestorPassword?: string;
26
+ remoteSnapshotId?: string;
27
+ /** 保留当前祖先副本与 ancestorId(缺省 false = 既有行为逐字不变) */
28
+ preserveAncestor?: boolean;
29
+ /** 待裁决冲突记录:null = 清除;缺省 = 不动该字段 */
30
+ pendingMerge?: PendingMerge | null;
31
+ /** P1-5:本轮**实际带走**的会话单元(提供即覆盖;缺省 = 保留原记录) */
32
+ sessionUnits?: string[];
33
+ /** P1-5:本轮累积的删除墓碑(提供即覆盖;缺省 = 保留原记录) */
34
+ deletedSessions?: string[];
35
+ /**
36
+ * issue #140:本次基线对应的**远端观测**(远端快照实际携带的分区哈希,G-44)。
37
+ *
38
+ * - 提供且非空 ⇒ 原样记录(只允许来自「真的看到了远端 sections」的调用点);
39
+ * - 提供但为空(加密快照)或未提供 ⇒ 指针若发生变化则**删除**既有观测(未知 ⇒ 判定回落 id);
40
+ * - 指针未变(preserveAncestor 的待裁决冲突)⇒ 保留既有观测(远端没动,观测仍成立)。
41
+ * 绝不允许由传入的 `sections`(本机观测)推导。
42
+ */
43
+ remoteSections?: SectionHashes;
44
+ }
45
+ /** 落盘所需的环境(引擎逐字段透传;此处不持有引擎实例)。 */
46
+ export interface RecordBaselineEnv {
47
+ fsx: SnapshotFs;
48
+ stateDir: string;
49
+ localSnapshotsDir?: string;
50
+ dshVersion: string;
51
+ platform: Platform;
52
+ transport: {
53
+ type: string;
54
+ ref: string;
55
+ };
56
+ now: () => Date;
57
+ msg: MsgFunc;
58
+ }
59
+ export interface RecordBaselineInput {
60
+ snapshotId: string;
61
+ /** 基线**恒为明文**(加密快照的基线 hash 也用明文算,供 hasLocalChanges 比较)。 */
62
+ sections: Partial<Record<SectionId, SectionData>>;
63
+ nowIso?: string;
64
+ opts?: RecordBaselineOptions;
65
+ env: RecordBaselineEnv;
66
+ }
67
+ export declare function recordBaseline(input: RecordBaselineInput): Promise<void>;
@@ -0,0 +1,74 @@
1
+ import { CURRENT_SCHEMA_VERSION } from '../schema/versions.js';
2
+ import { DEFAULT_ANCESTOR_KEEP, pruneAncestors, writeAncestor, writeEncryptedAncestor } from './ancestor.js';
3
+ import { encryptSectionsPayload } from './snapshot-crypto.js';
4
+ import { hashSection, loadSyncState, saveSyncState } from './sync-state.js';
5
+ export async function recordBaseline(input) {
6
+ const { snapshotId, sections, env } = input;
7
+ const opts = input.opts ?? {};
8
+ const ts = input.nowIso ?? env.now().toISOString();
9
+ const preserveAncestor = opts.preserveAncestor === true;
10
+ const ancestorPassword = opts.ancestorPassword;
11
+ const encryptedAncestor = ancestorPassword !== undefined && ancestorPassword !== '';
12
+ const writesAncestorCopy = !preserveAncestor && env.localSnapshotsDir !== undefined && opts.writeAncestor !== false;
13
+ // 1) 写本地祖先副本(如有 localSnapshotsDir)。
14
+ // ancestorPassword 提供 → 落**密文**祖先副本(issue #107:加密通道也能做三方合并);
15
+ // 否则落明文散文件布局(既有行为逐字不变)。
16
+ if (writesAncestorCopy && env.localSnapshotsDir !== undefined) {
17
+ const manifest = {
18
+ schemaVersion: CURRENT_SCHEMA_VERSION,
19
+ dshVersion: env.dshVersion,
20
+ platform: env.platform,
21
+ sectionIds: Object.keys(sections),
22
+ containsSecrets: false,
23
+ // 记录触发通道(git/webdav),供同步历史展示「由哪个通道触发」
24
+ transport: env.transport.type,
25
+ ...(encryptedAncestor ? { encrypted: true } : {}),
26
+ };
27
+ if (encryptedAncestor) {
28
+ const encryptedSections = await encryptSectionsPayload(sections, ancestorPassword);
29
+ await writeEncryptedAncestor(env.localSnapshotsDir, { id: snapshotId, createdAt: ts, manifest, sections: encryptedSections }, env.fsx);
30
+ }
31
+ else {
32
+ await writeAncestor(env.localSnapshotsDir, { id: snapshotId, createdAt: ts, manifest, sections }, env.fsx);
33
+ }
34
+ }
35
+ // 2) 更新 sync-state:远端指针 + 本地祖先目录名 + 每分区 hash/updatedAt + lastSyncAt + transport
36
+ const state = await loadSyncState(env.stateDir, env.fsx, env.msg);
37
+ const previousPointer = state.lastSnapshotId;
38
+ state.lastSnapshotId = opts.remoteSnapshotId ?? snapshotId;
39
+ // issue #140(G-44):远端观测只认调用方显式给出的「远端快照 sections」。
40
+ // 指针变了却拿不到观测 ⇒ 删除(下一轮判定回落 id 比较),绝不沿用上一份观测冒充现状。
41
+ if (opts.remoteSections !== undefined) {
42
+ if (Object.keys(opts.remoteSections).length > 0)
43
+ state.lastRemoteSections = { ...opts.remoteSections };
44
+ else
45
+ delete state.lastRemoteSections;
46
+ }
47
+ else if (state.lastSnapshotId !== previousPointer) {
48
+ delete state.lastRemoteSections;
49
+ }
50
+ // preserveAncestor:祖先目录名一并保持不动(既不是 snapshotId,也不是 '')
51
+ if (!preserveAncestor)
52
+ state.ancestorId = writesAncestorCopy ? snapshotId : '';
53
+ state.lastSyncAt = ts;
54
+ state.transport = { type: env.transport.type, ref: env.transport.ref };
55
+ // 基线纪律:null = 清除(全部裁决完);undefined = 不动该字段(既有调用方零感知)
56
+ if (opts.pendingMerge === null)
57
+ delete state.pendingMerge;
58
+ else if (opts.pendingMerge !== undefined)
59
+ state.pendingMerge = opts.pendingMerge;
60
+ // P1-5:只在调用方明确提供时覆盖(否则保留既有记录,绝不因某条路径不跟踪而清空)
61
+ if (opts.sessionUnits !== undefined)
62
+ state.sessionUnits = [...opts.sessionUnits];
63
+ if (opts.deletedSessions !== undefined)
64
+ state.deletedSessions = [...opts.deletedSessions];
65
+ for (const [sid, data] of Object.entries(sections)) {
66
+ state.sections[sid] = { hash: hashSection(data), updatedAt: ts };
67
+ }
68
+ await saveSyncState(env.stateDir, state, env.fsx);
69
+ // 3) 裁剪祖先副本(最近 N 个);preserveAncestor 时本轮没有新副本,不参与裁剪
70
+ if (!preserveAncestor && env.localSnapshotsDir !== undefined) {
71
+ await pruneAncestors(env.localSnapshotsDir, DEFAULT_ANCESTOR_KEEP, env.fsx);
72
+ }
73
+ }
74
+ //# sourceMappingURL=baseline-record.js.map
@@ -47,6 +47,19 @@ export async function refsToSection(refs, sink) {
47
47
  if (data === null) {
48
48
  throw new Error(engineMsg('sync.blobMissing', { hash: ref.blobHash, path: ref.relativePath }));
49
49
  }
50
+ // 内容寻址仓的引用自带 sha256(+ 字节数),取回后必须自证(审计 P6-3)。
51
+ // 注释承诺「远端仓被清理坏/被手工删过」必须硬失败,但此前只覆盖「删了」:
52
+ // 内容被改、半截写、base64 传输丢字符都会畅通无阻地把错误字节当成会话原样写回,
53
+ // 而「静默损坏」比「硬失败」更糟 —— 用户看不到任何错误,只发现对话内容变了。
54
+ const actualHash = sha256Hex(data);
55
+ if (actualHash !== ref.blobHash || (ref.sizeBytes !== undefined && data.byteLength !== ref.sizeBytes)) {
56
+ throw new Error(engineMsg('sync.blobCorrupt', {
57
+ hash: ref.blobHash,
58
+ path: ref.relativePath,
59
+ actual: actualHash,
60
+ size: String(data.byteLength),
61
+ }));
62
+ }
50
63
  files.push({ relativePath: ref.relativePath, data, contentHash: ref.blobHash });
51
64
  }
52
65
  return { version: 1, files };