@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,1184 +0,0 @@
1
- // @generated by scripts/build-runtime.mjs; do not edit.
2
- // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
- import {
4
- normalizeLocalFields
5
- } from "./chunk-X7R6DCVF.ts";
6
- import {
7
- backendIdentityCoordinates,
8
- normalizeEndpointIdentity,
9
- normalizeWebDavIdentityUrl,
10
- normalizeWebDavPath,
11
- normalizeWebDavUrl,
12
- validateWebDavCredentials
13
- } from "./chunk-2JZFHNLM.ts";
14
- import {
15
- normalizeGitBranch,
16
- normalizeGitDirectory,
17
- normalizeGitRemote,
18
- normalizeGitRemoteIdentity
19
- } from "./chunk-T2SJD3N7.ts";
20
- import {
21
- normalizeSyncInclude,
22
- syncSessionsSelected
23
- } from "./chunk-WUHRVSWI.ts";
24
- import {
25
- normalizeSyncExclude
26
- } from "./chunk-3JTZF7Z5.ts";
27
-
28
- // src/settings/config.ts
29
- import { createHash } from "node:crypto";
30
-
31
- // src/settings/config-file.ts
32
- import { randomUUID } from "node:crypto";
33
- import {
34
- mkdir,
35
- mkdirSync,
36
- realpath,
37
- realpathSync,
38
- rmdir,
39
- rmdirSync,
40
- stat,
41
- statSync,
42
- utimes,
43
- utimesSync
44
- } from "node:fs";
45
- import fs from "node:fs/promises";
46
- import path from "node:path";
47
- import { getAgentDir } from "@earendil-works/pi-coding-agent";
48
- import lockfile from "proper-lockfile";
49
- var CONFIG_FILE_NAME = "pi-sync.json";
50
- var LEGACY_CONFIG_FILE_NAME = "pi-sync.local.json";
51
- var configMigrationNotices = /* @__PURE__ */ new Map();
52
- var legacyPresenceNoticed = /* @__PURE__ */ new Set();
53
- var CONFIG_LOCK_STALE_MS = 3e4;
54
- var CONFIG_LOCK_UPDATE_MS = 1e4;
55
- var LOCKFILE_FS_ADAPTER = {
56
- mkdir,
57
- mkdirSync,
58
- realpath,
59
- realpathSync,
60
- rmdir,
61
- rmdirSync,
62
- stat,
63
- statSync,
64
- utimes,
65
- utimesSync
66
- };
67
- var configUpdateQueue = Promise.resolve();
68
- var publishConfigFile = publishFileWithGuard;
69
- var beforeConfigPublicationHook = async () => void 0;
70
- var afterMissingConfigReadProbeHook = async () => void 0;
71
- var afterReplacementInstalledHook = async () => void 0;
72
- var afterConfigQuarantinedHook = async () => void 0;
73
- function localConfigPath() {
74
- return path.join(getAgentDir(), CONFIG_FILE_NAME);
75
- }
76
- function legacyLocalConfigPath() {
77
- return path.join(getAgentDir(), LEGACY_CONFIG_FILE_NAME);
78
- }
79
- async function activeLocalConfigPath() {
80
- const canonicalPath = localConfigPath();
81
- const legacyPath = legacyLocalConfigPath();
82
- return queueConfigOperation(
83
- () => withLocalConfigReadLockIfNeeded(async () => {
84
- if (await pathExists(canonicalPath)) return canonicalPath;
85
- return await pathExists(legacyPath) ? legacyPath : canonicalPath;
86
- })
87
- );
88
- }
89
- function consumeLocalConfigMigrationNotice() {
90
- const configPath = localConfigPath();
91
- const notice = configMigrationNotices.get(configPath);
92
- configMigrationNotices.delete(configPath);
93
- return notice;
94
- }
95
- async function readActiveLocalConfigDocumentForRepair() {
96
- const canonicalPath = localConfigPath();
97
- const legacyPath = legacyLocalConfigPath();
98
- return queueConfigOperation(
99
- () => withLocalConfigReadLockIfNeeded(async () => {
100
- const filePath = await pathExists(canonicalPath) ? canonicalPath : legacyPath;
101
- const snapshot = await readConfigSnapshotIfExists(filePath);
102
- return snapshot ? { path: filePath, ...snapshot } : void 0;
103
- })
104
- );
105
- }
106
- async function readMigratingLocalConfigDocument(validateForMigration) {
107
- return queueConfigOperation(
108
- () => withLocalConfigReadLockIfNeeded(async () => {
109
- const configPath = await prepareLocalConfigPath(validateForMigration);
110
- const snapshot = await readConfigSnapshotIfExists(configPath);
111
- return snapshot ? { path: configPath, ...snapshot } : void 0;
112
- })
113
- );
114
- }
115
- async function withLocalConfigReadLockIfNeeded(read) {
116
- if (await pathExists(localConfigPath()) || await pathExists(legacyLocalConfigPath())) {
117
- return withLocalConfigFileLock(read);
118
- }
119
- await afterMissingConfigReadProbeHook();
120
- if (await pathExists(configMutationLockPath())) return withLocalConfigFileLock(read);
121
- await assertNoInterruptedConfigReplacement();
122
- return read();
123
- }
124
- function queueConfigOperation(run) {
125
- const operation = configUpdateQueue.then(run);
126
- configUpdateQueue = operation.then(
127
- () => void 0,
128
- () => void 0
129
- );
130
- return operation;
131
- }
132
- function updateLocalConfigDocument(defaultValue, update, validate, signal) {
133
- return queueConfigOperation(() => {
134
- signal?.throwIfAborted();
135
- return withLocalConfigFileLock(async () => {
136
- signal?.throwIfAborted();
137
- const configPath = await prepareLocalConfigPath(validate);
138
- signal?.throwIfAborted();
139
- const snapshot = await readConfigSnapshotIfExists(configPath);
140
- signal?.throwIfAborted();
141
- const document = snapshot ? { path: configPath, ...snapshot } : void 0;
142
- const current = document ? structuredClone(document.parsed) : structuredClone(defaultValue);
143
- const next = update(current);
144
- validate(next);
145
- signal?.throwIfAborted();
146
- if (document && JSON.stringify(document.parsed) === JSON.stringify(next)) return next;
147
- if (document) await replaceLocalConfigDocumentUnlocked(document, next, signal);
148
- else await installPrivateConfigExclusively(localConfigPath(), serializedConfig(next), signal);
149
- return next;
150
- });
151
- });
152
- }
153
- function createLocalConfigDocument(value, signal) {
154
- return queueConfigOperation(() => {
155
- signal?.throwIfAborted();
156
- return withLocalConfigFileLock(async () => {
157
- signal?.throwIfAborted();
158
- const bytes = serializedConfig(value);
159
- try {
160
- await installPrivateConfigExclusively(localConfigPath(), bytes, signal);
161
- } catch (error) {
162
- if (error.code === "EEXIST") {
163
- throw new Error("Pi-sync settings were created concurrently; reopen settings and retry.");
164
- }
165
- throw error;
166
- }
167
- });
168
- });
169
- }
170
- async function replaceLocalConfigDocumentUnlocked(document, value, signal) {
171
- const nextBytes = serializedConfig(value);
172
- const canonicalPath = localConfigPath();
173
- if (document.path !== canonicalPath) {
174
- if (!await configDocumentStillMatches(document)) throw settingsChangedError();
175
- let installed;
176
- try {
177
- installed = await installPrivateConfigExclusively(canonicalPath, nextBytes, signal);
178
- } catch (error) {
179
- if (error.code === "EEXIST") {
180
- throw new Error("Canonical settings were created concurrently; no settings were replaced.");
181
- }
182
- throw error;
183
- }
184
- if (!await configDocumentStillMatches(document)) {
185
- await quarantineAndRemoveConfigIfMatchesUnlocked(canonicalPath, installed, nextBytes);
186
- throw settingsChangedError();
187
- }
188
- return;
189
- }
190
- const recoveryPath = path.join(
191
- path.dirname(canonicalPath),
192
- `.${path.basename(canonicalPath)}.${randomUUID()}.schema-migration-source`
193
- );
194
- const previousHandle = await fs.open(canonicalPath, "r");
195
- try {
196
- const previous = await previousHandle.stat();
197
- if (previous.dev !== document.identity.dev || previous.ino !== document.identity.ino) {
198
- throw settingsChangedError();
199
- }
200
- await writePrivateConfigBytes(recoveryPath, document.bytes, "wx");
201
- await syncParentDirectory(canonicalPath);
202
- await withPrivateConfigTemporary(canonicalPath, nextBytes, async (temporaryPath, installed) => {
203
- let published = false;
204
- let previousBytesRead;
205
- const readPreviousBytes = () => previousBytesRead ??= previousHandle.readFile();
206
- try {
207
- signal?.throwIfAborted();
208
- await publishConfigFile(temporaryPath, canonicalPath, document, signal);
209
- published = true;
210
- await syncParentDirectory(canonicalPath);
211
- await afterReplacementInstalledHook();
212
- if (!(await readPreviousBytes()).equals(document.bytes)) throw settingsChangedError();
213
- if (!await fileIdentityAndContentsMatch(canonicalPath, installed, nextBytes)) {
214
- throw settingsChangedError();
215
- }
216
- } catch (error) {
217
- if (published || await fileIdentityAndContentsMatch(canonicalPath, installed, nextBytes)) {
218
- const previousBytes = await readPreviousBytes().catch(() => document.bytes);
219
- if (!previousBytes.equals(document.bytes)) {
220
- await writePrivateConfigBytes(recoveryPath, previousBytes, "w");
221
- }
222
- if (await fileIdentityAndContentsMatch(canonicalPath, installed, nextBytes)) {
223
- await fs.rename(recoveryPath, canonicalPath);
224
- await syncParentDirectory(canonicalPath);
225
- }
226
- } else if (await configDocumentStillMatches(document)) {
227
- await fs.rm(recoveryPath);
228
- }
229
- if (error.code === "EEXIST") {
230
- throw new Error("Canonical settings changed concurrently; no settings were replaced.");
231
- }
232
- throw error;
233
- }
234
- });
235
- await fs.rm(recoveryPath).catch(() => void 0);
236
- await syncParentDirectory(canonicalPath).catch(() => void 0);
237
- } catch (error) {
238
- if (await configDocumentStillMatches(document)) {
239
- await fs.rm(recoveryPath, { force: true }).catch(() => void 0);
240
- }
241
- throw error;
242
- } finally {
243
- await previousHandle.close().catch(() => void 0);
244
- }
245
- }
246
- async function prepareLocalConfigPath(validateForMigration) {
247
- const canonicalPath = localConfigPath();
248
- const legacyPath = legacyLocalConfigPath();
249
- if (await pathExists(canonicalPath)) {
250
- const legacyStatus = await secureIgnoredLegacyIfPresent(legacyPath);
251
- if (legacyStatus !== "missing" && !legacyPresenceNoticed.has(canonicalPath)) {
252
- legacyPresenceNoticed.add(canonicalPath);
253
- recordConfigMigrationNotice(
254
- canonicalPath,
255
- legacyStatus === "private" ? `${LEGACY_CONFIG_FILE_NAME} legacy settings were ignored because ${CONFIG_FILE_NAME} takes precedence. Delete ${LEGACY_CONFIG_FILE_NAME} after confirming your settings.` : `${LEGACY_CONFIG_FILE_NAME} legacy settings were ignored because ${CONFIG_FILE_NAME} takes precedence, but pi-sync could not verify them as a private regular file. Secure or delete the legacy path after confirming your settings.`
256
- );
257
- }
258
- return canonicalPath;
259
- }
260
- const legacy = await readConfigSnapshotIfExists(legacyPath);
261
- if (!legacy) return canonicalPath;
262
- validateForMigration(legacy.parsed);
263
- let installedIdentity;
264
- try {
265
- installedIdentity = await installPrivateConfigExclusively(canonicalPath, legacy.bytes);
266
- } catch (error) {
267
- if (error.code === "EEXIST") {
268
- recordConfigMigrationNotice(
269
- canonicalPath,
270
- `${LEGACY_CONFIG_FILE_NAME} legacy settings were ignored because ${CONFIG_FILE_NAME} was created concurrently and takes precedence.`
271
- );
272
- return canonicalPath;
273
- }
274
- recordConfigMigrationNotice(
275
- canonicalPath,
276
- `Could not migrate ${LEGACY_CONFIG_FILE_NAME} to ${CONFIG_FILE_NAME}; the legacy settings were used for this session and were not changed.`
277
- );
278
- return legacyPath;
279
- }
280
- if (!await configSnapshotStillMatches(legacyPath, legacy)) {
281
- const removed = await quarantineAndRemoveConfigIfMatchesUnlocked(canonicalPath, installedIdentity, legacy.bytes);
282
- recordConfigMigrationNotice(
283
- canonicalPath,
284
- removed ? `${LEGACY_CONFIG_FILE_NAME} changed during migration; the stale ${CONFIG_FILE_NAME} copy was removed and the legacy settings were used for this session.` : `${LEGACY_CONFIG_FILE_NAME} changed during migration, but ${CONFIG_FILE_NAME} was replaced concurrently and takes precedence.`
285
- );
286
- return removed ? legacyPath : canonicalPath;
287
- }
288
- legacyPresenceNoticed.add(canonicalPath);
289
- recordConfigMigrationNotice(
290
- canonicalPath,
291
- `pi-sync settings migrated from ${LEGACY_CONFIG_FILE_NAME} to ${CONFIG_FILE_NAME}; the private legacy file was retained as a recovery copy and can be deleted after verification.`
292
- );
293
- return canonicalPath;
294
- }
295
- async function secureIgnoredLegacyIfPresent(filePath) {
296
- let pathStat;
297
- try {
298
- pathStat = await fs.lstat(filePath);
299
- } catch (error) {
300
- if (error.code === "ENOENT") return "missing";
301
- return "unsafe";
302
- }
303
- if (pathStat.isSymbolicLink() || !pathStat.isFile()) return "unsafe";
304
- let handle;
305
- try {
306
- handle = await fs.open(filePath, "r");
307
- const openedStat = await handle.stat();
308
- if (openedStat.dev !== pathStat.dev || openedStat.ino !== pathStat.ino) {
309
- return "unsafe";
310
- }
311
- if (process.platform !== "win32" && (openedStat.mode & 511) !== 384) {
312
- await handle.chmod(384);
313
- }
314
- return "private";
315
- } catch {
316
- return "unsafe";
317
- } finally {
318
- await handle?.close().catch(() => void 0);
319
- }
320
- }
321
- async function readConfigSnapshotIfExists(filePath) {
322
- let pathStat;
323
- try {
324
- pathStat = await fs.lstat(filePath);
325
- } catch (error) {
326
- if (error.code === "ENOENT") return void 0;
327
- throw error;
328
- }
329
- if (pathStat.isSymbolicLink()) {
330
- throw new Error(`Refusing to read symlinked pi-sync config: ${filePath}`);
331
- }
332
- if (!pathStat.isFile()) throw new Error(`pi-sync config is not a regular file: ${filePath}`);
333
- const handle = await fs.open(filePath, "r");
334
- try {
335
- const openedStat = await handle.stat();
336
- if (openedStat.dev !== pathStat.dev || openedStat.ino !== pathStat.ino) {
337
- throw new Error(`pi-sync config changed while opening: ${filePath}`);
338
- }
339
- if (process.platform !== "win32" && (openedStat.mode & 511) !== 384) {
340
- await handle.chmod(384);
341
- }
342
- const bytes = await handle.readFile();
343
- return {
344
- bytes,
345
- identity: { dev: openedStat.dev, ino: openedStat.ino },
346
- parsed: parseConfigObject(bytes, filePath)
347
- };
348
- } finally {
349
- await handle.close();
350
- }
351
- }
352
- function serializedConfig(value) {
353
- return Buffer.from(`${JSON.stringify(value, null, " ")}
354
- `, "utf8");
355
- }
356
- function parseConfigObject(bytes, filePath) {
357
- let parsed;
358
- try {
359
- parsed = JSON.parse(bytes.toString("utf8"));
360
- } catch {
361
- throw new SyntaxError(`Invalid JSON in pi-sync config: ${filePath}`);
362
- }
363
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
364
- throw new Error(`pi-sync config must contain a JSON object: ${filePath}`);
365
- }
366
- return parsed;
367
- }
368
- async function installPrivateConfigExclusively(filePath, bytes, signal) {
369
- return withPrivateConfigTemporary(filePath, bytes, async (temporaryPath, installed) => {
370
- signal?.throwIfAborted();
371
- await publishConfigFile(temporaryPath, filePath, void 0, signal);
372
- try {
373
- if (!await fileIdentityAndContentsMatch(filePath, installed, bytes)) {
374
- throw new Error(`Published pi-sync settings changed concurrently: ${filePath}`);
375
- }
376
- await syncParentDirectory(filePath);
377
- } catch (error) {
378
- await quarantineAndRemoveConfigIfMatchesUnlocked(filePath, installed, bytes);
379
- throw error;
380
- }
381
- return installed;
382
- });
383
- }
384
- async function withPrivateConfigTemporary(filePath, bytes, publish) {
385
- await fs.mkdir(path.dirname(filePath), { recursive: true });
386
- const temporaryPath = path.join(
387
- path.dirname(filePath),
388
- `.${path.basename(filePath)}.${process.pid}.${randomUUID()}.migrate`
389
- );
390
- try {
391
- const identity = await writePrivateConfigBytes(temporaryPath, bytes, "wx");
392
- return await publish(temporaryPath, identity);
393
- } finally {
394
- await fs.rm(temporaryPath, { force: true }).catch(() => void 0);
395
- }
396
- }
397
- async function writePrivateConfigBytes(filePath, bytes, flags) {
398
- const handle = await fs.open(filePath, flags, 384);
399
- try {
400
- await handle.writeFile(bytes);
401
- if (process.platform !== "win32") await handle.chmod(384);
402
- await handle.sync();
403
- const installed = await handle.stat();
404
- return { dev: installed.dev, ino: installed.ino };
405
- } finally {
406
- await handle.close();
407
- }
408
- }
409
- async function configDocumentStillMatches(document) {
410
- return fileIdentityAndContentsMatch(document.path, document.identity, document.bytes);
411
- }
412
- function settingsChangedError() {
413
- return new Error("pi-sync settings changed during migration; no settings were replaced.");
414
- }
415
- async function configSnapshotStillMatches(filePath, snapshot) {
416
- return fileIdentityAndContentsMatch(filePath, snapshot.identity, snapshot.bytes);
417
- }
418
- async function quarantineAndRemoveConfigIfMatchesUnlocked(filePath, identity, expectedBytes) {
419
- const quarantinePath = path.join(
420
- path.dirname(filePath),
421
- `.${path.basename(filePath)}.${randomUUID()}.migration-retired`
422
- );
423
- try {
424
- await fs.rename(filePath, quarantinePath);
425
- } catch {
426
- return false;
427
- }
428
- await afterConfigQuarantinedHook();
429
- try {
430
- await syncParentDirectory(filePath);
431
- } catch {
432
- await restoreQuarantinedConfig(filePath, quarantinePath);
433
- return false;
434
- }
435
- const matches = await fileIdentityAndContentsMatch(quarantinePath, identity, expectedBytes);
436
- if (!matches) {
437
- await restoreQuarantinedConfig(filePath, quarantinePath);
438
- return false;
439
- }
440
- if (await pathExists(filePath)) {
441
- await fs.rm(quarantinePath, { force: true });
442
- await syncParentDirectory(filePath);
443
- return false;
444
- }
445
- await fs.rm(quarantinePath);
446
- await syncParentDirectory(filePath);
447
- return true;
448
- }
449
- async function fileIdentityAndContentsMatch(filePath, identity, expectedBytes) {
450
- try {
451
- const current = await fs.lstat(filePath);
452
- if (current.isSymbolicLink()) return false;
453
- if (current.dev !== identity.dev || current.ino !== identity.ino) return false;
454
- return (await fs.readFile(filePath)).equals(expectedBytes);
455
- } catch {
456
- return false;
457
- }
458
- }
459
- async function restoreQuarantinedConfig(filePath, quarantinePath) {
460
- try {
461
- await renameFileWithoutReplacement(quarantinePath, filePath);
462
- if (process.platform !== "win32") await fs.chmod(filePath, 384);
463
- await syncParentDirectory(filePath);
464
- return;
465
- } catch (error) {
466
- if (error.code !== "EEXIST") return;
467
- }
468
- try {
469
- if (process.platform !== "win32") await fs.chmod(quarantinePath, 384);
470
- await syncParentDirectory(filePath);
471
- } catch {
472
- }
473
- }
474
- function configMutationLockPath() {
475
- return `${localConfigPath()}.mutation-lock`;
476
- }
477
- async function withLocalConfigFileLock(run) {
478
- const configPath = localConfigPath();
479
- await fs.mkdir(path.dirname(configPath), { recursive: true });
480
- let compromisedError;
481
- const release = await lockfile.lock(configPath, {
482
- fs: LOCKFILE_FS_ADAPTER,
483
- lockfilePath: configMutationLockPath(),
484
- realpath: false,
485
- stale: CONFIG_LOCK_STALE_MS,
486
- update: CONFIG_LOCK_UPDATE_MS,
487
- retries: { retries: 100, factor: 1.2, minTimeout: 10, maxTimeout: 100 },
488
- onCompromised: (error) => {
489
- compromisedError = error;
490
- }
491
- });
492
- try {
493
- await assertNoInterruptedConfigReplacement();
494
- const result = await run();
495
- if (compromisedError) throw compromisedError;
496
- return result;
497
- } finally {
498
- await release();
499
- }
500
- }
501
- async function syncParentDirectory(filePath) {
502
- if (process.platform === "win32") return;
503
- let handle;
504
- try {
505
- handle = await fs.open(path.dirname(filePath), "r");
506
- await handle.sync();
507
- } finally {
508
- await handle?.close().catch(() => void 0);
509
- }
510
- }
511
- async function publishFileWithGuard(source, destination, expected, signal) {
512
- await beforeConfigPublicationHook();
513
- signal?.throwIfAborted();
514
- if (expected) {
515
- if (!await configDocumentStillMatches(expected)) throw settingsChangedError();
516
- signal?.throwIfAborted();
517
- await fs.rename(source, destination);
518
- } else {
519
- await renameFileWithoutReplacement(source, destination, signal);
520
- }
521
- }
522
- async function renameFileWithoutReplacement(source, destination, signal) {
523
- if (await pathExists(destination)) {
524
- throw Object.assign(new Error(`Settings already exist: ${destination}`), { code: "EEXIST" });
525
- }
526
- signal?.throwIfAborted();
527
- await fs.rename(source, destination);
528
- }
529
- async function assertNoInterruptedConfigReplacement() {
530
- const configPath = localConfigPath();
531
- if (await pathExists(configPath)) return;
532
- let names;
533
- try {
534
- names = await fs.readdir(path.dirname(configPath));
535
- } catch (error) {
536
- if (error.code === "ENOENT") return;
537
- throw error;
538
- }
539
- const prefix = `.${path.basename(configPath)}.`;
540
- if (names.some(
541
- (name) => name.startsWith(prefix) && (name.endsWith(".schema-migration-source") || name.endsWith(".migration-retired"))
542
- )) {
543
- throw new Error(
544
- "Interrupted pi-sync settings replacement: restore the retained recovery file to pi-sync.json before retrying; legacy settings were not loaded."
545
- );
546
- }
547
- }
548
- async function pathExists(filePath) {
549
- try {
550
- await fs.lstat(filePath);
551
- return true;
552
- } catch (error) {
553
- if (error.code === "ENOENT") return false;
554
- throw error;
555
- }
556
- }
557
- function recordConfigMigrationNotice(configPath, notice) {
558
- if (!configMigrationNotices.has(configPath)) configMigrationNotices.set(configPath, notice);
559
- }
560
-
561
- // src/settings/settings-validation.ts
562
- import path2 from "node:path";
563
- var DEFAULT_ON_SWITCH = "ask-before-pull";
564
- function normalizeOnSwitch(value) {
565
- if (value === "ask-before-pull" || value === "pull-after-switch" || value === "switch-only") {
566
- return value;
567
- }
568
- throw new Error(
569
- 'Invalid pi-sync settings: onSwitch must be "ask-before-pull", "pull-after-switch", or "switch-only".'
570
- );
571
- }
572
- function validateSettingsDocument(value) {
573
- if (value.version !== 3 && value.version !== 4 && value.version !== 5 && value.version !== 6) {
574
- throw new Error(
575
- `Unsupported pi-sync settings: version 3, 4, 5 or 6 is required. Keep the existing ${path2.basename(localConfigPath())} for recovery and use a compatible pi-sync client or review a separate supported setup; do not downgrade portable field policies. pi-sync will not migrate or overwrite unsupported settings.`
576
- );
577
- }
578
- rejectLegacyFields(
579
- value,
580
- [
581
- "profiles",
582
- "targets",
583
- "activeTarget",
584
- "targetSwitchAction",
585
- "endpoint",
586
- "bucket",
587
- "region",
588
- "accessKeyId",
589
- "secretAccessKey",
590
- "sessionToken",
591
- "profile",
592
- "prefix",
593
- "autoSync",
594
- "syncFiles",
595
- "syncSessions",
596
- "extraFiles"
597
- ],
598
- "top level"
599
- );
600
- normalizeOnSwitch(value.onSwitch);
601
- if (value.skipSecretScan !== void 0 && typeof value.skipSecretScan !== "boolean") {
602
- throw new Error("Invalid pi-sync settings: skipSecretScan must be boolean.");
603
- }
604
- if (value.showStatus !== void 0 && typeof value.showStatus !== "boolean") {
605
- throw new Error("Invalid pi-sync settings: showStatus must be boolean.");
606
- }
607
- if (value.debug !== void 0 && typeof value.debug !== "boolean") {
608
- throw new Error("Invalid pi-sync settings: debug must be boolean.");
609
- }
610
- const storageConnections = requireNamedObjectMap(
611
- value.storageConnections,
612
- "storageConnections",
613
- "storage connection"
614
- );
615
- const syncSetups = requireNamedObjectMap(value.syncSetups, "syncSetups", "sync setup");
616
- for (const name of Object.keys(storageConnections)) {
617
- validateStorageConnection(
618
- name,
619
- requireOwnObject(storageConnections, name, "storage connection")
620
- );
621
- }
622
- for (const name of Object.keys(syncSetups)) {
623
- validateSyncSetup(
624
- name,
625
- requireOwnObject(syncSetups, name, "sync setup"),
626
- storageConnections
627
- );
628
- }
629
- const names = Object.keys(syncSetups);
630
- const activeSyncSetup = optionalCanonicalReference(value.activeSyncSetup, "activeSyncSetup");
631
- if (names.length === 0) {
632
- if (activeSyncSetup !== void 0) {
633
- throw new Error("Invalid pi-sync settings: empty syncSetups cannot have activeSyncSetup.");
634
- }
635
- } else if (!activeSyncSetup || !Object.hasOwn(syncSetups, activeSyncSetup)) {
636
- throw new Error("Invalid pi-sync settings: activeSyncSetup must reference an existing own-property sync setup.");
637
- }
638
- for (const setup of Object.values(syncSetups)) {
639
- const policy = setup.sync;
640
- if (policy.localFields !== void 0 && value.version !== 4 && value.version !== 5 && value.version !== 6)
641
- throw new Error("localFields requires explicit settings version 4; older binaries must refuse portable state.");
642
- }
643
- for (const setup of Object.values(syncSetups)) {
644
- const policy = setup.sync;
645
- if (policy.exclude !== void 0 && value.version !== 6)
646
- throw new Error("sync.exclude requires explicit settings version 6; older clients must refuse excluded content.");
647
- if ((policy.mergeContent || policy.partialSync) && value.version !== 5 && value.version !== 6)
648
- throw new Error("Content/partial sync requires explicit settings version 5.");
649
- }
650
- validateUniqueRemoteSyncSetups(syncSetups, storageConnections);
651
- return value;
652
- }
653
- function validateStorageConnection(name, value) {
654
- rejectLegacyFields(
655
- value,
656
- ["kind", "accessKeyId", "secretAccessKey", "sessionToken", "username", "password"],
657
- `storage connection \u201C${name}\u201D`
658
- );
659
- const type = requiredString(value.type, `storage connection \u201C${name}\u201D type`);
660
- if (type !== "s3" && type !== "git" && type !== "webdav") {
661
- throw new Error(`Invalid pi-sync settings: storage connection \u201C${name}\u201D has unsupported type.`);
662
- }
663
- const known = ["endpoint", "region", "remote", "url", "credentials"];
664
- const allowed = type === "s3" ? /* @__PURE__ */ new Set(["endpoint", "region", "credentials"]) : type === "git" ? /* @__PURE__ */ new Set(["remote"]) : /* @__PURE__ */ new Set(["url", "credentials"]);
665
- if (known.some((field) => Object.hasOwn(value, field) && !allowed.has(field))) {
666
- throw new Error(
667
- `Invalid pi-sync settings: ${type.toUpperCase()} storage connection \u201C${name}\u201D mixes backend fields.`
668
- );
669
- }
670
- if (type === "git") {
671
- if (!normalizeGitRemote(requiredString(value.remote, `Git remote for \u201C${name}\u201D`))) {
672
- throw new Error(`Invalid pi-sync settings: Git remote for \u201C${name}\u201D is required.`);
673
- }
674
- return;
675
- }
676
- const credentials = requireRecord(value.credentials, `credentials for storage connection \u201C${name}\u201D`);
677
- if (type === "webdav") {
678
- normalizeWebDavUrl(requiredString(value.url, `WebDAV URL for \u201C${name}\u201D`));
679
- const username = requiredString(credentials.username, `WebDAV username for \u201C${name}\u201D`);
680
- const password = requiredSecret(credentials.password, `WebDAV password for \u201C${name}\u201D`);
681
- if (["accessKeyId", "secretAccessKey", "sessionToken"].some((field) => Object.hasOwn(credentials, field))) {
682
- throw new Error(`Invalid pi-sync settings: WebDAV credentials for \u201C${name}\u201D mix fields.`);
683
- }
684
- validateWebDavCredentials(username, password);
685
- return;
686
- }
687
- normalizeS3Endpoint(requiredString(value.endpoint, `S3 endpoint for \u201C${name}\u201D`));
688
- requiredString(value.region, `S3 region for \u201C${name}\u201D`);
689
- requiredString(credentials.accessKeyId, `S3 access key id for \u201C${name}\u201D`);
690
- requiredSecret(credentials.secretAccessKey, `S3 secret access key for \u201C${name}\u201D`);
691
- optionalString(credentials.sessionToken, `S3 session token for \u201C${name}\u201D`);
692
- if (["username", "password"].some((field) => Object.hasOwn(credentials, field))) {
693
- throw new Error(`Invalid pi-sync settings: S3 credentials for \u201C${name}\u201D mix fields.`);
694
- }
695
- }
696
- function validateSyncSetup(name, value, connections) {
697
- rejectLegacyFields(
698
- value,
699
- [
700
- "profile",
701
- "bucket",
702
- "branch",
703
- "path",
704
- "prefix",
705
- "directory",
706
- "namespace",
707
- "autoSync",
708
- "syncFiles",
709
- "syncSessions",
710
- "extraFiles"
711
- ],
712
- `sync setup \u201C${name}\u201D`
713
- );
714
- const storage = requireRecord(value.storage, `storage for sync setup \u201C${name}\u201D`);
715
- const sync = requireRecord(value.sync, `sync policy for sync setup \u201C${name}\u201D`);
716
- rejectLegacyFields(storage, ["profile", "prefix", "directory", "namespace"], `storage for sync setup \u201C${name}\u201D`);
717
- rejectLegacyFields(
718
- sync,
719
- ["autoSync", "syncFiles", "syncSessions", "extraFiles"],
720
- `sync policy for sync setup \u201C${name}\u201D`
721
- );
722
- const connectionName = requiredCanonicalReference(
723
- storage.connection,
724
- `storage connection reference for sync setup \u201C${name}\u201D`
725
- );
726
- validateConfigName(connectionName, "storage connection reference");
727
- const connection = ownObject(connections, connectionName);
728
- if (!connection) {
729
- throw new Error(
730
- `Invalid pi-sync settings: sync setup \u201C${name}\u201D references missing storage connection \u201C${connectionName}\u201D.`
731
- );
732
- }
733
- const type = connection.type;
734
- normalizeStoragePath(requiredString(storage.path, `storage path for sync setup \u201C${name}\u201D`));
735
- if (type === "s3") {
736
- normalizeS3Bucket(requiredString(storage.bucket, `S3 bucket for sync setup \u201C${name}\u201D`));
737
- if (Object.hasOwn(storage, "branch")) mixedSetupError("S3", name);
738
- } else if (type === "git") {
739
- normalizeGitBranch(requiredString(storage.branch, `Git branch for sync setup \u201C${name}\u201D`));
740
- if (Object.hasOwn(storage, "bucket")) mixedSetupError("Git", name);
741
- } else if (type === "webdav") {
742
- if (Object.hasOwn(storage, "bucket") || Object.hasOwn(storage, "branch")) {
743
- mixedSetupError("WebDAV", name);
744
- }
745
- }
746
- if (!Object.hasOwn(sync, "include")) {
747
- throw new Error(`Invalid pi-sync settings: sync setup \u201C${name}\u201D is missing sync.include.`);
748
- }
749
- const include = normalizeSyncInclude(sync.include);
750
- normalizeSyncExclude(sync.exclude);
751
- const localFields = normalizeLocalFields(sync.localFields);
752
- if (localFields.length > 0 && !include.includes("settings.json"))
753
- throw new Error("Nonempty localFields requires settings.json in sync.include.");
754
- for (const key of ["mergeContent", "partialSync", "agentMode", "continuous"])
755
- if (sync[key] !== void 0 && typeof sync[key] !== "boolean") throw new Error(`${key} must be boolean.`);
756
- if (sync.mergeSettings !== void 0 && typeof sync.mergeSettings !== "boolean")
757
- throw new Error("mergeSettings must be boolean.");
758
- if (sync.automaticTransfer !== void 0 && typeof sync.automaticTransfer !== "boolean") {
759
- throw new Error(`Invalid pi-sync settings: sync setup \u201C${name}\u201D sync.automaticTransfer must be boolean.`);
760
- }
761
- if (typeof sync.automatic !== "boolean") {
762
- throw new Error(`Invalid pi-sync settings: sync setup \u201C${name}\u201D sync.automatic must be boolean.`);
763
- }
764
- }
765
- function mixedSetupError(type, name) {
766
- throw new Error(`Invalid pi-sync settings: ${type} sync setup \u201C${name}\u201D mixes backend fields.`);
767
- }
768
- function validateUniqueRemoteSyncSetups(setups, connections) {
769
- const identities = /* @__PURE__ */ new Map();
770
- for (const name of Object.keys(setups)) {
771
- const setup = requireOwnObject(setups, name, "sync setup");
772
- const connection = requireOwnObject(
773
- connections,
774
- setup.storage.connection,
775
- "storage connection"
776
- );
777
- const identity = effectiveSyncSetupRemoteIdentity(setup, connection);
778
- const existing = identities.get(identity);
779
- if (existing) {
780
- throw new Error(
781
- `Invalid pi-sync settings: sync setups \u201C${existing}\u201D and \u201C${name}\u201D use the same normalized remote location.`
782
- );
783
- }
784
- identities.set(identity, name);
785
- }
786
- }
787
- function effectiveSyncSetupRemoteIdentity(setup, connection) {
788
- const storagePath = normalizeStoragePath(setup.storage.path);
789
- if (connection.type === "git") {
790
- return JSON.stringify([
791
- "git",
792
- normalizeGitRemoteIdentity(connection.remote),
793
- normalizeGitBranch(setup.storage.branch),
794
- normalizeGitDirectory(storagePath)
795
- ]);
796
- }
797
- if (connection.type === "webdav") {
798
- return JSON.stringify([
799
- "webdav",
800
- normalizeWebDavIdentityUrl(connection.url),
801
- connection.credentials.username.trim(),
802
- normalizeWebDavPath(storagePath)
803
- ]);
804
- }
805
- return JSON.stringify([
806
- "s3",
807
- normalizeEndpointIdentity(connection.endpoint),
808
- normalizeS3Bucket(setup.storage.bucket),
809
- storagePath
810
- ]);
811
- }
812
- function rejectLegacyFields(value, fields, context) {
813
- const field = fields.find((candidate) => Object.hasOwn(value, candidate));
814
- if (field) {
815
- throw new Error(`Invalid pi-sync settings: ${context} contains unsupported version 1/2 field \u201C${field}\u201D.`);
816
- }
817
- }
818
- function requireNamedObjectMap(value, field, itemLabel) {
819
- const result = requireRecord(value, field);
820
- for (const name of Object.keys(result)) validateConfigName(name, itemLabel);
821
- return result;
822
- }
823
- function requireOwnObject(value, key, label) {
824
- const item = ownObject(value, key);
825
- if (!item) throw new Error(`Invalid pi-sync settings: ${label} \u201C${key}\u201D must be an object.`);
826
- return item;
827
- }
828
- function ownObject(value, key) {
829
- if (!Object.hasOwn(value, key)) return void 0;
830
- const item = value[key];
831
- return item && typeof item === "object" && !Array.isArray(item) ? item : void 0;
832
- }
833
- function requireRecord(value, field) {
834
- if (!value || typeof value !== "object" || Array.isArray(value)) {
835
- throw new Error(`Invalid pi-sync settings: ${field} must be an object.`);
836
- }
837
- return value;
838
- }
839
- function validateConfigName(value, field) {
840
- if (!value.trim() || value !== value.trim() || value.length > 100 || value === "__proto__" || value === "prototype" || value === "constructor" || hasControlCharacter(value)) {
841
- throw new Error(`Invalid pi-sync settings: invalid ${field} name.`);
842
- }
843
- }
844
- function requiredString(value, field) {
845
- if (typeof value !== "string" || !value.trim() || hasControlCharacter(value)) {
846
- throw new Error(`Invalid pi-sync settings: ${field} must be a non-empty string.`);
847
- }
848
- return value.trim();
849
- }
850
- function requiredCanonicalReference(value, field) {
851
- const normalized = requiredString(value, field);
852
- if (value !== normalized) {
853
- throw new Error(`Invalid pi-sync settings: ${field} must not have surrounding whitespace.`);
854
- }
855
- return normalized;
856
- }
857
- function optionalCanonicalReference(value, field) {
858
- const normalized = optionalString(value, field);
859
- if (normalized !== void 0 && value !== normalized) {
860
- throw new Error(`Invalid pi-sync settings: ${field} must not have surrounding whitespace.`);
861
- }
862
- return normalized;
863
- }
864
- function requiredSecret(value, field) {
865
- if (typeof value !== "string" || !value || hasControlCharacter(value)) {
866
- throw new Error(`Invalid pi-sync settings: ${field} must be configured.`);
867
- }
868
- return value;
869
- }
870
- function optionalString(value, field) {
871
- if (value === void 0) return void 0;
872
- if (typeof value !== "string" || hasControlCharacter(value)) {
873
- throw new Error(`Invalid pi-sync settings: ${field} must be a string.`);
874
- }
875
- return value.trim() || void 0;
876
- }
877
- function normalizeStoragePath(value) {
878
- if (value.trim() === "." || value.trim() === "./") return "./";
879
- const normalized = value.trim().replace(/^\/+|\/+$/gu, "");
880
- if (!normalized || normalized.length > 1024 || normalized.startsWith("-") || normalized.includes("\\") || hasControlCharacter(normalized) || normalized.split("/").some((segment) => !segment || segment === "." || segment === "..")) {
881
- throw new Error("Invalid pi-sync settings: storage.path must be a safe relative path.");
882
- }
883
- return normalized;
884
- }
885
- function normalizeS3Endpoint(value) {
886
- let url;
887
- try {
888
- url = new URL(value.trim());
889
- } catch {
890
- throw new Error("Invalid pi-sync S3 endpoint.");
891
- }
892
- const loopback = url.hostname === "127.0.0.1" || url.hostname === "localhost" || url.hostname === "[::1]";
893
- if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback) || url.username || url.password || url.search || url.hash) {
894
- throw new Error("Invalid pi-sync S3 endpoint: HTTPS is required except for loopback.");
895
- }
896
- url.pathname = url.pathname.replace(/\/+$/gu, "");
897
- return url.toString().replace(/\/$/u, "");
898
- }
899
- function normalizeS3Bucket(value) {
900
- const bucket = requiredString(value, "S3 bucket");
901
- if (bucket.includes("/") || bucket.includes("\\") || bucket.startsWith("-")) {
902
- throw new Error("Invalid pi-sync S3 bucket.");
903
- }
904
- return bucket;
905
- }
906
- function hasControlCharacter(value) {
907
- return /[\u0000-\u001f\u007f-\u009f]/u.test(value);
908
- }
909
- function isCloudflareR2Endpoint(endpoint) {
910
- const value = endpoint?.trim();
911
- if (!value) return false;
912
- try {
913
- const hostname = new URL(value).hostname.toLowerCase();
914
- return hostname === "r2.cloudflarestorage.com" || hostname.endsWith(".r2.cloudflarestorage.com");
915
- } catch {
916
- return false;
917
- }
918
- }
919
- function ownRecord(value) {
920
- return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
921
- }
922
-
923
- // src/settings/settings-store.ts
924
- async function requireSettings() {
925
- const settings = await readLocalConfigObject();
926
- if (!settings) {
927
- throw new Error(`Missing pi-sync settings. Open /sync and choose Set up sync, or create ${localConfigPath()}.`);
928
- }
929
- return settings;
930
- }
931
- async function configuredSyncSetupNames() {
932
- const settings = await readLocalConfigObject();
933
- return settings ? Object.keys(settings.syncSetups).sort((left, right) => left.localeCompare(right)) : [];
934
- }
935
- async function loadOnSwitch() {
936
- return (await requireSettings()).onSwitch;
937
- }
938
- function localConfigTemplate() {
939
- return {
940
- version: 3,
941
- onSwitch: DEFAULT_ON_SWITCH,
942
- skipSecretScan: false,
943
- showStatus: true,
944
- debug: false,
945
- storageConnections: {},
946
- syncSetups: {}
947
- };
948
- }
949
- async function readLocalConfigDocument() {
950
- const document = await readMigratingLocalConfigDocument((settings) => {
951
- validateSettingsDocument(settings);
952
- });
953
- if (document) validateSettingsDocument(document.parsed);
954
- return document;
955
- }
956
- async function readLocalConfigObject() {
957
- return (await readLocalConfigDocument())?.parsed;
958
- }
959
- function updateLocalConfig(update, signal) {
960
- return updateLocalConfigDocument(localConfigTemplate(), update, validateSettingsDocument, signal);
961
- }
962
-
963
- // src/settings/config.ts
964
- async function loadConfig(setupName) {
965
- return configFromSettings(await requireSettings(), setupName);
966
- }
967
- async function loadConfigForCheck() {
968
- const document = await readActiveLocalConfigDocumentForRepair();
969
- if (!document) throw new Error(`Missing pi-sync settings: ${localConfigPath()}`);
970
- validateSettingsDocument(document.parsed);
971
- return configFromSettings(document.parsed);
972
- }
973
- function configFromSettings(settings, setupName) {
974
- const selectedName = setupName ?? settings.activeSyncSetup;
975
- if (!selectedName) throw new Error("No sync setups are configured.");
976
- validateConfigName(selectedName, "sync setup");
977
- const setup = ownObject(settings.syncSetups, selectedName);
978
- if (!setup) throw new Error(`Invalid pi-sync settings: sync setup \u201C${selectedName}\u201D was not found.`);
979
- const connectionName = setup.storage.connection;
980
- const connection = ownObject(settings.storageConnections, connectionName);
981
- if (!connection) {
982
- throw new Error(
983
- `Invalid pi-sync settings: sync setup \u201C${selectedName}\u201D references missing storage connection \u201C${connectionName}\u201D.`
984
- );
985
- }
986
- return {
987
- ...resolveSyncConfig(
988
- selectedName,
989
- setup,
990
- connectionName,
991
- connection,
992
- settings.onSwitch,
993
- settings.skipSecretScan ?? false,
994
- settings.showStatus ?? true
995
- ),
996
- debug: settings.debug ?? false
997
- };
998
- }
999
- async function loadPartialConfig(setupName) {
1000
- const config = await loadConfig(setupName);
1001
- return {
1002
- setupName: config.setupName,
1003
- ...storageReviewFromConfig(config),
1004
- include: [...config.include],
1005
- ...config.exclude === void 0 ? {} : { exclude: [...config.exclude] },
1006
- automatic: config.automatic,
1007
- automaticTransfer: config.automaticTransfer ?? false,
1008
- agentMode: config.agentMode ?? false,
1009
- continuous: config.continuous ?? false,
1010
- onSwitch: config.onSwitch,
1011
- showStatus: config.showStatus
1012
- };
1013
- }
1014
- function syncSetupStorageReview(setupName, setup, connectionName, connection) {
1015
- return storageReviewFromConfig(
1016
- resolveSyncConfig(setupName, setup, connectionName, connection, DEFAULT_ON_SWITCH, false, true)
1017
- );
1018
- }
1019
- function syncSetupReviewIdentity(setupName, setup, connectionName, connection) {
1020
- return syncConfigReviewIdentity(
1021
- resolveSyncConfig(setupName, setup, connectionName, connection, DEFAULT_ON_SWITCH, false, true)
1022
- );
1023
- }
1024
- function syncConfigReviewIdentity(config) {
1025
- return JSON.stringify([
1026
- config.setupName,
1027
- config.connectionName,
1028
- backendIdentityCoordinates(config),
1029
- config.include,
1030
- config.automatic,
1031
- config.automaticTransfer ?? false,
1032
- config.agentMode ?? false,
1033
- config.localFields,
1034
- config.mergeSettings ?? false,
1035
- config.mergeContent ?? false,
1036
- config.partialSync ?? false,
1037
- // Preserve existing Off identities and cached candidates across the upgrade.
1038
- ...config.continuous ? ["continuous"] : [],
1039
- ...config.exclude === void 0 ? [] : ["exclude", normalizeSyncExclude(config.exclude).map((rule) => rule.toLowerCase())]
1040
- ]);
1041
- }
1042
- function syncConfigReviewFingerprint(config) {
1043
- return createHash("sha256").update(syncConfigReviewIdentity(config)).digest("hex");
1044
- }
1045
- function syncCheckConfigFingerprint(config) {
1046
- return createHash("sha256").update(JSON.stringify({ ...config, showStatus: void 0, debug: void 0 })).digest("hex");
1047
- }
1048
- function storageReviewFromConfig(config) {
1049
- return {
1050
- connectionName: config.connectionName,
1051
- storageKind: config.backend.type,
1052
- storagePath: config.storagePath,
1053
- ...config.backend.type === "s3" ? { bucket: config.backend.destination.bucket } : config.backend.type === "git" ? { branch: config.backend.destination.branch } : {}
1054
- };
1055
- }
1056
- function resolveSyncConfig(setupName, setup, connectionName, connection, onSwitch, skipSecretScan, showStatus) {
1057
- const storagePath = normalizeStoragePath(setup.storage.path);
1058
- const namespace = storagePath === "./" ? "root" : storagePath.slice(storagePath.lastIndexOf("/") + 1);
1059
- const include = normalizeSyncInclude(setup.sync.include);
1060
- const common = {
1061
- setupName,
1062
- connectionName,
1063
- storagePath,
1064
- snapshotIdentity: namespace,
1065
- include,
1066
- ...setup.sync.exclude === void 0 ? {} : { exclude: normalizeSyncExclude(setup.sync.exclude) },
1067
- automatic: setup.sync.automatic,
1068
- automaticTransfer: setup.sync.automaticTransfer ?? false,
1069
- agentMode: setup.sync.agentMode ?? false,
1070
- continuous: setup.sync.continuous ?? false,
1071
- localFields: setup.sync.localFields === void 0 ? void 0 : normalizeLocalFields(setup.sync.localFields),
1072
- mergeSettings: setup.sync.mergeSettings ?? false,
1073
- mergeContent: setup.sync.mergeContent ?? false,
1074
- partialSync: setup.sync.partialSync ?? false,
1075
- onSwitch,
1076
- skipSecretScan,
1077
- showStatus
1078
- };
1079
- if (connection.type === "git") {
1080
- return {
1081
- ...common,
1082
- backend: {
1083
- type: "git",
1084
- profile: { kind: "git", remote: normalizeGitRemote(connection.remote) },
1085
- destination: {
1086
- branch: normalizeGitBranch(setup.storage.branch),
1087
- directory: normalizeGitDirectory(storagePath),
1088
- namespace
1089
- }
1090
- }
1091
- };
1092
- }
1093
- if (connection.type === "webdav") {
1094
- return {
1095
- ...common,
1096
- backend: {
1097
- type: "webdav",
1098
- profile: {
1099
- kind: "webdav",
1100
- url: normalizeWebDavUrl(connection.url),
1101
- username: connection.credentials.username,
1102
- password: connection.credentials.password
1103
- },
1104
- destination: { path: normalizeWebDavPath(storagePath), namespace }
1105
- }
1106
- };
1107
- }
1108
- return {
1109
- ...common,
1110
- backend: {
1111
- type: "s3",
1112
- profile: {
1113
- kind: isCloudflareR2Endpoint(connection.endpoint) ? "r2" : "s3-compatible",
1114
- endpoint: normalizeS3Endpoint(connection.endpoint),
1115
- region: requiredString(connection.region, "S3 region"),
1116
- accessKeyId: connection.credentials.accessKeyId,
1117
- secretAccessKey: connection.credentials.secretAccessKey,
1118
- sessionToken: optionalString(connection.credentials.sessionToken, "S3 session token")
1119
- },
1120
- destination: {
1121
- bucket: normalizeS3Bucket(setup.storage.bucket),
1122
- prefix: storagePath,
1123
- namespace
1124
- }
1125
- }
1126
- };
1127
- }
1128
- function sessionTokenWarnings(config) {
1129
- if (!isCloudflareR2Endpoint(config.endpoint) || !config.sessionToken) return [];
1130
- return [
1131
- "session token: configured for Cloudflare R2; if R2 rejects X-Amz-Security-Token, pi-sync retries once without it. R2 static access keys usually do not need a session token."
1132
- ];
1133
- }
1134
- function syncSessionsWarnings(config) {
1135
- if (!syncSessionsSelected(config)) return [];
1136
- return [
1137
- "sessions: included; Pi session JSONL can contain prompts, tool output, file paths, images, and secrets. Sync sessions only to storage you trust."
1138
- ];
1139
- }
1140
- function isEnabled(value, defaultValue) {
1141
- if (value === void 0) return defaultValue;
1142
- if (typeof value === "boolean") return value;
1143
- return !["0", "false", "no", "off"].includes(value.trim().toLowerCase());
1144
- }
1145
- function isExplicitlyEnabled(value) {
1146
- if (typeof value === "boolean") return value;
1147
- return ["1", "true", "yes", "on"].includes(value?.trim().toLowerCase() ?? "");
1148
- }
1149
-
1150
- export {
1151
- localConfigPath,
1152
- activeLocalConfigPath,
1153
- consumeLocalConfigMigrationNotice,
1154
- createLocalConfigDocument,
1155
- normalizeOnSwitch,
1156
- effectiveSyncSetupRemoteIdentity,
1157
- validateConfigName,
1158
- requiredString,
1159
- normalizeStoragePath,
1160
- normalizeS3Endpoint,
1161
- normalizeS3Bucket,
1162
- isCloudflareR2Endpoint,
1163
- ownRecord,
1164
- requireSettings,
1165
- configuredSyncSetupNames,
1166
- loadOnSwitch,
1167
- localConfigTemplate,
1168
- readLocalConfigObject,
1169
- updateLocalConfig,
1170
- loadConfig,
1171
- loadConfigForCheck,
1172
- configFromSettings,
1173
- loadPartialConfig,
1174
- syncSetupStorageReview,
1175
- syncSetupReviewIdentity,
1176
- syncConfigReviewIdentity,
1177
- syncConfigReviewFingerprint,
1178
- syncCheckConfigFingerprint,
1179
- sessionTokenWarnings,
1180
- syncSessionsWarnings,
1181
- isEnabled,
1182
- isExplicitlyEnabled
1183
- };
1184
- //# sourceMappingURL=chunk-XZ3ZTHKR.ts.map