@narumitw/pi-sync 0.58.0 → 0.59.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 +16 -0
- package/README.md +12 -6
- package/dist/chunks/{agent-candidate-U2NU3GUX.ts → agent-candidate-ZHN7FTZT.ts} +9 -8
- package/dist/chunks/{agent-plan-3YXDIJXO.ts → agent-plan-ILFEUJ2E.ts} +12 -11
- package/dist/chunks/{agent-plan-3YXDIJXO.ts.map → agent-plan-ILFEUJ2E.ts.map} +1 -1
- package/dist/chunks/{agent-refusal-retry-476YGNU5.ts → agent-refusal-retry-HRMHCX2A.ts} +9 -8
- package/dist/chunks/{agent-refusal-retry-476YGNU5.ts.map → agent-refusal-retry-HRMHCX2A.ts.map} +1 -1
- package/dist/chunks/{agent-store-7GINKTS7.ts → agent-store-CCKN4DPR.ts} +3 -3
- package/dist/chunks/{agent-sync-2R4GG2MF.ts → agent-sync-EGA2I5W7.ts} +4 -4
- package/dist/chunks/{chunk-CQD2TJHE.ts → chunk-25QCU3LY.ts} +4 -4
- package/dist/chunks/{chunk-OJARL2TG.ts → chunk-2UKUKIBI.ts} +4 -4
- package/dist/chunks/{chunk-MW6KUQYA.ts → chunk-2ZZJXITS.ts} +40 -10
- package/dist/chunks/chunk-2ZZJXITS.ts.map +7 -0
- package/dist/chunks/chunk-3JTZF7Z5.ts +77 -0
- package/dist/chunks/chunk-3JTZF7Z5.ts.map +7 -0
- package/dist/chunks/{chunk-DN4IA7MR.ts → chunk-4NVHHDN2.ts} +2 -2
- package/dist/chunks/{chunk-AKMV47YC.ts → chunk-6OFMB6KK.ts} +2 -2
- package/dist/chunks/{chunk-45COPAK7.ts → chunk-6XU5HZAN.ts} +6 -6
- package/dist/chunks/{chunk-45COPAK7.ts.map → chunk-6XU5HZAN.ts.map} +2 -2
- package/dist/chunks/{chunk-Y4UVXOLQ.ts → chunk-6YGRZSCN.ts} +15 -10
- package/dist/chunks/chunk-6YGRZSCN.ts.map +7 -0
- package/dist/chunks/{chunk-XEODG2PE.ts → chunk-76HID27T.ts} +2 -2
- package/dist/chunks/{chunk-7A35ZAVO.ts → chunk-7WYF2KUO.ts} +174 -122
- package/dist/chunks/chunk-7WYF2KUO.ts.map +7 -0
- package/dist/chunks/{chunk-MMQIEDZ6.ts → chunk-APDNHB2T.ts} +78 -35
- package/dist/chunks/chunk-APDNHB2T.ts.map +7 -0
- package/dist/chunks/{chunk-U6GXGY5G.ts → chunk-DTPELCPW.ts} +4 -4
- package/dist/chunks/{chunk-TZC7GDJE.ts → chunk-ILXMZ2HU.ts} +4 -4
- package/dist/chunks/{chunk-CBLTWXAU.ts → chunk-LA3HQMFG.ts} +2 -1
- package/dist/chunks/{chunk-CBLTWXAU.ts.map → chunk-LA3HQMFG.ts.map} +2 -2
- package/dist/chunks/{chunk-ESKOPQVB.ts → chunk-MKC3PXCN.ts} +53 -32
- package/dist/chunks/chunk-MKC3PXCN.ts.map +7 -0
- package/dist/chunks/{chunk-MG66XM5U.ts → chunk-NGW4JMBF.ts} +63 -19
- package/dist/chunks/chunk-NGW4JMBF.ts.map +7 -0
- package/dist/chunks/{chunk-TIMWN2RH.ts → chunk-OQBE2OMB.ts} +13 -14
- package/dist/chunks/chunk-OQBE2OMB.ts.map +7 -0
- package/dist/chunks/{chunk-MKSMJPVA.ts → chunk-P3YD4ONV.ts} +22 -6
- package/dist/chunks/chunk-P3YD4ONV.ts.map +7 -0
- package/dist/chunks/{chunk-JYILGR3K.ts → chunk-PQ75RPUP.ts} +3 -3
- package/dist/chunks/{chunk-FLHCOJCD.ts → chunk-QQVK2XFC.ts} +13 -6
- package/dist/chunks/chunk-QQVK2XFC.ts.map +7 -0
- package/dist/chunks/{chunk-WQMYV4DW.ts → chunk-RDOX3VH5.ts} +5 -5
- package/dist/chunks/{chunk-6O3EDBRL.ts → chunk-S7D6XWHI.ts} +2 -2
- package/dist/chunks/{chunk-7ZIYU5QS.ts → chunk-SHPNS7FM.ts} +7 -7
- package/dist/chunks/{chunk-7ZIYU5QS.ts.map → chunk-SHPNS7FM.ts.map} +2 -2
- package/dist/chunks/{chunk-GNYGNHFF.ts → chunk-T2TYBLXK.ts} +2 -2
- package/dist/chunks/{chunk-6LD5KX55.ts → chunk-UZSDS4HF.ts} +13 -6
- package/dist/chunks/chunk-UZSDS4HF.ts.map +7 -0
- package/dist/chunks/{chunk-5TSCBBPP.ts → chunk-VPODHKOX.ts} +3 -3
- package/dist/chunks/{chunk-BEST45H2.ts → chunk-WEKGW7HV.ts} +17 -8
- package/dist/chunks/chunk-WEKGW7HV.ts.map +7 -0
- package/dist/chunks/{chunk-KYTT7KV4.ts → chunk-WUHRVSWI.ts} +87 -37
- package/dist/chunks/chunk-WUHRVSWI.ts.map +7 -0
- package/dist/chunks/{chunk-OVBAW7KV.ts → chunk-XZ3ZTHKR.ts} +19 -9
- package/dist/chunks/chunk-XZ3ZTHKR.ts.map +7 -0
- package/dist/chunks/{chunk-S5OCYVPS.ts → chunk-YEULK7MK.ts} +3 -3
- package/dist/chunks/{command-handler-KCB6MCWS.ts → command-handler-SDGKIQH2.ts} +17 -14
- package/dist/chunks/command-handler-SDGKIQH2.ts.map +7 -0
- package/dist/chunks/{config-HYG7G5EM.ts → config-J5VZUY4J.ts} +4 -3
- package/dist/chunks/{conflict-artifacts-J6WSDCWP.ts → conflict-artifacts-MYSH3L2J.ts} +10 -9
- package/dist/chunks/{conflict-review-GXA6Y7KY.ts → conflict-review-J6ZSPNWL.ts} +21 -20
- package/dist/chunks/{conflict-review-GXA6Y7KY.ts.map → conflict-review-J6ZSPNWL.ts.map} +1 -1
- package/dist/chunks/{continuous-record-EPHGR2DU.ts → continuous-record-OM64J27R.ts} +4 -4
- package/dist/chunks/{continuous-sync-FAFNLEUW.ts → continuous-sync-BH5SWIRV.ts} +22 -17
- package/dist/chunks/continuous-sync-BH5SWIRV.ts.map +7 -0
- package/dist/chunks/{file-selection-IELTXSGZ.ts → file-selection-7HEVPO4T.ts} +11 -8
- package/dist/chunks/file-selection-7HEVPO4T.ts.map +7 -0
- package/dist/chunks/{git-backend-KHD36W27.ts → git-backend-6CKI6CUG.ts} +12 -15
- package/dist/chunks/{git-backend-KHD36W27.ts.map → git-backend-6CKI6CUG.ts.map} +2 -2
- package/dist/chunks/{local-fields-JEKAPZKD.ts → local-fields-SR7PH66U.ts} +6 -5
- package/dist/chunks/{manager-result-dispatcher-XCYPW7RC.ts → manager-result-dispatcher-CXUP5WDP.ts} +15 -14
- package/dist/chunks/{manager-ui-FMZXKPX2.ts → manager-ui-65ZETN6F.ts} +168 -51
- package/dist/chunks/manager-ui-65ZETN6F.ts.map +7 -0
- package/dist/chunks/{merge-baseline-store-65GKUMXI.ts → merge-baseline-store-4Y2X7P2D.ts} +4 -3
- package/dist/chunks/{remote-selection-ui-MYM2YCPF.ts → remote-selection-ui-W55BQDJQ.ts} +14 -13
- package/dist/chunks/{s3-backend-L24UZ6IK.ts → s3-backend-FDK7JSDQ.ts} +8 -7
- package/dist/chunks/{s3-backend-L24UZ6IK.ts.map → s3-backend-FDK7JSDQ.ts.map} +1 -1
- package/dist/chunks/{setup-switch-KLGESLQX.ts → setup-switch-AB27ADDI.ts} +5 -4
- package/dist/chunks/{setup-wizard-ZQAK35BP.ts → setup-wizard-5FILKFLQ.ts} +6 -5
- package/dist/chunks/{setup-wizard-ZQAK35BP.ts.map → setup-wizard-5FILKFLQ.ts.map} +1 -1
- package/dist/chunks/{snapshot-RGNDYT6A.ts → snapshot-G3W2GOGB.ts} +5 -4
- package/dist/chunks/{snapshot-transaction-26BQO36S.ts → snapshot-transaction-SGRUWT73.ts} +6 -5
- package/dist/chunks/{sync-inspection-MOMLGUTD.ts → sync-inspection-MDYHZHT7.ts} +10 -9
- package/dist/chunks/{sync-operations-45APGOL3.ts → sync-operations-ZAUP65FH.ts} +40 -29
- package/dist/chunks/sync-operations-ZAUP65FH.ts.map +7 -0
- package/dist/chunks/{sync-state-7L4NT7W2.ts → sync-state-H4TFZZ7S.ts} +7 -6
- package/dist/chunks/{webdav-backend-3ZCACILP.ts → webdav-backend-UNMIAXM5.ts} +7 -6
- package/dist/chunks/{webdav-backend-3ZCACILP.ts.map → webdav-backend-UNMIAXM5.ts.map} +1 -1
- package/dist/index.ts +26 -19
- package/dist/index.ts.map +2 -2
- package/docs/exclude-policy-audit.md +54 -0
- package/docs/exclude-review-ledger.md +36 -0
- package/docs/tui-contract.md +1 -1
- package/package.json +3 -2
- package/skills/configure-pi-sync/SKILL.md +4 -3
- package/skills/configure-pi-sync/references/configuration.md +72 -13
- package/src/backends/git/git-storage.ts +12 -11
- package/src/commands/command-execution.ts +2 -2
- package/src/commands/command-handler.ts +1 -0
- package/src/settings/config.ts +9 -3
- package/src/settings/settings-management.ts +4 -3
- package/src/settings/settings-types.ts +4 -1
- package/src/settings/settings-validation.ts +8 -4
- package/src/snapshot/session-paths.ts +1 -0
- package/src/snapshot/snapshot-apply.ts +23 -7
- package/src/snapshot/snapshot-codec.ts +12 -3
- package/src/snapshot/snapshot-exclude-safety.ts +44 -0
- package/src/snapshot/snapshot-transaction.ts +12 -0
- package/src/snapshot/snapshot-types.ts +4 -4
- package/src/snapshot/snapshot.ts +71 -30
- package/src/state/merge-baseline-store.ts +9 -1
- package/src/state/state-types.ts +1 -0
- package/src/sync/automatic-sync.ts +7 -2
- package/src/sync/continuous-watch.ts +4 -2
- package/src/sync/exclude-policy.ts +84 -0
- package/src/sync/local-fields.ts +15 -4
- package/src/sync/merge-apply.ts +6 -1
- package/src/sync/merge-journal.ts +12 -3
- package/src/sync/merged-sync.ts +17 -12
- package/src/sync/partial-progress.ts +1 -0
- package/src/sync/remote-snapshot.ts +7 -8
- package/src/sync/sync-decision.ts +11 -1
- package/src/sync/sync-inspection.ts +3 -1
- package/src/sync/sync-mutations.ts +11 -4
- package/src/sync/sync-policy.ts +101 -37
- package/src/sync/sync-queries.ts +13 -3
- package/src/sync/sync-state.ts +16 -10
- package/src/ui/excluded-paths-ui.ts +106 -0
- package/src/ui/file-selection.ts +6 -3
- package/src/ui/manager-state.ts +11 -5
- package/src/ui/remote-selection-ui.ts +73 -10
- package/src/ui/settings-ui.ts +20 -5
- package/src/ui/setup/setup-actions.ts +1 -1
- package/src/ui/setup/setup-switcher.ts +3 -2
- package/src/ui/storage-connections-ui.ts +2 -2
- package/src/ui/sync-attention.ts +46 -10
- package/src/ui/sync-format.ts +13 -1
- package/dist/chunks/chunk-6LD5KX55.ts.map +0 -7
- package/dist/chunks/chunk-7A35ZAVO.ts.map +0 -7
- package/dist/chunks/chunk-BEST45H2.ts.map +0 -7
- package/dist/chunks/chunk-ESKOPQVB.ts.map +0 -7
- package/dist/chunks/chunk-FLHCOJCD.ts.map +0 -7
- package/dist/chunks/chunk-KYTT7KV4.ts.map +0 -7
- package/dist/chunks/chunk-MG66XM5U.ts.map +0 -7
- package/dist/chunks/chunk-MKSMJPVA.ts.map +0 -7
- package/dist/chunks/chunk-MMQIEDZ6.ts.map +0 -7
- package/dist/chunks/chunk-MW6KUQYA.ts.map +0 -7
- package/dist/chunks/chunk-OVBAW7KV.ts.map +0 -7
- package/dist/chunks/chunk-TIMWN2RH.ts.map +0 -7
- package/dist/chunks/chunk-Y4UVXOLQ.ts.map +0 -7
- package/dist/chunks/command-handler-KCB6MCWS.ts.map +0 -7
- package/dist/chunks/continuous-sync-FAFNLEUW.ts.map +0 -7
- package/dist/chunks/file-selection-IELTXSGZ.ts.map +0 -7
- package/dist/chunks/manager-ui-FMZXKPX2.ts.map +0 -7
- package/dist/chunks/sync-operations-45APGOL3.ts.map +0 -7
- /package/dist/chunks/{agent-candidate-U2NU3GUX.ts.map → agent-candidate-ZHN7FTZT.ts.map} +0 -0
- /package/dist/chunks/{agent-store-7GINKTS7.ts.map → agent-store-CCKN4DPR.ts.map} +0 -0
- /package/dist/chunks/{agent-sync-2R4GG2MF.ts.map → agent-sync-EGA2I5W7.ts.map} +0 -0
- /package/dist/chunks/{chunk-CQD2TJHE.ts.map → chunk-25QCU3LY.ts.map} +0 -0
- /package/dist/chunks/{chunk-OJARL2TG.ts.map → chunk-2UKUKIBI.ts.map} +0 -0
- /package/dist/chunks/{chunk-DN4IA7MR.ts.map → chunk-4NVHHDN2.ts.map} +0 -0
- /package/dist/chunks/{chunk-AKMV47YC.ts.map → chunk-6OFMB6KK.ts.map} +0 -0
- /package/dist/chunks/{chunk-XEODG2PE.ts.map → chunk-76HID27T.ts.map} +0 -0
- /package/dist/chunks/{chunk-U6GXGY5G.ts.map → chunk-DTPELCPW.ts.map} +0 -0
- /package/dist/chunks/{chunk-TZC7GDJE.ts.map → chunk-ILXMZ2HU.ts.map} +0 -0
- /package/dist/chunks/{chunk-JYILGR3K.ts.map → chunk-PQ75RPUP.ts.map} +0 -0
- /package/dist/chunks/{chunk-WQMYV4DW.ts.map → chunk-RDOX3VH5.ts.map} +0 -0
- /package/dist/chunks/{chunk-6O3EDBRL.ts.map → chunk-S7D6XWHI.ts.map} +0 -0
- /package/dist/chunks/{chunk-GNYGNHFF.ts.map → chunk-T2TYBLXK.ts.map} +0 -0
- /package/dist/chunks/{chunk-5TSCBBPP.ts.map → chunk-VPODHKOX.ts.map} +0 -0
- /package/dist/chunks/{chunk-S5OCYVPS.ts.map → chunk-YEULK7MK.ts.map} +0 -0
- /package/dist/chunks/{config-HYG7G5EM.ts.map → config-J5VZUY4J.ts.map} +0 -0
- /package/dist/chunks/{conflict-artifacts-J6WSDCWP.ts.map → conflict-artifacts-MYSH3L2J.ts.map} +0 -0
- /package/dist/chunks/{continuous-record-EPHGR2DU.ts.map → continuous-record-OM64J27R.ts.map} +0 -0
- /package/dist/chunks/{local-fields-JEKAPZKD.ts.map → local-fields-SR7PH66U.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-XCYPW7RC.ts.map → manager-result-dispatcher-CXUP5WDP.ts.map} +0 -0
- /package/dist/chunks/{merge-baseline-store-65GKUMXI.ts.map → merge-baseline-store-4Y2X7P2D.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-MYM2YCPF.ts.map → remote-selection-ui-W55BQDJQ.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-KLGESLQX.ts.map → setup-switch-AB27ADDI.ts.map} +0 -0
- /package/dist/chunks/{snapshot-RGNDYT6A.ts.map → snapshot-G3W2GOGB.ts.map} +0 -0
- /package/dist/chunks/{snapshot-transaction-26BQO36S.ts.map → snapshot-transaction-SGRUWT73.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-MOMLGUTD.ts.map → sync-inspection-MDYHZHT7.ts.map} +0 -0
- /package/dist/chunks/{sync-state-7L4NT7W2.ts.map → sync-state-H4TFZZ7S.ts.map} +0 -0
package/src/sync/merged-sync.ts
CHANGED
|
@@ -70,7 +70,7 @@ import { resolveSettingsConflicts } from "./settings-conflicts.js";
|
|
|
70
70
|
import { createStartupTimings, type StartupTimings } from "./startup-timings.js";
|
|
71
71
|
import { createSyncDecision } from "./sync-decision.js";
|
|
72
72
|
import { backupLocal, captureMutationOwner, protectedSessionPaths } from "./sync-local.js";
|
|
73
|
-
import { inspectRemoteSelection } from "./sync-policy.js";
|
|
73
|
+
import { configuredSnapshotPathMatcher, inspectRemoteSelection, syncSessionsSelected } from "./sync-policy.js";
|
|
74
74
|
import { fileHashMap, hasLocalChanges, hasRemoteChanges, sameHashes, syncPolicyChanged } from "./sync-state.js";
|
|
75
75
|
import { TEXT_MERGE_WORK_LIMIT } from "./text-merge.js";
|
|
76
76
|
|
|
@@ -109,7 +109,7 @@ export async function mergeSync(
|
|
|
109
109
|
validateRetryAuthorization(config);
|
|
110
110
|
const configToken = syncCheckConfigFingerprint(config);
|
|
111
111
|
const modelToken = JSON.stringify(ctx.model);
|
|
112
|
-
const sessionRoot = config
|
|
112
|
+
const sessionRoot = syncSessionsSelected(config) ? await effectiveSessionRoot(ctx) : undefined;
|
|
113
113
|
validateOwner();
|
|
114
114
|
const snapshotOptions = {
|
|
115
115
|
...snapshotOptionsForContext(ctx, config),
|
|
@@ -205,7 +205,8 @@ export async function mergeSync(
|
|
|
205
205
|
!state.unresolved?.length &&
|
|
206
206
|
head.snapshotId === state.lastAppliedSnapshot &&
|
|
207
207
|
backend.sameRevision(head.revision, state.lastRemoteRevision) &&
|
|
208
|
-
inspectRemoteSelection(config.include, { selection: head.selection, files: [] }).kind ===
|
|
208
|
+
inspectRemoteSelection(config.include, { selection: head.selection, files: [] }, config.exclude).kind ===
|
|
209
|
+
"same" &&
|
|
209
210
|
matchesAcceptedState(state, config, head, local)
|
|
210
211
|
) {
|
|
211
212
|
const unchanged = await timings.measure("transfer unchanged verification", async () => {
|
|
@@ -288,7 +289,7 @@ export async function mergeSync(
|
|
|
288
289
|
throw review("Included content changed; review the selection before merging.", "remote-or-policy-changed");
|
|
289
290
|
if (!head || !remote || !rawRemote)
|
|
290
291
|
throw review("The established remote is missing; choose an explicit recovery direction.", "remote-empty");
|
|
291
|
-
const selectionState = inspectRemoteSelection(config.include, rawRemote);
|
|
292
|
+
const selectionState = inspectRemoteSelection(config.include, rawRemote, config.exclude);
|
|
292
293
|
const selectionCompatible = selectionState.kind === "same";
|
|
293
294
|
let plan = await timings.measure("transfer merge planning", () =>
|
|
294
295
|
planFileMerge({
|
|
@@ -379,7 +380,10 @@ export async function mergeSync(
|
|
|
379
380
|
if (!groups.length) return;
|
|
380
381
|
let ancestors: import("../snapshot/snapshot-types.js").SnapshotFile[] = [];
|
|
381
382
|
try {
|
|
382
|
-
|
|
383
|
+
const configured = configuredSnapshotPathMatcher(config);
|
|
384
|
+
ancestors = ((await readMergeAncestors(config, state)) ?? []).filter(
|
|
385
|
+
(file) => withheld.has(file.path) && configured(file.path),
|
|
386
|
+
);
|
|
383
387
|
} catch {
|
|
384
388
|
/* Retain unknown evidence; absence remains explicit. */
|
|
385
389
|
}
|
|
@@ -451,10 +455,10 @@ export async function mergeSync(
|
|
|
451
455
|
files: acceptedMergeFiles(plan.decisions, local.files, withheld),
|
|
452
456
|
});
|
|
453
457
|
const after = overlayLocalFields(accepted, localRaw, config.localFields);
|
|
454
|
-
if (config
|
|
458
|
+
if (syncSessionsSelected(config)) requireStableMergeSessionRoot(localRaw, after);
|
|
455
459
|
const publication = regenerateSnapshotIdentity({
|
|
456
460
|
...accepted,
|
|
457
|
-
version: config.partialSync ? 3 : accepted.version,
|
|
461
|
+
version: accepted.version === 4 ? 4 : config.partialSync ? 3 : accepted.version,
|
|
458
462
|
files: [
|
|
459
463
|
...accepted.files.filter((file) => !withheld.has(file.path)),
|
|
460
464
|
...remote.files.filter((file) => withheld.has(file.path)),
|
|
@@ -463,7 +467,7 @@ export async function mergeSync(
|
|
|
463
467
|
const upload = mergeRemotePreservedFiles(publication, rawRemote, config);
|
|
464
468
|
const publish =
|
|
465
469
|
!sameHashes(fileHashMap(publication), fileHashMap(remote)) ||
|
|
466
|
-
Boolean(config.partialSync && rawRemote.version !== 3);
|
|
470
|
+
Boolean(config.partialSync && rawRemote.version !== 3 && rawRemote.version !== 4);
|
|
467
471
|
const apply = !sameHashes(fileHashMap(localRaw), fileHashMap(after));
|
|
468
472
|
if (!publish && !apply) {
|
|
469
473
|
const beforeEvidence = await timings.measure("transfer remote head", () => backend.readHead(options.signal));
|
|
@@ -547,7 +551,7 @@ export async function mergeSync(
|
|
|
547
551
|
remoteBefore: rawRemote,
|
|
548
552
|
remoteAfter: upload,
|
|
549
553
|
publish,
|
|
550
|
-
sessions: config
|
|
554
|
+
sessions: syncSessionsSelected(config),
|
|
551
555
|
groups,
|
|
552
556
|
decisions: plan.decisions,
|
|
553
557
|
capability: backend.capability,
|
|
@@ -718,7 +722,7 @@ async function completeJournal(
|
|
|
718
722
|
"Merge journal belongs to a different setup, selection or local-field policy; preserve it for reviewed recovery.",
|
|
719
723
|
);
|
|
720
724
|
await validate();
|
|
721
|
-
const sessionRoot = config
|
|
725
|
+
const sessionRoot = syncSessionsSelected(config) ? await effectiveSessionRoot(ctx) : undefined;
|
|
722
726
|
await validate();
|
|
723
727
|
if (sessionRoot !== undefined && journal.sessionRoot !== sessionRoot) {
|
|
724
728
|
throw new Error(
|
|
@@ -810,11 +814,11 @@ async function completeJournal(
|
|
|
810
814
|
if (syncStateFingerprint(state) !== journal.stateIdentity) {
|
|
811
815
|
throw new Error("Sync baseline changed after the interrupted merge; preserve its journal and review recovery.");
|
|
812
816
|
}
|
|
813
|
-
if (inspectRemoteSelection(config.include, observed).kind !== "same")
|
|
817
|
+
if (inspectRemoteSelection(config.include, observed, config.exclude).kind !== "same")
|
|
814
818
|
throw new Error(
|
|
815
819
|
"Pending merge has unavailable remote selection metadata; preserve its journal and choose a reviewed explicit direction.",
|
|
816
820
|
);
|
|
817
|
-
if (config
|
|
821
|
+
if (syncSessionsSelected(config)) requireStableMergeSessionRoot(journal.before, journal.after);
|
|
818
822
|
await validate();
|
|
819
823
|
const validateOwner = captureMutationOwner(ctx, signal);
|
|
820
824
|
const validateMutation = () => {
|
|
@@ -894,6 +898,7 @@ function acceptedState(
|
|
|
894
898
|
lastRemoteRevision: head.revision,
|
|
895
899
|
lastFileHashes: fileHashMap(canonical ? portableSnapshot(snapshot, config.localFields) : snapshot),
|
|
896
900
|
include: [...config.include],
|
|
901
|
+
...(config.exclude === undefined ? {} : { exclude: [...config.exclude] }),
|
|
897
902
|
...(config.localFields !== undefined ? { localFields: config.localFields } : {}),
|
|
898
903
|
};
|
|
899
904
|
}
|
|
@@ -46,6 +46,7 @@ export function progressState(
|
|
|
46
46
|
profile: config.snapshotIdentity,
|
|
47
47
|
lastFileHashes: hashes,
|
|
48
48
|
include: [...config.include],
|
|
49
|
+
exclude: config.exclude === undefined ? undefined : [...config.exclude],
|
|
49
50
|
localFields: config.localFields,
|
|
50
51
|
lastObservedSnapshot: head.snapshotId,
|
|
51
52
|
lastObservedRevision: head.revision,
|
|
@@ -10,8 +10,7 @@ import {
|
|
|
10
10
|
inspectRemoteSelection,
|
|
11
11
|
type RemoteSelectionState,
|
|
12
12
|
remoteSelectionMismatch,
|
|
13
|
-
|
|
14
|
-
snapshotSelectionInclude,
|
|
13
|
+
sameSnapshotSelection,
|
|
15
14
|
} from "./sync-policy.js";
|
|
16
15
|
|
|
17
16
|
export async function readSnapshotForHead(backend: SyncBackend, head: RemoteHead, signal?: AbortSignal) {
|
|
@@ -22,8 +21,7 @@ export async function readSnapshotForHead(backend: SyncBackend, head: RemoteHead
|
|
|
22
21
|
throw new Error(`Remote head ${head.snapshotId} resolved to unexpected snapshot ${snapshot.id}.`);
|
|
23
22
|
}
|
|
24
23
|
if (head.selection) {
|
|
25
|
-
|
|
26
|
-
if (!snapshotInclude || !sameSyncInclude(head.selection.include, snapshotInclude)) {
|
|
24
|
+
if (!sameSnapshotSelection(head.selection, snapshot.selection)) {
|
|
27
25
|
throw new Error("Remote head selection does not match its immutable snapshot.");
|
|
28
26
|
}
|
|
29
27
|
}
|
|
@@ -35,9 +33,9 @@ export function requireCompatibleRemoteSelection(config: AnySyncConfig, snapshot
|
|
|
35
33
|
throw new Error(
|
|
36
34
|
"Remote local-field policy differs; confirm a reviewed directional migration. Old history is not erased.",
|
|
37
35
|
);
|
|
38
|
-
const state = inspectRemoteSelection(config.include, snapshot);
|
|
36
|
+
const state = inspectRemoteSelection(config.include, snapshot, config.exclude);
|
|
39
37
|
if (state.kind === "different") {
|
|
40
|
-
throw remoteSelectionMismatch(config, state.include, syncConfigReviewFingerprint(config));
|
|
38
|
+
throw remoteSelectionMismatch(config, state.include, syncConfigReviewFingerprint(config), state.exclude);
|
|
41
39
|
}
|
|
42
40
|
}
|
|
43
41
|
|
|
@@ -51,6 +49,7 @@ export function formatRemoteSelectionStatus(state: RemoteSelectionState | undefi
|
|
|
51
49
|
"remote included content: differs from this setup",
|
|
52
50
|
`remote-only selection: ${safeList(state.remoteOnly)}`,
|
|
53
51
|
`local-only selection: ${safeList(state.localOnly)}`,
|
|
52
|
+
`remote excluded paths: ${safeList(state.exclude ?? [])}`,
|
|
54
53
|
].join("\n");
|
|
55
54
|
}
|
|
56
55
|
|
|
@@ -67,10 +66,10 @@ export async function readRemoteSnapshot(
|
|
|
67
66
|
const head = await backend.readHead(signal);
|
|
68
67
|
if (!head) return { head: undefined, snapshot: undefined, selectionState: undefined };
|
|
69
68
|
const snapshot = await readSnapshotForHead(backend, head, signal);
|
|
70
|
-
const selectionState = inspectRemoteSelection(config.include, snapshot);
|
|
69
|
+
const selectionState = inspectRemoteSelection(config.include, snapshot, config.exclude);
|
|
71
70
|
if (!options.allowSelectionDifference && selectionState.kind === "different") {
|
|
72
71
|
const configIdentity = syncConfigReviewFingerprint(config);
|
|
73
|
-
throw remoteSelectionMismatch(config, selectionState.include, configIdentity);
|
|
72
|
+
throw remoteSelectionMismatch(config, selectionState.include, configIdentity, selectionState.exclude);
|
|
74
73
|
}
|
|
75
74
|
return {
|
|
76
75
|
head,
|
|
@@ -28,6 +28,8 @@ export interface SyncDecision {
|
|
|
28
28
|
};
|
|
29
29
|
previousInclude?: readonly string[];
|
|
30
30
|
currentInclude: readonly string[];
|
|
31
|
+
previousExclude?: readonly string[];
|
|
32
|
+
currentExclude?: readonly string[];
|
|
31
33
|
review: string;
|
|
32
34
|
directions: readonly SyncResolutionDirection[];
|
|
33
35
|
directMessage: string;
|
|
@@ -80,7 +82,13 @@ export function createSyncDecision(options: CreateSyncDecisionOptions) {
|
|
|
80
82
|
"Why a decision is required:",
|
|
81
83
|
...causeLines,
|
|
82
84
|
...(policyChanged
|
|
83
|
-
? [
|
|
85
|
+
? [
|
|
86
|
+
"",
|
|
87
|
+
`Previously included: ${safeList(previousInclude)}`,
|
|
88
|
+
`Currently included: ${safeList(currentInclude)}`,
|
|
89
|
+
`Previously excluded: ${safeList(state.exclude ?? [])}`,
|
|
90
|
+
`Currently excluded: ${safeList(config.exclude ?? [])}`,
|
|
91
|
+
]
|
|
84
92
|
: []),
|
|
85
93
|
"",
|
|
86
94
|
"Observed differences:",
|
|
@@ -93,6 +101,8 @@ export function createSyncDecision(options: CreateSyncDecisionOptions) {
|
|
|
93
101
|
causes,
|
|
94
102
|
...(policyChanged ? { previousInclude: [...previousInclude] } : {}),
|
|
95
103
|
currentInclude,
|
|
104
|
+
...(policyChanged && state.exclude !== undefined ? { previousExclude: [...state.exclude] } : {}),
|
|
105
|
+
...(config.exclude === undefined ? {} : { currentExclude: [...config.exclude] }),
|
|
96
106
|
review,
|
|
97
107
|
directions: kind === "remote-empty" ? ["push"] : ["push", "pull"],
|
|
98
108
|
directMessage: options.directMessage,
|
|
@@ -36,7 +36,9 @@ export async function inspectSync(
|
|
|
36
36
|
return {
|
|
37
37
|
...freshness,
|
|
38
38
|
head,
|
|
39
|
-
selectionState: head
|
|
39
|
+
selectionState: head
|
|
40
|
+
? inspectRemoteSelection(config.include, { selection: head.selection, files: [] }, config.exclude)
|
|
41
|
+
: undefined,
|
|
40
42
|
localFiles: local.files.length,
|
|
41
43
|
localChanged: hasLocalChanges(local, state, config),
|
|
42
44
|
remoteChanged: remoteChangedSinceState(head, state, config, (left, right) => backend.sameRevision(left, right)),
|
|
@@ -44,7 +44,7 @@ import { createSyncDecision } from "./sync-decision.js";
|
|
|
44
44
|
import { errorMessage } from "./sync-errors.js";
|
|
45
45
|
|
|
46
46
|
import { backupLocal, captureMutationOwner, protectedSessionPaths } from "./sync-local.js";
|
|
47
|
-
import { inspectRemoteSelection } from "./sync-policy.js";
|
|
47
|
+
import { inspectRemoteSelection, syncSessionsSelected } from "./sync-policy.js";
|
|
48
48
|
import {
|
|
49
49
|
canPullRemoteSessionsOnFirstSync,
|
|
50
50
|
canPullRemoteSettingsOnFirstSync,
|
|
@@ -132,7 +132,8 @@ export async function push(
|
|
|
132
132
|
!options.force &&
|
|
133
133
|
!remoteForUpload &&
|
|
134
134
|
head?.selection &&
|
|
135
|
-
inspectRemoteSelection(config.include, { selection: head.selection, files: [] }).kind ===
|
|
135
|
+
inspectRemoteSelection(config.include, { selection: head.selection, files: [] }, config.exclude).kind ===
|
|
136
|
+
"different"
|
|
136
137
|
) {
|
|
137
138
|
remoteForUpload = await readSnapshotForHead(backend, head, options.signal);
|
|
138
139
|
}
|
|
@@ -235,6 +236,7 @@ export async function push(
|
|
|
235
236
|
lastRemoteRevision: result.head.revision,
|
|
236
237
|
lastFileHashes: fileHashMap(local),
|
|
237
238
|
include: [...config.include],
|
|
239
|
+
...(config.exclude === undefined ? {} : { exclude: [...config.exclude] }),
|
|
238
240
|
...(config.localFields !== undefined ? { localFields: config.localFields } : {}),
|
|
239
241
|
},
|
|
240
242
|
local,
|
|
@@ -380,6 +382,7 @@ export async function pull(
|
|
|
380
382
|
options.onCommit?.();
|
|
381
383
|
const lastFileHashes = await applySnapshot(physical, protectedSessionPaths(ctx), {
|
|
382
384
|
include: config.include,
|
|
385
|
+
...(config.exclude === undefined ? {} : { exclude: [...config.exclude] }),
|
|
383
386
|
sessionDir: applySessionDir,
|
|
384
387
|
signal: options.signal,
|
|
385
388
|
validateMutation,
|
|
@@ -400,6 +403,7 @@ export async function pull(
|
|
|
400
403
|
? { ...lastFileHashes, "settings.json": fileHashMap(logical)["settings.json"] }
|
|
401
404
|
: lastFileHashes,
|
|
402
405
|
include: [...config.include],
|
|
406
|
+
...(config.exclude === undefined ? {} : { exclude: [...config.exclude] }),
|
|
403
407
|
...(config.localFields !== undefined ? { localFields: config.localFields } : {}),
|
|
404
408
|
},
|
|
405
409
|
logical,
|
|
@@ -412,7 +416,7 @@ export async function pull(
|
|
|
412
416
|
setSyncStatus(ctx, undefined);
|
|
413
417
|
if (!options.silent) {
|
|
414
418
|
ctx.ui.notify(`Pulled ${remote.files.length} files from ${remote.id}. Backup: ${backup}`, "info");
|
|
415
|
-
} else if (options.auto && config
|
|
419
|
+
} else if (options.auto && syncSessionsSelected(config) && snapshotIncludesSessions(remote)) {
|
|
416
420
|
ctx.ui.notify(
|
|
417
421
|
"Pulled Pi sessions after startup selected the current session. Restart Pi or resume a pulled session to use newly synced conversations.",
|
|
418
422
|
"warning",
|
|
@@ -481,6 +485,7 @@ export async function syncBoth(
|
|
|
481
485
|
lastRemoteRevision: head?.revision,
|
|
482
486
|
lastFileHashes: fileHashMap(accepted),
|
|
483
487
|
include: [...config.include],
|
|
488
|
+
...(config.exclude === undefined ? {} : { exclude: [...config.exclude] }),
|
|
484
489
|
...(config.localFields !== undefined ? { localFields: config.localFields } : {}),
|
|
485
490
|
},
|
|
486
491
|
accepted,
|
|
@@ -583,7 +588,7 @@ export async function rollback(
|
|
|
583
588
|
"Rollback requires the historical snapshot local-field policy to match the configured rules. Review push --force from current local bytes to migrate policy first; choose matching history afterward.",
|
|
584
589
|
);
|
|
585
590
|
const selected = filterSnapshotForConfigPolicy(
|
|
586
|
-
config
|
|
591
|
+
syncSessionsSelected(config) ? decoded : snapshotWithoutSessions(decoded),
|
|
587
592
|
config,
|
|
588
593
|
);
|
|
589
594
|
const remote = portableSnapshot(regenerateSnapshotIdentity(selected), config.localFields);
|
|
@@ -639,6 +644,7 @@ export async function rollback(
|
|
|
639
644
|
options.onCommit?.();
|
|
640
645
|
const lastFileHashes = await applySnapshot(physical, protectedSessionPaths(ctx), {
|
|
641
646
|
include: config.include,
|
|
647
|
+
...(config.exclude === undefined ? {} : { exclude: [...config.exclude] }),
|
|
642
648
|
sessionDir: applySessionDir,
|
|
643
649
|
signal: options.signal,
|
|
644
650
|
validateMutation,
|
|
@@ -671,6 +677,7 @@ export async function rollback(
|
|
|
671
677
|
? { ...lastFileHashes, "settings.json": fileHashMap(remote)["settings.json"] }
|
|
672
678
|
: lastFileHashes,
|
|
673
679
|
include: [...config.include],
|
|
680
|
+
...(config.exclude === undefined ? {} : { exclude: [...config.exclude] }),
|
|
674
681
|
...(config.localFields !== undefined ? { localFields: config.localFields } : {}),
|
|
675
682
|
},
|
|
676
683
|
remote,
|
package/src/sync/sync-policy.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { isDeniedPath, toPosix } from "../paths.js";
|
|
3
3
|
import type { Snapshot, SnapshotSelection } from "../snapshot/snapshot-types.js";
|
|
4
|
+
import { compileSyncExclude, normalizeSyncExclude, sameSyncExclude } from "./exclude-policy.js";
|
|
4
5
|
|
|
5
6
|
export const BUILT_IN_SYNC_ROOTS = [
|
|
6
7
|
"settings.json",
|
|
@@ -16,7 +17,6 @@ export const BUILT_IN_SYNC_ROOTS = [
|
|
|
16
17
|
|
|
17
18
|
export const DEFAULT_SYNC_INCLUDE = [...BUILT_IN_SYNC_ROOTS] as const;
|
|
18
19
|
export type BuiltInSyncFile = (typeof BUILT_IN_SYNC_ROOTS)[number];
|
|
19
|
-
const SNAPSHOT_SELECTION_VERSION = 1;
|
|
20
20
|
const MAX_SYNC_INCLUDE_ITEMS = 1_024;
|
|
21
21
|
const MAX_SYNC_INCLUDE_PATH_BYTES = 4_096;
|
|
22
22
|
const MAX_SYNC_INCLUDE_TOTAL_BYTES = 256 * 1_024;
|
|
@@ -131,24 +131,47 @@ export function portableSnapshotSelection(value: unknown): SnapshotSelection {
|
|
|
131
131
|
!selection ||
|
|
132
132
|
typeof selection !== "object" ||
|
|
133
133
|
Array.isArray(selection) ||
|
|
134
|
-
selection.version !==
|
|
134
|
+
(selection.version !== 1 && selection.version !== 2) ||
|
|
135
135
|
!Object.hasOwn(selection, "include") ||
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
(selection.version === 2 && !Object.hasOwn(selection, "exclude")) ||
|
|
137
|
+
Object.keys(selection).some(
|
|
138
|
+
(key) => key !== "version" && key !== "include" && !(selection.version === 2 && key === "exclude"),
|
|
139
|
+
)
|
|
140
|
+
)
|
|
138
141
|
throw new Error("Invalid snapshot selection policy.");
|
|
139
|
-
|
|
140
|
-
return {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
};
|
|
142
|
+
const include = normalizeSyncInclude(selection.include);
|
|
143
|
+
if (selection.version === 1) return { version: 1, include };
|
|
144
|
+
if (!Array.isArray(selection.exclude)) throw new Error("Invalid snapshot exclude policy.");
|
|
145
|
+
return { version: 2, include, exclude: normalizeSyncExclude(selection.exclude) };
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
export function snapshotSelectionInclude(snapshot: Pick<Snapshot, "selection">) {
|
|
147
149
|
return snapshot.selection === undefined ? undefined : portableSnapshotSelection(snapshot.selection).include;
|
|
148
150
|
}
|
|
149
151
|
|
|
150
|
-
export function
|
|
151
|
-
return
|
|
152
|
+
export function snapshotSelectionExclude(snapshot: Pick<Snapshot, "selection">) {
|
|
153
|
+
return snapshot.selection === undefined ? undefined : portableSnapshotSelection(snapshot.selection).exclude;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function selectionForSnapshot(include: unknown, exclude?: unknown): SnapshotSelection {
|
|
157
|
+
const normalized = normalizeSyncInclude(include);
|
|
158
|
+
return exclude === undefined
|
|
159
|
+
? { version: 1, include: normalized }
|
|
160
|
+
: { version: 2, include: normalized, exclude: normalizeSyncExclude(exclude) };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Metadata equality, not policy compatibility: bind the whole projection to its immutable image. */
|
|
164
|
+
export function sameSnapshotSelection(left: SnapshotSelection | undefined, right: SnapshotSelection | undefined) {
|
|
165
|
+
return (
|
|
166
|
+
JSON.stringify(left === undefined ? null : portableSnapshotSelection(left)) ===
|
|
167
|
+
JSON.stringify(right === undefined ? null : portableSnapshotSelection(right))
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function validateSnapshotSelection(snapshot: Pick<Snapshot, "version" | "selection">) {
|
|
172
|
+
const selection = snapshot.selection === undefined ? undefined : portableSnapshotSelection(snapshot.selection);
|
|
173
|
+
if ((snapshot.version === 4) !== (selection?.version === 2))
|
|
174
|
+
throw new Error("Exclude policy requires snapshot version 4 and selection version 2.");
|
|
152
175
|
}
|
|
153
176
|
|
|
154
177
|
export function sameSyncInclude(left: unknown, right: unknown) {
|
|
@@ -174,26 +197,35 @@ export function compareSyncInclude(local: unknown, remote: unknown) {
|
|
|
174
197
|
|
|
175
198
|
export type RemoteSelectionState =
|
|
176
199
|
| { kind: "legacy"; discovered: string[] }
|
|
177
|
-
| { kind: "same"; include: string[] }
|
|
200
|
+
| { kind: "same"; include: string[]; exclude?: string[] }
|
|
178
201
|
| {
|
|
179
202
|
kind: "different";
|
|
180
203
|
include: string[];
|
|
204
|
+
exclude?: string[];
|
|
181
205
|
remoteOnly: string[];
|
|
182
206
|
localOnly: string[];
|
|
207
|
+
excludeChanged?: boolean;
|
|
183
208
|
};
|
|
184
209
|
|
|
185
210
|
export function inspectRemoteSelection(
|
|
186
211
|
localInclude: unknown,
|
|
187
212
|
snapshot: Pick<Snapshot, "selection" | "files">,
|
|
213
|
+
localExclude?: unknown,
|
|
188
214
|
): RemoteSelectionState {
|
|
189
215
|
const remoteInclude = snapshotSelectionInclude(snapshot);
|
|
190
|
-
if (!remoteInclude) {
|
|
191
|
-
|
|
192
|
-
}
|
|
216
|
+
if (!remoteInclude) return { kind: "legacy", discovered: discoverLegacySnapshotInclude(snapshot) };
|
|
217
|
+
const exclude = snapshotSelectionExclude(snapshot);
|
|
193
218
|
const comparison = compareSyncInclude(localInclude, remoteInclude);
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
219
|
+
const rules = exclude === undefined ? {} : { exclude };
|
|
220
|
+
return comparison.same && sameSyncExclude(localExclude, exclude)
|
|
221
|
+
? { kind: "same", include: remoteInclude, ...rules }
|
|
222
|
+
: {
|
|
223
|
+
kind: "different",
|
|
224
|
+
include: remoteInclude,
|
|
225
|
+
...comparison,
|
|
226
|
+
...rules,
|
|
227
|
+
...(!sameSyncExclude(localExclude, exclude) ? { excludeChanged: true } : {}),
|
|
228
|
+
};
|
|
197
229
|
}
|
|
198
230
|
|
|
199
231
|
export interface RemoteSelectionDecision {
|
|
@@ -201,6 +233,8 @@ export interface RemoteSelectionDecision {
|
|
|
201
233
|
configIdentity: string;
|
|
202
234
|
localInclude: readonly string[];
|
|
203
235
|
remoteInclude: readonly string[];
|
|
236
|
+
localExclude?: readonly string[];
|
|
237
|
+
remoteExclude?: readonly string[];
|
|
204
238
|
}
|
|
205
239
|
|
|
206
240
|
export class RemoteSelectionMismatchError extends Error {
|
|
@@ -214,10 +248,12 @@ export class RemoteSelectionMismatchError extends Error {
|
|
|
214
248
|
localInclude: unknown,
|
|
215
249
|
remoteInclude: unknown,
|
|
216
250
|
configIdentity = JSON.stringify([setupName, normalizeSyncInclude(localInclude)]),
|
|
251
|
+
localExclude?: string[],
|
|
252
|
+
remoteExclude?: string[],
|
|
217
253
|
) {
|
|
218
254
|
const local = normalizeSyncInclude(localInclude);
|
|
219
255
|
const remote = normalizeSyncInclude(remoteInclude);
|
|
220
|
-
super(formatRemoteSelectionMismatch(setupName, local, remote));
|
|
256
|
+
super(formatRemoteSelectionMismatch(setupName, local, remote, localExclude, remoteExclude));
|
|
221
257
|
this.name = "RemoteSelectionMismatchError";
|
|
222
258
|
this.setupName = setupName;
|
|
223
259
|
this.localInclude = local;
|
|
@@ -227,22 +263,34 @@ export class RemoteSelectionMismatchError extends Error {
|
|
|
227
263
|
configIdentity,
|
|
228
264
|
localInclude: [...local],
|
|
229
265
|
remoteInclude: [...remote],
|
|
266
|
+
...(localExclude === undefined ? {} : { localExclude: normalizeSyncExclude(localExclude) }),
|
|
267
|
+
...(remoteExclude === undefined ? {} : { remoteExclude: normalizeSyncExclude(remoteExclude) }),
|
|
230
268
|
};
|
|
231
269
|
}
|
|
232
270
|
}
|
|
233
271
|
|
|
234
272
|
export function remoteSelectionMismatch(
|
|
235
|
-
config: { setupName: string; include: unknown },
|
|
273
|
+
config: { setupName: string; include: unknown; exclude?: string[] },
|
|
236
274
|
remoteInclude: unknown,
|
|
237
275
|
configIdentity?: string,
|
|
276
|
+
remoteExclude?: string[],
|
|
238
277
|
) {
|
|
239
|
-
return new RemoteSelectionMismatchError(
|
|
278
|
+
return new RemoteSelectionMismatchError(
|
|
279
|
+
config.setupName,
|
|
280
|
+
config.include,
|
|
281
|
+
remoteInclude,
|
|
282
|
+
configIdentity,
|
|
283
|
+
config.exclude,
|
|
284
|
+
remoteExclude,
|
|
285
|
+
);
|
|
240
286
|
}
|
|
241
287
|
|
|
242
288
|
export function formatRemoteSelectionMismatch(
|
|
243
289
|
setupName: string,
|
|
244
290
|
localInclude: readonly string[],
|
|
245
291
|
remoteInclude: readonly string[],
|
|
292
|
+
localExclude?: readonly string[],
|
|
293
|
+
remoteExclude?: readonly string[],
|
|
246
294
|
) {
|
|
247
295
|
const comparison = compareSyncInclude(localInclude, remoteInclude);
|
|
248
296
|
const lines = [
|
|
@@ -250,7 +298,12 @@ export function formatRemoteSelectionMismatch(
|
|
|
250
298
|
`Remote-only: ${comparison.remoteOnly.join(", ") || "none"}`,
|
|
251
299
|
`This-device-only: ${comparison.localOnly.join(", ") || "none"}`,
|
|
252
300
|
];
|
|
253
|
-
if (
|
|
301
|
+
if (!sameSyncExclude(localExclude, remoteExclude)) {
|
|
302
|
+
lines.push(
|
|
303
|
+
`Remote excluded paths: ${normalizeSyncExclude(remoteExclude).join(", ") || "none"}`,
|
|
304
|
+
`This device excluded paths: ${normalizeSyncExclude(localExclude).join(", ") || "none"}`,
|
|
305
|
+
);
|
|
306
|
+
} else if (comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0) {
|
|
254
307
|
lines.push(
|
|
255
308
|
"Only ordering differs.",
|
|
256
309
|
`Remote order: ${remoteInclude.join(", ") || "none"}`,
|
|
@@ -321,6 +374,7 @@ export function customIncludePathsByLower(value: unknown) {
|
|
|
321
374
|
|
|
322
375
|
export interface SyncSelectionConfig {
|
|
323
376
|
include?: unknown;
|
|
377
|
+
exclude?: unknown;
|
|
324
378
|
syncFiles?: unknown;
|
|
325
379
|
syncSessions?: boolean;
|
|
326
380
|
extraFiles?: unknown;
|
|
@@ -335,27 +389,37 @@ export function includeFromSelectionConfig(config: SyncSelectionConfig) {
|
|
|
335
389
|
];
|
|
336
390
|
}
|
|
337
391
|
|
|
392
|
+
export function syncSessionsSelected(config: SyncSelectionConfig) {
|
|
393
|
+
return includeFromSelectionConfig(config).includes("sessions") && !compileSyncExclude(config.exclude)("sessions");
|
|
394
|
+
}
|
|
395
|
+
|
|
338
396
|
export function isConfiguredSnapshotPath(
|
|
339
397
|
relativePath: string,
|
|
340
398
|
config: SyncSelectionConfig,
|
|
341
399
|
_legacyExtraFiles?: Set<string>,
|
|
342
400
|
) {
|
|
343
|
-
|
|
401
|
+
return configuredSnapshotPathMatcher(config)(relativePath);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export function configuredSnapshotPathMatcher(config: SyncSelectionConfig) {
|
|
344
405
|
const selection = syncIncludeSelection(includeFromSelectionConfig(config));
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
if (
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
return
|
|
358
|
-
|
|
406
|
+
const excluded = compileSyncExclude(config.exclude);
|
|
407
|
+
return (relativePath: string) => {
|
|
408
|
+
const normalized = toPosix(relativePath);
|
|
409
|
+
if (excluded(normalized)) return false;
|
|
410
|
+
if (normalized.startsWith("sessions/")) return selection.sessions;
|
|
411
|
+
const lower = normalized.toLowerCase();
|
|
412
|
+
if (!normalized.includes("/")) {
|
|
413
|
+
const builtIn = BUILT_IN_BY_LOWER.get(lower);
|
|
414
|
+
if (builtIn) return selection.builtIns.includes(builtIn) && !TOP_LEVEL_DIRS.has(builtIn);
|
|
415
|
+
}
|
|
416
|
+
const topLevel = normalized.slice(0, normalized.indexOf("/"));
|
|
417
|
+
if (selection.builtIns.includes(topLevel as BuiltInSyncFile) && TOP_LEVEL_DIRS.has(topLevel)) return true;
|
|
418
|
+
return selection.custom.some((candidate) => {
|
|
419
|
+
const key = candidate.toLowerCase();
|
|
420
|
+
return lower === key || lower.startsWith(`${key}/`);
|
|
421
|
+
});
|
|
422
|
+
};
|
|
359
423
|
}
|
|
360
424
|
|
|
361
425
|
export function canonicalSnapshotPathForConfig(relativePath: string, includePaths: Map<string, string>) {
|
package/src/sync/sync-queries.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { throwIfAborted } from "./signals.js";
|
|
|
17
17
|
import { errorMessage } from "./sync-errors.js";
|
|
18
18
|
import { inspectSync } from "./sync-inspection.js";
|
|
19
19
|
import { rollback } from "./sync-mutations.js";
|
|
20
|
+
import { syncSessionsSelected } from "./sync-policy.js";
|
|
20
21
|
|
|
21
22
|
const DEFAULT_PROFILE = "default";
|
|
22
23
|
|
|
@@ -50,7 +51,10 @@ export async function status(
|
|
|
50
51
|
`storage location: ${safeTerminalText(destination)}`,
|
|
51
52
|
`publication safety: ${publicationCapabilityDescription(capability)}`,
|
|
52
53
|
`included content: ${config.include.join(", ") || "none"}`,
|
|
53
|
-
|
|
54
|
+
...(config.exclude === undefined
|
|
55
|
+
? []
|
|
56
|
+
: [`excluded paths: ${config.exclude.map(safeTerminalText).join(", ") || "none"}`]),
|
|
57
|
+
`sessions: ${syncSessionsSelected(config) ? "included" : "excluded"}`,
|
|
54
58
|
...continuous,
|
|
55
59
|
remoteText,
|
|
56
60
|
formatRemoteSelectionStatus(selectionState),
|
|
@@ -89,7 +93,10 @@ export async function diff(
|
|
|
89
93
|
`storage connection: ${config.connectionName}`,
|
|
90
94
|
`storage location: ${safeTerminalText(backend.destination)}`,
|
|
91
95
|
`included content: ${config.include.join(", ") || "none"}`,
|
|
92
|
-
|
|
96
|
+
...(config.exclude === undefined
|
|
97
|
+
? []
|
|
98
|
+
: [`excluded paths: ${config.exclude.map(safeTerminalText).join(", ") || "none"}`]),
|
|
99
|
+
`sessions: ${syncSessionsSelected(config) ? "included" : "excluded"}`,
|
|
93
100
|
formatRemoteSelectionStatus(selectionState),
|
|
94
101
|
...warnings,
|
|
95
102
|
].join("\n");
|
|
@@ -123,7 +130,10 @@ export async function doctor(
|
|
|
123
130
|
messages.push(
|
|
124
131
|
`config: ok (sync setup ${config.setupName})`,
|
|
125
132
|
`included content: ${config.include.join(", ") || "none"}`,
|
|
126
|
-
|
|
133
|
+
...(config.exclude === undefined
|
|
134
|
+
? []
|
|
135
|
+
: [`excluded paths: ${config.exclude.map(safeTerminalText).join(", ") || "none"}`]),
|
|
136
|
+
`sessions: ${syncSessionsSelected(config) ? "included" : "excluded"}`,
|
|
127
137
|
);
|
|
128
138
|
backendSummary = [
|
|
129
139
|
`storage location: ${safeTerminalText(backend.destination)}`,
|
package/src/sync/sync-state.ts
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import type { RemoteHead } from "../backends/sync-backend.js";
|
|
2
2
|
import { toPosix } from "../paths.js";
|
|
3
|
-
import {
|
|
4
|
-
canonicalSnapshotPathForConfig,
|
|
5
|
-
filterSnapshotForConfigPolicy,
|
|
6
|
-
isConfiguredSnapshotPath,
|
|
7
|
-
isSessionPath,
|
|
8
|
-
} from "../snapshot/snapshot.js";
|
|
3
|
+
import { canonicalSnapshotPathForConfig, filterSnapshotForConfigPolicy, isSessionPath } from "../snapshot/snapshot.js";
|
|
9
4
|
import type { Snapshot } from "../snapshot/snapshot-types.js";
|
|
10
5
|
import type { SyncState } from "../state/state-types.js";
|
|
6
|
+
import { sameSyncExclude } from "./exclude-policy.js";
|
|
11
7
|
import { portableSnapshot, sameLocalFields } from "./local-fields.js";
|
|
12
8
|
import {
|
|
9
|
+
configuredSnapshotPathMatcher,
|
|
13
10
|
customIncludePathsByLower,
|
|
14
11
|
includeFromSelectionConfig,
|
|
15
12
|
normalizeSyncInclude,
|
|
16
13
|
type SyncSelectionConfig,
|
|
14
|
+
syncSessionsSelected,
|
|
17
15
|
} from "./sync-policy.js";
|
|
18
16
|
|
|
19
17
|
type SyncPolicyConfig = SyncSelectionConfig & { localFields?: string[] };
|
|
20
18
|
|
|
21
19
|
export function hasLocalChanges(local: Snapshot, state: SyncState, config: SyncPolicyConfig) {
|
|
22
20
|
return (
|
|
23
|
-
(Boolean(state.lastAppliedSnapshot) &&
|
|
21
|
+
(Boolean(state.lastAppliedSnapshot) &&
|
|
22
|
+
(!sameLocalFields(state.localFields, config.localFields) || !sameSyncExclude(state.exclude, config.exclude))) ||
|
|
24
23
|
!sameHashes(fileHashMap(portableSnapshot(local, config.localFields)), stateHashMapForConfig(state, config))
|
|
25
24
|
);
|
|
26
25
|
}
|
|
@@ -36,7 +35,9 @@ export function remoteChangedSinceState(
|
|
|
36
35
|
if (state.lastRemoteRevision && !sameRevision(head.revision, state.lastRemoteRevision)) return true;
|
|
37
36
|
if (syncPolicyChanged(state, config)) return true;
|
|
38
37
|
return (
|
|
39
|
-
|
|
38
|
+
syncSessionsSelected(config) &&
|
|
39
|
+
(!state.include?.includes("sessions") || !syncSessionsSelected(state)) &&
|
|
40
|
+
head.syncSessions
|
|
40
41
|
);
|
|
41
42
|
}
|
|
42
43
|
|
|
@@ -67,9 +68,10 @@ export function fileHashMap(snapshot: Snapshot) {
|
|
|
67
68
|
|
|
68
69
|
function stateHashMapForConfig(state: SyncState, config: SyncPolicyConfig) {
|
|
69
70
|
const includePaths = customIncludePathsByLower(includeFromSelectionConfig(config));
|
|
71
|
+
const configured = configuredSnapshotPathMatcher(config);
|
|
70
72
|
return Object.fromEntries(
|
|
71
73
|
Object.entries(state.lastFileHashes)
|
|
72
|
-
.filter(([filePath]) =>
|
|
74
|
+
.filter(([filePath]) => configured(filePath))
|
|
73
75
|
.map(([filePath, hash]) => [canonicalSnapshotPathForConfig(filePath, includePaths), hash]),
|
|
74
76
|
);
|
|
75
77
|
}
|
|
@@ -96,7 +98,11 @@ function withoutHashPaths(hashes: Record<string, string>, ignoredPaths: Set<stri
|
|
|
96
98
|
}
|
|
97
99
|
|
|
98
100
|
export function syncPolicyChanged(state: SyncState, config: SyncPolicyConfig) {
|
|
99
|
-
return
|
|
101
|
+
return (
|
|
102
|
+
syncIncludeChanged(state, config) ||
|
|
103
|
+
!sameSyncExclude(state.exclude, config.exclude) ||
|
|
104
|
+
!sameLocalFields(state.localFields, config.localFields)
|
|
105
|
+
);
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
export function shouldRefreshSyncedState(
|