@narumitw/pi-sync 0.66.0 → 0.67.1
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 +12 -0
- package/README.md +11 -2
- package/dist/chunks/{chunk-BYVHABNR.ts → chunk-2MUAR5GH.ts} +2 -2
- package/dist/chunks/{chunk-5YOLQKNZ.ts → chunk-3CO7QIYB.ts} +14 -14
- package/dist/chunks/{chunk-DAZZ5BEJ.ts → chunk-3NS4PMCI.ts} +6 -2
- package/dist/chunks/{chunk-FI2F5JBS.ts → chunk-3Q3DMMID.ts} +8 -8
- package/dist/chunks/{chunk-BESRBKVO.ts → chunk-CQXGMESM.ts} +7 -7
- package/dist/chunks/{chunk-SZJOUVCL.ts → chunk-DGVZYS7T.ts} +5 -5
- package/dist/chunks/{chunk-WJQ4TGN5.ts → chunk-ECUCXF5Y.ts} +2 -2
- package/dist/chunks/{chunk-Z5JMOXJM.ts → chunk-JNTDIVP6.ts} +5 -5
- package/dist/chunks/{chunk-AYGMIMCV.ts → chunk-PUSMSKIM.ts} +11 -2
- package/dist/chunks/chunk-PUSMSKIM.ts.map +7 -0
- package/dist/chunks/{chunk-ASU3GZPW.ts → chunk-W7DSN33J.ts} +6 -6
- package/dist/chunks/{chunk-JQ5BAWW2.ts → chunk-XPKHWTGT.ts} +77 -16
- package/dist/chunks/chunk-XPKHWTGT.ts.map +7 -0
- package/dist/chunks/{command-handler-44EFGPWH.ts → command-handler-H5X3BX5D.ts} +40 -32
- package/dist/chunks/command-handler-H5X3BX5D.ts.map +7 -0
- package/dist/chunks/config-P54GGMXY.ts +39 -0
- package/dist/chunks/{conflict-review-J7L7S4AR.ts → conflict-review-SSY37F4P.ts} +2 -2
- package/dist/chunks/{file-selection-XWACUTAH.ts → file-selection-GASCVN45.ts} +6 -6
- package/dist/chunks/{ignore-file-ui-OHFISFVC.ts → ignore-file-ui-UY2TEK4C.ts} +5 -5
- package/dist/chunks/{manager-result-dispatcher-WXE2BAQO.ts → manager-result-dispatcher-PEVIGLOS.ts} +7 -7
- package/dist/chunks/{manager-ui-CVZLMXJ5.ts → manager-ui-R5XHYRXK.ts} +165 -34
- package/dist/chunks/manager-ui-R5XHYRXK.ts.map +7 -0
- package/dist/chunks/{merge-review-AAC674C6.ts → merge-review-C2KETZKY.ts} +3 -3
- package/dist/chunks/{remote-selection-ui-E4XZCQ7A.ts → remote-selection-ui-WFLX6MAJ.ts} +6 -6
- package/dist/chunks/{setup-switch-644T6KHG.ts → setup-switch-JZDFQPVW.ts} +4 -4
- package/dist/chunks/setup-switch-JZDFQPVW.ts.map +7 -0
- package/dist/chunks/{setup-wizard-IEW56AZE.ts → setup-wizard-5OMFSFPJ.ts} +9 -9
- package/dist/chunks/{sync-inspection-NBBTSMKR.ts → sync-inspection-S2GHDBAD.ts} +5 -5
- package/dist/chunks/{sync-operations-AIEM2KL2.ts → sync-operations-LQ63CU2T.ts} +2 -2
- package/dist/daemon/dist/client.js +32 -18
- package/dist/daemon/dist/daemon-recovery.js +5 -3
- package/dist/daemon/dist/engine/ignore/adoption-journal.js +6 -3
- 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 +17 -2
- 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 +42 -49
- 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/dist/engine-service.js +22 -6
- package/dist/daemon/dist/foreground-queue-outcome.js +4 -0
- package/dist/daemon/dist/server.js +2 -1
- package/dist/daemon/dist/service-host.js +7 -2
- package/dist/daemon/package.json +1 -1
- package/dist/index.ts +41 -32
- package/dist/index.ts.map +2 -2
- package/docs/daemon-migration.md +8 -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/commands/command-execution.ts +10 -1
- package/src/commands/command-handler.ts +4 -0
- package/src/daemon/directional-recovery.ts +35 -5
- package/src/daemon/pi-client.ts +82 -12
- package/src/sync-extension.ts +17 -9
- package/src/ui/cancellable-operation.ts +13 -2
- package/src/ui/manager-state.ts +1 -0
- package/src/ui/manager-ui.ts +25 -4
- package/src/ui/settings-ui.ts +128 -4
- package/dist/chunks/chunk-AYGMIMCV.ts.map +0 -7
- package/dist/chunks/chunk-JQ5BAWW2.ts.map +0 -7
- package/dist/chunks/command-handler-44EFGPWH.ts.map +0 -7
- package/dist/chunks/manager-ui-CVZLMXJ5.ts.map +0 -7
- /package/dist/chunks/{chunk-BYVHABNR.ts.map → chunk-2MUAR5GH.ts.map} +0 -0
- /package/dist/chunks/{chunk-5YOLQKNZ.ts.map → chunk-3CO7QIYB.ts.map} +0 -0
- /package/dist/chunks/{chunk-DAZZ5BEJ.ts.map → chunk-3NS4PMCI.ts.map} +0 -0
- /package/dist/chunks/{chunk-FI2F5JBS.ts.map → chunk-3Q3DMMID.ts.map} +0 -0
- /package/dist/chunks/{chunk-BESRBKVO.ts.map → chunk-CQXGMESM.ts.map} +0 -0
- /package/dist/chunks/{chunk-SZJOUVCL.ts.map → chunk-DGVZYS7T.ts.map} +0 -0
- /package/dist/chunks/{chunk-WJQ4TGN5.ts.map → chunk-ECUCXF5Y.ts.map} +0 -0
- /package/dist/chunks/{chunk-Z5JMOXJM.ts.map → chunk-JNTDIVP6.ts.map} +0 -0
- /package/dist/chunks/{chunk-ASU3GZPW.ts.map → chunk-W7DSN33J.ts.map} +0 -0
- /package/dist/chunks/{ignore-file-ui-OHFISFVC.ts.map → config-P54GGMXY.ts.map} +0 -0
- /package/dist/chunks/{conflict-review-J7L7S4AR.ts.map → conflict-review-SSY37F4P.ts.map} +0 -0
- /package/dist/chunks/{file-selection-XWACUTAH.ts.map → file-selection-GASCVN45.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-WXE2BAQO.ts.map → ignore-file-ui-UY2TEK4C.ts.map} +0 -0
- /package/dist/chunks/{merge-review-AAC674C6.ts.map → manager-result-dispatcher-PEVIGLOS.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-E4XZCQ7A.ts.map → merge-review-C2KETZKY.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-644T6KHG.ts.map → remote-selection-ui-WFLX6MAJ.ts.map} +0 -0
- /package/dist/chunks/{setup-wizard-IEW56AZE.ts.map → setup-wizard-5OMFSFPJ.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-NBBTSMKR.ts.map → sync-inspection-S2GHDBAD.ts.map} +0 -0
- /package/dist/chunks/{sync-operations-AIEM2KL2.ts.map → sync-operations-LQ63CU2T.ts.map} +0 -0
|
@@ -5,30 +5,30 @@ import {
|
|
|
5
5
|
showGitSetup,
|
|
6
6
|
showS3Setup,
|
|
7
7
|
showWebDavSetup
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-W7DSN33J.ts";
|
|
9
9
|
import "./chunk-ECYCNZOE.ts";
|
|
10
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-JNTDIVP6.ts";
|
|
11
11
|
import "./chunk-KNEUL4XN.ts";
|
|
12
12
|
import {
|
|
13
13
|
validateConfigName
|
|
14
14
|
} from "./chunk-APZVJAEW.ts";
|
|
15
15
|
import "./chunk-WBIOSK76.ts";
|
|
16
|
+
import "./chunk-XPKHWTGT.ts";
|
|
16
17
|
import {
|
|
17
18
|
throwIfAborted
|
|
18
19
|
} from "./chunk-UMPA5S7X.ts";
|
|
20
|
+
import "./chunk-H7VOTY5N.ts";
|
|
19
21
|
import "./chunk-XUZV4OGI.ts";
|
|
20
|
-
import "./chunk-
|
|
22
|
+
import "./chunk-PUSMSKIM.ts";
|
|
23
|
+
import {
|
|
24
|
+
errorMessage
|
|
25
|
+
} from "./chunk-6YKOHBSC.ts";
|
|
21
26
|
import "./chunk-JREGWM2B.ts";
|
|
22
27
|
import {
|
|
23
28
|
localConfigPath
|
|
24
29
|
} from "./chunk-IBXEM35O.ts";
|
|
25
30
|
import "./chunk-NXWHPVXR.ts";
|
|
26
31
|
import "./chunk-GELYN4UC.ts";
|
|
27
|
-
import "./chunk-JQ5BAWW2.ts";
|
|
28
|
-
import "./chunk-H7VOTY5N.ts";
|
|
29
|
-
import {
|
|
30
|
-
errorMessage
|
|
31
|
-
} from "./chunk-6YKOHBSC.ts";
|
|
32
32
|
import "./chunk-R3SAMXB6.ts";
|
|
33
33
|
import {
|
|
34
34
|
safeTerminalText
|
|
@@ -95,4 +95,4 @@ async function showSetupWizard(ctx, signal) {
|
|
|
95
95
|
export {
|
|
96
96
|
showSetupWizard
|
|
97
97
|
};
|
|
98
|
-
//# sourceMappingURL=setup-wizard-
|
|
98
|
+
//# sourceMappingURL=setup-wizard-5OMFSFPJ.ts.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
2
|
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
|
-
import {
|
|
4
|
-
syncCheckConfigFingerprint
|
|
5
|
-
} from "./chunk-DAZZ5BEJ.ts";
|
|
6
3
|
import {
|
|
7
4
|
currentPiDaemonClient
|
|
8
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-XPKHWTGT.ts";
|
|
9
6
|
import "./chunk-H7VOTY5N.ts";
|
|
10
7
|
import "./chunk-6YKOHBSC.ts";
|
|
11
8
|
import "./chunk-R3SAMXB6.ts";
|
|
9
|
+
import {
|
|
10
|
+
syncCheckConfigFingerprint
|
|
11
|
+
} from "./chunk-3NS4PMCI.ts";
|
|
12
12
|
import "./chunk-2JNFEZ3V.ts";
|
|
13
13
|
|
|
14
14
|
// src/sync/sync-inspection.ts
|
|
@@ -20,4 +20,4 @@ var inspectSync = async (config, _options, signal) => await currentPiDaemonClien
|
|
|
20
20
|
export {
|
|
21
21
|
inspectSync
|
|
22
22
|
};
|
|
23
|
-
//# sourceMappingURL=sync-inspection-
|
|
23
|
+
//# sourceMappingURL=sync-inspection-S2GHDBAD.ts.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
3
|
import {
|
|
4
4
|
remoteOperation
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-XPKHWTGT.ts";
|
|
6
6
|
import "./chunk-H7VOTY5N.ts";
|
|
7
7
|
import "./chunk-6YKOHBSC.ts";
|
|
8
8
|
import "./chunk-R3SAMXB6.ts";
|
|
@@ -46,4 +46,4 @@ export {
|
|
|
46
46
|
status,
|
|
47
47
|
syncBoth
|
|
48
48
|
};
|
|
49
|
-
//# sourceMappingURL=sync-operations-
|
|
49
|
+
//# sourceMappingURL=sync-operations-LQ63CU2T.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { setTimeout as delay } from "node:timers/promises";
|
|
3
3
|
import { DaemonError, requestDaemon } from "./client-transport.js";
|
|
4
|
-
import { stopDaemonAfterForegroundQueueFailure } from "./daemon-recovery.js";
|
|
4
|
+
import { ForegroundStopRefusedError, stopDaemonAfterForegroundQueueFailure } from "./daemon-recovery.js";
|
|
5
5
|
import { isForegroundDirection, isForegroundQueueOutcome } from "./foreground-queue-outcome.js";
|
|
6
6
|
import { canonicalRootGuard, readProcessBirth } from "./identity.js";
|
|
7
7
|
import { withCleanup } from "./lifecycle.js";
|
|
@@ -270,7 +270,13 @@ export class DaemonConnection {
|
|
|
270
270
|
if (!foreground)
|
|
271
271
|
signal?.throwIfAborted();
|
|
272
272
|
if (assertRoot && isForegroundQueueOutcome(job.result))
|
|
273
|
-
this.foregroundRecovery = {
|
|
273
|
+
this.foregroundRecovery = {
|
|
274
|
+
job: id,
|
|
275
|
+
generation,
|
|
276
|
+
birth,
|
|
277
|
+
assertRoot,
|
|
278
|
+
retryOnRefusal: job.result.foregroundQueueCleanup === "resume-adoption",
|
|
279
|
+
};
|
|
274
280
|
return job.result;
|
|
275
281
|
};
|
|
276
282
|
if (onCommit)
|
|
@@ -367,29 +373,37 @@ export class DaemonConnection {
|
|
|
367
373
|
this.pendingJobs.delete(id);
|
|
368
374
|
});
|
|
369
375
|
}
|
|
376
|
+
canRecoverForeground(job) {
|
|
377
|
+
const target = this.foregroundRecovery;
|
|
378
|
+
return (!!target &&
|
|
379
|
+
target.job === job &&
|
|
380
|
+
target.generation === this.facts.generation &&
|
|
381
|
+
!target.attempted &&
|
|
382
|
+
this.attached &&
|
|
383
|
+
!this.closed &&
|
|
384
|
+
!this.admitting &&
|
|
385
|
+
!this.disposing &&
|
|
386
|
+
!this.pausing &&
|
|
387
|
+
this.pendingJobs.size === 0 &&
|
|
388
|
+
!this.uncertain &&
|
|
389
|
+
this.contactResumeState === "idle");
|
|
390
|
+
}
|
|
370
391
|
async recoverForeground(job, signal) {
|
|
371
392
|
signal.throwIfAborted();
|
|
372
393
|
const target = this.foregroundRecovery;
|
|
373
|
-
if (!target ||
|
|
374
|
-
target.job !== job ||
|
|
375
|
-
target.generation !== this.facts.generation ||
|
|
376
|
-
target.attempted ||
|
|
377
|
-
!this.attached ||
|
|
378
|
-
this.closed ||
|
|
379
|
-
this.admitting ||
|
|
380
|
-
this.disposing ||
|
|
381
|
-
this.pausing ||
|
|
382
|
-
this.pendingJobs.size ||
|
|
383
|
-
this.uncertain ||
|
|
384
|
-
this.contactResumeState !== "idle")
|
|
394
|
+
if (!target || !this.canRecoverForeground(job))
|
|
385
395
|
throw new Error("The current Pi session could not verify a completed transfer for daemon recovery.");
|
|
386
396
|
target.assertRoot();
|
|
387
397
|
target.attempted = true;
|
|
388
398
|
const owned = AbortSignal.any([signal, this.controller.signal, AbortSignal.timeout(FOREGROUND_RECOVERY_MS)]);
|
|
389
|
-
|
|
390
|
-
...target,
|
|
391
|
-
|
|
392
|
-
|
|
399
|
+
try {
|
|
400
|
+
await stopDaemonAfterForegroundQueueFailure(this.paths, this.identity, { ...target, client: this.facts.id }, owned);
|
|
401
|
+
}
|
|
402
|
+
catch (error) {
|
|
403
|
+
if (target.retryOnRefusal && error instanceof ForegroundStopRefusedError)
|
|
404
|
+
delete target.attempted;
|
|
405
|
+
throw error;
|
|
406
|
+
}
|
|
393
407
|
await this.closeLocal();
|
|
394
408
|
target.assertRoot();
|
|
395
409
|
}
|
|
@@ -3,6 +3,8 @@ import { acquireStartupLock, checkUpgradeConsent, finishUpgrade } from "./daemon
|
|
|
3
3
|
import { canonicalRootGuard, clearUpgradeOwner, processExists, processExited, readIdentity, readProcessBirth, readUpgradeOwner, recordUpgradeOwner, runtimePaths, upgradeRepairStarted, } from "./identity.js";
|
|
4
4
|
import { withCleanup } from "./lifecycle.js";
|
|
5
5
|
import { record } from "./protocol.js";
|
|
6
|
+
export class ForegroundStopRefusedError extends Error {
|
|
7
|
+
}
|
|
6
8
|
export async function stopDaemonAfterForegroundQueueFailure(paths, identity, { job, client, generation, birth }, signal) {
|
|
7
9
|
const assertRoot = canonicalRootGuard(paths.root);
|
|
8
10
|
if (process.platform === "linux" && birth === undefined)
|
|
@@ -44,10 +46,10 @@ export async function stopDaemonAfterForegroundQueueFailure(paths, identity, { j
|
|
|
44
46
|
return;
|
|
45
47
|
throw error;
|
|
46
48
|
}
|
|
49
|
+
if (record(checked) && typeof checked.blocked === "string" && checked.eligible !== true)
|
|
50
|
+
throw new ForegroundStopRefusedError(checked.blocked);
|
|
47
51
|
if (!record(checked) || checked.eligible !== true)
|
|
48
|
-
throw new Error(
|
|
49
|
-
? checked.blocked
|
|
50
|
-
: "Daemon queue cleanup could not be verified.");
|
|
52
|
+
throw new Error("Daemon queue cleanup could not be verified.");
|
|
51
53
|
if (!(await requireCurrent()))
|
|
52
54
|
return;
|
|
53
55
|
signal.throwIfAborted();
|
|
@@ -113,24 +113,27 @@ export async function verifyAdoptionBackup(journal, signal) {
|
|
|
113
113
|
await handle.close();
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
+
export function adoptionJournalFingerprint(journal) {
|
|
117
|
+
return createHash("sha256").update(JSON.stringify(journal)).digest("hex");
|
|
118
|
+
}
|
|
116
119
|
export async function createAdoptionJournal(journal) {
|
|
117
120
|
requireNoPendingAdoption();
|
|
118
121
|
const target = journalPath();
|
|
119
122
|
await writeJson(target, journal, { maxBytes: MAX_BYTES });
|
|
120
123
|
await syncDirectory(path.dirname(path.dirname(target)));
|
|
121
124
|
}
|
|
122
|
-
async function
|
|
125
|
+
export async function assertCurrentAdoptionJournal(journal) {
|
|
123
126
|
if (JSON.stringify(await loadAdoptionJournal()) !== JSON.stringify(journal))
|
|
124
127
|
throw new Error(recoveryMessage);
|
|
125
128
|
}
|
|
126
129
|
export async function recordInstalledIdentity(journal, identity) {
|
|
127
|
-
await
|
|
130
|
+
await assertCurrentAdoptionJournal(journal);
|
|
128
131
|
const next = { ...journal, installedIdentity: identity };
|
|
129
132
|
await writeJson(journalPath(), next, { maxBytes: MAX_BYTES });
|
|
130
133
|
return next;
|
|
131
134
|
}
|
|
132
135
|
export async function completeAdoptionJournal(journal) {
|
|
133
|
-
await
|
|
136
|
+
await assertCurrentAdoptionJournal(journal);
|
|
134
137
|
const target = journalPath();
|
|
135
138
|
const backups = path.join(path.dirname(target), "backups");
|
|
136
139
|
if (!(await fs.lstat(backups)).isDirectory())
|
|
@@ -9,9 +9,9 @@ import { compileIgnoreRules, DEFAULT_IGNORE_CREATION_RECORD, DEFAULT_IGNORE_FILE
|
|
|
9
9
|
function locateIgnoreFile(document, root, setup) {
|
|
10
10
|
const settings = document && validateSettingsDocument(document.parsed);
|
|
11
11
|
const current = settings && Object.hasOwn(settings.syncSetups, setup) ? settings.syncSetups[setup] : undefined;
|
|
12
|
-
if (!current)
|
|
12
|
+
if (!settings || !current)
|
|
13
13
|
throw new Error("Sync setup no longer exists; reopen ignore-file settings.");
|
|
14
|
-
if (
|
|
14
|
+
if (current.sync.pathPolicy !== "ignore-file")
|
|
15
15
|
throw new Error("This sync setup does not use an ignore file.");
|
|
16
16
|
const filename = current.sync.ignoreFile ?? DEFAULT_IGNORE_FILENAME;
|
|
17
17
|
return {
|
|
@@ -253,7 +253,8 @@ export async function migrateIgnoreSetup(execution, setupName, offerToken) {
|
|
|
253
253
|
const { include: _include, exclude: _exclude, reinclude: _reinclude, ...common } = policy;
|
|
254
254
|
const sessions = policy.scope === "agent-directory" ? policy.sessions === true : previous.include.includes("sessions");
|
|
255
255
|
next.syncSetups[setupName].sync = { ...common, scope: "agent-directory", sessions, pathPolicy: "ignore-file" };
|
|
256
|
-
next.version
|
|
256
|
+
if (next.version < 8)
|
|
257
|
+
next.version = 8;
|
|
257
258
|
validateSettingsDocument(next);
|
|
258
259
|
const source = await readPolicyReviewSource(execution.root, DEFAULT_IGNORE_FILENAME, execution, true);
|
|
259
260
|
execution.validate();
|
|
@@ -283,6 +283,9 @@ export function replaceLocalConfigDocument(document, value) {
|
|
|
283
283
|
return queueConfigOperation(() => withLocalConfigFileLock(() => replaceLocalConfigDocumentUnlocked(document, value)), true);
|
|
284
284
|
}
|
|
285
285
|
async function replaceLocalConfigDocumentUnlocked(document, value, signal, review) {
|
|
286
|
+
if (document.parsed.version === 9 && (typeof value.version !== "number" || value.version < 9)) {
|
|
287
|
+
throw new Error("Pi Sync settings version 9 cannot be downgraded; keep version 9 even when transfer limits are Off.");
|
|
288
|
+
}
|
|
286
289
|
const nextBytes = serializedConfig(value);
|
|
287
290
|
const canonicalPath = localConfigPath();
|
|
288
291
|
if (document.path !== canonicalPath) {
|
|
@@ -36,10 +36,8 @@ async function operationalConfig(document, setupName, signal) {
|
|
|
36
36
|
return resolveOperationPolicy(config, setupName, signal, document && { kind: "checked", document });
|
|
37
37
|
}
|
|
38
38
|
export async function loadSettingsConfig(setupName) {
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
async function readSettingsForCheck() {
|
|
42
|
-
return settingsFromCheckDocument(await readActiveLocalConfigDocumentForRepair());
|
|
39
|
+
const settings = settingsFromCheckDocument(await readActiveLocalConfigDocumentForRepair());
|
|
40
|
+
return { ...configFromSettings(settings, setupName), settingsVersion: settings.version };
|
|
43
41
|
}
|
|
44
42
|
function settingsFromCheckDocument(document) {
|
|
45
43
|
if (!document)
|
|
@@ -240,7 +238,7 @@ export function syncConfigReviewFingerprint(config) {
|
|
|
240
238
|
/** Internal freshness token, including credentials; never display or persist it. */
|
|
241
239
|
export function syncCheckConfigFingerprint(config) {
|
|
242
240
|
return createHash("sha256")
|
|
243
|
-
.update(JSON.stringify({ ...config, showStatus: undefined, debug: undefined }))
|
|
241
|
+
.update(JSON.stringify({ ...config, showStatus: undefined, debug: undefined, settingsVersion: undefined }))
|
|
244
242
|
.digest("hex");
|
|
245
243
|
}
|
|
246
244
|
export function syncSettingsConfigFingerprint(config) {
|
|
@@ -298,6 +296,8 @@ function resolveSyncConfig(setupName, setup, connectionName, connection, onSwitc
|
|
|
298
296
|
mergeSettings: setup.sync.mergeSettings ?? false,
|
|
299
297
|
mergeContent: setup.sync.mergeContent ?? false,
|
|
300
298
|
partialSync: setup.sync.partialSync ?? false,
|
|
299
|
+
...(policy.maxFileSizeMiB === undefined ? {} : { maxFileSizeMiB: policy.maxFileSizeMiB }),
|
|
300
|
+
...(policy.maxDirectorySizeMiB === undefined ? {} : { maxDirectorySizeMiB: policy.maxDirectorySizeMiB }),
|
|
301
301
|
onSwitch,
|
|
302
302
|
skipSecretScan,
|
|
303
303
|
showStatus,
|
|
@@ -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();
|
|
@@ -3,7 +3,7 @@ import { lstatSync, renameSync, statSync } from "node:fs";
|
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { getEngineRoot, withEngineMutationQueue } from "../host.js";
|
|
6
|
-
import { completeAdoptionJournal, createAdoptionJournal, recordInstalledIdentity, verifyAdoptionBackup, } from "../ignore/adoption-journal.js";
|
|
6
|
+
import { adoptionJournalFingerprint, assertCurrentAdoptionJournal, completeAdoptionJournal, createAdoptionJournal, recordInstalledIdentity, verifyAdoptionBackup, } from "../ignore/adoption-journal.js";
|
|
7
7
|
import { DEFAULT_IGNORE_FILENAME, ignoreFileIdentity, ignorePolicyFingerprint, ignoreSourceDigest, readIgnoreSource, sameFile, } from "../ignore/ignore-source.js";
|
|
8
8
|
import { validateSnapshotIgnoreRules } from "../ignore/snapshot-ignore-rules.js";
|
|
9
9
|
import { loadConfigForCheck, syncConfigReviewFingerprint, syncSettingsConfigFingerprint } from "../settings/config.js";
|
|
@@ -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);
|
|
@@ -200,8 +207,10 @@ export async function adoptRemoteRules(input) {
|
|
|
200
207
|
!sameLocalFields(latest.localFields, remote.localFields) ||
|
|
201
208
|
rawSnapshotHashIdentity(latest) !== remoteFilesIdentity)
|
|
202
209
|
throw new Error("The reviewed remote snapshot changed; reopen Pull.");
|
|
203
|
-
if (current)
|
|
210
|
+
if (current) {
|
|
204
211
|
await verifyAdoptionBackup(current, signal);
|
|
212
|
+
await assertCurrentAdoptionJournal(current);
|
|
213
|
+
}
|
|
205
214
|
await validateContext();
|
|
206
215
|
const refresh = async () => {
|
|
207
216
|
const next = await createSnapshot(config.snapshotIdentity, projected);
|
|
@@ -266,6 +275,8 @@ export async function adoptRemoteRules(input) {
|
|
|
266
275
|
...(config.localFields !== undefined ? { localFields: config.localFields } : {}),
|
|
267
276
|
});
|
|
268
277
|
const hashes = fileHashMap(await refresh());
|
|
278
|
+
if (resuming && source.identity !== journal.installedIdentity)
|
|
279
|
+
checkSize();
|
|
269
280
|
if (source.text !== text && journal.stateFingerprint !== stateFingerprint)
|
|
270
281
|
throw new Error("Baseline changed after the reviewed Pull. Preserve its journal.");
|
|
271
282
|
if (!sameHashes(hashes, journal.afterFiles)) {
|
|
@@ -274,15 +285,19 @@ export async function adoptRemoteRules(input) {
|
|
|
274
285
|
!sameHashes(appliedFileHashMap(physical, before, protectedPaths), journal.afterFiles))
|
|
275
286
|
throw new Error("Local files changed after the reviewed Pull. Preserve its journal.");
|
|
276
287
|
markCommit();
|
|
288
|
+
if (!journal.installedIdentity)
|
|
289
|
+
options.directionalAction?.setAdoptionResume?.(adoptionJournalFingerprint(journal));
|
|
277
290
|
await applySnapshot(physical, protectedPaths, {
|
|
278
291
|
...projected,
|
|
279
292
|
reviewedLocal: before,
|
|
280
293
|
validateApplyReview: async () => {
|
|
281
294
|
await validateContext();
|
|
295
|
+
await assertCurrentAdoptionJournal(journal);
|
|
282
296
|
if (syncStateFingerprint(await readStateForConfig(config)) !== journal.stateFingerprint)
|
|
283
297
|
throw new Error("Baseline changed at Pull's commit boundary.");
|
|
284
298
|
},
|
|
285
299
|
});
|
|
300
|
+
options.directionalAction?.setAdoptionResume?.(undefined);
|
|
286
301
|
}
|
|
287
302
|
await validateContext();
|
|
288
303
|
if (!sameHashes(fileHashMap(await refresh()), 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
|
+
}
|