@narumitw/pi-sync 0.58.1 → 0.60.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 (334) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +28 -15
  3. package/dist/chunks/{chunk-AMJRUXFT.ts → chunk-2JNFEZ3V.ts} +2 -6
  4. package/dist/chunks/{chunk-AMJRUXFT.ts.map → chunk-2JNFEZ3V.ts.map} +1 -1
  5. package/dist/chunks/{chunk-MG66XM5U.ts → chunk-4RNCZZY7.ts} +86 -36
  6. package/dist/chunks/chunk-4RNCZZY7.ts.map +7 -0
  7. package/dist/chunks/{config-HYG7G5EM.ts → chunk-7AC2RX4M.ts} +6 -12
  8. package/dist/chunks/chunk-7AC2RX4M.ts.map +7 -0
  9. package/dist/chunks/{chunk-XEODG2PE.ts → chunk-BGGKHHO4.ts} +18 -14
  10. package/dist/chunks/{chunk-XEODG2PE.ts.map → chunk-BGGKHHO4.ts.map} +1 -1
  11. package/dist/chunks/chunk-BWWTOQOW.ts +737 -0
  12. package/dist/chunks/chunk-BWWTOQOW.ts.map +7 -0
  13. package/dist/chunks/chunk-CEMFCWIU.ts +20 -0
  14. package/dist/chunks/chunk-CEMFCWIU.ts.map +7 -0
  15. package/dist/chunks/chunk-CZNBKIM5.ts +20 -0
  16. package/dist/chunks/chunk-CZNBKIM5.ts.map +7 -0
  17. package/dist/chunks/{chunk-YIPK23JW.ts → chunk-ENFHHB5O.ts} +1 -16
  18. package/dist/chunks/{chunk-YIPK23JW.ts.map → chunk-ENFHHB5O.ts.map} +1 -1
  19. package/dist/chunks/{chunk-KHBPED6W.ts → chunk-GSQGBVKG.ts} +2 -2
  20. package/dist/chunks/chunk-HNKLBM3U.ts +18 -0
  21. package/dist/chunks/chunk-HNKLBM3U.ts.map +7 -0
  22. package/dist/chunks/{chunk-QPC5HT3A.ts → chunk-J5COV5TY.ts} +21 -2
  23. package/dist/chunks/chunk-J5COV5TY.ts.map +7 -0
  24. package/dist/chunks/chunk-JKBUYCPC.ts +52 -0
  25. package/dist/chunks/chunk-JKBUYCPC.ts.map +7 -0
  26. package/dist/chunks/chunk-JZKCOM62.ts +26 -0
  27. package/dist/chunks/chunk-JZKCOM62.ts.map +7 -0
  28. package/dist/chunks/chunk-M7RHV3H6.ts +33 -0
  29. package/dist/chunks/chunk-M7RHV3H6.ts.map +7 -0
  30. package/dist/chunks/{chunk-REMGB255.ts → chunk-MIXZVHFR.ts} +35 -10
  31. package/dist/chunks/chunk-MIXZVHFR.ts.map +7 -0
  32. package/dist/chunks/chunk-NPT2G4FU.ts +15 -0
  33. package/dist/chunks/chunk-NPT2G4FU.ts.map +7 -0
  34. package/dist/chunks/chunk-PDBTD2K6.ts +11 -0
  35. package/dist/chunks/chunk-PDBTD2K6.ts.map +7 -0
  36. package/dist/chunks/chunk-UBE6XWOM.ts +29 -0
  37. package/dist/chunks/chunk-UBE6XWOM.ts.map +7 -0
  38. package/dist/chunks/{chunk-JYILGR3K.ts → chunk-UZUUUY7C.ts} +8 -8
  39. package/dist/chunks/chunk-VZCWYXRS.ts +23 -0
  40. package/dist/chunks/chunk-VZCWYXRS.ts.map +7 -0
  41. package/dist/chunks/{chunk-U6GXGY5G.ts → chunk-YWEYRRQI.ts} +45 -37
  42. package/dist/chunks/chunk-YWEYRRQI.ts.map +7 -0
  43. package/dist/chunks/{chunk-ECYCNZOE.ts → chunk-ZMNVNECV.ts} +5 -1
  44. package/dist/chunks/chunk-ZMNVNECV.ts.map +7 -0
  45. package/dist/chunks/{command-handler-MRXE5AKK.ts → command-handler-3O76V7Q5.ts} +83 -87
  46. package/dist/chunks/command-handler-3O76V7Q5.ts.map +7 -0
  47. package/dist/chunks/conflict-review-XBSME2ER.ts +18 -0
  48. package/dist/chunks/conflict-review-XBSME2ER.ts.map +7 -0
  49. package/dist/chunks/{continuous-record-EPHGR2DU.ts → continuous-record-ZHUXVO4E.ts} +5 -13
  50. package/dist/chunks/continuous-record-ZHUXVO4E.ts.map +7 -0
  51. package/dist/chunks/{file-selection-IELTXSGZ.ts → file-selection-S6CNNNQI.ts} +14 -14
  52. package/dist/chunks/file-selection-S6CNNNQI.ts.map +7 -0
  53. package/dist/chunks/manager-result-dispatcher-I2AMCCE7.ts +18 -0
  54. package/dist/chunks/{manager-ui-AY34N4UY.ts → manager-ui-SJOBTJLY.ts} +221 -147
  55. package/dist/chunks/manager-ui-SJOBTJLY.ts.map +7 -0
  56. package/dist/chunks/merge-review-SGDLMVS4.ts +10 -0
  57. package/dist/chunks/remote-selection-ui-GZHPDQ4L.ts +17 -0
  58. package/dist/chunks/{setup-switch-KLGESLQX.ts → setup-switch-M3BAFGJM.ts} +9 -12
  59. package/dist/chunks/{setup-wizard-ZQAK35BP.ts → setup-wizard-NFAWP4KF.ts} +18 -20
  60. package/dist/chunks/{setup-wizard-ZQAK35BP.ts.map → setup-wizard-NFAWP4KF.ts.map} +1 -1
  61. package/dist/chunks/{snapshot-RGNDYT6A.ts → snapshot-D4SFDP5J.ts} +8 -12
  62. package/dist/chunks/snapshot-D4SFDP5J.ts.map +7 -0
  63. package/dist/chunks/snapshot-transaction-directory-TNKBQ3UQ.ts +13 -0
  64. package/dist/chunks/snapshot-transaction-directory-TNKBQ3UQ.ts.map +7 -0
  65. package/dist/chunks/state-directory-JZSZVVPX.ts +17 -0
  66. package/dist/chunks/sync-inspection-BJ4KPPNO.ts +23 -0
  67. package/dist/chunks/sync-inspection-BJ4KPPNO.ts.map +7 -0
  68. package/dist/chunks/sync-operations-TLWER2TT.ts +45 -0
  69. package/dist/chunks/sync-operations-TLWER2TT.ts.map +7 -0
  70. package/dist/chunks/{sync-state-7L4NT7W2.ts → sync-state-FVCJJ7MY.ts} +5 -10
  71. package/dist/chunks/sync-state-FVCJJ7MY.ts.map +7 -0
  72. package/dist/index.ts +269 -306
  73. package/dist/index.ts.map +4 -4
  74. package/docs/daemon-migration.md +93 -0
  75. package/docs/exclude-policy-audit.md +54 -0
  76. package/docs/exclude-review-ledger.md +36 -0
  77. package/docs/tui-contract.md +1 -1
  78. package/package.json +3 -5
  79. package/skills/configure-pi-sync/SKILL.md +5 -4
  80. package/skills/configure-pi-sync/references/configuration.md +91 -19
  81. package/src/backends/backend-factory.ts +2 -23
  82. package/src/backends/backend-identity.ts +5 -40
  83. package/src/backends/backend-types.ts +1 -81
  84. package/src/backends/git/git-backend.ts +6 -784
  85. package/src/backends/git/git-config.ts +8 -130
  86. package/src/backends/git/git-runner.ts +7 -255
  87. package/src/backends/git/git-storage.ts +14 -292
  88. package/src/backends/s3/s3-backend.ts +11 -523
  89. package/src/backends/s3/s3-client.ts +2 -399
  90. package/src/backends/s3/s3-conditions.ts +2 -67
  91. package/src/backends/snapshot-pointer.ts +2 -27
  92. package/src/backends/sync-backend.ts +6 -101
  93. package/src/backends/webdav/webdav-backend.ts +10 -622
  94. package/src/backends/webdav/webdav-client.ts +6 -370
  95. package/src/backends/webdav/webdav-config.ts +8 -82
  96. package/src/commands/command-execution.ts +42 -38
  97. package/src/commands/command.ts +23 -1
  98. package/src/daemon/apply-gate.ts +146 -0
  99. package/src/daemon/pi-client.ts +591 -0
  100. package/src/daemon/recovery.ts +103 -0
  101. package/src/paths.ts +12 -83
  102. package/src/settings/config-errors.ts +2 -6
  103. package/src/settings/config-file.ts +19 -693
  104. package/src/settings/config.ts +16 -257
  105. package/src/settings/settings-management.ts +11 -253
  106. package/src/settings/settings-store.ts +10 -48
  107. package/src/settings/settings-types.ts +1 -154
  108. package/src/settings/settings-validation.ts +17 -431
  109. package/src/snapshot/session-paths.ts +11 -110
  110. package/src/snapshot/snapshot-apply.ts +9 -306
  111. package/src/snapshot/snapshot-case-replacement.ts +6 -80
  112. package/src/snapshot/snapshot-codec.ts +2 -50
  113. package/src/snapshot/snapshot-exclude-safety.ts +2 -0
  114. package/src/snapshot/snapshot-mutation-queues.ts +6 -142
  115. package/src/snapshot/snapshot-paths.ts +2 -11
  116. package/src/snapshot/snapshot-root-transition.ts +6 -154
  117. package/src/snapshot/snapshot-transaction-directory.ts +5 -16
  118. package/src/snapshot/snapshot-transaction-plan.ts +2 -72
  119. package/src/snapshot/snapshot-transaction.ts +6 -934
  120. package/src/snapshot/snapshot-types.ts +1 -43
  121. package/src/snapshot/snapshot.ts +18 -405
  122. package/src/state/json-file.ts +2 -47
  123. package/src/state/lock-policy.ts +2 -2
  124. package/src/state/lock.ts +10 -292
  125. package/src/state/lockfile-fs.ts +2 -25
  126. package/src/state/merge-baseline-store.ts +8 -200
  127. package/src/state/mutation-directory-sync.ts +2 -34
  128. package/src/state/operation-availability.ts +7 -59
  129. package/src/state/state-directory.ts +8 -243
  130. package/src/state/state-types.ts +1 -24
  131. package/src/state/sync-state-store.ts +11 -75
  132. package/src/sync/agent-candidate.ts +7 -256
  133. package/src/sync/agent-plan.ts +2 -107
  134. package/src/sync/agent-policy.ts +10 -13
  135. package/src/sync/agent-refusal-retry.ts +2 -54
  136. package/src/sync/agent-request.ts +2 -19
  137. package/src/sync/agent-runner.ts +2 -191
  138. package/src/sync/agent-store.ts +7 -182
  139. package/src/sync/agent-sync.ts +2 -141
  140. package/src/sync/apply-review.ts +2 -63
  141. package/src/sync/automatic-sync.ts +55 -106
  142. package/src/sync/conflict-artifact-ownership.ts +2 -63
  143. package/src/sync/conflict-artifacts.ts +8 -195
  144. package/src/sync/conflict-groups.ts +2 -68
  145. package/src/sync/conflict-preview.ts +2 -56
  146. package/src/sync/conflict-resolution.ts +2 -93
  147. package/src/sync/conflict-retention.ts +2 -72
  148. package/src/sync/conflict-review.ts +3 -92
  149. package/src/sync/content-conflicts.ts +2 -73
  150. package/src/sync/continuous-errors.ts +7 -85
  151. package/src/sync/continuous-lease.ts +2 -216
  152. package/src/sync/continuous-record.ts +10 -261
  153. package/src/sync/continuous-storage.ts +12 -64
  154. package/src/sync/continuous-sync.ts +2 -563
  155. package/src/sync/continuous-watch.ts +2 -59
  156. package/src/sync/exclude-policy.ts +6 -0
  157. package/src/sync/field-migration.ts +2 -39
  158. package/src/sync/file-merge-planner.ts +2 -143
  159. package/src/sync/json-document.ts +7 -184
  160. package/src/sync/local-field-policy.ts +2 -29
  161. package/src/sync/local-fields.ts +9 -108
  162. package/src/sync/merge-apply.ts +2 -434
  163. package/src/sync/merge-journal.ts +10 -219
  164. package/src/sync/merge-transfer-error.ts +2 -72
  165. package/src/sync/merged-sync.ts +2 -914
  166. package/src/sync/mutation-owner.ts +2 -22
  167. package/src/sync/package-merge.ts +2 -87
  168. package/src/sync/partial-progress.ts +2 -54
  169. package/src/sync/remote-snapshot.ts +7 -80
  170. package/src/sync/session-merge.ts +2 -194
  171. package/src/sync/settings-conflicts.ts +2 -64
  172. package/src/sync/settings-merge.ts +6 -121
  173. package/src/sync/signals.ts +2 -8
  174. package/src/sync/startup-check.ts +15 -31
  175. package/src/sync/startup-timings.ts +2 -94
  176. package/src/sync/sync-decision.ts +3 -101
  177. package/src/sync/sync-error-guidance.ts +2 -46
  178. package/src/sync/sync-errors.ts +7 -23
  179. package/src/sync/sync-inspection.ts +10 -57
  180. package/src/sync/sync-local.ts +2 -44
  181. package/src/sync/sync-mutations.ts +10 -781
  182. package/src/sync/sync-operations.ts +32 -11
  183. package/src/sync/sync-policy.ts +34 -410
  184. package/src/sync/sync-queries.ts +2 -237
  185. package/src/sync/sync-state.ts +18 -151
  186. package/src/sync/text-merge.ts +10 -133
  187. package/src/sync-extension.ts +192 -142
  188. package/src/ui/excluded-paths-ui.ts +106 -0
  189. package/src/ui/file-selection.ts +6 -3
  190. package/src/ui/manager-state.ts +11 -5
  191. package/src/ui/remote-selection-ui.ts +73 -10
  192. package/src/ui/settings-ui.ts +20 -5
  193. package/src/ui/setup/setup-actions.ts +1 -1
  194. package/src/ui/setup/setup-switcher.ts +3 -2
  195. package/src/ui/storage-connections-ui.ts +2 -2
  196. package/src/ui/sync-attention.ts +17 -3
  197. package/src/ui/sync-format.ts +13 -1
  198. package/dist/chunks/agent-candidate-U2NU3GUX.ts +0 -29
  199. package/dist/chunks/agent-plan-3YXDIJXO.ts +0 -123
  200. package/dist/chunks/agent-plan-3YXDIJXO.ts.map +0 -7
  201. package/dist/chunks/agent-refusal-retry-476YGNU5.ts +0 -72
  202. package/dist/chunks/agent-refusal-retry-476YGNU5.ts.map +0 -7
  203. package/dist/chunks/agent-runner-FCRV2Z75.ts +0 -185
  204. package/dist/chunks/agent-runner-FCRV2Z75.ts.map +0 -7
  205. package/dist/chunks/agent-store-7GINKTS7.ts +0 -175
  206. package/dist/chunks/agent-store-7GINKTS7.ts.map +0 -7
  207. package/dist/chunks/agent-sync-2R4GG2MF.ts +0 -22
  208. package/dist/chunks/chunk-2JZFHNLM.ts +0 -113
  209. package/dist/chunks/chunk-2JZFHNLM.ts.map +0 -7
  210. package/dist/chunks/chunk-3ST7RSYN.ts +0 -21
  211. package/dist/chunks/chunk-3ST7RSYN.ts.map +0 -7
  212. package/dist/chunks/chunk-45COPAK7.ts +0 -205
  213. package/dist/chunks/chunk-45COPAK7.ts.map +0 -7
  214. package/dist/chunks/chunk-5SFMBY5P.ts +0 -26
  215. package/dist/chunks/chunk-5SFMBY5P.ts.map +0 -7
  216. package/dist/chunks/chunk-5TSCBBPP.ts +0 -229
  217. package/dist/chunks/chunk-5TSCBBPP.ts.map +0 -7
  218. package/dist/chunks/chunk-6LD5KX55.ts +0 -396
  219. package/dist/chunks/chunk-6LD5KX55.ts.map +0 -7
  220. package/dist/chunks/chunk-6O3EDBRL.ts +0 -258
  221. package/dist/chunks/chunk-6O3EDBRL.ts.map +0 -7
  222. package/dist/chunks/chunk-7A35ZAVO.ts +0 -1109
  223. package/dist/chunks/chunk-7A35ZAVO.ts.map +0 -7
  224. package/dist/chunks/chunk-7D5SF7P3.ts +0 -29
  225. package/dist/chunks/chunk-7D5SF7P3.ts.map +0 -7
  226. package/dist/chunks/chunk-7ZIYU5QS.ts +0 -64
  227. package/dist/chunks/chunk-7ZIYU5QS.ts.map +0 -7
  228. package/dist/chunks/chunk-AKMV47YC.ts +0 -215
  229. package/dist/chunks/chunk-AKMV47YC.ts.map +0 -7
  230. package/dist/chunks/chunk-AR2DGDUI.ts +0 -55
  231. package/dist/chunks/chunk-AR2DGDUI.ts.map +0 -7
  232. package/dist/chunks/chunk-BEST45H2.ts +0 -153
  233. package/dist/chunks/chunk-BEST45H2.ts.map +0 -7
  234. package/dist/chunks/chunk-CBLTWXAU.ts +0 -114
  235. package/dist/chunks/chunk-CBLTWXAU.ts.map +0 -7
  236. package/dist/chunks/chunk-CQD2TJHE.ts +0 -220
  237. package/dist/chunks/chunk-CQD2TJHE.ts.map +0 -7
  238. package/dist/chunks/chunk-DN4IA7MR.ts +0 -61
  239. package/dist/chunks/chunk-DN4IA7MR.ts.map +0 -7
  240. package/dist/chunks/chunk-DT7M4VQS.ts +0 -69
  241. package/dist/chunks/chunk-DT7M4VQS.ts.map +0 -7
  242. package/dist/chunks/chunk-ECYCNZOE.ts.map +0 -7
  243. package/dist/chunks/chunk-ESKOPQVB.ts +0 -348
  244. package/dist/chunks/chunk-ESKOPQVB.ts.map +0 -7
  245. package/dist/chunks/chunk-FHE2DCA2.ts +0 -61
  246. package/dist/chunks/chunk-FHE2DCA2.ts.map +0 -7
  247. package/dist/chunks/chunk-FLHCOJCD.ts +0 -57
  248. package/dist/chunks/chunk-FLHCOJCD.ts.map +0 -7
  249. package/dist/chunks/chunk-G4RUXRWZ.ts +0 -48
  250. package/dist/chunks/chunk-G4RUXRWZ.ts.map +0 -7
  251. package/dist/chunks/chunk-GNYGNHFF.ts +0 -27
  252. package/dist/chunks/chunk-GNYGNHFF.ts.map +0 -7
  253. package/dist/chunks/chunk-KYTT7KV4.ts +0 -319
  254. package/dist/chunks/chunk-KYTT7KV4.ts.map +0 -7
  255. package/dist/chunks/chunk-M6VQJIOU.ts +0 -54
  256. package/dist/chunks/chunk-M6VQJIOU.ts.map +0 -7
  257. package/dist/chunks/chunk-MG66XM5U.ts.map +0 -7
  258. package/dist/chunks/chunk-MKSMJPVA.ts +0 -107
  259. package/dist/chunks/chunk-MKSMJPVA.ts.map +0 -7
  260. package/dist/chunks/chunk-MMQIEDZ6.ts +0 -1994
  261. package/dist/chunks/chunk-MMQIEDZ6.ts.map +0 -7
  262. package/dist/chunks/chunk-OJARL2TG.ts +0 -25
  263. package/dist/chunks/chunk-OJARL2TG.ts.map +0 -7
  264. package/dist/chunks/chunk-OVBAW7KV.ts +0 -1174
  265. package/dist/chunks/chunk-OVBAW7KV.ts.map +0 -7
  266. package/dist/chunks/chunk-PRUEIIK7.ts +0 -24
  267. package/dist/chunks/chunk-PRUEIIK7.ts.map +0 -7
  268. package/dist/chunks/chunk-PWMWOJP4.ts +0 -17
  269. package/dist/chunks/chunk-PWMWOJP4.ts.map +0 -7
  270. package/dist/chunks/chunk-QPC5HT3A.ts.map +0 -7
  271. package/dist/chunks/chunk-REMGB255.ts.map +0 -7
  272. package/dist/chunks/chunk-S5OCYVPS.ts +0 -415
  273. package/dist/chunks/chunk-S5OCYVPS.ts.map +0 -7
  274. package/dist/chunks/chunk-SWRVXVFD.ts +0 -248
  275. package/dist/chunks/chunk-SWRVXVFD.ts.map +0 -7
  276. package/dist/chunks/chunk-T2SJD3N7.ts +0 -99
  277. package/dist/chunks/chunk-T2SJD3N7.ts.map +0 -7
  278. package/dist/chunks/chunk-TIMWN2RH.ts +0 -89
  279. package/dist/chunks/chunk-TIMWN2RH.ts.map +0 -7
  280. package/dist/chunks/chunk-TZC7GDJE.ts +0 -58
  281. package/dist/chunks/chunk-TZC7GDJE.ts.map +0 -7
  282. package/dist/chunks/chunk-U6GXGY5G.ts.map +0 -7
  283. package/dist/chunks/chunk-WQMYV4DW.ts +0 -140
  284. package/dist/chunks/chunk-WQMYV4DW.ts.map +0 -7
  285. package/dist/chunks/chunk-X7R6DCVF.ts +0 -28
  286. package/dist/chunks/chunk-X7R6DCVF.ts.map +0 -7
  287. package/dist/chunks/chunk-XJHQPB3E.ts +0 -107
  288. package/dist/chunks/chunk-XJHQPB3E.ts.map +0 -7
  289. package/dist/chunks/chunk-Y4UVXOLQ.ts +0 -123
  290. package/dist/chunks/chunk-Y4UVXOLQ.ts.map +0 -7
  291. package/dist/chunks/chunk-YDVQYUHE.ts +0 -34
  292. package/dist/chunks/chunk-YDVQYUHE.ts.map +0 -7
  293. package/dist/chunks/chunk-YHT4YTYG.ts +0 -31
  294. package/dist/chunks/chunk-YHT4YTYG.ts.map +0 -7
  295. package/dist/chunks/chunk-ZW5ZLGBI.ts +0 -154
  296. package/dist/chunks/chunk-ZW5ZLGBI.ts.map +0 -7
  297. package/dist/chunks/command-handler-MRXE5AKK.ts.map +0 -7
  298. package/dist/chunks/conflict-artifacts-J6WSDCWP.ts +0 -32
  299. package/dist/chunks/conflict-review-GXA6Y7KY.ts +0 -189
  300. package/dist/chunks/conflict-review-GXA6Y7KY.ts.map +0 -7
  301. package/dist/chunks/continuous-sync-FAFNLEUW.ts +0 -585
  302. package/dist/chunks/continuous-sync-FAFNLEUW.ts.map +0 -7
  303. package/dist/chunks/file-selection-IELTXSGZ.ts.map +0 -7
  304. package/dist/chunks/git-backend-KHD36W27.ts +0 -1077
  305. package/dist/chunks/git-backend-KHD36W27.ts.map +0 -7
  306. package/dist/chunks/local-fields-JEKAPZKD.ts +0 -26
  307. package/dist/chunks/local-fields-JEKAPZKD.ts.map +0 -7
  308. package/dist/chunks/manager-result-dispatcher-XCYPW7RC.ts +0 -32
  309. package/dist/chunks/manager-result-dispatcher-XCYPW7RC.ts.map +0 -7
  310. package/dist/chunks/manager-ui-AY34N4UY.ts.map +0 -7
  311. package/dist/chunks/merge-baseline-store-65GKUMXI.ts +0 -25
  312. package/dist/chunks/merge-baseline-store-65GKUMXI.ts.map +0 -7
  313. package/dist/chunks/remote-selection-ui-MYM2YCPF.ts +0 -31
  314. package/dist/chunks/remote-selection-ui-MYM2YCPF.ts.map +0 -7
  315. package/dist/chunks/s3-backend-L24UZ6IK.ts +0 -844
  316. package/dist/chunks/s3-backend-L24UZ6IK.ts.map +0 -7
  317. package/dist/chunks/setup-switch-KLGESLQX.ts.map +0 -7
  318. package/dist/chunks/snapshot-RGNDYT6A.ts.map +0 -7
  319. package/dist/chunks/snapshot-transaction-26BQO36S.ts +0 -24
  320. package/dist/chunks/snapshot-transaction-26BQO36S.ts.map +0 -7
  321. package/dist/chunks/sync-inspection-MOMLGUTD.ts +0 -25
  322. package/dist/chunks/sync-inspection-MOMLGUTD.ts.map +0 -7
  323. package/dist/chunks/sync-operations-45APGOL3.ts +0 -1021
  324. package/dist/chunks/sync-operations-45APGOL3.ts.map +0 -7
  325. package/dist/chunks/sync-state-7L4NT7W2.ts.map +0 -7
  326. package/dist/chunks/webdav-backend-3ZCACILP.ts +0 -851
  327. package/dist/chunks/webdav-backend-3ZCACILP.ts.map +0 -7
  328. /package/dist/chunks/{chunk-KHBPED6W.ts.map → chunk-GSQGBVKG.ts.map} +0 -0
  329. /package/dist/chunks/{chunk-JYILGR3K.ts.map → chunk-UZUUUY7C.ts.map} +0 -0
  330. /package/dist/chunks/{agent-candidate-U2NU3GUX.ts.map → manager-result-dispatcher-I2AMCCE7.ts.map} +0 -0
  331. /package/dist/chunks/{agent-sync-2R4GG2MF.ts.map → merge-review-SGDLMVS4.ts.map} +0 -0
  332. /package/dist/chunks/{config-HYG7G5EM.ts.map → remote-selection-ui-GZHPDQ4L.ts.map} +0 -0
  333. /package/dist/chunks/{conflict-artifacts-J6WSDCWP.ts.map → setup-switch-M3BAFGJM.ts.map} +0 -0
  334. /package/dist/chunks/{continuous-record-EPHGR2DU.ts.map → state-directory-JZSZVVPX.ts.map} +0 -0
@@ -1,622 +1,10 @@
1
- import { createHash, randomUUID } from "node:crypto";
2
- import { decodeSnapshot, encodeSnapshot } from "../../snapshot/snapshot-codec.js";
3
- import type { Snapshot } from "../../snapshot/snapshot-types.js";
4
- import { validatePortableSnapshot } from "../../sync/local-fields.js";
5
- import { throwIfAborted } from "../../sync/signals.js";
6
- import { syncErrorGuidance } from "../../sync/sync-error-guidance.js";
7
- import { portableSnapshotSelection } from "../../sync/sync-policy.js";
8
- import type { LatestPointer, RemoteObject, ResolvedWebDavBackend } from "../backend-types.js";
9
- import { createLatestPointer, remoteHistoryEntry } from "../snapshot-pointer.js";
10
- import {
11
- type BackendDiagnostic,
12
- type ExpectedRemoteHead,
13
- type PublishSnapshotOptions,
14
- type PublishSnapshotResult,
15
- type RemoteHead,
16
- type RemoteHistoryEntry,
17
- type SyncBackend,
18
- SyncBackendConflictError,
19
- SyncBackendPublicationOutcomeUnknownError,
20
- } from "../sync-backend.js";
21
- import { WebDavClient, WebDavHttpError, WebDavPreconditionError } from "./webdav-client.js";
22
-
23
- const VERSION = 1;
24
- const POST_COMMIT_TIMEOUT_MS = 30_000;
25
-
26
- export class WebDavSyncBackend implements SyncBackend {
27
- readonly identity: string;
28
- readonly destination: string;
29
- private conditionalVerified = false;
30
- private readonly checksums = new Map<string, string>();
31
- private capabilityCheck?: Promise<void>;
32
-
33
- constructor(
34
- private readonly config: ResolvedWebDavBackend,
35
- private readonly postCommitTimeoutMs = POST_COMMIT_TIMEOUT_MS,
36
- ) {
37
- assertSafeDestination(config);
38
- this.identity = webDavBackendIdentity(config);
39
- this.destination = webDavStorageLocation(config);
40
- }
41
-
42
- get capability() {
43
- return this.conditionalVerified ? ("atomic-conditional" as const) : ("conditional-required" as const);
44
- }
45
-
46
- sameRevision(left: string, right: string) {
47
- return left === right;
48
- }
49
-
50
- async readHead(signal?: AbortSignal): Promise<RemoteHead | undefined> {
51
- const object = await new WebDavClient(this.config, signal).getJson<LatestPointer>(latestPath(this.config));
52
- throwIfAborted(signal);
53
- if (object.missing) return undefined;
54
- const pointer = requirePointer(object.value, this.config.destination.namespace);
55
- this.registerChecksum(pointer.snapshot, pointer.sha256);
56
- return remoteHead(pointer, this.identity, object.etag);
57
- }
58
-
59
- async readSnapshot(reference: string, signal?: AbortSignal): Promise<Snapshot> {
60
- requireSnapshotReference(reference);
61
- const expectedChecksum = this.checksums.get(reference) ?? (await this.resolveChecksum(reference, signal));
62
- const object = await new WebDavClient(this.config, signal).getBuffer(snapshotPath(this.config, reference));
63
- throwIfAborted(signal);
64
- if (!object.value) throw new Error(`Snapshot not found: ${reference}`);
65
- if (!expectedChecksum || sha256(object.value) !== expectedChecksum) {
66
- throw new Error("Remote snapshot checksum mismatch.");
67
- }
68
- const snapshot = await decodeSnapshot(object.value, { signal });
69
- if (snapshot.id !== reference || snapshot.profile !== this.config.destination.namespace) {
70
- throw new Error("Remote snapshot identity mismatch.");
71
- }
72
- validateSnapshotBundle(snapshot);
73
- return snapshot;
74
- }
75
-
76
- async publishSnapshot(
77
- snapshot: Snapshot,
78
- expected: ExpectedRemoteHead,
79
- options: PublishSnapshotOptions = {},
80
- ): Promise<PublishSnapshotResult> {
81
- throwIfAborted(options.signal);
82
- assertSnapshotIdentity(snapshot, this.config.destination.namespace);
83
- await this.ensureAtomicConditions(options.signal);
84
- throwIfAborted(options.signal);
85
- const client = new WebDavClient(this.config, options.signal);
86
- await client.ensureCollection(snapshotsPath(this.config));
87
- const encoded = await encodeSnapshot(snapshot);
88
- throwIfAborted(options.signal);
89
- const pointer = createLatestPointer(this.config.destination.namespace, snapshot, sha256(encoded));
90
- const stagedPath = snapshotPath(this.config, snapshot.id);
91
- try {
92
- await client.putBuffer(stagedPath, encoded, "application/gzip", { ifAbsent: true });
93
- } catch (error) {
94
- if (!(error instanceof WebDavPreconditionError)) throw error;
95
- const existing = await client.getBuffer(stagedPath);
96
- if (!existing.value || sha256(existing.value) !== pointer.sha256) {
97
- throw new SyncBackendConflictError(
98
- `Immutable snapshot id already exists with different content: ${snapshot.id}`,
99
- );
100
- }
101
- }
102
- const currentObject = await client.getJson<LatestPointer>(latestPath(this.config));
103
- throwIfAborted(options.signal);
104
- const current = currentObject.missing
105
- ? undefined
106
- : remoteHead(
107
- requirePointer(currentObject.value, this.config.destination.namespace),
108
- this.identity,
109
- currentObject.etag,
110
- );
111
- if (!matchesExpected(current, expected)) {
112
- throw new SyncBackendConflictError("Remote changed while pushing. Run /sync pull first, then retry.", {
113
- currentHead: current,
114
- });
115
- }
116
- const condition = publicationCondition(currentObject, expected, this.identity);
117
- throwIfAborted(options.signal);
118
- options.onCommit?.();
119
- const commitClient = new WebDavClient(
120
- this.config,
121
- AbortSignal.timeout(this.postCommitTimeoutMs),
122
- this.postCommitTimeoutMs,
123
- );
124
- try {
125
- await commitClient.putJson(latestPath(this.config), pointer, condition);
126
- } catch (error) {
127
- if (error instanceof WebDavPreconditionError) {
128
- const latest = await this.readHeadAfterCommit(commitClient).catch(() => undefined);
129
- throw new SyncBackendConflictError("Remote changed while publishing the WebDAV pointer.", {
130
- currentHead: latest,
131
- });
132
- }
133
- throw new SyncBackendPublicationOutcomeUnknownError(
134
- `Remote publication outcome is unknown: ${errorMessage(error)}`,
135
- { cause: error },
136
- );
137
- }
138
- let verifiedObject: RemoteObject<LatestPointer>;
139
- try {
140
- verifiedObject = await commitClient.getJson<LatestPointer>(latestPath(this.config));
141
- } catch (error) {
142
- throw new SyncBackendPublicationOutcomeUnknownError(
143
- `Remote snapshot may be active, but publication could not be verified: ${errorMessage(error)}`,
144
- { cause: error },
145
- );
146
- }
147
- let verified: LatestPointer;
148
- try {
149
- verified = requirePointer(verifiedObject.value, this.config.destination.namespace);
150
- } catch (error) {
151
- throw new SyncBackendPublicationOutcomeUnknownError(
152
- `Remote snapshot may be active, but publication verification was malformed: ${errorMessage(error)}`,
153
- { cause: error },
154
- );
155
- }
156
- if (!samePointer(pointer, verified)) {
157
- throw new SyncBackendConflictError(
158
- "Remote latest changed immediately after push. Run /sync status before continuing.",
159
- {
160
- phase: "after-commit",
161
- currentHead: remoteHead(verified, this.identity, verifiedObject.etag),
162
- candidateMayHaveBeenActive: true,
163
- },
164
- );
165
- }
166
- if (!strongEtag(verifiedObject.etag)) {
167
- throw new SyncBackendPublicationOutcomeUnknownError(
168
- "Remote snapshot is active, but the WebDAV server returned no strong ETag.",
169
- );
170
- }
171
- this.registerChecksum(verified.snapshot, verified.sha256);
172
- const head = remoteHead(verified, this.identity, verifiedObject.etag);
173
- const warning = await this.updateHistorySafely(commitClient, pointer);
174
- return { head, warnings: warning ? [warning] : [] };
175
- }
176
-
177
- async listHistory(signal?: AbortSignal): Promise<RemoteHistoryEntry[]> {
178
- const object = await new WebDavClient(this.config, signal).getJson<{
179
- version: number;
180
- snapshots: LatestPointer[];
181
- }>(historyPath(this.config));
182
- throwIfAborted(signal);
183
- if (object.missing) return [];
184
- const pointers = requireHistory(object.value, this.config.destination.namespace);
185
- for (const pointer of pointers) this.registerChecksum(pointer.snapshot, pointer.sha256);
186
- return pointers.map(remoteHistoryEntry);
187
- }
188
-
189
- async diagnose(signal?: AbortSignal): Promise<BackendDiagnostic[]> {
190
- const diagnostics: BackendDiagnostic[] = [
191
- {
192
- key: "webdav-url",
193
- level: "info",
194
- message: `webdav URL/TLS/auth: configured (${webDavStorageLocation(this.config)})`,
195
- },
196
- {
197
- key: "webdav-scope",
198
- level: "info",
199
- message:
200
- "webdav check scope: temporary write/delete probe; repair the active snapshot's history entry if missing. No local content is applied.",
201
- },
202
- ];
203
- try {
204
- await this.runCapabilityProbe(signal);
205
- diagnostics.push(
206
- { key: "webdav-collection", level: "info", message: "webdav collection read/write: ok" },
207
- {
208
- key: "webdav-conditional",
209
- level: "info",
210
- message: "webdav conditional publication: atomic-conditional (verified)",
211
- },
212
- { key: "webdav-cleanup", level: "info", message: "webdav probe cleanup: ok" },
213
- );
214
- } catch (error) {
215
- this.capabilityCheck = undefined;
216
- this.conditionalVerified = false;
217
- if (error instanceof Error && error.name === "AbortError") throw error;
218
- diagnostics.push({
219
- key: "webdav-probe",
220
- level: "error",
221
- message: `webdav publication is read-only until diagnostics pass: ${syncErrorGuidance(error)}`,
222
- });
223
- return diagnostics;
224
- }
225
- try {
226
- diagnostics.push({
227
- key: "webdav-history",
228
- level: "info",
229
- message: await this.reconcileActiveHistory(signal),
230
- });
231
- } catch (error) {
232
- if (error instanceof Error && error.name === "AbortError") throw error;
233
- diagnostics.push({
234
- key: "webdav-history",
235
- level: "error",
236
- message: `webdav history repair failed: ${syncErrorGuidance(error)}`,
237
- });
238
- }
239
- return diagnostics;
240
- }
241
-
242
- private ensureAtomicConditions(signal?: AbortSignal) {
243
- if (this.capabilityCheck) return this.capabilityCheck;
244
- this.conditionalVerified = false;
245
- const check = this.runCapabilityProbe(signal).finally(() => {
246
- if (this.capabilityCheck === check) this.capabilityCheck = undefined;
247
- });
248
- this.capabilityCheck = check;
249
- return check;
250
- }
251
-
252
- private async runCapabilityProbe(signal?: AbortSignal) {
253
- throwIfAborted(signal);
254
- const probeCollection = joinRemote(rootPath(this.config), ".pi-sync-probes", randomUUID());
255
- const probe = `${probeCollection}/conditional.txt`;
256
- const client = new WebDavClient(this.config, signal);
257
- let created = false;
258
- let operationError: unknown;
259
- try {
260
- created = true;
261
- await client.ensureCollection(probeCollection);
262
- await client.listCollection(probeCollection);
263
- await client.putBuffer(probe, Buffer.from("first"), "text/plain", { ifAbsent: true });
264
- const read = await client.getBuffer(probe);
265
- const etag = strongEtag(read.etag);
266
- if (!read.value || !etag) {
267
- throw new Error("WebDAV server did not return a strong ETag for the capability probe.");
268
- }
269
- await expectPrecondition(
270
- client.putBuffer(probe, Buffer.from("replace"), "text/plain", { ifAbsent: true }),
271
- "If-None-Match",
272
- );
273
- await expectPrecondition(
274
- client.putBuffer(probe, Buffer.from("replace"), "text/plain", {
275
- ifMatch: '"pi-sync-deliberately-stale"',
276
- }),
277
- "If-Match",
278
- );
279
- const unchanged = await client.getBuffer(probe);
280
- if (!unchanged.value?.equals(Buffer.from("first"))) {
281
- throw new Error("WebDAV server changed a probe despite a failed precondition.");
282
- }
283
- await client.putBuffer(probe, Buffer.from("second"), "text/plain", { ifMatch: etag });
284
- const changed = await client.getBuffer(probe);
285
- const changedEtag = strongEtag(changed.etag);
286
- if (!changed.value?.equals(Buffer.from("second")) || !changedEtag || changedEtag === etag) {
287
- throw new Error("WebDAV server did not rotate its strong ETag after changing the capability probe.");
288
- }
289
- } catch (error) {
290
- operationError = error;
291
- }
292
- if (created) {
293
- try {
294
- await new WebDavClient(this.config, undefined).delete(probeCollection);
295
- } catch (cleanupError) {
296
- const operationDetail = operationError ? `WebDAV probe failed: ${errorMessage(operationError)}; ` : "";
297
- throw new Error(
298
- `${operationDetail}probe cleanup also failed; remove ${probeCollection}: ${errorMessage(cleanupError)}`,
299
- { cause: operationError ?? cleanupError },
300
- );
301
- }
302
- }
303
- if (operationError) throw operationError;
304
- this.conditionalVerified = true;
305
- }
306
-
307
- private async resolveChecksum(reference: string, signal?: AbortSignal) {
308
- await this.readHead(signal);
309
- if (this.checksums.has(reference)) return this.checksums.get(reference);
310
- await this.listHistory(signal);
311
- return this.checksums.get(reference);
312
- }
313
-
314
- private registerChecksum(reference: string, checksum: string) {
315
- const known = this.checksums.get(reference);
316
- if (known && known !== checksum) {
317
- throw new Error("Remote snapshot reference was rebound to a different checksum.");
318
- }
319
- this.checksums.set(reference, checksum);
320
- }
321
-
322
- private async readHeadAfterCommit(client: WebDavClient) {
323
- const object = await client.getJson<LatestPointer>(latestPath(this.config));
324
- if (object.missing) return undefined;
325
- return remoteHead(requirePointer(object.value, this.config.destination.namespace), this.identity, object.etag);
326
- }
327
-
328
- private async reconcileActiveHistory(signal?: AbortSignal) {
329
- const client = new WebDavClient(this.config, signal);
330
- const object = await client.getJson<LatestPointer>(latestPath(this.config));
331
- throwIfAborted(signal);
332
- if (object.missing) return "webdav history: no active snapshot";
333
- const pointer = requirePointer(object.value, this.config.destination.namespace);
334
- this.registerChecksum(pointer.snapshot, pointer.sha256);
335
- const repaired = await this.ensureHistoryPointer(client, pointer);
336
- return repaired
337
- ? "webdav history: repaired active snapshot entry"
338
- : "webdav history: active snapshot entry present";
339
- }
340
-
341
- private async ensureHistoryPointer(client: WebDavClient, pointer: LatestPointer) {
342
- const object = await client.getJson<{ version: number; snapshots: LatestPointer[] }>(historyPath(this.config));
343
- const snapshots = object.missing ? [] : requireHistory(object.value, this.config.destination.namespace);
344
- const existing = snapshots.find((entry) => entry.snapshot === pointer.snapshot);
345
- if (existing) {
346
- if (!samePointer(existing, pointer)) {
347
- throw new Error("Remote history rebound an immutable snapshot reference.");
348
- }
349
- return false;
350
- }
351
- const next = [...snapshots, pointer].slice(-100);
352
- const condition = object.missing ? { ifAbsent: true } : { ifMatch: requireStrongEtag(object.etag, "history") };
353
- await client.putJson(historyPath(this.config), { version: VERSION, snapshots: next }, condition);
354
- return true;
355
- }
356
-
357
- private async updateHistorySafely(client: WebDavClient, pointer: LatestPointer) {
358
- try {
359
- await this.ensureHistoryPointer(client, pointer);
360
- return undefined;
361
- } catch (error) {
362
- return `Remote snapshot is active, but history could not be updated: ${errorMessage(error)}. Run /sync doctor before relying on history.`;
363
- }
364
- }
365
- }
366
-
367
- export function rootPath(config: ResolvedWebDavBackend) {
368
- return config.destination.path === "./" ? "" : config.destination.path;
369
- }
370
-
371
- export function latestPath(config: ResolvedWebDavBackend) {
372
- return joinRemote(rootPath(config), "latest.json");
373
- }
374
-
375
- export function historyPath(config: ResolvedWebDavBackend) {
376
- return joinRemote(rootPath(config), "history.json");
377
- }
378
-
379
- export function snapshotsPath(config: ResolvedWebDavBackend) {
380
- return joinRemote(rootPath(config), "snapshots");
381
- }
382
-
383
- export function snapshotPath(config: ResolvedWebDavBackend, reference: string) {
384
- requireSnapshotReference(reference);
385
- return joinRemote(snapshotsPath(config), `${reference}.json.gz`);
386
- }
387
-
388
- export function webDavBackendIdentity(config: ResolvedWebDavBackend) {
389
- return `webdav:${sha256(Buffer.from(JSON.stringify([secretFreeUrl(config.profile.url), config.destination.path])))}`;
390
- }
391
-
392
- function webDavStorageLocation(config: ResolvedWebDavBackend) {
393
- const url = new URL(secretFreeUrl(config.profile.url));
394
- return `${url.host} · ${config.destination.path}`;
395
- }
396
-
397
- function remoteHead(pointer: LatestPointer, identity: string, etag?: string): RemoteHead {
398
- return {
399
- snapshotRef: pointer.snapshot,
400
- snapshotId: pointer.snapshot,
401
- revision: encodeRevision(identity, etag, pointer),
402
- createdAt: pointer.createdAt,
403
- machine: pointer.machine,
404
- syncSessions: pointer.syncSessions === true,
405
- ...(pointer.selection === undefined ? {} : { selection: pointer.selection }),
406
- };
407
- }
408
-
409
- function encodeRevision(identity: string, etag: string | undefined, pointer: LatestPointer) {
410
- return `webdav-v1:${Buffer.from(JSON.stringify({ identity, etag: etag ?? null, pointer: sha256(Buffer.from(canonicalJson(pointer))) })).toString("base64url")}`;
411
- }
412
-
413
- function decodeRevision(value: string, identity: string) {
414
- try {
415
- if (!value.startsWith("webdav-v1:")) return undefined;
416
- const parsed = JSON.parse(Buffer.from(value.slice(10), "base64url").toString("utf8")) as {
417
- identity?: unknown;
418
- etag?: unknown;
419
- };
420
- if (parsed.identity !== identity || typeof parsed.etag !== "string") return undefined;
421
- return strongEtag(parsed.etag);
422
- } catch {
423
- return undefined;
424
- }
425
- }
426
-
427
- function publicationCondition(current: RemoteObject<LatestPointer>, expected: ExpectedRemoteHead, identity: string) {
428
- if (expected.kind === "missing") return { ifAbsent: true };
429
- const etag = decodeRevision(expected.revision, identity) ?? strongEtag(current.etag);
430
- if (!etag) throw new SyncBackendConflictError("WebDAV head has no usable strong ETag.");
431
- return { ifMatch: etag };
432
- }
433
-
434
- async function expectPrecondition(operation: Promise<unknown>, header: string) {
435
- try {
436
- await operation;
437
- } catch (error) {
438
- if (error instanceof WebDavPreconditionError) return;
439
- throw error;
440
- }
441
- throw new Error(`WebDAV server ignored ${header}; publication is read-only for safety.`);
442
- }
443
-
444
- function requireStrongEtag(value: string | undefined, resource: string) {
445
- const etag = strongEtag(value);
446
- if (!etag) throw new Error(`WebDAV ${resource} has no strong ETag.`);
447
- return etag;
448
- }
449
-
450
- function strongEtag(value: string | undefined) {
451
- return value && !value.startsWith("W/") && /^"[^"\r\n]+"$/u.test(value) ? value : undefined;
452
- }
453
-
454
- function requirePointer(value: LatestPointer | undefined, expectedProfile: string) {
455
- if (
456
- !value ||
457
- value.version !== VERSION ||
458
- value.profile !== expectedProfile ||
459
- !isSafeReference(value.snapshot) ||
460
- !/^[0-9a-f]{64}$/u.test(value.sha256) ||
461
- !isSafeMetadata(value.createdAt, 64) ||
462
- !isSafeMetadata(value.machine, 256) ||
463
- (value.syncSessions !== undefined && typeof value.syncSessions !== "boolean")
464
- ) {
465
- throw new Error("Remote latest pointer is malformed.");
466
- }
467
- if (value.selection !== undefined) portableSnapshotSelection(value.selection);
468
- return value;
469
- }
470
-
471
- function requireHistory(value: { version: number; snapshots: LatestPointer[] } | undefined, expectedProfile: string) {
472
- if (!value || value.version !== VERSION || !Array.isArray(value.snapshots)) {
473
- throw new Error("Remote history is malformed.");
474
- }
475
- const pointers = value.snapshots.map((item) => requirePointer(item, expectedProfile));
476
- if (new Set(pointers.map((item) => item.snapshot)).size !== pointers.length) {
477
- throw new Error("Remote history contains duplicate snapshot references.");
478
- }
479
- return pointers;
480
- }
481
-
482
- function assertSnapshotIdentity(snapshot: Snapshot, namespace: string) {
483
- validatePortableSnapshot(snapshot);
484
- if (
485
- snapshot.profile !== namespace ||
486
- !isSafeReference(snapshot.id) ||
487
- !isSafeMetadata(snapshot.createdAt, 64) ||
488
- !isSafeMetadata(snapshot.machine, 256) ||
489
- !Array.isArray(snapshot.files)
490
- ) {
491
- throw new Error("Invalid snapshot identity for WebDAV publication.");
492
- }
493
- }
494
-
495
- function validateSnapshotBundle(snapshot: Snapshot) {
496
- const paths = new Set<string>();
497
- for (const file of snapshot.files) {
498
- if (
499
- !file ||
500
- !isSafeSnapshotPath(file.path) ||
501
- paths.has(file.path) ||
502
- typeof file.contentBase64 !== "string" ||
503
- typeof file.sha256 !== "string"
504
- ) {
505
- throw new Error("Remote snapshot bundle is malformed.");
506
- }
507
- const content = Buffer.from(file.contentBase64, "base64");
508
- if (content.toString("base64") !== file.contentBase64 || sha256(content) !== file.sha256) {
509
- throw new Error("Remote snapshot bundle is malformed.");
510
- }
511
- paths.add(file.path);
512
- }
513
- }
514
-
515
- function isSafeSnapshotPath(value: unknown): value is string {
516
- if (typeof value !== "string" || !value || value.length > 4096 || value.includes("\\")) {
517
- return false;
518
- }
519
- if (
520
- [...value].some((character) => {
521
- const code = character.codePointAt(0) ?? 0;
522
- return code < 0x20 || (code >= 0x7f && code <= 0x9f);
523
- })
524
- ) {
525
- return false;
526
- }
527
- return value.split("/").every((segment) => segment && segment !== "." && segment !== "..");
528
- }
529
-
530
- function assertSafeDestination(config: ResolvedWebDavBackend) {
531
- const url = new URL(config.profile.url);
532
- if (url.username || url.password || url.search || url.hash) throw new Error("Invalid WebDAV URL.");
533
- for (const [label, value] of [
534
- ["path", config.destination.path],
535
- ["namespace", config.destination.namespace],
536
- ]) {
537
- if (label === "path" && value === "./") continue;
538
- if (
539
- !value ||
540
- value.includes("\\") ||
541
- [...value].some((character) => {
542
- const code = character.codePointAt(0) ?? 0;
543
- return code < 0x20 || (code >= 0x7f && code <= 0x9f);
544
- }) ||
545
- value.split("/").some((part) => part === "." || part === "..")
546
- ) {
547
- throw new Error("Invalid WebDAV storage location.");
548
- }
549
- }
550
- }
551
-
552
- function isSafeMetadata(value: unknown, maxLength: number): value is string {
553
- return (
554
- typeof value === "string" &&
555
- value.length > 0 &&
556
- value.length <= maxLength &&
557
- ![...value].some((character) => {
558
- const code = character.codePointAt(0) ?? 0;
559
- return code < 0x20 || (code >= 0x7f && code <= 0x9f);
560
- })
561
- );
562
- }
563
-
564
- function requireSnapshotReference(reference: string) {
565
- if (!isSafeReference(reference)) throw new Error("Invalid WebDAV snapshot reference.");
566
- }
567
-
568
- function isSafeReference(value: string) {
569
- return (
570
- !!value &&
571
- value.length <= 512 &&
572
- // biome-ignore lint/suspicious/noControlCharactersInRegex: Remote references cannot contain terminal controls.
573
- !/[\\/\u0000-\u001f\u007f-\u009f]/u.test(value) &&
574
- value !== "." &&
575
- value !== ".."
576
- );
577
- }
578
-
579
- function matchesExpected(head: RemoteHead | undefined, expected: ExpectedRemoteHead) {
580
- return expected.kind === "missing" ? head === undefined : head?.revision === expected.revision;
581
- }
582
-
583
- function samePointer(left: LatestPointer, right: LatestPointer) {
584
- return canonicalJson(left) === canonicalJson(right);
585
- }
586
-
587
- function canonicalJson(value: unknown): string {
588
- if (Array.isArray(value)) return JSON.stringify(value.map((item) => JSON.parse(canonicalJson(item))));
589
- if (!value || typeof value !== "object") return JSON.stringify(value);
590
- return JSON.stringify(
591
- Object.fromEntries(
592
- Object.keys(value)
593
- .sort()
594
- .map((key) => [key, JSON.parse(canonicalJson((value as Record<string, unknown>)[key]))]),
595
- ),
596
- );
597
- }
598
-
599
- function joinRemote(...parts: string[]) {
600
- return parts
601
- .flatMap((part) => part.split("/"))
602
- .filter(Boolean)
603
- .join("/");
604
- }
605
-
606
- function secretFreeUrl(value: string) {
607
- const url = new URL(value);
608
- url.username = "";
609
- url.password = "";
610
- url.search = "";
611
- url.hash = "";
612
- return url.toString();
613
- }
614
-
615
- function sha256(value: Buffer) {
616
- return createHash("sha256").update(value).digest("hex");
617
- }
618
-
619
- function errorMessage(error: unknown) {
620
- if (error instanceof WebDavHttpError) return error.message;
621
- return error instanceof Error ? error.message : String(error);
622
- }
1
+ export type * from "@narumitw/sync-daemon/engine/backends/webdav/webdav-backend";
2
+ export {
3
+ historyPath,
4
+ latestPath,
5
+ rootPath,
6
+ snapshotPath,
7
+ snapshotsPath,
8
+ WebDavSyncBackend,
9
+ webDavBackendIdentity,
10
+ } from "@narumitw/sync-daemon/engine/backends/webdav/webdav-backend";