@narumitw/pi-sync-daemon 0.6.2 → 0.8.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 +19 -0
- package/README.md +17 -3
- package/dist/consent.js +26 -1
- package/dist/engine/backends/git/git-backend.d.ts +1 -1
- package/dist/engine/backends/git/git-backend.js +17 -2
- package/dist/engine/backends/git/git-storage.d.ts +1 -1
- package/dist/engine/backends/git/git-storage.js +39 -13
- package/dist/engine/backends/s3/s3-backend.js +8 -0
- package/dist/engine/backends/sync-backend.d.ts +1 -0
- package/dist/engine/backends/webdav/webdav-backend.js +8 -0
- package/dist/engine/ignore/effective-ignore-policy.d.ts +10 -0
- package/dist/engine/ignore/effective-ignore-policy.js +33 -0
- package/dist/engine/ignore/ignore-edit.d.ts +13 -0
- package/dist/engine/ignore/ignore-edit.js +102 -0
- package/dist/engine/ignore/ignore-initialization.d.ts +6 -0
- package/dist/engine/ignore/ignore-initialization.js +186 -0
- package/dist/engine/ignore/ignore-migration-prompt.d.ts +7 -0
- package/dist/engine/ignore/ignore-migration-prompt.js +139 -0
- package/dist/engine/ignore/ignore-settings.d.ts +15 -0
- package/dist/engine/ignore/ignore-settings.js +322 -0
- package/dist/engine/ignore/ignore-source.d.ts +27 -0
- package/dist/engine/ignore/ignore-source.js +250 -0
- package/dist/engine/paths.js +1 -1
- package/dist/engine/settings/config-file.d.ts +9 -2
- package/dist/engine/settings/config-file.js +126 -28
- package/dist/engine/settings/config.d.ts +5 -4
- package/dist/engine/settings/config.js +114 -13
- package/dist/engine/settings/settings-management.js +34 -32
- package/dist/engine/settings/settings-types.d.ts +40 -5
- package/dist/engine/settings/settings-validation.js +52 -24
- package/dist/engine/snapshot/session-paths.d.ts +6 -4
- package/dist/engine/snapshot/session-paths.js +84 -15
- package/dist/engine/snapshot/snapshot-apply.d.ts +7 -8
- package/dist/engine/snapshot/snapshot-apply.js +107 -21
- package/dist/engine/snapshot/snapshot-bounds.d.ts +4 -0
- package/dist/engine/snapshot/snapshot-bounds.js +20 -0
- package/dist/engine/snapshot/snapshot-codec.d.ts +1 -1
- package/dist/engine/snapshot/snapshot-codec.js +15 -7
- package/dist/engine/snapshot/snapshot-entry-projection.d.ts +10 -0
- package/dist/engine/snapshot/snapshot-entry-projection.js +78 -0
- package/dist/engine/snapshot/snapshot-exclude-safety.d.ts +9 -2
- package/dist/engine/snapshot/snapshot-exclude-safety.js +239 -24
- package/dist/engine/snapshot/snapshot-payload.d.ts +2 -0
- package/dist/engine/snapshot/snapshot-payload.js +10 -0
- package/dist/engine/snapshot/snapshot-reviewed-preimages.d.ts +2 -0
- package/dist/engine/snapshot/snapshot-reviewed-preimages.js +60 -0
- package/dist/engine/snapshot/snapshot-root-transition.d.ts +4 -0
- package/dist/engine/snapshot/snapshot-root-transition.js +16 -0
- package/dist/engine/snapshot/snapshot-transaction-images.d.ts +39 -0
- package/dist/engine/snapshot/snapshot-transaction-images.js +387 -0
- package/dist/engine/snapshot/snapshot-transaction-policy.d.ts +73 -0
- package/dist/engine/snapshot/snapshot-transaction-policy.js +276 -0
- package/dist/engine/snapshot/snapshot-transaction-stage.d.ts +32 -0
- package/dist/engine/snapshot/snapshot-transaction-stage.js +303 -0
- package/dist/engine/snapshot/snapshot-transaction-verification.d.ts +7 -0
- package/dist/engine/snapshot/snapshot-transaction-verification.js +78 -0
- package/dist/engine/snapshot/snapshot-transaction.d.ts +1 -11
- package/dist/engine/snapshot/snapshot-transaction.js +390 -364
- package/dist/engine/snapshot/snapshot-types.d.ts +47 -2
- package/dist/engine/snapshot/snapshot-types.js +9 -1
- package/dist/engine/snapshot/snapshot.d.ts +22 -3
- package/dist/engine/snapshot/snapshot.js +357 -43
- package/dist/engine/state/merge-baseline-store.js +20 -9
- package/dist/engine/state/state-types.d.ts +3 -0
- package/dist/engine/sync/apply-review.d.ts +3 -3
- package/dist/engine/sync/apply-review.js +5 -4
- package/dist/engine/sync/continuous-sync.js +37 -12
- package/dist/engine/sync/continuous-watch.d.ts +4 -1
- package/dist/engine/sync/continuous-watch.js +90 -15
- package/dist/engine/sync/exclude-policy.d.ts +4 -0
- package/dist/engine/sync/exclude-policy.js +8 -1
- package/dist/engine/sync/initialization.js +9 -4
- package/dist/engine/sync/local-fields.d.ts +3 -1
- package/dist/engine/sync/local-fields.js +88 -8
- package/dist/engine/sync/merge-apply.js +190 -47
- package/dist/engine/sync/merge-journal.d.ts +18 -4
- package/dist/engine/sync/merge-journal.js +126 -10
- package/dist/engine/sync/merged-sync.d.ts +1 -1
- package/dist/engine/sync/merged-sync.js +124 -68
- package/dist/engine/sync/partial-progress.js +5 -3
- package/dist/engine/sync/remote-snapshot.d.ts +10 -2
- package/dist/engine/sync/remote-snapshot.js +59 -17
- package/dist/engine/sync/session-push.js +7 -6
- package/dist/engine/sync/sync-decision.d.ts +4 -0
- package/dist/engine/sync/sync-decision.js +17 -2
- package/dist/engine/sync/sync-inspection.js +8 -6
- package/dist/engine/sync/sync-mutations.d.ts +10 -2
- package/dist/engine/sync/sync-mutations.js +245 -101
- package/dist/engine/sync/sync-policy.d.ts +36 -10
- package/dist/engine/sync/sync-policy.js +285 -20
- package/dist/engine/sync/sync-queries.js +49 -32
- package/dist/engine/sync/sync-state.d.ts +11 -0
- package/dist/engine/sync/sync-state.js +42 -5
- package/dist/engine/ui/sync-format.js +22 -7
- package/dist/engine-service.js +24 -2
- package/docs/architecture.md +28 -0
- package/package.json +2 -1
|
@@ -2,22 +2,91 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { backendIdentityCoordinates } from "../backends/backend-identity.js";
|
|
3
3
|
import { normalizeGitBranch, normalizeGitDirectory, normalizeGitRemote } from "../backends/git/git-config.js";
|
|
4
4
|
import { normalizeWebDavPath, normalizeWebDavUrl } from "../backends/webdav/webdav-config.js";
|
|
5
|
+
import { getEngineRoot } from "../host.js";
|
|
6
|
+
import { loadEffectiveIgnorePolicy } from "../ignore/effective-ignore-policy.js";
|
|
7
|
+
import { DEFAULT_IGNORE_FILENAME, readIgnoreSource, validateIgnoreFilename } from "../ignore/ignore-source.js";
|
|
5
8
|
import { normalizeSyncExclude } from "../sync/exclude-policy.js";
|
|
6
9
|
import { normalizeLocalFields } from "../sync/local-field-policy.js";
|
|
7
|
-
import { normalizeSyncInclude, syncSessionsSelected } from "../sync/sync-policy.js";
|
|
8
|
-
import { localConfigPath, readActiveLocalConfigDocumentForRepair } from "./config-file.js";
|
|
10
|
+
import { normalizeDirectoryRules, normalizeSyncInclude, syncDirectoryPolicyKey, syncSessionsSelected, } from "../sync/sync-policy.js";
|
|
11
|
+
import { localConfigPath, readActiveLocalConfigDocumentForRepair, withLockedLocalConfigDocument, } from "./config-file.js";
|
|
9
12
|
import { requireSettings } from "./settings-store.js";
|
|
10
13
|
import { DEFAULT_ON_SWITCH, isCloudflareR2Endpoint, normalizeS3Bucket, normalizeS3Endpoint, normalizeStoragePath, optionalString, ownObject, requiredString, validateConfigName, validateSettingsDocument, } from "./settings-validation.js";
|
|
11
14
|
export async function loadConfig(setupName) {
|
|
12
|
-
return configFromSettings(await requireSettings(), setupName);
|
|
15
|
+
return requireLegacyOperationConfig(configFromSettings(await requireSettings(), setupName));
|
|
13
16
|
}
|
|
14
17
|
/** A background freshness read must never trigger legacy-file publication. */
|
|
15
18
|
export async function loadConfigForCheck() {
|
|
16
|
-
|
|
19
|
+
return requireLegacyOperationConfig(configFromSettings(await readSettingsForCheck()));
|
|
20
|
+
}
|
|
21
|
+
export async function loadSettingsConfig(setupName) {
|
|
22
|
+
return configFromSettings(await readSettingsForCheck(), setupName);
|
|
23
|
+
}
|
|
24
|
+
async function readSettingsForCheck() {
|
|
25
|
+
return settingsFromCheckDocument(await readActiveLocalConfigDocumentForRepair());
|
|
26
|
+
}
|
|
27
|
+
function settingsFromCheckDocument(document) {
|
|
17
28
|
if (!document)
|
|
18
29
|
throw new Error(`Missing pi-sync settings: ${localConfigPath()}`);
|
|
19
|
-
validateSettingsDocument(document.parsed);
|
|
20
|
-
|
|
30
|
+
return validateSettingsDocument(document.parsed);
|
|
31
|
+
}
|
|
32
|
+
export function requireLegacyOperationConfig(config) {
|
|
33
|
+
if (config.pathPolicy === "ignore-file" || config.ignorePolicy || config.reservedIgnoreNames !== undefined) {
|
|
34
|
+
throw new Error("This Pi Sync operation does not yet support settings with ignore-file policies.");
|
|
35
|
+
}
|
|
36
|
+
return config;
|
|
37
|
+
}
|
|
38
|
+
export async function resolveIgnoreConfig(settings, setupName, signal) {
|
|
39
|
+
signal?.throwIfAborted();
|
|
40
|
+
const config = configFromSettings(validateSettingsDocument(settings), setupName);
|
|
41
|
+
if (config.pathPolicy !== "ignore-file")
|
|
42
|
+
return requireLegacyOperationConfig(config);
|
|
43
|
+
const root = getEngineRoot();
|
|
44
|
+
const validateRoot = () => {
|
|
45
|
+
if (root !== getEngineRoot())
|
|
46
|
+
throw new Error("The Pi agent directory changed; reopen the review before continuing.");
|
|
47
|
+
};
|
|
48
|
+
const settingsFingerprint = syncCheckConfigFingerprint(config);
|
|
49
|
+
const validateSettings = (document) => {
|
|
50
|
+
signal?.throwIfAborted();
|
|
51
|
+
validateRoot();
|
|
52
|
+
const current = configFromSettings(document, setupName);
|
|
53
|
+
if (settingsFingerprint !== syncCheckConfigFingerprint(current)) {
|
|
54
|
+
throw new Error("Pi Sync settings changed; reopen the review before continuing.");
|
|
55
|
+
}
|
|
56
|
+
return current;
|
|
57
|
+
};
|
|
58
|
+
const ignorePolicy = await loadEffectiveIgnorePolicy(root, ignorePolicyInput(config), signal);
|
|
59
|
+
signal?.throwIfAborted();
|
|
60
|
+
validateRoot();
|
|
61
|
+
return {
|
|
62
|
+
...config,
|
|
63
|
+
ignorePolicy,
|
|
64
|
+
validateIgnorePolicy: async () => {
|
|
65
|
+
signal?.throwIfAborted();
|
|
66
|
+
validateRoot();
|
|
67
|
+
await withLockedLocalConfigDocument(async (document, recheck) => {
|
|
68
|
+
const current = validateSettings(settingsFromCheckDocument(document));
|
|
69
|
+
const source = await readIgnoreSource(root, current.ignoreFile, signal);
|
|
70
|
+
validateRoot();
|
|
71
|
+
recheck();
|
|
72
|
+
if (source.sourceDigest !== ignorePolicy.sourceDigest) {
|
|
73
|
+
throw new Error("Pi Sync ignore policy changed; reopen the review before continuing.");
|
|
74
|
+
}
|
|
75
|
+
if (!source.present) {
|
|
76
|
+
throw new Error(`Ignore file "${source.filename}" is missing; starter rules can only be used for a preview.`);
|
|
77
|
+
}
|
|
78
|
+
}, signal, true);
|
|
79
|
+
signal?.throwIfAborted();
|
|
80
|
+
validateRoot();
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function ignorePolicyInput(config) {
|
|
85
|
+
return {
|
|
86
|
+
filename: config.ignoreFile,
|
|
87
|
+
sessions: config.include.includes("sessions"),
|
|
88
|
+
configuredFilenames: config.reservedIgnoreNames ?? [],
|
|
89
|
+
};
|
|
21
90
|
}
|
|
22
91
|
export function configFromSettings(settings, setupName) {
|
|
23
92
|
const selectedName = setupName ?? settings.activeSyncSetup;
|
|
@@ -32,19 +101,30 @@ export function configFromSettings(settings, setupName) {
|
|
|
32
101
|
if (!connection) {
|
|
33
102
|
throw new Error(`Invalid pi-sync settings: sync setup “${selectedName}” references missing storage connection “${connectionName}”.`);
|
|
34
103
|
}
|
|
104
|
+
const ignoreNames = new Set();
|
|
105
|
+
for (const { sync } of Object.values(settings.syncSetups)) {
|
|
106
|
+
if (sync.pathPolicy === "ignore-file")
|
|
107
|
+
ignoreNames.add(validateIgnoreFilename(sync.ignoreFile ?? DEFAULT_IGNORE_FILENAME).toLowerCase());
|
|
108
|
+
}
|
|
109
|
+
if (ignoreNames.size > 0)
|
|
110
|
+
ignoreNames.add(DEFAULT_IGNORE_FILENAME);
|
|
35
111
|
return {
|
|
36
112
|
...resolveSyncConfig(selectedName, setup, connectionName, connection, settings.onSwitch, settings.skipSecretScan ?? false, settings.showStatus ?? true),
|
|
37
113
|
debug: settings.debug ?? false,
|
|
114
|
+
...(ignoreNames.size > 0 ? { reservedIgnoreNames: [...ignoreNames].sort() } : {}),
|
|
38
115
|
};
|
|
39
116
|
}
|
|
40
117
|
/** A validated setup-facing projection used by manager and settings UI. */
|
|
41
118
|
export async function loadPartialConfig(setupName) {
|
|
42
|
-
const config = await
|
|
119
|
+
const config = configFromSettings(await requireSettings(), setupName);
|
|
43
120
|
return {
|
|
44
121
|
setupName: config.setupName,
|
|
45
122
|
...storageReviewFromConfig(config),
|
|
46
123
|
include: [...config.include],
|
|
124
|
+
...(config.scope === undefined ? {} : { scope: config.scope }),
|
|
125
|
+
...(config.pathPolicy === undefined ? {} : { pathPolicy: config.pathPolicy, ignoreFile: config.ignoreFile }),
|
|
47
126
|
...(config.exclude === undefined ? {} : { exclude: [...config.exclude] }),
|
|
127
|
+
...(config.reinclude === undefined ? {} : { reinclude: [...config.reinclude] }),
|
|
48
128
|
automatic: config.automatic,
|
|
49
129
|
automaticTransfer: config.automaticTransfer ?? false,
|
|
50
130
|
agentMode: config.agentMode ?? false,
|
|
@@ -60,6 +140,9 @@ export function syncSetupReviewIdentity(setupName, setup, connectionName, connec
|
|
|
60
140
|
return syncConfigReviewIdentity(resolveSyncConfig(setupName, setup, connectionName, connection, DEFAULT_ON_SWITCH, false, true));
|
|
61
141
|
}
|
|
62
142
|
export function syncConfigReviewIdentity(config) {
|
|
143
|
+
const directoryPolicy = config.pathPolicy === "ignore-file" && !config.ignorePolicy
|
|
144
|
+
? JSON.stringify([config.pathPolicy, config.ignoreFile])
|
|
145
|
+
: syncDirectoryPolicyKey(config);
|
|
63
146
|
return JSON.stringify([
|
|
64
147
|
config.setupName,
|
|
65
148
|
config.connectionName,
|
|
@@ -74,9 +157,11 @@ export function syncConfigReviewIdentity(config) {
|
|
|
74
157
|
config.partialSync ?? false,
|
|
75
158
|
// Preserve existing Off identities and cached candidates across the upgrade.
|
|
76
159
|
...(config.continuous ? ["continuous"] : []),
|
|
77
|
-
...(
|
|
78
|
-
? []
|
|
79
|
-
:
|
|
160
|
+
...(directoryPolicy !== undefined
|
|
161
|
+
? [directoryPolicy]
|
|
162
|
+
: config.exclude === undefined
|
|
163
|
+
? []
|
|
164
|
+
: ["exclude", normalizeSyncExclude(config.exclude).map((rule) => rule.toLowerCase())]),
|
|
80
165
|
]);
|
|
81
166
|
}
|
|
82
167
|
export function syncConfigReviewFingerprint(config) {
|
|
@@ -103,14 +188,30 @@ function storageReviewFromConfig(config) {
|
|
|
103
188
|
function resolveSyncConfig(setupName, setup, connectionName, connection, onSwitch, skipSecretScan, showStatus) {
|
|
104
189
|
const storagePath = normalizeStoragePath(setup.storage.path);
|
|
105
190
|
const namespace = storagePath === "./" ? "root" : storagePath.slice(storagePath.lastIndexOf("/") + 1);
|
|
106
|
-
const
|
|
191
|
+
const policy = setup.sync;
|
|
192
|
+
const selection = policy.scope === "agent-directory"
|
|
193
|
+
? {
|
|
194
|
+
scope: policy.scope,
|
|
195
|
+
include: policy.sessions ? ["sessions"] : [],
|
|
196
|
+
...(policy.pathPolicy === "ignore-file"
|
|
197
|
+
? {
|
|
198
|
+
pathPolicy: policy.pathPolicy,
|
|
199
|
+
ignoreFile: validateIgnoreFilename(policy.ignoreFile ?? DEFAULT_IGNORE_FILENAME),
|
|
200
|
+
}
|
|
201
|
+
: {}),
|
|
202
|
+
...(policy.exclude === undefined ? {} : { exclude: normalizeDirectoryRules(policy.exclude) }),
|
|
203
|
+
...(policy.reinclude === undefined ? {} : { reinclude: normalizeDirectoryRules(policy.reinclude) }),
|
|
204
|
+
}
|
|
205
|
+
: {
|
|
206
|
+
include: normalizeSyncInclude(policy.include),
|
|
207
|
+
...(policy.exclude === undefined ? {} : { exclude: normalizeSyncExclude(policy.exclude) }),
|
|
208
|
+
};
|
|
107
209
|
const common = {
|
|
108
210
|
setupName,
|
|
109
211
|
connectionName,
|
|
110
212
|
storagePath,
|
|
111
213
|
snapshotIdentity: namespace,
|
|
112
|
-
|
|
113
|
-
...(setup.sync.exclude === undefined ? {} : { exclude: normalizeSyncExclude(setup.sync.exclude) }),
|
|
214
|
+
...selection,
|
|
114
215
|
automatic: setup.sync.automatic,
|
|
115
216
|
automaticTransfer: setup.sync.automaticTransfer ?? false,
|
|
116
217
|
agentMode: setup.sync.agentMode ?? false,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from "node:util";
|
|
2
|
-
import { normalizeSyncInclude } from "../sync/sync-policy.js";
|
|
3
2
|
import { configFromSettings, syncCheckConfigFingerprint, syncSetupStorageReview, } from "./config.js";
|
|
4
3
|
import { localConfigPath } from "./config-file.js";
|
|
5
4
|
import { updateLocalConfig } from "./settings-store.js";
|
|
@@ -11,31 +10,28 @@ export class SyncSetupReviewChangedError extends Error {
|
|
|
11
10
|
}
|
|
12
11
|
}
|
|
13
12
|
export async function saveNewV3Settings(input, signal) {
|
|
14
|
-
|
|
15
|
-
validateConfigName(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
skipSecretScan: false,
|
|
21
|
-
storageConnections: { [input.connectionName]: structuredClone(input.connection) },
|
|
22
|
-
syncSetups: {
|
|
23
|
-
[input.setupName]: {
|
|
24
|
-
...structuredClone(input.setup),
|
|
25
|
-
storage: { ...input.setup.storage, connection: input.connectionName },
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
};
|
|
13
|
+
const { setupName, connectionName } = input;
|
|
14
|
+
validateConfigName(setupName, "sync setup");
|
|
15
|
+
validateConfigName(connectionName, "storage connection");
|
|
16
|
+
const connection = structuredClone(input.connection);
|
|
17
|
+
const setup = structuredClone(input.setup);
|
|
18
|
+
setup.storage.connection = connectionName;
|
|
29
19
|
return updateLocalConfig((current) => {
|
|
30
20
|
if (Object.keys(current.storageConnections).length || Object.keys(current.syncSetups).length) {
|
|
31
21
|
throw new Error(`Settings already exist: ${localConfigPath()}`);
|
|
32
22
|
}
|
|
33
|
-
return {
|
|
23
|
+
return {
|
|
24
|
+
...current,
|
|
25
|
+
version: setupSettingsVersion(current.version, setup),
|
|
26
|
+
activeSyncSetup: setupName,
|
|
27
|
+
storageConnections: { [connectionName]: connection },
|
|
28
|
+
syncSetups: { [setupName]: setup },
|
|
29
|
+
};
|
|
34
30
|
}, signal);
|
|
35
31
|
}
|
|
36
32
|
export async function addStorageConnection(name, connection, signal) {
|
|
37
33
|
validateConfigName(name, "storage connection");
|
|
38
|
-
await
|
|
34
|
+
await updateLocalConfig((settings) => {
|
|
39
35
|
if (Object.hasOwn(settings.storageConnections, name)) {
|
|
40
36
|
throw new Error(`Storage connection already exists: ${name}`);
|
|
41
37
|
}
|
|
@@ -50,7 +46,7 @@ export async function addStorageConnection(name, connection, signal) {
|
|
|
50
46
|
}
|
|
51
47
|
export async function updateStorageConnection(name, update, expectedSetups, signal) {
|
|
52
48
|
validateConfigName(name, "storage connection");
|
|
53
|
-
await
|
|
49
|
+
await updateLocalConfig((settings) => {
|
|
54
50
|
const connection = settings.storageConnections[name];
|
|
55
51
|
if (!connection)
|
|
56
52
|
throw new Error(`Storage connection not found: ${name}`);
|
|
@@ -66,7 +62,7 @@ export async function updateStorageConnection(name, update, expectedSetups, sign
|
|
|
66
62
|
}
|
|
67
63
|
export async function addSyncSetup(name, setup, signal, expectedConnection) {
|
|
68
64
|
validateConfigName(name, "sync setup");
|
|
69
|
-
await
|
|
65
|
+
await updateLocalConfig((settings) => {
|
|
70
66
|
if (Object.hasOwn(settings.syncSetups, name))
|
|
71
67
|
throw new Error(`Sync setup already exists: ${name}`);
|
|
72
68
|
if (!Object.hasOwn(settings.storageConnections, setup.storage.connection)) {
|
|
@@ -80,6 +76,7 @@ export async function addSyncSetup(name, setup, signal, expectedConnection) {
|
|
|
80
76
|
assertUniqueLocations(nextSetups, settings.storageConnections);
|
|
81
77
|
return {
|
|
82
78
|
...settings,
|
|
79
|
+
version: setupSettingsVersion(settings.version, setup),
|
|
83
80
|
syncSetups: nextSetups,
|
|
84
81
|
...(settings.activeSyncSetup ? {} : { activeSyncSetup: name }),
|
|
85
82
|
};
|
|
@@ -87,7 +84,7 @@ export async function addSyncSetup(name, setup, signal, expectedConnection) {
|
|
|
87
84
|
}
|
|
88
85
|
export async function updateSyncSetup(name, update, options = {}) {
|
|
89
86
|
validateConfigName(name, "sync setup");
|
|
90
|
-
await
|
|
87
|
+
await updateLocalConfig((settings) => {
|
|
91
88
|
const setup = settings.syncSetups[name];
|
|
92
89
|
if (!setup)
|
|
93
90
|
throw new Error(`Sync setup not found: ${name}`);
|
|
@@ -95,7 +92,7 @@ export async function updateSyncSetup(name, update, options = {}) {
|
|
|
95
92
|
syncCheckConfigFingerprint(configFromSettings(settings, name)) !== options.expectedConfigFingerprint) {
|
|
96
93
|
throw new SyncSetupReviewChangedError(`Sync setup “${name}” changed while it was open; reopen it and review the current configuration.`);
|
|
97
94
|
}
|
|
98
|
-
if (options.expectedInclude && !sameNames(
|
|
95
|
+
if (options.expectedInclude && !sameNames(configFromSettings(settings, name).include, options.expectedInclude)) {
|
|
99
96
|
throw new SyncSetupReviewChangedError(`Sync setup “${name}” included content changed while it was open; reopen it and review the current selection.`);
|
|
100
97
|
}
|
|
101
98
|
if (options.expectedStorage) {
|
|
@@ -116,12 +113,16 @@ export async function updateSyncSetup(name, update, options = {}) {
|
|
|
116
113
|
}
|
|
117
114
|
const nextSetups = { ...settings.syncSetups, [name]: nextSetup };
|
|
118
115
|
assertUniqueLocations(nextSetups, settings.storageConnections);
|
|
119
|
-
return {
|
|
116
|
+
return {
|
|
117
|
+
...settings,
|
|
118
|
+
version: setupSettingsVersion(settings.version, nextSetup, options.upgradeExclude),
|
|
119
|
+
syncSetups: nextSetups,
|
|
120
|
+
};
|
|
120
121
|
}, options.signal);
|
|
121
122
|
}
|
|
122
123
|
export async function removeSyncSetup(name, signal) {
|
|
123
124
|
validateConfigName(name, "sync setup");
|
|
124
|
-
await
|
|
125
|
+
await updateLocalConfig((settings) => {
|
|
125
126
|
if (!Object.hasOwn(settings.syncSetups, name))
|
|
126
127
|
throw new Error(`Sync setup not found: ${name}`);
|
|
127
128
|
const isCurrent = settings.activeSyncSetup === name;
|
|
@@ -138,7 +139,7 @@ export async function removeSyncSetup(name, signal) {
|
|
|
138
139
|
}
|
|
139
140
|
export async function removeStorageConnection(name, signal) {
|
|
140
141
|
validateConfigName(name, "storage connection");
|
|
141
|
-
await
|
|
142
|
+
await updateLocalConfig((settings) => {
|
|
142
143
|
const referenced = referencingSetupNames(settings.syncSetups, name)[0];
|
|
143
144
|
if (referenced) {
|
|
144
145
|
throw new Error(`Storage connection “${name}” is used by sync setup “${referenced}”.`);
|
|
@@ -151,13 +152,14 @@ export async function removeStorageConnection(name, signal) {
|
|
|
151
152
|
return { ...settings, storageConnections };
|
|
152
153
|
}, signal);
|
|
153
154
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
155
|
+
function setupSettingsVersion(current, setup, upgradeExclude) {
|
|
156
|
+
if (setup.sync.pathPolicy === "ignore-file")
|
|
157
|
+
return 8;
|
|
158
|
+
if (current < 7 && setup.sync.scope === "agent-directory")
|
|
159
|
+
return 7;
|
|
160
|
+
if (current < 6 && upgradeExclude)
|
|
161
|
+
return 6;
|
|
162
|
+
return current;
|
|
161
163
|
}
|
|
162
164
|
function referencingSetupNames(setups, connection) {
|
|
163
165
|
return Object.entries(setups)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ResolvedS3Backend, ResolvedSyncBackend } from "../backends/backend-types.js";
|
|
2
|
+
import type { EffectiveIgnorePolicy, SnapshotOptions } from "../snapshot/snapshot-types.js";
|
|
2
3
|
export type StorageConnectionType = "s3" | "git" | "webdav";
|
|
3
4
|
export type OnSwitchAction = "ask-before-pull" | "pull-after-switch" | "switch-only";
|
|
4
5
|
export interface S3CredentialsSettings {
|
|
@@ -58,9 +59,7 @@ export interface WebDavSyncSetupStorageSettings extends CommonSyncSetupStorageSe
|
|
|
58
59
|
branch?: never;
|
|
59
60
|
}
|
|
60
61
|
export type SyncSetupStorageSettings = S3SyncSetupStorageSettings | GitSyncSetupStorageSettings | WebDavSyncSetupStorageSettings;
|
|
61
|
-
|
|
62
|
-
include: string[];
|
|
63
|
-
exclude?: string[];
|
|
62
|
+
interface CommonSyncPolicySettings {
|
|
64
63
|
automatic: boolean;
|
|
65
64
|
/** Explicit opt-in, separate from the legacy observe/shutdown policy. */
|
|
66
65
|
automaticTransfer?: boolean;
|
|
@@ -75,13 +74,38 @@ export interface SyncPolicySettings {
|
|
|
75
74
|
partialSync?: boolean;
|
|
76
75
|
[key: string]: unknown;
|
|
77
76
|
}
|
|
77
|
+
export type SyncPolicySettings = CommonSyncPolicySettings & ({
|
|
78
|
+
scope?: never;
|
|
79
|
+
pathPolicy?: never;
|
|
80
|
+
ignoreFile?: never;
|
|
81
|
+
include: string[];
|
|
82
|
+
exclude?: string[];
|
|
83
|
+
reinclude?: never;
|
|
84
|
+
sessions?: never;
|
|
85
|
+
} | {
|
|
86
|
+
scope: "agent-directory";
|
|
87
|
+
pathPolicy?: never;
|
|
88
|
+
ignoreFile?: never;
|
|
89
|
+
include?: never;
|
|
90
|
+
exclude?: string[];
|
|
91
|
+
reinclude?: string[];
|
|
92
|
+
sessions?: boolean;
|
|
93
|
+
} | {
|
|
94
|
+
scope: "agent-directory";
|
|
95
|
+
pathPolicy: "ignore-file";
|
|
96
|
+
ignoreFile?: string;
|
|
97
|
+
include?: never;
|
|
98
|
+
exclude?: never;
|
|
99
|
+
reinclude?: never;
|
|
100
|
+
sessions?: boolean;
|
|
101
|
+
});
|
|
78
102
|
export interface SyncSetupSettings {
|
|
79
103
|
storage: SyncSetupStorageSettings;
|
|
80
104
|
sync: SyncPolicySettings;
|
|
81
105
|
[key: string]: unknown;
|
|
82
106
|
}
|
|
83
107
|
export interface PiSyncSettingsV3 {
|
|
84
|
-
version: 3 | 4 | 5 | 6;
|
|
108
|
+
version: 3 | 4 | 5 | 6 | 7 | 8;
|
|
85
109
|
activeSyncSetup?: string;
|
|
86
110
|
onSwitch: OnSwitchAction;
|
|
87
111
|
skipSecretScan?: boolean;
|
|
@@ -98,7 +122,14 @@ export interface SyncConfig<Backend extends ResolvedSyncBackend = ResolvedS3Back
|
|
|
98
122
|
/** Snapshot/wire identity retained behind the settings normalization boundary. */
|
|
99
123
|
snapshotIdentity: string;
|
|
100
124
|
include: string[];
|
|
125
|
+
scope?: "agent-directory";
|
|
126
|
+
pathPolicy?: "ignore-file";
|
|
127
|
+
ignoreFile?: string;
|
|
128
|
+
reservedIgnoreNames?: readonly string[];
|
|
129
|
+
ignorePolicy?: EffectiveIgnorePolicy;
|
|
130
|
+
validateIgnorePolicy?: SnapshotOptions["validateIgnorePolicy"];
|
|
101
131
|
exclude?: string[];
|
|
132
|
+
reinclude?: string[];
|
|
102
133
|
automatic: boolean;
|
|
103
134
|
automaticTransfer?: boolean;
|
|
104
135
|
agentMode?: boolean;
|
|
@@ -115,14 +146,17 @@ export interface SyncConfig<Backend extends ResolvedSyncBackend = ResolvedS3Back
|
|
|
115
146
|
}
|
|
116
147
|
export type AnySyncConfig = SyncConfig<ResolvedSyncBackend>;
|
|
117
148
|
export type CommonSyncConfig = Omit<AnySyncConfig, "backend">;
|
|
118
|
-
/** UI projection over a fully validated v3 setup; it is never persisted directly. */
|
|
119
149
|
export interface PartialConfig {
|
|
120
150
|
setupName: string;
|
|
121
151
|
connectionName: string;
|
|
122
152
|
storageKind: StorageConnectionType;
|
|
123
153
|
storagePath: string;
|
|
124
154
|
include: string[];
|
|
155
|
+
scope?: "agent-directory";
|
|
156
|
+
pathPolicy?: "ignore-file";
|
|
157
|
+
ignoreFile?: string;
|
|
125
158
|
exclude?: string[];
|
|
159
|
+
reinclude?: string[];
|
|
126
160
|
automatic: boolean;
|
|
127
161
|
automaticTransfer?: boolean;
|
|
128
162
|
agentMode?: boolean;
|
|
@@ -132,3 +166,4 @@ export interface PartialConfig {
|
|
|
132
166
|
bucket?: string;
|
|
133
167
|
branch?: string;
|
|
134
168
|
}
|
|
169
|
+
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
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";
|
|
4
5
|
import { normalizeSyncExclude } from "../sync/exclude-policy.js";
|
|
5
6
|
import { normalizeLocalFields } from "../sync/local-field-policy.js";
|
|
6
|
-
import { normalizeSyncInclude } from "../sync/sync-policy.js";
|
|
7
|
+
import { normalizeDirectoryRules, normalizeSyncInclude } from "../sync/sync-policy.js";
|
|
7
8
|
import { CONFIG_FILE_NAME } from "./config-file.js";
|
|
8
9
|
export const DEFAULT_ON_SWITCH = "ask-before-pull";
|
|
9
10
|
export function normalizeOnSwitch(value) {
|
|
@@ -13,8 +14,9 @@ export function normalizeOnSwitch(value) {
|
|
|
13
14
|
throw new Error('Invalid pi-sync settings: onSwitch must be "ask-before-pull", "pull-after-switch", or "switch-only".');
|
|
14
15
|
}
|
|
15
16
|
export function validateSettingsDocument(value) {
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
const version = value.version;
|
|
18
|
+
if (version !== 3 && version !== 4 && version !== 5 && version !== 6 && version !== 7 && version !== 8) {
|
|
19
|
+
throw new Error(`Unsupported pi-sync settings: version 3 through 8 is required. Keep the existing ${CONFIG_FILE_NAME} for recovery and use a compatible pi-sync client or review a separate supported setup; do not downgrade portable policies. pi-sync will not migrate or overwrite unsupported settings.`);
|
|
18
20
|
}
|
|
19
21
|
rejectLegacyFields(value, [
|
|
20
22
|
"profiles",
|
|
@@ -50,7 +52,7 @@ export function validateSettingsDocument(value) {
|
|
|
50
52
|
validateStorageConnection(name, requireOwnObject(storageConnections, name, "storage connection"));
|
|
51
53
|
}
|
|
52
54
|
for (const name of Object.keys(syncSetups)) {
|
|
53
|
-
validateSyncSetup(name, requireOwnObject(syncSetups, name, "sync setup"), storageConnections);
|
|
55
|
+
validateSyncSetup(name, requireOwnObject(syncSetups, name, "sync setup"), storageConnections, version);
|
|
54
56
|
}
|
|
55
57
|
const names = Object.keys(syncSetups);
|
|
56
58
|
const activeSyncSetup = optionalCanonicalReference(value.activeSyncSetup, "activeSyncSetup");
|
|
@@ -62,18 +64,6 @@ export function validateSettingsDocument(value) {
|
|
|
62
64
|
else if (!activeSyncSetup || !Object.hasOwn(syncSetups, activeSyncSetup)) {
|
|
63
65
|
throw new Error("Invalid pi-sync settings: activeSyncSetup must reference an existing own-property sync setup.");
|
|
64
66
|
}
|
|
65
|
-
for (const setup of Object.values(syncSetups)) {
|
|
66
|
-
const policy = setup.sync;
|
|
67
|
-
if (policy.localFields !== undefined && value.version !== 4 && value.version !== 5 && value.version !== 6)
|
|
68
|
-
throw new Error("localFields requires explicit settings version 4; older binaries must refuse portable state.");
|
|
69
|
-
}
|
|
70
|
-
for (const setup of Object.values(syncSetups)) {
|
|
71
|
-
const policy = setup.sync;
|
|
72
|
-
if (policy.exclude !== undefined && value.version !== 6)
|
|
73
|
-
throw new Error("sync.exclude requires explicit settings version 6; older clients must refuse excluded content.");
|
|
74
|
-
if ((policy.mergeContent || policy.partialSync) && value.version !== 5 && value.version !== 6)
|
|
75
|
-
throw new Error("Content/partial sync requires explicit settings version 5.");
|
|
76
|
-
}
|
|
77
67
|
validateUniqueRemoteSyncSetups(syncSetups, storageConnections);
|
|
78
68
|
return value;
|
|
79
69
|
}
|
|
@@ -118,7 +108,7 @@ function validateStorageConnection(name, value) {
|
|
|
118
108
|
throw new Error(`Invalid pi-sync settings: S3 credentials for “${name}” mix fields.`);
|
|
119
109
|
}
|
|
120
110
|
}
|
|
121
|
-
function validateSyncSetup(name, value, connections) {
|
|
111
|
+
function validateSyncSetup(name, value, connections, version) {
|
|
122
112
|
rejectLegacyFields(value, [
|
|
123
113
|
"profile",
|
|
124
114
|
"bucket",
|
|
@@ -159,14 +149,52 @@ function validateSyncSetup(name, value, connections) {
|
|
|
159
149
|
mixedSetupError("WebDAV", name);
|
|
160
150
|
}
|
|
161
151
|
}
|
|
162
|
-
if (!Object.hasOwn(sync, "include")) {
|
|
163
|
-
throw new Error(`Invalid pi-sync settings: sync setup “${name}” is missing sync.include.`);
|
|
164
|
-
}
|
|
165
|
-
const include = normalizeSyncInclude(sync.include);
|
|
166
|
-
normalizeSyncExclude(sync.exclude);
|
|
167
152
|
const localFields = normalizeLocalFields(sync.localFields);
|
|
168
|
-
if (
|
|
169
|
-
|
|
153
|
+
if (Object.hasOwn(sync, "pathPolicy")) {
|
|
154
|
+
if (sync.pathPolicy !== "ignore-file")
|
|
155
|
+
throw new Error("Invalid pi-sync settings: unsupported sync.pathPolicy.");
|
|
156
|
+
if (version < 8)
|
|
157
|
+
throw new Error("sync.pathPolicy requires explicit settings version 8.");
|
|
158
|
+
if (!Object.hasOwn(sync, "scope") || sync.scope !== "agent-directory")
|
|
159
|
+
throw new Error("Invalid pi-sync settings: sync.pathPolicy requires agent-directory scope.");
|
|
160
|
+
for (const key of ["include", "exclude", "reinclude"]) {
|
|
161
|
+
if (Object.hasOwn(sync, key))
|
|
162
|
+
throw new Error(`Invalid pi-sync settings: ignore-file policy cannot use sync.${key}.`);
|
|
163
|
+
}
|
|
164
|
+
if (Object.hasOwn(sync, "ignoreFile"))
|
|
165
|
+
validateIgnoreFilename(sync.ignoreFile);
|
|
166
|
+
}
|
|
167
|
+
else if (Object.hasOwn(sync, "ignoreFile")) {
|
|
168
|
+
throw new Error("Invalid pi-sync settings: sync.ignoreFile requires ignore-file pathPolicy.");
|
|
169
|
+
}
|
|
170
|
+
else if (Object.hasOwn(sync, "scope")) {
|
|
171
|
+
if (sync.scope !== "agent-directory")
|
|
172
|
+
throw new Error("Invalid pi-sync settings: unsupported sync.scope.");
|
|
173
|
+
if (version < 7)
|
|
174
|
+
throw new Error("sync.scope requires explicit settings version 7.");
|
|
175
|
+
if (Object.hasOwn(sync, "include"))
|
|
176
|
+
throw new Error("Invalid pi-sync settings: agent-directory scope cannot use sync.include.");
|
|
177
|
+
normalizeDirectoryRules(sync.exclude);
|
|
178
|
+
normalizeDirectoryRules(sync.reinclude);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
if (Object.hasOwn(sync, "sessions") || Object.hasOwn(sync, "reinclude"))
|
|
182
|
+
throw new Error("Invalid pi-sync settings: sync.sessions and sync.reinclude require agent-directory scope.");
|
|
183
|
+
if (!Object.hasOwn(sync, "include"))
|
|
184
|
+
throw new Error(`Invalid pi-sync settings: sync setup “${name}” is missing sync.include.`);
|
|
185
|
+
const include = normalizeSyncInclude(sync.include);
|
|
186
|
+
normalizeSyncExclude(sync.exclude);
|
|
187
|
+
if (localFields.length > 0 && !include.includes("settings.json"))
|
|
188
|
+
throw new Error("Nonempty localFields requires settings.json in sync.include.");
|
|
189
|
+
}
|
|
190
|
+
if (sync.sessions !== undefined && typeof sync.sessions !== "boolean")
|
|
191
|
+
throw new Error("Invalid pi-sync settings: sync.sessions must be boolean.");
|
|
192
|
+
if (sync.localFields !== undefined && version < 4)
|
|
193
|
+
throw new Error("localFields requires explicit settings version 4; older binaries must refuse portable state.");
|
|
194
|
+
if (sync.exclude !== undefined && version < 6)
|
|
195
|
+
throw new Error("sync.exclude requires explicit settings version 6; older clients must refuse excluded content.");
|
|
196
|
+
if ((sync.mergeContent || sync.partialSync) && version < 5)
|
|
197
|
+
throw new Error("Content/partial sync requires explicit settings version 5.");
|
|
170
198
|
for (const key of ["mergeContent", "partialSync", "agentMode", "continuous"])
|
|
171
199
|
if (sync[key] !== undefined && typeof sync[key] !== "boolean")
|
|
172
200
|
throw new Error(`${key} must be boolean.`);
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { type EngineContext as ExtensionCommandContext, type EngineContext as ExtensionContext } from "../host.js";
|
|
2
2
|
import type { AnySyncConfig } from "../settings/settings-types.js";
|
|
3
|
+
import { type SyncSelectionConfig } from "../sync/sync-policy.js";
|
|
3
4
|
import type { Snapshot, SnapshotOptions } from "./snapshot-types.js";
|
|
4
5
|
export declare function sessionDirFromContext(ctx: ExtensionCommandContext | ExtensionContext): string | undefined;
|
|
5
|
-
export declare function configuredSessionDir(): Promise<string | undefined>;
|
|
6
|
-
export declare function effectiveSessionRoot(ctx: ExtensionCommandContext | ExtensionContext): Promise<string>;
|
|
7
|
-
export declare function sessionDirForApply(ctx: ExtensionCommandContext | ExtensionContext, snapshot: Snapshot): Promise<string | undefined>;
|
|
6
|
+
export declare function configuredSessionDir(options?: Pick<SnapshotOptions, "reservedIgnoreNames" | "signal">): Promise<string | undefined>;
|
|
7
|
+
export declare function effectiveSessionRoot(ctx: ExtensionCommandContext | ExtensionContext, policy?: SyncSelectionConfig, signal?: AbortSignal): Promise<string>;
|
|
8
|
+
export declare function sessionDirForApply(ctx: ExtensionCommandContext | ExtensionContext, snapshot: Snapshot, options?: SnapshotOptions): Promise<string | undefined>;
|
|
8
9
|
/** Hash-only merge plans cannot describe installation into a different session root. */
|
|
9
|
-
export declare function requireStableMergeSessionRoot(before: Snapshot, after: Snapshot): void;
|
|
10
|
+
export declare function requireStableMergeSessionRoot(before: Snapshot, after: Snapshot, scope?: SnapshotOptions["scope"]): void;
|
|
10
11
|
export declare function agentDir(): string;
|
|
11
12
|
export declare function expandSessionDir(value: string): string;
|
|
12
13
|
export declare function snapshotOptionsForContext(ctx: ExtensionCommandContext | ExtensionContext, config: AnySyncConfig): SnapshotOptions;
|
|
14
|
+
export declare function resolvedSnapshotOptionsForContext(ctx: ExtensionCommandContext | ExtensionContext, config: AnySyncConfig, signal?: AbortSignal): Promise<SnapshotOptions>;
|