@narumitw/pi-sync 0.60.5 → 0.62.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 +25 -0
- package/README.md +32 -23
- package/dist/chunks/{chunk-F64YWRXG.ts → chunk-3E3TR3JE.ts} +4 -4
- package/dist/chunks/{chunk-YVH5VJR4.ts → chunk-6PFZUEUG.ts} +138 -61
- package/dist/chunks/chunk-6PFZUEUG.ts.map +7 -0
- package/dist/chunks/{chunk-ZIL6PW5L.ts → chunk-6YKOHBSC.ts} +2 -2
- package/dist/chunks/{chunk-OA4NZLSL.ts → chunk-APZVJAEW.ts} +4 -3
- package/dist/chunks/{chunk-KPWZNMKM.ts → chunk-ECYCNZOE.ts} +1 -5
- package/dist/chunks/chunk-ECYCNZOE.ts.map +7 -0
- package/dist/chunks/chunk-GELYN4UC.ts +14 -0
- package/dist/chunks/chunk-GELYN4UC.ts.map +7 -0
- package/dist/chunks/{chunk-V2QIMC3U.ts → chunk-GSCZ4VXV.ts} +13 -8
- package/dist/chunks/chunk-GSCZ4VXV.ts.map +7 -0
- package/dist/chunks/{chunk-6W2SNZ5P.ts → chunk-IBXEM35O.ts} +8 -3
- package/dist/chunks/{chunk-6W2SNZ5P.ts.map → chunk-IBXEM35O.ts.map} +3 -3
- package/dist/chunks/{chunk-6KIWZ4AY.ts → chunk-INECVQNR.ts} +13 -12
- package/dist/chunks/chunk-INECVQNR.ts.map +7 -0
- package/dist/chunks/chunk-JREGWM2B.ts +139 -0
- package/dist/chunks/chunk-JREGWM2B.ts.map +7 -0
- package/dist/chunks/{chunk-277VHM2P.ts → chunk-MNYRU5U5.ts} +5 -2
- package/dist/chunks/{chunk-277VHM2P.ts.map → chunk-MNYRU5U5.ts.map} +2 -2
- package/dist/chunks/chunk-NHFGAZEC.ts +277 -0
- package/dist/chunks/chunk-NHFGAZEC.ts.map +7 -0
- package/dist/chunks/{chunk-EMRFVLZM.ts → chunk-NXWHPVXR.ts} +2 -2
- package/dist/chunks/{chunk-SMVKMYLK.ts → chunk-P4GI7LTT.ts} +2 -2
- package/dist/chunks/{chunk-MCUZFUHY.ts → chunk-PWESMTH6.ts} +10 -10
- package/dist/chunks/{chunk-V4AMI3VL.ts → chunk-R3SAMXB6.ts} +10 -2
- package/dist/chunks/chunk-R3SAMXB6.ts.map +7 -0
- package/dist/chunks/{chunk-RNIEVDTR.ts → chunk-T3LABNHF.ts} +2 -2
- package/dist/chunks/{chunk-S3R3W3KF.ts → chunk-UMPA5S7X.ts} +2 -2
- package/dist/chunks/{chunk-WP2M67XZ.ts → chunk-WBIOSK76.ts} +2 -2
- package/dist/chunks/{chunk-LAXTCSX4.ts → chunk-ZB3GNX3P.ts} +124 -139
- package/dist/chunks/chunk-ZB3GNX3P.ts.map +7 -0
- package/dist/chunks/{chunk-HEB6YT64.ts → chunk-ZO52JM4H.ts} +2 -2
- package/dist/chunks/{command-handler-TNPWFIPG.ts → command-handler-6ATREPG7.ts} +44 -40
- package/dist/chunks/command-handler-6ATREPG7.ts.map +7 -0
- package/dist/chunks/{conflict-review-ETCSYJTH.ts → conflict-review-MAOGTIAI.ts} +4 -4
- package/dist/chunks/{continuous-record-3XDXDOMV.ts → continuous-record-3SKJ6I3V.ts} +2 -2
- package/dist/chunks/{continuous-storage-HLKCHF6Z.ts → continuous-storage-3EU6I7Z3.ts} +2 -2
- package/dist/chunks/{file-selection-DD6X4J2K.ts → file-selection-QR2KZVGD.ts} +28 -15
- package/dist/chunks/file-selection-QR2KZVGD.ts.map +7 -0
- package/dist/chunks/manager-result-dispatcher-MC6EQOQY.ts +19 -0
- package/dist/chunks/{manager-ui-LFONXWQN.ts → manager-ui-AOFUNXAJ.ts} +648 -305
- package/dist/chunks/manager-ui-AOFUNXAJ.ts.map +7 -0
- package/dist/chunks/remote-selection-ui-4BTP2OJR.ts +18 -0
- package/dist/chunks/{setup-switch-SPZE7HIQ.ts → setup-switch-Y6AMFFNK.ts} +7 -7
- package/dist/chunks/{setup-wizard-5JYKAEIT.ts → setup-wizard-5G426MOZ.ts} +18 -16
- package/dist/chunks/setup-wizard-5G426MOZ.ts.map +7 -0
- package/dist/chunks/{snapshot-5HY3M2NL.ts → snapshot-ZUJJZCFW.ts} +2 -2
- package/dist/chunks/{snapshot-transaction-directory-OU2D7R7A.ts → snapshot-transaction-directory-F46JWRAU.ts} +2 -2
- package/dist/chunks/{state-directory-XXHU73Z3.ts → state-directory-CMAIF34J.ts} +2 -2
- package/dist/chunks/{sync-inspection-6VGR2UVZ.ts → sync-inspection-ITZ6Z4DE.ts} +7 -7
- package/dist/chunks/{sync-operations-SAKAZL6Z.ts → sync-operations-NMVKF7SE.ts} +13 -9
- package/dist/chunks/sync-operations-NMVKF7SE.ts.map +7 -0
- package/dist/chunks/{sync-state-2LMIXJ2C.ts → sync-state-QIT64TKV.ts} +2 -2
- package/dist/daemon/LICENSE +21 -0
- package/dist/daemon/dist/build-version.js +8 -0
- package/dist/daemon/dist/child-sdk.mjs +17 -0
- package/dist/daemon/dist/cli.js +169 -0
- package/dist/daemon/dist/client.js +909 -0
- package/dist/daemon/dist/consent.js +265 -0
- package/dist/daemon/dist/document.js +6 -0
- package/dist/daemon/dist/endpoint.js +91 -0
- package/dist/daemon/dist/engine/backends/backend-factory.js +16 -0
- package/dist/daemon/dist/engine/backends/backend-identity.js +38 -0
- package/dist/daemon/dist/engine/backends/backend-types.js +1 -0
- package/dist/daemon/dist/engine/backends/git/git-backend.js +715 -0
- package/dist/daemon/dist/engine/backends/git/git-config.js +118 -0
- package/dist/daemon/dist/engine/backends/git/git-runner.js +232 -0
- package/dist/daemon/dist/engine/backends/git/git-storage.js +252 -0
- package/dist/daemon/dist/engine/backends/s3/s3-backend.js +444 -0
- package/dist/daemon/dist/engine/backends/s3/s3-client.js +352 -0
- package/dist/daemon/dist/engine/backends/s3/s3-conditions.js +66 -0
- package/dist/daemon/dist/engine/backends/snapshot-pointer.js +22 -0
- package/dist/daemon/dist/engine/backends/sync-backend.js +23 -0
- package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +542 -0
- package/dist/daemon/dist/engine/backends/webdav/webdav-client.js +326 -0
- package/dist/daemon/dist/engine/backends/webdav/webdav-config.js +73 -0
- package/dist/daemon/dist/engine/commands/command-types.js +1 -0
- package/dist/daemon/dist/engine/host.js +16 -0
- package/dist/daemon/dist/engine/ignore/effective-ignore-policy.js +33 -0
- package/dist/daemon/dist/engine/ignore/ignore-edit.js +102 -0
- package/dist/daemon/dist/engine/ignore/ignore-initialization.js +186 -0
- package/dist/daemon/dist/engine/ignore/ignore-migration-prompt.js +139 -0
- package/dist/daemon/dist/engine/ignore/ignore-settings.js +322 -0
- package/dist/daemon/dist/engine/ignore/ignore-source.js +250 -0
- package/dist/daemon/dist/engine/paths.js +71 -0
- package/dist/daemon/dist/engine/settings/config-errors.js +4 -0
- package/dist/daemon/dist/engine/settings/config-file.js +736 -0
- package/dist/daemon/dist/engine/settings/config.js +301 -0
- package/dist/daemon/dist/engine/settings/settings-management.js +193 -0
- package/dist/daemon/dist/engine/settings/settings-store.js +41 -0
- package/dist/daemon/dist/engine/settings/settings-types.js +1 -0
- package/dist/daemon/dist/engine/settings/settings-validation.js +384 -0
- package/dist/daemon/dist/engine/snapshot/session-paths.js +160 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-apply.js +348 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-bounds.js +20 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-case-replacement.js +82 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-codec.js +61 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-entry-projection.js +78 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-exclude-safety.js +262 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-mutation-queues.js +133 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-paths.js +11 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-payload.js +10 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-reviewed-preimages.js +60 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-root-transition.js +138 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-directory.js +16 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-images.js +387 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-plan.js +68 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-policy.js +276 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-stage.js +303 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-verification.js +78 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction.js +813 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-types.js +9 -0
- package/dist/daemon/dist/engine/snapshot/snapshot.js +678 -0
- package/dist/daemon/dist/engine/state/json-file.js +49 -0
- package/dist/daemon/dist/engine/state/lock-policy.js +2 -0
- package/dist/daemon/dist/engine/state/lock.js +259 -0
- package/dist/daemon/dist/engine/state/lockfile-fs.js +13 -0
- package/dist/daemon/dist/engine/state/merge-baseline-store.js +198 -0
- package/dist/daemon/dist/engine/state/mutation-directory-sync.js +34 -0
- package/dist/daemon/dist/engine/state/operation-availability.js +40 -0
- package/dist/daemon/dist/engine/state/state-directory.js +227 -0
- package/dist/daemon/dist/engine/state/state-types.js +1 -0
- package/dist/daemon/dist/engine/state/sync-state-store.js +54 -0
- package/dist/daemon/dist/engine/sync/agent-candidate.js +207 -0
- package/dist/daemon/dist/engine/sync/agent-plan.js +84 -0
- package/dist/daemon/dist/engine/sync/agent-policy.js +10 -0
- package/dist/daemon/dist/engine/sync/agent-refusal-retry.js +39 -0
- package/dist/daemon/dist/engine/sync/agent-request.js +13 -0
- package/dist/daemon/dist/engine/sync/agent-runner.js +183 -0
- package/dist/daemon/dist/engine/sync/agent-store.js +177 -0
- package/dist/daemon/dist/engine/sync/agent-sync.js +132 -0
- package/dist/daemon/dist/engine/sync/apply-review.js +52 -0
- package/dist/daemon/dist/engine/sync/conflict-artifact-ownership.js +53 -0
- package/dist/daemon/dist/engine/sync/conflict-artifacts.js +158 -0
- package/dist/daemon/dist/engine/sync/conflict-groups.js +76 -0
- package/dist/daemon/dist/engine/sync/conflict-preview.js +53 -0
- package/dist/daemon/dist/engine/sync/conflict-resolution.js +53 -0
- package/dist/daemon/dist/engine/sync/conflict-retention.js +61 -0
- package/dist/daemon/dist/engine/sync/conflict-review.js +73 -0
- package/dist/daemon/dist/engine/sync/content-conflicts.js +70 -0
- package/dist/daemon/dist/engine/sync/continuous-errors.js +66 -0
- package/dist/daemon/dist/engine/sync/continuous-lease.js +206 -0
- package/dist/daemon/dist/engine/sync/continuous-record.js +199 -0
- package/dist/daemon/dist/engine/sync/continuous-storage.js +59 -0
- package/dist/daemon/dist/engine/sync/continuous-sync.js +521 -0
- package/dist/daemon/dist/engine/sync/continuous-watch.js +140 -0
- package/dist/daemon/dist/engine/sync/exclude-policy.js +86 -0
- package/dist/daemon/dist/engine/sync/field-migration.js +20 -0
- package/dist/daemon/dist/engine/sync/file-merge-planner.js +123 -0
- package/dist/daemon/dist/engine/sync/initialization.js +80 -0
- package/dist/daemon/dist/engine/sync/json-document.js +172 -0
- package/dist/daemon/dist/engine/sync/local-field-policy.js +26 -0
- package/dist/daemon/dist/engine/sync/local-fields.js +196 -0
- package/dist/daemon/dist/engine/sync/merge-apply.js +529 -0
- package/dist/daemon/dist/engine/sync/merge-journal.js +295 -0
- package/dist/daemon/dist/engine/sync/merge-transfer-error.js +64 -0
- package/dist/daemon/dist/engine/sync/merged-sync.js +674 -0
- package/dist/daemon/dist/engine/sync/mutation-owner.js +18 -0
- package/dist/daemon/dist/engine/sync/package-merge.js +82 -0
- package/dist/daemon/dist/engine/sync/partial-progress.js +41 -0
- package/dist/daemon/dist/engine/sync/remote-snapshot.js +104 -0
- package/dist/daemon/dist/engine/sync/resolver-stream.js +34 -0
- package/dist/daemon/dist/engine/sync/session-merge.js +178 -0
- package/dist/daemon/dist/engine/sync/session-push.js +33 -0
- package/dist/daemon/dist/engine/sync/settings-conflicts.js +56 -0
- package/dist/daemon/dist/engine/sync/settings-merge.js +93 -0
- package/dist/daemon/dist/engine/sync/signals.js +8 -0
- package/dist/daemon/dist/engine/sync/startup-timings.js +44 -0
- package/dist/daemon/dist/engine/sync/sync-decision.js +81 -0
- package/dist/daemon/dist/engine/sync/sync-error-guidance.js +55 -0
- package/dist/daemon/dist/engine/sync/sync-errors.js +18 -0
- package/dist/daemon/dist/engine/sync/sync-inspection.js +42 -0
- package/dist/daemon/dist/engine/sync/sync-loaders.js +8 -0
- package/dist/daemon/dist/engine/sync/sync-local.js +40 -0
- package/dist/daemon/dist/engine/sync/sync-mutations.js +733 -0
- package/dist/daemon/dist/engine/sync/sync-operations.js +3 -0
- package/dist/daemon/dist/engine/sync/sync-policy.js +621 -0
- package/dist/daemon/dist/engine/sync/sync-queries.js +212 -0
- package/dist/daemon/dist/engine/sync/sync-state.js +129 -0
- package/dist/daemon/dist/engine/sync/text-merge.js +124 -0
- package/dist/daemon/dist/engine/types.js +2 -0
- package/dist/daemon/dist/engine/ui/merge-review.js +7 -0
- package/dist/daemon/dist/engine/ui/merged-sync-summary.js +86 -0
- package/dist/daemon/dist/engine/ui/sync-format.js +165 -0
- package/dist/daemon/dist/engine/ui/sync-status.js +30 -0
- package/dist/daemon/dist/engine/ui/terminal-text.js +9 -0
- package/dist/daemon/dist/engine/ui/transfer-changes.js +24 -0
- package/dist/daemon/dist/engine/ui/transfer-review.js +19 -0
- package/dist/daemon/dist/engine-service.js +344 -0
- package/dist/daemon/dist/identity.js +241 -0
- package/dist/daemon/dist/idle-exit.js +77 -0
- package/dist/daemon/dist/index.js +4 -0
- package/dist/daemon/dist/lifecycle-log.js +53 -0
- package/dist/daemon/dist/lifecycle.js +21 -0
- package/dist/daemon/dist/model-signature.js +7 -0
- package/dist/daemon/dist/monitor.js +272 -0
- package/dist/daemon/dist/participant-admission.js +30 -0
- package/dist/daemon/dist/protocol.js +104 -0
- package/dist/daemon/dist/resolver-host.js +78 -0
- package/dist/daemon/dist/server.js +953 -0
- package/dist/daemon/dist/service-host.js +174 -0
- package/dist/daemon/dist/upgrade-repair.js +55 -0
- package/dist/daemon/package.json +3 -0
- package/dist/index.ts +32 -32
- package/dist/package.json +6 -0
- package/docs/daemon-migration.md +27 -16
- package/package.json +11 -5
- package/skills/configure-pi-sync/SKILL.md +38 -13
- package/skills/configure-pi-sync/references/configuration.md +61 -34
- package/src/commands/command-execution.ts +8 -2
- package/src/daemon/pi-client.ts +1 -0
- package/src/settings/config.ts +1 -0
- package/src/sync/sync-operations.ts +18 -10
- package/src/sync/sync-policy.ts +5 -0
- package/src/ui/agent-mode-setting.ts +9 -1
- package/src/ui/excluded-paths-ui.ts +157 -2
- package/src/ui/file-selection.ts +12 -7
- package/src/ui/ignore-file-ui.ts +271 -0
- package/src/ui/ignore-migration-prompt.ts +65 -0
- package/src/ui/manager-state.ts +39 -20
- package/src/ui/manager-ui.ts +38 -19
- package/src/ui/remote-selection-ui.ts +159 -33
- package/src/ui/settings-frame.ts +2 -8
- package/src/ui/settings-review.ts +26 -0
- package/src/ui/settings-ui.ts +327 -199
- package/src/ui/setup/directory-rules.ts +81 -0
- package/src/ui/setup/git-ui.ts +14 -24
- package/src/ui/setup/s3-ui.ts +13 -26
- package/src/ui/setup/setup-actions.ts +0 -4
- package/src/ui/setup/setup-prompts.ts +99 -17
- package/src/ui/setup/setup-switcher.ts +4 -2
- package/src/ui/setup/setup-wizard.ts +5 -4
- package/src/ui/setup/webdav-ui.ts +13 -27
- package/src/ui/storage-connections-ui.ts +22 -14
- package/src/ui/sync-attention.ts +8 -3
- package/src/ui/sync-format.ts +8 -1
- package/src/ui/sync-setups-ui.ts +47 -27
- package/dist/chunks/chunk-6KIWZ4AY.ts.map +0 -7
- package/dist/chunks/chunk-KPWZNMKM.ts.map +0 -7
- package/dist/chunks/chunk-LAXTCSX4.ts.map +0 -7
- package/dist/chunks/chunk-V2QIMC3U.ts.map +0 -7
- package/dist/chunks/chunk-V4AMI3VL.ts.map +0 -7
- package/dist/chunks/chunk-YVH5VJR4.ts.map +0 -7
- package/dist/chunks/command-handler-TNPWFIPG.ts.map +0 -7
- package/dist/chunks/file-selection-DD6X4J2K.ts.map +0 -7
- package/dist/chunks/manager-result-dispatcher-2GFNWHDM.ts +0 -18
- package/dist/chunks/manager-ui-LFONXWQN.ts.map +0 -7
- package/dist/chunks/remote-selection-ui-GFR6TDTX.ts +0 -17
- package/dist/chunks/setup-wizard-5JYKAEIT.ts.map +0 -7
- package/dist/chunks/sync-operations-SAKAZL6Z.ts.map +0 -7
- /package/dist/chunks/{chunk-F64YWRXG.ts.map → chunk-3E3TR3JE.ts.map} +0 -0
- /package/dist/chunks/{chunk-ZIL6PW5L.ts.map → chunk-6YKOHBSC.ts.map} +0 -0
- /package/dist/chunks/{chunk-OA4NZLSL.ts.map → chunk-APZVJAEW.ts.map} +0 -0
- /package/dist/chunks/{chunk-EMRFVLZM.ts.map → chunk-NXWHPVXR.ts.map} +0 -0
- /package/dist/chunks/{chunk-SMVKMYLK.ts.map → chunk-P4GI7LTT.ts.map} +0 -0
- /package/dist/chunks/{chunk-MCUZFUHY.ts.map → chunk-PWESMTH6.ts.map} +0 -0
- /package/dist/chunks/{chunk-RNIEVDTR.ts.map → chunk-T3LABNHF.ts.map} +0 -0
- /package/dist/chunks/{chunk-S3R3W3KF.ts.map → chunk-UMPA5S7X.ts.map} +0 -0
- /package/dist/chunks/{chunk-WP2M67XZ.ts.map → chunk-WBIOSK76.ts.map} +0 -0
- /package/dist/chunks/{chunk-HEB6YT64.ts.map → chunk-ZO52JM4H.ts.map} +0 -0
- /package/dist/chunks/{conflict-review-ETCSYJTH.ts.map → conflict-review-MAOGTIAI.ts.map} +0 -0
- /package/dist/chunks/{continuous-record-3XDXDOMV.ts.map → continuous-record-3SKJ6I3V.ts.map} +0 -0
- /package/dist/chunks/{continuous-storage-HLKCHF6Z.ts.map → continuous-storage-3EU6I7Z3.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-2GFNWHDM.ts.map → manager-result-dispatcher-MC6EQOQY.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-GFR6TDTX.ts.map → remote-selection-ui-4BTP2OJR.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-SPZE7HIQ.ts.map → setup-switch-Y6AMFFNK.ts.map} +0 -0
- /package/dist/chunks/{snapshot-5HY3M2NL.ts.map → snapshot-ZUJJZCFW.ts.map} +0 -0
- /package/dist/chunks/{snapshot-transaction-directory-OU2D7R7A.ts.map → snapshot-transaction-directory-F46JWRAU.ts.map} +0 -0
- /package/dist/chunks/{state-directory-XXHU73Z3.ts.map → state-directory-CMAIF34J.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-6VGR2UVZ.ts.map → sync-inspection-ITZ6Z4DE.ts.map} +0 -0
- /package/dist/chunks/{sync-state-2LMIXJ2C.ts.map → sync-state-QIT64TKV.ts.map} +0 -0
|
@@ -0,0 +1,733 @@
|
|
|
1
|
+
import { createSyncBackend } from "../backends/backend-factory.js";
|
|
2
|
+
import { expectedRemoteHead, } from "../backends/sync-backend.js";
|
|
3
|
+
import { loadConfig, syncCheckConfigFingerprint } from "../settings/config.js";
|
|
4
|
+
import { effectiveSessionRoot, requireStableMergeSessionRoot, resolvedSnapshotOptionsForContext, sessionDirForApply, } from "../snapshot/session-paths.js";
|
|
5
|
+
import { createSnapshot, filterSnapshotForConfigPolicy, mergeRemotePreservedFiles, regenerateSnapshotIdentity, scanSnapshot, snapshotIncludesSessions, snapshotWithoutSessions, } from "../snapshot/snapshot.js";
|
|
6
|
+
import { applySnapshot } from "../snapshot/snapshot-apply.js";
|
|
7
|
+
import { ignorePolicyValidator } from "../snapshot/snapshot-transaction-policy.js";
|
|
8
|
+
import { pruneMergeBaselines } from "../state/merge-baseline-store.js";
|
|
9
|
+
import { readStateForConfig, syncStateFingerprint, writeStateForConfig } from "../state/sync-state-store.js";
|
|
10
|
+
import { countPreservedRemoteFiles, formatPublicationPreview, formatPullSummary, formatPushSummary, formatRollbackSummary, } from "../ui/sync-format.js";
|
|
11
|
+
import { setSyncStatus } from "../ui/sync-status.js";
|
|
12
|
+
import { confirmTransferReview } from "../ui/transfer-review.js";
|
|
13
|
+
import { startupTransferEnabled } from "./agent-policy.js";
|
|
14
|
+
import { inspectCaseCleanup, revalidateCaseCleanup } from "./apply-review.js";
|
|
15
|
+
import { confirmFieldMigration } from "./field-migration.js";
|
|
16
|
+
import { overlayLocalFields, portableSnapshot, sameLocalFields, validatePortableSnapshot } from "./local-fields.js";
|
|
17
|
+
import { readMergeJournal, requireNoMergeJournal, retireMergeJournal } from "./merge-journal.js";
|
|
18
|
+
import { mergeSync } from "./merged-sync.js";
|
|
19
|
+
import { readRemoteSnapshot, readRemoteSnapshotForUpload, readSnapshotForHead, requireCompatibleRemoteSelection, sameRemoteHead, } from "./remote-snapshot.js";
|
|
20
|
+
import { throwIfAborted } from "./signals.js";
|
|
21
|
+
import { createSyncDecision } from "./sync-decision.js";
|
|
22
|
+
import { errorMessage } from "./sync-errors.js";
|
|
23
|
+
import { backupLocal, captureMutationOwner, protectedSessionPaths } from "./sync-local.js";
|
|
24
|
+
import { formatIgnorePolicyComparison, inspectRemoteSelection, requireLegacyTransferPolicy, syncSelectionHasContent, syncSessionsSelected, } from "./sync-policy.js";
|
|
25
|
+
import { acceptedSelection, canPullRemoteSessionsOnFirstSync, canPullRemoteSettingsOnFirstSync, fileHashMap, hasLocalChanges, hasRemoteChanges, remoteChangedSinceState, sameHashes, shouldRefreshSyncedState, snapshotHashesMatchState, snapshotsMatch, syncPolicyChanged, } from "./sync-state.js";
|
|
26
|
+
const VERSION = 1;
|
|
27
|
+
const POST_LOCAL_COMMIT_TIMEOUT_MS = 30_000;
|
|
28
|
+
/** Whole-direction acceptance must never forget withheld state without an explicit recovery choice. */
|
|
29
|
+
function requireResolvedDirectionalProgress(state, options, allowForce = true) {
|
|
30
|
+
if (state.unresolved?.length && (options.auto || !options.force || !allowForce))
|
|
31
|
+
throw new Error("Unresolved partial conflicts remain. Review /sync conflicts or explicitly choose push --force or pull --force; automatic transfer and rollback cannot accept unresolved groups.");
|
|
32
|
+
}
|
|
33
|
+
function requireIgnoreBaselineReview(ctx, config, state, options) {
|
|
34
|
+
if (config.ignorePolicy &&
|
|
35
|
+
state.lastAppliedSnapshot &&
|
|
36
|
+
syncPolicyChanged(state, config) &&
|
|
37
|
+
(options.auto || options.yes || !ctx.hasUI)) {
|
|
38
|
+
throw new Error("Local ignore-file policy or source changed since the last accepted baseline. Review a foreground directional transfer.");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export class PublicationStatePersistenceError extends Error {
|
|
42
|
+
head;
|
|
43
|
+
backupPath;
|
|
44
|
+
constructor(head, cause, backupPath) {
|
|
45
|
+
super(`Remote publication ${head.snapshotId} is active, but local sync state could not be saved${backupPath ? `; local backup: ${backupPath}` : ""}: ${errorMessage(cause)}`, { cause });
|
|
46
|
+
this.name = "PublicationStatePersistenceError";
|
|
47
|
+
this.head = head;
|
|
48
|
+
this.backupPath = backupPath;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export class RollbackPublicationError extends Error {
|
|
52
|
+
backupPath;
|
|
53
|
+
constructor(backupPath, cause) {
|
|
54
|
+
super(`Rollback applied locally with backup ${backupPath}, but remote publication failed: ${errorMessage(cause)}`, {
|
|
55
|
+
cause,
|
|
56
|
+
});
|
|
57
|
+
this.name = "RollbackPublicationError";
|
|
58
|
+
this.backupPath = backupPath;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export async function push(ctx, options, input, factory = createSyncBackend) {
|
|
62
|
+
const validateMutation = captureMutationOwner(ctx, options.signal);
|
|
63
|
+
const validateCommittedOwner = captureMutationOwner(ctx);
|
|
64
|
+
const config = input?.config ?? (await loadConfig(options.setup));
|
|
65
|
+
throwIfAborted(options.signal);
|
|
66
|
+
await requireNoMergeJournal(config, options);
|
|
67
|
+
const state = input?.state ?? (await readStateForConfig(config));
|
|
68
|
+
validateMutation();
|
|
69
|
+
requireResolvedDirectionalProgress(state, options);
|
|
70
|
+
if (options.auto &&
|
|
71
|
+
(config.scope === "agent-directory" || state.scope !== undefined) &&
|
|
72
|
+
(options.force || !state.lastAppliedSnapshot || syncPolicyChanged(state, config))) {
|
|
73
|
+
throw new Error("Automatic push requires an accepted baseline with matching content policy.");
|
|
74
|
+
}
|
|
75
|
+
setSyncStatus(ctx, `pushing ${config.setupName}`, { activity: "pushing" });
|
|
76
|
+
const backend = input?.backend ?? (await factory(config));
|
|
77
|
+
throwIfAborted(options.signal);
|
|
78
|
+
const snapshotOptions = await resolvedSnapshotOptionsForContext(ctx, config, options.signal);
|
|
79
|
+
validateMutation();
|
|
80
|
+
const validateIgnorePolicy = ignorePolicyValidator({ ...snapshotOptions, validateMutation });
|
|
81
|
+
const localRaw = input?.local ?? (await createSnapshot(config.snapshotIdentity, snapshotOptions));
|
|
82
|
+
const local = portableSnapshot(localRaw, config.localFields);
|
|
83
|
+
throwIfAborted(options.signal);
|
|
84
|
+
let head = await backend.readHead(options.signal);
|
|
85
|
+
let remoteForUpload = await readRemoteSnapshotForUpload(backend, config, head, state, options);
|
|
86
|
+
validateMutation();
|
|
87
|
+
if (config.ignorePolicy && remoteForUpload && options.force && (options.auto || options.yes || !ctx.hasUI)) {
|
|
88
|
+
const comparison = inspectRemoteSelection(config.include, remoteForUpload, config.exclude, config);
|
|
89
|
+
if (comparison.kind === "different")
|
|
90
|
+
requireCompatibleRemoteSelection(config, remoteForUpload);
|
|
91
|
+
}
|
|
92
|
+
requireIgnoreBaselineReview(ctx, config, state, options);
|
|
93
|
+
if (remoteForUpload && !options.force) {
|
|
94
|
+
requireCompatibleRemoteSelection(config, remoteForUpload);
|
|
95
|
+
}
|
|
96
|
+
if (remoteChangedSinceState(head, state, config, (left, right) => backend.sameRevision(left, right)) &&
|
|
97
|
+
!options.force) {
|
|
98
|
+
const remoteForConflict = remoteForUpload
|
|
99
|
+
? filterSnapshotForConfigPolicy(remoteForUpload, config, snapshotOptions)
|
|
100
|
+
: undefined;
|
|
101
|
+
if (!remoteForConflict || !snapshotHashesMatchState(remoteForConflict, state, config)) {
|
|
102
|
+
throw createSyncDecision({
|
|
103
|
+
kind: head ? "remote-or-policy-changed" : "remote-empty",
|
|
104
|
+
config,
|
|
105
|
+
state,
|
|
106
|
+
local,
|
|
107
|
+
remote: remoteForConflict,
|
|
108
|
+
localChanged: hasLocalChanges(local, state, config),
|
|
109
|
+
remoteChanged: true,
|
|
110
|
+
directMessage: "Remote or sync policy changed since last sync. Run /sync pull first or /sync push --force.",
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!remoteForUpload && head && (config.localFields !== undefined || !options.yes))
|
|
115
|
+
remoteForUpload = await readSnapshotForHead(backend, head, options.signal, config);
|
|
116
|
+
validateMutation();
|
|
117
|
+
if (!(await confirmFieldMigration(ctx, config, state, remoteForUpload, options.force, options.signal))) {
|
|
118
|
+
setSyncStatus(ctx, undefined);
|
|
119
|
+
return "cancelled";
|
|
120
|
+
}
|
|
121
|
+
const configIdentity = syncCheckConfigFingerprint(config);
|
|
122
|
+
let upload = await snapshotForUpload(backend, config, local, head, remoteForUpload, snapshotOptions);
|
|
123
|
+
if (!config.skipSecretScan) {
|
|
124
|
+
const secrets = scanSnapshot(local);
|
|
125
|
+
if (secrets.length > 0) {
|
|
126
|
+
throw new Error(`Refusing to push possible secrets:\n${secrets.map((s) => `- ${s}`).join("\n")}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (!(await confirmPush(ctx, options, config, backend, local, upload, head, remoteForUpload, validateMutation))) {
|
|
130
|
+
return "cancelled";
|
|
131
|
+
}
|
|
132
|
+
if (options.force) {
|
|
133
|
+
const refreshedHead = await backend.readHead(options.signal);
|
|
134
|
+
validateMutation();
|
|
135
|
+
if (!sameRemoteHead(backend, head, refreshedHead)) {
|
|
136
|
+
if (config.ignorePolicy)
|
|
137
|
+
throw new Error("Remote changed during ignore-file push review; reopen the review.");
|
|
138
|
+
head = refreshedHead;
|
|
139
|
+
remoteForUpload = head ? await readSnapshotForHead(backend, head, options.signal, config) : undefined;
|
|
140
|
+
validateMutation();
|
|
141
|
+
if (!(await confirmFieldMigration(ctx, config, state, remoteForUpload, options.force, options.signal))) {
|
|
142
|
+
setSyncStatus(ctx, undefined);
|
|
143
|
+
return "cancelled";
|
|
144
|
+
}
|
|
145
|
+
validateMutation();
|
|
146
|
+
upload = await snapshotForUpload(backend, config, local, head, remoteForUpload, snapshotOptions);
|
|
147
|
+
if (!(await confirmPush(ctx, options, config, backend, local, upload, head, remoteForUpload, validateMutation, "Remote changed during review. Push the refreshed plan?"))) {
|
|
148
|
+
return "cancelled";
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
validateMutation();
|
|
153
|
+
if (configIdentity !== syncCheckConfigFingerprint(await loadConfig(options.setup)))
|
|
154
|
+
throw new Error("Settings changed during push review.");
|
|
155
|
+
validateMutation();
|
|
156
|
+
if (config.scope === "agent-directory" ||
|
|
157
|
+
!options.yes ||
|
|
158
|
+
config.localFields !== undefined ||
|
|
159
|
+
(await readMergeJournal(config))) {
|
|
160
|
+
const current = await createSnapshot(config.snapshotIdentity, snapshotOptions);
|
|
161
|
+
if (!sameHashes(fileHashMap(current), fileHashMap(localRaw)))
|
|
162
|
+
throw new Error("Local content changed during push review; retry from current bytes.");
|
|
163
|
+
}
|
|
164
|
+
const currentState = await readStateForConfig(config);
|
|
165
|
+
if ((config.ignorePolicy || !options.yes) && syncStateFingerprint(currentState) !== syncStateFingerprint(state))
|
|
166
|
+
throw new Error("Baseline changed during push review.");
|
|
167
|
+
requireResolvedDirectionalProgress(currentState, options);
|
|
168
|
+
if (config.scope === "agent-directory" &&
|
|
169
|
+
snapshotOptions.sessionDir !== (await effectiveSessionRoot(ctx, config, options.signal)))
|
|
170
|
+
throw new Error("Pi session storage changed during push review.");
|
|
171
|
+
validateMutation();
|
|
172
|
+
if (configIdentity !== syncCheckConfigFingerprint(await loadConfig(options.setup)))
|
|
173
|
+
throw new Error("Settings changed during push review.");
|
|
174
|
+
validateMutation();
|
|
175
|
+
if (validateIgnorePolicy) {
|
|
176
|
+
validatePortableSnapshot(upload);
|
|
177
|
+
await validateIgnorePolicy();
|
|
178
|
+
}
|
|
179
|
+
const result = await backend.publishSnapshot(upload, expectedRemoteHead(head), {
|
|
180
|
+
signal: options.signal,
|
|
181
|
+
onCommit: options.onCommit,
|
|
182
|
+
...(validateIgnorePolicy ? { validateIgnorePolicy } : {}),
|
|
183
|
+
});
|
|
184
|
+
try {
|
|
185
|
+
await writeStateForConfig(config, {
|
|
186
|
+
version: VERSION,
|
|
187
|
+
profile: config.snapshotIdentity,
|
|
188
|
+
lastAppliedSnapshot: result.head.snapshotId,
|
|
189
|
+
lastRemoteRevision: result.head.revision,
|
|
190
|
+
lastFileHashes: fileHashMap(local),
|
|
191
|
+
...acceptedSelection(config),
|
|
192
|
+
...(config.localFields !== undefined ? { localFields: config.localFields } : {}),
|
|
193
|
+
}, local, validateCommittedOwner);
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
throw new PublicationStatePersistenceError(result.head, error);
|
|
197
|
+
}
|
|
198
|
+
await retireMergeJournal(config);
|
|
199
|
+
await pruneMergeBaselines(config, await readStateForConfig(config), validateCommittedOwner);
|
|
200
|
+
validateCommittedOwner();
|
|
201
|
+
if (options.signal?.aborted)
|
|
202
|
+
return;
|
|
203
|
+
setSyncStatus(ctx, undefined);
|
|
204
|
+
if (!options.silent) {
|
|
205
|
+
ctx.ui.notify([
|
|
206
|
+
`Pushed ${upload.files.length} files from sync setup “${config.setupName}” as ${result.head.snapshotId}.`,
|
|
207
|
+
...result.warnings,
|
|
208
|
+
]
|
|
209
|
+
.filter(Boolean)
|
|
210
|
+
.join("\n"), result.warnings.length > 0 ? "warning" : "info");
|
|
211
|
+
}
|
|
212
|
+
return "applied";
|
|
213
|
+
}
|
|
214
|
+
export async function pull(ctx, options, factory = createSyncBackend, initial) {
|
|
215
|
+
const validateMutation = captureMutationOwner(ctx, options.signal);
|
|
216
|
+
const validateCommittedOwner = captureMutationOwner(ctx);
|
|
217
|
+
const config = await loadConfig(options.setup);
|
|
218
|
+
validateMutation();
|
|
219
|
+
const configIdentity = syncCheckConfigFingerprint(config);
|
|
220
|
+
if (initial && initial.configIdentity !== configIdentity)
|
|
221
|
+
throw new Error("Settings changed before initial pull; run sync again.");
|
|
222
|
+
await requireNoMergeJournal(config, options);
|
|
223
|
+
setSyncStatus(ctx, `pulling ${config.setupName}`, { activity: "pulling" });
|
|
224
|
+
const backend = await factory(config);
|
|
225
|
+
const state = await readStateForConfig(config);
|
|
226
|
+
validateMutation();
|
|
227
|
+
if (initial && initial.stateIdentity !== syncStateFingerprint(state))
|
|
228
|
+
throw new Error("Baseline changed before initial pull; run sync again.");
|
|
229
|
+
requireResolvedDirectionalProgress(state, options);
|
|
230
|
+
const snapshotOptions = await resolvedSnapshotOptionsForContext(ctx, config, options.signal);
|
|
231
|
+
validateMutation();
|
|
232
|
+
const validateIgnorePolicy = ignorePolicyValidator({ ...snapshotOptions, validateMutation });
|
|
233
|
+
if (initial && initial.sessionDir !== snapshotOptions.sessionDir)
|
|
234
|
+
throw new Error("Pi session storage changed before initial pull; run sync again.");
|
|
235
|
+
const local = await createSnapshot(config.snapshotIdentity, snapshotOptions);
|
|
236
|
+
validateMutation();
|
|
237
|
+
if (initial && !sameHashes(initial.localHashes, fileHashMap(local)))
|
|
238
|
+
throw new Error("Local bytes changed before initial pull; run sync again.");
|
|
239
|
+
const { head, snapshot: remote } = await readRemoteSnapshot(backend, config, options.signal, snapshotOptions);
|
|
240
|
+
validateMutation();
|
|
241
|
+
if (initial && !matchesInitialHead(initial, backend, head))
|
|
242
|
+
throw new Error("Remote changed before initial pull; run sync again.");
|
|
243
|
+
requireIgnoreBaselineReview(ctx, config, state, options);
|
|
244
|
+
const localChanged = hasLocalChanges(local, state, config);
|
|
245
|
+
if (!remote) {
|
|
246
|
+
throw createSyncDecision({
|
|
247
|
+
kind: "remote-empty",
|
|
248
|
+
config,
|
|
249
|
+
state,
|
|
250
|
+
local,
|
|
251
|
+
localChanged,
|
|
252
|
+
remoteChanged: false,
|
|
253
|
+
directMessage: "Remote is empty. Run /sync push from a configured machine first.",
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
if (!sameLocalFields(config.localFields, remote.localFields)) {
|
|
257
|
+
setSyncStatus(ctx, undefined);
|
|
258
|
+
throw new Error("Pull requires the configured local-field policy to match the remote. To change the remote policy, review push --force from the authoritative machine first, then pull using matching rules; old history is not erased.");
|
|
259
|
+
}
|
|
260
|
+
if (!(await confirmFieldMigration(ctx, config, state, remote, options.force, options.signal))) {
|
|
261
|
+
setSyncStatus(ctx, undefined);
|
|
262
|
+
return "cancelled";
|
|
263
|
+
}
|
|
264
|
+
const logical = portableSnapshot(remote, config.localFields);
|
|
265
|
+
const physical = overlayLocalFields(logical, local, config.localFields);
|
|
266
|
+
if (config.scope === "agent-directory")
|
|
267
|
+
requireStableMergeSessionRoot(local, physical, config.scope);
|
|
268
|
+
const reviewedProtectedPaths = protectedSessionPaths(ctx, snapshotOptions.sessionDir);
|
|
269
|
+
const remoteChanged = hasRemoteChanges(remote, state, config, reviewedProtectedPaths);
|
|
270
|
+
if (localChanged && remoteChanged && state.lastAppliedSnapshot && !options.force) {
|
|
271
|
+
throw createSyncDecision({
|
|
272
|
+
kind: "both-changed",
|
|
273
|
+
config,
|
|
274
|
+
state,
|
|
275
|
+
local,
|
|
276
|
+
remote,
|
|
277
|
+
localChanged,
|
|
278
|
+
remoteChanged,
|
|
279
|
+
directMessage: "Both local and remote changed since last sync. Run /sync diff, then choose /sync pull --force or /sync push --force.",
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
const caseCleanup = options.yes ? [] : await inspectCaseCleanup(physical, snapshotOptions);
|
|
283
|
+
validateMutation();
|
|
284
|
+
if (!options.yes &&
|
|
285
|
+
!(await confirmTransferReview(ctx, snapshotIncludesSessions(remote) ? "Pull pi settings and sessions?" : "Pull pi settings?", formatPullSummary(config, backend.destination, local, physical, reviewedProtectedPaths, caseCleanup.map((item) => item.path)), options.signal, validateMutation))) {
|
|
286
|
+
setSyncStatus(ctx, undefined);
|
|
287
|
+
ctx.ui.notify("Pull cancelled.", "info");
|
|
288
|
+
return "cancelled";
|
|
289
|
+
}
|
|
290
|
+
throwIfAborted(options.signal);
|
|
291
|
+
const recoveringMerge = Boolean(await readMergeJournal(config));
|
|
292
|
+
const requireFreshRecovery = async () => {
|
|
293
|
+
validateMutation();
|
|
294
|
+
const currentHead = await backend.readHead(options.signal);
|
|
295
|
+
validateMutation();
|
|
296
|
+
const current = await createSnapshot(config.snapshotIdentity, snapshotOptions);
|
|
297
|
+
validateMutation();
|
|
298
|
+
if (!sameHashes(fileHashMap(current), fileHashMap(local)) || !sameRemoteHead(backend, head, currentHead)) {
|
|
299
|
+
throw new Error("Local or remote content changed during recovery review; retry from a fresh diff.");
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
if (recoveringMerge)
|
|
303
|
+
await requireFreshRecovery();
|
|
304
|
+
if (configIdentity !== syncCheckConfigFingerprint(await loadConfig(options.setup)))
|
|
305
|
+
throw new Error("Settings changed during pull review.");
|
|
306
|
+
validateMutation();
|
|
307
|
+
const refreshed = await createSnapshot(config.snapshotIdentity, snapshotOptions);
|
|
308
|
+
if (!sameHashes(fileHashMap(local), fileHashMap(refreshed)))
|
|
309
|
+
throw new Error("Local bytes changed during pull review.");
|
|
310
|
+
if (!sameRemoteHead(backend, head, await backend.readHead(options.signal)))
|
|
311
|
+
throw new Error("Remote changed during pull review.");
|
|
312
|
+
validateMutation();
|
|
313
|
+
const backup = await backupLocal(config.snapshotIdentity, snapshotOptions, options.signal);
|
|
314
|
+
const applySessionDir = await sessionDirForApply(ctx, physical, snapshotOptions);
|
|
315
|
+
if (recoveringMerge)
|
|
316
|
+
await requireFreshRecovery();
|
|
317
|
+
const currentState = await readStateForConfig(config);
|
|
318
|
+
validateMutation();
|
|
319
|
+
if ((config.ignorePolicy || initial || !options.yes) &&
|
|
320
|
+
syncStateFingerprint(currentState) !== syncStateFingerprint(state))
|
|
321
|
+
throw new Error("Baseline changed during pull review.");
|
|
322
|
+
requireResolvedDirectionalProgress(currentState, options);
|
|
323
|
+
if (!options.yes)
|
|
324
|
+
await revalidateCaseCleanup(caseCleanup, physical, snapshotOptions);
|
|
325
|
+
if (initial && !matchesInitialHead(initial, backend, await backend.readHead(options.signal)))
|
|
326
|
+
throw new Error("Remote changed during initial pull; run sync again.");
|
|
327
|
+
validateMutation();
|
|
328
|
+
if (config.scope && applySessionDir !== (await effectiveSessionRoot(ctx, config, options.signal)))
|
|
329
|
+
throw new Error("Pi session storage changed during pull review.");
|
|
330
|
+
validateMutation();
|
|
331
|
+
if (configIdentity !== syncCheckConfigFingerprint(await loadConfig(options.setup)))
|
|
332
|
+
throw new Error("Settings changed during pull review.");
|
|
333
|
+
validateMutation();
|
|
334
|
+
if (validateIgnorePolicy) {
|
|
335
|
+
if (!sameRemoteHead(backend, head, await backend.readHead(options.signal)))
|
|
336
|
+
throw new Error("Remote changed during pull review.");
|
|
337
|
+
await validateIgnorePolicy();
|
|
338
|
+
}
|
|
339
|
+
const protectedPaths = protectedSessionPaths(ctx, snapshotOptions.sessionDir);
|
|
340
|
+
if (validateIgnorePolicy && !samePaths(protectedPaths, reviewedProtectedPaths))
|
|
341
|
+
throw new Error("Live session protection changed during pull review; reopen the review.");
|
|
342
|
+
options.onCommit?.();
|
|
343
|
+
const lastFileHashes = await applySnapshot(physical, protectedPaths, {
|
|
344
|
+
...snapshotOptions,
|
|
345
|
+
sessionDir: applySessionDir,
|
|
346
|
+
validateMutation,
|
|
347
|
+
...(config.scope === "agent-directory" ? { reviewedLocal: local } : {}),
|
|
348
|
+
expectedFileHashes: config.localFields?.length
|
|
349
|
+
? { "settings.json": fileHashMap(local)["settings.json"] ?? null }
|
|
350
|
+
: undefined,
|
|
351
|
+
});
|
|
352
|
+
// Local installation is complete; user cancellation must not leave the baseline stale.
|
|
353
|
+
validateCommittedOwner();
|
|
354
|
+
await writeStateForConfig(config, {
|
|
355
|
+
version: VERSION,
|
|
356
|
+
profile: config.snapshotIdentity,
|
|
357
|
+
lastAppliedSnapshot: remote.id,
|
|
358
|
+
lastRemoteRevision: head?.revision,
|
|
359
|
+
lastFileHashes: config.localFields?.length
|
|
360
|
+
? { ...lastFileHashes, "settings.json": fileHashMap(logical)["settings.json"] }
|
|
361
|
+
: lastFileHashes,
|
|
362
|
+
...acceptedSelection(config),
|
|
363
|
+
...(config.localFields !== undefined ? { localFields: config.localFields } : {}),
|
|
364
|
+
}, logical, validateCommittedOwner);
|
|
365
|
+
await retireMergeJournal(config);
|
|
366
|
+
await pruneMergeBaselines(config, await readStateForConfig(config), validateCommittedOwner);
|
|
367
|
+
validateCommittedOwner();
|
|
368
|
+
if (options.signal?.aborted)
|
|
369
|
+
return "applied";
|
|
370
|
+
setSyncStatus(ctx, undefined);
|
|
371
|
+
if (!options.silent) {
|
|
372
|
+
ctx.ui.notify(`Pulled ${remote.files.length} files from ${remote.id}. Backup: ${backup}`, "info");
|
|
373
|
+
}
|
|
374
|
+
else if (options.auto && syncSessionsSelected(config) && snapshotIncludesSessions(remote)) {
|
|
375
|
+
ctx.ui.notify("Pulled Pi sessions after startup selected the current session. Restart Pi or resume a pulled session to use newly synced conversations.", "warning");
|
|
376
|
+
}
|
|
377
|
+
if (options.reload)
|
|
378
|
+
await maybeReload(ctx, options.signal, validateMutation);
|
|
379
|
+
return "applied";
|
|
380
|
+
}
|
|
381
|
+
export async function syncBoth(ctx, options, factory = createSyncBackend) {
|
|
382
|
+
const validateMutation = captureMutationOwner(ctx, options.signal);
|
|
383
|
+
const config = await loadConfig(options.setup);
|
|
384
|
+
throwIfAborted(options.signal);
|
|
385
|
+
options.background?.validate(config);
|
|
386
|
+
if (options.agentRetryRefusal) {
|
|
387
|
+
if (!config.agentMode || options.auto || options.background || !ctx.hasUI)
|
|
388
|
+
throw new Error("Enable Autonomous sync and use the foreground manager to retry a cached refusal.");
|
|
389
|
+
const state = await readStateForConfig(config);
|
|
390
|
+
validateMutation();
|
|
391
|
+
const pending = await readMergeJournal(config);
|
|
392
|
+
validateMutation();
|
|
393
|
+
if (!syncSelectionHasContent(config) || !state.lastAppliedSnapshot || pending)
|
|
394
|
+
throw new Error("Retry requires an accepted baseline and no pending journal. Use Sync now or reviewed recovery.");
|
|
395
|
+
return mergeSync(ctx, options, factory);
|
|
396
|
+
}
|
|
397
|
+
if (syncSelectionHasContent(config) && options.auto && startupTransferEnabled(config))
|
|
398
|
+
return mergeSync(ctx, options, factory);
|
|
399
|
+
if (!options.auto && syncSelectionHasContent(config) && (await readMergeJournal(config)))
|
|
400
|
+
return mergeSync(ctx, options, factory);
|
|
401
|
+
const state = await readStateForConfig(config);
|
|
402
|
+
throwIfAborted(options.signal);
|
|
403
|
+
if (!options.auto && syncSelectionHasContent(config) && state.lastAppliedSnapshot)
|
|
404
|
+
return mergeSync(ctx, options, factory);
|
|
405
|
+
if (!syncSelectionHasContent(config)) {
|
|
406
|
+
if (!options.silent) {
|
|
407
|
+
ctx.ui.notify(`Sync setup “${config.setupName}” includes no files. Choose included content in /sync Settings before syncing.`, "warning");
|
|
408
|
+
}
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const backend = await factory(config);
|
|
412
|
+
const snapshotOptions = await resolvedSnapshotOptionsForContext(ctx, config, options.signal);
|
|
413
|
+
validateMutation();
|
|
414
|
+
const local = await createSnapshot(config.snapshotIdentity, snapshotOptions);
|
|
415
|
+
throwIfAborted(options.signal);
|
|
416
|
+
const { head, snapshot: remote } = await readRemoteSnapshot(backend, config, options.signal, snapshotOptions);
|
|
417
|
+
throwIfAborted(options.signal);
|
|
418
|
+
const localChanged = hasLocalChanges(local, state, config);
|
|
419
|
+
const remoteChanged = remote
|
|
420
|
+
? hasRemoteChanges(remote, state, config, protectedSessionPaths(ctx, snapshotOptions.sessionDir))
|
|
421
|
+
: false;
|
|
422
|
+
if (options.auto)
|
|
423
|
+
throw new Error("Automatic transfer is not authorized by the current settings.");
|
|
424
|
+
// Established baselines return through mergeSync above; only initial-source selection remains.
|
|
425
|
+
const portableLocal = portableSnapshot(local, config.localFields);
|
|
426
|
+
const configIdentity = syncCheckConfigFingerprint(config);
|
|
427
|
+
const pullInitialSource = () => {
|
|
428
|
+
validateMutation();
|
|
429
|
+
return pull(ctx, options, factory, {
|
|
430
|
+
configIdentity,
|
|
431
|
+
stateIdentity: syncStateFingerprint(state),
|
|
432
|
+
sessionDir: snapshotOptions.sessionDir,
|
|
433
|
+
localHashes: fileHashMap(local),
|
|
434
|
+
head,
|
|
435
|
+
});
|
|
436
|
+
};
|
|
437
|
+
const acceptMatchingState = async (snapshot) => {
|
|
438
|
+
requireCompatibleRemoteSelection(config, snapshot);
|
|
439
|
+
if (config.scope === "agent-directory") {
|
|
440
|
+
const current = await createSnapshot(config.snapshotIdentity, snapshotOptions);
|
|
441
|
+
const currentState = await readStateForConfig(config);
|
|
442
|
+
const currentHead = await backend.readHead(options.signal);
|
|
443
|
+
if (!sameHashes(fileHashMap(current), fileHashMap(local)) ||
|
|
444
|
+
syncStateFingerprint(currentState) !== syncStateFingerprint(state) ||
|
|
445
|
+
!sameRemoteHead(backend, head, currentHead))
|
|
446
|
+
throw new Error("Initial source changed before baseline acceptance; run sync again.");
|
|
447
|
+
if (snapshotOptions.sessionDir !== (await effectiveSessionRoot(ctx, config, options.signal)) ||
|
|
448
|
+
configIdentity !== syncCheckConfigFingerprint(await loadConfig(options.setup)))
|
|
449
|
+
throw new Error("Settings or Pi session storage changed before baseline acceptance; run sync again.");
|
|
450
|
+
validateMutation();
|
|
451
|
+
const validateIgnorePolicy = ignorePolicyValidator({ ...snapshotOptions, validateMutation });
|
|
452
|
+
if (validateIgnorePolicy)
|
|
453
|
+
await validateIgnorePolicy();
|
|
454
|
+
}
|
|
455
|
+
const accepted = portableSnapshot(snapshot, config.localFields);
|
|
456
|
+
await writeStateForConfig(config, {
|
|
457
|
+
version: VERSION,
|
|
458
|
+
profile: config.snapshotIdentity,
|
|
459
|
+
lastAppliedSnapshot: snapshot.id,
|
|
460
|
+
lastRemoteRevision: head?.revision,
|
|
461
|
+
lastFileHashes: fileHashMap(accepted),
|
|
462
|
+
...acceptedSelection(config),
|
|
463
|
+
...(config.localFields !== undefined ? { localFields: config.localFields } : {}),
|
|
464
|
+
}, accepted, validateMutation);
|
|
465
|
+
await pruneMergeBaselines(config, await readStateForConfig(config), validateMutation);
|
|
466
|
+
validateMutation();
|
|
467
|
+
};
|
|
468
|
+
if (remote && remote.files.length > 0 && local.files.length > 0) {
|
|
469
|
+
requireCompatibleRemoteSelection(config, remote);
|
|
470
|
+
const portableRemote = portableSnapshot(remote, config.localFields);
|
|
471
|
+
if (!canPullRemoteSettingsOnFirstSync(portableLocal, portableRemote)) {
|
|
472
|
+
throw createSyncDecision({
|
|
473
|
+
kind: "first-sync-settings-diverged",
|
|
474
|
+
config,
|
|
475
|
+
state,
|
|
476
|
+
local,
|
|
477
|
+
remote,
|
|
478
|
+
localChanged: true,
|
|
479
|
+
remoteChanged: true,
|
|
480
|
+
directMessage: "Remote settings exist and this machine has different local Pi settings. Run /sync diff, then manually choose /sync pull or /sync push.",
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
if (!sameHashes(fileHashMap(portableLocal), fileHashMap(portableRemote))) {
|
|
484
|
+
if (!canPullRemoteSessionsOnFirstSync(portableLocal, portableRemote)) {
|
|
485
|
+
throw createSyncDecision({
|
|
486
|
+
kind: "first-sync-sessions-diverged",
|
|
487
|
+
config,
|
|
488
|
+
state,
|
|
489
|
+
local,
|
|
490
|
+
remote,
|
|
491
|
+
localChanged: true,
|
|
492
|
+
remoteChanged: true,
|
|
493
|
+
directMessage: "Remote settings match, but local and remote Pi sessions differ. Run /sync diff, then manually choose /sync pull or /sync push.",
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
await pullInitialSource();
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
await acceptMatchingState(remote);
|
|
500
|
+
if (!options.silent)
|
|
501
|
+
ctx.ui.notify("pi-sync state initialized; local settings already match remote.", "info");
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
if (localChanged &&
|
|
505
|
+
remoteChanged &&
|
|
506
|
+
remote &&
|
|
507
|
+
snapshotsMatch(portableLocal, portableSnapshot(remote, remote.localFields))) {
|
|
508
|
+
requireCompatibleRemoteSelection(config, remote);
|
|
509
|
+
await acceptMatchingState(remote);
|
|
510
|
+
if (!options.silent)
|
|
511
|
+
ctx.ui.notify("pi-sync is already up to date.", "info");
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
if (remoteChanged) {
|
|
515
|
+
await pullInitialSource();
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
if (localChanged || !remote) {
|
|
519
|
+
await push(ctx, options, { config, state, local, backend }, factory);
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
if (shouldRefreshSyncedState(remote, head, state, config, (left, right) => backend.sameRevision(left, right))) {
|
|
523
|
+
await acceptMatchingState(remote);
|
|
524
|
+
}
|
|
525
|
+
if (!options.silent)
|
|
526
|
+
ctx.ui.notify("pi-sync is already up to date.", "info");
|
|
527
|
+
}
|
|
528
|
+
export async function rollback(ctx, options, factory = createSyncBackend, expectedSelection) {
|
|
529
|
+
const validateMutation = captureMutationOwner(ctx, options.signal);
|
|
530
|
+
const validateCommittedOwner = captureMutationOwner(ctx);
|
|
531
|
+
const target = options.args[0];
|
|
532
|
+
if (!target)
|
|
533
|
+
throw new Error("Usage: /sync rollback <snapshot-id> [--yes]");
|
|
534
|
+
const config = await loadConfig(options.setup);
|
|
535
|
+
validateMutation();
|
|
536
|
+
if (config.ignorePolicy && (options.yes || options.auto || !ctx.hasUI))
|
|
537
|
+
throw new Error("Ignore-file rollback requires a separate foreground review; --yes cannot confirm it.");
|
|
538
|
+
const backend = await factory(config);
|
|
539
|
+
if (expectedSelection &&
|
|
540
|
+
(backend.identity !== expectedSelection.backendIdentity || config.setupName !== expectedSelection.setup)) {
|
|
541
|
+
throw new Error("Sync setup or storage location changed while history was open; reopen history and retry.");
|
|
542
|
+
}
|
|
543
|
+
// --force is only a rollback compatibility flag, not a reviewed merge-recovery direction.
|
|
544
|
+
await requireNoMergeJournal(config);
|
|
545
|
+
const state = await readStateForConfig(config);
|
|
546
|
+
validateMutation();
|
|
547
|
+
requireResolvedDirectionalProgress(state, options, false);
|
|
548
|
+
const decoded = await backend.readSnapshot(target, options.signal);
|
|
549
|
+
validateMutation();
|
|
550
|
+
validatePortableSnapshot(decoded);
|
|
551
|
+
if (!config.ignorePolicy)
|
|
552
|
+
requireLegacyTransferPolicy(decoded);
|
|
553
|
+
if (config.ignorePolicy && expectedSelection?.snapshotId && decoded.id !== expectedSelection.snapshotId)
|
|
554
|
+
throw new Error("Historical snapshot changed while history was open; reopen history and retry.");
|
|
555
|
+
if (!sameLocalFields(decoded.localFields, config.localFields))
|
|
556
|
+
throw new Error("Rollback requires the historical snapshot local-field policy to match the configured rules. Review push --force from current local bytes to migrate policy first; choose matching history afterward.");
|
|
557
|
+
const snapshotOptions = await resolvedSnapshotOptionsForContext(ctx, config, options.signal);
|
|
558
|
+
validateMutation();
|
|
559
|
+
const validateIgnorePolicy = ignorePolicyValidator({ ...snapshotOptions, validateMutation });
|
|
560
|
+
const selected = filterSnapshotForConfigPolicy(config.ignorePolicy || syncSessionsSelected(config) ? decoded : snapshotWithoutSessions(decoded), config, snapshotOptions);
|
|
561
|
+
const remote = portableSnapshot(regenerateSnapshotIdentity(selected), config.localFields);
|
|
562
|
+
const local = await createSnapshot(config.snapshotIdentity, snapshotOptions);
|
|
563
|
+
const expectedHead = await backend.readHead(options.signal);
|
|
564
|
+
const currentRemote = expectedHead
|
|
565
|
+
? await readSnapshotForHead(backend, expectedHead, options.signal, config)
|
|
566
|
+
: undefined;
|
|
567
|
+
validateMutation();
|
|
568
|
+
if (config.ignorePolicy && currentRemote)
|
|
569
|
+
requireCompatibleRemoteSelection(config, currentRemote);
|
|
570
|
+
if (!(await confirmFieldMigration(ctx, config, state, currentRemote, true, options.signal)))
|
|
571
|
+
return;
|
|
572
|
+
validateMutation();
|
|
573
|
+
const physical = overlayLocalFields(remote, local, config.localFields);
|
|
574
|
+
if (config.scope === "agent-directory")
|
|
575
|
+
requireStableMergeSessionRoot(local, physical, config.scope);
|
|
576
|
+
const upload = config.ignorePolicy
|
|
577
|
+
? remote
|
|
578
|
+
: await snapshotForUpload(backend, config, remote, expectedHead, currentRemote, snapshotOptions);
|
|
579
|
+
if (config.scope === "agent-directory")
|
|
580
|
+
validatePortableSnapshot(upload);
|
|
581
|
+
const caseCleanup = options.yes ? [] : await inspectCaseCleanup(physical, snapshotOptions);
|
|
582
|
+
validateMutation();
|
|
583
|
+
const reviewedProtectedPaths = protectedSessionPaths(ctx, snapshotOptions.sessionDir);
|
|
584
|
+
if (!options.yes) {
|
|
585
|
+
const title = snapshotIncludesSessions(remote) ? "Rollback pi settings and sessions?" : "Rollback pi settings?";
|
|
586
|
+
const summary = formatRollbackSummary(config, backend.destination, local, physical, target, reviewedProtectedPaths, caseCleanup.map((item) => item.path));
|
|
587
|
+
const confirmed = config.ignorePolicy
|
|
588
|
+
? await confirmTransferReview(ctx, title, `Historical files are projected through this device's current ignore rules. Historical rules are not adopted. Retained history is not erased.\n\n${summary}\n\nRemote publication:\n${formatPublicationPreview(currentRemote, upload)}`, options.signal, validateMutation)
|
|
589
|
+
: await ctx.ui.confirm(title, summary, { signal: options.signal });
|
|
590
|
+
validateMutation();
|
|
591
|
+
if (!confirmed) {
|
|
592
|
+
ctx.ui.notify("Rollback cancelled.", "info");
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
validateMutation();
|
|
597
|
+
const currentLocal = await createSnapshot(config.snapshotIdentity, snapshotOptions);
|
|
598
|
+
if (!sameHashes(fileHashMap(currentLocal), fileHashMap(local)))
|
|
599
|
+
throw new Error("Local bytes changed during rollback review.");
|
|
600
|
+
if (syncCheckConfigFingerprint(config) !== syncCheckConfigFingerprint(await loadConfig(options.setup)))
|
|
601
|
+
throw new Error("Settings changed during rollback review.");
|
|
602
|
+
if (!sameRemoteHead(backend, expectedHead, await backend.readHead(options.signal)))
|
|
603
|
+
throw new Error("Remote changed during rollback review.");
|
|
604
|
+
validateMutation();
|
|
605
|
+
throwIfAborted(options.signal);
|
|
606
|
+
const backup = await backupLocal(config.snapshotIdentity, snapshotOptions, options.signal);
|
|
607
|
+
const applySessionDir = await sessionDirForApply(ctx, config.scope ? physical : remote, snapshotOptions);
|
|
608
|
+
const currentState = await readStateForConfig(config);
|
|
609
|
+
if (!options.yes && syncStateFingerprint(currentState) !== syncStateFingerprint(state))
|
|
610
|
+
throw new Error("Baseline changed during rollback review.");
|
|
611
|
+
requireResolvedDirectionalProgress(currentState, options, false);
|
|
612
|
+
if (!options.yes)
|
|
613
|
+
await revalidateCaseCleanup(caseCleanup, physical, snapshotOptions);
|
|
614
|
+
if (config.scope && applySessionDir !== (await effectiveSessionRoot(ctx, config, options.signal)))
|
|
615
|
+
throw new Error("Pi session storage changed during rollback review.");
|
|
616
|
+
validateMutation();
|
|
617
|
+
if (syncCheckConfigFingerprint(config) !== syncCheckConfigFingerprint(await loadConfig(options.setup)))
|
|
618
|
+
throw new Error("Settings changed during rollback review.");
|
|
619
|
+
validateMutation();
|
|
620
|
+
if (validateIgnorePolicy) {
|
|
621
|
+
if (!sameRemoteHead(backend, expectedHead, await backend.readHead(options.signal)))
|
|
622
|
+
throw new Error("Remote changed during rollback review.");
|
|
623
|
+
await validateIgnorePolicy();
|
|
624
|
+
}
|
|
625
|
+
const protectedPaths = protectedSessionPaths(ctx, snapshotOptions.sessionDir);
|
|
626
|
+
if (validateIgnorePolicy && !samePaths(protectedPaths, reviewedProtectedPaths))
|
|
627
|
+
throw new Error("Live session protection changed during rollback review; reopen the review.");
|
|
628
|
+
options.onCommit?.();
|
|
629
|
+
const lastFileHashes = await applySnapshot(physical, protectedPaths, {
|
|
630
|
+
...snapshotOptions,
|
|
631
|
+
sessionDir: applySessionDir,
|
|
632
|
+
validateMutation,
|
|
633
|
+
...(config.scope === "agent-directory" ? { reviewedLocal: local } : {}),
|
|
634
|
+
expectedFileHashes: config.localFields?.length
|
|
635
|
+
? { "settings.json": fileHashMap(local)["settings.json"] ?? null }
|
|
636
|
+
: undefined,
|
|
637
|
+
});
|
|
638
|
+
// The local transaction is retired; finish publication despite caller cancellation.
|
|
639
|
+
validateCommittedOwner();
|
|
640
|
+
let result;
|
|
641
|
+
try {
|
|
642
|
+
const signal = AbortSignal.timeout(POST_LOCAL_COMMIT_TIMEOUT_MS);
|
|
643
|
+
const validateIgnorePolicy = ignorePolicyValidator({
|
|
644
|
+
...snapshotOptions,
|
|
645
|
+
signal,
|
|
646
|
+
validateMutation: validateCommittedOwner,
|
|
647
|
+
});
|
|
648
|
+
result = await backend.publishSnapshot(upload, expectedRemoteHead(expectedHead), {
|
|
649
|
+
signal,
|
|
650
|
+
...(validateIgnorePolicy ? { validateIgnorePolicy } : {}),
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
catch (error) {
|
|
654
|
+
throw new RollbackPublicationError(backup, error);
|
|
655
|
+
}
|
|
656
|
+
try {
|
|
657
|
+
await writeStateForConfig(config, {
|
|
658
|
+
version: VERSION,
|
|
659
|
+
profile: config.snapshotIdentity,
|
|
660
|
+
lastAppliedSnapshot: result.head.snapshotId,
|
|
661
|
+
lastRemoteRevision: result.head.revision,
|
|
662
|
+
lastFileHashes: config.localFields?.length
|
|
663
|
+
? { ...lastFileHashes, "settings.json": fileHashMap(remote)["settings.json"] }
|
|
664
|
+
: lastFileHashes,
|
|
665
|
+
...acceptedSelection(config),
|
|
666
|
+
...(config.localFields !== undefined ? { localFields: config.localFields } : {}),
|
|
667
|
+
}, remote, validateCommittedOwner);
|
|
668
|
+
}
|
|
669
|
+
catch (error) {
|
|
670
|
+
throw new PublicationStatePersistenceError(result.head, error, backup);
|
|
671
|
+
}
|
|
672
|
+
await retireMergeJournal(config);
|
|
673
|
+
await pruneMergeBaselines(config, await readStateForConfig(config), validateCommittedOwner);
|
|
674
|
+
validateCommittedOwner();
|
|
675
|
+
if (options.signal?.aborted)
|
|
676
|
+
return;
|
|
677
|
+
ctx.ui.notify([
|
|
678
|
+
`Rolled back sync setup “${config.setupName}” to ${target}; latest: ${result.head.snapshotId}. Backup: ${backup}`,
|
|
679
|
+
...result.warnings,
|
|
680
|
+
]
|
|
681
|
+
.filter(Boolean)
|
|
682
|
+
.join("\n"), result.warnings.length > 0 ? "warning" : "info");
|
|
683
|
+
await maybeReload(ctx, options.signal, validateMutation);
|
|
684
|
+
}
|
|
685
|
+
async function maybeReload(ctx, signal, validateMutation = captureMutationOwner(ctx, signal)) {
|
|
686
|
+
if (signal?.aborted || typeof ctx.reload !== "function")
|
|
687
|
+
return;
|
|
688
|
+
validateMutation();
|
|
689
|
+
if (ctx.hasUI &&
|
|
690
|
+
(await ctx.ui.confirm("Reload Pi resources now?", "This reloads extensions, skills, prompts, themes, and context files."))) {
|
|
691
|
+
if (signal?.aborted)
|
|
692
|
+
return;
|
|
693
|
+
validateMutation();
|
|
694
|
+
await ctx.reload();
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
async function snapshotForUpload(backend, config, local, head, remote, options) {
|
|
698
|
+
if (config.ignorePolicy)
|
|
699
|
+
return filterSnapshotForConfigPolicy(local, config, { ...options, regenerateId: true });
|
|
700
|
+
if (!head)
|
|
701
|
+
return local;
|
|
702
|
+
const snapshot = remote ?? (await readSnapshotForHead(backend, head, options.signal, config));
|
|
703
|
+
const remoteScoped = snapshot.selection?.version === 3;
|
|
704
|
+
if (remoteScoped !== (config.scope === "agent-directory")) {
|
|
705
|
+
throw new Error("Converting an existing remote between included paths and agent-directory scope is not supported. Use a separate storage location.");
|
|
706
|
+
}
|
|
707
|
+
return mergeRemotePreservedFiles(local, snapshot, config, options);
|
|
708
|
+
}
|
|
709
|
+
async function confirmPush(ctx, options, config, backend, local, upload, head, remote, validateMutation, title = snapshotIncludesSessions(upload) ? "Push pi settings and sessions?" : "Push pi settings?") {
|
|
710
|
+
validateMutation();
|
|
711
|
+
if (options.yes)
|
|
712
|
+
return true;
|
|
713
|
+
const summary = formatPushSummary(config, backend.destination, upload, head, countPreservedRemoteFiles(local, upload), remote);
|
|
714
|
+
const comparison = config.ignorePolicy && remote
|
|
715
|
+
? inspectRemoteSelection(config.include, remote, config.exclude, config).ignorePolicyComparison
|
|
716
|
+
: undefined;
|
|
717
|
+
const confirmed = await confirmTransferReview(ctx, title, comparison && comparison !== "match"
|
|
718
|
+
? `${formatIgnorePolicyComparison(comparison)}\nOnly files selected by this device's rules are published. Remote rules are not adopted.\n\n${summary}`
|
|
719
|
+
: summary, options.signal, validateMutation);
|
|
720
|
+
throwIfAborted(options.signal);
|
|
721
|
+
if (confirmed)
|
|
722
|
+
return true;
|
|
723
|
+
setSyncStatus(ctx, undefined);
|
|
724
|
+
ctx.ui.notify("Push cancelled.", "info");
|
|
725
|
+
return false;
|
|
726
|
+
}
|
|
727
|
+
function matchesInitialHead(initial, backend, current) {
|
|
728
|
+
return sameRemoteHead(backend, initial.head, current);
|
|
729
|
+
}
|
|
730
|
+
function samePaths(left, right) {
|
|
731
|
+
return left.size === right.size && [...left].every((item) => right.has(item));
|
|
732
|
+
}
|
|
733
|
+
export { backupLocal } from "./sync-local.js";
|