@narumitw/pi-sync 0.58.1 → 0.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (334) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +28 -15
  3. package/dist/chunks/{chunk-AMJRUXFT.ts → chunk-2JNFEZ3V.ts} +2 -6
  4. package/dist/chunks/{chunk-AMJRUXFT.ts.map → chunk-2JNFEZ3V.ts.map} +1 -1
  5. package/dist/chunks/{chunk-MG66XM5U.ts → chunk-4RNCZZY7.ts} +86 -36
  6. package/dist/chunks/chunk-4RNCZZY7.ts.map +7 -0
  7. package/dist/chunks/{config-HYG7G5EM.ts → chunk-7AC2RX4M.ts} +6 -12
  8. package/dist/chunks/chunk-7AC2RX4M.ts.map +7 -0
  9. package/dist/chunks/{chunk-XEODG2PE.ts → chunk-BGGKHHO4.ts} +18 -14
  10. package/dist/chunks/{chunk-XEODG2PE.ts.map → chunk-BGGKHHO4.ts.map} +1 -1
  11. package/dist/chunks/chunk-BWWTOQOW.ts +737 -0
  12. package/dist/chunks/chunk-BWWTOQOW.ts.map +7 -0
  13. package/dist/chunks/chunk-CEMFCWIU.ts +20 -0
  14. package/dist/chunks/chunk-CEMFCWIU.ts.map +7 -0
  15. package/dist/chunks/chunk-CZNBKIM5.ts +20 -0
  16. package/dist/chunks/chunk-CZNBKIM5.ts.map +7 -0
  17. package/dist/chunks/{chunk-YIPK23JW.ts → chunk-ENFHHB5O.ts} +1 -16
  18. package/dist/chunks/{chunk-YIPK23JW.ts.map → chunk-ENFHHB5O.ts.map} +1 -1
  19. package/dist/chunks/{chunk-KHBPED6W.ts → chunk-GSQGBVKG.ts} +2 -2
  20. package/dist/chunks/chunk-HNKLBM3U.ts +18 -0
  21. package/dist/chunks/chunk-HNKLBM3U.ts.map +7 -0
  22. package/dist/chunks/{chunk-QPC5HT3A.ts → chunk-J5COV5TY.ts} +21 -2
  23. package/dist/chunks/chunk-J5COV5TY.ts.map +7 -0
  24. package/dist/chunks/chunk-JKBUYCPC.ts +52 -0
  25. package/dist/chunks/chunk-JKBUYCPC.ts.map +7 -0
  26. package/dist/chunks/chunk-JZKCOM62.ts +26 -0
  27. package/dist/chunks/chunk-JZKCOM62.ts.map +7 -0
  28. package/dist/chunks/chunk-M7RHV3H6.ts +33 -0
  29. package/dist/chunks/chunk-M7RHV3H6.ts.map +7 -0
  30. package/dist/chunks/{chunk-REMGB255.ts → chunk-MIXZVHFR.ts} +35 -10
  31. package/dist/chunks/chunk-MIXZVHFR.ts.map +7 -0
  32. package/dist/chunks/chunk-NPT2G4FU.ts +15 -0
  33. package/dist/chunks/chunk-NPT2G4FU.ts.map +7 -0
  34. package/dist/chunks/chunk-PDBTD2K6.ts +11 -0
  35. package/dist/chunks/chunk-PDBTD2K6.ts.map +7 -0
  36. package/dist/chunks/chunk-UBE6XWOM.ts +29 -0
  37. package/dist/chunks/chunk-UBE6XWOM.ts.map +7 -0
  38. package/dist/chunks/{chunk-JYILGR3K.ts → chunk-UZUUUY7C.ts} +8 -8
  39. package/dist/chunks/chunk-VZCWYXRS.ts +23 -0
  40. package/dist/chunks/chunk-VZCWYXRS.ts.map +7 -0
  41. package/dist/chunks/{chunk-U6GXGY5G.ts → chunk-YWEYRRQI.ts} +45 -37
  42. package/dist/chunks/chunk-YWEYRRQI.ts.map +7 -0
  43. package/dist/chunks/{chunk-ECYCNZOE.ts → chunk-ZMNVNECV.ts} +5 -1
  44. package/dist/chunks/chunk-ZMNVNECV.ts.map +7 -0
  45. package/dist/chunks/{command-handler-MRXE5AKK.ts → command-handler-3O76V7Q5.ts} +83 -87
  46. package/dist/chunks/command-handler-3O76V7Q5.ts.map +7 -0
  47. package/dist/chunks/conflict-review-XBSME2ER.ts +18 -0
  48. package/dist/chunks/conflict-review-XBSME2ER.ts.map +7 -0
  49. package/dist/chunks/{continuous-record-EPHGR2DU.ts → continuous-record-ZHUXVO4E.ts} +5 -13
  50. package/dist/chunks/continuous-record-ZHUXVO4E.ts.map +7 -0
  51. package/dist/chunks/{file-selection-IELTXSGZ.ts → file-selection-S6CNNNQI.ts} +14 -14
  52. package/dist/chunks/file-selection-S6CNNNQI.ts.map +7 -0
  53. package/dist/chunks/manager-result-dispatcher-I2AMCCE7.ts +18 -0
  54. package/dist/chunks/{manager-ui-AY34N4UY.ts → manager-ui-SJOBTJLY.ts} +221 -147
  55. package/dist/chunks/manager-ui-SJOBTJLY.ts.map +7 -0
  56. package/dist/chunks/merge-review-SGDLMVS4.ts +10 -0
  57. package/dist/chunks/remote-selection-ui-GZHPDQ4L.ts +17 -0
  58. package/dist/chunks/{setup-switch-KLGESLQX.ts → setup-switch-M3BAFGJM.ts} +9 -12
  59. package/dist/chunks/{setup-wizard-ZQAK35BP.ts → setup-wizard-NFAWP4KF.ts} +18 -20
  60. package/dist/chunks/{setup-wizard-ZQAK35BP.ts.map → setup-wizard-NFAWP4KF.ts.map} +1 -1
  61. package/dist/chunks/{snapshot-RGNDYT6A.ts → snapshot-D4SFDP5J.ts} +8 -12
  62. package/dist/chunks/snapshot-D4SFDP5J.ts.map +7 -0
  63. package/dist/chunks/snapshot-transaction-directory-TNKBQ3UQ.ts +13 -0
  64. package/dist/chunks/snapshot-transaction-directory-TNKBQ3UQ.ts.map +7 -0
  65. package/dist/chunks/state-directory-JZSZVVPX.ts +17 -0
  66. package/dist/chunks/sync-inspection-BJ4KPPNO.ts +23 -0
  67. package/dist/chunks/sync-inspection-BJ4KPPNO.ts.map +7 -0
  68. package/dist/chunks/sync-operations-TLWER2TT.ts +45 -0
  69. package/dist/chunks/sync-operations-TLWER2TT.ts.map +7 -0
  70. package/dist/chunks/{sync-state-7L4NT7W2.ts → sync-state-FVCJJ7MY.ts} +5 -10
  71. package/dist/chunks/sync-state-FVCJJ7MY.ts.map +7 -0
  72. package/dist/index.ts +269 -306
  73. package/dist/index.ts.map +4 -4
  74. package/docs/daemon-migration.md +93 -0
  75. package/docs/exclude-policy-audit.md +54 -0
  76. package/docs/exclude-review-ledger.md +36 -0
  77. package/docs/tui-contract.md +1 -1
  78. package/package.json +3 -5
  79. package/skills/configure-pi-sync/SKILL.md +5 -4
  80. package/skills/configure-pi-sync/references/configuration.md +91 -19
  81. package/src/backends/backend-factory.ts +2 -23
  82. package/src/backends/backend-identity.ts +5 -40
  83. package/src/backends/backend-types.ts +1 -81
  84. package/src/backends/git/git-backend.ts +6 -784
  85. package/src/backends/git/git-config.ts +8 -130
  86. package/src/backends/git/git-runner.ts +7 -255
  87. package/src/backends/git/git-storage.ts +14 -292
  88. package/src/backends/s3/s3-backend.ts +11 -523
  89. package/src/backends/s3/s3-client.ts +2 -399
  90. package/src/backends/s3/s3-conditions.ts +2 -67
  91. package/src/backends/snapshot-pointer.ts +2 -27
  92. package/src/backends/sync-backend.ts +6 -101
  93. package/src/backends/webdav/webdav-backend.ts +10 -622
  94. package/src/backends/webdav/webdav-client.ts +6 -370
  95. package/src/backends/webdav/webdav-config.ts +8 -82
  96. package/src/commands/command-execution.ts +42 -38
  97. package/src/commands/command.ts +23 -1
  98. package/src/daemon/apply-gate.ts +146 -0
  99. package/src/daemon/pi-client.ts +591 -0
  100. package/src/daemon/recovery.ts +103 -0
  101. package/src/paths.ts +12 -83
  102. package/src/settings/config-errors.ts +2 -6
  103. package/src/settings/config-file.ts +19 -693
  104. package/src/settings/config.ts +16 -257
  105. package/src/settings/settings-management.ts +11 -253
  106. package/src/settings/settings-store.ts +10 -48
  107. package/src/settings/settings-types.ts +1 -154
  108. package/src/settings/settings-validation.ts +17 -431
  109. package/src/snapshot/session-paths.ts +11 -110
  110. package/src/snapshot/snapshot-apply.ts +9 -306
  111. package/src/snapshot/snapshot-case-replacement.ts +6 -80
  112. package/src/snapshot/snapshot-codec.ts +2 -50
  113. package/src/snapshot/snapshot-exclude-safety.ts +2 -0
  114. package/src/snapshot/snapshot-mutation-queues.ts +6 -142
  115. package/src/snapshot/snapshot-paths.ts +2 -11
  116. package/src/snapshot/snapshot-root-transition.ts +6 -154
  117. package/src/snapshot/snapshot-transaction-directory.ts +5 -16
  118. package/src/snapshot/snapshot-transaction-plan.ts +2 -72
  119. package/src/snapshot/snapshot-transaction.ts +6 -934
  120. package/src/snapshot/snapshot-types.ts +1 -43
  121. package/src/snapshot/snapshot.ts +18 -405
  122. package/src/state/json-file.ts +2 -47
  123. package/src/state/lock-policy.ts +2 -2
  124. package/src/state/lock.ts +10 -292
  125. package/src/state/lockfile-fs.ts +2 -25
  126. package/src/state/merge-baseline-store.ts +8 -200
  127. package/src/state/mutation-directory-sync.ts +2 -34
  128. package/src/state/operation-availability.ts +7 -59
  129. package/src/state/state-directory.ts +8 -243
  130. package/src/state/state-types.ts +1 -24
  131. package/src/state/sync-state-store.ts +11 -75
  132. package/src/sync/agent-candidate.ts +7 -256
  133. package/src/sync/agent-plan.ts +2 -107
  134. package/src/sync/agent-policy.ts +10 -13
  135. package/src/sync/agent-refusal-retry.ts +2 -54
  136. package/src/sync/agent-request.ts +2 -19
  137. package/src/sync/agent-runner.ts +2 -191
  138. package/src/sync/agent-store.ts +7 -182
  139. package/src/sync/agent-sync.ts +2 -141
  140. package/src/sync/apply-review.ts +2 -63
  141. package/src/sync/automatic-sync.ts +55 -106
  142. package/src/sync/conflict-artifact-ownership.ts +2 -63
  143. package/src/sync/conflict-artifacts.ts +8 -195
  144. package/src/sync/conflict-groups.ts +2 -68
  145. package/src/sync/conflict-preview.ts +2 -56
  146. package/src/sync/conflict-resolution.ts +2 -93
  147. package/src/sync/conflict-retention.ts +2 -72
  148. package/src/sync/conflict-review.ts +3 -92
  149. package/src/sync/content-conflicts.ts +2 -73
  150. package/src/sync/continuous-errors.ts +7 -85
  151. package/src/sync/continuous-lease.ts +2 -216
  152. package/src/sync/continuous-record.ts +10 -261
  153. package/src/sync/continuous-storage.ts +12 -64
  154. package/src/sync/continuous-sync.ts +2 -563
  155. package/src/sync/continuous-watch.ts +2 -59
  156. package/src/sync/exclude-policy.ts +6 -0
  157. package/src/sync/field-migration.ts +2 -39
  158. package/src/sync/file-merge-planner.ts +2 -143
  159. package/src/sync/json-document.ts +7 -184
  160. package/src/sync/local-field-policy.ts +2 -29
  161. package/src/sync/local-fields.ts +9 -108
  162. package/src/sync/merge-apply.ts +2 -434
  163. package/src/sync/merge-journal.ts +10 -219
  164. package/src/sync/merge-transfer-error.ts +2 -72
  165. package/src/sync/merged-sync.ts +2 -914
  166. package/src/sync/mutation-owner.ts +2 -22
  167. package/src/sync/package-merge.ts +2 -87
  168. package/src/sync/partial-progress.ts +2 -54
  169. package/src/sync/remote-snapshot.ts +7 -80
  170. package/src/sync/session-merge.ts +2 -194
  171. package/src/sync/settings-conflicts.ts +2 -64
  172. package/src/sync/settings-merge.ts +6 -121
  173. package/src/sync/signals.ts +2 -8
  174. package/src/sync/startup-check.ts +15 -31
  175. package/src/sync/startup-timings.ts +2 -94
  176. package/src/sync/sync-decision.ts +3 -101
  177. package/src/sync/sync-error-guidance.ts +2 -46
  178. package/src/sync/sync-errors.ts +7 -23
  179. package/src/sync/sync-inspection.ts +10 -57
  180. package/src/sync/sync-local.ts +2 -44
  181. package/src/sync/sync-mutations.ts +10 -781
  182. package/src/sync/sync-operations.ts +32 -11
  183. package/src/sync/sync-policy.ts +34 -410
  184. package/src/sync/sync-queries.ts +2 -237
  185. package/src/sync/sync-state.ts +18 -151
  186. package/src/sync/text-merge.ts +10 -133
  187. package/src/sync-extension.ts +192 -142
  188. package/src/ui/excluded-paths-ui.ts +106 -0
  189. package/src/ui/file-selection.ts +6 -3
  190. package/src/ui/manager-state.ts +11 -5
  191. package/src/ui/remote-selection-ui.ts +73 -10
  192. package/src/ui/settings-ui.ts +20 -5
  193. package/src/ui/setup/setup-actions.ts +1 -1
  194. package/src/ui/setup/setup-switcher.ts +3 -2
  195. package/src/ui/storage-connections-ui.ts +2 -2
  196. package/src/ui/sync-attention.ts +17 -3
  197. package/src/ui/sync-format.ts +13 -1
  198. package/dist/chunks/agent-candidate-U2NU3GUX.ts +0 -29
  199. package/dist/chunks/agent-plan-3YXDIJXO.ts +0 -123
  200. package/dist/chunks/agent-plan-3YXDIJXO.ts.map +0 -7
  201. package/dist/chunks/agent-refusal-retry-476YGNU5.ts +0 -72
  202. package/dist/chunks/agent-refusal-retry-476YGNU5.ts.map +0 -7
  203. package/dist/chunks/agent-runner-FCRV2Z75.ts +0 -185
  204. package/dist/chunks/agent-runner-FCRV2Z75.ts.map +0 -7
  205. package/dist/chunks/agent-store-7GINKTS7.ts +0 -175
  206. package/dist/chunks/agent-store-7GINKTS7.ts.map +0 -7
  207. package/dist/chunks/agent-sync-2R4GG2MF.ts +0 -22
  208. package/dist/chunks/chunk-2JZFHNLM.ts +0 -113
  209. package/dist/chunks/chunk-2JZFHNLM.ts.map +0 -7
  210. package/dist/chunks/chunk-3ST7RSYN.ts +0 -21
  211. package/dist/chunks/chunk-3ST7RSYN.ts.map +0 -7
  212. package/dist/chunks/chunk-45COPAK7.ts +0 -205
  213. package/dist/chunks/chunk-45COPAK7.ts.map +0 -7
  214. package/dist/chunks/chunk-5SFMBY5P.ts +0 -26
  215. package/dist/chunks/chunk-5SFMBY5P.ts.map +0 -7
  216. package/dist/chunks/chunk-5TSCBBPP.ts +0 -229
  217. package/dist/chunks/chunk-5TSCBBPP.ts.map +0 -7
  218. package/dist/chunks/chunk-6LD5KX55.ts +0 -396
  219. package/dist/chunks/chunk-6LD5KX55.ts.map +0 -7
  220. package/dist/chunks/chunk-6O3EDBRL.ts +0 -258
  221. package/dist/chunks/chunk-6O3EDBRL.ts.map +0 -7
  222. package/dist/chunks/chunk-7A35ZAVO.ts +0 -1109
  223. package/dist/chunks/chunk-7A35ZAVO.ts.map +0 -7
  224. package/dist/chunks/chunk-7D5SF7P3.ts +0 -29
  225. package/dist/chunks/chunk-7D5SF7P3.ts.map +0 -7
  226. package/dist/chunks/chunk-7ZIYU5QS.ts +0 -64
  227. package/dist/chunks/chunk-7ZIYU5QS.ts.map +0 -7
  228. package/dist/chunks/chunk-AKMV47YC.ts +0 -215
  229. package/dist/chunks/chunk-AKMV47YC.ts.map +0 -7
  230. package/dist/chunks/chunk-AR2DGDUI.ts +0 -55
  231. package/dist/chunks/chunk-AR2DGDUI.ts.map +0 -7
  232. package/dist/chunks/chunk-BEST45H2.ts +0 -153
  233. package/dist/chunks/chunk-BEST45H2.ts.map +0 -7
  234. package/dist/chunks/chunk-CBLTWXAU.ts +0 -114
  235. package/dist/chunks/chunk-CBLTWXAU.ts.map +0 -7
  236. package/dist/chunks/chunk-CQD2TJHE.ts +0 -220
  237. package/dist/chunks/chunk-CQD2TJHE.ts.map +0 -7
  238. package/dist/chunks/chunk-DN4IA7MR.ts +0 -61
  239. package/dist/chunks/chunk-DN4IA7MR.ts.map +0 -7
  240. package/dist/chunks/chunk-DT7M4VQS.ts +0 -69
  241. package/dist/chunks/chunk-DT7M4VQS.ts.map +0 -7
  242. package/dist/chunks/chunk-ECYCNZOE.ts.map +0 -7
  243. package/dist/chunks/chunk-ESKOPQVB.ts +0 -348
  244. package/dist/chunks/chunk-ESKOPQVB.ts.map +0 -7
  245. package/dist/chunks/chunk-FHE2DCA2.ts +0 -61
  246. package/dist/chunks/chunk-FHE2DCA2.ts.map +0 -7
  247. package/dist/chunks/chunk-FLHCOJCD.ts +0 -57
  248. package/dist/chunks/chunk-FLHCOJCD.ts.map +0 -7
  249. package/dist/chunks/chunk-G4RUXRWZ.ts +0 -48
  250. package/dist/chunks/chunk-G4RUXRWZ.ts.map +0 -7
  251. package/dist/chunks/chunk-GNYGNHFF.ts +0 -27
  252. package/dist/chunks/chunk-GNYGNHFF.ts.map +0 -7
  253. package/dist/chunks/chunk-KYTT7KV4.ts +0 -319
  254. package/dist/chunks/chunk-KYTT7KV4.ts.map +0 -7
  255. package/dist/chunks/chunk-M6VQJIOU.ts +0 -54
  256. package/dist/chunks/chunk-M6VQJIOU.ts.map +0 -7
  257. package/dist/chunks/chunk-MG66XM5U.ts.map +0 -7
  258. package/dist/chunks/chunk-MKSMJPVA.ts +0 -107
  259. package/dist/chunks/chunk-MKSMJPVA.ts.map +0 -7
  260. package/dist/chunks/chunk-MMQIEDZ6.ts +0 -1994
  261. package/dist/chunks/chunk-MMQIEDZ6.ts.map +0 -7
  262. package/dist/chunks/chunk-OJARL2TG.ts +0 -25
  263. package/dist/chunks/chunk-OJARL2TG.ts.map +0 -7
  264. package/dist/chunks/chunk-OVBAW7KV.ts +0 -1174
  265. package/dist/chunks/chunk-OVBAW7KV.ts.map +0 -7
  266. package/dist/chunks/chunk-PRUEIIK7.ts +0 -24
  267. package/dist/chunks/chunk-PRUEIIK7.ts.map +0 -7
  268. package/dist/chunks/chunk-PWMWOJP4.ts +0 -17
  269. package/dist/chunks/chunk-PWMWOJP4.ts.map +0 -7
  270. package/dist/chunks/chunk-QPC5HT3A.ts.map +0 -7
  271. package/dist/chunks/chunk-REMGB255.ts.map +0 -7
  272. package/dist/chunks/chunk-S5OCYVPS.ts +0 -415
  273. package/dist/chunks/chunk-S5OCYVPS.ts.map +0 -7
  274. package/dist/chunks/chunk-SWRVXVFD.ts +0 -248
  275. package/dist/chunks/chunk-SWRVXVFD.ts.map +0 -7
  276. package/dist/chunks/chunk-T2SJD3N7.ts +0 -99
  277. package/dist/chunks/chunk-T2SJD3N7.ts.map +0 -7
  278. package/dist/chunks/chunk-TIMWN2RH.ts +0 -89
  279. package/dist/chunks/chunk-TIMWN2RH.ts.map +0 -7
  280. package/dist/chunks/chunk-TZC7GDJE.ts +0 -58
  281. package/dist/chunks/chunk-TZC7GDJE.ts.map +0 -7
  282. package/dist/chunks/chunk-U6GXGY5G.ts.map +0 -7
  283. package/dist/chunks/chunk-WQMYV4DW.ts +0 -140
  284. package/dist/chunks/chunk-WQMYV4DW.ts.map +0 -7
  285. package/dist/chunks/chunk-X7R6DCVF.ts +0 -28
  286. package/dist/chunks/chunk-X7R6DCVF.ts.map +0 -7
  287. package/dist/chunks/chunk-XJHQPB3E.ts +0 -107
  288. package/dist/chunks/chunk-XJHQPB3E.ts.map +0 -7
  289. package/dist/chunks/chunk-Y4UVXOLQ.ts +0 -123
  290. package/dist/chunks/chunk-Y4UVXOLQ.ts.map +0 -7
  291. package/dist/chunks/chunk-YDVQYUHE.ts +0 -34
  292. package/dist/chunks/chunk-YDVQYUHE.ts.map +0 -7
  293. package/dist/chunks/chunk-YHT4YTYG.ts +0 -31
  294. package/dist/chunks/chunk-YHT4YTYG.ts.map +0 -7
  295. package/dist/chunks/chunk-ZW5ZLGBI.ts +0 -154
  296. package/dist/chunks/chunk-ZW5ZLGBI.ts.map +0 -7
  297. package/dist/chunks/command-handler-MRXE5AKK.ts.map +0 -7
  298. package/dist/chunks/conflict-artifacts-J6WSDCWP.ts +0 -32
  299. package/dist/chunks/conflict-review-GXA6Y7KY.ts +0 -189
  300. package/dist/chunks/conflict-review-GXA6Y7KY.ts.map +0 -7
  301. package/dist/chunks/continuous-sync-FAFNLEUW.ts +0 -585
  302. package/dist/chunks/continuous-sync-FAFNLEUW.ts.map +0 -7
  303. package/dist/chunks/file-selection-IELTXSGZ.ts.map +0 -7
  304. package/dist/chunks/git-backend-KHD36W27.ts +0 -1077
  305. package/dist/chunks/git-backend-KHD36W27.ts.map +0 -7
  306. package/dist/chunks/local-fields-JEKAPZKD.ts +0 -26
  307. package/dist/chunks/local-fields-JEKAPZKD.ts.map +0 -7
  308. package/dist/chunks/manager-result-dispatcher-XCYPW7RC.ts +0 -32
  309. package/dist/chunks/manager-result-dispatcher-XCYPW7RC.ts.map +0 -7
  310. package/dist/chunks/manager-ui-AY34N4UY.ts.map +0 -7
  311. package/dist/chunks/merge-baseline-store-65GKUMXI.ts +0 -25
  312. package/dist/chunks/merge-baseline-store-65GKUMXI.ts.map +0 -7
  313. package/dist/chunks/remote-selection-ui-MYM2YCPF.ts +0 -31
  314. package/dist/chunks/remote-selection-ui-MYM2YCPF.ts.map +0 -7
  315. package/dist/chunks/s3-backend-L24UZ6IK.ts +0 -844
  316. package/dist/chunks/s3-backend-L24UZ6IK.ts.map +0 -7
  317. package/dist/chunks/setup-switch-KLGESLQX.ts.map +0 -7
  318. package/dist/chunks/snapshot-RGNDYT6A.ts.map +0 -7
  319. package/dist/chunks/snapshot-transaction-26BQO36S.ts +0 -24
  320. package/dist/chunks/snapshot-transaction-26BQO36S.ts.map +0 -7
  321. package/dist/chunks/sync-inspection-MOMLGUTD.ts +0 -25
  322. package/dist/chunks/sync-inspection-MOMLGUTD.ts.map +0 -7
  323. package/dist/chunks/sync-operations-45APGOL3.ts +0 -1021
  324. package/dist/chunks/sync-operations-45APGOL3.ts.map +0 -7
  325. package/dist/chunks/sync-state-7L4NT7W2.ts.map +0 -7
  326. package/dist/chunks/webdav-backend-3ZCACILP.ts +0 -851
  327. package/dist/chunks/webdav-backend-3ZCACILP.ts.map +0 -7
  328. /package/dist/chunks/{chunk-KHBPED6W.ts.map → chunk-GSQGBVKG.ts.map} +0 -0
  329. /package/dist/chunks/{chunk-JYILGR3K.ts.map → chunk-UZUUUY7C.ts.map} +0 -0
  330. /package/dist/chunks/{agent-candidate-U2NU3GUX.ts.map → manager-result-dispatcher-I2AMCCE7.ts.map} +0 -0
  331. /package/dist/chunks/{agent-sync-2R4GG2MF.ts.map → merge-review-SGDLMVS4.ts.map} +0 -0
  332. /package/dist/chunks/{config-HYG7G5EM.ts.map → remote-selection-ui-GZHPDQ4L.ts.map} +0 -0
  333. /package/dist/chunks/{conflict-artifacts-J6WSDCWP.ts.map → setup-switch-M3BAFGJM.ts.map} +0 -0
  334. /package/dist/chunks/{continuous-record-EPHGR2DU.ts.map → state-directory-JZSZVVPX.ts.map} +0 -0
@@ -1,1021 +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
- inspectSync
5
- } from "./chunk-7ZIYU5QS.ts";
6
- import {
7
- addTopLevelCaseVariantDeletes,
8
- applySnapshot,
9
- countPreservedRemoteFiles,
10
- createSyncDecision,
11
- formatDiff,
12
- formatPullSummary,
13
- formatPushSummary,
14
- formatRollbackSummary,
15
- formatSnapshotOnlyDiff,
16
- mergeSync,
17
- publicationCapabilityDescription
18
- } from "./chunk-MMQIEDZ6.ts";
19
- import "./chunk-5TSCBBPP.ts";
20
- import {
21
- readMergeJournal,
22
- requireNoMergeJournal,
23
- retireMergeJournal
24
- } from "./chunk-BEST45H2.ts";
25
- import {
26
- canPullRemoteSessionsOnFirstSync,
27
- canPullRemoteSettingsOnFirstSync,
28
- fileHashMap,
29
- hasLocalChanges,
30
- hasRemoteChanges,
31
- remoteChangedSinceState,
32
- sameHashes,
33
- shouldRefreshSyncedState,
34
- snapshotHashesMatchState,
35
- snapshotsMatch,
36
- syncPolicyChanged
37
- } from "./chunk-Y4UVXOLQ.ts";
38
- import {
39
- formatRemoteSelectionStatus,
40
- readRemoteSnapshot,
41
- readSnapshotForHead,
42
- requireCompatibleRemoteSelection
43
- } from "./chunk-TIMWN2RH.ts";
44
- import {
45
- createSyncBackend
46
- } from "./chunk-OJARL2TG.ts";
47
- import {
48
- confirmMergeReview
49
- } from "./chunk-KHBPED6W.ts";
50
- import {
51
- backupLocal,
52
- protectedSessionPaths
53
- } from "./chunk-TZC7GDJE.ts";
54
- import "./chunk-FLHCOJCD.ts";
55
- import {
56
- overlayLocalFields,
57
- portableSnapshot,
58
- sameLocalFields,
59
- validatePortableSnapshot
60
- } from "./chunk-MKSMJPVA.ts";
61
- import "./chunk-M6VQJIOU.ts";
62
- import {
63
- captureMutationOwner
64
- } from "./chunk-GNYGNHFF.ts";
65
- import {
66
- safeTerminalText
67
- } from "./chunk-AMJRUXFT.ts";
68
- import {
69
- setSyncStatus
70
- } from "./chunk-YIPK23JW.ts";
71
- import {
72
- errorMessage
73
- } from "./chunk-7D5SF7P3.ts";
74
- import {
75
- loadConfig,
76
- syncCheckConfigFingerprint,
77
- syncSessionsWarnings
78
- } from "./chunk-OVBAW7KV.ts";
79
- import "./chunk-X7R6DCVF.ts";
80
- import "./chunk-7A35ZAVO.ts";
81
- import "./chunk-5SFMBY5P.ts";
82
- import {
83
- inspectLock,
84
- isLockGuardHeld,
85
- isStaleLock,
86
- withLock
87
- } from "./chunk-6O3EDBRL.ts";
88
- import {
89
- throwIfAborted
90
- } from "./chunk-PWMWOJP4.ts";
91
- import "./chunk-AKMV47YC.ts";
92
- import {
93
- pruneMergeBaselines
94
- } from "./chunk-6LD5KX55.ts";
95
- import "./chunk-ZW5ZLGBI.ts";
96
- import "./chunk-XJHQPB3E.ts";
97
- import {
98
- readStateForConfig,
99
- syncStateFingerprint,
100
- writeStateForConfig
101
- } from "./chunk-DN4IA7MR.ts";
102
- import "./chunk-AR2DGDUI.ts";
103
- import "./chunk-SWRVXVFD.ts";
104
- import "./chunk-2JZFHNLM.ts";
105
- import "./chunk-T2SJD3N7.ts";
106
- import {
107
- createSnapshot,
108
- filterSnapshotForConfigPolicy,
109
- mergeRemotePreservedFiles,
110
- regenerateSnapshotIdentity,
111
- scanSnapshot,
112
- snapshotIncludesSessions,
113
- snapshotWithoutSessions
114
- } from "./chunk-ESKOPQVB.ts";
115
- import {
116
- inspectRemoteSelection
117
- } from "./chunk-KYTT7KV4.ts";
118
- import {
119
- agentDir,
120
- sessionDirForApply,
121
- snapshotOptionsForContext
122
- } from "./chunk-CBLTWXAU.ts";
123
- import "./chunk-FHE2DCA2.ts";
124
- import "./chunk-DT7M4VQS.ts";
125
- import {
126
- expectedRemoteHead
127
- } from "./chunk-YDVQYUHE.ts";
128
- import {
129
- startupTransferEnabled
130
- } from "./chunk-PRUEIIK7.ts";
131
-
132
- // src/ui/transfer-review.ts
133
- async function confirmTransferReview(ctx, title, content, signal, validate) {
134
- validate();
135
- const isCurrent = () => {
136
- try {
137
- validate();
138
- return true;
139
- } catch {
140
- return false;
141
- }
142
- };
143
- const confirmed = ctx.mode === "tui" && ctx.hasUI ? await confirmMergeReview(ctx, title, content, signal, isCurrent, "apply reviewed transfer", content.split("\n")) : await ctx.ui.confirm(title, content, { signal });
144
- validate();
145
- return confirmed;
146
- }
147
-
148
- // src/sync/apply-review.ts
149
- import { createHash } from "node:crypto";
150
- import { constants } from "node:fs";
151
- import fs from "node:fs/promises";
152
- import path from "node:path";
153
- async function inspectCaseCleanup(snapshot, signal) {
154
- throwIfAborted(signal);
155
- const root = agentDir();
156
- const plan = await addTopLevelCaseVariantDeletes(root, { writes: [], deletes: [] }, snapshot);
157
- throwIfAborted(signal);
158
- const review = [];
159
- for (const target of plan.deletes.sort()) {
160
- const stat = await fs.lstat(target);
161
- throwIfAborted(signal);
162
- const hash = createHash("sha256");
163
- if (stat.isSymbolicLink()) hash.update(await fs.readlink(target));
164
- else {
165
- if (!stat.isFile()) throw new Error("Case-variant path is no longer a regular file or symlink.");
166
- const handle = await fs.open(
167
- target,
168
- constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0)
169
- );
170
- try {
171
- throwIfAborted(signal);
172
- const opened = await handle.stat();
173
- if (!opened.isFile() || opened.dev !== stat.dev || opened.ino !== stat.ino)
174
- throw new Error("Case-variant file changed while preparing review.");
175
- for await (const bytes of handle.createReadStream({ autoClose: false, signal })) {
176
- throwIfAborted(signal);
177
- hash.update(bytes);
178
- }
179
- } finally {
180
- await handle.close();
181
- }
182
- }
183
- throwIfAborted(signal);
184
- review.push({
185
- path: path.basename(target),
186
- fingerprint: `${stat.dev}:${stat.ino}:${stat.mode}:${hash.digest("hex")}`
187
- });
188
- }
189
- return review;
190
- }
191
- async function revalidateCaseCleanup(expected, snapshot, signal) {
192
- const current = await inspectCaseCleanup(snapshot, signal);
193
- if (JSON.stringify(current) !== JSON.stringify(expected))
194
- throw new Error("Case-variant paths changed during transfer review; reopen the preview.");
195
- }
196
-
197
- // src/sync/field-migration.ts
198
- async function confirmFieldMigration(ctx, config, state, remote, force, signal) {
199
- if (remote?.localFields !== void 0 && config.localFields === void 0)
200
- throw new Error(
201
- "Portable snapshots require settings version 4 and explicit localFields rules on this machine; older policy must not replace local-only values."
202
- );
203
- const changed = Boolean(state.lastAppliedSnapshot) && !sameLocalFields(state.localFields, config.localFields) || remote !== void 0 && !sameLocalFields(remote.localFields, config.localFields);
204
- if (!changed) return true;
205
- if (!force)
206
- throw new Error(
207
- "Local-field policy changed; review an explicit push --force or pull --force migration. Old remote history is not erased."
208
- );
209
- const validate = captureMutationOwner(ctx, signal);
210
- if (!ctx.hasUI) throw new Error("Local-field migration requires observable TUI/RPC confirmation.");
211
- validate();
212
- const confirmed = await ctx.ui.confirm(
213
- "Migrate portable settings policy?",
214
- `New machine-local fields: ${(config.localFields ?? []).map(safeTerminalText).join(", ") || "none"}. Additions remove fields from future snapshots, not old history. Removals make local-only values portable again and a pull may replace them. The selected direction is authoritative; inspect /sync diff first. This confirmation is required even with --yes.`,
215
- { signal }
216
- );
217
- validate();
218
- return confirmed;
219
- }
220
-
221
- // src/sync/sync-mutations.ts
222
- var VERSION = 1;
223
- var POST_LOCAL_COMMIT_TIMEOUT_MS = 3e4;
224
- function requireResolvedDirectionalProgress(state, options, allowForce = true) {
225
- if (state.unresolved?.length && (options.auto || !options.force || !allowForce))
226
- throw new Error(
227
- "Unresolved partial conflicts remain. Review /sync conflicts or explicitly choose push --force or pull --force; automatic transfer and rollback cannot accept unresolved groups."
228
- );
229
- }
230
- var PublicationStatePersistenceError = class extends Error {
231
- head;
232
- backupPath;
233
- constructor(head, cause, backupPath) {
234
- super(
235
- `Remote publication ${head.snapshotId} is active, but local sync state could not be saved${backupPath ? `; local backup: ${backupPath}` : ""}: ${errorMessage(cause)}`,
236
- { cause }
237
- );
238
- this.name = "PublicationStatePersistenceError";
239
- this.head = head;
240
- this.backupPath = backupPath;
241
- }
242
- };
243
- var RollbackPublicationError = class extends Error {
244
- backupPath;
245
- constructor(backupPath, cause) {
246
- super(`Rollback applied locally with backup ${backupPath}, but remote publication failed: ${errorMessage(cause)}`, {
247
- cause
248
- });
249
- this.name = "RollbackPublicationError";
250
- this.backupPath = backupPath;
251
- }
252
- };
253
- async function push(ctx, options, input, factory = createSyncBackend) {
254
- const validateMutation = captureMutationOwner(ctx, options.signal);
255
- const validateCommittedOwner = captureMutationOwner(ctx);
256
- const config = input?.config ?? await loadConfig(options.setup);
257
- throwIfAborted(options.signal);
258
- await requireNoMergeJournal(config, options);
259
- const state = input?.state ?? await readStateForConfig(config);
260
- validateMutation();
261
- requireResolvedDirectionalProgress(state, options);
262
- setSyncStatus(ctx, `pushing ${config.setupName}`, { activity: "pushing" });
263
- const backend = input?.backend ?? await factory(config);
264
- throwIfAborted(options.signal);
265
- const localRaw = input?.local ?? await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));
266
- const local = portableSnapshot(localRaw, config.localFields);
267
- throwIfAborted(options.signal);
268
- let head = await backend.readHead(options.signal);
269
- let remoteForUpload = await readRemoteSnapshotForUpload(backend, config, head, state, options.signal);
270
- if (!options.force && !remoteForUpload && head?.selection && inspectRemoteSelection(config.include, { selection: head.selection, files: [] }).kind === "different") {
271
- remoteForUpload = await readSnapshotForHead(backend, head, options.signal);
272
- }
273
- if (remoteForUpload && !options.force) {
274
- requireCompatibleRemoteSelection(config, remoteForUpload);
275
- }
276
- if (remoteChangedSinceState(head, state, config, (left, right) => backend.sameRevision(left, right)) && !options.force) {
277
- const remoteForConflict = remoteForUpload ? filterSnapshotForConfigPolicy(remoteForUpload, config) : void 0;
278
- if (!remoteForConflict || !snapshotHashesMatchState(remoteForConflict, state, config)) {
279
- throw createSyncDecision({
280
- kind: head ? "remote-or-policy-changed" : "remote-empty",
281
- config,
282
- state,
283
- local,
284
- remote: remoteForConflict,
285
- localChanged: hasLocalChanges(local, state, config),
286
- remoteChanged: true,
287
- directMessage: "Remote or sync policy changed since last sync. Run /sync pull first or /sync push --force."
288
- });
289
- }
290
- }
291
- if (!remoteForUpload && head && (config.localFields !== void 0 || !options.yes))
292
- remoteForUpload = await readSnapshotForHead(backend, head, options.signal);
293
- if (!await confirmFieldMigration(ctx, config, state, remoteForUpload, options.force, options.signal)) {
294
- setSyncStatus(ctx, void 0);
295
- return "cancelled";
296
- }
297
- const configIdentity = syncCheckConfigFingerprint(config);
298
- let upload = await snapshotForUpload(backend, config, local, head, remoteForUpload, options.signal);
299
- if (!config.skipSecretScan) {
300
- const secrets = scanSnapshot(local);
301
- if (secrets.length > 0) {
302
- throw new Error(`Refusing to push possible secrets:
303
- ${secrets.map((s) => `- ${s}`).join("\n")}`);
304
- }
305
- }
306
- if (!await confirmPush(ctx, options, config, backend, local, upload, head, remoteForUpload)) {
307
- return "cancelled";
308
- }
309
- if (options.force) {
310
- const refreshedHead = await backend.readHead(options.signal);
311
- if (!sameRemoteHead(backend, head, refreshedHead)) {
312
- head = refreshedHead;
313
- remoteForUpload = head ? await readSnapshotForHead(backend, head, options.signal) : void 0;
314
- validateMutation();
315
- if (!await confirmFieldMigration(ctx, config, state, remoteForUpload, options.force, options.signal)) {
316
- setSyncStatus(ctx, void 0);
317
- return "cancelled";
318
- }
319
- validateMutation();
320
- upload = await snapshotForUpload(backend, config, local, head, remoteForUpload, options.signal);
321
- if (!await confirmPush(
322
- ctx,
323
- options,
324
- config,
325
- backend,
326
- local,
327
- upload,
328
- head,
329
- remoteForUpload,
330
- "Remote changed during review. Push the refreshed plan?"
331
- )) {
332
- return "cancelled";
333
- }
334
- }
335
- }
336
- validateMutation();
337
- if (configIdentity !== syncCheckConfigFingerprint(await loadConfig(options.setup)))
338
- throw new Error("Settings changed during push review.");
339
- validateMutation();
340
- if (!options.yes || config.localFields !== void 0 || await readMergeJournal(config)) {
341
- const current = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));
342
- if (!sameHashes(fileHashMap(current), fileHashMap(localRaw)))
343
- throw new Error("Local content changed during push review; retry from current bytes.");
344
- }
345
- const currentState = await readStateForConfig(config);
346
- if (!options.yes && syncStateFingerprint(currentState) !== syncStateFingerprint(state))
347
- throw new Error("Baseline changed during push review.");
348
- requireResolvedDirectionalProgress(currentState, options);
349
- validateMutation();
350
- const result = await backend.publishSnapshot(upload, expectedRemoteHead(head), {
351
- signal: options.signal,
352
- onCommit: options.onCommit
353
- });
354
- try {
355
- await writeStateForConfig(
356
- config,
357
- {
358
- version: VERSION,
359
- profile: config.snapshotIdentity,
360
- lastAppliedSnapshot: result.head.snapshotId,
361
- lastRemoteRevision: result.head.revision,
362
- lastFileHashes: fileHashMap(local),
363
- include: [...config.include],
364
- ...config.localFields !== void 0 ? { localFields: config.localFields } : {}
365
- },
366
- local,
367
- validateCommittedOwner
368
- );
369
- } catch (error) {
370
- throw new PublicationStatePersistenceError(result.head, error);
371
- }
372
- await retireMergeJournal(config);
373
- await pruneMergeBaselines(config, await readStateForConfig(config), validateCommittedOwner);
374
- validateCommittedOwner();
375
- if (options.signal?.aborted) return;
376
- setSyncStatus(ctx, void 0);
377
- if (!options.silent) {
378
- ctx.ui.notify(
379
- [
380
- `Pushed ${upload.files.length} files from sync setup \u201C${config.setupName}\u201D as ${result.head.snapshotId}.`,
381
- ...result.warnings
382
- ].filter(Boolean).join("\n"),
383
- result.warnings.length > 0 ? "warning" : "info"
384
- );
385
- }
386
- return "applied";
387
- }
388
- async function pull(ctx, options, factory = createSyncBackend) {
389
- const validateMutation = captureMutationOwner(ctx, options.signal);
390
- const validateCommittedOwner = captureMutationOwner(ctx);
391
- const config = await loadConfig(options.setup);
392
- throwIfAborted(options.signal);
393
- await requireNoMergeJournal(config, options);
394
- setSyncStatus(ctx, `pulling ${config.setupName}`, { activity: "pulling" });
395
- const backend = await factory(config);
396
- const state = await readStateForConfig(config);
397
- validateMutation();
398
- requireResolvedDirectionalProgress(state, options);
399
- const local = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));
400
- throwIfAborted(options.signal);
401
- const { head, snapshot: remote } = await readRemoteSnapshot(backend, config, options.signal);
402
- throwIfAborted(options.signal);
403
- const localChanged = hasLocalChanges(local, state, config);
404
- if (!remote) {
405
- throw createSyncDecision({
406
- kind: "remote-empty",
407
- config,
408
- state,
409
- local,
410
- localChanged,
411
- remoteChanged: false,
412
- directMessage: "Remote is empty. Run /sync push from a configured machine first."
413
- });
414
- }
415
- if (!sameLocalFields(config.localFields, remote.localFields)) {
416
- setSyncStatus(ctx, void 0);
417
- throw new Error(
418
- "Pull requires the configured local-field policy to match the remote. To change the remote policy, review push --force from the authoritative machine first, then pull using matching rules; old history is not erased."
419
- );
420
- }
421
- if (!await confirmFieldMigration(ctx, config, state, remote, options.force, options.signal)) {
422
- setSyncStatus(ctx, void 0);
423
- return "cancelled";
424
- }
425
- const configIdentity = syncCheckConfigFingerprint(config);
426
- const logical = portableSnapshot(remote, config.localFields);
427
- const physical = overlayLocalFields(logical, local, config.localFields);
428
- const remoteChanged = hasRemoteChanges(remote, state, config, protectedSessionPaths(ctx));
429
- if (localChanged && remoteChanged && state.lastAppliedSnapshot && !options.force) {
430
- throw createSyncDecision({
431
- kind: "both-changed",
432
- config,
433
- state,
434
- local,
435
- remote,
436
- localChanged,
437
- remoteChanged,
438
- directMessage: "Both local and remote changed since last sync. Run /sync diff, then choose /sync pull --force or /sync push --force."
439
- });
440
- }
441
- const caseCleanup = options.yes ? [] : await inspectCaseCleanup(physical, options.signal);
442
- validateMutation();
443
- if (!options.yes && !await confirmTransferReview(
444
- ctx,
445
- snapshotIncludesSessions(remote) ? "Pull pi settings and sessions?" : "Pull pi settings?",
446
- formatPullSummary(
447
- config,
448
- backend.destination,
449
- local,
450
- physical,
451
- protectedSessionPaths(ctx),
452
- caseCleanup.map((item) => item.path)
453
- ),
454
- options.signal,
455
- validateMutation
456
- )) {
457
- setSyncStatus(ctx, void 0);
458
- ctx.ui.notify("Pull cancelled.", "info");
459
- return "cancelled";
460
- }
461
- throwIfAborted(options.signal);
462
- const recoveringMerge = Boolean(await readMergeJournal(config));
463
- const requireFreshRecovery = async () => {
464
- validateMutation();
465
- const currentHead = await backend.readHead(options.signal);
466
- validateMutation();
467
- const current = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));
468
- validateMutation();
469
- if (!sameHashes(fileHashMap(current), fileHashMap(local)) || !sameRemoteHead(backend, head, currentHead)) {
470
- throw new Error("Local or remote content changed during recovery review; retry from a fresh diff.");
471
- }
472
- };
473
- if (recoveringMerge) await requireFreshRecovery();
474
- if (configIdentity !== syncCheckConfigFingerprint(await loadConfig(options.setup)))
475
- throw new Error("Settings changed during pull review.");
476
- validateMutation();
477
- const refreshed = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));
478
- if (!sameHashes(fileHashMap(local), fileHashMap(refreshed)))
479
- throw new Error("Local bytes changed during pull review.");
480
- if (!sameRemoteHead(backend, head, await backend.readHead(options.signal)))
481
- throw new Error("Remote changed during pull review.");
482
- validateMutation();
483
- const backup = await backupLocal(config.snapshotIdentity, snapshotOptionsForContext(ctx, config), options.signal);
484
- const applySessionDir = await sessionDirForApply(ctx, physical);
485
- if (recoveringMerge) await requireFreshRecovery();
486
- const currentState = await readStateForConfig(config);
487
- if (!options.yes && syncStateFingerprint(currentState) !== syncStateFingerprint(state))
488
- throw new Error("Baseline changed during pull review.");
489
- requireResolvedDirectionalProgress(currentState, options);
490
- if (!options.yes) await revalidateCaseCleanup(caseCleanup, physical, options.signal);
491
- validateMutation();
492
- options.onCommit?.();
493
- const lastFileHashes = await applySnapshot(physical, protectedSessionPaths(ctx), {
494
- include: config.include,
495
- sessionDir: applySessionDir,
496
- signal: options.signal,
497
- validateMutation,
498
- expectedFileHashes: config.localFields?.length ? { "settings.json": fileHashMap(local)["settings.json"] ?? null } : void 0
499
- });
500
- validateCommittedOwner();
501
- await writeStateForConfig(
502
- config,
503
- {
504
- version: VERSION,
505
- profile: config.snapshotIdentity,
506
- lastAppliedSnapshot: remote.id,
507
- lastRemoteRevision: head?.revision,
508
- lastFileHashes: config.localFields?.length ? { ...lastFileHashes, "settings.json": fileHashMap(logical)["settings.json"] } : lastFileHashes,
509
- include: [...config.include],
510
- ...config.localFields !== void 0 ? { localFields: config.localFields } : {}
511
- },
512
- logical,
513
- validateCommittedOwner
514
- );
515
- await retireMergeJournal(config);
516
- await pruneMergeBaselines(config, await readStateForConfig(config), validateCommittedOwner);
517
- validateCommittedOwner();
518
- if (options.signal?.aborted) return "applied";
519
- setSyncStatus(ctx, void 0);
520
- if (!options.silent) {
521
- ctx.ui.notify(`Pulled ${remote.files.length} files from ${remote.id}. Backup: ${backup}`, "info");
522
- } else if (options.auto && config.include.includes("sessions") && snapshotIncludesSessions(remote)) {
523
- ctx.ui.notify(
524
- "Pulled Pi sessions after startup selected the current session. Restart Pi or resume a pulled session to use newly synced conversations.",
525
- "warning"
526
- );
527
- }
528
- if (options.reload) await maybeReload(ctx, options.signal, validateMutation);
529
- return "applied";
530
- }
531
- async function syncBoth(ctx, options, factory = createSyncBackend) {
532
- const validateMutation = captureMutationOwner(ctx, options.signal);
533
- const config = await loadConfig(options.setup);
534
- throwIfAborted(options.signal);
535
- options.background?.validate(config);
536
- if (options.agentRetryRefusal) {
537
- if (!config.agentMode || options.auto || options.background || !ctx.hasUI)
538
- throw new Error("Enable Autonomous sync and use the foreground manager to retry a cached refusal.");
539
- const state2 = await readStateForConfig(config);
540
- validateMutation();
541
- const pending = await readMergeJournal(config);
542
- validateMutation();
543
- if (!config.include.length || !state2.lastAppliedSnapshot || pending)
544
- throw new Error("Retry requires an accepted baseline and no pending journal. Use Sync now or reviewed recovery.");
545
- return mergeSync(ctx, options, factory);
546
- }
547
- if (config.include.length > 0 && options.auto && startupTransferEnabled(config))
548
- return mergeSync(ctx, options, factory);
549
- if (!options.auto && config.include.length > 0 && await readMergeJournal(config))
550
- return mergeSync(ctx, options, factory);
551
- const state = await readStateForConfig(config);
552
- throwIfAborted(options.signal);
553
- if (!options.auto && config.include.length > 0 && state.lastAppliedSnapshot) return mergeSync(ctx, options, factory);
554
- const backend = await factory(config);
555
- const local = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));
556
- throwIfAborted(options.signal);
557
- if (config.include.length === 0) {
558
- if (!options.silent) {
559
- ctx.ui.notify(
560
- `Sync setup \u201C${config.setupName}\u201D includes no files. Choose included content in /sync Settings before syncing.`,
561
- "warning"
562
- );
563
- }
564
- return;
565
- }
566
- const { head, snapshot: remote } = await readRemoteSnapshot(backend, config, options.signal);
567
- throwIfAborted(options.signal);
568
- const localChanged = hasLocalChanges(local, state, config);
569
- const remoteChanged = remote ? hasRemoteChanges(remote, state, config, protectedSessionPaths(ctx)) : false;
570
- if (options.auto) throw new Error("Automatic transfer is not authorized by the current settings.");
571
- const portableLocal = portableSnapshot(local, config.localFields);
572
- const acceptMatchingState = async (snapshot) => {
573
- requireCompatibleRemoteSelection(config, snapshot);
574
- const accepted = portableSnapshot(snapshot, config.localFields);
575
- await writeStateForConfig(
576
- config,
577
- {
578
- version: VERSION,
579
- profile: config.snapshotIdentity,
580
- lastAppliedSnapshot: snapshot.id,
581
- lastRemoteRevision: head?.revision,
582
- lastFileHashes: fileHashMap(accepted),
583
- include: [...config.include],
584
- ...config.localFields !== void 0 ? { localFields: config.localFields } : {}
585
- },
586
- accepted,
587
- validateMutation
588
- );
589
- await pruneMergeBaselines(config, await readStateForConfig(config), validateMutation);
590
- validateMutation();
591
- };
592
- if (remote && remote.files.length > 0 && local.files.length > 0) {
593
- requireCompatibleRemoteSelection(config, remote);
594
- const portableRemote = portableSnapshot(remote, config.localFields);
595
- if (!canPullRemoteSettingsOnFirstSync(portableLocal, portableRemote)) {
596
- throw createSyncDecision({
597
- kind: "first-sync-settings-diverged",
598
- config,
599
- state,
600
- local,
601
- remote,
602
- localChanged: true,
603
- remoteChanged: true,
604
- directMessage: "Remote settings exist and this machine has different local Pi settings. Run /sync diff, then manually choose /sync pull or /sync push."
605
- });
606
- }
607
- if (!sameHashes(fileHashMap(portableLocal), fileHashMap(portableRemote))) {
608
- if (!canPullRemoteSessionsOnFirstSync(portableLocal, portableRemote)) {
609
- throw createSyncDecision({
610
- kind: "first-sync-sessions-diverged",
611
- config,
612
- state,
613
- local,
614
- remote,
615
- localChanged: true,
616
- remoteChanged: true,
617
- directMessage: "Remote settings match, but local and remote Pi sessions differ. Run /sync diff, then manually choose /sync pull or /sync push."
618
- });
619
- }
620
- await pull(ctx, options, factory);
621
- return;
622
- }
623
- await acceptMatchingState(remote);
624
- if (!options.silent) ctx.ui.notify("pi-sync state initialized; local settings already match remote.", "info");
625
- return;
626
- }
627
- if (localChanged && remoteChanged && remote && snapshotsMatch(portableLocal, portableSnapshot(remote, remote.localFields))) {
628
- requireCompatibleRemoteSelection(config, remote);
629
- await acceptMatchingState(remote);
630
- if (!options.silent) ctx.ui.notify("pi-sync is already up to date.", "info");
631
- return;
632
- }
633
- if (remoteChanged) {
634
- await pull(ctx, options, factory);
635
- return;
636
- }
637
- if (localChanged || !remote) {
638
- await push(ctx, options, void 0, factory);
639
- return;
640
- }
641
- if (shouldRefreshSyncedState(remote, head, state, config, (left, right) => backend.sameRevision(left, right))) {
642
- await acceptMatchingState(remote);
643
- }
644
- if (!options.silent) ctx.ui.notify("pi-sync is already up to date.", "info");
645
- }
646
- async function rollback(ctx, options, factory = createSyncBackend, expectedSelection) {
647
- const validateMutation = captureMutationOwner(ctx, options.signal);
648
- const validateCommittedOwner = captureMutationOwner(ctx);
649
- const target = options.args[0];
650
- if (!target) throw new Error("Usage: /sync rollback <snapshot-id> [--yes]");
651
- const config = await loadConfig(options.setup);
652
- throwIfAborted(options.signal);
653
- const backend = await factory(config);
654
- if (expectedSelection && (backend.identity !== expectedSelection.backendIdentity || config.setupName !== expectedSelection.setup)) {
655
- throw new Error("Sync setup or storage location changed while history was open; reopen history and retry.");
656
- }
657
- await requireNoMergeJournal(config);
658
- const state = await readStateForConfig(config);
659
- validateMutation();
660
- requireResolvedDirectionalProgress(state, options, false);
661
- const decoded = await backend.readSnapshot(target, options.signal);
662
- validatePortableSnapshot(decoded);
663
- if (!sameLocalFields(decoded.localFields, config.localFields))
664
- throw new Error(
665
- "Rollback requires the historical snapshot local-field policy to match the configured rules. Review push --force from current local bytes to migrate policy first; choose matching history afterward."
666
- );
667
- const selected = filterSnapshotForConfigPolicy(
668
- config.include.includes("sessions") ? decoded : snapshotWithoutSessions(decoded),
669
- config
670
- );
671
- const remote = portableSnapshot(regenerateSnapshotIdentity(selected), config.localFields);
672
- const local = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));
673
- const expectedHead = await backend.readHead(options.signal);
674
- const currentRemote = expectedHead ? await readSnapshotForHead(backend, expectedHead, options.signal) : void 0;
675
- validateMutation();
676
- if (!await confirmFieldMigration(ctx, config, state, currentRemote, true, options.signal)) return;
677
- validateMutation();
678
- const physical = overlayLocalFields(remote, local, config.localFields);
679
- const caseCleanup = options.yes ? [] : await inspectCaseCleanup(physical, options.signal);
680
- validateMutation();
681
- if (!options.yes) {
682
- const confirmed = await ctx.ui.confirm(
683
- snapshotIncludesSessions(remote) ? "Rollback pi settings and sessions?" : "Rollback pi settings?",
684
- formatRollbackSummary(
685
- config,
686
- backend.destination,
687
- local,
688
- physical,
689
- target,
690
- protectedSessionPaths(ctx),
691
- caseCleanup.map((item) => item.path)
692
- ),
693
- { signal: options.signal }
694
- );
695
- validateMutation();
696
- if (!confirmed) {
697
- ctx.ui.notify("Rollback cancelled.", "info");
698
- return;
699
- }
700
- }
701
- validateMutation();
702
- const currentLocal = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));
703
- if (!sameHashes(fileHashMap(currentLocal), fileHashMap(local)))
704
- throw new Error("Local bytes changed during rollback review.");
705
- if (syncCheckConfigFingerprint(config) !== syncCheckConfigFingerprint(await loadConfig(options.setup)))
706
- throw new Error("Settings changed during rollback review.");
707
- if (!sameRemoteHead(backend, expectedHead, await backend.readHead(options.signal)))
708
- throw new Error("Remote changed during rollback review.");
709
- validateMutation();
710
- throwIfAborted(options.signal);
711
- const backup = await backupLocal(config.snapshotIdentity, snapshotOptionsForContext(ctx, config), options.signal);
712
- const applySessionDir = await sessionDirForApply(ctx, remote);
713
- const currentState = await readStateForConfig(config);
714
- if (!options.yes && syncStateFingerprint(currentState) !== syncStateFingerprint(state))
715
- throw new Error("Baseline changed during rollback review.");
716
- requireResolvedDirectionalProgress(currentState, options, false);
717
- if (!options.yes) await revalidateCaseCleanup(caseCleanup, physical, options.signal);
718
- validateMutation();
719
- options.onCommit?.();
720
- const lastFileHashes = await applySnapshot(physical, protectedSessionPaths(ctx), {
721
- include: config.include,
722
- sessionDir: applySessionDir,
723
- signal: options.signal,
724
- validateMutation,
725
- expectedFileHashes: config.localFields?.length ? { "settings.json": fileHashMap(local)["settings.json"] ?? null } : void 0
726
- });
727
- validateCommittedOwner();
728
- let result;
729
- try {
730
- const completionSignal = AbortSignal.timeout(POST_LOCAL_COMMIT_TIMEOUT_MS);
731
- const upload = await snapshotForUpload(backend, config, remote, expectedHead, currentRemote, completionSignal);
732
- validateCommittedOwner();
733
- result = await backend.publishSnapshot(upload, expectedRemoteHead(expectedHead), {
734
- signal: completionSignal
735
- });
736
- } catch (error) {
737
- throw new RollbackPublicationError(backup, error);
738
- }
739
- try {
740
- await writeStateForConfig(
741
- config,
742
- {
743
- version: VERSION,
744
- profile: config.snapshotIdentity,
745
- lastAppliedSnapshot: result.head.snapshotId,
746
- lastRemoteRevision: result.head.revision,
747
- lastFileHashes: config.localFields?.length ? { ...lastFileHashes, "settings.json": fileHashMap(remote)["settings.json"] } : lastFileHashes,
748
- include: [...config.include],
749
- ...config.localFields !== void 0 ? { localFields: config.localFields } : {}
750
- },
751
- remote,
752
- validateCommittedOwner
753
- );
754
- } catch (error) {
755
- throw new PublicationStatePersistenceError(result.head, error, backup);
756
- }
757
- await retireMergeJournal(config);
758
- await pruneMergeBaselines(config, await readStateForConfig(config), validateCommittedOwner);
759
- validateCommittedOwner();
760
- if (options.signal?.aborted) return;
761
- ctx.ui.notify(
762
- [
763
- `Rolled back sync setup \u201C${config.setupName}\u201D to ${target}; latest: ${result.head.snapshotId}. Backup: ${backup}`,
764
- ...result.warnings
765
- ].filter(Boolean).join("\n"),
766
- result.warnings.length > 0 ? "warning" : "info"
767
- );
768
- await maybeReload(ctx, options.signal, validateMutation);
769
- }
770
- async function maybeReload(ctx, signal, validateMutation = captureMutationOwner(ctx, signal)) {
771
- if (signal?.aborted || !("reload" in ctx)) return;
772
- validateMutation();
773
- if (ctx.hasUI && await ctx.ui.confirm(
774
- "Reload Pi resources now?",
775
- "This reloads extensions, skills, prompts, themes, and context files."
776
- )) {
777
- if (signal?.aborted) return;
778
- validateMutation();
779
- await ctx.reload();
780
- }
781
- }
782
- async function readRemoteSnapshotForUpload(backend, config, head, state, signal) {
783
- if (!head || head.snapshotId === state.lastAppliedSnapshot && !syncPolicyChanged(state, config) && (!state.lastRemoteRevision || backend.sameRevision(head.revision, state.lastRemoteRevision))) {
784
- return void 0;
785
- }
786
- return readSnapshotForHead(backend, head, signal);
787
- }
788
- async function snapshotForUpload(backend, config, local, head, remote, signal) {
789
- if (!head) return local;
790
- const snapshot = remote ?? await readSnapshotForHead(backend, head, signal);
791
- return mergeRemotePreservedFiles(local, snapshot, config);
792
- }
793
- async function confirmPush(ctx, options, config, backend, local, upload, head, remote, title = snapshotIncludesSessions(upload) ? "Push pi settings and sessions?" : "Push pi settings?") {
794
- throwIfAborted(options.signal);
795
- if (options.yes) return true;
796
- const confirmed = await confirmTransferReview(
797
- ctx,
798
- title,
799
- formatPushSummary(config, backend.destination, upload, head, countPreservedRemoteFiles(local, upload), remote),
800
- options.signal,
801
- captureMutationOwner(ctx, options.signal)
802
- );
803
- throwIfAborted(options.signal);
804
- if (confirmed) return true;
805
- setSyncStatus(ctx, void 0);
806
- ctx.ui.notify("Push cancelled.", "info");
807
- return false;
808
- }
809
- function sameRemoteHead(backend, left, right) {
810
- if (!left || !right) return left === right;
811
- return backend.sameRevision(left.revision, right.revision);
812
- }
813
-
814
- // src/sync/sync-queries.ts
815
- var DEFAULT_PROFILE = "default";
816
- async function status(ctx, options, factory = createSyncBackend) {
817
- const config = await loadConfig(options.setup);
818
- throwIfAborted(options.signal);
819
- setSyncStatus(ctx, `checking ${config.setupName}`, { activity: "checking" });
820
- const { head, selectionState, localChanged, remoteChanged, localFiles, destination, capability } = await inspectSync(
821
- config,
822
- snapshotOptionsForContext(ctx, config),
823
- options.signal,
824
- factory
825
- );
826
- throwIfAborted(options.signal);
827
- const continuous = config.continuous ? await (await import("./continuous-record-EPHGR2DU.ts")).continuousStatusLines(config) : [];
828
- throwIfAborted(options.signal);
829
- const remoteText = head ? `remote: ${head.snapshotId} from ${head.machine} at ${head.createdAt}` : "remote: empty";
830
- const warnings = syncSessionsWarnings(config);
831
- setSyncStatus(ctx, void 0);
832
- ctx.ui.notify(
833
- [
834
- `sync setup: ${config.setupName}`,
835
- `storage connection: ${config.connectionName}`,
836
- `storage location: ${safeTerminalText(destination)}`,
837
- `publication safety: ${publicationCapabilityDescription(capability)}`,
838
- `included content: ${config.include.join(", ") || "none"}`,
839
- `sessions: ${config.include.includes("sessions") ? "included" : "excluded"}`,
840
- ...continuous,
841
- remoteText,
842
- formatRemoteSelectionStatus(selectionState),
843
- `local files: ${localFiles}`,
844
- `local changed since last sync: ${localChanged ? "yes" : "no"}`,
845
- `remote changed since last sync: ${remoteChanged ? "yes" : "no"}`,
846
- ...warnings
847
- ].join("\n"),
848
- localChanged || remoteChanged || selectionState?.kind === "different" || warnings.length > 0 ? "warning" : "info"
849
- );
850
- }
851
- async function diff(ctx, options, factory = createSyncBackend) {
852
- const config = await loadConfig(options.setup);
853
- throwIfAborted(options.signal);
854
- setSyncStatus(ctx, `checking ${config.setupName}`, { activity: "checking" });
855
- const backend = await factory(config);
856
- const local = portableSnapshot(
857
- await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config)),
858
- config.localFields
859
- );
860
- throwIfAborted(options.signal);
861
- const { snapshot: remote, selectionState } = await readRemoteSnapshot(backend, config, options.signal, {
862
- allowSelectionDifference: true
863
- });
864
- throwIfAborted(options.signal);
865
- setSyncStatus(ctx, void 0);
866
- const warnings = syncSessionsWarnings(config);
867
- const header = [
868
- `sync setup: ${config.setupName}`,
869
- `storage connection: ${config.connectionName}`,
870
- `storage location: ${safeTerminalText(backend.destination)}`,
871
- `included content: ${config.include.join(", ") || "none"}`,
872
- `sessions: ${config.include.includes("sessions") ? "included" : "excluded"}`,
873
- formatRemoteSelectionStatus(selectionState),
874
- ...warnings
875
- ].join("\n");
876
- const level = warnings.length > 0 || selectionState?.kind === "different" ? "warning" : "info";
877
- if (!remote) {
878
- ctx.ui.notify(`${header}
879
-
880
- ${formatSnapshotOnlyDiff("Remote is empty. Local push would upload", local)}`, level);
881
- return;
882
- }
883
- ctx.ui.notify(`${header}
884
-
885
- ${formatDiff(local, portableSnapshot(remote, remote.localFields))}`, level);
886
- }
887
- async function doctor(ctx, options, factory = createSyncBackend) {
888
- const messages = [];
889
- let level = "info";
890
- let snapshotOptions = {};
891
- let profile = DEFAULT_PROFILE;
892
- let backend;
893
- let backendSummary = [];
894
- try {
895
- const config = await loadConfig(options.setup);
896
- throwIfAborted(options.signal);
897
- backend = await factory(config);
898
- profile = config.snapshotIdentity;
899
- snapshotOptions = snapshotOptionsForContext(ctx, config);
900
- messages.push(
901
- `config: ok (sync setup ${config.setupName})`,
902
- `included content: ${config.include.join(", ") || "none"}`,
903
- `sessions: ${config.include.includes("sessions") ? "included" : "excluded"}`
904
- );
905
- backendSummary = [
906
- `storage location: ${safeTerminalText(backend.destination)}`,
907
- `publication safety: ${publicationCapabilityDescription(backend.capability)}`
908
- ];
909
- const warnings = syncSessionsWarnings(config);
910
- if (warnings.length > 0) {
911
- level = "warning";
912
- messages.push(...warnings);
913
- }
914
- } catch (error) {
915
- throwIfAborted(options.signal);
916
- level = "warning";
917
- messages.push(`config: ${errorMessage(error)}`);
918
- }
919
- const local = await createSnapshot(profile, snapshotOptions);
920
- throwIfAborted(options.signal);
921
- const secrets = scanSnapshot(local);
922
- if (secrets.length > 0) {
923
- level = "warning";
924
- messages.push("secret scan: possible secrets found:");
925
- messages.push(...secrets.map((secret) => `- ${secret}`));
926
- } else {
927
- messages.push(`secret scan: ok (${local.files.length} files checked)`);
928
- }
929
- const lock = await inspectLock();
930
- throwIfAborted(options.signal);
931
- if (lock.status === "valid" && isStaleLock(lock.lock)) {
932
- level = "warning";
933
- messages.push(`lock: stale (pid ${lock.lock.pid}); run /sync unlock --stale after verifying no sync is running`);
934
- } else if (lock.status === "valid") {
935
- messages.push(`lock: held by pid ${lock.lock.pid} since ${lock.lock.startedAt}`);
936
- } else if (lock.status === "unreadable") {
937
- level = "warning";
938
- messages.push("lock: unreadable; use /sync unlock --stale only after verifying no sync is running");
939
- } else if (await isLockGuardHeld()) {
940
- throwIfAborted(options.signal);
941
- level = "warning";
942
- messages.push("lock: guard active while metadata is missing or still being initialized");
943
- } else {
944
- messages.push("lock: free");
945
- }
946
- if (backend) {
947
- messages.push(...backendSummary);
948
- const diagnostics = await backend.diagnose(options.signal);
949
- throwIfAborted(options.signal);
950
- for (const diagnostic of diagnostics) {
951
- messages.push(diagnostic.message);
952
- if (diagnostic.level !== "info") level = "warning";
953
- }
954
- }
955
- ctx.ui.notify(messages.join("\n"), level);
956
- }
957
- async function history(ctx, options, factory = createSyncBackend) {
958
- const config = await loadConfig(options.setup);
959
- throwIfAborted(options.signal);
960
- const backend = await factory(config);
961
- const snapshots = (await backend.listHistory(options.signal)).slice(-20).reverse();
962
- throwIfAborted(options.signal);
963
- const lastApplied = await readStateForConfig(config).then((state) => state.lastAppliedSnapshot).catch(() => void 0);
964
- throwIfAborted(options.signal);
965
- const appliedDetails = lastApplied ? `Last applied snapshot ID: ${safeTerminalText(lastApplied)}
966
- Application time: unavailable. Snapshot dates are creation times.` : "Last applied snapshot ID: unavailable.";
967
- if (snapshots.length === 0) {
968
- ctx.ui.notify(`No remote pi-sync history found.
969
- ${appliedDetails}`, "info");
970
- return;
971
- }
972
- const currentSnapshot = snapshots[0]?.snapshotId;
973
- if (ctx.mode === "tui") {
974
- const labels = snapshots.map(
975
- (item, index2) => `${index2 + 1}. ${item.createdAt} \xB7 ${safeTerminalText(item.machine)} \xB7 ${item.snapshotId}${item.snapshotId === currentSnapshot ? " (current)" : ""}${item.syncSessions ? " \xB7 sessions" : ""}`
976
- );
977
- const selected = await ctx.ui.select(
978
- `History for sync setup \u201C${safeTerminalText(config.setupName)}\u201D
979
-
980
- ${appliedDetails}
981
-
982
- Choose a snapshot to preview rollback.`,
983
- [...labels, "Back"],
984
- { signal: options.signal }
985
- );
986
- if (!selected || selected === "Back") return;
987
- throwIfAborted(options.signal);
988
- const index = labels.indexOf(selected);
989
- const snapshot = snapshots[index];
990
- if (!snapshot) return;
991
- await withLock(
992
- "rollback",
993
- () => rollback(ctx, { ...options, args: [snapshot.snapshotRef], yes: false }, factory, {
994
- backendIdentity: backend.identity,
995
- setup: config.setupName
996
- })
997
- );
998
- return;
999
- }
1000
- ctx.ui.notify(
1001
- [
1002
- appliedDetails,
1003
- ...snapshots.map((item) => `${item.snapshotRef} ${item.createdAt} ${safeTerminalText(item.machine)}`)
1004
- ].join("\n"),
1005
- "info"
1006
- );
1007
- }
1008
- export {
1009
- PublicationStatePersistenceError,
1010
- RollbackPublicationError,
1011
- backupLocal,
1012
- diff,
1013
- doctor,
1014
- history,
1015
- pull,
1016
- push,
1017
- rollback,
1018
- status,
1019
- syncBoth
1020
- };
1021
- //# sourceMappingURL=sync-operations-45APGOL3.ts.map