@narumitw/pi-sync-daemon 0.6.1 → 0.7.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 +15 -0
- package/README.md +3 -1
- package/dist/consent.js +11 -1
- package/dist/engine/backends/git/git-storage.js +11 -6
- package/dist/engine/paths.js +1 -1
- package/dist/engine/settings/config-file.js +2 -0
- package/dist/engine/settings/config.d.ts +2 -4
- package/dist/engine/settings/config.js +22 -7
- package/dist/engine/settings/settings-management.d.ts +2 -2
- package/dist/engine/settings/settings-management.js +27 -33
- package/dist/engine/settings/settings-types.d.ts +18 -4
- package/dist/engine/settings/settings-validation.js +34 -24
- package/dist/engine/snapshot/session-paths.d.ts +5 -3
- package/dist/engine/snapshot/session-paths.js +55 -9
- package/dist/engine/snapshot/snapshot-apply.d.ts +6 -7
- package/dist/engine/snapshot/snapshot-apply.js +88 -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.js +3 -4
- 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 +7 -2
- package/dist/engine/snapshot/snapshot-exclude-safety.js +180 -22
- 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 +37 -0
- package/dist/engine/snapshot/snapshot-transaction-images.js +357 -0
- package/dist/engine/snapshot/snapshot-transaction-policy.d.ts +50 -0
- package/dist/engine/snapshot/snapshot-transaction-policy.js +172 -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.d.ts +2 -1
- package/dist/engine/snapshot/snapshot-transaction.js +379 -331
- package/dist/engine/snapshot/snapshot-types.d.ts +24 -1
- package/dist/engine/snapshot/snapshot.d.ts +19 -2
- package/dist/engine/snapshot/snapshot.js +283 -26
- package/dist/engine/state/merge-baseline-store.js +20 -9
- package/dist/engine/state/state-types.d.ts +2 -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 +19 -9
- package/dist/engine/sync/continuous-watch.d.ts +4 -1
- package/dist/engine/sync/continuous-watch.js +86 -14
- 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 -5
- package/dist/engine/sync/local-fields.js +27 -8
- package/dist/engine/sync/merge-apply.js +155 -40
- package/dist/engine/sync/merge-journal.js +13 -4
- package/dist/engine/sync/merged-sync.js +21 -18
- package/dist/engine/sync/partial-progress.js +5 -3
- package/dist/engine/sync/remote-snapshot.d.ts +1 -0
- package/dist/engine/sync/remote-snapshot.js +8 -5
- 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 +3 -3
- package/dist/engine/sync/sync-mutations.d.ts +8 -1
- package/dist/engine/sync/sync-mutations.js +153 -72
- package/dist/engine/sync/sync-policy.d.ts +20 -10
- package/dist/engine/sync/sync-policy.js +170 -16
- package/dist/engine/sync/sync-queries.js +41 -31
- package/dist/engine/sync/sync-state.d.ts +11 -0
- package/dist/engine/sync/sync-state.js +24 -5
- package/dist/engine/ui/sync-format.js +22 -7
- package/dist/resolver-host.js +1 -1
- package/docs/architecture.md +6 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @narumitw/pi-sync-daemon
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 4d02a81: Default new Pi Sync setups to the Pi agent directory, with editable exclusions for sessions, managed binaries, and npm installations. Directory scope can restore selected exceptions to exclusions, but Pi credentials and project trust stay local. Existing selected-path setups keep their rules.
|
|
8
|
+
|
|
9
|
+
Recheck the directory scan limits before deletions and writes. If a recovery staging attempt stops before ownership is saved, retry in a fresh path and preserve the unverified files.
|
|
10
|
+
|
|
11
|
+
## 0.6.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- bb79479: Align the Sync daemon's model SDK with Pi 1.6. Keep pi-otel's Durable tracing compatible with Pi 1.6 and its parked tool states without exporting additional trace data.
|
|
16
|
+
- 77c45c6: Explain how to recover when the Sync daemon refuses a model whose definition or authentication source differs from the Pi host. Exact matching and no-fallback behavior are unchanged.
|
|
17
|
+
|
|
3
18
|
## 0.6.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ Pi starts the service only after configured interactive synchronization is neede
|
|
|
50
50
|
|
|
51
51
|
## ⚙️ Settings
|
|
52
52
|
|
|
53
|
-
Existing `pi-sync.json`, canonical `pi-sync/`, and legacy `.pisync/` remain in the selected agent directory. There is no second backend or credential configuration format. The daemon is the authoritative Pi Sync settings writer; stale reviews must reopen rather than overwrite a newer document.
|
|
53
|
+
Existing `pi-sync.json`, canonical `pi-sync/`, and legacy `.pisync/` remain in the selected agent directory. There is no second backend or credential configuration format. The daemon is the authoritative Pi Sync settings writer; stale reviews must reopen rather than overwrite a newer document. Settings version 7 and snapshot version 5 support [agent-directory scope](https://github.com/narumiruna/pi-extensions/blob/main/packages/pi-sync/skills/configure-pi-sync/references/configuration.md#agent-directory-scope). Older clients must refuse these formats, and existing selected-path setups do not change scope automatically.
|
|
54
54
|
|
|
55
55
|
Automatic, Autonomous, and Continuous defaults remain unchanged. Old permission for work while Pi is open does not permit work after the last client exits. `/sync daemon allow-after-exit` reviews that extra permission for the current setup and selected independently reproducible provider/model; `/sync daemon revoke-after-exit` revokes it. Setup changes invalidate the saved digest. Changes to an interactive client’s model, working directory, or session-directory binding revoke older unattended grants, including across restart. Print/JSON never launch a service; passive attachment to an existing service protects their sessions and pauses automatic work. Registered live PIDs keep the service alive, including passive, disconnected, publishing, and orderly retired clients. A valid explicit after-exit grant for the active setup keeps service lifetime under the existing fingerprint and binding rules; it does not expand transfer or model permission. Temporary provider or backend unavailability does not itself revoke that grant. Lifetime checks do not call a model, contact a provider or storage, or execute credential commands. There is no new setting, environment variable, or keep-alive flag.
|
|
56
56
|
|
|
@@ -62,6 +62,8 @@ Sync content, session conversations, storage credentials, and conflict evidence
|
|
|
62
62
|
|
|
63
63
|
## 🚧 Limitations
|
|
64
64
|
|
|
65
|
+
Autonomous conflict resolution requires the host and daemon to agree on the full model definition and independent authentication source. If the daemon rejects a model, align the Pi host and daemon’s bundled catalogs or verify a model with the same definition and auth source on both. Matching IDs alone are not enough. This check does not affect ordinary sync without model resolution.
|
|
66
|
+
|
|
65
67
|
A daemon does not lock every editor or shell command. Cooperating Pi clients reserve their actual public mutation queues; unregistered writers still require freshness checks and can cause safe refusal. Active sessions remain protected when contact is lost but their process is still alive. A heartbeat timeout is not proof of process exit.
|
|
66
68
|
|
|
67
69
|
Pi core's missing-`settings.json` write branch cannot be made safe with the existing file lock alone. The daemon refuses to create that file while a participating Pi is alive; create it through Pi first. Existing-file writes use the actual Pi settings-file lock.
|
package/dist/consent.js
CHANGED
|
@@ -3,6 +3,7 @@ import { closeSync, fstatSync, fsyncSync, lstatSync, mkdirSync, openSync, readFi
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { syncCheckConfigFingerprint } from "./engine/settings/config.js";
|
|
5
5
|
import { stateDir } from "./engine/state/state-directory.js";
|
|
6
|
+
import { safeTerminalText } from "./engine/ui/terminal-text.js";
|
|
6
7
|
import { record } from "./protocol.js";
|
|
7
8
|
function file(root) {
|
|
8
9
|
return path.join(stateDir(root), "daemon.json");
|
|
@@ -203,9 +204,18 @@ export async function authorizeAfterExit(execution, payload) {
|
|
|
203
204
|
throw new Error("Setup changed; reopen the daemon authorization review.");
|
|
204
205
|
if (payload.afterExit && (!config.continuous || !config.agentMode))
|
|
205
206
|
throw new Error("Enable the reviewed Autonomous and Continuous policies first.");
|
|
207
|
+
const paths = (rules) => rules?.map(safeTerminalText).join(", ") || "none";
|
|
208
|
+
const selection = config.scope === "agent-directory"
|
|
209
|
+
? [
|
|
210
|
+
"Selected content: all eligible files in the Pi agent directory",
|
|
211
|
+
`Excluded paths: ${paths(config.exclude)}`,
|
|
212
|
+
`Re-included paths: ${paths(config.reinclude)}`,
|
|
213
|
+
`Session opt-in: ${config.include.includes("sessions") ? "On — path rules still apply" : "Off"}`,
|
|
214
|
+
].join("\n")
|
|
215
|
+
: `Selected content: ${paths(config.include)}`;
|
|
206
216
|
const accepted = await execution.request("confirm", {
|
|
207
217
|
title: payload.afterExit ? "Allow continuous sync after all Pi clients exit?" : "Revoke unattended sync?",
|
|
208
|
-
message: `Setup: ${config.setupName}\
|
|
218
|
+
message: `Setup: ${safeTerminalText(config.setupName)}\n${selection}\nModel: ${safeTerminalText(facts?.model?.provider ?? "unavailable")}/${safeTerminalText(facts?.model?.id ?? "unavailable")}\n\n${payload.afterExit ? "The daemon may transfer selected private content and send conflict evidence to this independently available provider after Pi exits. Existing budgets, exclusions, journals, and stale-evidence checks still apply. No parent conversation or tools are sent. Changing this setup or model invalidates this permission." : "The daemon may remain alive, but no new transfer or model request may start with zero clients."}`,
|
|
209
219
|
});
|
|
210
220
|
execution.validate();
|
|
211
221
|
if (accepted !== true)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { sameLocalFields, validatePortableSnapshot, validateSnapshotFieldPolicy } from "../../sync/local-fields.js";
|
|
3
|
-
import { portableSnapshotSelection, sameSnapshotSelection, snapshotSelectionInclude, validateSnapshotSelection, } from "../../sync/sync-policy.js";
|
|
3
|
+
import { assertAgentDirectoryPathLayout, configuredSnapshotPathMatcher, portableSnapshotSelection, sameSnapshotSelection, snapshotSelectionInclude, validateSnapshotSelection, } from "../../sync/sync-policy.js";
|
|
4
4
|
export const GIT_MANIFEST_VERSION = 2;
|
|
5
5
|
export const MAX_GIT_MANIFEST_BYTES = 1024 * 1024;
|
|
6
6
|
export const MAX_GIT_TREE_OUTPUT_BYTES = 16 * 1024 * 1024;
|
|
@@ -21,7 +21,8 @@ export function requireGitManifest(value) {
|
|
|
21
21
|
(manifest.snapshotVersion !== 1 &&
|
|
22
22
|
manifest.snapshotVersion !== 2 &&
|
|
23
23
|
manifest.snapshotVersion !== 3 &&
|
|
24
|
-
manifest.snapshotVersion !== 4
|
|
24
|
+
manifest.snapshotVersion !== 4 &&
|
|
25
|
+
manifest.snapshotVersion !== 5) ||
|
|
25
26
|
typeof manifest.snapshotId !== "string" ||
|
|
26
27
|
manifest.snapshotId.length > 512 ||
|
|
27
28
|
!/^[A-Za-z0-9._-]+$/u.test(manifest.snapshotId) ||
|
|
@@ -55,9 +56,9 @@ export function requireGitManifest(value) {
|
|
|
55
56
|
throw new Error("Git publication manifest is malformed.");
|
|
56
57
|
}
|
|
57
58
|
validateSnapshotFieldPolicy({ version: manifest.snapshotVersion, localFields: manifest.localFields });
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
const selection = manifest.selection === undefined ? undefined : portableSnapshotSelection(manifest.selection);
|
|
60
|
+
validateSnapshotSelection({ version: manifest.snapshotVersion, selection });
|
|
61
|
+
const selected = selection?.scope ? configuredSnapshotPathMatcher(selection) : undefined;
|
|
61
62
|
let total = 0;
|
|
62
63
|
const paths = new Set();
|
|
63
64
|
for (const rawFile of manifest.files) {
|
|
@@ -67,6 +68,7 @@ export function requireGitManifest(value) {
|
|
|
67
68
|
const file = rawFile;
|
|
68
69
|
if (!hasExactKeys(file, ["path", "sha256", "size"]) ||
|
|
69
70
|
!isSafeSnapshotPath(file.path) ||
|
|
71
|
+
(selected !== undefined && !selected(file.path)) ||
|
|
70
72
|
typeof file.sha256 !== "string" ||
|
|
71
73
|
!/^[0-9a-f]{64}$/u.test(file.sha256) ||
|
|
72
74
|
typeof file.size !== "number" ||
|
|
@@ -80,7 +82,10 @@ export function requireGitManifest(value) {
|
|
|
80
82
|
}
|
|
81
83
|
paths.add(file.path);
|
|
82
84
|
}
|
|
83
|
-
|
|
85
|
+
if (selected)
|
|
86
|
+
assertAgentDirectoryPathLayout(paths);
|
|
87
|
+
else
|
|
88
|
+
assertNoPathConflicts([...paths]);
|
|
84
89
|
return manifest;
|
|
85
90
|
}
|
|
86
91
|
export function validateGitSnapshot(snapshot, manifest, namespace) {
|
package/dist/engine/paths.js
CHANGED
|
@@ -23,7 +23,7 @@ export function isDeniedPath(relativePath) {
|
|
|
23
23
|
}
|
|
24
24
|
export function isPathInside(parent, child) {
|
|
25
25
|
const relative = path.relative(path.resolve(parent), path.resolve(child));
|
|
26
|
-
return relative
|
|
26
|
+
return relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
27
27
|
}
|
|
28
28
|
export function safeJoin(root, relativePath) {
|
|
29
29
|
const target = path.resolve(root, relativePath);
|
|
@@ -171,6 +171,8 @@ export function updateLocalConfigDocument(defaultValue, update, validate, signal
|
|
|
171
171
|
signal?.throwIfAborted();
|
|
172
172
|
const document = snapshot ? { path: configPath, ...snapshot } : undefined;
|
|
173
173
|
validateSource?.(document);
|
|
174
|
+
if (document)
|
|
175
|
+
validate(document.parsed);
|
|
174
176
|
const current = document ? structuredClone(document.parsed) : structuredClone(defaultValue);
|
|
175
177
|
const next = update(current);
|
|
176
178
|
validate(next);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type SyncSelectionConfig } from "../sync/sync-policy.js";
|
|
1
2
|
import type { AnySyncConfig, PartialConfig, PiSyncSettingsV3, StorageConnectionSettings, SyncSetupSettings } from "./settings-types.js";
|
|
2
3
|
export declare function loadConfig(setupName?: string): Promise<AnySyncConfig>;
|
|
3
4
|
/** A background freshness read must never trigger legacy-file publication. */
|
|
@@ -16,9 +17,6 @@ export declare function sessionTokenWarnings(config: {
|
|
|
16
17
|
endpoint?: string;
|
|
17
18
|
sessionToken?: string;
|
|
18
19
|
}): string[];
|
|
19
|
-
export declare function syncSessionsWarnings(config:
|
|
20
|
-
include: readonly string[];
|
|
21
|
-
exclude?: readonly string[];
|
|
22
|
-
}): string[];
|
|
20
|
+
export declare function syncSessionsWarnings(config: SyncSelectionConfig): string[];
|
|
23
21
|
export declare function isEnabled(value: boolean | string | undefined, defaultValue: boolean): boolean;
|
|
24
22
|
export declare function isExplicitlyEnabled(value: boolean | string | undefined): boolean;
|
|
@@ -4,7 +4,7 @@ import { normalizeGitBranch, normalizeGitDirectory, normalizeGitRemote } from ".
|
|
|
4
4
|
import { normalizeWebDavPath, normalizeWebDavUrl } from "../backends/webdav/webdav-config.js";
|
|
5
5
|
import { normalizeSyncExclude } from "../sync/exclude-policy.js";
|
|
6
6
|
import { normalizeLocalFields } from "../sync/local-field-policy.js";
|
|
7
|
-
import { normalizeSyncInclude, syncSessionsSelected } from "../sync/sync-policy.js";
|
|
7
|
+
import { normalizeDirectoryRules, normalizeSyncInclude, syncDirectoryPolicyKey, syncSessionsSelected, } from "../sync/sync-policy.js";
|
|
8
8
|
import { localConfigPath, readActiveLocalConfigDocumentForRepair } from "./config-file.js";
|
|
9
9
|
import { requireSettings } from "./settings-store.js";
|
|
10
10
|
import { DEFAULT_ON_SWITCH, isCloudflareR2Endpoint, normalizeS3Bucket, normalizeS3Endpoint, normalizeStoragePath, optionalString, ownObject, requiredString, validateConfigName, validateSettingsDocument, } from "./settings-validation.js";
|
|
@@ -44,7 +44,9 @@ export async function loadPartialConfig(setupName) {
|
|
|
44
44
|
setupName: config.setupName,
|
|
45
45
|
...storageReviewFromConfig(config),
|
|
46
46
|
include: [...config.include],
|
|
47
|
+
...(config.scope === undefined ? {} : { scope: config.scope }),
|
|
47
48
|
...(config.exclude === undefined ? {} : { exclude: [...config.exclude] }),
|
|
49
|
+
...(config.reinclude === undefined ? {} : { reinclude: [...config.reinclude] }),
|
|
48
50
|
automatic: config.automatic,
|
|
49
51
|
automaticTransfer: config.automaticTransfer ?? false,
|
|
50
52
|
agentMode: config.agentMode ?? false,
|
|
@@ -60,6 +62,7 @@ export function syncSetupReviewIdentity(setupName, setup, connectionName, connec
|
|
|
60
62
|
return syncConfigReviewIdentity(resolveSyncConfig(setupName, setup, connectionName, connection, DEFAULT_ON_SWITCH, false, true));
|
|
61
63
|
}
|
|
62
64
|
export function syncConfigReviewIdentity(config) {
|
|
65
|
+
const directoryPolicy = syncDirectoryPolicyKey(config);
|
|
63
66
|
return JSON.stringify([
|
|
64
67
|
config.setupName,
|
|
65
68
|
config.connectionName,
|
|
@@ -74,9 +77,11 @@ export function syncConfigReviewIdentity(config) {
|
|
|
74
77
|
config.partialSync ?? false,
|
|
75
78
|
// Preserve existing Off identities and cached candidates across the upgrade.
|
|
76
79
|
...(config.continuous ? ["continuous"] : []),
|
|
77
|
-
...(
|
|
78
|
-
? []
|
|
79
|
-
:
|
|
80
|
+
...(directoryPolicy !== undefined
|
|
81
|
+
? [directoryPolicy]
|
|
82
|
+
: config.exclude === undefined
|
|
83
|
+
? []
|
|
84
|
+
: ["exclude", normalizeSyncExclude(config.exclude).map((rule) => rule.toLowerCase())]),
|
|
80
85
|
]);
|
|
81
86
|
}
|
|
82
87
|
export function syncConfigReviewFingerprint(config) {
|
|
@@ -103,14 +108,24 @@ function storageReviewFromConfig(config) {
|
|
|
103
108
|
function resolveSyncConfig(setupName, setup, connectionName, connection, onSwitch, skipSecretScan, showStatus) {
|
|
104
109
|
const storagePath = normalizeStoragePath(setup.storage.path);
|
|
105
110
|
const namespace = storagePath === "./" ? "root" : storagePath.slice(storagePath.lastIndexOf("/") + 1);
|
|
106
|
-
const
|
|
111
|
+
const policy = setup.sync;
|
|
112
|
+
const selection = policy.scope === "agent-directory"
|
|
113
|
+
? {
|
|
114
|
+
scope: policy.scope,
|
|
115
|
+
include: policy.sessions ? ["sessions"] : [],
|
|
116
|
+
...(policy.exclude === undefined ? {} : { exclude: normalizeDirectoryRules(policy.exclude) }),
|
|
117
|
+
...(policy.reinclude === undefined ? {} : { reinclude: normalizeDirectoryRules(policy.reinclude) }),
|
|
118
|
+
}
|
|
119
|
+
: {
|
|
120
|
+
include: normalizeSyncInclude(policy.include),
|
|
121
|
+
...(policy.exclude === undefined ? {} : { exclude: normalizeSyncExclude(policy.exclude) }),
|
|
122
|
+
};
|
|
107
123
|
const common = {
|
|
108
124
|
setupName,
|
|
109
125
|
connectionName,
|
|
110
126
|
storagePath,
|
|
111
127
|
snapshotIdentity: namespace,
|
|
112
|
-
|
|
113
|
-
...(setup.sync.exclude === undefined ? {} : { exclude: normalizeSyncExclude(setup.sync.exclude) }),
|
|
128
|
+
...selection,
|
|
114
129
|
automatic: setup.sync.automatic,
|
|
115
130
|
automaticTransfer: setup.sync.automaticTransfer ?? false,
|
|
116
131
|
agentMode: setup.sync.agentMode ?? false,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SyncSetupStorageReview } from "./config.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { StorageConnectionSettings, SyncSetupSettings } from "./settings-types.js";
|
|
3
3
|
export declare class SyncSetupReviewChangedError extends Error {
|
|
4
4
|
constructor(message: string);
|
|
5
5
|
}
|
|
@@ -8,7 +8,7 @@ export declare function saveNewV3Settings(input: {
|
|
|
8
8
|
connectionName: string;
|
|
9
9
|
connection: StorageConnectionSettings;
|
|
10
10
|
setup: SyncSetupSettings;
|
|
11
|
-
}, signal?: AbortSignal): Promise<PiSyncSettingsV3>;
|
|
11
|
+
}, signal?: AbortSignal): Promise<import("./settings-types.js").PiSyncSettingsV3>;
|
|
12
12
|
export declare function addStorageConnection(name: string, connection: StorageConnectionSettings, signal?: AbortSignal): Promise<void>;
|
|
13
13
|
export declare function updateStorageConnection(name: string, update: (connection: StorageConnectionSettings) => StorageConnectionSettings, expectedSetups?: readonly string[], signal?: AbortSignal): Promise<void>;
|
|
14
14
|
export declare function addSyncSetup(name: string, setup: SyncSetupSettings, signal?: AbortSignal, expectedConnection?: StorageConnectionSettings): Promise<void>;
|
|
@@ -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: setup.sync.scope === "agent-directory" ? 7 : current.version,
|
|
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: setup.sync.scope === "agent-directory" ? 7 : settings.version,
|
|
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,17 @@ export async function updateSyncSetup(name, update, options = {}) {
|
|
|
116
113
|
}
|
|
117
114
|
const nextSetups = { ...settings.syncSetups, [name]: nextSetup };
|
|
118
115
|
assertUniqueLocations(nextSetups, settings.storageConnections);
|
|
119
|
-
|
|
116
|
+
const version = nextSetup.sync.scope === "agent-directory"
|
|
117
|
+
? 7
|
|
118
|
+
: options.upgradeExclude && settings.version < 6
|
|
119
|
+
? 6
|
|
120
|
+
: settings.version;
|
|
121
|
+
return { ...settings, version, syncSetups: nextSetups };
|
|
120
122
|
}, options.signal);
|
|
121
123
|
}
|
|
122
124
|
export async function removeSyncSetup(name, signal) {
|
|
123
125
|
validateConfigName(name, "sync setup");
|
|
124
|
-
await
|
|
126
|
+
await updateLocalConfig((settings) => {
|
|
125
127
|
if (!Object.hasOwn(settings.syncSetups, name))
|
|
126
128
|
throw new Error(`Sync setup not found: ${name}`);
|
|
127
129
|
const isCurrent = settings.activeSyncSetup === name;
|
|
@@ -138,7 +140,7 @@ export async function removeSyncSetup(name, signal) {
|
|
|
138
140
|
}
|
|
139
141
|
export async function removeStorageConnection(name, signal) {
|
|
140
142
|
validateConfigName(name, "storage connection");
|
|
141
|
-
await
|
|
143
|
+
await updateLocalConfig((settings) => {
|
|
142
144
|
const referenced = referencingSetupNames(settings.syncSetups, name)[0];
|
|
143
145
|
if (referenced) {
|
|
144
146
|
throw new Error(`Storage connection “${name}” is used by sync setup “${referenced}”.`);
|
|
@@ -151,14 +153,6 @@ export async function removeStorageConnection(name, signal) {
|
|
|
151
153
|
return { ...settings, storageConnections };
|
|
152
154
|
}, signal);
|
|
153
155
|
}
|
|
154
|
-
async function updateSettings(update, signal) {
|
|
155
|
-
return updateLocalConfig((settings) => {
|
|
156
|
-
if (settings.version !== 3 && settings.version !== 4 && settings.version !== 5 && settings.version !== 6) {
|
|
157
|
-
throw new Error("Storage connections and sync setups require version 3, 4, 5 or 6 pi-sync settings.");
|
|
158
|
-
}
|
|
159
|
-
return update(settings);
|
|
160
|
-
}, signal);
|
|
161
|
-
}
|
|
162
156
|
function referencingSetupNames(setups, connection) {
|
|
163
157
|
return Object.entries(setups)
|
|
164
158
|
.filter(([, setup]) => setup.storage.connection === connection)
|
|
@@ -58,8 +58,7 @@ export interface WebDavSyncSetupStorageSettings extends CommonSyncSetupStorageSe
|
|
|
58
58
|
branch?: never;
|
|
59
59
|
}
|
|
60
60
|
export type SyncSetupStorageSettings = S3SyncSetupStorageSettings | GitSyncSetupStorageSettings | WebDavSyncSetupStorageSettings;
|
|
61
|
-
|
|
62
|
-
include: string[];
|
|
61
|
+
interface CommonSyncPolicySettings {
|
|
63
62
|
exclude?: string[];
|
|
64
63
|
automatic: boolean;
|
|
65
64
|
/** Explicit opt-in, separate from the legacy observe/shutdown policy. */
|
|
@@ -75,13 +74,24 @@ export interface SyncPolicySettings {
|
|
|
75
74
|
partialSync?: boolean;
|
|
76
75
|
[key: string]: unknown;
|
|
77
76
|
}
|
|
77
|
+
export type SyncPolicySettings = CommonSyncPolicySettings & ({
|
|
78
|
+
scope?: never;
|
|
79
|
+
include: string[];
|
|
80
|
+
reinclude?: never;
|
|
81
|
+
sessions?: never;
|
|
82
|
+
} | {
|
|
83
|
+
scope: "agent-directory";
|
|
84
|
+
include?: never;
|
|
85
|
+
reinclude?: string[];
|
|
86
|
+
sessions?: boolean;
|
|
87
|
+
});
|
|
78
88
|
export interface SyncSetupSettings {
|
|
79
89
|
storage: SyncSetupStorageSettings;
|
|
80
90
|
sync: SyncPolicySettings;
|
|
81
91
|
[key: string]: unknown;
|
|
82
92
|
}
|
|
83
93
|
export interface PiSyncSettingsV3 {
|
|
84
|
-
version: 3 | 4 | 5 | 6;
|
|
94
|
+
version: 3 | 4 | 5 | 6 | 7;
|
|
85
95
|
activeSyncSetup?: string;
|
|
86
96
|
onSwitch: OnSwitchAction;
|
|
87
97
|
skipSecretScan?: boolean;
|
|
@@ -98,7 +108,9 @@ export interface SyncConfig<Backend extends ResolvedSyncBackend = ResolvedS3Back
|
|
|
98
108
|
/** Snapshot/wire identity retained behind the settings normalization boundary. */
|
|
99
109
|
snapshotIdentity: string;
|
|
100
110
|
include: string[];
|
|
111
|
+
scope?: "agent-directory";
|
|
101
112
|
exclude?: string[];
|
|
113
|
+
reinclude?: string[];
|
|
102
114
|
automatic: boolean;
|
|
103
115
|
automaticTransfer?: boolean;
|
|
104
116
|
agentMode?: boolean;
|
|
@@ -115,14 +127,15 @@ export interface SyncConfig<Backend extends ResolvedSyncBackend = ResolvedS3Back
|
|
|
115
127
|
}
|
|
116
128
|
export type AnySyncConfig = SyncConfig<ResolvedSyncBackend>;
|
|
117
129
|
export type CommonSyncConfig = Omit<AnySyncConfig, "backend">;
|
|
118
|
-
/** UI projection over a fully validated v3 setup; it is never persisted directly. */
|
|
119
130
|
export interface PartialConfig {
|
|
120
131
|
setupName: string;
|
|
121
132
|
connectionName: string;
|
|
122
133
|
storageKind: StorageConnectionType;
|
|
123
134
|
storagePath: string;
|
|
124
135
|
include: string[];
|
|
136
|
+
scope?: "agent-directory";
|
|
125
137
|
exclude?: string[];
|
|
138
|
+
reinclude?: string[];
|
|
126
139
|
automatic: boolean;
|
|
127
140
|
automaticTransfer?: boolean;
|
|
128
141
|
agentMode?: boolean;
|
|
@@ -132,3 +145,4 @@ export interface PartialConfig {
|
|
|
132
145
|
bucket?: string;
|
|
133
146
|
branch?: string;
|
|
134
147
|
}
|
|
148
|
+
export {};
|
|
@@ -3,7 +3,7 @@ import { normalizeGitBranch, normalizeGitDirectory, normalizeGitRemote, normaliz
|
|
|
3
3
|
import { normalizeWebDavIdentityUrl, normalizeWebDavPath, normalizeWebDavUrl, validateWebDavCredentials, } from "../backends/webdav/webdav-config.js";
|
|
4
4
|
import { normalizeSyncExclude } from "../sync/exclude-policy.js";
|
|
5
5
|
import { normalizeLocalFields } from "../sync/local-field-policy.js";
|
|
6
|
-
import { normalizeSyncInclude } from "../sync/sync-policy.js";
|
|
6
|
+
import { normalizeDirectoryRules, normalizeSyncInclude } from "../sync/sync-policy.js";
|
|
7
7
|
import { CONFIG_FILE_NAME } from "./config-file.js";
|
|
8
8
|
export const DEFAULT_ON_SWITCH = "ask-before-pull";
|
|
9
9
|
export function normalizeOnSwitch(value) {
|
|
@@ -13,8 +13,9 @@ export function normalizeOnSwitch(value) {
|
|
|
13
13
|
throw new Error('Invalid pi-sync settings: onSwitch must be "ask-before-pull", "pull-after-switch", or "switch-only".');
|
|
14
14
|
}
|
|
15
15
|
export function validateSettingsDocument(value) {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const version = value.version;
|
|
17
|
+
if (version !== 3 && version !== 4 && version !== 5 && version !== 6 && version !== 7) {
|
|
18
|
+
throw new Error(`Unsupported pi-sync settings: version 3, 4, 5, 6 or 7 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
19
|
}
|
|
19
20
|
rejectLegacyFields(value, [
|
|
20
21
|
"profiles",
|
|
@@ -50,7 +51,7 @@ export function validateSettingsDocument(value) {
|
|
|
50
51
|
validateStorageConnection(name, requireOwnObject(storageConnections, name, "storage connection"));
|
|
51
52
|
}
|
|
52
53
|
for (const name of Object.keys(syncSetups)) {
|
|
53
|
-
validateSyncSetup(name, requireOwnObject(syncSetups, name, "sync setup"), storageConnections);
|
|
54
|
+
validateSyncSetup(name, requireOwnObject(syncSetups, name, "sync setup"), storageConnections, version);
|
|
54
55
|
}
|
|
55
56
|
const names = Object.keys(syncSetups);
|
|
56
57
|
const activeSyncSetup = optionalCanonicalReference(value.activeSyncSetup, "activeSyncSetup");
|
|
@@ -62,18 +63,6 @@ export function validateSettingsDocument(value) {
|
|
|
62
63
|
else if (!activeSyncSetup || !Object.hasOwn(syncSetups, activeSyncSetup)) {
|
|
63
64
|
throw new Error("Invalid pi-sync settings: activeSyncSetup must reference an existing own-property sync setup.");
|
|
64
65
|
}
|
|
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
66
|
validateUniqueRemoteSyncSetups(syncSetups, storageConnections);
|
|
78
67
|
return value;
|
|
79
68
|
}
|
|
@@ -118,7 +107,7 @@ function validateStorageConnection(name, value) {
|
|
|
118
107
|
throw new Error(`Invalid pi-sync settings: S3 credentials for “${name}” mix fields.`);
|
|
119
108
|
}
|
|
120
109
|
}
|
|
121
|
-
function validateSyncSetup(name, value, connections) {
|
|
110
|
+
function validateSyncSetup(name, value, connections, version) {
|
|
122
111
|
rejectLegacyFields(value, [
|
|
123
112
|
"profile",
|
|
124
113
|
"bucket",
|
|
@@ -159,14 +148,35 @@ function validateSyncSetup(name, value, connections) {
|
|
|
159
148
|
mixedSetupError("WebDAV", name);
|
|
160
149
|
}
|
|
161
150
|
}
|
|
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
151
|
const localFields = normalizeLocalFields(sync.localFields);
|
|
168
|
-
if (
|
|
169
|
-
|
|
152
|
+
if (Object.hasOwn(sync, "scope")) {
|
|
153
|
+
if (sync.scope !== "agent-directory")
|
|
154
|
+
throw new Error("Invalid pi-sync settings: unsupported sync.scope.");
|
|
155
|
+
if (version < 7)
|
|
156
|
+
throw new Error("sync.scope requires explicit settings version 7.");
|
|
157
|
+
if (Object.hasOwn(sync, "include"))
|
|
158
|
+
throw new Error("Invalid pi-sync settings: agent-directory scope cannot use sync.include.");
|
|
159
|
+
normalizeDirectoryRules(sync.exclude);
|
|
160
|
+
normalizeDirectoryRules(sync.reinclude);
|
|
161
|
+
if (sync.sessions !== undefined && typeof sync.sessions !== "boolean")
|
|
162
|
+
throw new Error("Invalid pi-sync settings: sync.sessions must be boolean.");
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
if (Object.hasOwn(sync, "sessions") || Object.hasOwn(sync, "reinclude"))
|
|
166
|
+
throw new Error("Invalid pi-sync settings: sync.sessions and sync.reinclude require agent-directory scope.");
|
|
167
|
+
if (!Object.hasOwn(sync, "include"))
|
|
168
|
+
throw new Error(`Invalid pi-sync settings: sync setup “${name}” is missing sync.include.`);
|
|
169
|
+
const include = normalizeSyncInclude(sync.include);
|
|
170
|
+
normalizeSyncExclude(sync.exclude);
|
|
171
|
+
if (localFields.length > 0 && !include.includes("settings.json"))
|
|
172
|
+
throw new Error("Nonempty localFields requires settings.json in sync.include.");
|
|
173
|
+
}
|
|
174
|
+
if (sync.localFields !== undefined && version < 4)
|
|
175
|
+
throw new Error("localFields requires explicit settings version 4; older binaries must refuse portable state.");
|
|
176
|
+
if (sync.exclude !== undefined && version < 6)
|
|
177
|
+
throw new Error("sync.exclude requires explicit settings version 6; older clients must refuse excluded content.");
|
|
178
|
+
if ((sync.mergeContent || sync.partialSync) && version < 5)
|
|
179
|
+
throw new Error("Content/partial sync requires explicit settings version 5.");
|
|
170
180
|
for (const key of ["mergeContent", "partialSync", "agentMode", "continuous"])
|
|
171
181
|
if (sync[key] !== undefined && typeof sync[key] !== "boolean")
|
|
172
182
|
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
6
|
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>;
|
|
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>;
|