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
@@ -41,6 +41,13 @@ export interface AutosyncHistoryEntry {
41
41
  pulledSnapshotId?: string;
42
42
  /** failed 时的错误摘要(脱敏) */
43
43
  error?: string;
44
+ /**
45
+ * issue #136:本轮下行的用户可见告警(被保住的脱敏叶子 / 被扣下的叶级冲突)。
46
+ * 与 status 同看:有告警就不可能是一条「纯成功、什么都做了」的记录。
47
+ */
48
+ warnings?: string[];
49
+ /** issue #136:被保留待裁决的叶级冲突所在分区。 */
50
+ heldSections?: SectionId[];
44
51
  /** 连续失败 3 次通知时间(ISO-8601 UTC) */
45
52
  notifiedAt?: string;
46
53
  /** 本次触发时的连续失败计数 */
@@ -31,6 +31,18 @@ export interface SyncSectionState {
31
31
  updatedAt: string; // ISO-8601 UTC
32
32
  }
33
33
 
34
+ /**
35
+ * 分区 id → 内容哈希(= hashSection 的结果)。
36
+ *
37
+ * 同一个形状服务两种**完全不同**的观测,调用方必须分清(G-44:
38
+ * docs/known-issues/known-gaps.md 的「祖先副本与 state.sections 一参两用」):
39
+ * - `SyncState.sections`:**本机**文件最近一次基线的内容哈希(含本机尚未推送的改动);
40
+ * - `SyncState.lastRemoteSections`:上一次**远端快照实际携带**的分区哈希(远端观测);
41
+ * - 推送前刚导出的本地哈希(content-diff.hashSections)。
42
+ * 内容判定(src/sync/content-diff.ts)只接受后两者,绝不拿 state.sections 冒充远端观测。
43
+ */
44
+ export type SectionHashes = Partial<Record<SectionId, string>>;
45
+
34
46
  /**
35
47
  * 待裁决的合并状态(基线纪律,2026-10)。
36
48
  *
@@ -92,6 +104,23 @@ export interface SyncState {
92
104
  * 让冲突在下一轮重新出现(详见 PendingMerge)。
93
105
  */
94
106
  pendingMerge?: PendingMerge;
107
+ /**
108
+ * issue #140:上一次**远端快照实际携带**的分区哈希(远端观测,不是本机观测)。
109
+ *
110
+ * 用途:拉取侧判定「远端最新快照的内容是否真的变了」——只比 id 时,任何一次新推送
111
+ * (哪怕分区逐字相同)都会判成「有新生」,白跑 download + 三方合并。
112
+ *
113
+ * 纪律(G-44):
114
+ * - 只许由「真的看到了远端快照 sections」的路径写入(推送成功 / 推送跳过收养 / 收养孤儿头 /
115
+ * 合并应用到某个远端快照之后);
116
+ * - 指针变化但本轮没有远端观测 ⇒ 必须**删除**该字段(未知 ⇒ 调用方回落 id 比较),
117
+ * 绝不保留上一份观测冒充「远端现在也是这样」;
118
+ * - 加密快照的 sections 恒为空(transport.ts)⇒ 该字段保持缺席,判定恒为 unknown。
119
+ *
120
+ * 纯可选字段:**不提升 SYNC_STATE_SCHEMA_VERSION**(旧文件缺它 → 读回形状逐键不变;
121
+ * 旧版本代码读到新文件只是忽略它)。
122
+ */
123
+ lastRemoteSections?: SectionHashes;
95
124
  }
96
125
 
97
126
  /** 文件类分区判定:{ version: 1, files: [...] }(duck-typing,与 JSON 分区区分) */
@@ -165,6 +194,21 @@ function readPendingMerge(raw: unknown): PendingMerge | undefined {
165
194
  return { remoteSnapshotId: o['remoteSnapshotId'], sections: sections as SectionId[], since: o['since'] };
166
195
  }
167
196
 
197
+ /**
198
+ * 读取「远端观测」(分区 id → hash)。
199
+ *
200
+ * 形状不符(损坏/被篡改)或为空对象 → undefined:空集合无法证伪任何内容,
201
+ * 按「没有观测」处理(调用方回落到 id 比较),绝不把空对象当成「远端什么都没有」。
202
+ */
203
+ function readSectionHashes(raw: unknown): SectionHashes | undefined {
204
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) return undefined;
205
+ const out: SectionHashes = {};
206
+ for (const [sid, value] of Object.entries(raw as Record<string, unknown>)) {
207
+ if (typeof value === 'string' && value !== '') out[sid as SectionId] = value;
208
+ }
209
+ return Object.keys(out).length > 0 ? out : undefined;
210
+ }
211
+
168
212
  /** 读取同步状态;文件不存在 → 返回缺省空状态(从未同步)。
169
213
  * 旧版本文件(v1/v2)→ 在内存中迁移到当前版本(见 SYNC_STATE_SUPPORTED_VERSIONS),
170
214
  * 不在磁盘上就地升级(首次 saveSyncState 时才写回新版本)。 */
@@ -220,6 +264,10 @@ export async function loadSyncState(dir: string, fsx: SnapshotFs = createSnapsho
220
264
  ...(typeof obj['deviceName'] === 'string' && obj['deviceName'] !== '' ? { deviceName: obj['deviceName'] } : {}),
221
265
  // 基线纪律:同样「写过才回填」—— 缺席 = 无待裁决冲突(旧文件读回形状逐键不变)
222
266
  ...(readPendingMerge(obj['pendingMerge']) !== undefined ? { pendingMerge: readPendingMerge(obj['pendingMerge'])! } : {}),
267
+ // issue #140:远端观测同样「写过才回填」—— 缺席/空 = 未知(判定层回落 id 比较)
268
+ ...(readSectionHashes(obj['lastRemoteSections']) !== undefined
269
+ ? { lastRemoteSections: readSectionHashes(obj['lastRemoteSections'])! }
270
+ : {}),
223
271
  };
224
272
  const t = obj['transport'];
225
273
  if (t !== undefined) {
@@ -7,7 +7,7 @@
7
7
  import test from 'node:test';
8
8
  import assert from 'node:assert/strict';
9
9
 
10
- import { classifyNetworkErrorText, computeSnapshotMeta, manifestSummaryFrom } from './transport.ts';
10
+ import { classifyNetworkErrorText, computeSnapshotMeta, isPreconditionFailedStatus, manifestSummaryFrom } from './transport.ts';
11
11
  import { hashSection } from './sync-state.ts';
12
12
  import type { ManifestSummary, SyncSnapshot, SyncTransport } from './transport.ts';
13
13
  import type { Manifest, SectionData, SectionId } from '../schema/types.ts';
@@ -130,3 +130,15 @@ test('ManifestSummary 类型形状(编译期保证 + 运行期检查)', () =
130
130
  assert.equal(s.schemaVersion, 1);
131
131
  assert.ok(Array.isArray(s.sectionIds));
132
132
  });
133
+
134
+ /* ------------------------------------------------- audit-sync sync-P6-5:条件写状态判定的单一实现 */
135
+
136
+ test('isPreconditionFailedStatus: 412 恒为并发写失败;409 仅在带条件头(guarded)时算', () => {
137
+ assert.equal(isPreconditionFailedStatus(412), true, 'WebDAV If-Match/If-None-Match 冲突 = 412');
138
+ assert.equal(isPreconditionFailedStatus(412, { guarded: false }), true);
139
+ assert.equal(isPreconditionFailedStatus(409, { guarded: true }), true, 'S3 兼容端点把条件写冲突报成 409');
140
+ assert.equal(isPreconditionFailedStatus(409), false, '无条件 409 另有含义(如 WebDAV MKCOL 缺父目录),不得当成并发写');
141
+ assert.equal(isPreconditionFailedStatus(409, { guarded: false }), false);
142
+ assert.equal(isPreconditionFailedStatus(200), false);
143
+ assert.equal(isPreconditionFailedStatus(500), false);
144
+ });
@@ -114,10 +114,18 @@ export interface SyncProbeResult {
114
114
  createdCollections?: string[];
115
115
  }
116
116
 
117
- /** 写出/删除路径的**条件写**失败(HTTP 412 Precondition Failed,或 S3 兼容端点的 409):
118
- * 远端在我读取之后被别人改过 —— 必须中止本次写入让用户重试,绝不静默覆盖。 */
119
- export function isPreconditionFailedStatus(status: number): boolean {
120
- return status === 412;
117
+ /**
118
+ * 写出/删除路径的**条件写**失败判定(两条通道共用的唯一实现处):
119
+ * - 412 Precondition Failed 恒算(If-Match / If-None-Match 的语义);
120
+ * - 409 只在**本次确实带了条件写头**时才算 —— S3 兼容端点用 409 表达「对象已存在 / 冲突」,
121
+ * 而 WebDAV 的 409(如 MKCOL 缺父目录)与无条件的 409 另有含义,绝不能吞成并发冲突。
122
+ *
123
+ * 判定通过后仍须按通道报文细分:OSS 的 409 还可能表示 FileImmutable(桶被保护),
124
+ * 那必须如实报错而不是谎称「别的设备改过索引」(见 s3-transport 的 conditionalFailure)。
125
+ */
126
+ export function isPreconditionFailedStatus(status: number, opts: { guarded?: boolean } = {}): boolean {
127
+ if (status === 412) return true;
128
+ return status === 409 && opts.guarded === true;
121
129
  }
122
130
 
123
131
  export interface SyncTransport {
@@ -0,0 +1,249 @@
1
+ /**
2
+ * audit-sync sync-P6-1 / sync-P6-4(P3)的回归钉子(WebDAV 通道):
3
+ *
4
+ * P6-1:delete 必须**先条件写索引、后删对象**。旧顺序(先 DELETE 对象)在索引 PUT 回 412 时留下
5
+ * 「索引指向已删对象」的条目 —— list 不校验存在性,别的设备 pull 到它就是 notfound 硬失败。
6
+ * 最坏情况改为「索引摘除成功但对象 DELETE 失败」= 一个 list 看不到、pull 不会命中的孤儿文件。
7
+ *
8
+ * P6-4:blob 索引的「读失败」与「确实没有索引」必须分开。旧实现把 5xx / 坏 JSON 当空索引,
9
+ * 随后 appendBlobIndex 整体 PUT 覆盖 ⇒ 已登记条目全丢。现在:404/405/501 才是空,其余非 2xx 抛
10
+ * 可重试错误、坏 JSON 抛 protocol,绝不整体覆盖。
11
+ */
12
+ import test from 'node:test'
13
+ import assert from 'node:assert/strict'
14
+
15
+ import { WebDavTransport, WebDavTransportError } from './webdav-transport.ts'
16
+ import type { WebDavRequestFn, WebDavResponse, WebDavTransportOptions } from './webdav-transport.ts'
17
+ import type { SyncSnapshot } from '../transport.ts'
18
+ import { zhMsg } from '../../core/messages.ts'
19
+
20
+ const BASE = 'https://dav.example.com/dav/config'
21
+ const COL = BASE + '/dsh-config-manager'
22
+ const BLOBS_COL = COL + '/blobs'
23
+ const INDEX_URL = COL + '/index.json'
24
+ const BLOBS_INDEX_URL = COL + '/blobs-index.json'
25
+ const SNAPSHOT_URL = COL + '/snap-001.json'
26
+ const TEST_PASSWORD = 'super-secret-password-9876'
27
+ const OLD_HASH = 'a'.repeat(64)
28
+ const NEW_HASH = 'b'.repeat(64)
29
+
30
+ interface MockCall { method: string; url: string; headers?: Record<string, string>; body?: string }
31
+
32
+ function res(status: number, bodyText = '', headers?: Record<string, string>): WebDavResponse {
33
+ return {
34
+ status,
35
+ ok: status >= 200 && status < 300,
36
+ ...(headers !== undefined ? { headers } : {}),
37
+ async text() { return bodyText; },
38
+ };
39
+ }
40
+
41
+ function makeOptions(request: WebDavRequestFn): WebDavTransportOptions {
42
+ return {
43
+ baseUrl: BASE,
44
+ username: 'alice',
45
+ credentials: { getPassword: async () => TEST_PASSWORD },
46
+ request,
47
+ };
48
+ }
49
+
50
+ function recorder(calls: MockCall[], handler: (m: MockCall) => WebDavResponse): WebDavRequestFn {
51
+ return async (method, url, opts = {}) => {
52
+ const rec: MockCall = { method, url, headers: opts.headers, body: opts.body };
53
+ calls.push(rec);
54
+ return handler(rec);
55
+ };
56
+ }
57
+
58
+ /** 一条索引条目(schema 只要求 id/createdAt/manifest/sections) */
59
+ const META = {
60
+ id: 'snap-001',
61
+ createdAt: '2026-10-18T09:00:00.000Z',
62
+ sections: {},
63
+ manifest: { schemaVersion: 1, dshVersion: '1', platform: 'win32', sectionIds: [], containsSecrets: false },
64
+ }
65
+
66
+ /** 带 sessions 文件分区的快照(触发 externalize → blob 仓读写) */
67
+ function sessionsSnapshot(): SyncSnapshot {
68
+ return {
69
+ id: 'snap-001',
70
+ createdAt: '2026-10-18T10:00:00.000Z',
71
+ manifest: {
72
+ schemaVersion: 1,
73
+ dshVersion: '1.2.3',
74
+ platform: 'win32',
75
+ sectionIds: ['sessions'],
76
+ containsSecrets: false,
77
+ },
78
+ sections: {
79
+ sessions: {
80
+ version: 1,
81
+ files: [
82
+ { relativePath: 's1.jsonl', data: new TextEncoder().encode('one'), contentHash: OLD_HASH },
83
+ { relativePath: 's2.jsonl', data: new TextEncoder().encode('two'), contentHash: NEW_HASH },
84
+ ],
85
+ },
86
+ },
87
+ } as unknown as SyncSnapshot;
88
+ }
89
+
90
+ const callsOf = (calls: MockCall[], method: string, url: string): MockCall[] =>
91
+ calls.filter((c) => c.method === method && c.url === url);
92
+
93
+ /* ---------------- P6-1:删除顺序 ---------------- */
94
+
95
+ test('P6-1(删除路径):索引写回 412 → 快照文件零 DELETE(绝不留「索引指向已删对象」)', async () => {
96
+ const calls: MockCall[] = [];
97
+ const t = new WebDavTransport(makeOptions(recorder(calls, (m) => {
98
+ if (m.method === 'GET' && m.url === INDEX_URL) return res(200, JSON.stringify([META]), { etag: '"v1-del"' });
99
+ if (m.method === 'PUT' && m.url === INDEX_URL) return res(412, 'precondition failed');
100
+ if (m.method === 'DELETE' && m.url === SNAPSHOT_URL) return res(204, '');
101
+ return res(500, 'unexpected ' + m.method + ' ' + m.url);
102
+ })));
103
+
104
+ await assert.rejects(
105
+ () => t.delete('snap-001'),
106
+ (err: unknown) => {
107
+ assert.ok(err instanceof WebDavTransportError);
108
+ assert.equal(err.kind, 'conflict');
109
+ assert.equal(err.message, zhMsg('sync.webdav.concurrentWrite', { status: '412', url: INDEX_URL }));
110
+ return true;
111
+ },
112
+ );
113
+ assert.equal(callsOf(calls, 'DELETE', SNAPSHOT_URL).length, 0, '索引没写成功就绝不许删对象');
114
+ });
115
+
116
+ test('P6-1(删除路径):成功路径顺序 = 先条件写索引(If-Match),后 DELETE 快照对象', async () => {
117
+ const calls: MockCall[] = [];
118
+ const t = new WebDavTransport(makeOptions(recorder(calls, (m) => {
119
+ if (m.method === 'GET' && m.url === INDEX_URL) return res(200, JSON.stringify([META]), { etag: '"v1-del"' });
120
+ if (m.method === 'PUT' && m.url === INDEX_URL) return res(201, '');
121
+ if (m.method === 'DELETE' && m.url === SNAPSHOT_URL) return res(204, '');
122
+ if (m.method === 'GET' && m.url === BLOBS_INDEX_URL) return res(404, '');
123
+ return res(500, 'unexpected ' + m.method + ' ' + m.url);
124
+ })));
125
+
126
+ await t.delete('snap-001');
127
+
128
+ const puts = callsOf(calls, 'PUT', INDEX_URL);
129
+ assert.equal(puts.length, 1, '删除后写回一次索引');
130
+ assert.equal(puts[0]!.headers?.['If-Match'], '"v1-del"', '索引写回仍是条件写');
131
+ assert.equal(puts[0]!.body, '[]', '摘掉了目标条目');
132
+ const putAt = calls.findIndex((c) => c.method === 'PUT' && c.url === INDEX_URL);
133
+ const delAt = calls.findIndex((c) => c.method === 'DELETE' && c.url === SNAPSHOT_URL);
134
+ assert.ok(putAt >= 0 && delAt >= 0, '两条请求都必须发生');
135
+ assert.ok(putAt < delAt, '索引必须先落盘,再删对象(P6-1)');
136
+ });
137
+
138
+ test('P6-1(删除路径):索引无该 id 且对象存在 → 只删对象,不写回索引', async () => {
139
+ const calls: MockCall[] = [];
140
+ const t = new WebDavTransport(makeOptions(recorder(calls, (m) => {
141
+ if (m.method === 'GET' && m.url === INDEX_URL) return res(200, '[]', { etag: '"v1-del"' });
142
+ if (m.method === 'DELETE' && m.url === SNAPSHOT_URL) return res(204, '');
143
+ if (m.method === 'GET' && m.url === BLOBS_INDEX_URL) return res(404, '');
144
+ return res(500, 'unexpected ' + m.method + ' ' + m.url);
145
+ })));
146
+
147
+ await t.delete('snap-001');
148
+
149
+ assert.equal(callsOf(calls, 'PUT', INDEX_URL).length, 0, '索引无变化就不写回(N1③ 口径)');
150
+ assert.equal(callsOf(calls, 'DELETE', SNAPSHOT_URL).length, 1, '孤儿对象仍按用户意图删掉');
151
+ });
152
+
153
+ /* ---------------- P6-4:blob 索引三态读 ---------------- */
154
+
155
+ test('P6-4:blob 索引 GET 500 → 上传可重试失败,快照与 blobs-index 零写入', async () => {
156
+ const calls: MockCall[] = [];
157
+ const t = new WebDavTransport(makeOptions(recorder(calls, (m) => {
158
+ if (m.method === 'GET' && m.url === INDEX_URL) return res(200, '[]', { etag: '"v1"' });
159
+ if (m.method === 'MKCOL') return res(201, '');
160
+ if (m.method === 'GET' && m.url === BLOBS_INDEX_URL) return res(503, 'backend down');
161
+ if (m.method === 'PUT' && m.url === SNAPSHOT_URL) return res(201, '');
162
+ return res(500, 'unexpected ' + m.method + ' ' + m.url);
163
+ })));
164
+
165
+ await assert.rejects(
166
+ () => t.upload(sessionsSnapshot()),
167
+ (err: unknown) => {
168
+ assert.ok(err instanceof WebDavTransportError);
169
+ assert.equal(err.kind, 'server');
170
+ assert.equal(err.retryable, true, '读抖动属于可重试,不能报成不可恢复');
171
+ return true;
172
+ },
173
+ );
174
+ assert.equal(callsOf(calls, 'PUT', SNAPSHOT_URL).length, 0, '读不出来就零写入');
175
+ assert.equal(callsOf(calls, 'PUT', BLOBS_INDEX_URL).length, 0, '绝不整体覆盖');
176
+ });
177
+
178
+ test('P6-4:blob 索引 200 + 坏 JSON → protocol 错误,绝不覆盖成只有本次条目', async () => {
179
+ const calls: MockCall[] = [];
180
+ const t = new WebDavTransport(makeOptions(recorder(calls, (m) => {
181
+ if (m.method === 'GET' && m.url === INDEX_URL) return res(200, '[]', { etag: '"v1"' });
182
+ if (m.method === 'MKCOL') return res(201, '');
183
+ if (m.method === 'GET' && m.url === BLOBS_INDEX_URL) return res(200, '{not-json');
184
+ return res(500, 'unexpected ' + m.method + ' ' + m.url);
185
+ })));
186
+
187
+ await assert.rejects(
188
+ () => t.upload(sessionsSnapshot()),
189
+ (err: unknown) => {
190
+ assert.ok(err instanceof WebDavTransportError);
191
+ assert.equal(err.kind, 'protocol');
192
+ assert.equal(err.retryable, false);
193
+ return true;
194
+ },
195
+ );
196
+ assert.equal(callsOf(calls, 'PUT', BLOBS_INDEX_URL).length, 0);
197
+ });
198
+
199
+ test('P6-4:写回前再读 blobs-index 失败 → 绝不 PUT(已登记条目不得被覆盖掉)', async () => {
200
+ const calls: MockCall[] = [];
201
+ let blobIdxReads = 0;
202
+ const t = new WebDavTransport(makeOptions(recorder(calls, (m) => {
203
+ if (m.method === 'GET' && m.url === INDEX_URL) return res(200, '[]', { etag: '"v1"' });
204
+ if (m.method === 'MKCOL') return res(201, '');
205
+ if (m.method === 'GET' && m.url === BLOBS_INDEX_URL) {
206
+ blobIdxReads += 1;
207
+ // 第一次(externalize 跳过判定)成功:OLD_HASH 已登记 → 零传输;第二次(合并写回)抖动
208
+ return blobIdxReads === 1 ? res(200, JSON.stringify({ [OLD_HASH]: 1 })) : res(500, 'flaky');
209
+ }
210
+ if (m.method === 'PUT' && m.url === SNAPSHOT_URL) return res(201, '');
211
+ if (m.method === 'PUT' && m.url === INDEX_URL) return res(201, '');
212
+ if (m.method === 'PUT' && m.url === BLOBS_INDEX_URL) return res(201, '');
213
+ if (m.method === 'PUT' && m.url.startsWith(BLOBS_COL + '/')) return res(201, '');
214
+ return res(500, 'unexpected ' + m.method + ' ' + m.url);
215
+ })));
216
+
217
+ await assert.rejects(
218
+ () => t.upload(sessionsSnapshot()),
219
+ (err: unknown) => {
220
+ assert.ok(err instanceof WebDavTransportError);
221
+ assert.equal(err.kind, 'server');
222
+ return true;
223
+ },
224
+ );
225
+ assert.equal(blobIdxReads, 2, '跳过判定一次 + 合并写回一次');
226
+ assert.equal(callsOf(calls, 'PUT', BLOBS_INDEX_URL).length, 0, '读失败时绝不整体 PUT(P6-4 的核心)');
227
+ assert.equal(callsOf(calls, 'PUT', SNAPSHOT_URL).length, 1, '快照已落盘:本次 blob 漏登记只占空间,不误删');
228
+ });
229
+
230
+ test('P6-4:blob 索引 404(确实没有索引)→ 照常上传并新建索引', async () => {
231
+ const calls: MockCall[] = [];
232
+ const t = new WebDavTransport(makeOptions(recorder(calls, (m) => {
233
+ if (m.method === 'GET' && m.url === INDEX_URL) return res(200, '[]', { etag: '"v1"' });
234
+ if (m.method === 'MKCOL') return res(201, '');
235
+ if (m.method === 'GET' && m.url === BLOBS_INDEX_URL) return res(404, '');
236
+ if (m.method === 'PUT' && m.url === SNAPSHOT_URL) return res(201, '');
237
+ if (m.method === 'PUT' && m.url === INDEX_URL) return res(201, '');
238
+ if (m.method === 'PUT' && m.url === BLOBS_INDEX_URL) return res(201, '');
239
+ if (m.method === 'PUT' && m.url.startsWith(BLOBS_COL + '/')) return res(201, '');
240
+ return res(500, 'unexpected ' + m.method + ' ' + m.url);
241
+ })));
242
+
243
+ await t.upload(sessionsSnapshot());
244
+
245
+ const puts = callsOf(calls, 'PUT', BLOBS_INDEX_URL);
246
+ assert.equal(puts.length, 1, '缺资源 = 空是安全的,必须照常建索引');
247
+ const written = JSON.parse(puts[0]!.body ?? '{}') as Record<string, number>;
248
+ assert.deepEqual(Object.keys(written).sort(), [OLD_HASH, NEW_HASH].sort());
249
+ });
@@ -39,7 +39,7 @@ import { BLOB_SECTIONS, gcBlobs, isBlobRefsSection, isFilesSectionLike, referenc
39
39
  import type { BlobRefsSection, BlobSink } from '../blob-store.ts';
40
40
  import {
41
41
  classifyHttpStatus, classifyNetworkErrorText, computeSnapshotMeta, DEFAULT_SYNC_TIMEOUT_MS,
42
- isEncryptedSections, sectionsEqual, SyncTransportError, withSyncRetry,
42
+ isEncryptedSections, isPreconditionFailedStatus, sectionsEqual, SyncTransportError, withSyncRetry,
43
43
  } from '../transport.ts';
44
44
  import type { FilesSection, SectionData, SectionId } from '../../schema/types.ts';
45
45
  import type {
@@ -420,11 +420,15 @@ export class WebDavTransport implements SyncTransport {
420
420
  const merged = idxBefore.filter((m) => m.id !== snapshot.id);
421
421
  merged.push(meta);
422
422
  merged.sort((a, b) => (a.createdAt < b.createdAt ? -1 : a.createdAt > b.createdAt ? 1 : 0));
423
+ const idxHeaders = conditionalHeaders(idxEtag, indexMissing);
423
424
  const putIdx = await this.send('PUT', idxUrl, pwd, {
424
425
  body: JSON.stringify(merged),
425
- headers: conditionalHeaders(idxEtag, indexMissing),
426
+ headers: idxHeaders,
426
427
  });
427
- if (putIdx.status === 412) throw this.concurrentWrite(idxUrl, putIdx.status);
428
+ // 条件写失败判定与 s3 通道共用 transport.ts 的唯一实现(412 恒算;409 仅在真的带了条件头时算)
429
+ if (isPreconditionFailedStatus(putIdx.status, { guarded: Object.keys(idxHeaders).length > 0 })) {
430
+ throw this.concurrentWrite(idxUrl, putIdx.status);
431
+ }
428
432
  if (!putIdx.ok) {
429
433
  throw new WebDavTransportError(await this.failText('PUT', idxUrl, putIdx, pwd), classifyHttpStatus(putIdx.status));
430
434
  }
@@ -471,29 +475,46 @@ export class WebDavTransport implements SyncTransport {
471
475
  // gcBlobStore 以空引用集回收,删掉仍被现存快照文件引用的会话 blob(不可恢复)。
472
476
  // 与 F1 同口径:宁可显式失败,也不制造不可恢复的远端状态。list() 仍保留「404 = 空集合」语义。
473
477
  const { entries: idx, missing: indexMissing, etag: idxEtag } = await this.readIndexDetailed(pwd);
474
- // delete 快照文件:404 = 不存在,视为成功
475
478
  const url = this.snapshotUrl(id);
476
- const res = await this.send('DELETE', url, pwd);
477
- if (!res.ok && res.status !== 404) {
478
- throw new WebDavTransportError(await this.failText('DELETE', url, res, pwd), classifyHttpStatus(res.status));
479
+ if (indexMissing) {
480
+ // audit-sync sync-N1(P0):索引真缺失(404)= **缺信息**而不是「集合为空」。此时「哪些 blob
481
+ // 无人引用」无从证明 —— 一律**不写回 index.json、不触发 blob GC**,其余快照与其引用的 blob
482
+ // 原样保留(宁可留垃圾,不可删在用的)。目标快照文件按用户意图删除(404 视为成功)。
483
+ const res = await this.send('DELETE', url, pwd);
484
+ if (!res.ok && res.status !== 404) {
485
+ throw new WebDavTransportError(await this.failText('DELETE', url, res, pwd), classifyHttpStatus(res.status));
486
+ }
487
+ return;
479
488
  }
480
- // audit-sync sync-N1(P0):索引真缺失(404)= **缺信息**而不是「集合为空」。此时「哪些 blob
481
- // 无人引用」无从证明 —— 一律**不写回 index.json、不触发 blob GC**,其余快照与其引用的 blob
482
- // 原样保留(宁可留垃圾,不可删在用的)。目标快照文件已按用户意图删除(404 视为成功)。
483
- if (indexMissing) return;
484
- // 若 index 中无该 id,则无需写回
485
489
  const remaining = idx.filter((m) => m.id !== id);
486
- if (remaining.length === idx.length && res.status === 404) {
487
- return; // 文件与 index 都不存在 → 静默成功,无写回
490
+ const entryPresent = remaining.length !== idx.length;
491
+ // audit-sync sync-P6-1(P3):**先写索引、后删对象**。
492
+ // 反序(旧实现先 DELETE 快照文件)的伤害:索引 PUT 回 412(别的设备刚改过索引)时本次删除已
493
+ // 抛错中止,但对象已经没了 ⇒ 索引里留下指向不存在对象的条目;list() 不校验存在性,别的设备
494
+ // pull 到该 id 就是 notfound 硬失败,只能靠用户再删一次自愈。
495
+ // 调整顺序后的**最坏情况**:索引写成功而对象 DELETE 失败 ⇒ 远端留一个索引里不存在、list()
496
+ // 看不到、pull 不会命中的孤儿文件(只占空间);重跑 delete 会把对象补删(404 视为成功)。
497
+ // 「多一个看不见的孤儿文件」远轻于「索引指向已删对象」,因此顺序必须是索引在前。
498
+ if (entryPresent) {
499
+ const idxHeaders = conditionalHeaders(idxEtag, false);
500
+ const putIdx = await this.send('PUT', idxUrl, pwd, {
501
+ body: JSON.stringify(remaining),
502
+ headers: idxHeaders,
503
+ });
504
+ // 判定与 s3 通道共用同一实现(412 恒算;409 仅在真的带了条件头时算)
505
+ if (isPreconditionFailedStatus(putIdx.status, { guarded: Object.keys(idxHeaders).length > 0 })) {
506
+ throw this.concurrentWrite(idxUrl, putIdx.status);
507
+ }
508
+ if (!putIdx.ok) {
509
+ throw new WebDavTransportError(await this.failText('PUT', idxUrl, putIdx, pwd), classifyHttpStatus(putIdx.status));
510
+ }
488
511
  }
489
- const putIdx = await this.send('PUT', idxUrl, pwd, {
490
- body: JSON.stringify(remaining),
491
- headers: conditionalHeaders(idxEtag, false),
492
- });
493
- if (putIdx.status === 412) throw this.concurrentWrite(idxUrl, putIdx.status);
494
- if (!putIdx.ok) {
495
- throw new WebDavTransportError(await this.failText('PUT', idxUrl, putIdx, pwd), classifyHttpStatus(putIdx.status));
512
+ // 索引已摘除(或本来就无该 id)后才动对象:404 = 不存在,视为成功
513
+ const res = await this.send('DELETE', url, pwd);
514
+ if (!res.ok && res.status !== 404) {
515
+ throw new WebDavTransportError(await this.failText('DELETE', url, res, pwd), classifyHttpStatus(res.status));
496
516
  }
517
+ if (!entryPresent && !res.ok) return; // 索引无该 id 且对象本就不存在 → 静默成功,无 GC 可做
497
518
  // P1-4:快照被裁掉后回收无人引用的 blob(best-effort,失败不影响删除结果)
498
519
  await this.gcBlobStore(pwd, remaining).catch(() => undefined);
499
520
  }
@@ -528,7 +549,10 @@ export class WebDavTransport implements SyncTransport {
528
549
  }
529
550
  }
530
551
 
531
- /** 把本次新写入的 blob 合并进远端索引(写失败 → 抛错,调用方看到的是上传失败而非静默漏记)。 */
552
+ /**
553
+ * 把本次新写入的 blob 合并进远端索引(写失败 → 抛错,调用方看到的是上传失败而非静默漏记)。
554
+ * audit-sync sync-P6-4(P3):这里的读失败必须上抛 —— 整体 PUT 会覆盖远端已登记条目。
555
+ */
532
556
  private async appendBlobIndex(fresh: Map<string, number>, pwd: string): Promise<void> {
533
557
  const index = await this.readBlobIndex(pwd);
534
558
  for (const [hash, at] of fresh) index[hash] = at;
@@ -567,23 +591,51 @@ export class WebDavTransport implements SyncTransport {
567
591
  }
568
592
  }
569
593
 
570
- /** 读取 blob 索引(哈希 → 写入时间 ms);缺失/损坏 → 空(GC 只会「少删」,不会误删)。 */
594
+ /** 读取 blob 索引(哈希 → 写入时间 ms);只读失败即抛,绝不回落成空索引,见 readBlobIndexDetailed。 */
571
595
  private async readBlobIndex(pwd: string): Promise<Record<string, number>> {
596
+ return (await this.readBlobIndexDetailed(pwd)).index;
597
+ }
598
+
599
+ /**
600
+ * audit-sync sync-P6-4(P3):读 blob 索引的**带缺失标志**版本 —— 「读失败」与「确实没有索引」必须分开。
601
+ *
602
+ * 旧实现把 5xx / 坏 JSON / 非法结构一律当成空索引返回,紧接着 appendBlobIndex 读→合并→**整体 PUT**,
603
+ * 于是「一次读抖动」= 远端索引被覆盖成本次新增的那几条,已登记条目全丢(GC 从此看不见这些 blob,
604
+ * 等于远端漏账;再叠加 delete 的 GC 就可能删掉它们)。语义因此必须三态:
605
+ * - 404 / 405 / 501 → missing = true:**缺资源**。405/501 是部分 WebDAV 服务端表达「没有这个资源」
606
+ * 的方言(与 remoteHasPriorContent 同口径),此时确实没有索引可丢,按空处理是安全的;
607
+ * - 其它非 2xx(5xx / 403 / …)→ 抛错(可重试):读不出来就**不许**整体覆盖,让上传显式失败;
608
+ * - 200 但坏 JSON / 非对象 → 抛 protocol(不可重试):索引损坏是远端状态问题,覆盖写会抹掉残存记录。
609
+ *
610
+ * 最坏情况(可重试失败):本可跳过的 blob 被重传一遍,或本次 blob 漏登记(只占空间,不误删)。
611
+ */
612
+ private async readBlobIndexDetailed(pwd: string): Promise<{ index: Record<string, number>; missing: boolean }> {
572
613
  const url = this.blobsIndexUrl();
573
614
  const res = await this.send('GET', url, pwd);
574
- if (res.status === 404) return {};
575
- if (!res.ok) return {};
615
+ if (res.status === 404 || res.status === 405 || res.status === 501) return { index: {}, missing: true };
616
+ if (!res.ok) {
617
+ throw new WebDavTransportError(await this.failText('GET', url, res, pwd), classifyHttpStatus(res.status));
618
+ }
619
+ let parsed: unknown;
576
620
  try {
577
- const parsed = parseJsonSafe(await res.text());
578
- if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return {};
579
- const out: Record<string, number> = {};
580
- for (const [hash, at] of Object.entries(parsed as Record<string, unknown>)) {
581
- if (BLOB_HASH_RE.test(hash) && typeof at === 'number' && Number.isFinite(at)) out[hash] = at;
582
- }
583
- return out;
584
- } catch {
585
- return {};
621
+ parsed = parseJsonSafe(await res.text());
622
+ } catch (err) {
623
+ throw new WebDavTransportError(
624
+ this.o.msg('sync.webdav.indexInvalid', { url, err: this.mask(String((err as Error)?.message ?? ''), pwd) }),
625
+ { kind: 'protocol', retryable: false },
626
+ );
627
+ }
628
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
629
+ throw new WebDavTransportError(
630
+ this.o.msg('sync.webdav.indexInvalid', { url, err: 'not an object' }),
631
+ { kind: 'protocol', retryable: false },
632
+ );
633
+ }
634
+ const out: Record<string, number> = {};
635
+ for (const [hash, at] of Object.entries(parsed as Record<string, unknown>)) {
636
+ if (BLOB_HASH_RE.test(hash) && typeof at === 'number' && Number.isFinite(at)) out[hash] = at;
586
637
  }
638
+ return { index: out, missing: false };
587
639
  }
588
640
 
589
641
  private async writeBlobIndex(pwd: string, index: Record<string, number>): Promise<void> {
@@ -30,14 +30,21 @@ export interface GranularMergeOutcome {
30
30
  conflicts: MergeConflict[];
31
31
  /** 自动并入的变更点(口径 = 用户能感知的「两侧各自的改动都保住了」处数) */
32
32
  mergePoints: number;
33
+ /** 远端删了、但按开关保留在本机的条目键(`plugins.<name>` / `patch.<file>#<lineId>` …) */
33
34
  }
34
35
 
35
36
  /**
36
- * 钩子可读的合并上下文:目前只有 plugins 需要 —— 「跟随远端删除插件」是用户开关,
37
- * 关着时钩子必须**不参与**(交给通用路径 = 与未引入 #132 前逐字一致),否则会静默丢掉本机条目。
37
+ * 钩子可读的合并上下文(只放「用户开关」与「本进程事实」,不放会让钩子做出猜测的东西)。
38
+ *
39
+ * issue #145 起两者分工固定:
40
+ * - 合并**恒参与**(开关不再决定钩子是否介入,否则 patch 行这类与卸载无关的改动永远合不进去);
41
+ * - `deletePlugins` 只管「远端删了、本机未改的条目要不要真的删掉」;
42
+ * - `selfPluginName` 让 plugins 钩子排除自身(自身条目永不删、不报冲突)。
38
43
  */
39
44
  export interface GranularMergeHooks {
40
45
  deletePlugins?: boolean;
46
+ /** 本插件的包名(空串 / 缺省 = 不知道,不排除任何条目)。 */
47
+ selfPluginName?: string;
41
48
  }
42
49
 
43
50
  /** 记录级合并钩子签名(`merge.ts` 按分区 id 调用;返回 undefined = 不参与,走通用路径)。 */
@@ -68,7 +68,7 @@ export interface ArtifactInput {
68
68
  /** 远端当前基线(sync-state.lastSnapshotId);命中即标「当前基线」。未知/缺省 = 不标 */
69
69
  remoteCurrentId?: string | null
70
70
  /** 远端通道类型(元数据行第 1 段)。未知 = 该段不渲染(不猜成 Git) */
71
- remoteChannel?: 'git' | 'webdav' | null
71
+ remoteChannel?: 'git' | 'webdav' | 's3' | 'gist' | null
72
72
  marketItems?: readonly MarketItemInput[]
73
73
  }
74
74
 
@@ -70,6 +70,17 @@ test('关键词命中(同义说法)', () => {
70
70
  assert.ok(ids(filterCommands(COMMANDS, 'webdav', titleOf, ctx())).includes('go.sync'))
71
71
  })
72
72
 
73
+ test('关键词命中:四个同步通道都能搜到「同步」(P10-1:手写镜像漏过 s3/gist)', () => {
74
+ // 镜像只抄了 git/webdav 两通道时,搜 s3 或 gist 一条「同步」命令都不出现 ——
75
+ // 现在关键词从 SYNC_CHANNELS 派生(唯一事实源在 utils/shared-constants.ts)。
76
+ for (const channel of ['git', 'webdav', 's3', 'gist']) {
77
+ assert.ok(
78
+ ids(filterCommands(COMMANDS, channel, titleOf, ctx())).includes('go.sync'),
79
+ '搜 ' + channel + ' 必须命中 go.sync',
80
+ )
81
+ }
82
+ })
83
+
73
84
  test('关键词命中:口语「磁盘」直达维护与诊断、「恢复」直达事故恢复', () => {
74
85
  assert.ok(ids(filterCommands(COMMANDS, '磁盘', titleOf, ctx())).includes('maintenance.open'))
75
86
  assert.ok(ids(filterCommands(COMMANDS, '恢复', titleOf, ctx())).includes('recovery.open'))
@@ -12,19 +12,10 @@
12
12
  * 中文用户敲「导出」命中标题,英文用户敲 "export" 命中 id。
13
13
  */
14
14
 
15
- // 只导入**类型**:type-only import 在编译期被擦除,不会把 src/sync 的运行时依赖带进 client bundle。
16
- import type { SyncTransportType } from '../sync/sync-config.ts'
17
-
18
- /**
19
- * 通道搜索词 = **受守卫的客户端镜像**。
20
- *
21
- * 为什么必须写成这个形状:t32 源码守卫(`src/sync/sync-config.test.ts`)把「两个通道名的
22
- * 字面量相邻出现」视为第二处通道枚举声明(历史上一模一样的两份数组漏改过一份,导致某通道
23
- * 永不排期),只有带 `satisfies` 穷尽标记的客户端镜像才放行。**连注释里都不许把这两个名字
24
- * 写成相邻的带引号字面量** —— 守卫扫的是文本,不区分代码与注释。
25
- * 写成搜索关键词也一样要守这条规矩 —— 守卫认的是形状,不是用途。
26
- */
27
- const SYNC_CHANNEL_TERMS = ['git', 'webdav'] satisfies readonly SyncTransportType[]
15
+ // 通道搜索词只认**唯一事实源** `SYNC_CHANNELS`(`src/utils/shared-constants.ts`,零依赖,
16
+ // client 侧已有多处运行时 import 先例)。这里绝不再抄一份清单:手写镜像漏过 s3/gist,
17
+ // 结果搜这两个通道名时「同步」一条命令都不出现(审计 P10-1)。通道增删时这里自动跟随。
18
+ import { SYNC_CHANNELS } from '../utils/shared-constants.ts'
28
19
 
29
20
  /** 命令分组(渲染顺序见 `COMMAND_GROUP_ORDER`)。 */
30
21
  export type CommandGroup = 'navigate' | 'library' | 'action' | 'view' | 'rescue'
@@ -92,7 +83,7 @@ export const COMMANDS: readonly CommandItem[] = [
92
83
  // —— 前往:四个一级页面(v3 §3.1;市场不再是页面)——
93
84
  { id: 'go.home', group: 'navigate', titleKey: 'nav.home', keywords: ['home', 'overview', '首页', '总览'] },
94
85
  { id: 'go.library', group: 'navigate', titleKey: 'library.title', keywords: ['library', 'artifact', '产物', '快照'] },
95
- { id: 'go.sync', group: 'navigate', titleKey: 'nav.sync', keywords: ['sync', ...SYNC_CHANNEL_TERMS, '同步'] },
86
+ { id: 'go.sync', group: 'navigate', titleKey: 'nav.sync', keywords: ['sync', ...SYNC_CHANNELS, '同步'] },
96
87
  {
97
88
  // 环境 = 档案 + 维护与诊断。文案用导航条上的名字(environment.title),
98
89
  // 不用旧的 nav.profiles('档案')—— 面板里找不到「档案」这个页面。