@narumitw/pi-sync 0.61.0 → 0.63.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 +46 -25
- package/dist/chunks/{chunk-277VHM2P.ts → chunk-27F5W7DX.ts} +7 -3
- package/dist/chunks/chunk-27F5W7DX.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-CKUGCBHP.ts +114 -0
- package/dist/chunks/chunk-CKUGCBHP.ts.map +7 -0
- package/dist/chunks/chunk-EJDDRS6O.ts +17 -0
- package/dist/chunks/chunk-EJDDRS6O.ts.map +7 -0
- package/dist/chunks/{chunk-JVFCVPPD.ts → chunk-EXDWEFIJ.ts} +87 -147
- package/dist/chunks/chunk-EXDWEFIJ.ts.map +7 -0
- package/dist/chunks/{chunk-4SR3ZYHA.ts → chunk-GELYN4UC.ts} +2 -2
- package/dist/chunks/{chunk-2ZGV5KNC.ts → chunk-HSCAFOT5.ts} +15 -12
- package/dist/chunks/chunk-HSCAFOT5.ts.map +7 -0
- package/dist/chunks/{chunk-YQSFJLJ3.ts → chunk-IBXEM35O.ts} +4 -3
- package/dist/chunks/{chunk-2JHAN3ZO.ts → chunk-JREGWM2B.ts} +3 -3
- package/dist/chunks/chunk-MANNB4WZ.ts +36 -0
- package/dist/chunks/chunk-MANNB4WZ.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-ZVGRZD4C.ts → chunk-R3SAMXB6.ts} +2 -2
- package/dist/chunks/{chunk-4KTJLJSJ.ts → chunk-S6FUUWV5.ts} +148 -21
- package/dist/chunks/chunk-S6FUUWV5.ts.map +7 -0
- package/dist/chunks/{chunk-PJMM75W5.ts → chunk-SXCH4Q5O.ts} +41 -23
- package/dist/chunks/chunk-SXCH4Q5O.ts.map +7 -0
- package/dist/chunks/{chunk-RNIEVDTR.ts → chunk-T3LABNHF.ts} +2 -2
- package/dist/chunks/{chunk-E3YLRLJM.ts → chunk-UGS6RYDZ.ts} +14 -12
- package/dist/chunks/chunk-UGS6RYDZ.ts.map +7 -0
- package/dist/chunks/{chunk-S3R3W3KF.ts → chunk-UMPA5S7X.ts} +2 -2
- package/dist/chunks/{chunk-EMVZL4PH.ts → chunk-V76KCWHO.ts} +7 -5
- package/dist/chunks/{chunk-EMVZL4PH.ts.map → chunk-V76KCWHO.ts.map} +1 -1
- package/dist/chunks/{chunk-S7F4FOAS.ts → chunk-VQ47JBLF.ts} +5 -5
- package/dist/chunks/{chunk-WP2M67XZ.ts → chunk-WBIOSK76.ts} +2 -2
- package/dist/chunks/chunk-WFBHWYI6.ts +18 -0
- package/dist/chunks/chunk-WFBHWYI6.ts.map +7 -0
- package/dist/chunks/{chunk-HEB6YT64.ts → chunk-ZO52JM4H.ts} +2 -2
- package/dist/chunks/{command-handler-K4XJOGYC.ts → command-handler-VINMQ7ZM.ts} +26 -43
- package/dist/chunks/command-handler-VINMQ7ZM.ts.map +7 -0
- package/dist/chunks/{conflict-review-IGKY2TOJ.ts → conflict-review-PCDFRIVB.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-MGGVOKM7.ts → file-selection-KID23GAD.ts} +21 -14
- package/dist/chunks/file-selection-KID23GAD.ts.map +7 -0
- package/dist/chunks/manager-result-dispatcher-GDB74IOP.ts +20 -0
- package/dist/chunks/{manager-ui-KYQ5AZJS.ts → manager-ui-YHDECYKI.ts} +454 -167
- package/dist/chunks/manager-ui-YHDECYKI.ts.map +7 -0
- package/dist/chunks/remote-selection-ui-GPITNEBF.ts +19 -0
- package/dist/chunks/{setup-switch-D6K6PBPC.ts → setup-switch-L54X5U5I.ts} +7 -7
- package/dist/chunks/{setup-wizard-4DYUDHJR.ts → setup-wizard-YO4MCPUF.ts} +15 -11
- package/dist/chunks/{setup-wizard-4DYUDHJR.ts.map → setup-wizard-YO4MCPUF.ts.map} +1 -1
- 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-J3CRBORL.ts → sync-inspection-H2WX5SUT.ts} +5 -5
- package/dist/chunks/{sync-operations-BVWYYKH3.ts → sync-operations-2MZAYHL2.ts} +13 -9
- package/dist/chunks/sync-operations-2MZAYHL2.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 +383 -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 +746 -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 +252 -0
- package/dist/daemon/dist/engine/ignore/ignore-migration-prompt.js +139 -0
- package/dist/daemon/dist/engine/ignore/ignore-settings.js +393 -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 +344 -0
- package/dist/daemon/dist/engine/settings/settings-management.js +199 -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 +165 -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 +296 -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 +855 -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 +85 -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 +139 -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 +538 -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-acceptance.js +29 -0
- package/dist/daemon/dist/engine/sync/merge-apply.js +532 -0
- package/dist/daemon/dist/engine/sync/merge-journal.js +314 -0
- package/dist/daemon/dist/engine/sync/merge-transfer-error.js +64 -0
- package/dist/daemon/dist/engine/sync/merged-sync.js +666 -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 +119 -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 +47 -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 +754 -0
- package/dist/daemon/dist/engine/sync/sync-operations.js +3 -0
- package/dist/daemon/dist/engine/sync/sync-policy.js +646 -0
- package/dist/daemon/dist/engine/sync/sync-queries.js +212 -0
- package/dist/daemon/dist/engine/sync/sync-state.js +124 -0
- package/dist/daemon/dist/engine/sync/text-merge.js +124 -0
- package/dist/daemon/dist/engine/sync/transfer-freshness.js +82 -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 +441 -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 +324 -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 +994 -0
- package/dist/daemon/dist/service-host.js +175 -0
- package/dist/daemon/dist/upgrade-repair.js +55 -0
- package/dist/daemon/package.json +3 -0
- package/dist/index.ts +40 -37
- package/dist/index.ts.map +4 -4
- package/dist/package.json +6 -0
- package/docs/daemon-migration.md +27 -16
- package/package.json +9 -3
- package/skills/configure-pi-sync/SKILL.md +24 -46
- package/skills/configure-pi-sync/references/configuration.md +62 -22
- package/src/commands/command-execution.ts +13 -9
- package/src/commands/command-types.ts +1 -0
- package/src/daemon/pi-client.ts +4 -2
- package/src/settings/config.ts +2 -0
- package/src/sync/automatic-sync.ts +9 -2
- package/src/sync/setup-switch.ts +38 -15
- package/src/sync/startup-check.ts +7 -4
- package/src/sync/sync-operations.ts +18 -10
- package/src/ui/excluded-paths-ui.ts +6 -3
- package/src/ui/file-selection.ts +7 -2
- package/src/ui/ignore-file-guidance.ts +7 -0
- package/src/ui/ignore-file-ui.ts +97 -0
- package/src/ui/ignore-migration-prompt.ts +65 -0
- package/src/ui/manager-state.ts +40 -14
- package/src/ui/manager-ui.ts +41 -19
- package/src/ui/remote-selection-ui.ts +88 -28
- package/src/ui/settings-review.ts +26 -0
- package/src/ui/settings-ui.ts +378 -224
- package/src/ui/setup/setup-actions.ts +16 -4
- package/src/ui/setup/setup-prompts.ts +55 -9
- package/src/ui/setup/setup-switcher.ts +24 -11
- package/src/ui/storage-connections-ui.ts +50 -20
- package/src/ui/sync-setups-ui.ts +65 -30
- package/dist/chunks/chunk-277VHM2P.ts.map +0 -7
- package/dist/chunks/chunk-2ZGV5KNC.ts.map +0 -7
- package/dist/chunks/chunk-4KTJLJSJ.ts.map +0 -7
- package/dist/chunks/chunk-E3YLRLJM.ts.map +0 -7
- package/dist/chunks/chunk-ECYCNZOE.ts +0 -12
- package/dist/chunks/chunk-ECYCNZOE.ts.map +0 -7
- package/dist/chunks/chunk-JVFCVPPD.ts.map +0 -7
- package/dist/chunks/chunk-PJMM75W5.ts.map +0 -7
- package/dist/chunks/command-handler-K4XJOGYC.ts.map +0 -7
- package/dist/chunks/file-selection-MGGVOKM7.ts.map +0 -7
- package/dist/chunks/manager-result-dispatcher-4VJVDEUD.ts +0 -19
- package/dist/chunks/manager-ui-KYQ5AZJS.ts.map +0 -7
- package/dist/chunks/remote-selection-ui-W3KOZM3W.ts +0 -18
- package/dist/chunks/sync-operations-BVWYYKH3.ts.map +0 -7
- /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-4SR3ZYHA.ts.map → chunk-GELYN4UC.ts.map} +0 -0
- /package/dist/chunks/{chunk-YQSFJLJ3.ts.map → chunk-IBXEM35O.ts.map} +0 -0
- /package/dist/chunks/{chunk-2JHAN3ZO.ts.map → chunk-JREGWM2B.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-ZVGRZD4C.ts.map → chunk-R3SAMXB6.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-S7F4FOAS.ts.map → chunk-VQ47JBLF.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-IGKY2TOJ.ts.map → conflict-review-PCDFRIVB.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-4VJVDEUD.ts.map → manager-result-dispatcher-GDB74IOP.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-W3KOZM3W.ts.map → remote-selection-ui-GPITNEBF.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-D6K6PBPC.ts.map → setup-switch-L54X5U5I.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-J3CRBORL.ts.map → sync-inspection-H2WX5SUT.ts.map} +0 -0
- /package/dist/chunks/{sync-state-2LMIXJ2C.ts.map → sync-state-QIT64TKV.ts.map} +0 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { documentFingerprint } from "../../document.js";
|
|
4
|
+
import { backendIdentityCoordinates } from "../backends/backend-identity.js";
|
|
5
|
+
import { normalizeGitBranch, normalizeGitDirectory, normalizeGitRemote } from "../backends/git/git-config.js";
|
|
6
|
+
import { normalizeWebDavPath, normalizeWebDavUrl } from "../backends/webdav/webdav-config.js";
|
|
7
|
+
import { engineHost, getEngineRoot } from "../host.js";
|
|
8
|
+
import { compileEffectiveIgnorePolicy } from "../ignore/effective-ignore-policy.js";
|
|
9
|
+
import { DEFAULT_IGNORE_FILENAME, readIgnoreSource, validateIgnoreFilename } from "../ignore/ignore-source.js";
|
|
10
|
+
import { normalizeSyncExclude } from "../sync/exclude-policy.js";
|
|
11
|
+
import { normalizeLocalFields } from "../sync/local-field-policy.js";
|
|
12
|
+
import { localIgnorePolicyKey, normalizeDirectoryRules, normalizeSyncInclude, syncDirectoryPolicyKey, syncSessionsSelected, } from "../sync/sync-policy.js";
|
|
13
|
+
import { safeTerminalText } from "../ui/terminal-text.js";
|
|
14
|
+
import { localConfigPath, readActiveLocalConfigDocumentForRepair, withLockedLocalConfigDocument, } from "./config-file.js";
|
|
15
|
+
import { readLocalConfigDocument, requireSettings } from "./settings-store.js";
|
|
16
|
+
import { DEFAULT_ON_SWITCH, isCloudflareR2Endpoint, normalizeS3Bucket, normalizeS3Endpoint, normalizeStoragePath, optionalString, ownObject, requiredString, validateConfigName, validateSettingsDocument, } from "./settings-validation.js";
|
|
17
|
+
export async function loadConfig(setupName, signal) {
|
|
18
|
+
signal?.throwIfAborted();
|
|
19
|
+
const document = await readLocalConfigDocument();
|
|
20
|
+
if (!document)
|
|
21
|
+
throw new Error(`Missing pi-sync settings. Open /sync and choose Set up sync, or create ${localConfigPath()}.`);
|
|
22
|
+
return operationalConfig(document, setupName, signal);
|
|
23
|
+
}
|
|
24
|
+
/** A background freshness read must never trigger legacy-file publication. */
|
|
25
|
+
export async function loadConfigForCheck(setupName, signal) {
|
|
26
|
+
signal?.throwIfAborted();
|
|
27
|
+
return operationalConfig(await readActiveLocalConfigDocumentForRepair(), setupName, signal);
|
|
28
|
+
}
|
|
29
|
+
async function operationalConfig(document, setupName, signal) {
|
|
30
|
+
signal?.throwIfAborted();
|
|
31
|
+
const config = configFromSettings(settingsFromCheckDocument(document), setupName);
|
|
32
|
+
if (!config.reservedIgnoreNames)
|
|
33
|
+
return config;
|
|
34
|
+
if (engineHost().ignoreFileOperationsAvailable === false)
|
|
35
|
+
return requireLegacyOperationConfig(config);
|
|
36
|
+
return resolveOperationPolicy(config, setupName, signal, document);
|
|
37
|
+
}
|
|
38
|
+
export async function loadSettingsConfig(setupName) {
|
|
39
|
+
return configFromSettings(await readSettingsForCheck(), setupName);
|
|
40
|
+
}
|
|
41
|
+
async function readSettingsForCheck() {
|
|
42
|
+
return settingsFromCheckDocument(await readActiveLocalConfigDocumentForRepair());
|
|
43
|
+
}
|
|
44
|
+
function settingsFromCheckDocument(document) {
|
|
45
|
+
if (!document)
|
|
46
|
+
throw new Error(`Missing pi-sync settings: ${localConfigPath()}`);
|
|
47
|
+
return validateSettingsDocument(document.parsed);
|
|
48
|
+
}
|
|
49
|
+
export function requireLegacyOperationConfig(config) {
|
|
50
|
+
if (config.pathPolicy === "ignore-file" || config.ignorePolicy || config.reservedIgnoreNames !== undefined) {
|
|
51
|
+
throw new Error("This Pi Sync operation does not yet support settings with ignore-file policies.");
|
|
52
|
+
}
|
|
53
|
+
return config;
|
|
54
|
+
}
|
|
55
|
+
export async function resolveIgnoreConfig(settings, setupName, signal) {
|
|
56
|
+
signal?.throwIfAborted();
|
|
57
|
+
return resolveOperationPolicy(configFromSettings(validateSettingsDocument(settings), setupName), setupName, signal);
|
|
58
|
+
}
|
|
59
|
+
function settingsDocumentFingerprint(document) {
|
|
60
|
+
return documentFingerprint(document && { bytes: document.bytes.toString("base64"), identity: document.identity });
|
|
61
|
+
}
|
|
62
|
+
async function resolveOperationPolicy(config, setupName, signal, original) {
|
|
63
|
+
if (!config.reservedIgnoreNames)
|
|
64
|
+
return config;
|
|
65
|
+
const root = getEngineRoot();
|
|
66
|
+
const validateRoot = () => {
|
|
67
|
+
signal?.throwIfAborted();
|
|
68
|
+
if (root !== getEngineRoot())
|
|
69
|
+
throw new Error("The Pi agent directory changed; reopen the review before continuing.");
|
|
70
|
+
};
|
|
71
|
+
const configDocumentFingerprint = original && settingsDocumentFingerprint(original);
|
|
72
|
+
const settingsFingerprint = syncCheckConfigFingerprint(config);
|
|
73
|
+
const validateSettings = (document) => {
|
|
74
|
+
validateRoot();
|
|
75
|
+
if ((original &&
|
|
76
|
+
(document?.path !== original.path || settingsDocumentFingerprint(document) !== configDocumentFingerprint)) ||
|
|
77
|
+
settingsFingerprint !==
|
|
78
|
+
syncCheckConfigFingerprint(configFromSettings(settingsFromCheckDocument(document), setupName))) {
|
|
79
|
+
throw new Error("Pi Sync settings changed; reopen the review before continuing.");
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const source = config.pathPolicy === "ignore-file" ? await readIgnoreSource(root, config.ignoreFile, signal) : undefined;
|
|
83
|
+
validateRoot();
|
|
84
|
+
if (original && source && !source.present) {
|
|
85
|
+
throw new Error(`Ignore file is missing: ${safeTerminalText(path.join(root, source.filename))}. Create it and reopen Pi Sync; starter rules are only a preview.`);
|
|
86
|
+
}
|
|
87
|
+
if (original && source)
|
|
88
|
+
validateSettings(await readActiveLocalConfigDocumentForRepair());
|
|
89
|
+
return {
|
|
90
|
+
...config,
|
|
91
|
+
...(configDocumentFingerprint ? { configDocumentFingerprint } : {}),
|
|
92
|
+
...(source ? { ignorePolicy: compileEffectiveIgnorePolicy(source, ignorePolicyInput(config)) } : {}),
|
|
93
|
+
...(source?.identity ? { ignoreSourceIdentity: source.identity } : {}),
|
|
94
|
+
validateIgnorePolicy: async () => {
|
|
95
|
+
validateRoot();
|
|
96
|
+
await withLockedLocalConfigDocument(async (document, recheck) => {
|
|
97
|
+
validateSettings(document);
|
|
98
|
+
if (source) {
|
|
99
|
+
const current = await readIgnoreSource(root, source.filename, signal);
|
|
100
|
+
validateRoot();
|
|
101
|
+
recheck();
|
|
102
|
+
if (current.sourceDigest !== source.sourceDigest || current.identity !== source.identity) {
|
|
103
|
+
throw new Error("Pi Sync ignore policy changed; reopen the review before continuing.");
|
|
104
|
+
}
|
|
105
|
+
if (!current.present) {
|
|
106
|
+
throw new Error(`Ignore file "${source.filename}" is missing; starter rules can only be used for a preview.`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
recheck();
|
|
111
|
+
}
|
|
112
|
+
}, signal, true);
|
|
113
|
+
validateRoot();
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function ignorePolicyInput(config) {
|
|
118
|
+
return {
|
|
119
|
+
filename: config.ignoreFile,
|
|
120
|
+
sessions: config.include.includes("sessions"),
|
|
121
|
+
configuredFilenames: config.reservedIgnoreNames ?? [],
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export function configFromSettings(settings, setupName) {
|
|
125
|
+
const selectedName = setupName ?? settings.activeSyncSetup;
|
|
126
|
+
if (!selectedName)
|
|
127
|
+
throw new Error("No sync setups are configured.");
|
|
128
|
+
validateConfigName(selectedName, "sync setup");
|
|
129
|
+
const setup = ownObject(settings.syncSetups, selectedName);
|
|
130
|
+
if (!setup)
|
|
131
|
+
throw new Error(`Invalid pi-sync settings: sync setup “${selectedName}” was not found.`);
|
|
132
|
+
const connectionName = setup.storage.connection;
|
|
133
|
+
const connection = ownObject(settings.storageConnections, connectionName);
|
|
134
|
+
if (!connection) {
|
|
135
|
+
throw new Error(`Invalid pi-sync settings: sync setup “${selectedName}” references missing storage connection “${connectionName}”.`);
|
|
136
|
+
}
|
|
137
|
+
const ignoreNames = new Set();
|
|
138
|
+
for (const { sync } of Object.values(settings.syncSetups)) {
|
|
139
|
+
if (sync.pathPolicy === "ignore-file")
|
|
140
|
+
ignoreNames.add(validateIgnoreFilename(sync.ignoreFile ?? DEFAULT_IGNORE_FILENAME).toLowerCase());
|
|
141
|
+
}
|
|
142
|
+
if (ignoreNames.size > 0)
|
|
143
|
+
ignoreNames.add(DEFAULT_IGNORE_FILENAME);
|
|
144
|
+
return {
|
|
145
|
+
...resolveSyncConfig(selectedName, setup, connectionName, connection, settings.onSwitch, settings.skipSecretScan ?? false, settings.showStatus ?? true),
|
|
146
|
+
debug: settings.debug ?? false,
|
|
147
|
+
...(ignoreNames.size > 0 ? { reservedIgnoreNames: [...ignoreNames].sort() } : {}),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/** A validated setup-facing projection used by manager and settings UI. */
|
|
151
|
+
export async function loadPartialConfig(setupName) {
|
|
152
|
+
const config = configFromSettings(await requireSettings(), setupName);
|
|
153
|
+
return {
|
|
154
|
+
setupName: config.setupName,
|
|
155
|
+
...storageReviewFromConfig(config),
|
|
156
|
+
include: [...config.include],
|
|
157
|
+
...(config.scope === undefined ? {} : { scope: config.scope }),
|
|
158
|
+
...(config.pathPolicy === undefined ? {} : { pathPolicy: config.pathPolicy, ignoreFile: config.ignoreFile }),
|
|
159
|
+
...(config.exclude === undefined ? {} : { exclude: [...config.exclude] }),
|
|
160
|
+
...(config.reinclude === undefined ? {} : { reinclude: [...config.reinclude] }),
|
|
161
|
+
automatic: config.automatic,
|
|
162
|
+
automaticTransfer: config.automaticTransfer ?? false,
|
|
163
|
+
agentMode: config.agentMode ?? false,
|
|
164
|
+
continuous: config.continuous ?? false,
|
|
165
|
+
onSwitch: config.onSwitch,
|
|
166
|
+
showStatus: config.showStatus,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
export function syncSetupStorageReview(setupName, setup, connectionName, connection) {
|
|
170
|
+
return storageReviewFromConfig(resolveSyncConfig(setupName, setup, connectionName, connection, DEFAULT_ON_SWITCH, false, true));
|
|
171
|
+
}
|
|
172
|
+
export function syncSetupReviewIdentity(setupName, setup, connectionName, connection) {
|
|
173
|
+
return syncConfigReviewIdentity(resolveSyncConfig(setupName, setup, connectionName, connection, DEFAULT_ON_SWITCH, false, true));
|
|
174
|
+
}
|
|
175
|
+
export function syncConfigReviewIdentity(config) {
|
|
176
|
+
const localPolicy = localIgnorePolicyKey(config);
|
|
177
|
+
const directoryPolicy = config.pathPolicy === "ignore-file" && !config.ignorePolicy
|
|
178
|
+
? JSON.stringify([config.pathPolicy, config.ignoreFile])
|
|
179
|
+
: syncDirectoryPolicyKey(config);
|
|
180
|
+
return JSON.stringify([
|
|
181
|
+
config.setupName,
|
|
182
|
+
config.connectionName,
|
|
183
|
+
backendIdentityCoordinates(config),
|
|
184
|
+
config.include,
|
|
185
|
+
config.automatic,
|
|
186
|
+
config.automaticTransfer ?? false,
|
|
187
|
+
config.agentMode ?? false,
|
|
188
|
+
config.localFields,
|
|
189
|
+
config.mergeSettings ?? false,
|
|
190
|
+
config.mergeContent ?? false,
|
|
191
|
+
config.partialSync ?? false,
|
|
192
|
+
// Preserve existing Off identities and cached candidates across the upgrade.
|
|
193
|
+
...(config.continuous ? ["continuous"] : []),
|
|
194
|
+
...(directoryPolicy !== undefined
|
|
195
|
+
? [directoryPolicy]
|
|
196
|
+
: config.exclude === undefined
|
|
197
|
+
? []
|
|
198
|
+
: ["exclude", normalizeSyncExclude(config.exclude).map((rule) => rule.toLowerCase())]),
|
|
199
|
+
...(localPolicy ? [localPolicy] : []),
|
|
200
|
+
]);
|
|
201
|
+
}
|
|
202
|
+
export function syncConfigReviewFingerprint(config) {
|
|
203
|
+
return createHash("sha256").update(syncConfigReviewIdentity(config)).digest("hex");
|
|
204
|
+
}
|
|
205
|
+
/** Internal freshness token, including credentials; never display or persist it. */
|
|
206
|
+
export function syncCheckConfigFingerprint(config) {
|
|
207
|
+
return createHash("sha256")
|
|
208
|
+
.update(JSON.stringify({ ...config, showStatus: undefined, debug: undefined }))
|
|
209
|
+
.digest("hex");
|
|
210
|
+
}
|
|
211
|
+
export function syncSettingsConfigFingerprint(config) {
|
|
212
|
+
return syncCheckConfigFingerprint({
|
|
213
|
+
...config,
|
|
214
|
+
configDocumentFingerprint: undefined,
|
|
215
|
+
ignoreSourceIdentity: undefined,
|
|
216
|
+
ignorePolicy: undefined,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
function storageReviewFromConfig(config) {
|
|
220
|
+
return {
|
|
221
|
+
connectionName: config.connectionName,
|
|
222
|
+
storageKind: config.backend.type,
|
|
223
|
+
storagePath: config.storagePath,
|
|
224
|
+
...(config.backend.type === "s3"
|
|
225
|
+
? { bucket: config.backend.destination.bucket }
|
|
226
|
+
: config.backend.type === "git"
|
|
227
|
+
? { branch: config.backend.destination.branch }
|
|
228
|
+
: {}),
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function resolveSyncConfig(setupName, setup, connectionName, connection, onSwitch, skipSecretScan, showStatus) {
|
|
232
|
+
const storagePath = normalizeStoragePath(setup.storage.path);
|
|
233
|
+
const namespace = storagePath === "./" ? "root" : storagePath.slice(storagePath.lastIndexOf("/") + 1);
|
|
234
|
+
const policy = setup.sync;
|
|
235
|
+
const selection = policy.scope === "agent-directory"
|
|
236
|
+
? {
|
|
237
|
+
scope: policy.scope,
|
|
238
|
+
include: policy.sessions ? ["sessions"] : [],
|
|
239
|
+
...(policy.pathPolicy === "ignore-file"
|
|
240
|
+
? {
|
|
241
|
+
pathPolicy: policy.pathPolicy,
|
|
242
|
+
ignoreFile: validateIgnoreFilename(policy.ignoreFile ?? DEFAULT_IGNORE_FILENAME),
|
|
243
|
+
}
|
|
244
|
+
: {}),
|
|
245
|
+
...(policy.exclude === undefined ? {} : { exclude: normalizeDirectoryRules(policy.exclude) }),
|
|
246
|
+
...(policy.reinclude === undefined ? {} : { reinclude: normalizeDirectoryRules(policy.reinclude) }),
|
|
247
|
+
}
|
|
248
|
+
: {
|
|
249
|
+
include: normalizeSyncInclude(policy.include),
|
|
250
|
+
...(policy.exclude === undefined ? {} : { exclude: normalizeSyncExclude(policy.exclude) }),
|
|
251
|
+
};
|
|
252
|
+
const common = {
|
|
253
|
+
setupName,
|
|
254
|
+
connectionName,
|
|
255
|
+
storagePath,
|
|
256
|
+
snapshotIdentity: namespace,
|
|
257
|
+
...selection,
|
|
258
|
+
automatic: setup.sync.automatic,
|
|
259
|
+
automaticTransfer: setup.sync.automaticTransfer ?? false,
|
|
260
|
+
agentMode: setup.sync.agentMode ?? false,
|
|
261
|
+
continuous: setup.sync.continuous ?? false,
|
|
262
|
+
localFields: setup.sync.localFields === undefined ? undefined : normalizeLocalFields(setup.sync.localFields),
|
|
263
|
+
mergeSettings: setup.sync.mergeSettings ?? false,
|
|
264
|
+
mergeContent: setup.sync.mergeContent ?? false,
|
|
265
|
+
partialSync: setup.sync.partialSync ?? false,
|
|
266
|
+
onSwitch,
|
|
267
|
+
skipSecretScan,
|
|
268
|
+
showStatus,
|
|
269
|
+
};
|
|
270
|
+
if (connection.type === "git") {
|
|
271
|
+
return {
|
|
272
|
+
...common,
|
|
273
|
+
backend: {
|
|
274
|
+
type: "git",
|
|
275
|
+
profile: { kind: "git", remote: normalizeGitRemote(connection.remote) },
|
|
276
|
+
destination: {
|
|
277
|
+
branch: normalizeGitBranch(setup.storage.branch),
|
|
278
|
+
directory: normalizeGitDirectory(storagePath),
|
|
279
|
+
namespace,
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
if (connection.type === "webdav") {
|
|
285
|
+
return {
|
|
286
|
+
...common,
|
|
287
|
+
backend: {
|
|
288
|
+
type: "webdav",
|
|
289
|
+
profile: {
|
|
290
|
+
kind: "webdav",
|
|
291
|
+
url: normalizeWebDavUrl(connection.url),
|
|
292
|
+
username: connection.credentials.username,
|
|
293
|
+
password: connection.credentials.password,
|
|
294
|
+
},
|
|
295
|
+
destination: { path: normalizeWebDavPath(storagePath), namespace },
|
|
296
|
+
},
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
...common,
|
|
301
|
+
backend: {
|
|
302
|
+
type: "s3",
|
|
303
|
+
profile: {
|
|
304
|
+
kind: isCloudflareR2Endpoint(connection.endpoint) ? "r2" : "s3-compatible",
|
|
305
|
+
endpoint: normalizeS3Endpoint(connection.endpoint),
|
|
306
|
+
region: requiredString(connection.region, "S3 region"),
|
|
307
|
+
accessKeyId: connection.credentials.accessKeyId,
|
|
308
|
+
secretAccessKey: connection.credentials.secretAccessKey,
|
|
309
|
+
sessionToken: optionalString(connection.credentials.sessionToken, "S3 session token"),
|
|
310
|
+
},
|
|
311
|
+
destination: {
|
|
312
|
+
bucket: normalizeS3Bucket(setup.storage.bucket),
|
|
313
|
+
prefix: storagePath,
|
|
314
|
+
namespace,
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
export function sessionTokenWarnings(config) {
|
|
320
|
+
if (!isCloudflareR2Endpoint(config.endpoint) || !config.sessionToken)
|
|
321
|
+
return [];
|
|
322
|
+
return [
|
|
323
|
+
"session token: configured for Cloudflare R2; if R2 rejects X-Amz-Security-Token, pi-sync retries once without it. R2 static access keys usually do not need a session token.",
|
|
324
|
+
];
|
|
325
|
+
}
|
|
326
|
+
export function syncSessionsWarnings(config) {
|
|
327
|
+
if (!syncSessionsSelected(config))
|
|
328
|
+
return [];
|
|
329
|
+
return [
|
|
330
|
+
"sessions: included; Pi session JSONL can contain prompts, tool output, file paths, images, and secrets. Sync sessions only to storage you trust.",
|
|
331
|
+
];
|
|
332
|
+
}
|
|
333
|
+
export function isEnabled(value, defaultValue) {
|
|
334
|
+
if (value === undefined)
|
|
335
|
+
return defaultValue;
|
|
336
|
+
if (typeof value === "boolean")
|
|
337
|
+
return value;
|
|
338
|
+
return !["0", "false", "no", "off"].includes(value.trim().toLowerCase());
|
|
339
|
+
}
|
|
340
|
+
export function isExplicitlyEnabled(value) {
|
|
341
|
+
if (typeof value === "boolean")
|
|
342
|
+
return value;
|
|
343
|
+
return ["1", "true", "yes", "on"].includes(value?.trim().toLowerCase() ?? "");
|
|
344
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
import { configFromSettings, syncCheckConfigFingerprint, syncSetupStorageReview, } from "./config.js";
|
|
3
|
+
import { localConfigPath } from "./config-file.js";
|
|
4
|
+
import { updateLocalConfig } from "./settings-store.js";
|
|
5
|
+
import { effectiveSyncSetupRemoteIdentity, validateConfigName } from "./settings-validation.js";
|
|
6
|
+
export class SyncSetupReviewChangedError extends Error {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "SyncSetupReviewChangedError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export async function saveNewV3Settings(input, signal) {
|
|
13
|
+
const { setupName, connectionName } = input;
|
|
14
|
+
validateConfigName(setupName, "sync setup");
|
|
15
|
+
validateConfigName(connectionName, "storage connection");
|
|
16
|
+
const connection = structuredClone(input.connection);
|
|
17
|
+
const setup = structuredClone(input.setup);
|
|
18
|
+
setup.storage.connection = connectionName;
|
|
19
|
+
return updateLocalConfig((current) => {
|
|
20
|
+
if (Object.keys(current.storageConnections).length || Object.keys(current.syncSetups).length) {
|
|
21
|
+
throw new Error(`Settings already exist: ${localConfigPath()}`);
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
...current,
|
|
25
|
+
version: setupSettingsVersion(current.version, setup),
|
|
26
|
+
activeSyncSetup: setupName,
|
|
27
|
+
storageConnections: { [connectionName]: connection },
|
|
28
|
+
syncSetups: { [setupName]: setup },
|
|
29
|
+
};
|
|
30
|
+
}, signal);
|
|
31
|
+
}
|
|
32
|
+
export async function addStorageConnection(name, connection, signal) {
|
|
33
|
+
validateConfigName(name, "storage connection");
|
|
34
|
+
await updateLocalConfig((settings) => {
|
|
35
|
+
if (Object.hasOwn(settings.storageConnections, name)) {
|
|
36
|
+
throw new Error(`Storage connection already exists: ${name}`);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
...settings,
|
|
40
|
+
storageConnections: {
|
|
41
|
+
...settings.storageConnections,
|
|
42
|
+
[name]: structuredClone(connection),
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}, signal);
|
|
46
|
+
}
|
|
47
|
+
export async function updateStorageConnection(name, update, expectedSetups, signal) {
|
|
48
|
+
validateConfigName(name, "storage connection");
|
|
49
|
+
await updateLocalConfig((settings) => {
|
|
50
|
+
const connection = settings.storageConnections[name];
|
|
51
|
+
if (!connection)
|
|
52
|
+
throw new Error(`Storage connection not found: ${name}`);
|
|
53
|
+
const currentSetups = referencingSetupNames(settings.syncSetups, name);
|
|
54
|
+
if (expectedSetups && !sameNames(currentSetups, expectedSetups)) {
|
|
55
|
+
throw new Error(`Storage connection “${name}” usage changed while it was open; reopen it and review the affected sync setups.`);
|
|
56
|
+
}
|
|
57
|
+
const nextConnection = update(structuredClone(connection));
|
|
58
|
+
const nextConnections = { ...settings.storageConnections, [name]: nextConnection };
|
|
59
|
+
assertUniqueLocations(settings.syncSetups, nextConnections);
|
|
60
|
+
return { ...settings, storageConnections: nextConnections };
|
|
61
|
+
}, signal);
|
|
62
|
+
}
|
|
63
|
+
export async function addSyncSetup(name, setup, signal, expectedConnection) {
|
|
64
|
+
validateConfigName(name, "sync setup");
|
|
65
|
+
await updateLocalConfig((settings) => {
|
|
66
|
+
if (Object.hasOwn(settings.syncSetups, name))
|
|
67
|
+
throw new Error(`Sync setup already exists: ${name}`);
|
|
68
|
+
if (!Object.hasOwn(settings.storageConnections, setup.storage.connection)) {
|
|
69
|
+
throw new Error(`Storage connection not found: ${setup.storage.connection}`);
|
|
70
|
+
}
|
|
71
|
+
if (expectedConnection &&
|
|
72
|
+
!isDeepStrictEqual(settings.storageConnections[setup.storage.connection], expectedConnection)) {
|
|
73
|
+
throw new SyncSetupReviewChangedError("Storage connection changed while the setup review was open; reopen it.");
|
|
74
|
+
}
|
|
75
|
+
const nextSetups = { ...settings.syncSetups, [name]: structuredClone(setup) };
|
|
76
|
+
assertUniqueLocations(nextSetups, settings.storageConnections);
|
|
77
|
+
return {
|
|
78
|
+
...settings,
|
|
79
|
+
version: setupSettingsVersion(settings.version, setup),
|
|
80
|
+
syncSetups: nextSetups,
|
|
81
|
+
...(settings.activeSyncSetup ? {} : { activeSyncSetup: name }),
|
|
82
|
+
};
|
|
83
|
+
}, signal);
|
|
84
|
+
}
|
|
85
|
+
export async function updateSyncSetup(name, update, options = {}) {
|
|
86
|
+
validateConfigName(name, "sync setup");
|
|
87
|
+
await updateLocalConfig((settings) => {
|
|
88
|
+
const setup = settings.syncSetups[name];
|
|
89
|
+
if (!setup)
|
|
90
|
+
throw new Error(`Sync setup not found: ${name}`);
|
|
91
|
+
if (options.expectedConfigFingerprint !== undefined &&
|
|
92
|
+
syncCheckConfigFingerprint(configFromSettings(settings, name)) !== options.expectedConfigFingerprint) {
|
|
93
|
+
throw new SyncSetupReviewChangedError(`Sync setup “${name}” changed while it was open; reopen it and review the current configuration.`);
|
|
94
|
+
}
|
|
95
|
+
if (options.expectedInclude && !sameNames(configFromSettings(settings, name).include, options.expectedInclude)) {
|
|
96
|
+
throw new SyncSetupReviewChangedError(`Sync setup “${name}” included content changed while it was open; reopen it and review the current selection.`);
|
|
97
|
+
}
|
|
98
|
+
if (options.expectedStorage) {
|
|
99
|
+
const connectionName = setup.storage.connection;
|
|
100
|
+
const connection = settings.storageConnections[connectionName];
|
|
101
|
+
if (!connection ||
|
|
102
|
+
!sameStorageReview(syncSetupStorageReview(name, setup, connectionName, connection), options.expectedStorage)) {
|
|
103
|
+
throw new SyncSetupReviewChangedError(`Sync setup “${name}” storage changed while it was open; reopen it and review the current storage location.`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (options.expectedConnection &&
|
|
107
|
+
!isDeepStrictEqual(settings.storageConnections[setup.storage.connection], options.expectedConnection)) {
|
|
108
|
+
throw new SyncSetupReviewChangedError("Storage connection changed while the setup review was open; reopen it.");
|
|
109
|
+
}
|
|
110
|
+
const nextSetup = update(structuredClone(setup));
|
|
111
|
+
if (!Object.hasOwn(settings.storageConnections, nextSetup.storage.connection)) {
|
|
112
|
+
throw new Error(`Storage connection not found: ${nextSetup.storage.connection}`);
|
|
113
|
+
}
|
|
114
|
+
const nextSetups = { ...settings.syncSetups, [name]: nextSetup };
|
|
115
|
+
assertUniqueLocations(nextSetups, settings.storageConnections);
|
|
116
|
+
return {
|
|
117
|
+
...settings,
|
|
118
|
+
version: setupSettingsVersion(settings.version, nextSetup, options.upgradeExclude),
|
|
119
|
+
syncSetups: nextSetups,
|
|
120
|
+
};
|
|
121
|
+
}, options.signal);
|
|
122
|
+
}
|
|
123
|
+
export async function removeSyncSetup(name, signal) {
|
|
124
|
+
validateConfigName(name, "sync setup");
|
|
125
|
+
let removedLastIgnoreSetup = false;
|
|
126
|
+
const saved = await updateLocalConfig((settings) => {
|
|
127
|
+
const setup = settings.syncSetups[name];
|
|
128
|
+
if (!Object.hasOwn(settings.syncSetups, name) || !setup)
|
|
129
|
+
throw new Error(`Sync setup not found: ${name}`);
|
|
130
|
+
const isCurrent = settings.activeSyncSetup === name;
|
|
131
|
+
if (isCurrent && Object.keys(settings.syncSetups).length > 1) {
|
|
132
|
+
throw new Error("Switch to another sync setup before removing the current setup.");
|
|
133
|
+
}
|
|
134
|
+
const syncSetups = { ...settings.syncSetups };
|
|
135
|
+
delete syncSetups[name];
|
|
136
|
+
removedLastIgnoreSetup =
|
|
137
|
+
setup.sync.pathPolicy === "ignore-file" &&
|
|
138
|
+
!Object.values(syncSetups).some((remaining) => remaining.sync.pathPolicy === "ignore-file");
|
|
139
|
+
const next = { ...settings, syncSetups };
|
|
140
|
+
if (isCurrent)
|
|
141
|
+
delete next.activeSyncSetup;
|
|
142
|
+
return next;
|
|
143
|
+
}, signal);
|
|
144
|
+
return { revertedToLegacyOnly: removedLastIgnoreSetup && saved.activeSyncSetup !== undefined };
|
|
145
|
+
}
|
|
146
|
+
export async function removeStorageConnection(name, signal) {
|
|
147
|
+
validateConfigName(name, "storage connection");
|
|
148
|
+
await updateLocalConfig((settings) => {
|
|
149
|
+
const referenced = referencingSetupNames(settings.syncSetups, name)[0];
|
|
150
|
+
if (referenced) {
|
|
151
|
+
throw new Error(`Storage connection “${name}” is used by sync setup “${referenced}”.`);
|
|
152
|
+
}
|
|
153
|
+
if (!Object.hasOwn(settings.storageConnections, name)) {
|
|
154
|
+
throw new Error(`Storage connection not found: ${name}`);
|
|
155
|
+
}
|
|
156
|
+
const storageConnections = { ...settings.storageConnections };
|
|
157
|
+
delete storageConnections[name];
|
|
158
|
+
return { ...settings, storageConnections };
|
|
159
|
+
}, signal);
|
|
160
|
+
}
|
|
161
|
+
function setupSettingsVersion(current, setup, upgradeExclude) {
|
|
162
|
+
if (setup.sync.pathPolicy === "ignore-file")
|
|
163
|
+
return 8;
|
|
164
|
+
if (current < 7 && setup.sync.scope === "agent-directory")
|
|
165
|
+
return 7;
|
|
166
|
+
if (current < 6 && upgradeExclude)
|
|
167
|
+
return 6;
|
|
168
|
+
return current;
|
|
169
|
+
}
|
|
170
|
+
function referencingSetupNames(setups, connection) {
|
|
171
|
+
return Object.entries(setups)
|
|
172
|
+
.filter(([, setup]) => setup.storage.connection === connection)
|
|
173
|
+
.map(([name]) => name)
|
|
174
|
+
.sort((left, right) => left.localeCompare(right));
|
|
175
|
+
}
|
|
176
|
+
function assertUniqueLocations(setups, connections) {
|
|
177
|
+
const identities = new Map();
|
|
178
|
+
for (const [name, setup] of Object.entries(setups)) {
|
|
179
|
+
const connection = connections[setup.storage.connection];
|
|
180
|
+
if (!connection)
|
|
181
|
+
throw new Error(`Storage connection not found: ${setup.storage.connection}`);
|
|
182
|
+
const identity = effectiveSyncSetupRemoteIdentity(setup, connection);
|
|
183
|
+
const previous = identities.get(identity);
|
|
184
|
+
if (previous) {
|
|
185
|
+
throw new Error(`Sync setup “${name}” duplicates the storage location of “${previous}”.`);
|
|
186
|
+
}
|
|
187
|
+
identities.set(identity, name);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function sameNames(left, right) {
|
|
191
|
+
return left.length === right.length && left.every((name, index) => name === right[index]);
|
|
192
|
+
}
|
|
193
|
+
function sameStorageReview(left, right) {
|
|
194
|
+
return (left.connectionName === right.connectionName &&
|
|
195
|
+
left.storageKind === right.storageKind &&
|
|
196
|
+
left.storagePath === right.storagePath &&
|
|
197
|
+
left.bucket === right.bucket &&
|
|
198
|
+
left.branch === right.branch);
|
|
199
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { localConfigPath, readMigratingLocalConfigDocument, updateLocalConfigDocument } from "./config-file.js";
|
|
2
|
+
import { DEFAULT_ON_SWITCH, validateSettingsDocument } from "./settings-validation.js";
|
|
3
|
+
export async function requireSettings() {
|
|
4
|
+
const settings = await readLocalConfigObject();
|
|
5
|
+
if (!settings) {
|
|
6
|
+
throw new Error(`Missing pi-sync settings. Open /sync and choose Set up sync, or create ${localConfigPath()}.`);
|
|
7
|
+
}
|
|
8
|
+
return settings;
|
|
9
|
+
}
|
|
10
|
+
export async function configuredSyncSetupNames() {
|
|
11
|
+
const settings = await readLocalConfigObject();
|
|
12
|
+
return settings ? Object.keys(settings.syncSetups).sort((left, right) => left.localeCompare(right)) : [];
|
|
13
|
+
}
|
|
14
|
+
export async function loadOnSwitch() {
|
|
15
|
+
return (await requireSettings()).onSwitch;
|
|
16
|
+
}
|
|
17
|
+
export function localConfigTemplate() {
|
|
18
|
+
return {
|
|
19
|
+
version: 3,
|
|
20
|
+
onSwitch: DEFAULT_ON_SWITCH,
|
|
21
|
+
skipSecretScan: false,
|
|
22
|
+
showStatus: true,
|
|
23
|
+
debug: false,
|
|
24
|
+
storageConnections: {},
|
|
25
|
+
syncSetups: {},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export async function readLocalConfigDocument() {
|
|
29
|
+
const document = await readMigratingLocalConfigDocument((settings) => {
|
|
30
|
+
validateSettingsDocument(settings);
|
|
31
|
+
});
|
|
32
|
+
if (document)
|
|
33
|
+
validateSettingsDocument(document.parsed);
|
|
34
|
+
return document;
|
|
35
|
+
}
|
|
36
|
+
export async function readLocalConfigObject() {
|
|
37
|
+
return (await readLocalConfigDocument())?.parsed;
|
|
38
|
+
}
|
|
39
|
+
export function updateLocalConfig(update, signal) {
|
|
40
|
+
return updateLocalConfigDocument(localConfigTemplate(), update, validateSettingsDocument, signal);
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|