@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,55 +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
|
-
|
|
4
|
-
// src/state/json-file.ts
|
|
5
|
-
import { randomUUID } from "node:crypto";
|
|
6
|
-
import fs from "node:fs/promises";
|
|
7
|
-
import path from "node:path";
|
|
8
|
-
async function readJsonIfExists(filePath) {
|
|
9
|
-
try {
|
|
10
|
-
return JSON.parse(await fs.readFile(filePath, "utf8"));
|
|
11
|
-
} catch (error) {
|
|
12
|
-
if (error.code === "ENOENT") return void 0;
|
|
13
|
-
throw error;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async function writeJson(filePath, value, options = {}) {
|
|
17
|
-
const content = `${JSON.stringify(value, null, " ")}
|
|
18
|
-
`;
|
|
19
|
-
if (options.maxBytes !== void 0 && Buffer.byteLength(content) > options.maxBytes)
|
|
20
|
-
throw new Error(
|
|
21
|
-
"Private state document exceeds its storage bound; preserve existing evidence and use reviewed recovery."
|
|
22
|
-
);
|
|
23
|
-
await fs.mkdir(path.dirname(filePath), { recursive: true, mode: 448 });
|
|
24
|
-
const temp = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
|
|
25
|
-
try {
|
|
26
|
-
const handle = await fs.open(temp, "wx", 384);
|
|
27
|
-
try {
|
|
28
|
-
await handle.writeFile(content);
|
|
29
|
-
await handle.sync();
|
|
30
|
-
} finally {
|
|
31
|
-
await handle.close();
|
|
32
|
-
}
|
|
33
|
-
if (process.platform !== "win32") await fs.chmod(temp, 384);
|
|
34
|
-
await fs.rename(temp, filePath);
|
|
35
|
-
await syncDirectory(path.dirname(filePath));
|
|
36
|
-
} finally {
|
|
37
|
-
await fs.rm(temp, { force: true });
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
async function syncDirectory(directory) {
|
|
41
|
-
if (process.platform === "win32") return;
|
|
42
|
-
const handle = await fs.open(directory, "r");
|
|
43
|
-
try {
|
|
44
|
-
await handle.sync();
|
|
45
|
-
} finally {
|
|
46
|
-
await handle.close();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export {
|
|
51
|
-
readJsonIfExists,
|
|
52
|
-
writeJson,
|
|
53
|
-
syncDirectory
|
|
54
|
-
};
|
|
55
|
-
//# sourceMappingURL=chunk-AR2DGDUI.ts.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/state/json-file.ts"],
|
|
4
|
-
"sourcesContent": ["import { randomUUID } from \"node:crypto\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\nexport async function readJsonIfExists<T>(filePath: string): Promise<T | undefined> {\n try {\n return JSON.parse(await fs.readFile(filePath, \"utf8\")) as T;\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n throw error;\n }\n}\n\nexport async function writeJson(filePath: string, value: unknown, options: { maxBytes?: number } = {}) {\n const content = `${JSON.stringify(value, null, \"\\t\")}\\n`;\n if (options.maxBytes !== undefined && Buffer.byteLength(content) > options.maxBytes)\n throw new Error(\n \"Private state document exceeds its storage bound; preserve existing evidence and use reviewed recovery.\",\n );\n await fs.mkdir(path.dirname(filePath), { recursive: true, mode: 0o700 });\n const temp = `${filePath}.${process.pid}.${randomUUID()}.tmp`;\n try {\n const handle = await fs.open(temp, \"wx\", 0o600);\n try {\n await handle.writeFile(content);\n await handle.sync();\n } finally {\n await handle.close();\n }\n if (process.platform !== \"win32\") await fs.chmod(temp, 0o600);\n await fs.rename(temp, filePath);\n await syncDirectory(path.dirname(filePath));\n } finally {\n await fs.rm(temp, { force: true });\n }\n}\n\n/** POSIX rename/unlink durability; Windows does not expose directory fsync through Node. */\nexport async function syncDirectory(directory: string) {\n if (process.platform === \"win32\") return;\n const handle = await fs.open(directory, \"r\");\n try {\n await handle.sync();\n } finally {\n await handle.close();\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;AAAA,SAAS,kBAAkB;AAC3B,OAAO,QAAQ;AACf,OAAO,UAAU;AAEjB,eAAsB,iBAAoB,UAA0C;AAClF,MAAI;AACF,WAAO,KAAK,MAAM,MAAM,GAAG,SAAS,UAAU,MAAM,CAAC;AAAA,EACvD,SAAS,OAAO;AACd,QAAK,MAAgC,SAAS,SAAU,QAAO;AAC/D,UAAM;AAAA,EACR;AACF;AAEA,eAAsB,UAAU,UAAkB,OAAgB,UAAiC,CAAC,GAAG;AACrG,QAAM,UAAU,GAAG,KAAK,UAAU,OAAO,MAAM,GAAI,CAAC;AAAA;AACpD,MAAI,QAAQ,aAAa,UAAa,OAAO,WAAW,OAAO,IAAI,QAAQ;AACzE,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,QAAM,GAAG,MAAM,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,MAAM,MAAM,IAAM,CAAC;AACvE,QAAM,OAAO,GAAG,QAAQ,IAAI,QAAQ,GAAG,IAAI,WAAW,CAAC;AACvD,MAAI;AACF,UAAM,SAAS,MAAM,GAAG,KAAK,MAAM,MAAM,GAAK;AAC9C,QAAI;AACF,YAAM,OAAO,UAAU,OAAO;AAC9B,YAAM,OAAO,KAAK;AAAA,IACpB,UAAE;AACA,YAAM,OAAO,MAAM;AAAA,IACrB;AACA,QAAI,QAAQ,aAAa,QAAS,OAAM,GAAG,MAAM,MAAM,GAAK;AAC5D,UAAM,GAAG,OAAO,MAAM,QAAQ;AAC9B,UAAM,cAAc,KAAK,QAAQ,QAAQ,CAAC;AAAA,EAC5C,UAAE;AACA,UAAM,GAAG,GAAG,MAAM,EAAE,OAAO,KAAK,CAAC;AAAA,EACnC;AACF;AAGA,eAAsB,cAAc,WAAmB;AACrD,MAAI,QAAQ,aAAa,QAAS;AAClC,QAAM,SAAS,MAAM,GAAG,KAAK,WAAW,GAAG;AAC3C,MAAI;AACF,UAAM,OAAO,KAAK;AAAA,EACpB,UAAE;AACA,UAAM,OAAO,MAAM;AAAA,EACrB;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,153 +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
|
-
fileHashMap,
|
|
5
|
-
sameHashes
|
|
6
|
-
} from "./chunk-Y4UVXOLQ.ts";
|
|
7
|
-
import {
|
|
8
|
-
portableSnapshot,
|
|
9
|
-
sameLocalFields,
|
|
10
|
-
validatePortableSnapshot,
|
|
11
|
-
validateSnapshotFieldPolicy
|
|
12
|
-
} from "./chunk-MKSMJPVA.ts";
|
|
13
|
-
import {
|
|
14
|
-
planFileMerge
|
|
15
|
-
} from "./chunk-XJHQPB3E.ts";
|
|
16
|
-
import {
|
|
17
|
-
statePathForConfig,
|
|
18
|
-
syncStateFingerprint
|
|
19
|
-
} from "./chunk-DN4IA7MR.ts";
|
|
20
|
-
import {
|
|
21
|
-
readJsonIfExists,
|
|
22
|
-
syncDirectory,
|
|
23
|
-
writeJson
|
|
24
|
-
} from "./chunk-AR2DGDUI.ts";
|
|
25
|
-
|
|
26
|
-
// src/sync/merge-journal.ts
|
|
27
|
-
import { randomUUID } from "node:crypto";
|
|
28
|
-
import fs from "node:fs/promises";
|
|
29
|
-
import path from "node:path";
|
|
30
|
-
function mergeJournalIdentity(config, backendIdentity) {
|
|
31
|
-
return JSON.stringify([config.setupName, backendIdentity, [...config.include].sort(), config.localFields ?? null]);
|
|
32
|
-
}
|
|
33
|
-
function mergeJournalPath(config) {
|
|
34
|
-
return `${statePathForConfig(config)}.merge-journal.json`;
|
|
35
|
-
}
|
|
36
|
-
async function readMergeJournal(config) {
|
|
37
|
-
let journal;
|
|
38
|
-
try {
|
|
39
|
-
const stat = await fs.lstat(mergeJournalPath(config));
|
|
40
|
-
if (!stat.isFile() || stat.size > 384 * 1024 * 1024) throw new Error("Unsafe or oversized journal.");
|
|
41
|
-
journal = await readJsonIfExists(mergeJournalPath(config));
|
|
42
|
-
} catch (error) {
|
|
43
|
-
if (error.code === "ENOENT") return;
|
|
44
|
-
throw new Error("Cannot read the private merge journal; preserve it and review recovery.");
|
|
45
|
-
}
|
|
46
|
-
if (!journal) return;
|
|
47
|
-
if (journal.version !== 1 || typeof journal.identity !== "string" || typeof journal.backup !== "string" || typeof journal.stateIdentity !== "string" || journal.applyOnly !== void 0 && (journal.applyOnly !== true || !journal.committedHead || journal.committedHead.revision !== journal.expectedHead?.revision || journal.committedHead.snapshotId !== journal.expectedHead?.snapshotId || journal.upload?.id !== journal.expectedHead?.snapshotId) || journal.sessionRoot !== void 0 && (typeof journal.sessionRoot !== "string" || !path.isAbsolute(journal.sessionRoot) || path.resolve(journal.sessionRoot) !== journal.sessionRoot) || journal.warnings !== void 0 && (!Array.isArray(journal.warnings) || journal.warnings.length > 64 || journal.warnings.some((item) => typeof item !== "string")) || !journal.expectedHead || typeof journal.expectedHead.revision !== "string" || !journal.before || !journal.after || !journal.upload || !Array.isArray(journal.before.files) || !Array.isArray(journal.after.files) || !Array.isArray(journal.upload.files))
|
|
48
|
-
throw new Error("Unsupported or damaged merge journal; preserve it and review recovery before syncing.");
|
|
49
|
-
try {
|
|
50
|
-
const pinnedPaths = new Set(journal.progress?.groups.flatMap((group) => group.paths) ?? []);
|
|
51
|
-
for (const snapshot of [
|
|
52
|
-
journal.before,
|
|
53
|
-
journal.after,
|
|
54
|
-
journal.upload,
|
|
55
|
-
...journal.accepted ? [journal.accepted] : []
|
|
56
|
-
]) {
|
|
57
|
-
validateSnapshotFieldPolicy(snapshot);
|
|
58
|
-
if (snapshot.version !== 1 && snapshot.version !== 2 && snapshot.version !== 3 || typeof snapshot.id !== "string" || typeof snapshot.profile !== "string" || snapshot.files.length > 16384 || snapshot.files.reduce(
|
|
59
|
-
(bytes, file) => bytes + (typeof file?.contentBase64 === "string" ? file.contentBase64.length * 0.75 : Infinity),
|
|
60
|
-
0
|
|
61
|
-
) > 64 * 1024 * 1024)
|
|
62
|
-
throw new Error("Invalid journal input.");
|
|
63
|
-
const plan = planFileMerge({ baseline: {}, local: snapshot.files, remote: [], selectionCompatible: true });
|
|
64
|
-
if (plan.kind !== "planned" || plan.conflicts.some((conflict) => conflict.reason !== "path-collision" || !pinnedPaths.has(conflict.path)))
|
|
65
|
-
throw new Error("Invalid journal collision group.");
|
|
66
|
-
}
|
|
67
|
-
validatePortableSnapshot(journal.upload);
|
|
68
|
-
if ((journal.upload.version === 2 || journal.upload.version === 3) && !journal.accepted)
|
|
69
|
-
throw new Error("Portable merge journal requires an explicit accepted projection.");
|
|
70
|
-
if (journal.accepted) validatePortableSnapshot(journal.accepted);
|
|
71
|
-
} catch {
|
|
72
|
-
throw new Error("Invalid merge journal paths, metadata, or bytes; preserve evidence for review.");
|
|
73
|
-
}
|
|
74
|
-
try {
|
|
75
|
-
if (journal.accepted && (!sameLocalFields(journal.accepted.localFields, journal.upload.localFields) || !sameHashes(
|
|
76
|
-
fileHashMap(portableSnapshot(journal.after, journal.upload.localFields)),
|
|
77
|
-
fileHashMap(portableSnapshot(journal.accepted, journal.upload.localFields))
|
|
78
|
-
)))
|
|
79
|
-
throw new Error("Projection mismatch.");
|
|
80
|
-
} catch {
|
|
81
|
-
throw new Error("Invalid accepted merge projection; preserve journal evidence.");
|
|
82
|
-
}
|
|
83
|
-
if (journal.progress) {
|
|
84
|
-
const known = /* @__PURE__ */ new Set([
|
|
85
|
-
...Object.keys(journal.progress.previous?.lastFileHashes ?? {}),
|
|
86
|
-
...[...journal.before.files, ...journal.after.files, ...journal.upload.files].map((file) => file.path)
|
|
87
|
-
]);
|
|
88
|
-
const progress = journal.progress;
|
|
89
|
-
if (!config.partialSync || !progress.previous || syncStateFingerprint(progress.previous) !== journal.stateIdentity || !Array.isArray(progress.groups) || progress.groups.length > 16384 || progress.groups.some(
|
|
90
|
-
(group) => !Array.isArray(group.paths) || !group.paths.length || group.paths.length > 16384 || group.paths.some((filePath) => !known.has(filePath)) || !/^[a-f0-9-]{36}$/u.test(group.artifact)
|
|
91
|
-
))
|
|
92
|
-
throw new Error("Invalid partial acceptance metadata; preserve journal evidence.");
|
|
93
|
-
}
|
|
94
|
-
if (journal.progress) {
|
|
95
|
-
const before = fileHashMap(journal.before);
|
|
96
|
-
const after = fileHashMap(journal.after);
|
|
97
|
-
const { readConflictArtifact } = await import("./conflict-artifacts-J6WSDCWP.ts");
|
|
98
|
-
const backendIdentity = JSON.parse(journal.identity)[1];
|
|
99
|
-
if (typeof backendIdentity !== "string") throw new Error("Invalid partial backend identity.");
|
|
100
|
-
const byArtifact = /* @__PURE__ */ new Map();
|
|
101
|
-
for (const group of journal.progress.groups) {
|
|
102
|
-
const groups = byArtifact.get(group.artifact) ?? [];
|
|
103
|
-
groups.push(group);
|
|
104
|
-
byArtifact.set(group.artifact, groups);
|
|
105
|
-
}
|
|
106
|
-
for (const [token, groups] of byArtifact) {
|
|
107
|
-
const artifact = await readConflictArtifact(config, backendIdentity, token);
|
|
108
|
-
const retainedGroups = new Set(artifact.groups.map((group) => JSON.stringify(group.paths)));
|
|
109
|
-
const remote = fileHashMap(artifact.remote);
|
|
110
|
-
const upload = fileHashMap(journal.upload);
|
|
111
|
-
for (const group of groups) {
|
|
112
|
-
if (!retainedGroups.has(JSON.stringify(group.paths)))
|
|
113
|
-
throw new Error("Partial group does not match retained artifact evidence.");
|
|
114
|
-
for (const filePath of group.paths)
|
|
115
|
-
if (before[filePath] !== after[filePath] || remote[filePath] !== upload[filePath] || journal.progress.previous.lastFileHashes[filePath] !== artifact.state.lastFileHashes[filePath])
|
|
116
|
-
throw new Error("Withheld version changed in journal; preserve evidence.");
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return journal;
|
|
121
|
-
}
|
|
122
|
-
async function writeMergeJournal(config, journal) {
|
|
123
|
-
await writeJson(mergeJournalPath(config), journal, { maxBytes: 384 * 1024 * 1024 });
|
|
124
|
-
}
|
|
125
|
-
async function clearMergeJournal(config) {
|
|
126
|
-
await fs.rm(mergeJournalPath(config), { force: true });
|
|
127
|
-
await syncDirectory(path.dirname(mergeJournalPath(config)));
|
|
128
|
-
}
|
|
129
|
-
async function retireMergeJournal(config) {
|
|
130
|
-
if (!await readMergeJournal(config)) return;
|
|
131
|
-
const file = mergeJournalPath(config);
|
|
132
|
-
await fs.rename(file, `${file}.${randomUUID()}.resolved`);
|
|
133
|
-
await syncDirectory(path.dirname(file));
|
|
134
|
-
}
|
|
135
|
-
async function requireNoMergeJournal(config, options = {}) {
|
|
136
|
-
const journal = await readMergeJournal(config);
|
|
137
|
-
if (options.force || !journal) return;
|
|
138
|
-
if (journal) {
|
|
139
|
-
throw new Error(
|
|
140
|
-
"A merged transfer needs recovery. Run /sync sync to reconcile it. If newer local edits or remote revisions prevent recovery, review /sync diff and explicitly choose push --force or pull --force; the selected directional result will archive the old journal, not restore old bytes. Keep its backup; do not downgrade while recovery is pending."
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export {
|
|
146
|
-
mergeJournalIdentity,
|
|
147
|
-
readMergeJournal,
|
|
148
|
-
writeMergeJournal,
|
|
149
|
-
clearMergeJournal,
|
|
150
|
-
retireMergeJournal,
|
|
151
|
-
requireNoMergeJournal
|
|
152
|
-
};
|
|
153
|
-
//# sourceMappingURL=chunk-BEST45H2.ts.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/sync/merge-journal.ts"],
|
|
4
|
-
"sourcesContent": ["import { randomUUID } from \"node:crypto\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { RemoteHead } from \"../backends/sync-backend.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport { readJsonIfExists, syncDirectory, writeJson } from \"../state/json-file.js\";\nimport { statePathForConfig, syncStateFingerprint } from \"../state/sync-state-store.js\";\nimport { planFileMerge } from \"./file-merge-planner.js\";\nimport {\n portableSnapshot,\n sameLocalFields,\n validatePortableSnapshot,\n validateSnapshotFieldPolicy,\n} from \"./local-fields.js\";\nimport type { PartialProgress } from \"./partial-progress.js\";\nimport { fileHashMap, sameHashes } from \"./sync-state.js\";\n\nexport interface MergeJournal {\n version: 1;\n identity: string;\n before: Snapshot;\n after: Snapshot;\n accepted?: Snapshot;\n progress?: PartialProgress;\n upload: Snapshot;\n expectedHead: RemoteHead;\n committedHead?: RemoteHead;\n /** No remote publication was attempted; a stale candidate can retire if local preimages remain intact. */\n applyOnly?: boolean;\n backup: string;\n stateIdentity: string;\n /** Effective collection/apply root; absent legacy evidence cannot authorize session recovery. */\n sessionRoot?: string;\n warnings?: string[];\n}\n\nexport function mergeJournalIdentity(config: AnySyncConfig, backendIdentity: string) {\n return JSON.stringify([config.setupName, backendIdentity, [...config.include].sort(), config.localFields ?? null]);\n}\n\nexport function mergeJournalPath(config: AnySyncConfig) {\n return `${statePathForConfig(config)}.merge-journal.json`;\n}\n\nexport async function readMergeJournal(config: AnySyncConfig): Promise<MergeJournal | undefined> {\n let journal: MergeJournal | undefined;\n try {\n const stat = await fs.lstat(mergeJournalPath(config));\n if (!stat.isFile() || stat.size > 384 * 1024 * 1024) throw new Error(\"Unsafe or oversized journal.\");\n journal = await readJsonIfExists<MergeJournal>(mergeJournalPath(config));\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return;\n // A JSON parser error may quote sensitive journal contents; do not retain it in a public error.\n throw new Error(\"Cannot read the private merge journal; preserve it and review recovery.\");\n }\n if (!journal) return;\n if (\n journal.version !== 1 ||\n typeof journal.identity !== \"string\" ||\n typeof journal.backup !== \"string\" ||\n typeof journal.stateIdentity !== \"string\" ||\n (journal.applyOnly !== undefined &&\n (journal.applyOnly !== true ||\n !journal.committedHead ||\n journal.committedHead.revision !== journal.expectedHead?.revision ||\n journal.committedHead.snapshotId !== journal.expectedHead?.snapshotId ||\n journal.upload?.id !== journal.expectedHead?.snapshotId)) ||\n (journal.sessionRoot !== undefined &&\n (typeof journal.sessionRoot !== \"string\" ||\n !path.isAbsolute(journal.sessionRoot) ||\n path.resolve(journal.sessionRoot) !== journal.sessionRoot)) ||\n (journal.warnings !== undefined &&\n (!Array.isArray(journal.warnings) ||\n journal.warnings.length > 64 ||\n journal.warnings.some((item) => typeof item !== \"string\"))) ||\n !journal.expectedHead ||\n typeof journal.expectedHead.revision !== \"string\" ||\n !journal.before ||\n !journal.after ||\n !journal.upload ||\n !Array.isArray(journal.before.files) ||\n !Array.isArray(journal.after.files) ||\n !Array.isArray(journal.upload.files)\n )\n throw new Error(\"Unsupported or damaged merge journal; preserve it and review recovery before syncing.\");\n // Verify every path and byte, including the unmanaged remote files retained for publication.\n try {\n const pinnedPaths = new Set(journal.progress?.groups.flatMap((group) => group.paths) ?? []);\n for (const snapshot of [\n journal.before,\n journal.after,\n journal.upload,\n ...(journal.accepted ? [journal.accepted] : []),\n ]) {\n validateSnapshotFieldPolicy(snapshot);\n if (\n (snapshot.version !== 1 && snapshot.version !== 2 && snapshot.version !== 3) ||\n typeof snapshot.id !== \"string\" ||\n typeof snapshot.profile !== \"string\" ||\n snapshot.files.length > 16_384 ||\n snapshot.files.reduce(\n (bytes, file) =>\n bytes + (typeof file?.contentBase64 === \"string\" ? file.contentBase64.length * 0.75 : Infinity),\n 0,\n ) >\n 64 * 1024 * 1024\n )\n throw new Error(\"Invalid journal input.\");\n const plan = planFileMerge({ baseline: {}, local: snapshot.files, remote: [], selectionCompatible: true });\n if (\n plan.kind !== \"planned\" ||\n plan.conflicts.some((conflict) => conflict.reason !== \"path-collision\" || !pinnedPaths.has(conflict.path))\n )\n throw new Error(\"Invalid journal collision group.\");\n }\n validatePortableSnapshot(journal.upload);\n if ((journal.upload.version === 2 || journal.upload.version === 3) && !journal.accepted)\n throw new Error(\"Portable merge journal requires an explicit accepted projection.\");\n if (journal.accepted) validatePortableSnapshot(journal.accepted);\n } catch {\n throw new Error(\"Invalid merge journal paths, metadata, or bytes; preserve evidence for review.\");\n }\n // Integrity is intrinsic to the recorded transaction, not the user's current recovery policy.\n // completeJournal separately checks that the recorded policy matches the current setup.\n try {\n if (\n journal.accepted &&\n (!sameLocalFields(journal.accepted.localFields, journal.upload.localFields) ||\n !sameHashes(\n fileHashMap(portableSnapshot(journal.after, journal.upload.localFields)),\n fileHashMap(portableSnapshot(journal.accepted, journal.upload.localFields)),\n ))\n )\n throw new Error(\"Projection mismatch.\");\n } catch {\n throw new Error(\"Invalid accepted merge projection; preserve journal evidence.\");\n }\n if (journal.progress) {\n const known = new Set([\n ...Object.keys(journal.progress.previous?.lastFileHashes ?? {}),\n ...[...journal.before.files, ...journal.after.files, ...journal.upload.files].map((file) => file.path),\n ]);\n const progress = journal.progress;\n if (\n !config.partialSync ||\n !progress.previous ||\n syncStateFingerprint(progress.previous) !== journal.stateIdentity ||\n !Array.isArray(progress.groups) ||\n progress.groups.length > 16_384 ||\n progress.groups.some(\n (group) =>\n !Array.isArray(group.paths) ||\n !group.paths.length ||\n group.paths.length > 16_384 ||\n group.paths.some((filePath) => !known.has(filePath)) ||\n !/^[a-f0-9-]{36}$/u.test(group.artifact),\n )\n )\n throw new Error(\"Invalid partial acceptance metadata; preserve journal evidence.\");\n }\n if (journal.progress) {\n const before = fileHashMap(journal.before);\n const after = fileHashMap(journal.after);\n const { readConflictArtifact } = await import(\"./conflict-artifacts.js\");\n const backendIdentity = (JSON.parse(journal.identity) as unknown[])[1];\n if (typeof backendIdentity !== \"string\") throw new Error(\"Invalid partial backend identity.\");\n const byArtifact = new Map<string, typeof journal.progress.groups>();\n for (const group of journal.progress.groups) {\n const groups = byArtifact.get(group.artifact) ?? [];\n groups.push(group);\n byArtifact.set(group.artifact, groups);\n }\n for (const [token, groups] of byArtifact) {\n const artifact = await readConflictArtifact(config, backendIdentity, token);\n const retainedGroups = new Set(artifact.groups.map((group) => JSON.stringify(group.paths)));\n const remote = fileHashMap(artifact.remote);\n const upload = fileHashMap(journal.upload);\n for (const group of groups) {\n if (!retainedGroups.has(JSON.stringify(group.paths)))\n throw new Error(\"Partial group does not match retained artifact evidence.\");\n for (const filePath of group.paths)\n if (\n before[filePath] !== after[filePath] ||\n remote[filePath] !== upload[filePath] ||\n journal.progress.previous.lastFileHashes[filePath] !== artifact.state.lastFileHashes[filePath]\n )\n throw new Error(\"Withheld version changed in journal; preserve evidence.\");\n }\n }\n }\n return journal;\n}\n\nexport async function writeMergeJournal(config: AnySyncConfig, journal: MergeJournal) {\n await writeJson(mergeJournalPath(config), journal, { maxBytes: 384 * 1024 * 1024 });\n}\n\nexport async function clearMergeJournal(config: AnySyncConfig) {\n await fs.rm(mergeJournalPath(config), { force: true });\n await syncDirectory(path.dirname(mergeJournalPath(config)));\n}\n\nexport async function retireMergeJournal(config: AnySyncConfig) {\n if (!(await readMergeJournal(config))) return;\n const file = mergeJournalPath(config);\n await fs.rename(file, `${file}.${randomUUID()}.resolved`);\n await syncDirectory(path.dirname(file));\n}\n\nexport async function requireNoMergeJournal(config: AnySyncConfig, options: { force?: boolean } = {}) {\n const journal = await readMergeJournal(config);\n if (options.force || !journal) return;\n if (journal) {\n throw new Error(\n \"A merged transfer needs recovery. Run /sync sync to reconcile it. If newer local edits or remote revisions prevent recovery, review /sync diff and explicitly choose push --force or pull --force; the selected directional result will archive the old journal, not restore old bytes. Keep its backup; do not downgrade while recovery is pending.\",\n );\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,OAAO,QAAQ;AACf,OAAO,UAAU;AAmCV,SAAS,qBAAqB,QAAuB,iBAAyB;AACnF,SAAO,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cAAc,KAAK,QAAQ,iBAAiB,MAAM,CAAC,CAAC;AAC5D;AAEA,eAAsB,mBAAmB,QAAuB;AAC9D,MAAI,CAAE,MAAM,iBAAiB,MAAM,EAAI;AACvC,QAAM,OAAO,iBAAiB,MAAM;AACpC,QAAM,GAAG,OAAO,MAAM,GAAG,IAAI,IAAI,WAAW,CAAC,WAAW;AACxD,QAAM,cAAc,KAAK,QAAQ,IAAI,CAAC;AACxC;AAEA,eAAsB,sBAAsB,QAAuB,UAA+B,CAAC,GAAG;AACpG,QAAM,UAAU,MAAM,iBAAiB,MAAM;AAC7C,MAAI,QAAQ,SAAS,CAAC,QAAS;AAC/B,MAAI,SAAS;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,114 +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
|
-
|
|
4
|
-
// src/snapshot/snapshot-paths.ts
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
function expandHome(value) {
|
|
7
|
-
if (value === "~") return process.env.HOME ?? value;
|
|
8
|
-
if (value.startsWith("~/")) return path.join(process.env.HOME ?? "~", value.slice(2));
|
|
9
|
-
return value;
|
|
10
|
-
}
|
|
11
|
-
function sessionStorageRoot(root, configuredSessionDir2) {
|
|
12
|
-
return configuredSessionDir2 ? path.resolve(expandHome(configuredSessionDir2)) : path.resolve(root, "sessions");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// src/snapshot/session-paths.ts
|
|
16
|
-
import fs from "node:fs/promises";
|
|
17
|
-
import os from "node:os";
|
|
18
|
-
import path2 from "node:path";
|
|
19
|
-
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
20
|
-
function sessionDirFromContext(ctx) {
|
|
21
|
-
const manager = ctx.sessionManager;
|
|
22
|
-
const usesDefaultSessionDir = manager.usesDefaultSessionDir;
|
|
23
|
-
if (typeof usesDefaultSessionDir === "function" && usesDefaultSessionDir.call(manager)) {
|
|
24
|
-
return void 0;
|
|
25
|
-
}
|
|
26
|
-
const getSessionDir = manager.getSessionDir;
|
|
27
|
-
return typeof getSessionDir === "function" ? getSessionDir.call(manager) : void 0;
|
|
28
|
-
}
|
|
29
|
-
async function configuredSessionDir() {
|
|
30
|
-
let content;
|
|
31
|
-
try {
|
|
32
|
-
content = await fs.readFile(path2.join(agentDir(), "settings.json"), "utf8");
|
|
33
|
-
} catch (error) {
|
|
34
|
-
if (error.code === "ENOENT") return void 0;
|
|
35
|
-
throw error;
|
|
36
|
-
}
|
|
37
|
-
let settings;
|
|
38
|
-
try {
|
|
39
|
-
settings = JSON.parse(content.replace(/^\uFEFF/u, ""));
|
|
40
|
-
} catch {
|
|
41
|
-
throw new SyntaxError("Pi settings.json cannot be parsed; repair the file before syncing.");
|
|
42
|
-
}
|
|
43
|
-
return settings?.sessionDir ? expandSessionDir(settings.sessionDir) : void 0;
|
|
44
|
-
}
|
|
45
|
-
async function effectiveSessionRoot(ctx) {
|
|
46
|
-
return path2.resolve(sessionStorageRoot(agentDir(), sessionDirFromContext(ctx) ?? await configuredSessionDir()));
|
|
47
|
-
}
|
|
48
|
-
async function sessionDirForApply(ctx, snapshot) {
|
|
49
|
-
const contextSessionDir = sessionDirFromContext(ctx);
|
|
50
|
-
const localSessionDir = await configuredSessionDir();
|
|
51
|
-
if (contextSessionDir && path2.resolve(contextSessionDir) !== path2.resolve(localSessionDir ?? "")) {
|
|
52
|
-
return contextSessionDir;
|
|
53
|
-
}
|
|
54
|
-
return sessionDirFromSnapshot(snapshot) ?? contextSessionDir;
|
|
55
|
-
}
|
|
56
|
-
function requireStableMergeSessionRoot(before, after) {
|
|
57
|
-
const root = agentDir();
|
|
58
|
-
if (path2.resolve(sessionStorageRoot(root, sessionDirFromSnapshot(before))) !== path2.resolve(sessionStorageRoot(root, sessionDirFromSnapshot(after)))) {
|
|
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
|
-
function sessionDirFromSnapshot(snapshot) {
|
|
65
|
-
const settingsFile = snapshot.files.find((file) => file.path === "settings.json");
|
|
66
|
-
if (!settingsFile) return void 0;
|
|
67
|
-
let settings;
|
|
68
|
-
try {
|
|
69
|
-
settings = JSON.parse(
|
|
70
|
-
new TextDecoder("utf-8", { fatal: true }).decode(
|
|
71
|
-
decodeBase64Strict(settingsFile.contentBase64, settingsFile.path)
|
|
72
|
-
)
|
|
73
|
-
);
|
|
74
|
-
} catch {
|
|
75
|
-
throw new Error("Merged settings cannot be parsed; review a directional recovery.");
|
|
76
|
-
}
|
|
77
|
-
if (!settings || typeof settings !== "object" || Array.isArray(settings))
|
|
78
|
-
throw new Error("Merged settings must be a JSON object; review a directional recovery.");
|
|
79
|
-
const sessionDir = settings.sessionDir;
|
|
80
|
-
if (sessionDir !== void 0 && typeof sessionDir !== "string")
|
|
81
|
-
throw new Error("Merged sessionDir must be a string; review a directional recovery.");
|
|
82
|
-
return sessionDir ? expandSessionDir(sessionDir) : void 0;
|
|
83
|
-
}
|
|
84
|
-
function decodeBase64Strict(value, filePath) {
|
|
85
|
-
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(value) || value.length % 4 !== 0) {
|
|
86
|
-
throw new Error(`Invalid base64 content in snapshot file: ${filePath}`);
|
|
87
|
-
}
|
|
88
|
-
return Buffer.from(value, "base64");
|
|
89
|
-
}
|
|
90
|
-
function agentDir() {
|
|
91
|
-
return getAgentDir();
|
|
92
|
-
}
|
|
93
|
-
function expandSessionDir(value) {
|
|
94
|
-
return value === "~" || value.startsWith("~/") ? path2.join(os.homedir(), value.slice(2)) : value;
|
|
95
|
-
}
|
|
96
|
-
function snapshotOptionsForContext(ctx, config) {
|
|
97
|
-
return {
|
|
98
|
-
include: config.include,
|
|
99
|
-
sessionDir: sessionDirFromContext(ctx)
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export {
|
|
104
|
-
sessionStorageRoot,
|
|
105
|
-
sessionDirFromContext,
|
|
106
|
-
configuredSessionDir,
|
|
107
|
-
effectiveSessionRoot,
|
|
108
|
-
sessionDirForApply,
|
|
109
|
-
requireStableMergeSessionRoot,
|
|
110
|
-
agentDir,
|
|
111
|
-
expandSessionDir,
|
|
112
|
-
snapshotOptionsForContext
|
|
113
|
-
};
|
|
114
|
-
//# sourceMappingURL=chunk-CBLTWXAU.ts.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/snapshot/snapshot-paths.ts", "../../src/snapshot/session-paths.ts"],
|
|
4
|
-
"sourcesContent": ["import path from \"node:path\";\n\nfunction expandHome(value: string) {\n if (value === \"~\") return process.env.HOME ?? value;\n if (value.startsWith(\"~/\")) return path.join(process.env.HOME ?? \"~\", value.slice(2));\n return value;\n}\n\nexport function sessionStorageRoot(root: string, configuredSessionDir?: string) {\n return configuredSessionDir ? path.resolve(expandHome(configuredSessionDir)) : path.resolve(root, \"sessions\");\n}\n", "import fs from \"node:fs/promises\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { type ExtensionCommandContext, type ExtensionContext, getAgentDir } from \"@earendil-works/pi-coding-agent\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport { sessionStorageRoot } from \"./snapshot-paths.js\";\nimport type { Snapshot, SnapshotOptions } from \"./snapshot-types.js\";\n\nexport function sessionDirFromContext(ctx: ExtensionCommandContext | ExtensionContext) {\n const manager = ctx.sessionManager as typeof ctx.sessionManager & {\n usesDefaultSessionDir?: () => boolean;\n };\n const usesDefaultSessionDir = manager.usesDefaultSessionDir;\n if (typeof usesDefaultSessionDir === \"function\" && usesDefaultSessionDir.call(manager)) {\n return undefined;\n }\n const getSessionDir = manager.getSessionDir;\n return typeof getSessionDir === \"function\" ? (getSessionDir.call(manager) as string | undefined) : undefined;\n}\n\nexport async function configuredSessionDir() {\n let content: string;\n try {\n content = await fs.readFile(path.join(agentDir(), \"settings.json\"), \"utf8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n throw error;\n }\n let settings: { sessionDir?: string } | null;\n try {\n // Pi accepts a leading UTF-8 BOM in its settings file; snapshot bytes stay unchanged.\n settings = JSON.parse(content.replace(/^\\uFEFF/u, \"\")) as typeof settings;\n } catch {\n throw new SyntaxError(\"Pi settings.json cannot be parsed; repair the file before syncing.\");\n }\n return settings?.sessionDir ? expandSessionDir(settings.sessionDir) : undefined;\n}\n\nexport async function effectiveSessionRoot(ctx: ExtensionCommandContext | ExtensionContext) {\n return path.resolve(sessionStorageRoot(agentDir(), sessionDirFromContext(ctx) ?? (await configuredSessionDir())));\n}\n\nexport async function sessionDirForApply(ctx: ExtensionCommandContext | ExtensionContext, snapshot: Snapshot) {\n const contextSessionDir = sessionDirFromContext(ctx);\n const localSessionDir = await configuredSessionDir();\n if (contextSessionDir && path.resolve(contextSessionDir) !== path.resolve(localSessionDir ?? \"\")) {\n return contextSessionDir;\n }\n return sessionDirFromSnapshot(snapshot) ?? contextSessionDir;\n}\n\n/** Hash-only merge plans cannot describe installation into a different session root. */\nexport function requireStableMergeSessionRoot(before: Snapshot, after: Snapshot) {\n const root = agentDir();\n if (\n path.resolve(sessionStorageRoot(root, sessionDirFromSnapshot(before))) !==\n path.resolve(sessionStorageRoot(root, sessionDirFromSnapshot(after)))\n ) {\n throw new Error(\n \"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.\",\n );\n }\n}\n\nfunction sessionDirFromSnapshot(snapshot: Snapshot) {\n const settingsFile = snapshot.files.find((file) => file.path === \"settings.json\");\n if (!settingsFile) return undefined;\n let settings: unknown;\n try {\n settings = JSON.parse(\n new TextDecoder(\"utf-8\", { fatal: true }).decode(\n decodeBase64Strict(settingsFile.contentBase64, settingsFile.path),\n ),\n );\n } catch {\n // JSON parser errors can quote private settings values; never surface their payload.\n throw new Error(\"Merged settings cannot be parsed; review a directional recovery.\");\n }\n if (!settings || typeof settings !== \"object\" || Array.isArray(settings))\n throw new Error(\"Merged settings must be a JSON object; review a directional recovery.\");\n const sessionDir = (settings as { sessionDir?: unknown }).sessionDir;\n if (sessionDir !== undefined && typeof sessionDir !== \"string\")\n throw new Error(\"Merged sessionDir must be a string; review a directional recovery.\");\n return sessionDir ? expandSessionDir(sessionDir) : undefined;\n}\n\nfunction decodeBase64Strict(value: string, filePath: string) {\n if (!/^[A-Za-z0-9+/]*={0,2}$/.test(value) || value.length % 4 !== 0) {\n throw new Error(`Invalid base64 content in snapshot file: ${filePath}`);\n }\n return Buffer.from(value, \"base64\");\n}\n\nexport function agentDir() {\n return getAgentDir();\n}\n\nexport function expandSessionDir(value: string) {\n return value === \"~\" || value.startsWith(\"~/\") ? path.join(os.homedir(), value.slice(2)) : value;\n}\n\nexport function snapshotOptionsForContext(\n ctx: ExtensionCommandContext | ExtensionContext,\n config: AnySyncConfig,\n): SnapshotOptions {\n return {\n include: config.include,\n sessionDir: sessionDirFromContext(ctx),\n };\n}\n"],
|
|
5
|
-
"mappings": ";;;;AAAA,OAAO,UAAU;AAEjB,SAAS,WAAW,OAAe;AACjC,MAAI,UAAU,IAAK,QAAO,QAAQ,IAAI,QAAQ;AAC9C,MAAI,MAAM,WAAW,IAAI,EAAG,QAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,KAAK,MAAM,MAAM,CAAC,CAAC;AACpF,SAAO;AACT;AAEO,SAAS,mBAAmB,MAAcA,uBAA+B;AAC9E,SAAOA,wBAAuB,KAAK,QAAQ,WAAWA,qBAAoB,CAAC,IAAI,KAAK,QAAQ,MAAM,UAAU;AAC9G;;;ACVA,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,OAAOC,WAAU;AACjB,SAA8D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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
|
-
COUPLED_FIELDS,
|
|
5
|
-
mergeSettingsJson,
|
|
6
|
-
snapshotFile
|
|
7
|
-
} from "./chunk-AKMV47YC.ts";
|
|
8
|
-
import {
|
|
9
|
-
edits,
|
|
10
|
-
isMergeTextPath,
|
|
11
|
-
lines,
|
|
12
|
-
text
|
|
13
|
-
} from "./chunk-6LD5KX55.ts";
|
|
14
|
-
import {
|
|
15
|
-
parseJsonObjectDocument,
|
|
16
|
-
parseSettingsDocument
|
|
17
|
-
} from "./chunk-ZW5ZLGBI.ts";
|
|
18
|
-
import {
|
|
19
|
-
scanSnapshot
|
|
20
|
-
} from "./chunk-ESKOPQVB.ts";
|
|
21
|
-
import {
|
|
22
|
-
AGENT_INPUT_BYTES,
|
|
23
|
-
AGENT_MAX_UNITS,
|
|
24
|
-
AGENT_OUTPUT_BYTES
|
|
25
|
-
} from "./chunk-PRUEIIK7.ts";
|
|
26
|
-
|
|
27
|
-
// src/sync/agent-candidate.ts
|
|
28
|
-
import { createHash } from "node:crypto";
|
|
29
|
-
var digest = (value) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
30
|
-
function overlaps(a, b) {
|
|
31
|
-
return a.start === a.end || b.start === b.end ? a.start <= b.end && b.start <= a.end : a.start < b.end && b.start < a.end;
|
|
32
|
-
}
|
|
33
|
-
function textParts(filePath, baseText, localText, remoteText) {
|
|
34
|
-
const base = lines(baseText);
|
|
35
|
-
const changes = [
|
|
36
|
-
...edits(base, lines(localText)).map((hunk) => ({ ...hunk, side: "local" })),
|
|
37
|
-
...edits(base, lines(remoteText)).map((hunk) => ({ ...hunk, side: "remote" }))
|
|
38
|
-
].sort((a, b) => a.start - b.start || a.end - b.end);
|
|
39
|
-
const clusters = [];
|
|
40
|
-
for (const change of changes) {
|
|
41
|
-
const last = clusters.at(-1);
|
|
42
|
-
if (last?.some((item) => overlaps(item, change))) last.push(change);
|
|
43
|
-
else clusters.push([change]);
|
|
44
|
-
}
|
|
45
|
-
const result = [];
|
|
46
|
-
let cursor = 0;
|
|
47
|
-
for (const cluster of clusters) {
|
|
48
|
-
const start = Math.min(...cluster.map((item) => item.start));
|
|
49
|
-
const end = Math.max(...cluster.map((item) => item.end));
|
|
50
|
-
result.push(base.slice(cursor, start).join(""));
|
|
51
|
-
const image = (side) => {
|
|
52
|
-
let position = start;
|
|
53
|
-
const output = [];
|
|
54
|
-
for (const hunk of cluster.filter((item) => item.side === side)) {
|
|
55
|
-
output.push(...base.slice(position, hunk.start), ...hunk.lines);
|
|
56
|
-
position = hunk.end;
|
|
57
|
-
}
|
|
58
|
-
return [...output, ...base.slice(position, end)].join("");
|
|
59
|
-
};
|
|
60
|
-
const local = image("local");
|
|
61
|
-
const remote = image("remote");
|
|
62
|
-
const original = base.slice(start, end).join("");
|
|
63
|
-
if (local === remote || local === original || remote === original) result.push(local === original ? remote : local);
|
|
64
|
-
else result.push({ id: "", path: filePath, kind: "text", base: original, local, remote });
|
|
65
|
-
cursor = end;
|
|
66
|
-
}
|
|
67
|
-
result.push(base.slice(cursor).join(""));
|
|
68
|
-
return result;
|
|
69
|
-
}
|
|
70
|
-
function buildAgentEvidence(plan, local, remote, ancestors) {
|
|
71
|
-
const evidence = { units: [], files: [], unsupported: [] };
|
|
72
|
-
if (plan.kind !== "planned") return evidence;
|
|
73
|
-
if (plan.conflicts.length > AGENT_MAX_UNITS)
|
|
74
|
-
throw new Error("Autonomous sync paused: too many conflict paths for bounded analysis.");
|
|
75
|
-
for (const conflict of plan.conflicts) {
|
|
76
|
-
try {
|
|
77
|
-
if (conflict.reason !== "both-changed") throw new Error("unsupported conflict");
|
|
78
|
-
const versions = [ancestors, local.files, remote.files].map((files) => {
|
|
79
|
-
const file2 = files.find((item) => item.path === conflict.path);
|
|
80
|
-
if (!file2) throw new Error("missing ancestor/version");
|
|
81
|
-
const bytes = Buffer.from(file2.contentBase64, "base64");
|
|
82
|
-
if (bytes.length > 8192) throw new Error("file bound");
|
|
83
|
-
return text(bytes);
|
|
84
|
-
});
|
|
85
|
-
const [base, left, right] = versions;
|
|
86
|
-
const file = { path: conflict.path, base, local: left, remote: right };
|
|
87
|
-
let units;
|
|
88
|
-
if (conflict.path === "settings.json") {
|
|
89
|
-
const documents = versions.map((value) => parseSettingsDocument(Buffer.from(value)));
|
|
90
|
-
const merge = mergeSettingsJson(
|
|
91
|
-
...versions.map((value) => Buffer.from(value)),
|
|
92
|
-
void 0,
|
|
93
|
-
true
|
|
94
|
-
);
|
|
95
|
-
if (merge.kind === "review" && merge.reason !== "field-conflict") throw new Error("unsupported settings");
|
|
96
|
-
const fields = new Set(merge.kind === "review" ? merge.fields : []);
|
|
97
|
-
const groups = COUPLED_FIELDS.map((group) => [...group]);
|
|
98
|
-
const coupled = new Set(groups.flat());
|
|
99
|
-
groups.push(...[...fields].filter((key) => !coupled.has(key)).map((key) => [key]));
|
|
100
|
-
file.fields = [];
|
|
101
|
-
units = groups.filter((group) => group.some((key) => fields.has(key))).map((group) => {
|
|
102
|
-
const values = documents.map(
|
|
103
|
-
(document) => JSON.stringify(
|
|
104
|
-
Object.fromEntries(
|
|
105
|
-
group.flatMap((key) => {
|
|
106
|
-
const node = document.root.members.get(key)?.node;
|
|
107
|
-
return node ? [[key, node.value]] : [];
|
|
108
|
-
})
|
|
109
|
-
)
|
|
110
|
-
)
|
|
111
|
-
);
|
|
112
|
-
const unit = {
|
|
113
|
-
id: "",
|
|
114
|
-
path: file.path,
|
|
115
|
-
kind: "settings",
|
|
116
|
-
base: values[0] ?? "{}",
|
|
117
|
-
local: values[1] ?? "{}",
|
|
118
|
-
remote: values[2] ?? "{}"
|
|
119
|
-
};
|
|
120
|
-
file.fields?.push({ id: String(evidence.units.length + file.fields.length), key: group[0] ?? "" });
|
|
121
|
-
return unit;
|
|
122
|
-
});
|
|
123
|
-
} else {
|
|
124
|
-
if (!isMergeTextPath(conflict.path)) throw new Error("unsupported path");
|
|
125
|
-
file.parts = textParts(file.path, base, left, right);
|
|
126
|
-
units = file.parts.filter((part) => typeof part !== "string");
|
|
127
|
-
}
|
|
128
|
-
for (const unit of units) {
|
|
129
|
-
unit.id = String(evidence.units.length);
|
|
130
|
-
evidence.units.push(unit);
|
|
131
|
-
}
|
|
132
|
-
evidence.files.push(file);
|
|
133
|
-
} catch {
|
|
134
|
-
evidence.unsupported.push(conflict.path);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (evidence.units.length > AGENT_MAX_UNITS || Buffer.byteLength(JSON.stringify(evidence.units)) > AGENT_INPUT_BYTES)
|
|
138
|
-
throw new Error("Autonomous sync paused: conflict evidence exceeds its input bound.");
|
|
139
|
-
if (scanSnapshot({
|
|
140
|
-
...local,
|
|
141
|
-
files: evidence.units.flatMap(
|
|
142
|
-
(unit) => [unit.path, unit.base, unit.local, unit.remote].map((value) => snapshotFile(unit.path, Buffer.from(value)))
|
|
143
|
-
)
|
|
144
|
-
}).length)
|
|
145
|
-
throw new Error("Autonomous sync paused: possible secrets in model evidence; nothing was disclosed.");
|
|
146
|
-
return evidence;
|
|
147
|
-
}
|
|
148
|
-
function parseAgentCandidate(raw, evidence) {
|
|
149
|
-
if (Buffer.byteLength(raw) > AGENT_OUTPUT_BYTES) throw new Error("Agent output exceeds its bound.");
|
|
150
|
-
const parsed = parseJsonObjectDocument(Buffer.from(raw)).root.value;
|
|
151
|
-
if (Object.keys(parsed).sort().join(",") !== "results,version" || parsed.version !== 1 || !Array.isArray(parsed.results) || parsed.results.length !== evidence.units.length)
|
|
152
|
-
throw new Error("Invalid agent candidate contract.");
|
|
153
|
-
const seen = /* @__PURE__ */ new Set();
|
|
154
|
-
for (const result of parsed.results) {
|
|
155
|
-
if (!result || typeof result !== "object" || Array.isArray(result)) throw new Error("Invalid agent result.");
|
|
156
|
-
const row = result;
|
|
157
|
-
const unit = evidence.units.find((unit2) => unit2.id === row.id);
|
|
158
|
-
if (!unit || seen.has(unit.id)) throw new Error("Unowned or duplicate agent unit.");
|
|
159
|
-
seen.add(unit.id);
|
|
160
|
-
const keys = Object.keys(row).sort().join(",");
|
|
161
|
-
if (keys === "id,refuse" && row.refuse === true) continue;
|
|
162
|
-
if (unit.kind === "settings" && keys === "id,source" && (row.source === "local" || row.source === "remote"))
|
|
163
|
-
continue;
|
|
164
|
-
if (unit.kind === "text" && keys === "content,id" && typeof row.content === "string" && row.content.length > 0) {
|
|
165
|
-
text(Buffer.from(row.content));
|
|
166
|
-
if (/^(?:<{7}|={7}|>{7}|\|{7})/mu.test(row.content)) throw new Error("Unresolved conflict markers.");
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
throw new Error("Unsupported agent action.");
|
|
170
|
-
}
|
|
171
|
-
return parsed;
|
|
172
|
-
}
|
|
173
|
-
function applyAgentCandidate(plan, evidence, candidate) {
|
|
174
|
-
parseAgentCandidate(JSON.stringify(candidate), evidence);
|
|
175
|
-
if (plan.kind !== "planned") throw new Error("Unverified merge plan.");
|
|
176
|
-
const results = new Map(candidate.results.map((row) => [row.id, row]));
|
|
177
|
-
const replacements = /* @__PURE__ */ new Map();
|
|
178
|
-
for (const file of evidence.files) {
|
|
179
|
-
const units = evidence.units.filter((unit) => unit.path === file.path);
|
|
180
|
-
if (units.some((unit) => results.get(unit.id) && "refuse" in (results.get(unit.id) ?? {}))) continue;
|
|
181
|
-
let bytes;
|
|
182
|
-
if (file.parts) {
|
|
183
|
-
bytes = Buffer.from(
|
|
184
|
-
file.parts.map((part) => typeof part === "string" ? part : results.get(part.id).content).join("")
|
|
185
|
-
);
|
|
186
|
-
} else {
|
|
187
|
-
const selections = new Map(
|
|
188
|
-
(file.fields ?? []).map(({ id, key }) => [key, results.get(id).source])
|
|
189
|
-
);
|
|
190
|
-
const merged = mergeSettingsJson(
|
|
191
|
-
Buffer.from(file.base),
|
|
192
|
-
Buffer.from(file.local),
|
|
193
|
-
Buffer.from(file.remote),
|
|
194
|
-
selections,
|
|
195
|
-
true
|
|
196
|
-
);
|
|
197
|
-
if (merged.kind !== "merged") throw new Error("Agent settings units remain unresolved.");
|
|
198
|
-
parseSettingsDocument(merged.content);
|
|
199
|
-
for (const { key } of file.fields ?? []) {
|
|
200
|
-
if (!selections.has(key)) throw new Error("Missing atomic settings selection.");
|
|
201
|
-
}
|
|
202
|
-
bytes = merged.content;
|
|
203
|
-
}
|
|
204
|
-
if (bytes.length > AGENT_OUTPUT_BYTES) throw new Error("Agent file exceeds output bound.");
|
|
205
|
-
replacements.set(file.path, snapshotFile(file.path, bytes));
|
|
206
|
-
}
|
|
207
|
-
const decisions = plan.decisions.map((decision) => {
|
|
208
|
-
const file = replacements.get(decision.path);
|
|
209
|
-
return file && decision.kind === "conflict" ? { kind: "accepted", path: file.path, source: "merged", file } : decision;
|
|
210
|
-
});
|
|
211
|
-
return { kind: "planned", decisions, conflicts: decisions.filter((item) => item.kind === "conflict") };
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export {
|
|
215
|
-
digest,
|
|
216
|
-
buildAgentEvidence,
|
|
217
|
-
parseAgentCandidate,
|
|
218
|
-
applyAgentCandidate
|
|
219
|
-
};
|
|
220
|
-
//# sourceMappingURL=chunk-CQD2TJHE.ts.map
|