@narumitw/pi-sync 0.59.0 → 0.60.1

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 (327) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +25 -17
  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-NGW4JMBF.ts → chunk-4RNCZZY7.ts} +33 -27
  6. package/dist/chunks/{chunk-NGW4JMBF.ts.map → chunk-4RNCZZY7.ts.map} +3 -3
  7. package/dist/chunks/{chunk-2ZZJXITS.ts → chunk-6LHIRS5R.ts} +30 -47
  8. package/dist/chunks/chunk-6LHIRS5R.ts.map +7 -0
  9. package/dist/chunks/{config-J5VZUY4J.ts → chunk-7AC2RX4M.ts} +6 -13
  10. package/dist/chunks/chunk-7AC2RX4M.ts.map +7 -0
  11. package/dist/chunks/{chunk-76HID27T.ts → chunk-BGGKHHO4.ts} +18 -14
  12. package/dist/chunks/{chunk-76HID27T.ts.map → chunk-BGGKHHO4.ts.map} +1 -1
  13. package/dist/chunks/chunk-BWWTOQOW.ts +737 -0
  14. package/dist/chunks/chunk-BWWTOQOW.ts.map +7 -0
  15. package/dist/chunks/chunk-CEMFCWIU.ts +20 -0
  16. package/dist/chunks/chunk-CEMFCWIU.ts.map +7 -0
  17. package/dist/chunks/chunk-CZNBKIM5.ts +20 -0
  18. package/dist/chunks/chunk-CZNBKIM5.ts.map +7 -0
  19. package/dist/chunks/{chunk-YIPK23JW.ts → chunk-ENFHHB5O.ts} +1 -16
  20. package/dist/chunks/{chunk-YIPK23JW.ts.map → chunk-ENFHHB5O.ts.map} +1 -1
  21. package/dist/chunks/{chunk-KHBPED6W.ts → chunk-GSQGBVKG.ts} +2 -2
  22. package/dist/chunks/chunk-HNKLBM3U.ts +18 -0
  23. package/dist/chunks/chunk-HNKLBM3U.ts.map +7 -0
  24. package/dist/chunks/{chunk-QPC5HT3A.ts → chunk-J5COV5TY.ts} +21 -2
  25. package/dist/chunks/chunk-J5COV5TY.ts.map +7 -0
  26. package/dist/chunks/chunk-JKBUYCPC.ts +52 -0
  27. package/dist/chunks/chunk-JKBUYCPC.ts.map +7 -0
  28. package/dist/chunks/chunk-JZKCOM62.ts +26 -0
  29. package/dist/chunks/chunk-JZKCOM62.ts.map +7 -0
  30. package/dist/chunks/chunk-M7RHV3H6.ts +33 -0
  31. package/dist/chunks/chunk-M7RHV3H6.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-PQ75RPUP.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-DTPELCPW.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-SDGKIQH2.ts → command-handler-FO4XBBHF.ts} +80 -86
  46. package/dist/chunks/command-handler-FO4XBBHF.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-OM64J27R.ts → continuous-record-ZHUXVO4E.ts} +5 -13
  50. package/dist/chunks/continuous-record-ZHUXVO4E.ts.map +7 -0
  51. package/dist/chunks/continuous-storage-SQBAXACF.ts +27 -0
  52. package/dist/chunks/continuous-storage-SQBAXACF.ts.map +7 -0
  53. package/dist/chunks/{file-selection-7HEVPO4T.ts → file-selection-S6CNNNQI.ts} +11 -14
  54. package/dist/chunks/{file-selection-7HEVPO4T.ts.map → file-selection-S6CNNNQI.ts.map} +1 -1
  55. package/dist/chunks/manager-result-dispatcher-I2AMCCE7.ts +18 -0
  56. package/dist/chunks/{manager-ui-65ZETN6F.ts → manager-ui-AY5ZU6B4.ts} +180 -164
  57. package/dist/chunks/manager-ui-AY5ZU6B4.ts.map +7 -0
  58. package/dist/chunks/merge-review-SGDLMVS4.ts +10 -0
  59. package/dist/chunks/remote-selection-ui-GZHPDQ4L.ts +17 -0
  60. package/dist/chunks/{setup-switch-AB27ADDI.ts → setup-switch-M3BAFGJM.ts} +9 -13
  61. package/dist/chunks/{setup-wizard-5FILKFLQ.ts → setup-wizard-NFAWP4KF.ts} +18 -21
  62. package/dist/chunks/{setup-wizard-5FILKFLQ.ts.map → setup-wizard-NFAWP4KF.ts.map} +1 -1
  63. package/dist/chunks/{snapshot-G3W2GOGB.ts → snapshot-D4SFDP5J.ts} +8 -13
  64. package/dist/chunks/snapshot-D4SFDP5J.ts.map +7 -0
  65. package/dist/chunks/snapshot-transaction-directory-TNKBQ3UQ.ts +13 -0
  66. package/dist/chunks/snapshot-transaction-directory-TNKBQ3UQ.ts.map +7 -0
  67. package/dist/chunks/state-directory-JZSZVVPX.ts +17 -0
  68. package/dist/chunks/sync-inspection-BJ4KPPNO.ts +23 -0
  69. package/dist/chunks/sync-inspection-BJ4KPPNO.ts.map +7 -0
  70. package/dist/chunks/sync-operations-TLWER2TT.ts +45 -0
  71. package/dist/chunks/sync-operations-TLWER2TT.ts.map +7 -0
  72. package/dist/chunks/{sync-state-H4TFZZ7S.ts → sync-state-FVCJJ7MY.ts} +5 -11
  73. package/dist/chunks/sync-state-FVCJJ7MY.ts.map +7 -0
  74. package/dist/index.ts +269 -313
  75. package/dist/index.ts.map +4 -4
  76. package/docs/daemon-migration.md +93 -0
  77. package/docs/tui-contract.md +12 -0
  78. package/package.json +3 -6
  79. package/skills/configure-pi-sync/SKILL.md +1 -1
  80. package/skills/configure-pi-sync/references/configuration.md +19 -6
  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 -293
  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 +40 -36
  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 -263
  105. package/src/settings/settings-management.ts +11 -254
  106. package/src/settings/settings-store.ts +10 -48
  107. package/src/settings/settings-types.ts +1 -157
  108. package/src/settings/settings-validation.ts +17 -435
  109. package/src/snapshot/session-paths.ts +11 -111
  110. package/src/snapshot/snapshot-apply.ts +9 -322
  111. package/src/snapshot/snapshot-case-replacement.ts +6 -80
  112. package/src/snapshot/snapshot-codec.ts +2 -59
  113. package/src/snapshot/snapshot-exclude-safety.ts +2 -44
  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 -946
  120. package/src/snapshot/snapshot-types.ts +1 -43
  121. package/src/snapshot/snapshot.ts +19 -447
  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 -208
  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 -25
  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 -111
  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 -61
  156. package/src/sync/exclude-policy.ts +6 -84
  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 -119
  162. package/src/sync/merge-apply.ts +2 -439
  163. package/src/sync/merge-journal.ts +10 -228
  164. package/src/sync/merge-transfer-error.ts +2 -72
  165. package/src/sync/merged-sync.ts +2 -919
  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 -55
  169. package/src/sync/remote-snapshot.ts +7 -79
  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 -111
  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 -59
  180. package/src/sync/sync-local.ts +2 -44
  181. package/src/sync/sync-mutations.ts +10 -788
  182. package/src/sync/sync-operations.ts +32 -11
  183. package/src/sync/sync-policy.ts +34 -474
  184. package/src/sync/sync-queries.ts +2 -247
  185. package/src/sync/sync-state.ts +18 -157
  186. package/src/sync/text-merge.ts +10 -133
  187. package/src/sync-extension.ts +192 -142
  188. package/src/ui/manager-state.ts +35 -23
  189. package/src/ui/manager-ui.ts +80 -36
  190. package/src/ui/sync-attention.ts +7 -49
  191. package/dist/chunks/agent-candidate-ZHN7FTZT.ts +0 -30
  192. package/dist/chunks/agent-plan-ILFEUJ2E.ts +0 -124
  193. package/dist/chunks/agent-plan-ILFEUJ2E.ts.map +0 -7
  194. package/dist/chunks/agent-refusal-retry-HRMHCX2A.ts +0 -73
  195. package/dist/chunks/agent-refusal-retry-HRMHCX2A.ts.map +0 -7
  196. package/dist/chunks/agent-runner-FCRV2Z75.ts +0 -185
  197. package/dist/chunks/agent-runner-FCRV2Z75.ts.map +0 -7
  198. package/dist/chunks/agent-store-CCKN4DPR.ts +0 -175
  199. package/dist/chunks/agent-store-CCKN4DPR.ts.map +0 -7
  200. package/dist/chunks/agent-sync-EGA2I5W7.ts +0 -22
  201. package/dist/chunks/chunk-25QCU3LY.ts +0 -220
  202. package/dist/chunks/chunk-25QCU3LY.ts.map +0 -7
  203. package/dist/chunks/chunk-2JZFHNLM.ts +0 -113
  204. package/dist/chunks/chunk-2JZFHNLM.ts.map +0 -7
  205. package/dist/chunks/chunk-2UKUKIBI.ts +0 -25
  206. package/dist/chunks/chunk-2UKUKIBI.ts.map +0 -7
  207. package/dist/chunks/chunk-2ZZJXITS.ts.map +0 -7
  208. package/dist/chunks/chunk-3JTZF7Z5.ts +0 -77
  209. package/dist/chunks/chunk-3JTZF7Z5.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-4NVHHDN2.ts +0 -61
  213. package/dist/chunks/chunk-4NVHHDN2.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-6OFMB6KK.ts +0 -215
  217. package/dist/chunks/chunk-6OFMB6KK.ts.map +0 -7
  218. package/dist/chunks/chunk-6XU5HZAN.ts +0 -205
  219. package/dist/chunks/chunk-6XU5HZAN.ts.map +0 -7
  220. package/dist/chunks/chunk-6YGRZSCN.ts +0 -128
  221. package/dist/chunks/chunk-6YGRZSCN.ts.map +0 -7
  222. package/dist/chunks/chunk-7D5SF7P3.ts +0 -29
  223. package/dist/chunks/chunk-7D5SF7P3.ts.map +0 -7
  224. package/dist/chunks/chunk-7WYF2KUO.ts +0 -1161
  225. package/dist/chunks/chunk-7WYF2KUO.ts.map +0 -7
  226. package/dist/chunks/chunk-APDNHB2T.ts +0 -2037
  227. package/dist/chunks/chunk-APDNHB2T.ts.map +0 -7
  228. package/dist/chunks/chunk-AR2DGDUI.ts +0 -55
  229. package/dist/chunks/chunk-AR2DGDUI.ts.map +0 -7
  230. package/dist/chunks/chunk-DT7M4VQS.ts +0 -69
  231. package/dist/chunks/chunk-DT7M4VQS.ts.map +0 -7
  232. package/dist/chunks/chunk-DTPELCPW.ts.map +0 -7
  233. package/dist/chunks/chunk-ECYCNZOE.ts.map +0 -7
  234. package/dist/chunks/chunk-FHE2DCA2.ts +0 -61
  235. package/dist/chunks/chunk-FHE2DCA2.ts.map +0 -7
  236. package/dist/chunks/chunk-G4RUXRWZ.ts +0 -48
  237. package/dist/chunks/chunk-G4RUXRWZ.ts.map +0 -7
  238. package/dist/chunks/chunk-ILXMZ2HU.ts +0 -58
  239. package/dist/chunks/chunk-ILXMZ2HU.ts.map +0 -7
  240. package/dist/chunks/chunk-LA3HQMFG.ts +0 -115
  241. package/dist/chunks/chunk-LA3HQMFG.ts.map +0 -7
  242. package/dist/chunks/chunk-M6VQJIOU.ts +0 -54
  243. package/dist/chunks/chunk-M6VQJIOU.ts.map +0 -7
  244. package/dist/chunks/chunk-MKC3PXCN.ts +0 -369
  245. package/dist/chunks/chunk-MKC3PXCN.ts.map +0 -7
  246. package/dist/chunks/chunk-OQBE2OMB.ts +0 -88
  247. package/dist/chunks/chunk-OQBE2OMB.ts.map +0 -7
  248. package/dist/chunks/chunk-P3YD4ONV.ts +0 -123
  249. package/dist/chunks/chunk-P3YD4ONV.ts.map +0 -7
  250. package/dist/chunks/chunk-PRUEIIK7.ts +0 -24
  251. package/dist/chunks/chunk-PRUEIIK7.ts.map +0 -7
  252. package/dist/chunks/chunk-PWMWOJP4.ts +0 -17
  253. package/dist/chunks/chunk-PWMWOJP4.ts.map +0 -7
  254. package/dist/chunks/chunk-QPC5HT3A.ts.map +0 -7
  255. package/dist/chunks/chunk-QQVK2XFC.ts +0 -64
  256. package/dist/chunks/chunk-QQVK2XFC.ts.map +0 -7
  257. package/dist/chunks/chunk-RDOX3VH5.ts +0 -140
  258. package/dist/chunks/chunk-RDOX3VH5.ts.map +0 -7
  259. package/dist/chunks/chunk-S7D6XWHI.ts +0 -258
  260. package/dist/chunks/chunk-S7D6XWHI.ts.map +0 -7
  261. package/dist/chunks/chunk-SHPNS7FM.ts +0 -64
  262. package/dist/chunks/chunk-SHPNS7FM.ts.map +0 -7
  263. package/dist/chunks/chunk-SWRVXVFD.ts +0 -248
  264. package/dist/chunks/chunk-SWRVXVFD.ts.map +0 -7
  265. package/dist/chunks/chunk-T2SJD3N7.ts +0 -99
  266. package/dist/chunks/chunk-T2SJD3N7.ts.map +0 -7
  267. package/dist/chunks/chunk-T2TYBLXK.ts +0 -27
  268. package/dist/chunks/chunk-T2TYBLXK.ts.map +0 -7
  269. package/dist/chunks/chunk-UZSDS4HF.ts +0 -403
  270. package/dist/chunks/chunk-UZSDS4HF.ts.map +0 -7
  271. package/dist/chunks/chunk-VPODHKOX.ts +0 -229
  272. package/dist/chunks/chunk-VPODHKOX.ts.map +0 -7
  273. package/dist/chunks/chunk-WEKGW7HV.ts +0 -162
  274. package/dist/chunks/chunk-WEKGW7HV.ts.map +0 -7
  275. package/dist/chunks/chunk-WUHRVSWI.ts +0 -369
  276. package/dist/chunks/chunk-WUHRVSWI.ts.map +0 -7
  277. package/dist/chunks/chunk-X7R6DCVF.ts +0 -28
  278. package/dist/chunks/chunk-X7R6DCVF.ts.map +0 -7
  279. package/dist/chunks/chunk-XJHQPB3E.ts +0 -107
  280. package/dist/chunks/chunk-XJHQPB3E.ts.map +0 -7
  281. package/dist/chunks/chunk-XZ3ZTHKR.ts +0 -1184
  282. package/dist/chunks/chunk-XZ3ZTHKR.ts.map +0 -7
  283. package/dist/chunks/chunk-YDVQYUHE.ts +0 -34
  284. package/dist/chunks/chunk-YDVQYUHE.ts.map +0 -7
  285. package/dist/chunks/chunk-YEULK7MK.ts +0 -415
  286. package/dist/chunks/chunk-YEULK7MK.ts.map +0 -7
  287. package/dist/chunks/chunk-YHT4YTYG.ts +0 -31
  288. package/dist/chunks/chunk-YHT4YTYG.ts.map +0 -7
  289. package/dist/chunks/chunk-ZW5ZLGBI.ts +0 -154
  290. package/dist/chunks/chunk-ZW5ZLGBI.ts.map +0 -7
  291. package/dist/chunks/command-handler-SDGKIQH2.ts.map +0 -7
  292. package/dist/chunks/conflict-artifacts-MYSH3L2J.ts +0 -33
  293. package/dist/chunks/conflict-review-J6ZSPNWL.ts +0 -190
  294. package/dist/chunks/conflict-review-J6ZSPNWL.ts.map +0 -7
  295. package/dist/chunks/continuous-sync-BH5SWIRV.ts +0 -590
  296. package/dist/chunks/continuous-sync-BH5SWIRV.ts.map +0 -7
  297. package/dist/chunks/git-backend-6CKI6CUG.ts +0 -1074
  298. package/dist/chunks/git-backend-6CKI6CUG.ts.map +0 -7
  299. package/dist/chunks/local-fields-SR7PH66U.ts +0 -27
  300. package/dist/chunks/local-fields-SR7PH66U.ts.map +0 -7
  301. package/dist/chunks/manager-result-dispatcher-CXUP5WDP.ts +0 -33
  302. package/dist/chunks/manager-result-dispatcher-CXUP5WDP.ts.map +0 -7
  303. package/dist/chunks/manager-ui-65ZETN6F.ts.map +0 -7
  304. package/dist/chunks/merge-baseline-store-4Y2X7P2D.ts +0 -26
  305. package/dist/chunks/merge-baseline-store-4Y2X7P2D.ts.map +0 -7
  306. package/dist/chunks/remote-selection-ui-W55BQDJQ.ts +0 -32
  307. package/dist/chunks/remote-selection-ui-W55BQDJQ.ts.map +0 -7
  308. package/dist/chunks/s3-backend-FDK7JSDQ.ts +0 -845
  309. package/dist/chunks/s3-backend-FDK7JSDQ.ts.map +0 -7
  310. package/dist/chunks/setup-switch-AB27ADDI.ts.map +0 -7
  311. package/dist/chunks/snapshot-G3W2GOGB.ts.map +0 -7
  312. package/dist/chunks/snapshot-transaction-SGRUWT73.ts +0 -25
  313. package/dist/chunks/snapshot-transaction-SGRUWT73.ts.map +0 -7
  314. package/dist/chunks/sync-inspection-MDYHZHT7.ts +0 -26
  315. package/dist/chunks/sync-inspection-MDYHZHT7.ts.map +0 -7
  316. package/dist/chunks/sync-operations-ZAUP65FH.ts +0 -1032
  317. package/dist/chunks/sync-operations-ZAUP65FH.ts.map +0 -7
  318. package/dist/chunks/sync-state-H4TFZZ7S.ts.map +0 -7
  319. package/dist/chunks/webdav-backend-UNMIAXM5.ts +0 -852
  320. package/dist/chunks/webdav-backend-UNMIAXM5.ts.map +0 -7
  321. /package/dist/chunks/{chunk-KHBPED6W.ts.map → chunk-GSQGBVKG.ts.map} +0 -0
  322. /package/dist/chunks/{chunk-PQ75RPUP.ts.map → chunk-UZUUUY7C.ts.map} +0 -0
  323. /package/dist/chunks/{agent-candidate-ZHN7FTZT.ts.map → manager-result-dispatcher-I2AMCCE7.ts.map} +0 -0
  324. /package/dist/chunks/{agent-sync-EGA2I5W7.ts.map → merge-review-SGDLMVS4.ts.map} +0 -0
  325. /package/dist/chunks/{config-J5VZUY4J.ts.map → remote-selection-ui-GZHPDQ4L.ts.map} +0 -0
  326. /package/dist/chunks/{conflict-artifacts-MYSH3L2J.ts.map → setup-switch-M3BAFGJM.ts.map} +0 -0
  327. /package/dist/chunks/{continuous-record-OM64J27R.ts.map → state-directory-JZSZVVPX.ts.map} +0 -0
@@ -1,399 +1,2 @@
1
- import { createHash, createHmac } from "node:crypto";
2
- import { setTimeout as sleep } from "node:timers/promises";
3
- import { encodeKey, posixJoin } from "../../paths.js";
4
- import { retryAfter } from "../../sync/continuous-errors.js";
5
- import type { RemoteObject, ResolvedS3Backend } from "../backend-types.js";
6
-
7
- const MAX_JSON_RESPONSE_BYTES = 1024 * 1024;
8
- const MAX_SNAPSHOT_RESPONSE_BYTES = 256 * 1024 * 1024;
9
- const MAX_ERROR_RESPONSE_BYTES = 64 * 1024;
10
- const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
11
-
12
- function iso8601Basic(date: Date) {
13
- return date.toISOString().replace(/[:-]|\.\d{3}/g, "");
14
- }
15
-
16
- function isCloudflareR2Endpoint(endpoint: string | undefined) {
17
- const value = endpoint?.trim();
18
- if (!value) return false;
19
- try {
20
- const hostname = new URL(value).hostname.toLowerCase();
21
- return hostname === "r2.cloudflarestorage.com" || hostname.endsWith(".r2.cloudflarestorage.com");
22
- } catch {
23
- return false;
24
- }
25
- }
26
-
27
- export class S3ObjectAlreadyExistsError extends Error {
28
- constructor(readonly key: string) {
29
- super(`S3 object already exists: ${key}`);
30
- this.name = "S3ObjectAlreadyExistsError";
31
- }
32
- }
33
-
34
- export class S3HttpError extends Error {
35
- constructor(
36
- message: string,
37
- readonly status: number,
38
- readonly retryAfterMs?: number,
39
- ) {
40
- super(message);
41
- this.name = "S3HttpError";
42
- }
43
- }
44
-
45
- export class S3Client {
46
- private config: ResolvedS3Backend;
47
- private endpoint: URL;
48
- private signal?: AbortSignal;
49
- private requestTimeoutMs: number;
50
- private omitSessionTokenAfterRejection = false;
51
-
52
- constructor(config: ResolvedS3Backend, signal?: AbortSignal, requestTimeoutMs = DEFAULT_REQUEST_TIMEOUT_MS) {
53
- this.config = config;
54
- this.endpoint = new URL(config.profile.endpoint);
55
- this.signal = signal;
56
- this.requestTimeoutMs = requestTimeoutMs;
57
- }
58
-
59
- /** Read-only access probe. A bare 404 cannot distinguish a missing key from a missing bucket. */
60
- async diagnoseRead(key: string): Promise<"readable" | "missing-key" | "missing-bucket" | "unknown-404"> {
61
- this.signal?.throwIfAborted();
62
- const response = await this.request("GET", key);
63
- if (response.ok) {
64
- await response.body?.cancel();
65
- this.signal?.throwIfAborted();
66
- return "readable";
67
- }
68
- const detail = await this.readErrorText(response);
69
- this.signal?.throwIfAborted();
70
- if (response.status === 404) {
71
- const code = /<Code>\s*([A-Za-z]+)\s*<\/Code>/u.exec(detail)?.[1];
72
- if (code === "NoSuchBucket") return "missing-bucket";
73
- if (code === "NoSuchKey") return "missing-key";
74
- return "unknown-404";
75
- }
76
- throw new S3HttpError(`S3 remote read failed (HTTP ${response.status}).`, response.status);
77
- }
78
-
79
- async getJson<T>(key: string): Promise<RemoteObject<T>> {
80
- const maxAttempts = 3;
81
- let lastError: unknown;
82
- for (let attempt = 1; attempt <= maxAttempts; attempt++) {
83
- const object = await this.request("GET", key);
84
- if (object.status === 404) return { missing: true };
85
- if (!object.ok) {
86
- throw new S3HttpError(
87
- `S3 GET failed (${object.status}): ${await this.readErrorText(object)}`,
88
- object.status,
89
- retryAfter(object),
90
- );
91
- }
92
- const body = await readBoundedText(object, MAX_JSON_RESPONSE_BYTES, "S3 JSON response");
93
- // R2 can intermittently return an empty 200 body (read-after-write
94
- // inconsistency on a long-lived keep-alive connection), which makes
95
- // response.json() throw "JSON Parse error: Unexpected EOF" under Bun.
96
- // Retry so the transient blip is absorbed instead of surfacing as a
97
- // "pi-sync auto sync skipped" warning on every session start.
98
- if (body.length > 0) {
99
- return {
100
- value: JSON.parse(body) as T,
101
- etag: normalizeEtag(object.headers.get("etag")),
102
- missing: false,
103
- };
104
- }
105
- lastError = new Error(`S3 GET returned an empty body for ${key}`);
106
- if (attempt < maxAttempts) {
107
- await sleep(250 * attempt, undefined, { signal: this.signal });
108
- }
109
- }
110
- throw lastError;
111
- }
112
-
113
- async getBuffer(key: string): Promise<RemoteObject<Buffer>> {
114
- const maxAttempts = 3;
115
- let lastError: unknown;
116
- for (let attempt = 1; attempt <= maxAttempts; attempt++) {
117
- const object = await this.request("GET", key);
118
- if (object.status === 404) return { missing: true };
119
- if (!object.ok) {
120
- throw new S3HttpError(
121
- `S3 GET failed (${object.status}): ${await this.readErrorText(object)}`,
122
- object.status,
123
- retryAfter(object),
124
- );
125
- }
126
- const buffer = await readBoundedBuffer(object, MAX_SNAPSHOT_RESPONSE_BYTES, "S3 snapshot response");
127
- // R2 can intermittently return an empty 200 body on a long-lived
128
- // keep-alive connection (same root cause as the getJson retry
129
- // above). getBuffer is only used for snapshot .json.gz payloads,
130
- // which are always non-empty, so an empty body is a transient
131
- // blip, not a legitimate response. Retry so the checksum guard
132
- // downstream doesn't surface it as "Remote snapshot checksum
133
- // mismatch".
134
- if (buffer.length > 0) {
135
- return { value: buffer, etag: normalizeEtag(object.headers.get("etag")), missing: false };
136
- }
137
- lastError = new Error(`S3 GET returned an empty body for ${key}`);
138
- if (attempt < maxAttempts) {
139
- await sleep(250 * attempt, undefined, { signal: this.signal });
140
- }
141
- }
142
- throw lastError;
143
- }
144
-
145
- async putJson(key: string, value: unknown, options: { ifAbsent?: boolean; ifMatch?: string } = {}) {
146
- const body = Buffer.from(JSON.stringify(value, null, "\t"), "utf8");
147
- await this.putBuffer(key, body, "application/json", options);
148
- }
149
-
150
- async putBuffer(
151
- key: string,
152
- body: Buffer,
153
- contentType: string,
154
- options: { ifAbsent?: boolean; ifMatch?: string } = {},
155
- ) {
156
- const headers: Record<string, string> = { "content-type": contentType };
157
- if (options.ifAbsent) headers["if-none-match"] = "*";
158
- if (options.ifMatch) headers["if-match"] = options.ifMatch;
159
- const response = await this.request("PUT", key, body, headers);
160
- if ((options.ifAbsent || options.ifMatch) && (response.status === 412 || response.status === 409)) {
161
- await response.body?.cancel();
162
- if (options.ifAbsent && response.status === 412) throw new S3ObjectAlreadyExistsError(key);
163
- if (options.ifAbsent || options.ifMatch) {
164
- throw new S3HttpError(`S3 conditional PUT rejected (${response.status}).`, response.status);
165
- }
166
- }
167
- if (!response.ok) {
168
- throw new S3HttpError(
169
- `S3 PUT failed (${response.status}): ${await this.readErrorText(response)}`,
170
- response.status,
171
- retryAfter(response),
172
- );
173
- }
174
- await response.body?.cancel();
175
- }
176
-
177
- async delete(key: string) {
178
- const response = await this.request("DELETE", key);
179
- if (!response.ok && response.status !== 404) {
180
- throw new S3HttpError(
181
- `S3 DELETE failed (${response.status}): ${await this.readErrorText(response)}`,
182
- response.status,
183
- retryAfter(response),
184
- );
185
- }
186
- await response.body?.cancel();
187
- }
188
-
189
- private async request(
190
- method: "GET" | "PUT" | "DELETE",
191
- key: string,
192
- body?: Buffer,
193
- extraHeaders: Record<string, string> = {},
194
- ) {
195
- const url = new URL(this.endpoint.toString());
196
- // Preserve escaped endpoint bytes without decoding or double-encoding them.
197
- // SigV4 requires uppercase escape hex, including existing endpoint escapes.
198
- const endpointPath = url.pathname
199
- .replace(/%(?![0-9A-Fa-f]{2})|[^A-Za-z0-9._~/%-]/gu, encodeKey)
200
- .replace(/%[0-9A-Fa-f]{2}/gu, (escaped) => escaped.toUpperCase());
201
- url.pathname = posixJoin(endpointPath, encodeKey(this.config.destination.bucket), encodeKey(key));
202
- const send = async (sessionToken: string | undefined) => {
203
- const transportSignal = this.transportSignal();
204
- const headers = await signedHeaders({
205
- method,
206
- url,
207
- body,
208
- // Transfer compression can weaken an object's ETag (R2 JSON responses).
209
- // Read the original representation for exact checksums and strong If-Match tokens.
210
- extraHeaders: method === "GET" ? { ...extraHeaders, "accept-encoding": "identity" } : extraHeaders,
211
- accessKeyId: this.config.profile.accessKeyId,
212
- secretAccessKey: this.config.profile.secretAccessKey,
213
- sessionToken,
214
- region: this.config.profile.region,
215
- });
216
- try {
217
- return await fetch(url, {
218
- method,
219
- headers,
220
- body: body ? new Uint8Array(body) : undefined,
221
- // Never forward signed headers or snapshot bodies to an unreviewed URL.
222
- redirect: "error",
223
- signal: transportSignal,
224
- });
225
- } catch (error) {
226
- if (error instanceof Error && error.name === "AbortError") throw error;
227
- if (error instanceof Error && error.name === "TimeoutError") {
228
- throw new Error("S3 request timed out.", { cause: error });
229
- }
230
- throw new Error(`S3 request failed: ${this.redact(errorMessage(error))}`, { cause: error });
231
- }
232
- };
233
- const sessionToken = this.omitSessionTokenAfterRejection ? undefined : this.config.profile.sessionToken;
234
- const response = await send(sessionToken);
235
- try {
236
- if (!(await this.shouldRetryWithoutSessionToken(response, sessionToken))) return response;
237
- } catch (error) {
238
- await response.body?.cancel().catch(() => undefined);
239
- throw error;
240
- }
241
- await response.body?.cancel();
242
- const retry = await send(undefined);
243
- if (retry.ok || retry.status === 404) this.omitSessionTokenAfterRejection = true;
244
- return retry;
245
- }
246
-
247
- private transportSignal() {
248
- const timeout = AbortSignal.timeout(this.requestTimeoutMs);
249
- return this.signal ? AbortSignal.any([this.signal, timeout]) : timeout;
250
- }
251
-
252
- private async shouldRetryWithoutSessionToken(response: Response, sessionToken: string | undefined) {
253
- if (
254
- !sessionToken ||
255
- !isCloudflareR2Endpoint(this.config.profile.endpoint) ||
256
- response.ok ||
257
- response.status !== 400
258
- ) {
259
- return false;
260
- }
261
- return isSecurityTokenInvalidArgument(
262
- await readBoundedText(response.clone(), MAX_ERROR_RESPONSE_BYTES, "S3 error response"),
263
- );
264
- }
265
-
266
- private async readErrorText(response: Response) {
267
- try {
268
- return this.redact(await readBoundedText(response, MAX_ERROR_RESPONSE_BYTES, "S3 error response"));
269
- } catch (error) {
270
- return this.redact(errorMessage(error));
271
- }
272
- }
273
-
274
- private redact(value: string) {
275
- let redacted = value;
276
- let endpointUsername: string | undefined;
277
- let endpointPassword: string | undefined;
278
- let endpointQueryValues: string[] = [];
279
- try {
280
- const endpoint = new URL(this.config.profile.endpoint);
281
- endpointUsername = endpoint.username;
282
- endpointPassword = endpoint.password;
283
- endpointQueryValues = [...endpoint.searchParams.values()];
284
- } catch {
285
- // The constructor already validates normal runtime endpoints.
286
- }
287
- for (const secret of [
288
- this.config.profile.accessKeyId,
289
- this.config.profile.secretAccessKey,
290
- this.config.profile.sessionToken,
291
- endpointUsername,
292
- endpointPassword,
293
- ...endpointQueryValues,
294
- ]) {
295
- if (secret) redacted = redacted.replaceAll(secret, "[REDACTED]");
296
- }
297
- return redacted;
298
- }
299
- }
300
-
301
- async function readBoundedText(response: Response, limit: number, label: string) {
302
- return (await readBoundedBuffer(response, limit, label)).toString("utf8");
303
- }
304
-
305
- async function readBoundedBuffer(response: Response, limit: number, label: string) {
306
- const contentLength = Number(response.headers.get("content-length"));
307
- if (Number.isFinite(contentLength) && contentLength > limit) {
308
- // Do not await cancellation of a cloned stream before its sibling can be released.
309
- void response.body?.cancel().catch(() => undefined);
310
- throw new Error(`${label} exceeds the ${limit}-byte limit.`);
311
- }
312
- if (!response.body) return Buffer.alloc(0);
313
- const reader = response.body.getReader();
314
- const chunks: Buffer[] = [];
315
- let total = 0;
316
- try {
317
- while (true) {
318
- const { done, value } = await reader.read();
319
- if (done) break;
320
- total += value.byteLength;
321
- if (total > limit) {
322
- void reader.cancel().catch(() => undefined);
323
- throw new Error(`${label} exceeds the ${limit}-byte limit.`);
324
- }
325
- chunks.push(Buffer.from(value));
326
- }
327
- } finally {
328
- reader.releaseLock();
329
- }
330
- return Buffer.concat(chunks, total);
331
- }
332
-
333
- function errorMessage(error: unknown) {
334
- return error instanceof Error ? error.message : String(error);
335
- }
336
-
337
- async function signedHeaders(input: {
338
- method: string;
339
- url: URL;
340
- body?: Buffer;
341
- extraHeaders: Record<string, string>;
342
- accessKeyId: string;
343
- secretAccessKey: string;
344
- sessionToken?: string;
345
- region: string;
346
- }) {
347
- const now = new Date();
348
- const amzDate = iso8601Basic(now);
349
- const dateStamp = amzDate.slice(0, 8);
350
- const payloadHash = sha256(input.body ?? Buffer.alloc(0));
351
- const headers: Record<string, string> = {
352
- ...lowercaseKeys(input.extraHeaders),
353
- host: input.url.host,
354
- "x-amz-content-sha256": payloadHash,
355
- "x-amz-date": amzDate,
356
- };
357
- if (input.sessionToken) headers["x-amz-security-token"] = input.sessionToken;
358
- const signedHeaderNames = Object.keys(headers).sort();
359
- const canonicalHeaders = signedHeaderNames.map((name) => `${name}:${headers[name]?.trim()}\n`).join("");
360
- const canonicalRequest = [
361
- input.method,
362
- input.url.pathname,
363
- input.url.searchParams.toString(),
364
- canonicalHeaders,
365
- signedHeaderNames.join(";"),
366
- payloadHash,
367
- ].join("\n");
368
- const scope = `${dateStamp}/${input.region}/s3/aws4_request`;
369
- const stringToSign = ["AWS4-HMAC-SHA256", amzDate, scope, sha256(Buffer.from(canonicalRequest))].join("\n");
370
- const signingKey = hmac(
371
- hmac(hmac(hmac(Buffer.from(`AWS4${input.secretAccessKey}`), dateStamp), input.region), "s3"),
372
- "aws4_request",
373
- );
374
- const signature = createHmac("sha256", signingKey).update(stringToSign).digest("hex");
375
- return {
376
- ...headers,
377
- authorization: `AWS4-HMAC-SHA256 Credential=${input.accessKeyId}/${scope}, SignedHeaders=${signedHeaderNames.join(";")}, Signature=${signature}`,
378
- };
379
- }
380
-
381
- function hmac(key: Buffer, value: string) {
382
- return createHmac("sha256", key).update(value).digest();
383
- }
384
-
385
- function sha256(value: Buffer) {
386
- return createHash("sha256").update(value).digest("hex");
387
- }
388
-
389
- function lowercaseKeys(value: Record<string, string>) {
390
- return Object.fromEntries(Object.entries(value).map(([key, item]) => [key.toLowerCase(), item]));
391
- }
392
-
393
- function normalizeEtag(value: string | null) {
394
- return value ?? undefined;
395
- }
396
-
397
- function isSecurityTokenInvalidArgument(text: string) {
398
- return text.includes("<Code>InvalidArgument</Code>") && text.includes("<Message>X-Amz-Security-Token</Message>");
399
- }
1
+ export type * from "@narumitw/sync-daemon/engine/backends/s3/s3-client";
2
+ export { S3Client, S3HttpError, S3ObjectAlreadyExistsError } from "@narumitw/sync-daemon/engine/backends/s3/s3-client";
@@ -1,67 +1,2 @@
1
- import { randomUUID } from "node:crypto";
2
- import { posixJoin } from "../../paths.js";
3
- import type { ResolvedS3Backend } from "../backend-types.js";
4
- import { S3Client, S3HttpError, S3ObjectAlreadyExistsError } from "./s3-client.js";
5
-
6
- export function requireS3Etag(value: string | undefined) {
7
- if (!value || !/^"[^"\r\n]+"$/u.test(value)) throw new Error("S3 conditional publication requires a strong ETag.");
8
- return value;
9
- }
10
-
11
- /** Never probe the active pointer or immutable snapshots; ignored conditions must not corrupt either. */
12
- export async function verifyS3Conditions(config: ResolvedS3Backend, signal?: AbortSignal) {
13
- const key = posixJoin(
14
- config.destination.prefix === "./" ? "" : config.destination.prefix,
15
- ".pi-sync-probes",
16
- randomUUID(),
17
- );
18
- const client = new S3Client(config, signal);
19
- let failure: unknown;
20
- let attempted = false;
21
- try {
22
- signal?.throwIfAborted();
23
- attempted = true;
24
- await client.putBuffer(key, Buffer.from("first"), "text/plain", { ifAbsent: true });
25
- const first = await client.getBuffer(key);
26
- const etag = requireS3Etag(first.etag);
27
- if (!first.value?.equals(Buffer.from("first"))) throw new Error("S3 conditional probe read did not match.");
28
- await expectRejected(client.putBuffer(key, Buffer.from("ignored"), "text/plain", { ifAbsent: true }));
29
- await expectRejected(client.putBuffer(key, Buffer.from("ignored"), "text/plain", { ifMatch: '"pi-sync-stale"' }));
30
- const unchanged = await client.getBuffer(key);
31
- if (!unchanged.value?.equals(first.value) || unchanged.etag !== etag)
32
- throw new Error("S3 failed precondition changed the probe.");
33
- await client.putBuffer(key, Buffer.from("second"), "text/plain", { ifMatch: etag });
34
- const second = await client.getBuffer(key);
35
- if (!second.value?.equals(Buffer.from("second")) || requireS3Etag(second.etag) === etag) {
36
- throw new Error("S3 conditional write did not rotate the probe ETag.");
37
- }
38
- await expectRejected(client.putBuffer(key, Buffer.from("ignored"), "text/plain", { ifMatch: etag }));
39
- const final = await client.getBuffer(key);
40
- if (!final.value?.equals(second.value) || final.etag !== second.etag)
41
- throw new Error("S3 stale ETag changed the probe.");
42
- signal?.throwIfAborted();
43
- } catch (error) {
44
- failure = error;
45
- }
46
- // Cleanup has its own bounded deadline even when the owning session was cancelled.
47
- if (attempted) {
48
- try {
49
- await new S3Client(config, AbortSignal.timeout(10_000)).delete(key);
50
- } catch (error) {
51
- throw new Error(`S3 probe cleanup failed; remove ${key}.`, { cause: failure ?? error });
52
- }
53
- }
54
- if (failure) throw failure;
55
- signal?.throwIfAborted();
56
- }
57
-
58
- async function expectRejected(operation: Promise<void>) {
59
- try {
60
- await operation;
61
- } catch (error) {
62
- // 409 is retryable contention, not proof that a failed condition was enforced.
63
- if (error instanceof S3ObjectAlreadyExistsError || (error instanceof S3HttpError && error.status === 412)) return;
64
- throw error;
65
- }
66
- throw new Error("S3 server ignored a write precondition; publication stopped for safety.");
67
- }
1
+ export type * from "@narumitw/sync-daemon/engine/backends/s3/s3-conditions";
2
+ export { requireS3Etag, verifyS3Conditions } from "@narumitw/sync-daemon/engine/backends/s3/s3-conditions";
@@ -1,27 +1,2 @@
1
- import type { Snapshot } from "../snapshot/snapshot-types.js";
2
- import type { LatestPointer } from "./backend-types.js";
3
- import type { RemoteHistoryEntry } from "./sync-backend.js";
4
-
5
- /** Shared latest/history metadata for the S3 and WebDAV object-store format. */
6
- export function createLatestPointer(namespace: string, snapshot: Snapshot, checksum: string): LatestPointer {
7
- return {
8
- version: 1,
9
- profile: namespace,
10
- snapshot: snapshot.id,
11
- sha256: checksum,
12
- createdAt: snapshot.createdAt,
13
- machine: snapshot.machine,
14
- syncSessions: snapshot.syncSessions === true || snapshot.files.some((file) => file.path.startsWith("sessions/")),
15
- ...(snapshot.selection === undefined ? {} : { selection: snapshot.selection }),
16
- };
17
- }
18
-
19
- export function remoteHistoryEntry(pointer: LatestPointer): RemoteHistoryEntry {
20
- return {
21
- snapshotRef: pointer.snapshot,
22
- snapshotId: pointer.snapshot,
23
- createdAt: pointer.createdAt,
24
- machine: pointer.machine,
25
- syncSessions: pointer.syncSessions === true,
26
- };
27
- }
1
+ export type * from "@narumitw/sync-daemon/engine/backends/snapshot-pointer";
2
+ export { createLatestPointer, remoteHistoryEntry } from "@narumitw/sync-daemon/engine/backends/snapshot-pointer";
@@ -1,101 +1,6 @@
1
- import type { Snapshot, SnapshotSelection } from "../snapshot/snapshot-types.js";
2
-
3
- export type PublicationCapability =
4
- | "read-check-write-verify"
5
- | "conditional-required"
6
- | "atomic-conditional"
7
- | "lease-protected";
8
-
9
- export interface RemoteHead {
10
- /** Backend-owned reference used only to retrieve this immutable snapshot. */
11
- snapshotRef: string;
12
- /** Backend-neutral snapshot content identity retained in local sync state. */
13
- snapshotId: string;
14
- revision: string;
15
- createdAt: string;
16
- machine: string;
17
- syncSessions: boolean;
18
- /** Validated lightweight projection; revalidate it against the immutable snapshot before adoption. */
19
- selection?: SnapshotSelection;
20
- }
21
-
22
- export interface RemoteHistoryEntry {
23
- snapshotRef: string;
24
- snapshotId: string;
25
- createdAt: string;
26
- machine: string;
27
- syncSessions: boolean;
28
- }
29
-
30
- export type ExpectedRemoteHead = { kind: "missing" } | { kind: "revision"; revision: string };
31
-
32
- export interface PublishSnapshotOptions {
33
- signal?: AbortSignal;
34
- /** Called at the backend's active-head commit boundary. */
35
- onCommit?: () => void;
36
- }
37
-
38
- export interface PublishSnapshotResult {
39
- head: RemoteHead;
40
- warnings: string[];
41
- }
42
-
43
- export interface BackendDiagnostic {
44
- key: string;
45
- level: "info" | "warning" | "error";
46
- message: string;
47
- }
48
-
49
- export interface SyncBackend {
50
- readonly identity: string;
51
- readonly destination: string;
52
- readonly capability: PublicationCapability;
53
- /** Compare opaque revisions produced by this backend identity. */
54
- sameRevision(left: string, right: string): boolean;
55
- /** Recovery-only equivalence for retiring an inactive candidate; never authorizes publication or apply. */
56
- matchesUncommittedRecoveryHead?(current: RemoteHead, recorded: RemoteHead): boolean;
57
- readHead(signal?: AbortSignal): Promise<RemoteHead | undefined>;
58
- readSnapshot(reference: string, signal?: AbortSignal): Promise<Snapshot>;
59
- publishSnapshot(
60
- snapshot: Snapshot,
61
- expected: ExpectedRemoteHead,
62
- options?: PublishSnapshotOptions,
63
- ): Promise<PublishSnapshotResult>;
64
- listHistory(signal?: AbortSignal): Promise<RemoteHistoryEntry[]>;
65
- diagnose(signal?: AbortSignal): Promise<BackendDiagnostic[]>;
66
- }
67
-
68
- export class SyncBackendConflictError extends Error {
69
- readonly code = "SYNC_BACKEND_CONFLICT";
70
- readonly phase: "before-commit" | "after-commit";
71
- readonly currentHead?: RemoteHead;
72
- readonly candidateMayHaveBeenActive: boolean;
73
-
74
- constructor(
75
- message: string,
76
- options: ErrorOptions & {
77
- phase?: "before-commit" | "after-commit";
78
- currentHead?: RemoteHead;
79
- candidateMayHaveBeenActive?: boolean;
80
- } = {},
81
- ) {
82
- super(message, options);
83
- this.name = "SyncBackendConflictError";
84
- this.phase = options.phase ?? "before-commit";
85
- this.currentHead = options.currentHead;
86
- this.candidateMayHaveBeenActive = options.candidateMayHaveBeenActive ?? false;
87
- }
88
- }
89
-
90
- export class SyncBackendPublicationOutcomeUnknownError extends Error {
91
- readonly code = "SYNC_BACKEND_PUBLICATION_OUTCOME_UNKNOWN";
92
-
93
- constructor(message: string, options?: ErrorOptions) {
94
- super(message, options);
95
- this.name = "SyncBackendPublicationOutcomeUnknownError";
96
- }
97
- }
98
-
99
- export function expectedRemoteHead(head: RemoteHead | undefined): ExpectedRemoteHead {
100
- return head ? { kind: "revision", revision: head.revision } : { kind: "missing" };
101
- }
1
+ export type * from "@narumitw/sync-daemon/engine/backends/sync-backend";
2
+ export {
3
+ expectedRemoteHead,
4
+ SyncBackendConflictError,
5
+ SyncBackendPublicationOutcomeUnknownError,
6
+ } from "@narumitw/sync-daemon/engine/backends/sync-backend";