@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.
- package/CHANGELOG.md +21 -0
- package/README.md +28 -15
- package/dist/chunks/{chunk-AMJRUXFT.ts → chunk-2JNFEZ3V.ts} +2 -6
- package/dist/chunks/{chunk-AMJRUXFT.ts.map → chunk-2JNFEZ3V.ts.map} +1 -1
- package/dist/chunks/{chunk-MG66XM5U.ts → chunk-4RNCZZY7.ts} +86 -36
- package/dist/chunks/chunk-4RNCZZY7.ts.map +7 -0
- package/dist/chunks/{config-HYG7G5EM.ts → chunk-7AC2RX4M.ts} +6 -12
- package/dist/chunks/chunk-7AC2RX4M.ts.map +7 -0
- package/dist/chunks/{chunk-XEODG2PE.ts → chunk-BGGKHHO4.ts} +18 -14
- package/dist/chunks/{chunk-XEODG2PE.ts.map → chunk-BGGKHHO4.ts.map} +1 -1
- package/dist/chunks/chunk-BWWTOQOW.ts +737 -0
- package/dist/chunks/chunk-BWWTOQOW.ts.map +7 -0
- package/dist/chunks/chunk-CEMFCWIU.ts +20 -0
- package/dist/chunks/chunk-CEMFCWIU.ts.map +7 -0
- package/dist/chunks/chunk-CZNBKIM5.ts +20 -0
- package/dist/chunks/chunk-CZNBKIM5.ts.map +7 -0
- package/dist/chunks/{chunk-YIPK23JW.ts → chunk-ENFHHB5O.ts} +1 -16
- package/dist/chunks/{chunk-YIPK23JW.ts.map → chunk-ENFHHB5O.ts.map} +1 -1
- package/dist/chunks/{chunk-KHBPED6W.ts → chunk-GSQGBVKG.ts} +2 -2
- package/dist/chunks/chunk-HNKLBM3U.ts +18 -0
- package/dist/chunks/chunk-HNKLBM3U.ts.map +7 -0
- package/dist/chunks/{chunk-QPC5HT3A.ts → chunk-J5COV5TY.ts} +21 -2
- package/dist/chunks/chunk-J5COV5TY.ts.map +7 -0
- package/dist/chunks/chunk-JKBUYCPC.ts +52 -0
- package/dist/chunks/chunk-JKBUYCPC.ts.map +7 -0
- package/dist/chunks/chunk-JZKCOM62.ts +26 -0
- package/dist/chunks/chunk-JZKCOM62.ts.map +7 -0
- package/dist/chunks/chunk-M7RHV3H6.ts +33 -0
- package/dist/chunks/chunk-M7RHV3H6.ts.map +7 -0
- package/dist/chunks/{chunk-REMGB255.ts → chunk-MIXZVHFR.ts} +35 -10
- package/dist/chunks/chunk-MIXZVHFR.ts.map +7 -0
- package/dist/chunks/chunk-NPT2G4FU.ts +15 -0
- package/dist/chunks/chunk-NPT2G4FU.ts.map +7 -0
- package/dist/chunks/chunk-PDBTD2K6.ts +11 -0
- package/dist/chunks/chunk-PDBTD2K6.ts.map +7 -0
- package/dist/chunks/chunk-UBE6XWOM.ts +29 -0
- package/dist/chunks/chunk-UBE6XWOM.ts.map +7 -0
- package/dist/chunks/{chunk-JYILGR3K.ts → chunk-UZUUUY7C.ts} +8 -8
- package/dist/chunks/chunk-VZCWYXRS.ts +23 -0
- package/dist/chunks/chunk-VZCWYXRS.ts.map +7 -0
- package/dist/chunks/{chunk-U6GXGY5G.ts → chunk-YWEYRRQI.ts} +45 -37
- package/dist/chunks/chunk-YWEYRRQI.ts.map +7 -0
- package/dist/chunks/{chunk-ECYCNZOE.ts → chunk-ZMNVNECV.ts} +5 -1
- package/dist/chunks/chunk-ZMNVNECV.ts.map +7 -0
- package/dist/chunks/{command-handler-MRXE5AKK.ts → command-handler-3O76V7Q5.ts} +83 -87
- package/dist/chunks/command-handler-3O76V7Q5.ts.map +7 -0
- package/dist/chunks/conflict-review-XBSME2ER.ts +18 -0
- package/dist/chunks/conflict-review-XBSME2ER.ts.map +7 -0
- package/dist/chunks/{continuous-record-EPHGR2DU.ts → continuous-record-ZHUXVO4E.ts} +5 -13
- package/dist/chunks/continuous-record-ZHUXVO4E.ts.map +7 -0
- package/dist/chunks/{file-selection-IELTXSGZ.ts → file-selection-S6CNNNQI.ts} +14 -14
- package/dist/chunks/file-selection-S6CNNNQI.ts.map +7 -0
- package/dist/chunks/manager-result-dispatcher-I2AMCCE7.ts +18 -0
- package/dist/chunks/{manager-ui-AY34N4UY.ts → manager-ui-SJOBTJLY.ts} +221 -147
- package/dist/chunks/manager-ui-SJOBTJLY.ts.map +7 -0
- package/dist/chunks/merge-review-SGDLMVS4.ts +10 -0
- package/dist/chunks/remote-selection-ui-GZHPDQ4L.ts +17 -0
- package/dist/chunks/{setup-switch-KLGESLQX.ts → setup-switch-M3BAFGJM.ts} +9 -12
- package/dist/chunks/{setup-wizard-ZQAK35BP.ts → setup-wizard-NFAWP4KF.ts} +18 -20
- package/dist/chunks/{setup-wizard-ZQAK35BP.ts.map → setup-wizard-NFAWP4KF.ts.map} +1 -1
- package/dist/chunks/{snapshot-RGNDYT6A.ts → snapshot-D4SFDP5J.ts} +8 -12
- package/dist/chunks/snapshot-D4SFDP5J.ts.map +7 -0
- package/dist/chunks/snapshot-transaction-directory-TNKBQ3UQ.ts +13 -0
- package/dist/chunks/snapshot-transaction-directory-TNKBQ3UQ.ts.map +7 -0
- package/dist/chunks/state-directory-JZSZVVPX.ts +17 -0
- package/dist/chunks/sync-inspection-BJ4KPPNO.ts +23 -0
- package/dist/chunks/sync-inspection-BJ4KPPNO.ts.map +7 -0
- package/dist/chunks/sync-operations-TLWER2TT.ts +45 -0
- package/dist/chunks/sync-operations-TLWER2TT.ts.map +7 -0
- package/dist/chunks/{sync-state-7L4NT7W2.ts → sync-state-FVCJJ7MY.ts} +5 -10
- package/dist/chunks/sync-state-FVCJJ7MY.ts.map +7 -0
- package/dist/index.ts +269 -306
- package/dist/index.ts.map +4 -4
- package/docs/daemon-migration.md +93 -0
- package/docs/exclude-policy-audit.md +54 -0
- package/docs/exclude-review-ledger.md +36 -0
- package/docs/tui-contract.md +1 -1
- package/package.json +3 -5
- package/skills/configure-pi-sync/SKILL.md +5 -4
- package/skills/configure-pi-sync/references/configuration.md +91 -19
- package/src/backends/backend-factory.ts +2 -23
- package/src/backends/backend-identity.ts +5 -40
- package/src/backends/backend-types.ts +1 -81
- package/src/backends/git/git-backend.ts +6 -784
- package/src/backends/git/git-config.ts +8 -130
- package/src/backends/git/git-runner.ts +7 -255
- package/src/backends/git/git-storage.ts +14 -292
- package/src/backends/s3/s3-backend.ts +11 -523
- package/src/backends/s3/s3-client.ts +2 -399
- package/src/backends/s3/s3-conditions.ts +2 -67
- package/src/backends/snapshot-pointer.ts +2 -27
- package/src/backends/sync-backend.ts +6 -101
- package/src/backends/webdav/webdav-backend.ts +10 -622
- package/src/backends/webdav/webdav-client.ts +6 -370
- package/src/backends/webdav/webdav-config.ts +8 -82
- package/src/commands/command-execution.ts +42 -38
- package/src/commands/command.ts +23 -1
- package/src/daemon/apply-gate.ts +146 -0
- package/src/daemon/pi-client.ts +591 -0
- package/src/daemon/recovery.ts +103 -0
- package/src/paths.ts +12 -83
- package/src/settings/config-errors.ts +2 -6
- package/src/settings/config-file.ts +19 -693
- package/src/settings/config.ts +16 -257
- package/src/settings/settings-management.ts +11 -253
- package/src/settings/settings-store.ts +10 -48
- package/src/settings/settings-types.ts +1 -154
- package/src/settings/settings-validation.ts +17 -431
- package/src/snapshot/session-paths.ts +11 -110
- package/src/snapshot/snapshot-apply.ts +9 -306
- package/src/snapshot/snapshot-case-replacement.ts +6 -80
- package/src/snapshot/snapshot-codec.ts +2 -50
- package/src/snapshot/snapshot-exclude-safety.ts +2 -0
- package/src/snapshot/snapshot-mutation-queues.ts +6 -142
- package/src/snapshot/snapshot-paths.ts +2 -11
- package/src/snapshot/snapshot-root-transition.ts +6 -154
- package/src/snapshot/snapshot-transaction-directory.ts +5 -16
- package/src/snapshot/snapshot-transaction-plan.ts +2 -72
- package/src/snapshot/snapshot-transaction.ts +6 -934
- package/src/snapshot/snapshot-types.ts +1 -43
- package/src/snapshot/snapshot.ts +18 -405
- package/src/state/json-file.ts +2 -47
- package/src/state/lock-policy.ts +2 -2
- package/src/state/lock.ts +10 -292
- package/src/state/lockfile-fs.ts +2 -25
- package/src/state/merge-baseline-store.ts +8 -200
- package/src/state/mutation-directory-sync.ts +2 -34
- package/src/state/operation-availability.ts +7 -59
- package/src/state/state-directory.ts +8 -243
- package/src/state/state-types.ts +1 -24
- package/src/state/sync-state-store.ts +11 -75
- package/src/sync/agent-candidate.ts +7 -256
- package/src/sync/agent-plan.ts +2 -107
- package/src/sync/agent-policy.ts +10 -13
- package/src/sync/agent-refusal-retry.ts +2 -54
- package/src/sync/agent-request.ts +2 -19
- package/src/sync/agent-runner.ts +2 -191
- package/src/sync/agent-store.ts +7 -182
- package/src/sync/agent-sync.ts +2 -141
- package/src/sync/apply-review.ts +2 -63
- package/src/sync/automatic-sync.ts +55 -106
- package/src/sync/conflict-artifact-ownership.ts +2 -63
- package/src/sync/conflict-artifacts.ts +8 -195
- package/src/sync/conflict-groups.ts +2 -68
- package/src/sync/conflict-preview.ts +2 -56
- package/src/sync/conflict-resolution.ts +2 -93
- package/src/sync/conflict-retention.ts +2 -72
- package/src/sync/conflict-review.ts +3 -92
- package/src/sync/content-conflicts.ts +2 -73
- package/src/sync/continuous-errors.ts +7 -85
- package/src/sync/continuous-lease.ts +2 -216
- package/src/sync/continuous-record.ts +10 -261
- package/src/sync/continuous-storage.ts +12 -64
- package/src/sync/continuous-sync.ts +2 -563
- package/src/sync/continuous-watch.ts +2 -59
- package/src/sync/exclude-policy.ts +6 -0
- package/src/sync/field-migration.ts +2 -39
- package/src/sync/file-merge-planner.ts +2 -143
- package/src/sync/json-document.ts +7 -184
- package/src/sync/local-field-policy.ts +2 -29
- package/src/sync/local-fields.ts +9 -108
- package/src/sync/merge-apply.ts +2 -434
- package/src/sync/merge-journal.ts +10 -219
- package/src/sync/merge-transfer-error.ts +2 -72
- package/src/sync/merged-sync.ts +2 -914
- package/src/sync/mutation-owner.ts +2 -22
- package/src/sync/package-merge.ts +2 -87
- package/src/sync/partial-progress.ts +2 -54
- package/src/sync/remote-snapshot.ts +7 -80
- package/src/sync/session-merge.ts +2 -194
- package/src/sync/settings-conflicts.ts +2 -64
- package/src/sync/settings-merge.ts +6 -121
- package/src/sync/signals.ts +2 -8
- package/src/sync/startup-check.ts +15 -31
- package/src/sync/startup-timings.ts +2 -94
- package/src/sync/sync-decision.ts +3 -101
- package/src/sync/sync-error-guidance.ts +2 -46
- package/src/sync/sync-errors.ts +7 -23
- package/src/sync/sync-inspection.ts +10 -57
- package/src/sync/sync-local.ts +2 -44
- package/src/sync/sync-mutations.ts +10 -781
- package/src/sync/sync-operations.ts +32 -11
- package/src/sync/sync-policy.ts +34 -410
- package/src/sync/sync-queries.ts +2 -237
- package/src/sync/sync-state.ts +18 -151
- package/src/sync/text-merge.ts +10 -133
- package/src/sync-extension.ts +192 -142
- package/src/ui/excluded-paths-ui.ts +106 -0
- package/src/ui/file-selection.ts +6 -3
- package/src/ui/manager-state.ts +11 -5
- package/src/ui/remote-selection-ui.ts +73 -10
- package/src/ui/settings-ui.ts +20 -5
- package/src/ui/setup/setup-actions.ts +1 -1
- package/src/ui/setup/setup-switcher.ts +3 -2
- package/src/ui/storage-connections-ui.ts +2 -2
- package/src/ui/sync-attention.ts +17 -3
- package/src/ui/sync-format.ts +13 -1
- package/dist/chunks/agent-candidate-U2NU3GUX.ts +0 -29
- package/dist/chunks/agent-plan-3YXDIJXO.ts +0 -123
- package/dist/chunks/agent-plan-3YXDIJXO.ts.map +0 -7
- package/dist/chunks/agent-refusal-retry-476YGNU5.ts +0 -72
- package/dist/chunks/agent-refusal-retry-476YGNU5.ts.map +0 -7
- package/dist/chunks/agent-runner-FCRV2Z75.ts +0 -185
- package/dist/chunks/agent-runner-FCRV2Z75.ts.map +0 -7
- package/dist/chunks/agent-store-7GINKTS7.ts +0 -175
- package/dist/chunks/agent-store-7GINKTS7.ts.map +0 -7
- package/dist/chunks/agent-sync-2R4GG2MF.ts +0 -22
- package/dist/chunks/chunk-2JZFHNLM.ts +0 -113
- package/dist/chunks/chunk-2JZFHNLM.ts.map +0 -7
- package/dist/chunks/chunk-3ST7RSYN.ts +0 -21
- package/dist/chunks/chunk-3ST7RSYN.ts.map +0 -7
- package/dist/chunks/chunk-45COPAK7.ts +0 -205
- package/dist/chunks/chunk-45COPAK7.ts.map +0 -7
- package/dist/chunks/chunk-5SFMBY5P.ts +0 -26
- package/dist/chunks/chunk-5SFMBY5P.ts.map +0 -7
- package/dist/chunks/chunk-5TSCBBPP.ts +0 -229
- package/dist/chunks/chunk-5TSCBBPP.ts.map +0 -7
- package/dist/chunks/chunk-6LD5KX55.ts +0 -396
- package/dist/chunks/chunk-6LD5KX55.ts.map +0 -7
- package/dist/chunks/chunk-6O3EDBRL.ts +0 -258
- package/dist/chunks/chunk-6O3EDBRL.ts.map +0 -7
- package/dist/chunks/chunk-7A35ZAVO.ts +0 -1109
- package/dist/chunks/chunk-7A35ZAVO.ts.map +0 -7
- package/dist/chunks/chunk-7D5SF7P3.ts +0 -29
- package/dist/chunks/chunk-7D5SF7P3.ts.map +0 -7
- package/dist/chunks/chunk-7ZIYU5QS.ts +0 -64
- package/dist/chunks/chunk-7ZIYU5QS.ts.map +0 -7
- package/dist/chunks/chunk-AKMV47YC.ts +0 -215
- package/dist/chunks/chunk-AKMV47YC.ts.map +0 -7
- package/dist/chunks/chunk-AR2DGDUI.ts +0 -55
- package/dist/chunks/chunk-AR2DGDUI.ts.map +0 -7
- package/dist/chunks/chunk-BEST45H2.ts +0 -153
- package/dist/chunks/chunk-BEST45H2.ts.map +0 -7
- package/dist/chunks/chunk-CBLTWXAU.ts +0 -114
- package/dist/chunks/chunk-CBLTWXAU.ts.map +0 -7
- package/dist/chunks/chunk-CQD2TJHE.ts +0 -220
- package/dist/chunks/chunk-CQD2TJHE.ts.map +0 -7
- package/dist/chunks/chunk-DN4IA7MR.ts +0 -61
- package/dist/chunks/chunk-DN4IA7MR.ts.map +0 -7
- package/dist/chunks/chunk-DT7M4VQS.ts +0 -69
- package/dist/chunks/chunk-DT7M4VQS.ts.map +0 -7
- package/dist/chunks/chunk-ECYCNZOE.ts.map +0 -7
- package/dist/chunks/chunk-ESKOPQVB.ts +0 -348
- package/dist/chunks/chunk-ESKOPQVB.ts.map +0 -7
- package/dist/chunks/chunk-FHE2DCA2.ts +0 -61
- package/dist/chunks/chunk-FHE2DCA2.ts.map +0 -7
- package/dist/chunks/chunk-FLHCOJCD.ts +0 -57
- package/dist/chunks/chunk-FLHCOJCD.ts.map +0 -7
- package/dist/chunks/chunk-G4RUXRWZ.ts +0 -48
- package/dist/chunks/chunk-G4RUXRWZ.ts.map +0 -7
- package/dist/chunks/chunk-GNYGNHFF.ts +0 -27
- package/dist/chunks/chunk-GNYGNHFF.ts.map +0 -7
- package/dist/chunks/chunk-KYTT7KV4.ts +0 -319
- package/dist/chunks/chunk-KYTT7KV4.ts.map +0 -7
- package/dist/chunks/chunk-M6VQJIOU.ts +0 -54
- package/dist/chunks/chunk-M6VQJIOU.ts.map +0 -7
- package/dist/chunks/chunk-MG66XM5U.ts.map +0 -7
- package/dist/chunks/chunk-MKSMJPVA.ts +0 -107
- package/dist/chunks/chunk-MKSMJPVA.ts.map +0 -7
- package/dist/chunks/chunk-MMQIEDZ6.ts +0 -1994
- package/dist/chunks/chunk-MMQIEDZ6.ts.map +0 -7
- package/dist/chunks/chunk-OJARL2TG.ts +0 -25
- package/dist/chunks/chunk-OJARL2TG.ts.map +0 -7
- package/dist/chunks/chunk-OVBAW7KV.ts +0 -1174
- package/dist/chunks/chunk-OVBAW7KV.ts.map +0 -7
- package/dist/chunks/chunk-PRUEIIK7.ts +0 -24
- package/dist/chunks/chunk-PRUEIIK7.ts.map +0 -7
- package/dist/chunks/chunk-PWMWOJP4.ts +0 -17
- package/dist/chunks/chunk-PWMWOJP4.ts.map +0 -7
- package/dist/chunks/chunk-QPC5HT3A.ts.map +0 -7
- package/dist/chunks/chunk-REMGB255.ts.map +0 -7
- package/dist/chunks/chunk-S5OCYVPS.ts +0 -415
- package/dist/chunks/chunk-S5OCYVPS.ts.map +0 -7
- package/dist/chunks/chunk-SWRVXVFD.ts +0 -248
- package/dist/chunks/chunk-SWRVXVFD.ts.map +0 -7
- package/dist/chunks/chunk-T2SJD3N7.ts +0 -99
- package/dist/chunks/chunk-T2SJD3N7.ts.map +0 -7
- package/dist/chunks/chunk-TIMWN2RH.ts +0 -89
- package/dist/chunks/chunk-TIMWN2RH.ts.map +0 -7
- package/dist/chunks/chunk-TZC7GDJE.ts +0 -58
- package/dist/chunks/chunk-TZC7GDJE.ts.map +0 -7
- package/dist/chunks/chunk-U6GXGY5G.ts.map +0 -7
- package/dist/chunks/chunk-WQMYV4DW.ts +0 -140
- package/dist/chunks/chunk-WQMYV4DW.ts.map +0 -7
- package/dist/chunks/chunk-X7R6DCVF.ts +0 -28
- package/dist/chunks/chunk-X7R6DCVF.ts.map +0 -7
- package/dist/chunks/chunk-XJHQPB3E.ts +0 -107
- package/dist/chunks/chunk-XJHQPB3E.ts.map +0 -7
- package/dist/chunks/chunk-Y4UVXOLQ.ts +0 -123
- package/dist/chunks/chunk-Y4UVXOLQ.ts.map +0 -7
- package/dist/chunks/chunk-YDVQYUHE.ts +0 -34
- package/dist/chunks/chunk-YDVQYUHE.ts.map +0 -7
- package/dist/chunks/chunk-YHT4YTYG.ts +0 -31
- package/dist/chunks/chunk-YHT4YTYG.ts.map +0 -7
- package/dist/chunks/chunk-ZW5ZLGBI.ts +0 -154
- package/dist/chunks/chunk-ZW5ZLGBI.ts.map +0 -7
- package/dist/chunks/command-handler-MRXE5AKK.ts.map +0 -7
- package/dist/chunks/conflict-artifacts-J6WSDCWP.ts +0 -32
- package/dist/chunks/conflict-review-GXA6Y7KY.ts +0 -189
- package/dist/chunks/conflict-review-GXA6Y7KY.ts.map +0 -7
- package/dist/chunks/continuous-sync-FAFNLEUW.ts +0 -585
- package/dist/chunks/continuous-sync-FAFNLEUW.ts.map +0 -7
- package/dist/chunks/file-selection-IELTXSGZ.ts.map +0 -7
- package/dist/chunks/git-backend-KHD36W27.ts +0 -1077
- package/dist/chunks/git-backend-KHD36W27.ts.map +0 -7
- package/dist/chunks/local-fields-JEKAPZKD.ts +0 -26
- package/dist/chunks/local-fields-JEKAPZKD.ts.map +0 -7
- package/dist/chunks/manager-result-dispatcher-XCYPW7RC.ts +0 -32
- package/dist/chunks/manager-result-dispatcher-XCYPW7RC.ts.map +0 -7
- package/dist/chunks/manager-ui-AY34N4UY.ts.map +0 -7
- package/dist/chunks/merge-baseline-store-65GKUMXI.ts +0 -25
- package/dist/chunks/merge-baseline-store-65GKUMXI.ts.map +0 -7
- package/dist/chunks/remote-selection-ui-MYM2YCPF.ts +0 -31
- package/dist/chunks/remote-selection-ui-MYM2YCPF.ts.map +0 -7
- package/dist/chunks/s3-backend-L24UZ6IK.ts +0 -844
- package/dist/chunks/s3-backend-L24UZ6IK.ts.map +0 -7
- package/dist/chunks/setup-switch-KLGESLQX.ts.map +0 -7
- package/dist/chunks/snapshot-RGNDYT6A.ts.map +0 -7
- package/dist/chunks/snapshot-transaction-26BQO36S.ts +0 -24
- package/dist/chunks/snapshot-transaction-26BQO36S.ts.map +0 -7
- package/dist/chunks/sync-inspection-MOMLGUTD.ts +0 -25
- package/dist/chunks/sync-inspection-MOMLGUTD.ts.map +0 -7
- package/dist/chunks/sync-operations-45APGOL3.ts +0 -1021
- package/dist/chunks/sync-operations-45APGOL3.ts.map +0 -7
- package/dist/chunks/sync-state-7L4NT7W2.ts.map +0 -7
- package/dist/chunks/webdav-backend-3ZCACILP.ts +0 -851
- package/dist/chunks/webdav-backend-3ZCACILP.ts.map +0 -7
- /package/dist/chunks/{chunk-KHBPED6W.ts.map → chunk-GSQGBVKG.ts.map} +0 -0
- /package/dist/chunks/{chunk-JYILGR3K.ts.map → chunk-UZUUUY7C.ts.map} +0 -0
- /package/dist/chunks/{agent-candidate-U2NU3GUX.ts.map → manager-result-dispatcher-I2AMCCE7.ts.map} +0 -0
- /package/dist/chunks/{agent-sync-2R4GG2MF.ts.map → merge-review-SGDLMVS4.ts.map} +0 -0
- /package/dist/chunks/{config-HYG7G5EM.ts.map → remote-selection-ui-GZHPDQ4L.ts.map} +0 -0
- /package/dist/chunks/{conflict-artifacts-J6WSDCWP.ts.map → setup-switch-M3BAFGJM.ts.map} +0 -0
- /package/dist/chunks/{continuous-record-EPHGR2DU.ts.map → state-directory-JZSZVVPX.ts.map} +0 -0
|
@@ -1,110 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
const usesDefaultSessionDir = manager.usesDefaultSessionDir;
|
|
14
|
-
if (typeof usesDefaultSessionDir === "function" && usesDefaultSessionDir.call(manager)) {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
const getSessionDir = manager.getSessionDir;
|
|
18
|
-
return typeof getSessionDir === "function" ? (getSessionDir.call(manager) as string | undefined) : undefined;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function configuredSessionDir() {
|
|
22
|
-
let content: string;
|
|
23
|
-
try {
|
|
24
|
-
content = await fs.readFile(path.join(agentDir(), "settings.json"), "utf8");
|
|
25
|
-
} catch (error) {
|
|
26
|
-
if ((error as NodeJS.ErrnoException).code === "ENOENT") return undefined;
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
29
|
-
let settings: { sessionDir?: string } | null;
|
|
30
|
-
try {
|
|
31
|
-
// Pi accepts a leading UTF-8 BOM in its settings file; snapshot bytes stay unchanged.
|
|
32
|
-
settings = JSON.parse(content.replace(/^\uFEFF/u, "")) as typeof settings;
|
|
33
|
-
} catch {
|
|
34
|
-
throw new SyntaxError("Pi settings.json cannot be parsed; repair the file before syncing.");
|
|
35
|
-
}
|
|
36
|
-
return settings?.sessionDir ? expandSessionDir(settings.sessionDir) : undefined;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export async function effectiveSessionRoot(ctx: ExtensionCommandContext | ExtensionContext) {
|
|
40
|
-
return path.resolve(sessionStorageRoot(agentDir(), sessionDirFromContext(ctx) ?? (await configuredSessionDir())));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export async function sessionDirForApply(ctx: ExtensionCommandContext | ExtensionContext, snapshot: Snapshot) {
|
|
44
|
-
const contextSessionDir = sessionDirFromContext(ctx);
|
|
45
|
-
const localSessionDir = await configuredSessionDir();
|
|
46
|
-
if (contextSessionDir && path.resolve(contextSessionDir) !== path.resolve(localSessionDir ?? "")) {
|
|
47
|
-
return contextSessionDir;
|
|
48
|
-
}
|
|
49
|
-
return sessionDirFromSnapshot(snapshot) ?? contextSessionDir;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** Hash-only merge plans cannot describe installation into a different session root. */
|
|
53
|
-
export function requireStableMergeSessionRoot(before: Snapshot, after: Snapshot) {
|
|
54
|
-
const root = agentDir();
|
|
55
|
-
if (
|
|
56
|
-
path.resolve(sessionStorageRoot(root, sessionDirFromSnapshot(before))) !==
|
|
57
|
-
path.resolve(sessionStorageRoot(root, sessionDirFromSnapshot(after)))
|
|
58
|
-
) {
|
|
59
|
-
throw new Error(
|
|
60
|
-
"Merged transfer changes the session root; no local apply or baseline acceptance is allowed. Review /sync diff and choose an explicit push or pull direction.",
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function sessionDirFromSnapshot(snapshot: Snapshot) {
|
|
66
|
-
const settingsFile = snapshot.files.find((file) => file.path === "settings.json");
|
|
67
|
-
if (!settingsFile) return undefined;
|
|
68
|
-
let settings: unknown;
|
|
69
|
-
try {
|
|
70
|
-
settings = JSON.parse(
|
|
71
|
-
new TextDecoder("utf-8", { fatal: true }).decode(
|
|
72
|
-
decodeBase64Strict(settingsFile.contentBase64, settingsFile.path),
|
|
73
|
-
),
|
|
74
|
-
);
|
|
75
|
-
} catch {
|
|
76
|
-
// JSON parser errors can quote private settings values; never surface their payload.
|
|
77
|
-
throw new Error("Merged settings cannot be parsed; review a directional recovery.");
|
|
78
|
-
}
|
|
79
|
-
if (!settings || typeof settings !== "object" || Array.isArray(settings))
|
|
80
|
-
throw new Error("Merged settings must be a JSON object; review a directional recovery.");
|
|
81
|
-
const sessionDir = (settings as { sessionDir?: unknown }).sessionDir;
|
|
82
|
-
if (sessionDir !== undefined && typeof sessionDir !== "string")
|
|
83
|
-
throw new Error("Merged sessionDir must be a string; review a directional recovery.");
|
|
84
|
-
return sessionDir ? expandSessionDir(sessionDir) : undefined;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function decodeBase64Strict(value: string, filePath: string) {
|
|
88
|
-
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(value) || value.length % 4 !== 0) {
|
|
89
|
-
throw new Error(`Invalid base64 content in snapshot file: ${filePath}`);
|
|
90
|
-
}
|
|
91
|
-
return Buffer.from(value, "base64");
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function agentDir() {
|
|
95
|
-
return getAgentDir();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function expandSessionDir(value: string) {
|
|
99
|
-
return value === "~" || value.startsWith("~/") ? path.join(os.homedir(), value.slice(2)) : value;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function snapshotOptionsForContext(
|
|
103
|
-
ctx: ExtensionCommandContext | ExtensionContext,
|
|
104
|
-
config: AnySyncConfig,
|
|
105
|
-
): SnapshotOptions {
|
|
106
|
-
return {
|
|
107
|
-
include: config.include,
|
|
108
|
-
sessionDir: sessionDirFromContext(ctx),
|
|
109
|
-
};
|
|
110
|
-
}
|
|
1
|
+
export type * from "@narumitw/sync-daemon/engine/snapshot/session-paths";
|
|
2
|
+
export {
|
|
3
|
+
agentDir,
|
|
4
|
+
configuredSessionDir,
|
|
5
|
+
effectiveSessionRoot,
|
|
6
|
+
expandSessionDir,
|
|
7
|
+
requireStableMergeSessionRoot,
|
|
8
|
+
sessionDirForApply,
|
|
9
|
+
sessionDirFromContext,
|
|
10
|
+
snapshotOptionsForContext,
|
|
11
|
+
} from "@narumitw/sync-daemon/engine/snapshot/session-paths";
|
|
@@ -1,306 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
isSessionFilePath,
|
|
11
|
-
isSessionPath,
|
|
12
|
-
sessionStorageRoot,
|
|
13
|
-
snapshotIncludesSessions,
|
|
14
|
-
snapshotTarget,
|
|
15
|
-
} from "./snapshot.js";
|
|
16
|
-
import { applySnapshotTransaction, recoverPendingSnapshotTransactions } from "./snapshot-transaction.js";
|
|
17
|
-
import type { Snapshot, SnapshotApplyPlan, SnapshotOptions } from "./snapshot-types.js";
|
|
18
|
-
|
|
19
|
-
function sha256(value: Buffer) {
|
|
20
|
-
return createHash("sha256").update(value).digest("hex");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function fileHashMap(snapshot: Snapshot) {
|
|
24
|
-
return Object.fromEntries(snapshot.files.map((file) => [file.path, file.sha256]));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export async function applySnapshot(
|
|
28
|
-
snapshot: Snapshot,
|
|
29
|
-
protectedRelativePaths = new Set<string>(),
|
|
30
|
-
options: Pick<
|
|
31
|
-
SnapshotOptions,
|
|
32
|
-
| "include"
|
|
33
|
-
| "sessionDir"
|
|
34
|
-
| "syncFiles"
|
|
35
|
-
| "syncSessions"
|
|
36
|
-
| "extraFiles"
|
|
37
|
-
| "signal"
|
|
38
|
-
| "validateMutation"
|
|
39
|
-
| "expectedFileHashes"
|
|
40
|
-
> = {},
|
|
41
|
-
) {
|
|
42
|
-
const root = agentDir();
|
|
43
|
-
const { sessionDir } = options;
|
|
44
|
-
const transactionOptions = {
|
|
45
|
-
sessionDir,
|
|
46
|
-
signal: options.signal,
|
|
47
|
-
validateMutation: options.validateMutation,
|
|
48
|
-
protectedTargets: [...protectedRelativePaths].map((relative) => snapshotTarget(root, relative, sessionDir)),
|
|
49
|
-
expectedPreimages: new Map(
|
|
50
|
-
Object.entries(options.expectedFileHashes ?? {}).map(([relative, hash]) => [
|
|
51
|
-
snapshotTarget(root, relative, sessionDir),
|
|
52
|
-
hash === null ? "missing" : `file:${hash}`,
|
|
53
|
-
]),
|
|
54
|
-
),
|
|
55
|
-
};
|
|
56
|
-
options.validateMutation?.();
|
|
57
|
-
await recoverPendingSnapshotTransactions(transactionOptions);
|
|
58
|
-
const current = await createSnapshot(snapshot.profile, {
|
|
59
|
-
...options,
|
|
60
|
-
...(options.include === undefined ? { syncSessions: snapshotIncludesSessions(snapshot) } : {}),
|
|
61
|
-
sessionDir,
|
|
62
|
-
});
|
|
63
|
-
const plan = await addTopLevelCaseVariantDeletes(
|
|
64
|
-
root,
|
|
65
|
-
protectSnapshotApplyPlan(
|
|
66
|
-
root,
|
|
67
|
-
preflightSnapshotApply(root, snapshot, current, { sessionDir }),
|
|
68
|
-
protectedRelativePaths,
|
|
69
|
-
sessionDir,
|
|
70
|
-
),
|
|
71
|
-
snapshot,
|
|
72
|
-
);
|
|
73
|
-
await preflightSnapshotMutations(root, plan, sessionDir, options);
|
|
74
|
-
await applySnapshotTransaction(plan, transactionOptions);
|
|
75
|
-
return appliedFileHashMap(snapshot, current, protectedRelativePaths);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function preflightSnapshotApply(
|
|
79
|
-
root: string,
|
|
80
|
-
snapshot: Snapshot,
|
|
81
|
-
current: Snapshot,
|
|
82
|
-
options: { sessionDir?: string } = {},
|
|
83
|
-
): SnapshotApplyPlan {
|
|
84
|
-
const seenPaths = new Set<string>();
|
|
85
|
-
const remotePaths = new Set<string>();
|
|
86
|
-
const writes: Array<{ target: string; content: Buffer }> = [];
|
|
87
|
-
const deletes: string[] = [];
|
|
88
|
-
|
|
89
|
-
for (const file of snapshot.files) {
|
|
90
|
-
const normalized = toPosix(file.path);
|
|
91
|
-
if (!isSafeSnapshotPath(file.path)) {
|
|
92
|
-
throw new Error(`Unsafe path in snapshot: ${file.path}`);
|
|
93
|
-
}
|
|
94
|
-
if (isSessionPath(normalized) && !isSessionFilePath(normalized)) {
|
|
95
|
-
throw new Error(`Unsafe session path in snapshot: ${file.path}`);
|
|
96
|
-
}
|
|
97
|
-
if (seenPaths.has(normalized)) throw new Error(`Duplicate path in snapshot: ${normalized}`);
|
|
98
|
-
seenPaths.add(normalized);
|
|
99
|
-
remotePaths.add(normalized);
|
|
100
|
-
|
|
101
|
-
const target = snapshotTarget(root, normalized, options.sessionDir);
|
|
102
|
-
const content = decodeBase64Strict(file.contentBase64, normalized);
|
|
103
|
-
if (sha256(content) !== file.sha256) throw new Error(`Checksum mismatch in snapshot file: ${normalized}`);
|
|
104
|
-
writes.push({ target, content });
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const deletePaths = new Set<string>();
|
|
108
|
-
for (const file of current.files) {
|
|
109
|
-
const normalized = toPosix(file.path);
|
|
110
|
-
if (!remotePaths.has(normalized)) {
|
|
111
|
-
deletePaths.add(snapshotTarget(root, normalized, options.sessionDir));
|
|
112
|
-
}
|
|
113
|
-
for (const remotePath of parentPaths(normalized)) {
|
|
114
|
-
if (remotePaths.has(remotePath)) {
|
|
115
|
-
deletePaths.add(snapshotTarget(root, remotePath, options.sessionDir));
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
deletes.push(...deletePaths);
|
|
120
|
-
|
|
121
|
-
return { writes, deletes };
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function protectSnapshotApplyPlan(
|
|
125
|
-
root: string,
|
|
126
|
-
plan: SnapshotApplyPlan,
|
|
127
|
-
protectedRelativePaths: Set<string>,
|
|
128
|
-
sessionDir?: string,
|
|
129
|
-
): SnapshotApplyPlan {
|
|
130
|
-
if (protectedRelativePaths.size === 0) return plan;
|
|
131
|
-
const protectedTargets = new Set(
|
|
132
|
-
[...protectedRelativePaths].map((relativePath) => snapshotTarget(root, relativePath, sessionDir)),
|
|
133
|
-
);
|
|
134
|
-
return {
|
|
135
|
-
writes: plan.writes.filter((item) => !protectedTargets.has(item.target)),
|
|
136
|
-
deletes: plan.deletes.filter((target) => !protectedTargets.has(target)),
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export async function addTopLevelCaseVariantDeletes(
|
|
141
|
-
root: string,
|
|
142
|
-
plan: SnapshotApplyPlan,
|
|
143
|
-
snapshot: Pick<Snapshot, "files">,
|
|
144
|
-
): Promise<SnapshotApplyPlan> {
|
|
145
|
-
const topLevelPaths = new Map<string, string>();
|
|
146
|
-
for (const file of snapshot.files) {
|
|
147
|
-
const normalized = toPosix(file.path);
|
|
148
|
-
if (!normalized.includes("/") && isSafeSnapshotPath(file.path)) {
|
|
149
|
-
topLevelPaths.set(normalized.toLowerCase(), normalized);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (topLevelPaths.size === 0) return plan;
|
|
153
|
-
|
|
154
|
-
let entries: Dirent[];
|
|
155
|
-
try {
|
|
156
|
-
entries = await fs.readdir(root, { withFileTypes: true });
|
|
157
|
-
} catch (error) {
|
|
158
|
-
if ((error as NodeJS.ErrnoException).code === "ENOENT") return plan;
|
|
159
|
-
throw error;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const deletes = new Set(plan.deletes);
|
|
163
|
-
for (const entry of entries) {
|
|
164
|
-
const canonicalPath = topLevelPaths.get(entry.name.toLowerCase());
|
|
165
|
-
if (canonicalPath && entry.name !== canonicalPath && (entry.isFile() || entry.isSymbolicLink())) {
|
|
166
|
-
deletes.add(safeJoin(root, entry.name));
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return { ...plan, deletes: [...deletes] };
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function appliedFileHashMap(snapshot: Snapshot, current: Snapshot, protectedRelativePaths: Set<string>) {
|
|
173
|
-
const hashes = fileHashMap(snapshot);
|
|
174
|
-
if (protectedRelativePaths.size === 0) return hashes;
|
|
175
|
-
const currentHashes = fileHashMap(current);
|
|
176
|
-
for (const relativePath of protectedRelativePaths) {
|
|
177
|
-
const normalized = toPosix(relativePath);
|
|
178
|
-
if (currentHashes[normalized]) {
|
|
179
|
-
hashes[normalized] = currentHashes[normalized];
|
|
180
|
-
} else {
|
|
181
|
-
delete hashes[normalized];
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return hashes;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function isSafeSnapshotPath(relativePath: string) {
|
|
188
|
-
if (relativePath.includes("\\")) return false;
|
|
189
|
-
const normalized = toPosix(relativePath);
|
|
190
|
-
return (
|
|
191
|
-
Boolean(normalized) &&
|
|
192
|
-
normalized !== "." &&
|
|
193
|
-
normalized !== ".." &&
|
|
194
|
-
!normalized.startsWith("../") &&
|
|
195
|
-
!path.posix.isAbsolute(normalized) &&
|
|
196
|
-
path.posix.normalize(normalized) === normalized &&
|
|
197
|
-
!isDeniedPath(normalized)
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function decodeBase64Strict(value: string, filePath: string) {
|
|
202
|
-
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(value) || value.length % 4 !== 0) {
|
|
203
|
-
throw new Error(`Invalid base64 content in snapshot file: ${filePath}`);
|
|
204
|
-
}
|
|
205
|
-
return Buffer.from(value, "base64");
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
type MutationGuards = Pick<SnapshotOptions, "signal" | "validateMutation">;
|
|
209
|
-
|
|
210
|
-
export async function preflightSnapshotMutations(
|
|
211
|
-
root: string,
|
|
212
|
-
plan: { deletes: string[]; writes: Array<{ target: string; content: Buffer }> },
|
|
213
|
-
sessionDir?: string,
|
|
214
|
-
options: MutationGuards = {},
|
|
215
|
-
) {
|
|
216
|
-
assertMutationCurrent(options);
|
|
217
|
-
const deletePaths = new Set(plan.deletes);
|
|
218
|
-
for (const target of plan.deletes) {
|
|
219
|
-
await assertNoSymlinkParents(rootForTarget(root, target, sessionDir), target, options);
|
|
220
|
-
assertMutationCurrent(options);
|
|
221
|
-
}
|
|
222
|
-
for (const item of plan.writes) {
|
|
223
|
-
await prepareSnapshotWrite(rootForTarget(root, item.target, sessionDir), item.target, deletePaths, options);
|
|
224
|
-
assertMutationCurrent(options);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function assertMutationCurrent(options: MutationGuards) {
|
|
229
|
-
options.validateMutation?.();
|
|
230
|
-
options.signal?.throwIfAborted();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
async function guardedStat(target: string, options: MutationGuards) {
|
|
234
|
-
assertMutationCurrent(options);
|
|
235
|
-
let stat: Stats;
|
|
236
|
-
try {
|
|
237
|
-
stat = await fs.lstat(target);
|
|
238
|
-
} catch (error) {
|
|
239
|
-
assertMutationCurrent(options);
|
|
240
|
-
if ((error as NodeJS.ErrnoException).code === "ENOENT") return undefined;
|
|
241
|
-
throw error;
|
|
242
|
-
}
|
|
243
|
-
assertMutationCurrent(options);
|
|
244
|
-
return stat;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
function rootForTarget(root: string, target: string, sessionDir?: string) {
|
|
248
|
-
const sessionRoot = sessionDir ? sessionStorageRoot(root, sessionDir) : undefined;
|
|
249
|
-
if (sessionRoot && isPathInside(sessionRoot, target)) return sessionRoot;
|
|
250
|
-
return root;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
async function prepareSnapshotWrite(root: string, target: string, deletePaths: Set<string>, options: MutationGuards) {
|
|
254
|
-
const parentWillBeReplaced = await ensureSafeDirectory(root, path.dirname(target), deletePaths, options);
|
|
255
|
-
assertMutationCurrent(options);
|
|
256
|
-
if (parentWillBeReplaced) return;
|
|
257
|
-
const stat = await guardedStat(target, options);
|
|
258
|
-
assertMutationCurrent(options);
|
|
259
|
-
if (stat?.isSymbolicLink()) throw new Error(`Refusing to overwrite symlink during snapshot apply: ${target}`);
|
|
260
|
-
if (stat?.isDirectory() && !deletePaths.has(target)) {
|
|
261
|
-
throw new Error(`Refusing to overwrite directory during snapshot apply: ${target}`);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
async function ensureSafeDirectory(root: string, directory: string, deletePaths: Set<string>, options: MutationGuards) {
|
|
266
|
-
assertMutationCurrent(options);
|
|
267
|
-
assertWithinRoot(root, directory);
|
|
268
|
-
const rootPath = path.resolve(root);
|
|
269
|
-
const relative = path.relative(rootPath, path.resolve(directory));
|
|
270
|
-
let current = rootPath;
|
|
271
|
-
for (const part of relative.split(path.sep).filter(Boolean)) {
|
|
272
|
-
current = path.join(current, part);
|
|
273
|
-
const stat = await guardedStat(current, options);
|
|
274
|
-
assertMutationCurrent(options);
|
|
275
|
-
if (stat) {
|
|
276
|
-
if (stat.isSymbolicLink()) throw new Error(`Refusing to follow symlink during snapshot apply: ${current}`);
|
|
277
|
-
if (!stat.isDirectory()) {
|
|
278
|
-
if (deletePaths.has(current)) return true;
|
|
279
|
-
throw new Error(`Snapshot path parent is not a directory: ${current}`);
|
|
280
|
-
}
|
|
281
|
-
} else {
|
|
282
|
-
await fs.mkdir(current);
|
|
283
|
-
assertMutationCurrent(options);
|
|
284
|
-
await syncDirectory(path.dirname(current));
|
|
285
|
-
assertMutationCurrent(options);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
async function assertNoSymlinkParents(root: string, target: string, options: MutationGuards) {
|
|
292
|
-
assertMutationCurrent(options);
|
|
293
|
-
assertWithinRoot(root, target);
|
|
294
|
-
const rootPath = path.resolve(root);
|
|
295
|
-
const relative = path.relative(rootPath, path.resolve(target));
|
|
296
|
-
let current = rootPath;
|
|
297
|
-
const parts = relative.split(path.sep).filter(Boolean);
|
|
298
|
-
for (const part of parts.slice(0, -1)) {
|
|
299
|
-
current = path.join(current, part);
|
|
300
|
-
const stat = await guardedStat(current, options);
|
|
301
|
-
assertMutationCurrent(options);
|
|
302
|
-
if (!stat) return;
|
|
303
|
-
if (stat.isSymbolicLink()) throw new Error(`Refusing to follow symlink during snapshot apply: ${current}`);
|
|
304
|
-
if (!stat.isDirectory()) throw new Error(`Snapshot path parent is not a directory: ${current}`);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
1
|
+
export type * from "@narumitw/sync-daemon/engine/snapshot/snapshot-apply";
|
|
2
|
+
export {
|
|
3
|
+
addTopLevelCaseVariantDeletes,
|
|
4
|
+
appliedFileHashMap,
|
|
5
|
+
applySnapshot,
|
|
6
|
+
preflightSnapshotApply,
|
|
7
|
+
preflightSnapshotMutations,
|
|
8
|
+
protectSnapshotApplyPlan,
|
|
9
|
+
} from "@narumitw/sync-daemon/engine/snapshot/snapshot-apply";
|
|
@@ -1,80 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return (
|
|
8
|
-
before !== after &&
|
|
9
|
-
path.dirname(before) === root &&
|
|
10
|
-
path.dirname(after) === root &&
|
|
11
|
-
path.basename(before).toLowerCase() === path.basename(after).toLowerCase()
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** Absence is handled by the journal's removal/replacement evidence, never by naming evidence. */
|
|
16
|
-
export async function caseReplacementSpelling(before: string, after: string): Promise<string | undefined> {
|
|
17
|
-
const observations = await Promise.all(
|
|
18
|
-
[before, after].map(async (target) => {
|
|
19
|
-
try {
|
|
20
|
-
const stat = await fs.lstat(target);
|
|
21
|
-
if (!stat.isFile() || stat.nlink !== 1) throw new Error("Unsafe case replacement target.");
|
|
22
|
-
return await fs.realpath(target);
|
|
23
|
-
} catch (error) {
|
|
24
|
-
if ((error as NodeJS.ErrnoException).code === "ENOENT") return undefined;
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
}),
|
|
28
|
-
);
|
|
29
|
-
if (observations.every((value) => value === undefined)) return undefined;
|
|
30
|
-
if (!observations[0] || observations[0] !== observations[1])
|
|
31
|
-
throw new Error("Case replacement no longer identifies one physical file; preserve evidence for review.");
|
|
32
|
-
const names = (await fs.readdir(path.dirname(before))).filter(
|
|
33
|
-
(name) => name.toLowerCase() === path.basename(before).toLowerCase(),
|
|
34
|
-
);
|
|
35
|
-
if (names.length !== 1 || (names[0] !== path.basename(before) && names[0] !== path.basename(after)))
|
|
36
|
-
throw new Error("Case replacement spelling changed; preserve evidence for review.");
|
|
37
|
-
return path.join(path.dirname(before), names[0]);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export async function coalesceCaseReplacements(root: string, plan: SnapshotApplyPlan) {
|
|
41
|
-
const replacements = new Map<string, string>();
|
|
42
|
-
const deletesByCase = new Map<string, string[]>();
|
|
43
|
-
const writeTargets = new Set(plan.writes.map((item) => item.target));
|
|
44
|
-
for (const target of new Set(plan.deletes)) {
|
|
45
|
-
if (path.dirname(target) !== root || writeTargets.has(target)) continue;
|
|
46
|
-
const key = path.basename(target).toLowerCase();
|
|
47
|
-
const group = deletesByCase.get(key) ?? [];
|
|
48
|
-
group.push(target);
|
|
49
|
-
deletesByCase.set(key, group);
|
|
50
|
-
}
|
|
51
|
-
for (const item of plan.writes) {
|
|
52
|
-
if (path.dirname(item.target) !== root) continue;
|
|
53
|
-
const candidates = deletesByCase.get(path.basename(item.target).toLowerCase()) ?? [];
|
|
54
|
-
if (candidates.length !== 1) continue;
|
|
55
|
-
const before = candidates[0];
|
|
56
|
-
if (!before || !isCaseReplacement(root, before, item.target)) continue;
|
|
57
|
-
// Different real paths on a case-sensitive filesystem remain independent targets.
|
|
58
|
-
let beforePath: string;
|
|
59
|
-
let afterPath: string;
|
|
60
|
-
try {
|
|
61
|
-
[beforePath, afterPath] = await Promise.all([fs.realpath(before), fs.realpath(item.target)]);
|
|
62
|
-
} catch (error) {
|
|
63
|
-
if ((error as NodeJS.ErrnoException).code === "ENOENT") continue;
|
|
64
|
-
throw error;
|
|
65
|
-
}
|
|
66
|
-
if (beforePath !== afterPath) continue;
|
|
67
|
-
if (replacements.has(before)) throw new Error("Multiple writes alias a case replacement target.");
|
|
68
|
-
if ((await caseReplacementSpelling(before, item.target)) !== before)
|
|
69
|
-
throw new Error("Case replacement preimage spelling changed; review is required.");
|
|
70
|
-
replacements.set(before, item.target);
|
|
71
|
-
}
|
|
72
|
-
const beforeByAfter = new Map([...replacements].map(([before, after]) => [after, before]));
|
|
73
|
-
return {
|
|
74
|
-
replacements,
|
|
75
|
-
plan: {
|
|
76
|
-
deletes: plan.deletes,
|
|
77
|
-
writes: plan.writes.map((item) => ({ ...item, target: beforeByAfter.get(item.target) ?? item.target })),
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
}
|
|
1
|
+
export type * from "@narumitw/sync-daemon/engine/snapshot/snapshot-case-replacement";
|
|
2
|
+
export {
|
|
3
|
+
caseReplacementSpelling,
|
|
4
|
+
coalesceCaseReplacements,
|
|
5
|
+
isCaseReplacement,
|
|
6
|
+
} from "@narumitw/sync-daemon/engine/snapshot/snapshot-case-replacement";
|
|
@@ -1,50 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { promisify } from "node:util";
|
|
4
|
-
import { createGunzip, gzip } from "node:zlib";
|
|
5
|
-
import { throwIfAborted } from "../sync/signals.js";
|
|
6
|
-
import { snapshotSelectionInclude } from "../sync/sync-policy.js";
|
|
7
|
-
import type { Snapshot } from "./snapshot-types.js";
|
|
8
|
-
|
|
9
|
-
const VERSION = 1;
|
|
10
|
-
const MAX_DECOMPRESSED_SNAPSHOT_BYTES = 512 * 1024 * 1024;
|
|
11
|
-
const gzipAsync = promisify(gzip);
|
|
12
|
-
|
|
13
|
-
export async function encodeSnapshot(snapshot: Snapshot) {
|
|
14
|
-
snapshotSelectionInclude(snapshot);
|
|
15
|
-
return gzipAsync(Buffer.from(JSON.stringify(snapshot), "utf8"));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function decodeSnapshot(
|
|
19
|
-
buffer: Buffer,
|
|
20
|
-
options: { signal?: AbortSignal; maxOutputLength?: number } = {},
|
|
21
|
-
): Promise<Snapshot> {
|
|
22
|
-
throwIfAborted(options.signal);
|
|
23
|
-
const limit = options.maxOutputLength ?? MAX_DECOMPRESSED_SNAPSHOT_BYTES;
|
|
24
|
-
const chunks: Buffer[] = [];
|
|
25
|
-
let total = 0;
|
|
26
|
-
const sink = new Writable({
|
|
27
|
-
write(chunk: Buffer, _encoding, callback) {
|
|
28
|
-
total += chunk.byteLength;
|
|
29
|
-
if (total > limit) {
|
|
30
|
-
callback(new Error(`Decompressed snapshot exceeds the ${limit}-byte limit.`));
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
chunks.push(Buffer.from(chunk));
|
|
34
|
-
callback();
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
await pipeline(Readable.from([buffer]), createGunzip(), sink, { signal: options.signal });
|
|
38
|
-
throwIfAborted(options.signal);
|
|
39
|
-
const parsed = JSON.parse(Buffer.concat(chunks, total).toString("utf8")) as Snapshot;
|
|
40
|
-
if ((parsed.version !== VERSION && parsed.version !== 2 && parsed.version !== 3) || !Array.isArray(parsed.files)) {
|
|
41
|
-
throw new Error("Unsupported snapshot format.");
|
|
42
|
-
}
|
|
43
|
-
if (parsed.version === 2 || parsed.version === 3) {
|
|
44
|
-
const { normalizeLocalFields, validatePortableSnapshot } = await import("../sync/local-fields.js");
|
|
45
|
-
validatePortableSnapshot(parsed);
|
|
46
|
-
if (parsed.localFields !== undefined) parsed.localFields = normalizeLocalFields(parsed.localFields);
|
|
47
|
-
} else if (parsed.localFields !== undefined) throw new Error("Portable field policy requires snapshot version 2.");
|
|
48
|
-
snapshotSelectionInclude(parsed);
|
|
49
|
-
return parsed;
|
|
50
|
-
}
|
|
1
|
+
export type * from "@narumitw/sync-daemon/engine/snapshot/snapshot-codec";
|
|
2
|
+
export { decodeSnapshot, encodeSnapshot } from "@narumitw/sync-daemon/engine/snapshot/snapshot-codec";
|