@narumitw/pi-sync 0.67.2 → 0.68.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 +17 -0
- package/README.md +29 -49
- package/dist/chunks/{chunk-XUZV4OGI.ts → chunk-335XTMMZ.ts} +3 -2
- package/dist/chunks/{chunk-XUZV4OGI.ts.map → chunk-335XTMMZ.ts.map} +2 -2
- package/dist/chunks/{chunk-PUSMSKIM.ts → chunk-AYGMIMCV.ts} +2 -11
- package/dist/chunks/chunk-AYGMIMCV.ts.map +7 -0
- package/dist/chunks/{chunk-2MSJDLSM.ts → chunk-BCDBT4X3.ts} +7 -7
- package/dist/chunks/{chunk-GRXNUC6O.ts → chunk-FQKWGVMA.ts} +20 -54
- package/dist/chunks/chunk-FQKWGVMA.ts.map +7 -0
- package/dist/chunks/{chunk-DGVZYS7T.ts → chunk-FR6A7ASZ.ts} +8 -11
- package/dist/chunks/chunk-FR6A7ASZ.ts.map +7 -0
- package/dist/chunks/{chunk-3NS4PMCI.ts → chunk-J52GYZO6.ts} +2 -8
- package/dist/chunks/{chunk-3NS4PMCI.ts.map → chunk-J52GYZO6.ts.map} +2 -2
- package/dist/chunks/{chunk-2MUAR5GH.ts → chunk-KAIVTJIQ.ts} +7 -10
- package/dist/chunks/chunk-KAIVTJIQ.ts.map +7 -0
- package/dist/chunks/{chunk-WBIOSK76.ts → chunk-R7PN3KIY.ts} +1 -2
- package/dist/chunks/{chunk-3Q3DMMID.ts → chunk-TLYT6HVI.ts} +8 -8
- package/dist/chunks/{chunk-UF2HU2NM.ts → chunk-WCGLU526.ts} +39 -118
- package/dist/chunks/chunk-WCGLU526.ts.map +7 -0
- package/dist/chunks/{chunk-JREGWM2B.ts → chunk-XNUARYLR.ts} +1 -2
- package/dist/chunks/{chunk-C3E75DXW.ts → chunk-YV2R5SJU.ts} +73 -85
- package/dist/chunks/chunk-YV2R5SJU.ts.map +7 -0
- package/dist/chunks/{command-handler-HWRPH3K3.ts → command-handler-S6BRZMPW.ts} +117 -69
- package/dist/chunks/command-handler-S6BRZMPW.ts.map +7 -0
- package/dist/chunks/{conflict-review-OBBBSVQD.ts → conflict-review-3XMYDJIK.ts} +2 -2
- package/dist/chunks/{file-selection-GASCVN45.ts → file-selection-4BOQBXS7.ts} +10 -17
- package/dist/chunks/file-selection-4BOQBXS7.ts.map +7 -0
- package/dist/chunks/{manager-result-dispatcher-MJ6G2CEI.ts → manager-result-dispatcher-A4IWLS4J.ts} +7 -7
- package/dist/chunks/{manager-ui-Z3B5ZTA6.ts → manager-ui-KHMCSLLV.ts} +114 -581
- package/dist/chunks/manager-ui-KHMCSLLV.ts.map +7 -0
- package/dist/chunks/{chunk-ECUCXF5Y.ts → merge-review-LWMUE5IW.ts} +2 -3
- package/dist/chunks/{remote-selection-ui-34WC7OFE.ts → remote-selection-ui-F6NJBQ3Y.ts} +6 -6
- package/dist/chunks/{setup-switch-JZDFQPVW.ts → setup-switch-7LMIRMZ7.ts} +6 -6
- package/dist/chunks/{setup-wizard-YOXLXLBY.ts → setup-wizard-2NRPR433.ts} +11 -16
- package/dist/chunks/{setup-wizard-YOXLXLBY.ts.map → setup-wizard-2NRPR433.ts.map} +1 -1
- package/dist/chunks/{sync-inspection-NIITROKS.ts → sync-inspection-QGM54YCM.ts} +5 -5
- package/dist/chunks/{sync-operations-FFI4ZZQL.ts → sync-operations-DTQMKVRQ.ts} +2 -2
- package/dist/daemon/dist/build-id.json +1 -0
- package/dist/daemon/dist/build-version.js +24 -4
- package/dist/daemon/dist/cli.js +51 -67
- package/dist/daemon/dist/client-transport.js +15 -5
- package/dist/daemon/dist/client.js +2 -10
- package/dist/daemon/dist/consent.js +13 -126
- package/dist/daemon/dist/daemon-startup.js +135 -30
- package/dist/daemon/dist/daemon-status.js +56 -0
- package/dist/daemon/dist/engine/backends/git/git-backend.js +4 -17
- package/dist/daemon/dist/engine/backends/git/git-storage.js +11 -44
- package/dist/daemon/dist/engine/backends/s3/s3-backend.js +6 -6
- package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +6 -6
- package/dist/daemon/dist/engine/settings/config.js +16 -149
- package/dist/daemon/dist/engine/settings/retired-ignore-policy.js +16 -0
- package/dist/daemon/dist/engine/settings/retired-ignore-recovery.js +14 -0
- package/dist/daemon/dist/engine/settings/settings-management.js +2 -10
- package/dist/daemon/dist/engine/settings/settings-validation.js +8 -21
- package/dist/daemon/dist/engine/snapshot/session-paths.js +13 -41
- package/dist/daemon/dist/engine/snapshot/snapshot-apply.js +8 -24
- package/dist/daemon/dist/engine/snapshot/snapshot-codec.js +7 -11
- package/dist/daemon/dist/engine/snapshot/snapshot-exclude-safety.js +19 -76
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-images.js +1 -7
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-policy.js +8 -102
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction.js +20 -100
- package/dist/daemon/dist/engine/snapshot/snapshot-types.js +1 -11
- package/dist/daemon/dist/engine/snapshot/snapshot.js +26 -78
- package/dist/daemon/dist/engine/state/sync-state-store.js +5 -1
- package/dist/daemon/dist/engine/sync/agent-plan.js +0 -1
- package/dist/daemon/dist/engine/sync/agent-policy.js +1 -1
- package/dist/daemon/dist/engine/sync/conflict-review.js +0 -2
- package/dist/daemon/dist/engine/sync/continuous-sync.js +2 -17
- package/dist/daemon/dist/engine/sync/continuous-watch.js +3 -7
- package/dist/daemon/dist/engine/sync/directional-action.js +3 -21
- package/dist/daemon/dist/engine/sync/initialization.js +4 -15
- package/dist/daemon/dist/engine/sync/local-fields.js +4 -65
- package/dist/daemon/dist/engine/sync/merge-apply.js +8 -31
- package/dist/daemon/dist/engine/sync/merge-journal.js +8 -118
- package/dist/daemon/dist/engine/sync/merged-sync.js +13 -70
- package/dist/daemon/dist/engine/sync/push-review.js +1 -16
- package/dist/daemon/dist/engine/sync/remote-snapshot.js +48 -65
- package/dist/daemon/dist/engine/sync/startup-bootstrap.js +3 -3
- package/dist/daemon/dist/engine/sync/sync-error-guidance.js +1 -1
- package/dist/daemon/dist/engine/sync/sync-inspection.js +1 -2
- package/dist/daemon/dist/engine/sync/sync-mutations.js +26 -118
- package/dist/daemon/dist/engine/sync/sync-policy.js +26 -150
- package/dist/daemon/dist/engine/sync/sync-queries.js +1 -8
- package/dist/daemon/dist/engine/sync/sync-rollback.js +12 -50
- package/dist/daemon/dist/engine/sync/sync-state.js +2 -15
- package/dist/daemon/dist/engine/sync/transfer-freshness.js +7 -17
- package/dist/daemon/dist/engine/sync/transfer-size-limits.js +3 -7
- package/dist/daemon/dist/engine-service.js +62 -205
- package/dist/daemon/dist/foreground-queue-outcome.js +0 -4
- package/dist/daemon/dist/index.js +2 -0
- package/dist/daemon/dist/legacy-consent-guard.js +34 -0
- package/dist/daemon/dist/server.js +99 -11
- package/dist/daemon/dist/service-host.js +3 -9
- package/dist/daemon/package.json +1 -1
- package/dist/index.ts +49 -49
- package/dist/index.ts.map +3 -3
- package/docs/agent-continuous-hardening.md +2 -0
- package/docs/continuous-sync-verification.md +1 -1
- package/docs/daemon-migration.md +17 -15
- package/docs/tui-contract.md +4 -6
- package/package.json +2 -3
- package/skills/configure-pi-sync/SKILL.md +23 -78
- package/skills/configure-pi-sync/references/configuration.md +59 -76
- package/src/commands/command-execution.ts +15 -38
- package/src/commands/command-handler.ts +0 -4
- package/src/commands/command.ts +2 -1
- package/src/daemon/daemon-status-ui.ts +64 -0
- package/src/daemon/directional-recovery.ts +4 -33
- package/src/daemon/pi-client.ts +87 -94
- package/src/settings/config.ts +0 -1
- package/src/sync/setup-switch.ts +1 -4
- package/src/sync-extension.ts +14 -27
- package/src/ui/cancellable-operation.ts +2 -13
- package/src/ui/excluded-paths-ui.ts +1 -4
- package/src/ui/file-selection.ts +0 -5
- package/src/ui/manager-state.ts +12 -75
- package/src/ui/manager-ui.ts +7 -96
- package/src/ui/remote-selection-ui.ts +29 -130
- package/src/ui/settings-ui.ts +169 -388
- package/src/ui/setup/setup-actions.ts +4 -16
- package/src/ui/setup/setup-prompts.ts +12 -49
- package/src/ui/setup/setup-switcher.ts +8 -14
- package/src/ui/storage-connections-ui.ts +21 -32
- package/src/ui/sync-setups-ui.ts +27 -53
- package/dist/chunks/chunk-2MUAR5GH.ts.map +0 -7
- package/dist/chunks/chunk-C3E75DXW.ts.map +0 -7
- package/dist/chunks/chunk-DGVZYS7T.ts.map +0 -7
- package/dist/chunks/chunk-EJDDRS6O.ts +0 -17
- package/dist/chunks/chunk-EJDDRS6O.ts.map +0 -7
- package/dist/chunks/chunk-GRXNUC6O.ts.map +0 -7
- package/dist/chunks/chunk-I72HGZJJ.ts +0 -106
- package/dist/chunks/chunk-I72HGZJJ.ts.map +0 -7
- package/dist/chunks/chunk-KNEUL4XN.ts +0 -30
- package/dist/chunks/chunk-KNEUL4XN.ts.map +0 -7
- package/dist/chunks/chunk-PUSMSKIM.ts.map +0 -7
- package/dist/chunks/chunk-UF2HU2NM.ts.map +0 -7
- package/dist/chunks/chunk-WFBHWYI6.ts +0 -18
- package/dist/chunks/chunk-WFBHWYI6.ts.map +0 -7
- package/dist/chunks/command-handler-HWRPH3K3.ts.map +0 -7
- package/dist/chunks/config-P54GGMXY.ts +0 -39
- package/dist/chunks/continuous-record-3SKJ6I3V.ts +0 -23
- package/dist/chunks/continuous-record-3SKJ6I3V.ts.map +0 -7
- package/dist/chunks/continuous-storage-3EU6I7Z3.ts +0 -27
- package/dist/chunks/continuous-storage-3EU6I7Z3.ts.map +0 -7
- package/dist/chunks/file-selection-GASCVN45.ts.map +0 -7
- package/dist/chunks/ignore-file-ui-5BWA6LBC.ts +0 -21
- package/dist/chunks/manager-ui-Z3B5ZTA6.ts.map +0 -7
- package/dist/chunks/merge-review-C2KETZKY.ts +0 -11
- package/dist/chunks/merge-review-C2KETZKY.ts.map +0 -7
- package/dist/chunks/remote-selection-ui-34WC7OFE.ts.map +0 -7
- package/dist/chunks/setup-switch-JZDFQPVW.ts.map +0 -7
- package/dist/daemon/dist/engine/ignore/adoption-journal.js +0 -146
- package/dist/daemon/dist/engine/ignore/effective-ignore-policy.js +0 -33
- package/dist/daemon/dist/engine/ignore/ignore-edit.js +0 -102
- package/dist/daemon/dist/engine/ignore/ignore-initialization.js +0 -288
- package/dist/daemon/dist/engine/ignore/ignore-migration-prompt.js +0 -139
- package/dist/daemon/dist/engine/ignore/ignore-settings.js +0 -391
- package/dist/daemon/dist/engine/ignore/ignore-source.js +0 -250
- package/dist/daemon/dist/engine/ignore/snapshot-ignore-rules.js +0 -39
- package/dist/daemon/dist/engine/sync/ignore-adoption-recovery.js +0 -50
- package/dist/daemon/dist/engine/sync/ignore-adoption.js +0 -416
- package/dist/daemon/dist/engine/sync/ignore-publication.js +0 -23
- package/dist/daemon/dist/engine/ui/ignore-rule-preview.js +0 -18
- package/dist/daemon/dist/monitor.js +0 -344
- package/src/ui/agent-mode-setting.ts +0 -99
- package/src/ui/ignore-file-guidance.ts +0 -7
- package/src/ui/ignore-file-ui.ts +0 -105
- package/src/ui/ignore-migration-prompt.ts +0 -65
- package/src/ui/settings-review.ts +0 -26
- /package/dist/chunks/{chunk-2MSJDLSM.ts.map → chunk-BCDBT4X3.ts.map} +0 -0
- /package/dist/chunks/{chunk-WBIOSK76.ts.map → chunk-R7PN3KIY.ts.map} +0 -0
- /package/dist/chunks/{chunk-3Q3DMMID.ts.map → chunk-TLYT6HVI.ts.map} +0 -0
- /package/dist/chunks/{chunk-JREGWM2B.ts.map → chunk-XNUARYLR.ts.map} +0 -0
- /package/dist/chunks/{conflict-review-OBBBSVQD.ts.map → conflict-review-3XMYDJIK.ts.map} +0 -0
- /package/dist/chunks/{config-P54GGMXY.ts.map → manager-result-dispatcher-A4IWLS4J.ts.map} +0 -0
- /package/dist/chunks/{chunk-ECUCXF5Y.ts.map → merge-review-LWMUE5IW.ts.map} +0 -0
- /package/dist/chunks/{ignore-file-ui-5BWA6LBC.ts.map → remote-selection-ui-F6NJBQ3Y.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-MJ6G2CEI.ts.map → setup-switch-7LMIRMZ7.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-NIITROKS.ts.map → sync-inspection-QGM54YCM.ts.map} +0 -0
- /package/dist/chunks/{sync-operations-FFI4ZZQL.ts.map → sync-operations-DTQMKVRQ.ts.map} +0 -0
|
@@ -1,39 +1,30 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { documentFingerprint } from "../../document.js";
|
|
4
2
|
import { backendIdentityCoordinates } from "../backends/backend-identity.js";
|
|
5
3
|
import { normalizeGitBranch, normalizeGitDirectory, normalizeGitRemote } from "../backends/git/git-config.js";
|
|
6
4
|
import { normalizeWebDavPath, normalizeWebDavUrl } from "../backends/webdav/webdav-config.js";
|
|
7
|
-
import { engineHost, getEngineRoot } from "../host.js";
|
|
8
|
-
import { compileEffectiveIgnorePolicy } from "../ignore/effective-ignore-policy.js";
|
|
9
|
-
import { DEFAULT_IGNORE_FILENAME, readIgnoreSource, validateIgnoreFilename } from "../ignore/ignore-source.js";
|
|
10
5
|
import { normalizeSyncExclude } from "../sync/exclude-policy.js";
|
|
11
6
|
import { normalizeLocalFields } from "../sync/local-field-policy.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { readLocalConfigDocument
|
|
7
|
+
import { normalizeDirectoryRules, normalizeSyncInclude, syncDirectoryPolicyKey, syncSessionsSelected, } from "../sync/sync-policy.js";
|
|
8
|
+
import { localConfigPath, readActiveLocalConfigDocumentForRepair } from "./config-file.js";
|
|
9
|
+
import { assertNoRetiredRuleJournal } from "./retired-ignore-recovery.js";
|
|
10
|
+
import { readLocalConfigDocument } from "./settings-store.js";
|
|
16
11
|
import { DEFAULT_ON_SWITCH, isCloudflareR2Endpoint, normalizeS3Bucket, normalizeS3Endpoint, normalizeStoragePath, optionalString, ownObject, requiredString, validateConfigName, validateSettingsDocument, } from "./settings-validation.js";
|
|
17
12
|
export async function loadConfig(setupName, signal) {
|
|
18
13
|
signal?.throwIfAborted();
|
|
14
|
+
assertNoRetiredRuleJournal();
|
|
19
15
|
const document = await readLocalConfigDocument();
|
|
20
16
|
if (!document)
|
|
21
17
|
throw new Error(`Missing pi-sync settings. Open /sync and choose Set up sync, or create ${localConfigPath()}.`);
|
|
22
|
-
|
|
18
|
+
signal?.throwIfAborted();
|
|
19
|
+
return configFromSettings(settingsFromCheckDocument(document), setupName);
|
|
23
20
|
}
|
|
24
21
|
/** A background freshness read must never trigger legacy-file publication. */
|
|
25
22
|
export async function loadConfigForCheck(setupName, signal) {
|
|
26
23
|
signal?.throwIfAborted();
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
async function operationalConfig(document, setupName, signal) {
|
|
24
|
+
assertNoRetiredRuleJournal();
|
|
25
|
+
const document = await readActiveLocalConfigDocumentForRepair();
|
|
30
26
|
signal?.throwIfAborted();
|
|
31
|
-
|
|
32
|
-
if (!config.reservedIgnoreNames)
|
|
33
|
-
return config;
|
|
34
|
-
if (engineHost().ignoreFileOperationsAvailable === false)
|
|
35
|
-
return requireLegacyOperationConfig(config);
|
|
36
|
-
return resolveOperationPolicy(config, setupName, signal, document && { kind: "checked", document });
|
|
27
|
+
return configFromSettings(settingsFromCheckDocument(document), setupName);
|
|
37
28
|
}
|
|
38
29
|
export async function loadSettingsConfig(setupName) {
|
|
39
30
|
const settings = settingsFromCheckDocument(await readActiveLocalConfigDocumentForRepair());
|
|
@@ -44,123 +35,20 @@ function settingsFromCheckDocument(document) {
|
|
|
44
35
|
throw new Error(`Missing pi-sync settings: ${localConfigPath()}`);
|
|
45
36
|
return validateSettingsDocument(document.parsed);
|
|
46
37
|
}
|
|
47
|
-
export function requireLegacyOperationConfig(config) {
|
|
48
|
-
if (config.pathPolicy === "ignore-file" || config.ignorePolicy || config.reservedIgnoreNames !== undefined) {
|
|
49
|
-
throw new Error("This Pi Sync operation does not yet support settings with ignore-file policies.");
|
|
50
|
-
}
|
|
51
|
-
return config;
|
|
52
|
-
}
|
|
53
|
-
export async function resolveIgnoreConfig(settings, setupName, signal) {
|
|
54
|
-
signal?.throwIfAborted();
|
|
55
|
-
return resolveOperationPolicy(configFromSettings(validateSettingsDocument(settings), setupName), setupName, signal);
|
|
56
|
-
}
|
|
57
38
|
export function createSettingsConfigView(document) {
|
|
58
39
|
const settings = validateSettingsDocument(document.parsed);
|
|
59
|
-
const
|
|
60
|
-
const metadata = (setupName) => projectSettingsConfig(settings, setupName, () => ignoreNames);
|
|
61
|
-
let fingerprint;
|
|
40
|
+
const metadata = (setupName) => configFromSettings(settings, setupName);
|
|
62
41
|
return {
|
|
63
42
|
activeSetupName: settings.activeSyncSetup,
|
|
64
43
|
setupNames: Object.keys(settings.syncSetups),
|
|
65
44
|
metadata,
|
|
66
45
|
async observe(setupName, signal) {
|
|
67
46
|
signal?.throwIfAborted();
|
|
68
|
-
|
|
69
|
-
if (!config.reservedIgnoreNames)
|
|
70
|
-
return config;
|
|
71
|
-
if (engineHost().ignoreFileOperationsAvailable === false)
|
|
72
|
-
return requireLegacyOperationConfig(config);
|
|
73
|
-
fingerprint ??= settingsDocumentFingerprint(document);
|
|
74
|
-
return resolveOperationPolicy(config, setupName, signal, { kind: "view", fingerprint });
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
function settingsDocumentFingerprint(document) {
|
|
79
|
-
return documentFingerprint(document && { bytes: document.bytes.toString("base64"), identity: document.identity });
|
|
80
|
-
}
|
|
81
|
-
async function resolveOperationPolicy(config, setupName, signal, settingsSource) {
|
|
82
|
-
if (!config.reservedIgnoreNames)
|
|
83
|
-
return config;
|
|
84
|
-
const root = getEngineRoot();
|
|
85
|
-
const validateRoot = () => {
|
|
86
|
-
signal?.throwIfAborted();
|
|
87
|
-
if (root !== getEngineRoot())
|
|
88
|
-
throw new Error("The Pi agent directory changed; reopen the review before continuing.");
|
|
89
|
-
};
|
|
90
|
-
const original = settingsSource?.kind === "checked" ? settingsSource.document : undefined;
|
|
91
|
-
const configDocumentFingerprint = settingsSource?.kind === "view" ? settingsSource.fingerprint : original && settingsDocumentFingerprint(original);
|
|
92
|
-
const settingsFingerprint = settingsSource?.kind === "view" ? undefined : syncCheckConfigFingerprint(config);
|
|
93
|
-
const validateSettings = (document) => {
|
|
94
|
-
validateRoot();
|
|
95
|
-
if ((original &&
|
|
96
|
-
(document?.path !== original.path || settingsDocumentFingerprint(document) !== configDocumentFingerprint)) ||
|
|
97
|
-
settingsFingerprint !==
|
|
98
|
-
syncCheckConfigFingerprint(configFromSettings(settingsFromCheckDocument(document), setupName))) {
|
|
99
|
-
throw new Error("Pi Sync settings changed; reopen the review before continuing.");
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
const source = config.pathPolicy === "ignore-file" ? await readIgnoreSource(root, config.ignoreFile, signal) : undefined;
|
|
103
|
-
validateRoot();
|
|
104
|
-
if (settingsSource && source && !source.present) {
|
|
105
|
-
throw new Error(`Ignore file is missing: ${safeTerminalText(path.join(root, source.filename))}. Create it and reopen Pi Sync; starter rules are only a preview.`);
|
|
106
|
-
}
|
|
107
|
-
if (original && source)
|
|
108
|
-
validateSettings(await readActiveLocalConfigDocumentForRepair());
|
|
109
|
-
const observed = {
|
|
110
|
-
...config,
|
|
111
|
-
...(configDocumentFingerprint ? { configDocumentFingerprint } : {}),
|
|
112
|
-
...(source ? { ignorePolicy: compileEffectiveIgnorePolicy(source, ignorePolicyInput(config)) } : {}),
|
|
113
|
-
...(source?.identity ? { ignoreSourceIdentity: source.identity } : {}),
|
|
114
|
-
};
|
|
115
|
-
if (settingsSource?.kind === "view")
|
|
116
|
-
return observed;
|
|
117
|
-
return {
|
|
118
|
-
...observed,
|
|
119
|
-
validateIgnorePolicy: async () => {
|
|
120
|
-
validateRoot();
|
|
121
|
-
await withLockedLocalConfigDocument(async (document, recheck) => {
|
|
122
|
-
validateSettings(document);
|
|
123
|
-
if (source) {
|
|
124
|
-
const current = await readIgnoreSource(root, source.filename, signal);
|
|
125
|
-
validateRoot();
|
|
126
|
-
recheck();
|
|
127
|
-
if (current.sourceDigest !== source.sourceDigest || current.identity !== source.identity) {
|
|
128
|
-
throw new Error("Pi Sync ignore policy changed; reopen the review before continuing.");
|
|
129
|
-
}
|
|
130
|
-
if (!current.present) {
|
|
131
|
-
throw new Error(`Ignore file "${source.filename}" is missing; starter rules can only be used for a preview.`);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
recheck();
|
|
136
|
-
}
|
|
137
|
-
}, signal, true);
|
|
138
|
-
validateRoot();
|
|
47
|
+
return metadata(setupName);
|
|
139
48
|
},
|
|
140
49
|
};
|
|
141
50
|
}
|
|
142
|
-
function ignorePolicyInput(config) {
|
|
143
|
-
return {
|
|
144
|
-
filename: config.ignoreFile,
|
|
145
|
-
sessions: config.include.includes("sessions"),
|
|
146
|
-
configuredFilenames: config.reservedIgnoreNames ?? [],
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
function reservedIgnoreFilenames(settings) {
|
|
150
|
-
const names = new Set();
|
|
151
|
-
for (const { sync } of Object.values(settings.syncSetups)) {
|
|
152
|
-
if (sync.pathPolicy === "ignore-file")
|
|
153
|
-
names.add(validateIgnoreFilename(sync.ignoreFile ?? DEFAULT_IGNORE_FILENAME).toLowerCase());
|
|
154
|
-
}
|
|
155
|
-
if (names.size === 0)
|
|
156
|
-
return undefined;
|
|
157
|
-
names.add(DEFAULT_IGNORE_FILENAME);
|
|
158
|
-
return [...names].sort();
|
|
159
|
-
}
|
|
160
51
|
export function configFromSettings(settings, setupName) {
|
|
161
|
-
return projectSettingsConfig(settings, setupName, () => reservedIgnoreFilenames(settings));
|
|
162
|
-
}
|
|
163
|
-
function projectSettingsConfig(settings, setupName, getReservedIgnoreNames) {
|
|
164
52
|
const selectedName = setupName ?? settings.activeSyncSetup;
|
|
165
53
|
if (!selectedName)
|
|
166
54
|
throw new Error("No sync setups are configured.");
|
|
@@ -173,22 +61,19 @@ function projectSettingsConfig(settings, setupName, getReservedIgnoreNames) {
|
|
|
173
61
|
if (!connection) {
|
|
174
62
|
throw new Error(`Invalid pi-sync settings: sync setup “${selectedName}” references missing storage connection “${connectionName}”.`);
|
|
175
63
|
}
|
|
176
|
-
const reservedIgnoreNames = getReservedIgnoreNames();
|
|
177
64
|
return {
|
|
178
65
|
...resolveSyncConfig(selectedName, setup, connectionName, connection, settings.onSwitch, settings.skipSecretScan ?? false, settings.showStatus ?? true),
|
|
179
66
|
debug: settings.debug ?? false,
|
|
180
|
-
...(reservedIgnoreNames ? { reservedIgnoreNames } : {}),
|
|
181
67
|
};
|
|
182
68
|
}
|
|
183
69
|
/** A validated setup-facing projection used by manager and settings UI. */
|
|
184
70
|
export async function loadPartialConfig(setupName) {
|
|
185
|
-
const config =
|
|
71
|
+
const config = await loadConfig(setupName);
|
|
186
72
|
return {
|
|
187
73
|
setupName: config.setupName,
|
|
188
74
|
...storageReviewFromConfig(config),
|
|
189
75
|
include: [...config.include],
|
|
190
76
|
...(config.scope === undefined ? {} : { scope: config.scope }),
|
|
191
|
-
...(config.pathPolicy === undefined ? {} : { pathPolicy: config.pathPolicy, ignoreFile: config.ignoreFile }),
|
|
192
77
|
...(config.exclude === undefined ? {} : { exclude: [...config.exclude] }),
|
|
193
78
|
...(config.reinclude === undefined ? {} : { reinclude: [...config.reinclude] }),
|
|
194
79
|
automatic: config.automatic,
|
|
@@ -206,10 +91,7 @@ export function syncSetupReviewIdentity(setupName, setup, connectionName, connec
|
|
|
206
91
|
return syncConfigReviewIdentity(resolveSyncConfig(setupName, setup, connectionName, connection, DEFAULT_ON_SWITCH, false, true));
|
|
207
92
|
}
|
|
208
93
|
export function syncConfigReviewIdentity(config) {
|
|
209
|
-
const
|
|
210
|
-
const directoryPolicy = config.pathPolicy === "ignore-file" && !config.ignorePolicy
|
|
211
|
-
? JSON.stringify([config.pathPolicy, config.ignoreFile])
|
|
212
|
-
: syncDirectoryPolicyKey(config);
|
|
94
|
+
const directoryPolicy = syncDirectoryPolicyKey(config);
|
|
213
95
|
return JSON.stringify([
|
|
214
96
|
config.setupName,
|
|
215
97
|
config.connectionName,
|
|
@@ -229,7 +111,6 @@ export function syncConfigReviewIdentity(config) {
|
|
|
229
111
|
: config.exclude === undefined
|
|
230
112
|
? []
|
|
231
113
|
: ["exclude", normalizeSyncExclude(config.exclude).map((rule) => rule.toLowerCase())]),
|
|
232
|
-
...(localPolicy ? [localPolicy] : []),
|
|
233
114
|
]);
|
|
234
115
|
}
|
|
235
116
|
export function syncConfigReviewFingerprint(config) {
|
|
@@ -241,14 +122,6 @@ export function syncCheckConfigFingerprint(config) {
|
|
|
241
122
|
.update(JSON.stringify({ ...config, showStatus: undefined, debug: undefined, settingsVersion: undefined }))
|
|
242
123
|
.digest("hex");
|
|
243
124
|
}
|
|
244
|
-
export function syncSettingsConfigFingerprint(config) {
|
|
245
|
-
return syncCheckConfigFingerprint({
|
|
246
|
-
...config,
|
|
247
|
-
configDocumentFingerprint: undefined,
|
|
248
|
-
ignoreSourceIdentity: undefined,
|
|
249
|
-
ignorePolicy: undefined,
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
125
|
function storageReviewFromConfig(config) {
|
|
253
126
|
return {
|
|
254
127
|
connectionName: config.connectionName,
|
|
@@ -269,12 +142,6 @@ function resolveSyncConfig(setupName, setup, connectionName, connection, onSwitc
|
|
|
269
142
|
? {
|
|
270
143
|
scope: policy.scope,
|
|
271
144
|
include: policy.sessions ? ["sessions"] : [],
|
|
272
|
-
...(policy.pathPolicy === "ignore-file"
|
|
273
|
-
? {
|
|
274
|
-
pathPolicy: policy.pathPolicy,
|
|
275
|
-
ignoreFile: validateIgnoreFilename(policy.ignoreFile ?? DEFAULT_IGNORE_FILENAME),
|
|
276
|
-
}
|
|
277
|
-
: {}),
|
|
278
145
|
...(policy.exclude === undefined ? {} : { exclude: normalizeDirectoryRules(policy.exclude) }),
|
|
279
146
|
...(policy.reinclude === undefined ? {} : { reinclude: normalizeDirectoryRules(policy.reinclude) }),
|
|
280
147
|
}
|
|
@@ -290,8 +157,8 @@ function resolveSyncConfig(setupName, setup, connectionName, connection, onSwitc
|
|
|
290
157
|
...selection,
|
|
291
158
|
automatic: setup.sync.automatic,
|
|
292
159
|
automaticTransfer: setup.sync.automaticTransfer ?? false,
|
|
293
|
-
agentMode:
|
|
294
|
-
continuous:
|
|
160
|
+
agentMode: false,
|
|
161
|
+
continuous: false,
|
|
295
162
|
localFields: setup.sync.localFields === undefined ? undefined : normalizeLocalFields(setup.sync.localFields),
|
|
296
163
|
mergeSettings: setup.sync.mergeSettings ?? false,
|
|
297
164
|
mergeContent: setup.sync.mergeContent ?? false,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class RetiredIgnorePolicyError extends Error {
|
|
2
|
+
kind;
|
|
3
|
+
constructor(kind) {
|
|
4
|
+
const reason = {
|
|
5
|
+
settings: "Ignore-file sync settings are no longer supported.",
|
|
6
|
+
snapshot: "This remote uses a retired ignore-file snapshot format.",
|
|
7
|
+
baseline: "The last accepted sync is bound to a retired ignore-file policy.",
|
|
8
|
+
recovery: "An ignore-file operation still needs recovery with a compatible Pi Sync build.",
|
|
9
|
+
}[kind];
|
|
10
|
+
super(`${reason} Preserve the data and use /skill:configure-pi-sync for guidance.`);
|
|
11
|
+
this.kind = kind;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function retiredIgnorePolicy(kind) {
|
|
15
|
+
return new RetiredIgnorePolicyError(kind);
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { lstatSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { getEngineRoot } from "../host.js";
|
|
4
|
+
import { stateDir } from "../state/state-directory.js";
|
|
5
|
+
import { retiredIgnorePolicy } from "./retired-ignore-policy.js";
|
|
6
|
+
export function hasRetiredRuleJournal(root) {
|
|
7
|
+
return Boolean(lstatSync(path.join(root, ".pi-sync.json.syncignore-creation"), { throwIfNoEntry: false }) ||
|
|
8
|
+
lstatSync(path.join(stateDir(root), "ignore-adoption.json"), { throwIfNoEntry: false }));
|
|
9
|
+
}
|
|
10
|
+
export function assertNoRetiredRuleJournal(root = getEngineRoot()) {
|
|
11
|
+
if (hasRetiredRuleJournal(root)) {
|
|
12
|
+
throw retiredIgnorePolicy("recovery");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -125,10 +125,8 @@ export async function updateSyncSetup(name, update, options = {}) {
|
|
|
125
125
|
}
|
|
126
126
|
export async function removeSyncSetup(name, signal) {
|
|
127
127
|
validateConfigName(name, "sync setup");
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const setup = settings.syncSetups[name];
|
|
131
|
-
if (!Object.hasOwn(settings.syncSetups, name) || !setup)
|
|
128
|
+
await updateLocalConfig((settings) => {
|
|
129
|
+
if (!Object.hasOwn(settings.syncSetups, name))
|
|
132
130
|
throw new Error(`Sync setup not found: ${name}`);
|
|
133
131
|
const isCurrent = settings.activeSyncSetup === name;
|
|
134
132
|
if (isCurrent && Object.keys(settings.syncSetups).length > 1) {
|
|
@@ -136,15 +134,11 @@ export async function removeSyncSetup(name, signal) {
|
|
|
136
134
|
}
|
|
137
135
|
const syncSetups = { ...settings.syncSetups };
|
|
138
136
|
delete syncSetups[name];
|
|
139
|
-
removedLastIgnoreSetup =
|
|
140
|
-
setup.sync.pathPolicy === "ignore-file" &&
|
|
141
|
-
!Object.values(syncSetups).some((remaining) => remaining.sync.pathPolicy === "ignore-file");
|
|
142
137
|
const next = { ...settings, syncSetups };
|
|
143
138
|
if (isCurrent)
|
|
144
139
|
delete next.activeSyncSetup;
|
|
145
140
|
return next;
|
|
146
141
|
}, signal);
|
|
147
|
-
return { revertedToLegacyOnly: removedLastIgnoreSetup && saved.activeSyncSetup !== undefined };
|
|
148
142
|
}
|
|
149
143
|
export async function removeStorageConnection(name, signal) {
|
|
150
144
|
validateConfigName(name, "storage connection");
|
|
@@ -164,8 +158,6 @@ export async function removeStorageConnection(name, signal) {
|
|
|
164
158
|
function setupSettingsVersion(current, setup, upgradeExclude) {
|
|
165
159
|
if (setup.sync.maxFileSizeMiB !== undefined || setup.sync.maxDirectorySizeMiB !== undefined)
|
|
166
160
|
return 9;
|
|
167
|
-
if (current < 8 && setup.sync.pathPolicy === "ignore-file")
|
|
168
|
-
return 8;
|
|
169
161
|
if (current < 7 && setup.sync.scope === "agent-directory")
|
|
170
162
|
return 7;
|
|
171
163
|
if (current < 6 && upgradeExclude)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { normalizeEndpointIdentity } from "../backends/backend-identity.js";
|
|
2
2
|
import { normalizeGitBranch, normalizeGitDirectory, normalizeGitRemote, normalizeGitRemoteIdentity, } from "../backends/git/git-config.js";
|
|
3
3
|
import { normalizeWebDavIdentityUrl, normalizeWebDavPath, normalizeWebDavUrl, validateWebDavCredentials, } from "../backends/webdav/webdav-config.js";
|
|
4
|
-
import { validateIgnoreFilename } from "../ignore/ignore-source.js";
|
|
5
4
|
import { normalizeSyncExclude } from "../sync/exclude-policy.js";
|
|
6
5
|
import { normalizeLocalFields } from "../sync/local-field-policy.js";
|
|
7
6
|
import { normalizeDirectoryRules, normalizeSyncInclude } from "../sync/sync-policy.js";
|
|
8
7
|
import { CONFIG_FILE_NAME } from "./config-file.js";
|
|
8
|
+
import { retiredIgnorePolicy } from "./retired-ignore-policy.js";
|
|
9
9
|
export const DEFAULT_ON_SWITCH = "ask-before-pull";
|
|
10
10
|
export function normalizeOnSwitch(value) {
|
|
11
11
|
if (value === "ask-before-pull" || value === "pull-after-switch" || value === "switch-only") {
|
|
@@ -130,6 +130,10 @@ function validateSyncSetup(name, value, connections, version) {
|
|
|
130
130
|
], `sync setup “${name}”`);
|
|
131
131
|
const storage = requireRecord(value.storage, `storage for sync setup “${name}”`);
|
|
132
132
|
const sync = requireRecord(value.sync, `sync policy for sync setup “${name}”`);
|
|
133
|
+
if (sync.pathPolicy === "ignore-file" || Object.hasOwn(sync, "ignoreFile"))
|
|
134
|
+
throw retiredIgnorePolicy("settings");
|
|
135
|
+
if (Object.hasOwn(sync, "pathPolicy"))
|
|
136
|
+
throw new Error("Invalid pi-sync settings: unsupported sync.pathPolicy.");
|
|
133
137
|
rejectLegacyFields(storage, ["profile", "prefix", "directory", "namespace"], `storage for sync setup “${name}”`);
|
|
134
138
|
rejectLegacyFields(sync, ["autoSync", "syncFiles", "syncSessions", "extraFiles"], `sync policy for sync setup “${name}”`);
|
|
135
139
|
const connectionName = requiredCanonicalReference(storage.connection, `storage connection reference for sync setup “${name}”`);
|
|
@@ -156,24 +160,7 @@ function validateSyncSetup(name, value, connections, version) {
|
|
|
156
160
|
}
|
|
157
161
|
}
|
|
158
162
|
const localFields = normalizeLocalFields(sync.localFields);
|
|
159
|
-
if (Object.hasOwn(sync, "
|
|
160
|
-
if (sync.pathPolicy !== "ignore-file")
|
|
161
|
-
throw new Error("Invalid pi-sync settings: unsupported sync.pathPolicy.");
|
|
162
|
-
if (version < 8)
|
|
163
|
-
throw new Error("sync.pathPolicy requires explicit settings version 8.");
|
|
164
|
-
if (!Object.hasOwn(sync, "scope") || sync.scope !== "agent-directory")
|
|
165
|
-
throw new Error("Invalid pi-sync settings: sync.pathPolicy requires agent-directory scope.");
|
|
166
|
-
for (const key of ["include", "exclude", "reinclude"]) {
|
|
167
|
-
if (Object.hasOwn(sync, key))
|
|
168
|
-
throw new Error(`Invalid pi-sync settings: ignore-file policy cannot use sync.${key}.`);
|
|
169
|
-
}
|
|
170
|
-
if (Object.hasOwn(sync, "ignoreFile"))
|
|
171
|
-
validateIgnoreFilename(sync.ignoreFile);
|
|
172
|
-
}
|
|
173
|
-
else if (Object.hasOwn(sync, "ignoreFile")) {
|
|
174
|
-
throw new Error("Invalid pi-sync settings: sync.ignoreFile requires ignore-file pathPolicy.");
|
|
175
|
-
}
|
|
176
|
-
else if (Object.hasOwn(sync, "scope")) {
|
|
163
|
+
if (Object.hasOwn(sync, "scope")) {
|
|
177
164
|
if (sync.scope !== "agent-directory")
|
|
178
165
|
throw new Error("Invalid pi-sync settings: unsupported sync.scope.");
|
|
179
166
|
if (version < 7)
|
|
@@ -182,6 +169,8 @@ function validateSyncSetup(name, value, connections, version) {
|
|
|
182
169
|
throw new Error("Invalid pi-sync settings: agent-directory scope cannot use sync.include.");
|
|
183
170
|
normalizeDirectoryRules(sync.exclude);
|
|
184
171
|
normalizeDirectoryRules(sync.reinclude);
|
|
172
|
+
if (sync.sessions !== undefined && typeof sync.sessions !== "boolean")
|
|
173
|
+
throw new Error("Invalid pi-sync settings: sync.sessions must be boolean.");
|
|
185
174
|
}
|
|
186
175
|
else {
|
|
187
176
|
if (Object.hasOwn(sync, "sessions") || Object.hasOwn(sync, "reinclude"))
|
|
@@ -193,8 +182,6 @@ function validateSyncSetup(name, value, connections, version) {
|
|
|
193
182
|
if (localFields.length > 0 && !include.includes("settings.json"))
|
|
194
183
|
throw new Error("Nonempty localFields requires settings.json in sync.include.");
|
|
195
184
|
}
|
|
196
|
-
if (sync.sessions !== undefined && typeof sync.sessions !== "boolean")
|
|
197
|
-
throw new Error("Invalid pi-sync settings: sync.sessions must be boolean.");
|
|
198
185
|
if (sync.localFields !== undefined && version < 4)
|
|
199
186
|
throw new Error("localFields requires explicit settings version 4; older binaries must refuse portable state.");
|
|
200
187
|
if (sync.exclude !== undefined && version < 6)
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { backendIdentityCoordinates } from "../backends/backend-identity.js";
|
|
5
4
|
import { getEngineRoot as getAgentDir, } from "../host.js";
|
|
6
5
|
import { configuredSnapshotPathMatcher } from "../sync/sync-policy.js";
|
|
7
|
-
import { agentDirectorySessionRoot
|
|
6
|
+
import { agentDirectorySessionRoot } from "./snapshot-exclude-safety.js";
|
|
8
7
|
import { sessionStorageRoot } from "./snapshot-paths.js";
|
|
9
8
|
export function sessionDirFromContext(ctx) {
|
|
10
9
|
const manager = ctx.sessionManager;
|
|
@@ -15,19 +14,10 @@ export function sessionDirFromContext(ctx) {
|
|
|
15
14
|
const getSessionDir = manager.getSessionDir;
|
|
16
15
|
return typeof getSessionDir === "function" ? getSessionDir.call(manager) : undefined;
|
|
17
16
|
}
|
|
18
|
-
export async function configuredSessionDir(
|
|
19
|
-
const root = agentDir();
|
|
20
|
-
const target = path.join(root, "settings.json");
|
|
21
|
-
const guardReserved = reservedIgnoreTargetGuard(root, options);
|
|
17
|
+
export async function configuredSessionDir() {
|
|
22
18
|
let content;
|
|
23
19
|
try {
|
|
24
|
-
|
|
25
|
-
const { readLegacySnapshotSource } = await import("./snapshot.js");
|
|
26
|
-
content = (await readLegacySnapshotSource(target, guardReserved, options.signal)).toString("utf8");
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
content = await fs.readFile(target, "utf8");
|
|
30
|
-
}
|
|
20
|
+
content = await fs.readFile(path.join(agentDir(), "settings.json"), "utf8");
|
|
31
21
|
}
|
|
32
22
|
catch (error) {
|
|
33
23
|
if (error.code === "ENOENT")
|
|
@@ -46,41 +36,31 @@ export async function configuredSessionDir(options = {}) {
|
|
|
46
36
|
}
|
|
47
37
|
export async function effectiveSessionRoot(ctx, policy, signal) {
|
|
48
38
|
const sessionDir = sessionDirFromContext(ctx);
|
|
49
|
-
const root = agentDir();
|
|
50
39
|
if (policy?.scope === "agent-directory") {
|
|
40
|
+
const root = agentDir();
|
|
51
41
|
if (sessionDir !== undefined || ctx.sessionManager.usesDefaultSessionDir?.())
|
|
52
|
-
return agentDirectorySessionRoot(root, sessionDir
|
|
42
|
+
return agentDirectorySessionRoot(root, sessionDir);
|
|
53
43
|
if (!configuredSnapshotPathMatcher(policy)("settings.json"))
|
|
54
44
|
throw new Error("Pi session storage is unknown and settings.json is excluded. Use an active Pi context to sync.");
|
|
55
45
|
const { agentDirectoryConfiguredSessionDir } = await import("./snapshot.js");
|
|
56
46
|
signal?.throwIfAborted();
|
|
57
|
-
|
|
58
|
-
return agentDirectorySessionRoot(root, configured, policy.ignorePolicy, policy.reservedIgnoreNames);
|
|
47
|
+
return agentDirectorySessionRoot(root, await agentDirectoryConfiguredSessionDir(signal));
|
|
59
48
|
}
|
|
60
|
-
|
|
61
|
-
const guardReserved = reservedIgnoreTargetGuard(root, policy ?? {});
|
|
62
|
-
if (guardReserved)
|
|
63
|
-
await guardReserved(resolved);
|
|
64
|
-
return resolved;
|
|
49
|
+
return path.resolve(sessionStorageRoot(agentDir(), sessionDir ?? (await configuredSessionDir())));
|
|
65
50
|
}
|
|
66
51
|
export async function sessionDirForApply(ctx, snapshot, options = {}) {
|
|
67
52
|
const contextSessionDir = sessionDirFromContext(ctx);
|
|
68
53
|
if (options.scope === "agent-directory") {
|
|
69
54
|
const root = await effectiveSessionRoot(ctx, options, options.signal);
|
|
70
|
-
if (root !==
|
|
71
|
-
agentDirectorySessionRoot(agentDir(), options.sessionDir, options.ignorePolicy, options.reservedIgnoreNames))
|
|
55
|
+
if (root !== agentDirectorySessionRoot(agentDir(), options.sessionDir))
|
|
72
56
|
throw new Error("Pi session storage changed during transfer; retry from a fresh review.");
|
|
73
57
|
return root;
|
|
74
58
|
}
|
|
75
|
-
const localSessionDir = await configuredSessionDir(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const guardReserved = reservedIgnoreTargetGuard(root, options);
|
|
81
|
-
if (guardReserved)
|
|
82
|
-
await guardReserved(sessionStorageRoot(root, sessionDir));
|
|
83
|
-
return sessionDir;
|
|
59
|
+
const localSessionDir = await configuredSessionDir();
|
|
60
|
+
if (contextSessionDir && path.resolve(contextSessionDir) !== path.resolve(localSessionDir ?? "")) {
|
|
61
|
+
return contextSessionDir;
|
|
62
|
+
}
|
|
63
|
+
return sessionDirFromSnapshot(snapshot) ?? contextSessionDir;
|
|
84
64
|
}
|
|
85
65
|
/** Hash-only merge plans cannot describe installation into a different session root. */
|
|
86
66
|
export function requireStableMergeSessionRoot(before, after, scope) {
|
|
@@ -143,16 +123,8 @@ export function snapshotOptionsForContext(ctx, config) {
|
|
|
143
123
|
return {
|
|
144
124
|
include: config.include,
|
|
145
125
|
...(config.scope === undefined ? {} : { scope: config.scope }),
|
|
146
|
-
...(config.setupName === undefined ? {} : { setupName: config.setupName }),
|
|
147
|
-
...(config.backend && (config.ignorePolicy || config.reservedIgnoreNames !== undefined)
|
|
148
|
-
? { recoverySetupKey: JSON.stringify([backendIdentityCoordinates(config), config.localFields]) }
|
|
149
|
-
: {}),
|
|
150
|
-
...(config.ignorePolicy ? { ignorePolicy: config.ignorePolicy } : {}),
|
|
151
|
-
...(config.ignoreSourceIdentity === undefined ? {} : { ignoreSourceIdentity: config.ignoreSourceIdentity }),
|
|
152
|
-
...(config.validateIgnorePolicy === undefined ? {} : { validateIgnorePolicy: config.validateIgnorePolicy }),
|
|
153
126
|
...(config.exclude === undefined ? {} : { exclude: config.exclude }),
|
|
154
127
|
...(config.reinclude === undefined ? {} : { reinclude: config.reinclude }),
|
|
155
|
-
...(config.reservedIgnoreNames === undefined ? {} : { reservedIgnoreNames: config.reservedIgnoreNames }),
|
|
156
128
|
sessionDir: sessionDirFromContext(ctx) ?? defaultScopedSessionDir,
|
|
157
129
|
};
|
|
158
130
|
}
|
|
@@ -5,7 +5,7 @@ import { assertWithinRoot, isDeniedPath, isPathInside, parentPaths, safeJoin, to
|
|
|
5
5
|
import { syncDirectory } from "../state/json-file.js";
|
|
6
6
|
import { stateDir } from "../state/state-directory.js";
|
|
7
7
|
import { collidingPaths } from "../sync/file-merge-planner.js";
|
|
8
|
-
import { assertSnapshotExcludesDebugLog, compileSyncPolicyExclude, requireLegacyTransferPolicy,
|
|
8
|
+
import { assertSnapshotExcludesDebugLog, compileSyncPolicyExclude, requireLegacyTransferPolicy, } from "../sync/sync-policy.js";
|
|
9
9
|
import { agentDir } from "./session-paths.js";
|
|
10
10
|
import { agentDirectoryConfiguredSessionDir, agentDirectoryInventory, createSnapshot, isSessionFilePath, isSessionPath, sessionStorageRoot, snapshotIncludesSessions, snapshotTarget, } from "./snapshot.js";
|
|
11
11
|
import { assertAgentDirectorySnapshotBound } from "./snapshot-bounds.js";
|
|
@@ -14,35 +14,20 @@ import { agentDirectoryPhysicalSessionPath, assertUnexcludedTargets } from "./sn
|
|
|
14
14
|
import { decodeBase64Strict } from "./snapshot-payload.js";
|
|
15
15
|
import { reviewedSnapshotPreimages } from "./snapshot-reviewed-preimages.js";
|
|
16
16
|
import { applySnapshotTransaction, recoverPendingSnapshotTransactions, } from "./snapshot-transaction.js";
|
|
17
|
-
import { ignorePolicyValidator } from "./snapshot-transaction-policy.js";
|
|
18
|
-
import { isIgnoreSnapshotVersion, } from "./snapshot-types.js";
|
|
19
17
|
function sha256(value) {
|
|
20
18
|
return createHash("sha256").update(value).digest("hex");
|
|
21
19
|
}
|
|
22
20
|
function fileHashMap(snapshot) {
|
|
23
21
|
return Object.fromEntries(snapshot.files.map((file) => [file.path, file.sha256]));
|
|
24
22
|
}
|
|
25
|
-
function assertSnapshotApplyPolicy(snapshot, options) {
|
|
26
|
-
assertSnapshotExcludesDebugLog(snapshot);
|
|
27
|
-
if (!isIgnoreSnapshotVersion(snapshot.version)) {
|
|
28
|
-
requireLegacyTransferPolicy(snapshot);
|
|
29
|
-
if (options.ignorePolicy)
|
|
30
|
-
throw new Error("Project the snapshot into the reviewed local ignore-file policy before applying it.");
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (options.scope !== "agent-directory" || !options.ignorePolicy)
|
|
34
|
-
requireLegacyTransferPolicy(snapshot);
|
|
35
|
-
if (!sameSnapshotSelection(snapshot.selection, selectionForSnapshot(undefined, undefined, options)))
|
|
36
|
-
throw new Error("Snapshot does not match the local ignore-file policy; review and project it before applying it.");
|
|
37
|
-
}
|
|
38
23
|
export async function applySnapshot(snapshot, protectedRelativePaths = new Set(), options = {}) {
|
|
39
|
-
|
|
40
|
-
|
|
24
|
+
requireLegacyTransferPolicy(snapshot);
|
|
25
|
+
assertSnapshotExcludesDebugLog(snapshot);
|
|
41
26
|
const root = agentDir();
|
|
42
27
|
if (snapshot.version === 5 && options.scope !== "agent-directory")
|
|
43
28
|
throw new Error("Agent-directory snapshot apply requires the local agent-directory policy.");
|
|
44
29
|
const sessionDir = options.scope === "agent-directory"
|
|
45
|
-
? sessionStorageRoot(root, options.sessionDir ?? (await agentDirectoryConfiguredSessionDir(options.signal, root
|
|
30
|
+
? sessionStorageRoot(root, options.sessionDir ?? (await agentDirectoryConfiguredSessionDir(options.signal, root)))
|
|
46
31
|
: options.sessionDir;
|
|
47
32
|
options.validateMutation?.();
|
|
48
33
|
options = { ...options, sessionDir };
|
|
@@ -59,8 +44,6 @@ export async function applySnapshot(snapshot, protectedRelativePaths = new Set()
|
|
|
59
44
|
])),
|
|
60
45
|
};
|
|
61
46
|
options.validateMutation?.();
|
|
62
|
-
if (validateIgnorePolicy)
|
|
63
|
-
await validateIgnorePolicy();
|
|
64
47
|
await recoverPendingSnapshotTransactions(transactionOptions);
|
|
65
48
|
const current = await createSnapshot(snapshot.profile, {
|
|
66
49
|
...options,
|
|
@@ -125,7 +108,8 @@ function sameReviewedFiles(scanned, reviewed) {
|
|
|
125
108
|
reviewed.files.every((file) => hashes.get(file.path) === file.sha256));
|
|
126
109
|
}
|
|
127
110
|
export function preflightSnapshotApply(root, snapshot, current, options = {}) {
|
|
128
|
-
|
|
111
|
+
requireLegacyTransferPolicy(snapshot);
|
|
112
|
+
assertSnapshotExcludesDebugLog(snapshot);
|
|
129
113
|
const seenPaths = new Set();
|
|
130
114
|
const remotePaths = new Set();
|
|
131
115
|
const writes = [];
|
|
@@ -185,7 +169,7 @@ export function protectSnapshotApplyPlan(root, plan, protectedRelativePaths, ses
|
|
|
185
169
|
};
|
|
186
170
|
}
|
|
187
171
|
export async function addTopLevelCaseVariantDeletes(root, plan, snapshot, options = {}) {
|
|
188
|
-
if (options.scope === "agent-directory" || snapshot.selection?.
|
|
172
|
+
if (options.scope === "agent-directory" || snapshot.selection?.version === 3)
|
|
189
173
|
return plan;
|
|
190
174
|
const excluded = compileSyncPolicyExclude(options);
|
|
191
175
|
const topLevelPaths = new Map();
|
|
@@ -250,7 +234,7 @@ function excludedApplyPath(root, options) {
|
|
|
250
234
|
const excluded = compileSyncPolicyExclude(options);
|
|
251
235
|
if (options.scope !== "agent-directory")
|
|
252
236
|
return excluded;
|
|
253
|
-
const physicalSessionPath = agentDirectoryPhysicalSessionPath(root, options.sessionDir
|
|
237
|
+
const physicalSessionPath = agentDirectoryPhysicalSessionPath(root, options.sessionDir);
|
|
254
238
|
return (relative) => excluded(relative) ||
|
|
255
239
|
(/^sessions(?:\/|$)/iu.test(relative) ? !isSessionFilePath(relative) : physicalSessionPath(relative));
|
|
256
240
|
}
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import { isUtf8 } from "node:buffer";
|
|
2
1
|
import { Readable, Writable } from "node:stream";
|
|
3
2
|
import { pipeline } from "node:stream/promises";
|
|
4
3
|
import { promisify } from "node:util";
|
|
5
4
|
import { createGunzip, gzip } from "node:zlib";
|
|
6
5
|
import { throwIfAborted } from "../sync/signals.js";
|
|
7
|
-
import { assertSnapshotExcludesDebugLog,
|
|
8
|
-
import {
|
|
6
|
+
import { assertSnapshotExcludesDebugLog, requireLegacyTransferPolicy, validateSnapshotSelection, } from "../sync/sync-policy.js";
|
|
7
|
+
import { isSupportedSnapshotVersion } from "./snapshot-types.js";
|
|
9
8
|
const VERSION = 1;
|
|
10
9
|
const MAX_DECOMPRESSED_SNAPSHOT_BYTES = 512 * 1024 * 1024;
|
|
11
10
|
const gzipAsync = promisify(gzip);
|
|
12
11
|
export async function encodeSnapshot(snapshot) {
|
|
12
|
+
requireLegacyTransferPolicy(snapshot);
|
|
13
13
|
if (!isSupportedSnapshotVersion(snapshot?.version))
|
|
14
14
|
throw new Error("Unsupported snapshot format.");
|
|
15
15
|
assertSnapshotExcludesDebugLog(snapshot);
|
|
16
|
-
if (!isIgnoreSnapshotVersion(snapshot.version))
|
|
17
|
-
snapshotSelectionInclude(snapshot);
|
|
18
16
|
validateSnapshotSelection(snapshot);
|
|
19
|
-
if (snapshot.version >= 4
|
|
17
|
+
if (snapshot.version >= 4) {
|
|
20
18
|
const { validatePortableSnapshot } = await import("../sync/local-fields.js");
|
|
21
19
|
validatePortableSnapshot(snapshot);
|
|
22
20
|
}
|
|
@@ -42,14 +40,14 @@ export async function decodeSnapshot(buffer, options = {}) {
|
|
|
42
40
|
throwIfAborted(options.signal);
|
|
43
41
|
const payload = Buffer.concat(chunks, total);
|
|
44
42
|
const parsed = JSON.parse(payload.toString("utf8"));
|
|
43
|
+
if (parsed && typeof parsed === "object")
|
|
44
|
+
requireLegacyTransferPolicy(parsed);
|
|
45
45
|
if (!isSupportedSnapshotVersion(parsed?.version) || !Array.isArray(parsed.files)) {
|
|
46
46
|
throw new Error("Unsupported snapshot format.");
|
|
47
47
|
}
|
|
48
|
-
if (isIgnoreSnapshotVersion(parsed.version) && !isUtf8(payload))
|
|
49
|
-
throw new Error("Invalid snapshot UTF-8.");
|
|
50
48
|
assertSnapshotExcludesDebugLog(parsed);
|
|
51
49
|
validateSnapshotSelection(parsed);
|
|
52
|
-
if (parsed.version !== VERSION
|
|
50
|
+
if (parsed.version !== VERSION) {
|
|
53
51
|
const { normalizeLocalFields, validatePortableSnapshot } = await import("../sync/local-fields.js");
|
|
54
52
|
validatePortableSnapshot(parsed);
|
|
55
53
|
if (parsed.localFields !== undefined)
|
|
@@ -57,7 +55,5 @@ export async function decodeSnapshot(buffer, options = {}) {
|
|
|
57
55
|
}
|
|
58
56
|
else if (parsed.localFields !== undefined)
|
|
59
57
|
throw new Error("Portable field policy requires snapshot version 2.");
|
|
60
|
-
if (!isIgnoreSnapshotVersion(parsed.version))
|
|
61
|
-
snapshotSelectionInclude(parsed);
|
|
62
58
|
return parsed;
|
|
63
59
|
}
|