@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,3 @@
|
|
|
1
|
+
// First-use operation surface for the cached loader; implementations stay lazy.
|
|
2
|
+
export { backupLocal, PublicationStatePersistenceError, pull, push, RollbackPublicationError, rollback, syncBoth, } from "./sync-mutations.js";
|
|
3
|
+
export { diff, doctor, history, status } from "./sync-queries.js";
|
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { isDeniedPath, toPosix } from "../paths.js";
|
|
3
|
+
import { IGNORE_SNAPSHOT_VERSION, } from "../snapshot/snapshot-types.js";
|
|
4
|
+
import { compilePathRules, compileSyncExclude, normalizeSyncExclude, sameSyncExclude } from "./exclude-policy.js";
|
|
5
|
+
export const BUILT_IN_SYNC_ROOTS = [
|
|
6
|
+
"settings.json",
|
|
7
|
+
"keybindings.json",
|
|
8
|
+
"models.json",
|
|
9
|
+
"AGENTS.md",
|
|
10
|
+
"APPEND_SYSTEM.md",
|
|
11
|
+
"skills",
|
|
12
|
+
"prompts",
|
|
13
|
+
"themes",
|
|
14
|
+
"extensions",
|
|
15
|
+
];
|
|
16
|
+
export const DEFAULT_SYNC_INCLUDE = [...BUILT_IN_SYNC_ROOTS];
|
|
17
|
+
const MAX_SYNC_INCLUDE_ITEMS = 1_024;
|
|
18
|
+
const MAX_SYNC_INCLUDE_PATH_BYTES = 4_096;
|
|
19
|
+
const MAX_SYNC_INCLUDE_TOTAL_BYTES = 256 * 1_024;
|
|
20
|
+
const BUILT_IN_BY_LOWER = new Map(BUILT_IN_SYNC_ROOTS.map((fileName) => [fileName.toLowerCase(), fileName]));
|
|
21
|
+
const TOP_LEVEL_FILE_PATHS = new Map(BUILT_IN_SYNC_ROOTS.filter((fileName) => fileName.includes(".")).map((fileName) => [
|
|
22
|
+
fileName.toLowerCase(),
|
|
23
|
+
fileName,
|
|
24
|
+
]));
|
|
25
|
+
const TOP_LEVEL_DIRS = new Set(BUILT_IN_SYNC_ROOTS.filter((fileName) => !fileName.includes(".")));
|
|
26
|
+
const RESERVED_TOP_LEVEL_NAMES = new Set([...BUILT_IN_BY_LOWER.keys(), "sessions"]);
|
|
27
|
+
export function normalizeSyncInclude(value) {
|
|
28
|
+
if (!Array.isArray(value)) {
|
|
29
|
+
throw new Error("Invalid pi-sync settings: sync.include must be an array.");
|
|
30
|
+
}
|
|
31
|
+
if (value.length > MAX_SYNC_INCLUDE_ITEMS) {
|
|
32
|
+
throw new Error(`Invalid pi-sync settings: sync.include has too many items; limit: ${MAX_SYNC_INCLUDE_ITEMS}.`);
|
|
33
|
+
}
|
|
34
|
+
const result = [];
|
|
35
|
+
const seen = new Set();
|
|
36
|
+
const pathRoot = { children: new Map() };
|
|
37
|
+
let totalBytes = 0;
|
|
38
|
+
for (const item of value) {
|
|
39
|
+
if (typeof item !== "string") {
|
|
40
|
+
throw new Error("Invalid pi-sync settings: sync.include items must be strings.");
|
|
41
|
+
}
|
|
42
|
+
const itemBytes = Buffer.byteLength(item, "utf8");
|
|
43
|
+
if (itemBytes > MAX_SYNC_INCLUDE_PATH_BYTES) {
|
|
44
|
+
throw new Error(`Invalid pi-sync settings: sync.include item is too long; limit: ${MAX_SYNC_INCLUDE_PATH_BYTES} bytes.`);
|
|
45
|
+
}
|
|
46
|
+
totalBytes += itemBytes;
|
|
47
|
+
if (totalBytes > MAX_SYNC_INCLUDE_TOTAL_BYTES) {
|
|
48
|
+
throw new Error(`Invalid pi-sync settings: sync.include is too large; limit: ${MAX_SYNC_INCLUDE_TOTAL_BYTES} bytes.`);
|
|
49
|
+
}
|
|
50
|
+
const trimmed = item.trim();
|
|
51
|
+
const builtIn = BUILT_IN_BY_LOWER.get(trimmed.toLowerCase());
|
|
52
|
+
const normalized = builtIn ?? (trimmed.toLowerCase() === "sessions" ? "sessions" : trimmed);
|
|
53
|
+
if (!builtIn && normalized !== "sessions")
|
|
54
|
+
validateAgentRelativeInclude(normalized);
|
|
55
|
+
const identity = normalized.toLowerCase();
|
|
56
|
+
if (seen.has(identity)) {
|
|
57
|
+
throw new Error(`Invalid pi-sync settings: duplicate sync.include item: ${item}`);
|
|
58
|
+
}
|
|
59
|
+
addIncludePath(pathRoot, identity, item);
|
|
60
|
+
seen.add(identity);
|
|
61
|
+
result.push(normalized);
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
function addIncludePath(root, identity, source) {
|
|
66
|
+
let node = root;
|
|
67
|
+
for (const segment of identity.split("/")) {
|
|
68
|
+
if (node.selected !== undefined)
|
|
69
|
+
throwOverlappingInclude(source);
|
|
70
|
+
let child = node.children.get(segment);
|
|
71
|
+
if (!child) {
|
|
72
|
+
child = { children: new Map() };
|
|
73
|
+
node.children.set(segment, child);
|
|
74
|
+
}
|
|
75
|
+
node = child;
|
|
76
|
+
}
|
|
77
|
+
if (node.children.size > 0)
|
|
78
|
+
throwOverlappingInclude(source);
|
|
79
|
+
node.selected = identity;
|
|
80
|
+
}
|
|
81
|
+
function throwOverlappingInclude(item) {
|
|
82
|
+
throw new Error(`Invalid pi-sync settings: overlapping sync.include items are ambiguous: ${item}`);
|
|
83
|
+
}
|
|
84
|
+
function validateAgentRelativeInclude(value) {
|
|
85
|
+
const normalized = toPosix(value);
|
|
86
|
+
const topLevel = normalized.split("/")[0]?.toLowerCase();
|
|
87
|
+
if (!normalized ||
|
|
88
|
+
normalized === "." ||
|
|
89
|
+
normalized === ".." ||
|
|
90
|
+
normalized.startsWith("../") ||
|
|
91
|
+
path.posix.isAbsolute(normalized) ||
|
|
92
|
+
normalized.includes("\\") ||
|
|
93
|
+
path.posix.normalize(normalized) !== normalized ||
|
|
94
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: Include paths cannot contain controls.
|
|
95
|
+
/[\u0000-\u001f\u007f-\u009f]/u.test(normalized)) {
|
|
96
|
+
throw new Error(`Invalid pi-sync settings: sync.include item must be a safe agent-relative path: ${value}`);
|
|
97
|
+
}
|
|
98
|
+
if (isDeniedPath(normalized)) {
|
|
99
|
+
throw new Error(`Invalid pi-sync settings: ${value} cannot be synced.`);
|
|
100
|
+
}
|
|
101
|
+
if (topLevel && RESERVED_TOP_LEVEL_NAMES.has(topLevel)) {
|
|
102
|
+
throw new Error(`Invalid pi-sync settings: use the canonical ${topLevel} root instead of a nested sync.include path.`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export function normalizeDirectoryRules(value) {
|
|
106
|
+
return normalizeSyncExclude(Array.isArray(value)
|
|
107
|
+
? value.map((rule) => (typeof rule === "string" ? rule.replace(/(?<!\/)\/(?= *$)/u, "") : rule))
|
|
108
|
+
: value);
|
|
109
|
+
}
|
|
110
|
+
export function portableSnapshotSelection(value) {
|
|
111
|
+
const selection = value;
|
|
112
|
+
if (selection && typeof selection === "object" && !Array.isArray(selection) && selection.version === 4) {
|
|
113
|
+
if (selection.scope !== "agent-directory" ||
|
|
114
|
+
typeof selection.sessions !== "boolean" ||
|
|
115
|
+
typeof selection.fingerprint !== "string" ||
|
|
116
|
+
selection.fingerprint.length !== 64 ||
|
|
117
|
+
!/^[0-9a-f]{64}$/u.test(selection.fingerprint) ||
|
|
118
|
+
Object.keys(selection).length !== 4 ||
|
|
119
|
+
!["version", "scope", "sessions", "fingerprint"].every((key) => Object.hasOwn(selection, key)))
|
|
120
|
+
throw new Error("Invalid ignore-file snapshot policy.");
|
|
121
|
+
return {
|
|
122
|
+
version: 4,
|
|
123
|
+
scope: "agent-directory",
|
|
124
|
+
fingerprint: selection.fingerprint,
|
|
125
|
+
sessions: selection.sessions,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (selection && typeof selection === "object" && !Array.isArray(selection) && selection.version === 3) {
|
|
129
|
+
if (selection.scope !== "agent-directory" ||
|
|
130
|
+
!Array.isArray(selection.exclude) ||
|
|
131
|
+
!Array.isArray(selection.reinclude) ||
|
|
132
|
+
Object.keys(selection).some((key) => !["version", "scope", "include", "exclude", "reinclude"].includes(key)))
|
|
133
|
+
throw new Error("Invalid agent-directory snapshot policy.");
|
|
134
|
+
return directorySelection(selection.include, selection.exclude, selection.reinclude);
|
|
135
|
+
}
|
|
136
|
+
if (!selection ||
|
|
137
|
+
typeof selection !== "object" ||
|
|
138
|
+
Array.isArray(selection) ||
|
|
139
|
+
(selection.version !== 1 && selection.version !== 2) ||
|
|
140
|
+
!Object.hasOwn(selection, "include") ||
|
|
141
|
+
(selection.version === 2 && !Object.hasOwn(selection, "exclude")) ||
|
|
142
|
+
Object.keys(selection).some((key) => key !== "version" && key !== "include" && !(selection.version === 2 && key === "exclude")))
|
|
143
|
+
throw new Error("Invalid snapshot selection policy.");
|
|
144
|
+
const include = normalizeSyncInclude(selection.include);
|
|
145
|
+
if (selection.version === 1)
|
|
146
|
+
return { version: 1, include };
|
|
147
|
+
if (!Array.isArray(selection.exclude))
|
|
148
|
+
throw new Error("Invalid snapshot exclude policy.");
|
|
149
|
+
return { version: 2, include, exclude: normalizeSyncExclude(selection.exclude) };
|
|
150
|
+
}
|
|
151
|
+
export function snapshotSelectionInclude(snapshot) {
|
|
152
|
+
if (snapshot.selection === undefined)
|
|
153
|
+
return undefined;
|
|
154
|
+
const selection = portableSnapshotSelection(snapshot.selection);
|
|
155
|
+
return selection.version === 4 ? (selection.sessions ? ["sessions"] : []) : selection.include;
|
|
156
|
+
}
|
|
157
|
+
export function snapshotSelectionExclude(snapshot) {
|
|
158
|
+
return snapshot.selection === undefined ? undefined : portableSnapshotSelection(snapshot.selection).exclude;
|
|
159
|
+
}
|
|
160
|
+
function directorySelection(include, exclude, reinclude) {
|
|
161
|
+
const normalized = normalizeSyncInclude(include);
|
|
162
|
+
if (normalized.some((root) => root !== "sessions"))
|
|
163
|
+
throw new Error("Agent-directory snapshots only use include metadata for explicit session selection.");
|
|
164
|
+
return {
|
|
165
|
+
version: 3,
|
|
166
|
+
scope: "agent-directory",
|
|
167
|
+
include: normalized,
|
|
168
|
+
exclude: normalizeDirectoryRules(exclude),
|
|
169
|
+
reinclude: normalizeDirectoryRules(reinclude),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
export function selectionForSnapshot(include, exclude, directory) {
|
|
173
|
+
if (directory?.ignorePolicy) {
|
|
174
|
+
if (directory.scope !== "agent-directory")
|
|
175
|
+
throw new Error("Ignore rules require agent-directory scope.");
|
|
176
|
+
return portableSnapshotSelection({
|
|
177
|
+
version: 4,
|
|
178
|
+
scope: directory.scope,
|
|
179
|
+
fingerprint: directory.ignorePolicy.fingerprint,
|
|
180
|
+
sessions: directory.ignorePolicy.sessions,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if (directory?.scope === "agent-directory")
|
|
184
|
+
return directorySelection(include, exclude, directory.reinclude);
|
|
185
|
+
const normalized = normalizeSyncInclude(include);
|
|
186
|
+
return exclude === undefined
|
|
187
|
+
? { version: 1, include: normalized }
|
|
188
|
+
: { version: 2, include: normalized, exclude: normalizeSyncExclude(exclude) };
|
|
189
|
+
}
|
|
190
|
+
/** Metadata equality, not policy compatibility: bind the whole projection to its immutable image. */
|
|
191
|
+
export function sameSnapshotSelection(left, right) {
|
|
192
|
+
return (JSON.stringify(left === undefined ? null : portableSnapshotSelection(left)) ===
|
|
193
|
+
JSON.stringify(right === undefined ? null : portableSnapshotSelection(right)));
|
|
194
|
+
}
|
|
195
|
+
export function validateSnapshotSelection(snapshot) {
|
|
196
|
+
const selection = snapshot.selection === undefined ? undefined : portableSnapshotSelection(snapshot.selection);
|
|
197
|
+
if ((snapshot.version === 4) !== (selection?.version === 2))
|
|
198
|
+
throw new Error("Exclude policy requires snapshot version 4 and selection version 2.");
|
|
199
|
+
if ((snapshot.version === 5) !== (selection?.version === 3))
|
|
200
|
+
throw new Error("Agent-directory policy requires snapshot version 5 and selection version 3.");
|
|
201
|
+
if ((snapshot.version === IGNORE_SNAPSHOT_VERSION) !== (selection?.version === 4))
|
|
202
|
+
throw new Error("Ignore-file policy requires snapshot version 6 and selection version 4.");
|
|
203
|
+
}
|
|
204
|
+
export function requireLegacyTransferPolicy(snapshot) {
|
|
205
|
+
if (snapshot.version === IGNORE_SNAPSHOT_VERSION || snapshot.selection?.version === 4)
|
|
206
|
+
throw new Error("This setup cannot transfer an ignore-file snapshot without a reviewed local ignore policy.");
|
|
207
|
+
}
|
|
208
|
+
export function sameSyncInclude(left, right) {
|
|
209
|
+
const normalizedLeft = normalizeSyncInclude(left);
|
|
210
|
+
const normalizedRight = normalizeSyncInclude(right);
|
|
211
|
+
return (normalizedLeft.length === normalizedRight.length &&
|
|
212
|
+
normalizedLeft.every((item, index) => item === normalizedRight[index]));
|
|
213
|
+
}
|
|
214
|
+
export function compareSyncInclude(local, remote) {
|
|
215
|
+
const localInclude = normalizeSyncInclude(local);
|
|
216
|
+
const remoteInclude = normalizeSyncInclude(remote);
|
|
217
|
+
const localSet = new Set(localInclude);
|
|
218
|
+
const remoteSet = new Set(remoteInclude);
|
|
219
|
+
return {
|
|
220
|
+
same: sameSyncInclude(localInclude, remoteInclude),
|
|
221
|
+
remoteOnly: remoteInclude.filter((item) => !localSet.has(item)),
|
|
222
|
+
localOnly: localInclude.filter((item) => !remoteSet.has(item)),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
export function compareIgnorePolicy(local, remote) {
|
|
226
|
+
if (remote?.version !== 4)
|
|
227
|
+
return local ? "local-ignore-remote-legacy" : undefined;
|
|
228
|
+
if (!local)
|
|
229
|
+
return "local-legacy-remote-ignore";
|
|
230
|
+
return local.fingerprint === remote.fingerprint && local.sessions === remote.sessions ? "match" : "mismatch";
|
|
231
|
+
}
|
|
232
|
+
export function formatIgnorePolicyComparison(comparison) {
|
|
233
|
+
switch (comparison) {
|
|
234
|
+
case "match":
|
|
235
|
+
return "Remote ignore-file policy matches this device.";
|
|
236
|
+
case "mismatch":
|
|
237
|
+
return "Remote ignore-file policy differs. Edit local rules to match, or review publishing this device's policy.";
|
|
238
|
+
case "local-ignore-remote-legacy":
|
|
239
|
+
return "Remote uses a legacy content policy. Review publishing this device's ignore-file policy.";
|
|
240
|
+
case "local-legacy-remote-ignore":
|
|
241
|
+
return "Remote uses an ignore-file policy. Configure matching local rules before transferring.";
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
export function syncDirectoryPolicyKey(config) {
|
|
245
|
+
if (config.scope !== "agent-directory")
|
|
246
|
+
return undefined;
|
|
247
|
+
const policy = config.ignorePolicy;
|
|
248
|
+
if (policy) {
|
|
249
|
+
return JSON.stringify([
|
|
250
|
+
"ignore-file",
|
|
251
|
+
policy.fingerprint,
|
|
252
|
+
policy.sessions,
|
|
253
|
+
policy.filename,
|
|
254
|
+
policy.sourceDigest,
|
|
255
|
+
policy.reservedNames,
|
|
256
|
+
]);
|
|
257
|
+
}
|
|
258
|
+
return JSON.stringify([
|
|
259
|
+
config.scope,
|
|
260
|
+
includeFromSelectionConfig(config).includes("sessions"),
|
|
261
|
+
normalizeDirectoryRules(config.exclude).map((rule) => rule.toLowerCase()),
|
|
262
|
+
normalizeDirectoryRules(config.reinclude).map((rule) => rule.toLowerCase()),
|
|
263
|
+
]);
|
|
264
|
+
}
|
|
265
|
+
export function inspectRemoteSelection(localInclude, snapshot, localExclude, directory) {
|
|
266
|
+
const selection = snapshot.selection === undefined ? undefined : portableSnapshotSelection(snapshot.selection);
|
|
267
|
+
const ignorePolicyComparison = compareIgnorePolicy(directory?.ignorePolicy, selection);
|
|
268
|
+
if (ignorePolicyComparison !== undefined) {
|
|
269
|
+
const include = snapshotSelectionInclude(snapshot) ?? discoverLegacySnapshotInclude(snapshot);
|
|
270
|
+
const scope = selection?.scope;
|
|
271
|
+
if (ignorePolicyComparison === "match")
|
|
272
|
+
return { kind: "same", include, scope, ignorePolicyComparison };
|
|
273
|
+
const comparison = compareSyncInclude(directory?.ignorePolicy ? (directory.ignorePolicy.sessions ? ["sessions"] : []) : localInclude, include);
|
|
274
|
+
return { kind: "different", include, scope, ...comparison, ignorePolicyComparison };
|
|
275
|
+
}
|
|
276
|
+
if (!selection && !directory?.scope)
|
|
277
|
+
return { kind: "legacy", discovered: discoverLegacySnapshotInclude(snapshot) };
|
|
278
|
+
const remoteInclude = selection?.include ?? discoverLegacySnapshotInclude(snapshot);
|
|
279
|
+
const exclude = selection?.exclude;
|
|
280
|
+
const comparison = compareSyncInclude(localInclude, remoteInclude);
|
|
281
|
+
const rules = {
|
|
282
|
+
...(exclude === undefined ? {} : { exclude }),
|
|
283
|
+
...(selection?.scope ? { scope: selection.scope, reinclude: selection.reinclude } : {}),
|
|
284
|
+
};
|
|
285
|
+
const directoryKey = syncDirectoryPolicyKey({ include: localInclude, exclude: localExclude, ...directory });
|
|
286
|
+
const sameDirectoryPolicy = directoryKey === syncDirectoryPolicyKey({ include: remoteInclude, ...rules });
|
|
287
|
+
const sameExclusions = directoryKey !== undefined
|
|
288
|
+
? sameSyncExclude(normalizeDirectoryRules(localExclude), exclude)
|
|
289
|
+
: sameSyncExclude(localExclude, exclude);
|
|
290
|
+
return comparison.same && sameExclusions && sameDirectoryPolicy
|
|
291
|
+
? { kind: "same", include: remoteInclude, ...rules }
|
|
292
|
+
: {
|
|
293
|
+
kind: "different",
|
|
294
|
+
include: remoteInclude,
|
|
295
|
+
...comparison,
|
|
296
|
+
...rules,
|
|
297
|
+
...(!sameExclusions ? { excludeChanged: true } : {}),
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
export class RemoteSelectionMismatchError extends Error {
|
|
301
|
+
decision;
|
|
302
|
+
setupName;
|
|
303
|
+
localInclude;
|
|
304
|
+
remoteInclude;
|
|
305
|
+
constructor(setupName, localInclude, remoteInclude, configIdentity = JSON.stringify([setupName, normalizeSyncInclude(localInclude)]), localExclude, remoteExclude, localDirectory, remoteDirectory, ignorePolicyComparison) {
|
|
306
|
+
const local = normalizeSyncInclude(localInclude);
|
|
307
|
+
const remote = normalizeSyncInclude(remoteInclude);
|
|
308
|
+
super(ignorePolicyComparison
|
|
309
|
+
? formatIgnorePolicyComparison(ignorePolicyComparison)
|
|
310
|
+
: formatRemoteSelectionMismatch(setupName, local, remote, localExclude, remoteExclude, localDirectory, remoteDirectory));
|
|
311
|
+
this.name = "RemoteSelectionMismatchError";
|
|
312
|
+
this.setupName = setupName;
|
|
313
|
+
this.localInclude = local;
|
|
314
|
+
this.remoteInclude = remote;
|
|
315
|
+
this.decision = {
|
|
316
|
+
setupName,
|
|
317
|
+
configIdentity,
|
|
318
|
+
localInclude: [...local],
|
|
319
|
+
remoteInclude: [...remote],
|
|
320
|
+
...(ignorePolicyComparison
|
|
321
|
+
? { ignorePolicyComparison }
|
|
322
|
+
: {
|
|
323
|
+
...(localExclude === undefined ? {} : { localExclude: normalizeSyncExclude(localExclude) }),
|
|
324
|
+
...(remoteExclude === undefined ? {} : { remoteExclude: normalizeSyncExclude(remoteExclude) }),
|
|
325
|
+
...(localDirectory?.scope ? { localDirectory: directoryRules(localDirectory) } : {}),
|
|
326
|
+
...(remoteDirectory?.scope ? { remoteDirectory: directoryRules(remoteDirectory) } : {}),
|
|
327
|
+
}),
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function directoryRules(directory) {
|
|
332
|
+
return { scope: directory.scope, reinclude: normalizeDirectoryRules(directory.reinclude) };
|
|
333
|
+
}
|
|
334
|
+
export function remoteSelectionMismatch(config, remoteInclude, configIdentity, remoteExclude, remoteDirectory) {
|
|
335
|
+
return new RemoteSelectionMismatchError(config.setupName, config.include, remoteInclude, configIdentity, config.exclude, remoteExclude, config, remoteDirectory, remoteDirectory?.ignorePolicyComparison);
|
|
336
|
+
}
|
|
337
|
+
export function formatRemoteSelectionMismatch(setupName, localInclude, remoteInclude, localExclude, remoteExclude, localDirectory, remoteDirectory) {
|
|
338
|
+
const comparison = compareSyncInclude(localInclude, remoteInclude);
|
|
339
|
+
const lines = [
|
|
340
|
+
`Synced content differs for sync setup “${stripTerminalControls(setupName)}”.`,
|
|
341
|
+
`Remote-only: ${comparison.remoteOnly.join(", ") || "none"}`,
|
|
342
|
+
`This-device-only: ${comparison.localOnly.join(", ") || "none"}`,
|
|
343
|
+
];
|
|
344
|
+
if (localDirectory?.scope || remoteDirectory?.scope) {
|
|
345
|
+
lines.push(`Remote scope: ${remoteDirectory?.scope ?? "selected paths or legacy"}`, `This device scope: ${localDirectory?.scope ?? "selected paths"}`, `Remote excluded paths: ${normalizeSyncExclude(remoteExclude).join(", ") || "none"}`, `This device excluded paths: ${normalizeSyncExclude(localExclude).join(", ") || "none"}`, `Remote re-included paths: ${normalizeDirectoryRules(remoteDirectory?.reinclude).join(", ") || "none"}`, `This device re-included paths: ${normalizeDirectoryRules(localDirectory?.reinclude).join(", ") || "none"}`);
|
|
346
|
+
}
|
|
347
|
+
else if (!sameSyncExclude(localExclude, remoteExclude)) {
|
|
348
|
+
lines.push(`Remote excluded paths: ${normalizeSyncExclude(remoteExclude).join(", ") || "none"}`, `This device excluded paths: ${normalizeSyncExclude(localExclude).join(", ") || "none"}`);
|
|
349
|
+
}
|
|
350
|
+
else if (comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0) {
|
|
351
|
+
lines.push("Only ordering differs.", `Remote order: ${remoteInclude.join(", ") || "none"}`, `This device order: ${localInclude.join(", ") || "none"}`);
|
|
352
|
+
}
|
|
353
|
+
lines.push("Run /sync in TUI to review both content lists and choose what happens next.");
|
|
354
|
+
return lines.join("\n");
|
|
355
|
+
}
|
|
356
|
+
function stripTerminalControls(value) {
|
|
357
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: Escape untrusted terminal controls.
|
|
358
|
+
return value.replace(/[\u0000-\u001f\u007f-\u009f]/gu, "?");
|
|
359
|
+
}
|
|
360
|
+
export function discoverLegacySnapshotInclude(snapshot) {
|
|
361
|
+
const builtIns = new Set();
|
|
362
|
+
const custom = new Set();
|
|
363
|
+
let sessions = false;
|
|
364
|
+
for (const file of snapshot.files) {
|
|
365
|
+
const normalized = toPosix(file.path);
|
|
366
|
+
if (!normalized ||
|
|
367
|
+
file.path.includes("\\") ||
|
|
368
|
+
normalized.length > 4096 ||
|
|
369
|
+
normalized.startsWith("../") ||
|
|
370
|
+
path.posix.isAbsolute(normalized) ||
|
|
371
|
+
path.posix.normalize(normalized) !== normalized ||
|
|
372
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: Ignore unsafe legacy paths.
|
|
373
|
+
/[\u0000-\u001f\u007f-\u009f]/u.test(normalized) ||
|
|
374
|
+
isDeniedPath(normalized)) {
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
const [topLevel, ...rest] = normalized.split("/");
|
|
378
|
+
if (!topLevel)
|
|
379
|
+
continue;
|
|
380
|
+
if (topLevel === "sessions" && rest.length > 0) {
|
|
381
|
+
sessions = true;
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
const builtIn = BUILT_IN_BY_LOWER.get(topLevel.toLowerCase());
|
|
385
|
+
if (builtIn &&
|
|
386
|
+
((TOP_LEVEL_DIRS.has(builtIn) && rest.length > 0) || (!TOP_LEVEL_DIRS.has(builtIn) && rest.length === 0))) {
|
|
387
|
+
builtIns.add(builtIn);
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (isSafeCustomIncludePath(topLevel))
|
|
391
|
+
custom.add(topLevel);
|
|
392
|
+
}
|
|
393
|
+
return [
|
|
394
|
+
...BUILT_IN_SYNC_ROOTS.filter((item) => builtIns.has(item)),
|
|
395
|
+
...[...custom].sort((left, right) => left.localeCompare(right)),
|
|
396
|
+
...(sessions ? ["sessions"] : []),
|
|
397
|
+
];
|
|
398
|
+
}
|
|
399
|
+
export function syncIncludeSelection(value) {
|
|
400
|
+
const include = normalizeSyncInclude(value);
|
|
401
|
+
const builtIns = include.filter((item) => BUILT_IN_BY_LOWER.has(item.toLowerCase()));
|
|
402
|
+
const custom = include.filter((item) => item !== "sessions" && !BUILT_IN_BY_LOWER.has(item.toLowerCase()));
|
|
403
|
+
return { include, builtIns, custom, sessions: include.includes("sessions") };
|
|
404
|
+
}
|
|
405
|
+
export function customIncludePathsByLower(value) {
|
|
406
|
+
return new Map(syncIncludeSelection(value).custom.map((relativePath) => [relativePath.toLowerCase(), relativePath]));
|
|
407
|
+
}
|
|
408
|
+
export function includeFromSelectionConfig(config) {
|
|
409
|
+
if (config.ignorePolicy)
|
|
410
|
+
return config.ignorePolicy.sessions ? ["sessions"] : [];
|
|
411
|
+
if (config.include !== undefined)
|
|
412
|
+
return normalizeSyncInclude(config.include);
|
|
413
|
+
if (config.scope === "agent-directory")
|
|
414
|
+
return isIgnoreSnapshotSelection(config) && config.sessions ? ["sessions"] : [];
|
|
415
|
+
return [
|
|
416
|
+
...normalizeSyncFiles(config.syncFiles),
|
|
417
|
+
...normalizeExtraFiles(config.extraFiles),
|
|
418
|
+
...(config.syncSessions ? ["sessions"] : []),
|
|
419
|
+
];
|
|
420
|
+
}
|
|
421
|
+
export function syncSelectionHasContent(config) {
|
|
422
|
+
return config.scope === "agent-directory" || includeFromSelectionConfig(config).length > 0;
|
|
423
|
+
}
|
|
424
|
+
const DIRECTORY_SCOPE_LOCAL_ROOTS = new Set([
|
|
425
|
+
"auth.json",
|
|
426
|
+
"auth.json.lock",
|
|
427
|
+
"trust.json",
|
|
428
|
+
"trust.json.lock",
|
|
429
|
+
"settings.json.lock",
|
|
430
|
+
"models-store.json",
|
|
431
|
+
"models-store.json.lock",
|
|
432
|
+
"crashes.json",
|
|
433
|
+
"pi-debug.log",
|
|
434
|
+
]);
|
|
435
|
+
function hasControlCharacter(value) {
|
|
436
|
+
for (let index = 0; index < value.length; index++) {
|
|
437
|
+
const code = value.charCodeAt(index);
|
|
438
|
+
if (code < 32 || (code >= 127 && code <= 159))
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
function isProtectedDirectoryPath(relativePath) {
|
|
444
|
+
if (Buffer.byteLength(relativePath, "utf8") > 4_096)
|
|
445
|
+
return true;
|
|
446
|
+
const segments = relativePath.split("/");
|
|
447
|
+
const root = segments[0]?.toLowerCase();
|
|
448
|
+
if (segments.some((segment) => !segment || /[. ]$/u.test(segment) || /^(?:con|prn|aux|nul|com[1-9¹²³]|lpt[1-9¹²³])(?:\.|$)/iu.test(segment)) ||
|
|
449
|
+
/[\\<>:"|?*]/u.test(relativePath) ||
|
|
450
|
+
hasControlCharacter(relativePath) ||
|
|
451
|
+
(root === "sessions" && segments[0] !== "sessions") ||
|
|
452
|
+
(root === "settings.json" && relativePath !== "settings.json") ||
|
|
453
|
+
(root !== undefined && DIRECTORY_SCOPE_LOCAL_ROOTS.has(root)))
|
|
454
|
+
return true;
|
|
455
|
+
for (let ancestor = relativePath; ancestor;) {
|
|
456
|
+
if (isDeniedPath(ancestor))
|
|
457
|
+
return true;
|
|
458
|
+
const slash = ancestor.lastIndexOf("/");
|
|
459
|
+
if (slash < 0)
|
|
460
|
+
break;
|
|
461
|
+
ancestor = ancestor.slice(0, slash);
|
|
462
|
+
}
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
export function isIgnoreControlPath(relativePath, reservedNames) {
|
|
466
|
+
const first = (relativePath.split("/", 1)[0] ?? "").toLowerCase();
|
|
467
|
+
return first === ".syncignore" || reservedNames?.has(first) === true;
|
|
468
|
+
}
|
|
469
|
+
function isIgnoreSnapshotSelection(config) {
|
|
470
|
+
return config.version === 4 && config.fingerprint !== undefined;
|
|
471
|
+
}
|
|
472
|
+
function compileIgnoreControlPath(config) {
|
|
473
|
+
const local = config.ignorePolicy;
|
|
474
|
+
if (!local && !config.reservedIgnoreNames && !isIgnoreSnapshotSelection(config))
|
|
475
|
+
return undefined;
|
|
476
|
+
const names = new Set([...(local ? [local.filename, ...local.reservedNames] : []), ...(config.reservedIgnoreNames ?? [])].map((name) => name.toLowerCase()));
|
|
477
|
+
return (relativePath) => isIgnoreControlPath(relativePath, names);
|
|
478
|
+
}
|
|
479
|
+
function compileDirectoryPolicy(config) {
|
|
480
|
+
const localIgnore = config.ignorePolicy;
|
|
481
|
+
const ignoreSelection = localIgnore !== undefined || isIgnoreSnapshotSelection(config);
|
|
482
|
+
const controlPath = compileIgnoreControlPath(config);
|
|
483
|
+
const sessions = includeFromSelectionConfig(config).includes("sessions");
|
|
484
|
+
const blocked = (relativePath) => isProtectedDirectoryPath(relativePath) ||
|
|
485
|
+
(ignoreSelection && !relativePath.isWellFormed()) ||
|
|
486
|
+
controlPath?.(relativePath) === true ||
|
|
487
|
+
(!sessions && /^sessions(?:\/|$)/iu.test(relativePath));
|
|
488
|
+
if (localIgnore) {
|
|
489
|
+
return {
|
|
490
|
+
excludes: (relativePath, directory = false) => blocked(relativePath) || localIgnore.matches(relativePath, directory),
|
|
491
|
+
descends: (relativePath) => !blocked(relativePath) && !localIgnore.matches(relativePath, true),
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
const excluded = compilePathRules(normalizeDirectoryRules(config.exclude));
|
|
495
|
+
const restored = compilePathRules(normalizeDirectoryRules(config.reinclude));
|
|
496
|
+
return {
|
|
497
|
+
excludes: (relativePath) => blocked(relativePath) || (excluded.matches(relativePath) && !restored.matches(relativePath)),
|
|
498
|
+
descends: (relativePath) => !blocked(relativePath) &&
|
|
499
|
+
(!excluded.matches(relativePath) || restored.matches(relativePath) || restored.mayMatchBelow(relativePath)),
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
export const MAX_AGENT_DIRECTORY_ENTRIES = 65_536;
|
|
503
|
+
export const MAX_AGENT_DIRECTORY_FILES = 16_384;
|
|
504
|
+
export function assertAgentDirectoryPathLayout(files) {
|
|
505
|
+
const prefixes = new Map();
|
|
506
|
+
let count = 0;
|
|
507
|
+
for (const file of files) {
|
|
508
|
+
if (++count > MAX_AGENT_DIRECTORY_FILES)
|
|
509
|
+
throw new Error("Agent-directory snapshot exceeds the file bound.");
|
|
510
|
+
for (let end = file.indexOf("/");; end = file.indexOf("/", end + 1)) {
|
|
511
|
+
const spelling = end === -1 ? file : file.slice(0, end);
|
|
512
|
+
const portable = spelling.normalize("NFC").toLowerCase();
|
|
513
|
+
const known = prefixes.get(portable);
|
|
514
|
+
if (known && (known.spelling !== spelling || known.file || end === -1))
|
|
515
|
+
throw new Error("Agent-directory snapshot has conflicting portable paths.");
|
|
516
|
+
if (!known) {
|
|
517
|
+
if (prefixes.size >= MAX_AGENT_DIRECTORY_ENTRIES)
|
|
518
|
+
throw new Error("Agent-directory snapshot exceeds the path bound.");
|
|
519
|
+
prefixes.set(portable, { spelling, file: end === -1 });
|
|
520
|
+
}
|
|
521
|
+
if (end === -1)
|
|
522
|
+
break;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
export function compileSyncPolicyExclude(config) {
|
|
527
|
+
if (config.scope === "agent-directory")
|
|
528
|
+
return compileDirectoryPolicy(config).excludes;
|
|
529
|
+
const excludes = compileSyncExclude(config.exclude);
|
|
530
|
+
const controlPath = compileIgnoreControlPath(config);
|
|
531
|
+
return controlPath ? (relativePath) => controlPath(toPosix(relativePath)) || excludes(relativePath) : excludes;
|
|
532
|
+
}
|
|
533
|
+
export function compileSyncPolicyTraversal(config) {
|
|
534
|
+
if (config.scope === "agent-directory")
|
|
535
|
+
return compileDirectoryPolicy(config).descends;
|
|
536
|
+
const excludes = compileSyncPolicyExclude(config);
|
|
537
|
+
return (relativePath) => !excludes(relativePath);
|
|
538
|
+
}
|
|
539
|
+
export function syncSessionsSelected(config) {
|
|
540
|
+
return includeFromSelectionConfig(config).includes("sessions") && compileSyncPolicyTraversal(config)("sessions");
|
|
541
|
+
}
|
|
542
|
+
export function isConfiguredSnapshotPath(relativePath, config, _legacyExtraFiles) {
|
|
543
|
+
return configuredSnapshotPathMatcher(config)(relativePath);
|
|
544
|
+
}
|
|
545
|
+
export function configuredSnapshotPathMatcher(config) {
|
|
546
|
+
if (config.scope === "agent-directory") {
|
|
547
|
+
const excluded = compileSyncPolicyExclude(config);
|
|
548
|
+
return (relativePath) => !excluded(relativePath) &&
|
|
549
|
+
relativePath !== "sessions" &&
|
|
550
|
+
(!relativePath.startsWith("sessions/") || relativePath.endsWith(".jsonl"));
|
|
551
|
+
}
|
|
552
|
+
const selection = syncIncludeSelection(includeFromSelectionConfig(config));
|
|
553
|
+
const excluded = compileSyncPolicyExclude(config);
|
|
554
|
+
return (relativePath) => {
|
|
555
|
+
const normalized = toPosix(relativePath);
|
|
556
|
+
if (excluded(normalized))
|
|
557
|
+
return false;
|
|
558
|
+
if (normalized.startsWith("sessions/"))
|
|
559
|
+
return selection.sessions;
|
|
560
|
+
const lower = normalized.toLowerCase();
|
|
561
|
+
if (!normalized.includes("/")) {
|
|
562
|
+
const builtIn = BUILT_IN_BY_LOWER.get(lower);
|
|
563
|
+
if (builtIn)
|
|
564
|
+
return selection.builtIns.includes(builtIn) && !TOP_LEVEL_DIRS.has(builtIn);
|
|
565
|
+
}
|
|
566
|
+
const topLevel = normalized.slice(0, normalized.indexOf("/"));
|
|
567
|
+
if (selection.builtIns.includes(topLevel) && TOP_LEVEL_DIRS.has(topLevel))
|
|
568
|
+
return true;
|
|
569
|
+
return selection.custom.some((candidate) => {
|
|
570
|
+
const key = candidate.toLowerCase();
|
|
571
|
+
return lower === key || lower.startsWith(`${key}/`);
|
|
572
|
+
});
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
export function canonicalSnapshotPathForConfig(relativePath, includePaths) {
|
|
576
|
+
const normalized = toPosix(relativePath);
|
|
577
|
+
const lower = normalized.toLowerCase();
|
|
578
|
+
return TOP_LEVEL_FILE_PATHS.get(lower) ?? includePaths.get(lower) ?? normalized;
|
|
579
|
+
}
|
|
580
|
+
export function isPreservableUnmanagedSnapshotPath(relativePath) {
|
|
581
|
+
const normalized = toPosix(relativePath);
|
|
582
|
+
if (!normalized || isDeniedPath(normalized))
|
|
583
|
+
return false;
|
|
584
|
+
if (normalized.startsWith("sessions/"))
|
|
585
|
+
return normalized.endsWith(".jsonl");
|
|
586
|
+
if (!normalized.includes("/")) {
|
|
587
|
+
const lower = normalized.toLowerCase();
|
|
588
|
+
return TOP_LEVEL_FILE_PATHS.has(lower) || !RESERVED_TOP_LEVEL_NAMES.has(lower);
|
|
589
|
+
}
|
|
590
|
+
return true;
|
|
591
|
+
}
|
|
592
|
+
export function isSafeCustomIncludePath(relativePath) {
|
|
593
|
+
try {
|
|
594
|
+
validateAgentRelativeInclude(relativePath);
|
|
595
|
+
return true;
|
|
596
|
+
}
|
|
597
|
+
catch {
|
|
598
|
+
return false;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
export function isBuiltInTopLevelFile(fileName) {
|
|
602
|
+
return TOP_LEVEL_FILE_PATHS.has(path.posix.basename(fileName).toLowerCase());
|
|
603
|
+
}
|
|
604
|
+
/** Compatibility projection for backend-neutral output while callers move to sync.include. */
|
|
605
|
+
export function normalizeSyncFiles(value) {
|
|
606
|
+
if (value === undefined)
|
|
607
|
+
return [...DEFAULT_SYNC_INCLUDE];
|
|
608
|
+
if (Array.isArray(value)) {
|
|
609
|
+
return normalizeSyncInclude(value).filter((item) => BUILT_IN_BY_LOWER.has(item.toLowerCase()));
|
|
610
|
+
}
|
|
611
|
+
throw new Error("Invalid pi-sync settings: expected an include array.");
|
|
612
|
+
}
|
|
613
|
+
/** Compatibility projection for old rendering helpers; v3 persistence never writes this split field. */
|
|
614
|
+
export function normalizeExtraFiles(value) {
|
|
615
|
+
if (!Array.isArray(value))
|
|
616
|
+
return [];
|
|
617
|
+
return value.filter((item) => typeof item === "string" && isSafeCustomIncludePath(item));
|
|
618
|
+
}
|
|
619
|
+
export const extraFilePathsByLower = customIncludePathsByLower;
|
|
620
|
+
export const isSafeExtraFileName = isSafeCustomIncludePath;
|
|
621
|
+
export const selectedSyncFileSet = (value) => new Set(normalizeSyncFiles(value));
|