@narumitw/pi-sync 0.66.0 → 0.67.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 +6 -0
- package/README.md +10 -1
- package/dist/chunks/{command-handler-44EFGPWH.ts → command-handler-SQC2L2FJ.ts} +2 -2
- package/dist/chunks/{manager-ui-CVZLMXJ5.ts → manager-ui-DWOMAJKE.ts} +116 -3
- package/dist/chunks/manager-ui-DWOMAJKE.ts.map +7 -0
- package/dist/daemon/dist/engine/ignore/ignore-edit.js +2 -2
- package/dist/daemon/dist/engine/ignore/ignore-settings.js +2 -1
- package/dist/daemon/dist/engine/settings/config-file.js +3 -0
- package/dist/daemon/dist/engine/settings/config.js +5 -5
- package/dist/daemon/dist/engine/settings/settings-management.js +6 -1
- package/dist/daemon/dist/engine/settings/settings-validation.js +21 -2
- package/dist/daemon/dist/engine/sync/continuous-errors.js +6 -0
- package/dist/daemon/dist/engine/sync/continuous-sync.js +4 -2
- package/dist/daemon/dist/engine/sync/ignore-adoption.js +9 -0
- package/dist/daemon/dist/engine/sync/merge-apply.js +18 -1
- package/dist/daemon/dist/engine/sync/merged-sync.js +36 -4
- package/dist/daemon/dist/engine/sync/push-review.js +33 -0
- package/dist/daemon/dist/engine/sync/sync-mutations.js +38 -48
- package/dist/daemon/dist/engine/sync/sync-rollback.js +16 -2
- package/dist/daemon/dist/engine/sync/transfer-freshness.js +3 -2
- package/dist/daemon/dist/engine/sync/transfer-size-limits.js +92 -0
- package/dist/daemon/package.json +1 -1
- package/dist/index.ts +1 -1
- package/docs/daemon-migration.md +6 -0
- package/docs/tui-contract.md +4 -3
- package/package.json +2 -2
- package/skills/configure-pi-sync/SKILL.md +1 -1
- package/skills/configure-pi-sync/references/configuration.md +33 -6
- package/src/ui/settings-ui.ts +128 -4
- package/dist/chunks/manager-ui-CVZLMXJ5.ts.map +0 -7
- /package/dist/chunks/{command-handler-44EFGPWH.ts.map → command-handler-SQC2L2FJ.ts.map} +0 -0
|
@@ -85,6 +85,9 @@ export async function addSyncSetup(name, setup, signal, expectedConnection) {
|
|
|
85
85
|
export async function updateSyncSetup(name, update, options = {}) {
|
|
86
86
|
validateConfigName(name, "sync setup");
|
|
87
87
|
await updateLocalConfig((settings) => {
|
|
88
|
+
if (options.expectedActiveSetup && settings.activeSyncSetup !== name) {
|
|
89
|
+
throw new SyncSetupReviewChangedError("The active sync setup changed while Settings was open; reopen it.");
|
|
90
|
+
}
|
|
88
91
|
const setup = settings.syncSetups[name];
|
|
89
92
|
if (!setup)
|
|
90
93
|
throw new Error(`Sync setup not found: ${name}`);
|
|
@@ -159,7 +162,9 @@ export async function removeStorageConnection(name, signal) {
|
|
|
159
162
|
}, signal);
|
|
160
163
|
}
|
|
161
164
|
function setupSettingsVersion(current, setup, upgradeExclude) {
|
|
162
|
-
if (setup.sync.
|
|
165
|
+
if (setup.sync.maxFileSizeMiB !== undefined || setup.sync.maxDirectorySizeMiB !== undefined)
|
|
166
|
+
return 9;
|
|
167
|
+
if (current < 8 && setup.sync.pathPolicy === "ignore-file")
|
|
163
168
|
return 8;
|
|
164
169
|
if (current < 7 && setup.sync.scope === "agent-directory")
|
|
165
170
|
return 7;
|
|
@@ -15,8 +15,14 @@ export function normalizeOnSwitch(value) {
|
|
|
15
15
|
}
|
|
16
16
|
export function validateSettingsDocument(value) {
|
|
17
17
|
const version = value.version;
|
|
18
|
-
if (version !== 3 &&
|
|
19
|
-
|
|
18
|
+
if (version !== 3 &&
|
|
19
|
+
version !== 4 &&
|
|
20
|
+
version !== 5 &&
|
|
21
|
+
version !== 6 &&
|
|
22
|
+
version !== 7 &&
|
|
23
|
+
version !== 8 &&
|
|
24
|
+
version !== 9) {
|
|
25
|
+
throw new Error(`Unsupported pi-sync settings: version 3 through 9 is required. Keep the existing ${CONFIG_FILE_NAME} for recovery and use a compatible Pi Sync client and daemon; do not downgrade settings. Pi Sync will not migrate or overwrite unsupported settings.`);
|
|
20
26
|
}
|
|
21
27
|
rejectLegacyFields(value, [
|
|
22
28
|
"profiles",
|
|
@@ -195,6 +201,19 @@ function validateSyncSetup(name, value, connections, version) {
|
|
|
195
201
|
throw new Error("sync.exclude requires explicit settings version 6; older clients must refuse excluded content.");
|
|
196
202
|
if ((sync.mergeContent || sync.partialSync) && version < 5)
|
|
197
203
|
throw new Error("Content/partial sync requires explicit settings version 5.");
|
|
204
|
+
for (const key of ["maxFileSizeMiB", "maxDirectorySizeMiB"]) {
|
|
205
|
+
const limit = sync[key];
|
|
206
|
+
if (limit === undefined)
|
|
207
|
+
continue;
|
|
208
|
+
if (version < 9)
|
|
209
|
+
throw new Error(`sync.${key} requires explicit settings version 9.`);
|
|
210
|
+
if (typeof limit !== "number" ||
|
|
211
|
+
!Number.isInteger(limit) ||
|
|
212
|
+
limit <= 0 ||
|
|
213
|
+
!Number.isSafeInteger(limit * 1_048_576)) {
|
|
214
|
+
throw new Error(`Invalid pi-sync settings: sync.${key} must be a positive whole number of MiB with a safe byte count.`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
198
217
|
for (const key of ["mergeContent", "partialSync", "agentMode", "continuous"])
|
|
199
218
|
if (sync[key] !== undefined && typeof sync[key] !== "boolean")
|
|
200
219
|
throw new Error(`${key} must be boolean.`);
|
|
@@ -10,6 +10,12 @@ export class ContinuousError extends Error {
|
|
|
10
10
|
this.name = "ContinuousError";
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
export class TransferSizeError extends ContinuousError {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super("unsafe", message);
|
|
16
|
+
this.name = "TransferSizeError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
13
19
|
export function continuousFailure(error) {
|
|
14
20
|
const seen = new Set();
|
|
15
21
|
for (let current = error; current && !seen.has(current) && seen.size < 8;) {
|
|
@@ -6,7 +6,7 @@ import { withStateDirectoryAccess } from "../state/state-directory.js";
|
|
|
6
6
|
import { readStateForConfig } from "../state/sync-state-store.js";
|
|
7
7
|
import { setSyncStatus, syncStatusFailureReason } from "../ui/sync-status.js";
|
|
8
8
|
import { withAgentSyncLock } from "./agent-sync.js";
|
|
9
|
-
import { ContinuousError, continuousFailure } from "./continuous-errors.js";
|
|
9
|
+
import { ContinuousError, continuousFailure, TransferSizeError, } from "./continuous-errors.js";
|
|
10
10
|
import { acquireContinuousLease } from "./continuous-lease.js";
|
|
11
11
|
import { normalizeContinuousClock, readContinuousRecord, reserveContinuousRequest, updateContinuousRecord, } from "./continuous-record.js";
|
|
12
12
|
import { continuousBinding, hashContinuous } from "./continuous-storage.js";
|
|
@@ -343,7 +343,9 @@ export function createContinuousSync(loaders, clock = systemClock, publish, diag
|
|
|
343
343
|
});
|
|
344
344
|
validate();
|
|
345
345
|
if (announce && !failure.retry)
|
|
346
|
-
ctx.ui.notify(
|
|
346
|
+
ctx.ui.notify(error instanceof TransferSizeError
|
|
347
|
+
? `Continuous sync blocked. ${error.message}`
|
|
348
|
+
: `Continuous sync blocked (${failure.kind}). Review /sync or repair the setup. Evidence was retained.`, "warning");
|
|
347
349
|
}
|
|
348
350
|
finally {
|
|
349
351
|
cancelDeadline();
|
|
@@ -28,6 +28,7 @@ import { readSnapshotForHead, sameRemoteHead } from "./remote-snapshot.js";
|
|
|
28
28
|
import { backupDirectionalSnapshot, captureMutationOwner, maybeReload, protectedSessionPaths } from "./sync-local.js";
|
|
29
29
|
import { acceptedSelection, fileHashMap, rawSnapshotHashIdentity, sameHashes } from "./sync-state.js";
|
|
30
30
|
import { checkLiveProtection } from "./transfer-freshness.js";
|
|
31
|
+
import { requireTransferSize, selectedPullImage, transferSizeLimitsEnabled } from "./transfer-size-limits.js";
|
|
31
32
|
export function canReviewAdoption(ctx, options) {
|
|
32
33
|
return (ctx.hasUI &&
|
|
33
34
|
(ctx.mode === "tui" || ctx.mode === "rpc") &&
|
|
@@ -163,6 +164,12 @@ export async function adoptRemoteRules(input) {
|
|
|
163
164
|
const caseCleanup = current ? [] : await inspectCaseCleanup(physical, projected);
|
|
164
165
|
requireStableMergeSessionRoot(before, physical, config.scope);
|
|
165
166
|
await validateSource();
|
|
167
|
+
const checkSize = () => {
|
|
168
|
+
if (transferSizeLimitsEnabled(config))
|
|
169
|
+
requireTransferSize(config, selectedPullImage(logical, before, protectedPaths, { filename, text }));
|
|
170
|
+
};
|
|
171
|
+
if (!resuming)
|
|
172
|
+
checkSize();
|
|
166
173
|
const approved = await confirmTransferReview(ctx, current ? "Resume reviewed ignore-rule Pull?" : "Overwrite local rules and pull?", formatTransferReview(`Local rule file: ${snapshotPathLabel(target)}. The remote will not change.`, `Sessions opt-in: ${sessions ? "on" : "off"} (unchanged).`, ...(current
|
|
167
174
|
? ["Resume from the recorded snapshot, not the current remote head. Local evidence must still match."]
|
|
168
175
|
: []), formatPullSummary(policyConfig, backend.destination, before, physical, protectedPaths, caseCleanup.map((item) => item.path)), ...(left.length ? [scopeChangeReview("Now excluded; leave local", left)] : []), ...(!current && newlyRemoved.length ? [scopeChangeReview("Newly selected; remove locally", newlyRemoved)] : []), formatRuleChanges(current?.beforeRules ?? source.text, text)), signal, validateMutation);
|
|
@@ -266,6 +273,8 @@ export async function adoptRemoteRules(input) {
|
|
|
266
273
|
...(config.localFields !== undefined ? { localFields: config.localFields } : {}),
|
|
267
274
|
});
|
|
268
275
|
const hashes = fileHashMap(await refresh());
|
|
276
|
+
if (resuming && source.identity !== journal.installedIdentity)
|
|
277
|
+
checkSize();
|
|
269
278
|
if (source.text !== text && journal.stateFingerprint !== stateFingerprint)
|
|
270
279
|
throw new Error("Baseline changed after the reviewed Pull. Preserve its journal.");
|
|
271
280
|
if (!sameHashes(hashes, journal.afterFiles)) {
|
|
@@ -4,7 +4,7 @@ import fs from "node:fs/promises";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { withEngineMutationQueue as withFileMutationQueue } from "../host.js";
|
|
6
6
|
import { agentDir } from "../snapshot/session-paths.js";
|
|
7
|
-
import { agentDirectoryConfiguredSessionDir, agentDirectoryInventory, createSnapshot, snapshotTarget, } from "../snapshot/snapshot.js";
|
|
7
|
+
import { agentDirectoryConfiguredSessionDir, agentDirectoryInventory, createSnapshot, observeSnapshot, snapshotTarget, } from "../snapshot/snapshot.js";
|
|
8
8
|
import { preflightSnapshotApply, preflightSnapshotMutations } from "../snapshot/snapshot-apply.js";
|
|
9
9
|
import { assertAgentDirectorySnapshotBound, MAX_AGENT_DIRECTORY_BYTES } from "../snapshot/snapshot-bounds.js";
|
|
10
10
|
import { assertProjectedAgentDirectoryBudget, recheckAgentDirectoryBudget, } from "../snapshot/snapshot-entry-projection.js";
|
|
@@ -16,6 +16,7 @@ import { recheckScopedImage, scopedTransactionImage } from "../snapshot/snapshot
|
|
|
16
16
|
import { ignorePolicyValidator } from "../snapshot/snapshot-transaction-policy.js";
|
|
17
17
|
import { syncDirectory } from "../state/json-file.js";
|
|
18
18
|
import { syncMutationParents } from "../state/mutation-directory-sync.js";
|
|
19
|
+
import { ContinuousError } from "./continuous-errors.js";
|
|
19
20
|
import { mergePathIdentity } from "./file-merge-planner.js";
|
|
20
21
|
import { configuredSnapshotPathMatcher } from "./sync-policy.js";
|
|
21
22
|
import { fileHashMap } from "./sync-state.js";
|
|
@@ -433,6 +434,18 @@ export async function applyMergedSnapshot(before, after, protectedPaths, options
|
|
|
433
434
|
requireReviewedHash(relative, hash);
|
|
434
435
|
return kind;
|
|
435
436
|
};
|
|
437
|
+
let checkApplyImage = options.requireReviewedApplyImage;
|
|
438
|
+
const requireReviewedApplyImage = async () => {
|
|
439
|
+
const latest = fileHashMap(await observeSnapshot(options));
|
|
440
|
+
await validate();
|
|
441
|
+
options.validateMutation?.();
|
|
442
|
+
if ([...new Set([...Object.keys(latest), ...paths])].some((relative) => {
|
|
443
|
+
const hash = Object.hasOwn(latest, relative) ? latest[relative] : undefined;
|
|
444
|
+
return hash !== beforeHashes[relative] && hash !== afterHashes[relative];
|
|
445
|
+
}))
|
|
446
|
+
throw new ContinuousError("unsafe", "Cannot verify the size-limited local apply image: local files changed. Keep the merge journal and backup for review.");
|
|
447
|
+
checkApplyImage = false;
|
|
448
|
+
};
|
|
436
449
|
if (options.scope === "agent-directory" && plan.deletes.length)
|
|
437
450
|
await recheckAgentDirectoryBudget(root, plan, options);
|
|
438
451
|
for (const target of plan.deletes) {
|
|
@@ -443,6 +456,8 @@ export async function applyMergedSnapshot(before, after, protectedPaths, options
|
|
|
443
456
|
await validate();
|
|
444
457
|
kind = stat.isDirectory() ? "directory" : "file";
|
|
445
458
|
}
|
|
459
|
+
if (kind !== "missing" && checkApplyImage)
|
|
460
|
+
await requireReviewedApplyImage();
|
|
446
461
|
if (kind === "directory")
|
|
447
462
|
await fs.rmdir(target); // Only an empty, reviewed directory may be replaced.
|
|
448
463
|
else if (kind === "file")
|
|
@@ -497,6 +512,8 @@ export async function applyMergedSnapshot(before, after, protectedPaths, options
|
|
|
497
512
|
if (validateIgnore)
|
|
498
513
|
await validateIgnore();
|
|
499
514
|
await assertFilesystemTarget(root, relative, options, new Set());
|
|
515
|
+
if (checkApplyImage)
|
|
516
|
+
await requireReviewedApplyImage();
|
|
500
517
|
await fs.mkdir(path.dirname(item.target), { recursive: true });
|
|
501
518
|
const temporary = path.join(path.dirname(item.target), `.pi-sync.json.${randomUUID()}.apply`);
|
|
502
519
|
let mode = 0o600;
|
|
@@ -16,7 +16,7 @@ import { conflictGroups, readConflictArtifact, saveConflictArtifact, } from "./c
|
|
|
16
16
|
import { resolveReviewedGroup } from "./conflict-resolution.js";
|
|
17
17
|
import { pruneCompletedConflicts } from "./conflict-retention.js";
|
|
18
18
|
import { resolveContentConflicts } from "./content-conflicts.js";
|
|
19
|
-
import { ContinuousError } from "./continuous-errors.js";
|
|
19
|
+
import { ContinuousError, TransferSizeError } from "./continuous-errors.js";
|
|
20
20
|
import { planFileMerge } from "./file-merge-planner.js";
|
|
21
21
|
import { ignorePublicationNotice, withPublishedIgnoreRules } from "./ignore-publication.js";
|
|
22
22
|
import { overlayLocalFields, portableSnapshot, sameLocalFields } from "./local-fields.js";
|
|
@@ -34,6 +34,7 @@ import { configuredSnapshotPathMatcher, inspectRemoteSelection, syncSessionsSele
|
|
|
34
34
|
import { fileHashMap, hasLocalChanges, hasRemoteChanges, sameHashes, syncPolicyChanged } from "./sync-state.js";
|
|
35
35
|
import { TEXT_MERGE_WORK_LIMIT } from "./text-merge.js";
|
|
36
36
|
import { checkLiveProtection, validateMergeApplyReview, validateMergedPublication } from "./transfer-freshness.js";
|
|
37
|
+
import { requireTransferSize, selectedPublicationImage, transferSizeDetails, transferSizeLimitsEnabled, } from "./transfer-size-limits.js";
|
|
37
38
|
const MAX_ATTEMPTS = 3;
|
|
38
39
|
/** Established-baseline sync only. First-source selection remains in the existing command flow. */
|
|
39
40
|
export async function mergeSync(ctx, options, factory = createSyncBackend, resolution) {
|
|
@@ -188,7 +189,23 @@ export async function mergeSync(ctx, options, factory = createSyncBackend, resol
|
|
|
188
189
|
const files = [...local.files, ...rawRemote.files];
|
|
189
190
|
if (files.length > 16_384 ||
|
|
190
191
|
files.reduce((bytes, file) => bytes + file.contentBase64.length * 0.75, 0) > 64 * 1024 * 1024) {
|
|
191
|
-
|
|
192
|
+
const message = "Merged transfer exceeds the 64 MiB / 16,384 input-file bound; review an explicit push or pull instead.";
|
|
193
|
+
if (!transferSizeLimitsEnabled(config))
|
|
194
|
+
throw new Error(message);
|
|
195
|
+
let details;
|
|
196
|
+
try {
|
|
197
|
+
const projected = portableSnapshot(filterSnapshotForConfigPolicy(rawRemote, config, { sessionDir: sessionRoot }), rawRemote.localFields);
|
|
198
|
+
details = transferSizeDetails(config, [
|
|
199
|
+
{ side: "Local input", files: local.files },
|
|
200
|
+
{ side: "Remote input", files: projected.files },
|
|
201
|
+
]);
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
throw new ContinuousError("unsafe", message);
|
|
205
|
+
}
|
|
206
|
+
if (details)
|
|
207
|
+
throw new TransferSizeError(`${message} ${details}`);
|
|
208
|
+
throw new ContinuousError("unsafe", message);
|
|
192
209
|
}
|
|
193
210
|
}
|
|
194
211
|
const remote = rawRemote
|
|
@@ -392,6 +409,8 @@ export async function mergeSync(ctx, options, factory = createSyncBackend, resol
|
|
|
392
409
|
: "Pi Sync is already up to date.", progress ? "warning" : "info");
|
|
393
410
|
return "applied";
|
|
394
411
|
}
|
|
412
|
+
if (transferSizeLimitsEnabled(config))
|
|
413
|
+
requireTransferSize(config, ...(apply ? [{ side: "Local", files: accepted.files }] : []), ...(publish ? [selectedPublicationImage(upload, config, sessionRoot)] : []));
|
|
395
414
|
await timings.measure("transfer preflight", () => preflightMergedTargets(localRaw, after, snapshotOptions, [
|
|
396
415
|
...(ctx.protectedSessionFiles ?? []),
|
|
397
416
|
...[ctx.sessionManager.getSessionFile?.()].filter((file) => Boolean(file)),
|
|
@@ -485,7 +504,7 @@ export async function mergeSync(ctx, options, factory = createSyncBackend, resol
|
|
|
485
504
|
? {
|
|
486
505
|
validateIgnorePolicy: () => validateMergedPublication(ctx, config, snapshotOptions, localRaw, after, journal.stateIdentity, validateFresh),
|
|
487
506
|
}
|
|
488
|
-
: {}),
|
|
507
|
+
: { validateIgnorePolicy: validateFresh }),
|
|
489
508
|
}));
|
|
490
509
|
journal.committedHead = result.head;
|
|
491
510
|
journal.warnings = result.warnings;
|
|
@@ -650,6 +669,19 @@ async function completeJournal(ctx, config, backend, journal, { validate, valida
|
|
|
650
669
|
}
|
|
651
670
|
if (inspectRemoteSelection(config.include, observed, config.exclude, config).kind !== "same")
|
|
652
671
|
throw new Error("Pending merge has unavailable remote selection metadata; preserve its journal and backup for review.");
|
|
672
|
+
const requireReviewedApplyImage = journal.applyOnly && transferSizeLimitsEnabled(config);
|
|
673
|
+
if (requireReviewedApplyImage) {
|
|
674
|
+
const selected = journal.accepted ?? portableSnapshot(journal.after, config.localFields);
|
|
675
|
+
const details = transferSizeDetails(config, [{ side: "Local", files: selected.files }]);
|
|
676
|
+
if (details) {
|
|
677
|
+
const { sameBaseline, sameLocal } = await readRetirementEvidence();
|
|
678
|
+
if (sameBaseline && sameLocal) {
|
|
679
|
+
await clearMergeJournal(config);
|
|
680
|
+
throw new TransferSizeError(`Transfer blocked by size limits. ${details}`);
|
|
681
|
+
}
|
|
682
|
+
throw new TransferSizeError(`Transfer blocked by size limits. The local apply is not verified. Keep the journal and backup. Review the limits before retrying /sync sync. ${details}`);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
653
685
|
if (sessionRoot !== undefined)
|
|
654
686
|
requireStableMergeSessionRoot(journal.before, journal.after, config.scope);
|
|
655
687
|
await validateFresh();
|
|
@@ -662,7 +694,7 @@ async function completeJournal(ctx, config, backend, journal, { validate, valida
|
|
|
662
694
|
const validateApplyReview = journal.localPolicyKey
|
|
663
695
|
? () => validateMergeApplyReview(backend, config, head, journal.stateIdentity, validateFresh, signal)
|
|
664
696
|
: undefined;
|
|
665
|
-
await timings.measure("transfer local apply", () => applyMergedSnapshot(journal.before, journal.after, protectedPaths, { ...snapshotOptions, validateMutation: validateApply, validateApplyReview }, validate, ctx.sessionManager.getSessionFile?.()));
|
|
697
|
+
await timings.measure("transfer local apply", () => applyMergedSnapshot(journal.before, journal.after, protectedPaths, { ...snapshotOptions, validateMutation: validateApply, validateApplyReview, requireReviewedApplyImage }, validate, ctx.sessionManager.getSessionFile?.()));
|
|
666
698
|
await validate();
|
|
667
699
|
const headAtAcceptance = await timings.measure("transfer remote head", () => backend.readHead(signal));
|
|
668
700
|
await validate();
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { snapshotIncludesSessions } from "../snapshot/snapshot.js";
|
|
2
|
+
import { formatRuleChanges } from "../ui/ignore-rule-preview.js";
|
|
3
|
+
import { countPreservedRemoteFiles, formatPushSummary, formatTransferReview } from "../ui/sync-format.js";
|
|
4
|
+
import { setSyncStatus } from "../ui/sync-status.js";
|
|
5
|
+
import { confirmTransferReview } from "../ui/transfer-review.js";
|
|
6
|
+
import { ignorePublicationNotice } from "./ignore-publication.js";
|
|
7
|
+
import { throwIfAborted } from "./signals.js";
|
|
8
|
+
import { formatIgnorePolicyComparison, inspectRemoteSelection } from "./sync-policy.js";
|
|
9
|
+
export async function confirmPush(ctx, options, config, backend, local, upload, head, remote, validateMutation, title = snapshotIncludesSessions(upload) ? "Push pi settings and sessions?" : "Push pi settings?") {
|
|
10
|
+
validateMutation();
|
|
11
|
+
if (options.yes)
|
|
12
|
+
return true;
|
|
13
|
+
const summary = formatPushSummary(config, backend.destination, upload, head, countPreservedRemoteFiles(local, upload), remote);
|
|
14
|
+
const comparison = config.ignorePolicy && remote
|
|
15
|
+
? inspectRemoteSelection(config.include, remote, config.exclude, config).ignorePolicyComparison
|
|
16
|
+
: undefined;
|
|
17
|
+
const notice = ignorePublicationNotice(upload);
|
|
18
|
+
const overwrite = comparison !== undefined && comparison !== "match";
|
|
19
|
+
const confirmed = await confirmTransferReview(ctx, overwrite ? "Overwrite remote policy and push?" : title, formatTransferReview(...(overwrite
|
|
20
|
+
? [
|
|
21
|
+
formatIgnorePolicyComparison(comparison),
|
|
22
|
+
"This replaces the remote policy with this device's rules. Remote rules are not adopted on this device.",
|
|
23
|
+
`Sessions opt-in: ${remote?.selection?.version === 4 ? (remote.selection.sessions ? "on" : "off") : "legacy"} → ${config.ignorePolicy?.sessions ? "on" : "off"}.`,
|
|
24
|
+
formatRuleChanges(remote?.ignoreRules?.text, upload.ignoreRules?.text),
|
|
25
|
+
]
|
|
26
|
+
: []), ...(notice ? [notice, ""] : []), summary), options.signal, validateMutation);
|
|
27
|
+
throwIfAborted(options.signal);
|
|
28
|
+
if (confirmed)
|
|
29
|
+
return true;
|
|
30
|
+
setSyncStatus(ctx, undefined);
|
|
31
|
+
ctx.ui.notify("Push cancelled.", "info");
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
@@ -9,8 +9,7 @@ import { pendingTransactionEntries } from "../snapshot/snapshot-transaction-dire
|
|
|
9
9
|
import { ignorePolicyValidator } from "../snapshot/snapshot-transaction-policy.js";
|
|
10
10
|
import { pruneMergeBaselines } from "../state/merge-baseline-store.js";
|
|
11
11
|
import { readStateForConfig, syncStateFingerprint, writeStateForConfig } from "../state/sync-state-store.js";
|
|
12
|
-
import {
|
|
13
|
-
import { countPreservedRemoteFiles, formatPullSummary, formatPushSummary, formatTransferReview, } from "../ui/sync-format.js";
|
|
12
|
+
import { formatPullSummary } from "../ui/sync-format.js";
|
|
14
13
|
import { setSyncStatus } from "../ui/sync-status.js";
|
|
15
14
|
import { confirmTransferReview } from "../ui/transfer-review.js";
|
|
16
15
|
import { startupTransferEnabled } from "./agent-policy.js";
|
|
@@ -18,18 +17,20 @@ import { inspectCaseCleanup, revalidateCaseCleanup } from "./apply-review.js";
|
|
|
18
17
|
import { checkpointDirectionalAction, foregroundDirectionalAction, keepProtectedRemoteSessions, localRestoreGuidance, notifyDirectionalSuccess, remoteRestoreGuidance, requireDirectionalPullBoundary, requireDirectionalSelection, validateDirectionalSettings, } from "./directional-action.js";
|
|
19
18
|
import { confirmFieldMigration } from "./field-migration.js";
|
|
20
19
|
import { adoptionSettingsFingerprint, adoptRemoteRules, canReviewAdoption } from "./ignore-adoption.js";
|
|
21
|
-
import {
|
|
20
|
+
import { withPublishedIgnoreRules } from "./ignore-publication.js";
|
|
22
21
|
import { overlayLocalFields, portableSnapshot, sameLocalFields, validatePortableSnapshot } from "./local-fields.js";
|
|
23
22
|
import { readMergeJournal, requireNoMergeJournal, retireMergeJournal } from "./merge-journal.js";
|
|
24
23
|
import { mergeSync } from "./merged-sync.js";
|
|
24
|
+
import { confirmPush } from "./push-review.js";
|
|
25
25
|
import { readRemoteSnapshot, readRemoteSnapshotForUpload, readSnapshotForHead, requireCompatibleRemoteSelection, sameRemoteHead, snapshotForUpload, } from "./remote-snapshot.js";
|
|
26
26
|
import { throwIfAborted } from "./signals.js";
|
|
27
27
|
import { createSyncDecision } from "./sync-decision.js";
|
|
28
28
|
import { errorMessage, PublicationStatePersistenceError } from "./sync-errors.js";
|
|
29
29
|
import { backupDirectionalSnapshot, backupLocal, captureMutationOwner, LocalBackupVerificationError, maybeReload, protectedSessionPaths, } from "./sync-local.js";
|
|
30
|
-
import {
|
|
30
|
+
import { inspectRemoteSelection, syncSelectionHasContent, syncSessionsSelected } from "./sync-policy.js";
|
|
31
31
|
import { acceptedSelection, canPullRemoteSessionsOnFirstSync, canPullRemoteSettingsOnFirstSync, fileHashMap, hasLocalChanges, hasRemoteChanges, remoteChangedSinceState, sameHashes, shouldRefreshSyncedState, snapshotHashesMatchState, snapshotsMatch, syncPolicyChanged, } from "./sync-state.js";
|
|
32
32
|
import { checkLiveProtection, directionalApplyGuards, requireIgnoreBaselineReview, requireResolvedDirectionalProgress, validateDirectionalPublication, } from "./transfer-freshness.js";
|
|
33
|
+
import { requireTransferSize, selectedPublicationImage, selectedPullImage, transferSizeLimitsEnabled, } from "./transfer-size-limits.js";
|
|
33
34
|
const VERSION = 1;
|
|
34
35
|
export { PublicationStatePersistenceError, RollbackPublicationError } from "./sync-errors.js";
|
|
35
36
|
export { rollback } from "./sync-rollback.js";
|
|
@@ -120,6 +121,17 @@ export async function push(ctx, options, input, factory = createSyncBackend) {
|
|
|
120
121
|
return "cancelled";
|
|
121
122
|
}
|
|
122
123
|
const configIdentity = syncCheckConfigFingerprint(config);
|
|
124
|
+
const validateSettings = async () => {
|
|
125
|
+
if (action)
|
|
126
|
+
await validateDirectionalSettings(options, config, validateMutation);
|
|
127
|
+
else if (configIdentity !== syncCheckConfigFingerprint(await loadConfig(options.setup, options.signal)))
|
|
128
|
+
throw new Error("Settings changed during push review.");
|
|
129
|
+
validateMutation();
|
|
130
|
+
};
|
|
131
|
+
const checkUpload = (upload) => {
|
|
132
|
+
if (transferSizeLimitsEnabled(config))
|
|
133
|
+
requireTransferSize(config, selectedPublicationImage(upload, config, snapshotOptions.sessionDir));
|
|
134
|
+
};
|
|
123
135
|
let upload = await snapshotForUpload(backend, config, local, head, remoteForUpload, snapshotOptions);
|
|
124
136
|
if (action) {
|
|
125
137
|
upload = keepProtectedRemoteSessions(config, upload, remoteForUpload, snapshotOptions.sessionDir, reviewedProtectedPaths);
|
|
@@ -127,6 +139,7 @@ export async function push(ctx, options, input, factory = createSyncBackend) {
|
|
|
127
139
|
}
|
|
128
140
|
upload = await withPublishedIgnoreRules(upload, config, options.signal);
|
|
129
141
|
validateMutation();
|
|
142
|
+
checkUpload(upload);
|
|
130
143
|
if (!config.skipSecretScan) {
|
|
131
144
|
const secrets = scanSnapshot({ ...local, ...(upload.ignoreRules ? { ignoreRules: upload.ignoreRules } : {}) });
|
|
132
145
|
if (secrets.length > 0) {
|
|
@@ -165,17 +178,15 @@ export async function push(ctx, options, input, factory = createSyncBackend) {
|
|
|
165
178
|
}
|
|
166
179
|
validateMutation();
|
|
167
180
|
upload = await snapshotForUpload(backend, config, local, head, remoteForUpload, snapshotOptions);
|
|
181
|
+
validateMutation();
|
|
182
|
+
checkUpload(upload);
|
|
168
183
|
if (!(await confirmPush(ctx, options, config, backend, local, upload, head, remoteForUpload, validateMutation, "Remote changed during review. Push the refreshed plan?"))) {
|
|
169
184
|
return "cancelled";
|
|
170
185
|
}
|
|
171
186
|
}
|
|
172
187
|
}
|
|
173
188
|
validateMutation();
|
|
174
|
-
|
|
175
|
-
await validateDirectionalSettings(options, config, validateMutation);
|
|
176
|
-
else if (configIdentity !== syncCheckConfigFingerprint(await loadConfig(options.setup)))
|
|
177
|
-
throw new Error("Settings changed during push review.");
|
|
178
|
-
validateMutation();
|
|
189
|
+
await validateSettings();
|
|
179
190
|
if (!action &&
|
|
180
191
|
(config.scope === "agent-directory" ||
|
|
181
192
|
validateIgnorePolicy ||
|
|
@@ -194,11 +205,7 @@ export async function push(ctx, options, input, factory = createSyncBackend) {
|
|
|
194
205
|
snapshotOptions.sessionDir !== (await effectiveSessionRoot(ctx, config, options.signal)))
|
|
195
206
|
throw new Error("Pi session storage changed during push review.");
|
|
196
207
|
validateMutation();
|
|
197
|
-
|
|
198
|
-
await validateDirectionalSettings(options, config, validateMutation);
|
|
199
|
-
else if (configIdentity !== syncCheckConfigFingerprint(await loadConfig(options.setup)))
|
|
200
|
-
throw new Error("Settings changed during push review.");
|
|
201
|
-
validateMutation();
|
|
208
|
+
await validateSettings();
|
|
202
209
|
const validatePublication = validateIgnorePolicy || options.background || action
|
|
203
210
|
? async () => {
|
|
204
211
|
if (action && !sameRemoteHead(backend, head, await backend.readHead(options.signal)))
|
|
@@ -210,14 +217,9 @@ export async function push(ctx, options, input, factory = createSyncBackend) {
|
|
|
210
217
|
await validateDirectionalSettings(options, config, validateMutation);
|
|
211
218
|
checkLiveProtection(ctx, snapshotOptions.sessionDir, reviewedProtectedPaths);
|
|
212
219
|
}
|
|
213
|
-
: (validateIgnorePolicy ??
|
|
214
|
-
(async () => {
|
|
215
|
-
if (configIdentity !== syncCheckConfigFingerprint(await loadConfig(options.setup, options.signal)))
|
|
216
|
-
throw new Error("Settings changed before push publication.");
|
|
217
|
-
validateMutation();
|
|
218
|
-
})), "push", Boolean(action));
|
|
220
|
+
: (validateIgnorePolicy ?? validateSettings), "push", Boolean(action));
|
|
219
221
|
}
|
|
220
|
-
:
|
|
222
|
+
: validateSettings;
|
|
221
223
|
if (validateIgnorePolicy) {
|
|
222
224
|
validatePortableSnapshot(upload);
|
|
223
225
|
await validateIgnorePolicy();
|
|
@@ -240,7 +242,7 @@ export async function push(ctx, options, input, factory = createSyncBackend) {
|
|
|
240
242
|
startedPublication = true;
|
|
241
243
|
}
|
|
242
244
|
: options.onCommit,
|
|
243
|
-
|
|
245
|
+
validateIgnorePolicy: validatePublication,
|
|
244
246
|
});
|
|
245
247
|
}
|
|
246
248
|
catch (error) {
|
|
@@ -421,6 +423,9 @@ export async function pull(ctx, options, factory = createSyncBackend, initial) {
|
|
|
421
423
|
if (action || config.scope === "agent-directory")
|
|
422
424
|
requireStableMergeSessionRoot(local, physical, config.scope);
|
|
423
425
|
const reviewedProtectedPaths = protectedSessionPaths(ctx, snapshotOptions.sessionDir);
|
|
426
|
+
const sizeLimited = transferSizeLimitsEnabled(config);
|
|
427
|
+
if (sizeLimited)
|
|
428
|
+
requireTransferSize(config, selectedPullImage(logical, local, reviewedProtectedPaths));
|
|
424
429
|
const remoteChanged = hasRemoteChanges(remote, state, config, reviewedProtectedPaths);
|
|
425
430
|
if (!action && localChanged && remoteChanged && state.lastAppliedSnapshot && !options.force) {
|
|
426
431
|
throw createSyncDecision({
|
|
@@ -516,6 +521,13 @@ export async function pull(ctx, options, factory = createSyncBackend, initial) {
|
|
|
516
521
|
await validateIgnorePolicy();
|
|
517
522
|
}
|
|
518
523
|
const protectedPaths = protectedSessionPaths(ctx, snapshotOptions.sessionDir);
|
|
524
|
+
const validateApplySettings = async () => {
|
|
525
|
+
if (configIdentity !== syncCheckConfigFingerprint(await loadConfig(options.setup, options.signal)))
|
|
526
|
+
throw new Error("Settings changed before pull apply.");
|
|
527
|
+
validateMutation();
|
|
528
|
+
if (sizeLimited)
|
|
529
|
+
checkLiveProtection(ctx, snapshotOptions.sessionDir, reviewedProtectedPaths);
|
|
530
|
+
};
|
|
519
531
|
const applyGuards = directionalApplyGuards({
|
|
520
532
|
ctx,
|
|
521
533
|
config,
|
|
@@ -539,6 +551,7 @@ export async function pull(ctx, options, factory = createSyncBackend, initial) {
|
|
|
539
551
|
await validateActionBoundary?.();
|
|
540
552
|
}
|
|
541
553
|
: validateIgnorePolicy,
|
|
554
|
+
validateSettings: action ? undefined : validateApplySettings,
|
|
542
555
|
effectiveRoot: Boolean(action),
|
|
543
556
|
});
|
|
544
557
|
applyGuards.validateMutation();
|
|
@@ -548,7 +561,9 @@ export async function pull(ctx, options, factory = createSyncBackend, initial) {
|
|
|
548
561
|
...snapshotOptions,
|
|
549
562
|
sessionDir: applySessionDir,
|
|
550
563
|
...applyGuards,
|
|
551
|
-
...(action || config.scope === "agent-directory" || validateIgnorePolicy
|
|
564
|
+
...(action || config.scope === "agent-directory" || validateIgnorePolicy || sizeLimited
|
|
565
|
+
? { reviewedLocal: local }
|
|
566
|
+
: {}),
|
|
552
567
|
expectedFileHashes: config.localFields?.length
|
|
553
568
|
? { "settings.json": fileHashMap(local)["settings.json"] ?? null }
|
|
554
569
|
: undefined,
|
|
@@ -758,31 +773,6 @@ export async function syncBoth(ctx, options, factory = createSyncBackend) {
|
|
|
758
773
|
if (!options.silent)
|
|
759
774
|
ctx.ui.notify("pi-sync is already up to date.", "info");
|
|
760
775
|
}
|
|
761
|
-
async function confirmPush(ctx, options, config, backend, local, upload, head, remote, validateMutation, title = snapshotIncludesSessions(upload) ? "Push pi settings and sessions?" : "Push pi settings?") {
|
|
762
|
-
validateMutation();
|
|
763
|
-
if (options.yes)
|
|
764
|
-
return true;
|
|
765
|
-
const summary = formatPushSummary(config, backend.destination, upload, head, countPreservedRemoteFiles(local, upload), remote);
|
|
766
|
-
const comparison = config.ignorePolicy && remote
|
|
767
|
-
? inspectRemoteSelection(config.include, remote, config.exclude, config).ignorePolicyComparison
|
|
768
|
-
: undefined;
|
|
769
|
-
const notice = ignorePublicationNotice(upload);
|
|
770
|
-
const overwrite = comparison !== undefined && comparison !== "match";
|
|
771
|
-
const confirmed = await confirmTransferReview(ctx, overwrite ? "Overwrite remote policy and push?" : title, formatTransferReview(...(overwrite
|
|
772
|
-
? [
|
|
773
|
-
formatIgnorePolicyComparison(comparison),
|
|
774
|
-
"This replaces the remote policy with this device's rules. Remote rules are not adopted on this device.",
|
|
775
|
-
`Sessions opt-in: ${remote?.selection?.version === 4 ? (remote.selection.sessions ? "on" : "off") : "legacy"} → ${config.ignorePolicy?.sessions ? "on" : "off"}.`,
|
|
776
|
-
formatRuleChanges(remote?.ignoreRules?.text, upload.ignoreRules?.text),
|
|
777
|
-
]
|
|
778
|
-
: []), ...(notice ? [notice, ""] : []), summary), options.signal, validateMutation);
|
|
779
|
-
throwIfAborted(options.signal);
|
|
780
|
-
if (confirmed)
|
|
781
|
-
return true;
|
|
782
|
-
setSyncStatus(ctx, undefined);
|
|
783
|
-
ctx.ui.notify("Push cancelled.", "info");
|
|
784
|
-
return false;
|
|
785
|
-
}
|
|
786
776
|
function matchesInitialHead(initial, backend, current) {
|
|
787
777
|
return sameRemoteHead(backend, initial.head, current);
|
|
788
778
|
}
|
|
@@ -21,7 +21,8 @@ import { PublicationStatePersistenceError, RollbackPublicationError } from "./sy
|
|
|
21
21
|
import { backupLocal, captureMutationOwner, maybeReload, protectedSessionPaths } from "./sync-local.js";
|
|
22
22
|
import { requireLegacyTransferPolicy, syncSessionsSelected } from "./sync-policy.js";
|
|
23
23
|
import { acceptedSelection, fileHashMap, sameHashes } from "./sync-state.js";
|
|
24
|
-
import { directionalApplyGuards, requireIgnoreBaselineReview, requireResolvedDirectionalProgress, validateDirectionalPublication, } from "./transfer-freshness.js";
|
|
24
|
+
import { checkLiveProtection, directionalApplyGuards, requireIgnoreBaselineReview, requireResolvedDirectionalProgress, validateDirectionalPublication, } from "./transfer-freshness.js";
|
|
25
|
+
import { requireTransferSize, selectedPublicationImage, selectedPullImage, transferSizeLimitsEnabled, } from "./transfer-size-limits.js";
|
|
25
26
|
const VERSION = 1;
|
|
26
27
|
const POST_LOCAL_COMMIT_TIMEOUT_MS = 30_000;
|
|
27
28
|
export async function rollback(ctx, options, factory = createSyncBackend, expectedSelection) {
|
|
@@ -86,6 +87,9 @@ export async function rollback(ctx, options, factory = createSyncBackend, expect
|
|
|
86
87
|
const caseCleanup = options.yes ? [] : await inspectCaseCleanup(physical, snapshotOptions);
|
|
87
88
|
validateMutation();
|
|
88
89
|
const reviewedProtectedPaths = protectedSessionPaths(ctx, snapshotOptions.sessionDir);
|
|
90
|
+
const sizeLimited = transferSizeLimitsEnabled(config);
|
|
91
|
+
if (sizeLimited)
|
|
92
|
+
requireTransferSize(config, selectedPullImage(remote, local, reviewedProtectedPaths), selectedPublicationImage(upload, config, snapshotOptions.sessionDir));
|
|
89
93
|
if (!options.yes) {
|
|
90
94
|
const title = snapshotIncludesSessions(remote) ? "Rollback pi settings and sessions?" : "Rollback pi settings?";
|
|
91
95
|
const summary = formatRollbackSummary(config, backend.destination, local, physical, target, reviewedProtectedPaths, caseCleanup.map((item) => item.path));
|
|
@@ -128,6 +132,8 @@ export async function rollback(ctx, options, factory = createSyncBackend, expect
|
|
|
128
132
|
await validateIgnorePolicy();
|
|
129
133
|
}
|
|
130
134
|
const protectedPaths = protectedSessionPaths(ctx, snapshotOptions.sessionDir);
|
|
135
|
+
if (sizeLimited)
|
|
136
|
+
checkLiveProtection(ctx, snapshotOptions.sessionDir, reviewedProtectedPaths);
|
|
131
137
|
const applyGuards = directionalApplyGuards({
|
|
132
138
|
ctx,
|
|
133
139
|
config,
|
|
@@ -140,6 +146,14 @@ export async function rollback(ctx, options, factory = createSyncBackend, expect
|
|
|
140
146
|
onCommit: options.onCommit,
|
|
141
147
|
validateMutation,
|
|
142
148
|
validateIgnorePolicy,
|
|
149
|
+
validateSettings: async () => {
|
|
150
|
+
if (syncCheckConfigFingerprint(config) !==
|
|
151
|
+
syncCheckConfigFingerprint(await loadConfig(options.setup, options.signal)))
|
|
152
|
+
throw new Error("Settings changed before rollback apply.");
|
|
153
|
+
validateMutation();
|
|
154
|
+
if (sizeLimited)
|
|
155
|
+
checkLiveProtection(ctx, snapshotOptions.sessionDir, reviewedProtectedPaths);
|
|
156
|
+
},
|
|
143
157
|
});
|
|
144
158
|
applyGuards.validateMutation();
|
|
145
159
|
if (!validateIgnorePolicy)
|
|
@@ -148,7 +162,7 @@ export async function rollback(ctx, options, factory = createSyncBackend, expect
|
|
|
148
162
|
...snapshotOptions,
|
|
149
163
|
sessionDir: applySessionDir,
|
|
150
164
|
...applyGuards,
|
|
151
|
-
...(config.scope === "agent-directory" || validateIgnorePolicy ? { reviewedLocal: local } : {}),
|
|
165
|
+
...(config.scope === "agent-directory" || validateIgnorePolicy || sizeLimited ? { reviewedLocal: local } : {}),
|
|
152
166
|
expectedFileHashes: config.localFields?.length
|
|
153
167
|
? { "settings.json": fileHashMap(local)["settings.json"] ?? null }
|
|
154
168
|
: undefined,
|
|
@@ -38,9 +38,9 @@ export function checkLiveProtection(ctx, sessionDir, reviewed) {
|
|
|
38
38
|
if (current.size !== reviewed.size || [...current].some((item) => !reviewed.has(item)))
|
|
39
39
|
throw new StaleIgnorePolicyError("Live session protection changed during review; reopen the review.");
|
|
40
40
|
}
|
|
41
|
-
export function directionalApplyGuards({ ctx, config, backend, state, sessionDir, head, protectedPaths, signal, validateMutation, validateIgnorePolicy, onCommit, effectiveRoot = false, }) {
|
|
41
|
+
export function directionalApplyGuards({ ctx, config, backend, state, sessionDir, head, protectedPaths, signal, validateMutation, validateIgnorePolicy, validateSettings, onCommit, effectiveRoot = false, }) {
|
|
42
42
|
if (!validateIgnorePolicy)
|
|
43
|
-
return { validateMutation };
|
|
43
|
+
return { validateMutation, validateApplyReview: validateSettings };
|
|
44
44
|
const validateOwner = () => {
|
|
45
45
|
validateMutation();
|
|
46
46
|
checkLiveProtection(ctx, sessionDir, protectedPaths);
|
|
@@ -58,6 +58,7 @@ export function directionalApplyGuards({ ctx, config, backend, state, sessionDir
|
|
|
58
58
|
? await effectiveSessionRoot(ctx, config, signal)
|
|
59
59
|
: (await resolvedSnapshotOptionsForContext(ctx, config, signal)).sessionDir))
|
|
60
60
|
throw new StaleIgnorePolicyError("Pi session storage changed before local apply; reopen the review.");
|
|
61
|
+
await validateSettings?.();
|
|
61
62
|
await validateIgnorePolicy();
|
|
62
63
|
validateOwner();
|
|
63
64
|
if (!committed) {
|