@narumitw/pi-sync 0.67.2 → 0.68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +29 -49
- package/dist/chunks/{chunk-XUZV4OGI.ts → chunk-335XTMMZ.ts} +3 -2
- package/dist/chunks/{chunk-XUZV4OGI.ts.map → chunk-335XTMMZ.ts.map} +2 -2
- package/dist/chunks/{chunk-PUSMSKIM.ts → chunk-AYGMIMCV.ts} +2 -11
- package/dist/chunks/chunk-AYGMIMCV.ts.map +7 -0
- package/dist/chunks/{chunk-2MSJDLSM.ts → chunk-BCDBT4X3.ts} +7 -7
- package/dist/chunks/{chunk-GRXNUC6O.ts → chunk-FQKWGVMA.ts} +20 -54
- package/dist/chunks/chunk-FQKWGVMA.ts.map +7 -0
- package/dist/chunks/{chunk-DGVZYS7T.ts → chunk-FR6A7ASZ.ts} +8 -11
- package/dist/chunks/chunk-FR6A7ASZ.ts.map +7 -0
- package/dist/chunks/{chunk-3NS4PMCI.ts → chunk-J52GYZO6.ts} +2 -8
- package/dist/chunks/{chunk-3NS4PMCI.ts.map → chunk-J52GYZO6.ts.map} +2 -2
- package/dist/chunks/{chunk-2MUAR5GH.ts → chunk-KAIVTJIQ.ts} +7 -10
- package/dist/chunks/chunk-KAIVTJIQ.ts.map +7 -0
- package/dist/chunks/{chunk-WBIOSK76.ts → chunk-R7PN3KIY.ts} +1 -2
- package/dist/chunks/{chunk-3Q3DMMID.ts → chunk-TLYT6HVI.ts} +8 -8
- package/dist/chunks/{chunk-UF2HU2NM.ts → chunk-WCGLU526.ts} +39 -118
- package/dist/chunks/chunk-WCGLU526.ts.map +7 -0
- package/dist/chunks/{chunk-JREGWM2B.ts → chunk-XNUARYLR.ts} +1 -2
- package/dist/chunks/{chunk-C3E75DXW.ts → chunk-YV2R5SJU.ts} +73 -85
- package/dist/chunks/chunk-YV2R5SJU.ts.map +7 -0
- package/dist/chunks/{command-handler-HWRPH3K3.ts → command-handler-S6BRZMPW.ts} +117 -69
- package/dist/chunks/command-handler-S6BRZMPW.ts.map +7 -0
- package/dist/chunks/{conflict-review-OBBBSVQD.ts → conflict-review-3XMYDJIK.ts} +2 -2
- package/dist/chunks/{file-selection-GASCVN45.ts → file-selection-4BOQBXS7.ts} +10 -17
- package/dist/chunks/file-selection-4BOQBXS7.ts.map +7 -0
- package/dist/chunks/{manager-result-dispatcher-MJ6G2CEI.ts → manager-result-dispatcher-A4IWLS4J.ts} +7 -7
- package/dist/chunks/{manager-ui-Z3B5ZTA6.ts → manager-ui-KHMCSLLV.ts} +114 -581
- package/dist/chunks/manager-ui-KHMCSLLV.ts.map +7 -0
- package/dist/chunks/{chunk-ECUCXF5Y.ts → merge-review-LWMUE5IW.ts} +2 -3
- package/dist/chunks/{remote-selection-ui-34WC7OFE.ts → remote-selection-ui-F6NJBQ3Y.ts} +6 -6
- package/dist/chunks/{setup-switch-JZDFQPVW.ts → setup-switch-7LMIRMZ7.ts} +6 -6
- package/dist/chunks/{setup-wizard-YOXLXLBY.ts → setup-wizard-2NRPR433.ts} +11 -16
- package/dist/chunks/{setup-wizard-YOXLXLBY.ts.map → setup-wizard-2NRPR433.ts.map} +1 -1
- package/dist/chunks/{sync-inspection-NIITROKS.ts → sync-inspection-QGM54YCM.ts} +5 -5
- package/dist/chunks/{sync-operations-FFI4ZZQL.ts → sync-operations-DTQMKVRQ.ts} +2 -2
- package/dist/daemon/dist/build-id.json +1 -0
- package/dist/daemon/dist/build-version.js +24 -4
- package/dist/daemon/dist/cli.js +51 -67
- package/dist/daemon/dist/client-transport.js +15 -5
- package/dist/daemon/dist/client.js +2 -10
- package/dist/daemon/dist/consent.js +13 -126
- package/dist/daemon/dist/daemon-startup.js +135 -30
- package/dist/daemon/dist/daemon-status.js +56 -0
- package/dist/daemon/dist/engine/backends/git/git-backend.js +4 -17
- package/dist/daemon/dist/engine/backends/git/git-storage.js +11 -44
- package/dist/daemon/dist/engine/backends/s3/s3-backend.js +6 -6
- package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +6 -6
- package/dist/daemon/dist/engine/settings/config.js +16 -149
- package/dist/daemon/dist/engine/settings/retired-ignore-policy.js +16 -0
- package/dist/daemon/dist/engine/settings/retired-ignore-recovery.js +14 -0
- package/dist/daemon/dist/engine/settings/settings-management.js +2 -10
- package/dist/daemon/dist/engine/settings/settings-validation.js +8 -21
- package/dist/daemon/dist/engine/snapshot/session-paths.js +13 -41
- package/dist/daemon/dist/engine/snapshot/snapshot-apply.js +8 -24
- package/dist/daemon/dist/engine/snapshot/snapshot-codec.js +7 -11
- package/dist/daemon/dist/engine/snapshot/snapshot-exclude-safety.js +19 -76
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-images.js +1 -7
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-policy.js +8 -102
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction.js +20 -100
- package/dist/daemon/dist/engine/snapshot/snapshot-types.js +1 -11
- package/dist/daemon/dist/engine/snapshot/snapshot.js +26 -78
- package/dist/daemon/dist/engine/state/sync-state-store.js +5 -1
- package/dist/daemon/dist/engine/sync/agent-plan.js +0 -1
- package/dist/daemon/dist/engine/sync/agent-policy.js +1 -1
- package/dist/daemon/dist/engine/sync/conflict-review.js +0 -2
- package/dist/daemon/dist/engine/sync/continuous-sync.js +2 -17
- package/dist/daemon/dist/engine/sync/continuous-watch.js +3 -7
- package/dist/daemon/dist/engine/sync/directional-action.js +3 -21
- package/dist/daemon/dist/engine/sync/initialization.js +4 -15
- package/dist/daemon/dist/engine/sync/local-fields.js +4 -65
- package/dist/daemon/dist/engine/sync/merge-apply.js +8 -31
- package/dist/daemon/dist/engine/sync/merge-journal.js +8 -118
- package/dist/daemon/dist/engine/sync/merged-sync.js +13 -70
- package/dist/daemon/dist/engine/sync/push-review.js +1 -16
- package/dist/daemon/dist/engine/sync/remote-snapshot.js +48 -65
- package/dist/daemon/dist/engine/sync/startup-bootstrap.js +3 -3
- package/dist/daemon/dist/engine/sync/sync-error-guidance.js +1 -1
- package/dist/daemon/dist/engine/sync/sync-inspection.js +1 -2
- package/dist/daemon/dist/engine/sync/sync-mutations.js +26 -118
- package/dist/daemon/dist/engine/sync/sync-policy.js +26 -150
- package/dist/daemon/dist/engine/sync/sync-queries.js +1 -8
- package/dist/daemon/dist/engine/sync/sync-rollback.js +12 -50
- package/dist/daemon/dist/engine/sync/sync-state.js +2 -15
- package/dist/daemon/dist/engine/sync/transfer-freshness.js +7 -17
- package/dist/daemon/dist/engine/sync/transfer-size-limits.js +3 -7
- package/dist/daemon/dist/engine-service.js +62 -205
- package/dist/daemon/dist/foreground-queue-outcome.js +0 -4
- package/dist/daemon/dist/index.js +2 -0
- package/dist/daemon/dist/legacy-consent-guard.js +34 -0
- package/dist/daemon/dist/server.js +99 -11
- package/dist/daemon/dist/service-host.js +3 -9
- package/dist/daemon/package.json +1 -1
- package/dist/index.ts +49 -49
- package/dist/index.ts.map +3 -3
- package/docs/agent-continuous-hardening.md +2 -0
- package/docs/continuous-sync-verification.md +1 -1
- package/docs/daemon-migration.md +17 -15
- package/docs/tui-contract.md +4 -6
- package/package.json +2 -3
- package/skills/configure-pi-sync/SKILL.md +23 -78
- package/skills/configure-pi-sync/references/configuration.md +59 -76
- package/src/commands/command-execution.ts +15 -38
- package/src/commands/command-handler.ts +0 -4
- package/src/commands/command.ts +2 -1
- package/src/daemon/daemon-status-ui.ts +64 -0
- package/src/daemon/directional-recovery.ts +4 -33
- package/src/daemon/pi-client.ts +87 -94
- package/src/settings/config.ts +0 -1
- package/src/sync/setup-switch.ts +1 -4
- package/src/sync-extension.ts +14 -27
- package/src/ui/cancellable-operation.ts +2 -13
- package/src/ui/excluded-paths-ui.ts +1 -4
- package/src/ui/file-selection.ts +0 -5
- package/src/ui/manager-state.ts +12 -75
- package/src/ui/manager-ui.ts +7 -96
- package/src/ui/remote-selection-ui.ts +29 -130
- package/src/ui/settings-ui.ts +169 -388
- package/src/ui/setup/setup-actions.ts +4 -16
- package/src/ui/setup/setup-prompts.ts +12 -49
- package/src/ui/setup/setup-switcher.ts +8 -14
- package/src/ui/storage-connections-ui.ts +21 -32
- package/src/ui/sync-setups-ui.ts +27 -53
- package/dist/chunks/chunk-2MUAR5GH.ts.map +0 -7
- package/dist/chunks/chunk-C3E75DXW.ts.map +0 -7
- package/dist/chunks/chunk-DGVZYS7T.ts.map +0 -7
- package/dist/chunks/chunk-EJDDRS6O.ts +0 -17
- package/dist/chunks/chunk-EJDDRS6O.ts.map +0 -7
- package/dist/chunks/chunk-GRXNUC6O.ts.map +0 -7
- package/dist/chunks/chunk-I72HGZJJ.ts +0 -106
- package/dist/chunks/chunk-I72HGZJJ.ts.map +0 -7
- package/dist/chunks/chunk-KNEUL4XN.ts +0 -30
- package/dist/chunks/chunk-KNEUL4XN.ts.map +0 -7
- package/dist/chunks/chunk-PUSMSKIM.ts.map +0 -7
- package/dist/chunks/chunk-UF2HU2NM.ts.map +0 -7
- package/dist/chunks/chunk-WFBHWYI6.ts +0 -18
- package/dist/chunks/chunk-WFBHWYI6.ts.map +0 -7
- package/dist/chunks/command-handler-HWRPH3K3.ts.map +0 -7
- package/dist/chunks/config-P54GGMXY.ts +0 -39
- package/dist/chunks/continuous-record-3SKJ6I3V.ts +0 -23
- package/dist/chunks/continuous-record-3SKJ6I3V.ts.map +0 -7
- package/dist/chunks/continuous-storage-3EU6I7Z3.ts +0 -27
- package/dist/chunks/continuous-storage-3EU6I7Z3.ts.map +0 -7
- package/dist/chunks/file-selection-GASCVN45.ts.map +0 -7
- package/dist/chunks/ignore-file-ui-5BWA6LBC.ts +0 -21
- package/dist/chunks/manager-ui-Z3B5ZTA6.ts.map +0 -7
- package/dist/chunks/merge-review-C2KETZKY.ts +0 -11
- package/dist/chunks/merge-review-C2KETZKY.ts.map +0 -7
- package/dist/chunks/remote-selection-ui-34WC7OFE.ts.map +0 -7
- package/dist/chunks/setup-switch-JZDFQPVW.ts.map +0 -7
- package/dist/daemon/dist/engine/ignore/adoption-journal.js +0 -146
- package/dist/daemon/dist/engine/ignore/effective-ignore-policy.js +0 -33
- package/dist/daemon/dist/engine/ignore/ignore-edit.js +0 -102
- package/dist/daemon/dist/engine/ignore/ignore-initialization.js +0 -288
- package/dist/daemon/dist/engine/ignore/ignore-migration-prompt.js +0 -139
- package/dist/daemon/dist/engine/ignore/ignore-settings.js +0 -391
- package/dist/daemon/dist/engine/ignore/ignore-source.js +0 -250
- package/dist/daemon/dist/engine/ignore/snapshot-ignore-rules.js +0 -39
- package/dist/daemon/dist/engine/sync/ignore-adoption-recovery.js +0 -50
- package/dist/daemon/dist/engine/sync/ignore-adoption.js +0 -416
- package/dist/daemon/dist/engine/sync/ignore-publication.js +0 -23
- package/dist/daemon/dist/engine/ui/ignore-rule-preview.js +0 -18
- package/dist/daemon/dist/monitor.js +0 -344
- package/src/ui/agent-mode-setting.ts +0 -99
- package/src/ui/ignore-file-guidance.ts +0 -7
- package/src/ui/ignore-file-ui.ts +0 -105
- package/src/ui/ignore-migration-prompt.ts +0 -65
- package/src/ui/settings-review.ts +0 -26
- /package/dist/chunks/{chunk-2MSJDLSM.ts.map → chunk-BCDBT4X3.ts.map} +0 -0
- /package/dist/chunks/{chunk-WBIOSK76.ts.map → chunk-R7PN3KIY.ts.map} +0 -0
- /package/dist/chunks/{chunk-3Q3DMMID.ts.map → chunk-TLYT6HVI.ts.map} +0 -0
- /package/dist/chunks/{chunk-JREGWM2B.ts.map → chunk-XNUARYLR.ts.map} +0 -0
- /package/dist/chunks/{conflict-review-OBBBSVQD.ts.map → conflict-review-3XMYDJIK.ts.map} +0 -0
- /package/dist/chunks/{config-P54GGMXY.ts.map → manager-result-dispatcher-A4IWLS4J.ts.map} +0 -0
- /package/dist/chunks/{chunk-ECUCXF5Y.ts.map → merge-review-LWMUE5IW.ts.map} +0 -0
- /package/dist/chunks/{ignore-file-ui-5BWA6LBC.ts.map → remote-selection-ui-F6NJBQ3Y.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-MJ6G2CEI.ts.map → setup-switch-7LMIRMZ7.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-NIITROKS.ts.map → sync-inspection-QGM54YCM.ts.map} +0 -0
- /package/dist/chunks/{sync-operations-FFI4ZZQL.ts.map → sync-operations-DTQMKVRQ.ts.map} +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { loadConfigForCheck, syncCheckConfigFingerprint } from "../settings/config.js";
|
|
2
2
|
import { resolvedSnapshotOptionsForContext } from "../snapshot/session-paths.js";
|
|
3
|
-
import { ignorePolicyValidator } from "../snapshot/snapshot-transaction-policy.js";
|
|
4
3
|
import { withLock } from "../state/lock.js";
|
|
5
4
|
import { withStateDirectoryAccess } from "../state/state-directory.js";
|
|
6
5
|
import { readStateForConfig } from "../state/sync-state-store.js";
|
|
@@ -11,7 +10,7 @@ import { acquireContinuousLease } from "./continuous-lease.js";
|
|
|
11
10
|
import { normalizeContinuousClock, readContinuousRecord, reserveContinuousRequest, updateContinuousRecord, } from "./continuous-record.js";
|
|
12
11
|
import { continuousBinding, hashContinuous } from "./continuous-storage.js";
|
|
13
12
|
import { watchContinuous } from "./continuous-watch.js";
|
|
14
|
-
import {
|
|
13
|
+
import { readMergeJournal } from "./merge-journal.js";
|
|
15
14
|
import { createStartupTimings } from "./startup-timings.js";
|
|
16
15
|
import { captureMutationOwner } from "./sync-local.js";
|
|
17
16
|
import { rawSnapshotHashIdentity } from "./sync-state.js";
|
|
@@ -231,8 +230,6 @@ export function createContinuousSync(loaders, clock = systemClock, publish, diag
|
|
|
231
230
|
return;
|
|
232
231
|
validate();
|
|
233
232
|
if (syncCheckConfigFingerprint(latest) !== syncCheckConfigFingerprint(config)) {
|
|
234
|
-
if (config.reservedIgnoreNames !== undefined || latest.reservedIgnoreNames !== undefined)
|
|
235
|
-
return;
|
|
236
233
|
explicitRetry = false;
|
|
237
234
|
closeWatch();
|
|
238
235
|
config = latest;
|
|
@@ -249,12 +246,7 @@ export function createContinuousSync(loaders, clock = systemClock, publish, diag
|
|
|
249
246
|
await updateContinuousRecord(binding, lease, (current) => normalizeContinuousClock(current, now));
|
|
250
247
|
validate();
|
|
251
248
|
}
|
|
252
|
-
const configuration = hashContinuous([
|
|
253
|
-
config.ignorePolicy
|
|
254
|
-
? syncCheckConfigFingerprint(config)
|
|
255
|
-
: { ...config, showStatus: undefined, debug: undefined },
|
|
256
|
-
ctx.model,
|
|
257
|
-
]);
|
|
249
|
+
const configuration = hashContinuous([{ ...config, showStatus: undefined, debug: undefined }, ctx.model]);
|
|
258
250
|
const controlChanged = record.configuration !== configuration;
|
|
259
251
|
if (controlChanged || explicitRetry) {
|
|
260
252
|
record.next = 0;
|
|
@@ -401,8 +393,6 @@ export function createContinuousSync(loaders, clock = systemClock, publish, diag
|
|
|
401
393
|
// A newly pending journal may prove an uncertain commit. It is never authority to republish.
|
|
402
394
|
const pending = await guardedLock("continuous-journal", () => readMergeJournal(config));
|
|
403
395
|
validate();
|
|
404
|
-
if (pending)
|
|
405
|
-
assertMergeJournalPolicy(pending, config);
|
|
406
396
|
if (!force &&
|
|
407
397
|
!pending &&
|
|
408
398
|
current.phase === "blocked" &&
|
|
@@ -415,9 +405,6 @@ export function createContinuousSync(loaders, clock = systemClock, publish, diag
|
|
|
415
405
|
validate();
|
|
416
406
|
const snapshotOptions = await resolvedSnapshotOptionsForContext(ctx, config, signal);
|
|
417
407
|
validate();
|
|
418
|
-
const validateIgnore = ignorePolicyValidator({ ...snapshotOptions, validateMutation: validate });
|
|
419
|
-
if (validateIgnore)
|
|
420
|
-
await validateIgnore();
|
|
421
408
|
await refresh();
|
|
422
409
|
const inspection = await inspectionModule.inspectSync(config, snapshotOptions, signal, undefined, timings);
|
|
423
410
|
await refresh();
|
|
@@ -431,8 +418,6 @@ export function createContinuousSync(loaders, clock = systemClock, publish, diag
|
|
|
431
418
|
}
|
|
432
419
|
const journal = await readMergeJournal(config);
|
|
433
420
|
validate();
|
|
434
|
-
if (journal)
|
|
435
|
-
assertMergeJournalPolicy(journal, config);
|
|
436
421
|
return { inspection, journal, localIdentity };
|
|
437
422
|
}));
|
|
438
423
|
validate();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { watch } from "node:fs";
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { getEngineRoot as getAgentDir } from "../host.js";
|
|
@@ -38,13 +38,9 @@ export async function watchContinuous(config, changed, options = {}) {
|
|
|
38
38
|
if (!file || closed || options.signal?.aborted)
|
|
39
39
|
return;
|
|
40
40
|
const target = path.resolve(directory, String(file));
|
|
41
|
-
|
|
42
|
-
if (!relativeWithin(directory, target) || directoryOnlyHint)
|
|
41
|
+
if (!relativeWithin(directory, target))
|
|
43
42
|
return;
|
|
44
|
-
if (target === path.join(root, "pi-sync.json")
|
|
45
|
-
(config.ignorePolicy &&
|
|
46
|
-
path.dirname(target) === root &&
|
|
47
|
-
path.basename(target).toLowerCase() === config.ignorePolicy.filename.toLowerCase()))
|
|
43
|
+
if (target === path.join(root, "pi-sync.json"))
|
|
48
44
|
changed(true);
|
|
49
45
|
else if (scoped) {
|
|
50
46
|
const relative = scopedPath(target);
|
|
@@ -49,27 +49,12 @@ export async function checkpointDirectionalAction(options, evidence) {
|
|
|
49
49
|
.digest("hex");
|
|
50
50
|
await options.directionalAction?.checkpoint?.(hash);
|
|
51
51
|
}
|
|
52
|
-
export function requireDirectionalSelection(config, state,
|
|
52
|
+
export function requireDirectionalSelection(config, state, _local, remote, _sessionDir) {
|
|
53
53
|
if (!syncSelectionHasContent(config))
|
|
54
54
|
throw new Error("This setup has no managed content for the transfer.");
|
|
55
|
-
const current = config.ignorePolicy;
|
|
56
|
-
const remoteProjected = current && remote && filterSnapshotForConfigPolicy(remote, config, { sessionDir });
|
|
57
|
-
const managed = new Set([...local.files, ...(remoteProjected?.files ?? [])].map((file) => file.path));
|
|
58
|
-
const provesNarrowing = (priorPaths, priorSessions) => {
|
|
59
|
-
if (!current || (!priorSessions && current.sessions))
|
|
60
|
-
return false;
|
|
61
|
-
const prior = new Set(priorPaths);
|
|
62
|
-
return ([...managed].every((item) => prior.has(item)) &&
|
|
63
|
-
((priorSessions && !current.sessions) ||
|
|
64
|
-
priorPaths.some((item) => !managed.has(item) && current.matches(item, false))));
|
|
65
|
-
};
|
|
66
55
|
if (remote)
|
|
67
56
|
requireCompatibleRemoteSelection(config, remote);
|
|
68
|
-
if (state.lastAppliedSnapshot &&
|
|
69
|
-
syncPolicyChanged(state, config) &&
|
|
70
|
-
!(state.scope === config.scope &&
|
|
71
|
-
state.ignorePolicyKey &&
|
|
72
|
-
provesNarrowing(Object.keys(state.lastFileHashes), state.include?.includes("sessions") === true)))
|
|
57
|
+
if (state.lastAppliedSnapshot && syncPolicyChanged(state, config))
|
|
73
58
|
throw new Error("Managed content policy changed and this transfer cannot prove that it only narrows the accepted selection. Review the new policy before transferring.");
|
|
74
59
|
}
|
|
75
60
|
export function keepProtectedRemoteSessions(config, upload, remote, sessionDir, protectedPaths) {
|
|
@@ -84,9 +69,6 @@ export function keepProtectedRemoteSessions(config, upload, remote, sessionDir,
|
|
|
84
69
|
const files = [...upload.files.filter((file) => !protectedPaths.has(file.path)), ...retained];
|
|
85
70
|
return {
|
|
86
71
|
...upload,
|
|
87
|
-
...(upload.selection?.version === 4
|
|
88
|
-
? { syncSessions: files.some((file) => file.path.startsWith("sessions/")) }
|
|
89
|
-
: {}),
|
|
90
72
|
files: files.sort((a, b) => a.path.localeCompare(b.path)),
|
|
91
73
|
};
|
|
92
74
|
}
|
|
@@ -108,7 +90,7 @@ export function notifyDirectionalSuccess(ctx, options, message, warning = false)
|
|
|
108
90
|
export function remoteRestoreGuidance(head, previous, config, sessionDir) {
|
|
109
91
|
const ref = head.snapshotRef === head.snapshotId ? "" : ` (reference ${safeTerminalText(head.snapshotRef)})`;
|
|
110
92
|
const version = `${safeTerminalText(head.snapshotId)}${ref}`;
|
|
111
|
-
const eligible =
|
|
93
|
+
const eligible = syncSessionsSelected(config) ? previous : snapshotWithoutSessions(previous);
|
|
112
94
|
const selected = filterSnapshotForConfigPolicy(eligible, config, { sessionDir });
|
|
113
95
|
return selected.files.length === previous.files.length
|
|
114
96
|
? `Restore the previous remote version ${version} from /sync → History.`
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { loadConfig } from "../settings/config.js";
|
|
1
|
+
import { configFromSettings, loadConfig } from "../settings/config.js";
|
|
3
2
|
import { isMissingConfigError } from "../settings/config-errors.js";
|
|
4
3
|
import { consumeLocalConfigMigrationNotice } from "../settings/config-file.js";
|
|
4
|
+
import { assertNoRetiredRuleJournal } from "../settings/retired-ignore-recovery.js";
|
|
5
5
|
import { readLocalConfigObject } from "../settings/settings-store.js";
|
|
6
6
|
import { effectiveSessionRoot, sessionDirFromContext, snapshotOptionsForContext } from "../snapshot/session-paths.js";
|
|
7
7
|
import { pendingTransactionEntries } from "../snapshot/snapshot-transaction-directory.js";
|
|
@@ -22,27 +22,16 @@ export async function initializeSync(ctx, signal, publish, observe) {
|
|
|
22
22
|
if (stateNotice && ctx.hasUI)
|
|
23
23
|
ctx.ui.notify(stateNotice, "warning");
|
|
24
24
|
await timings.measure("transaction recovery", async () => {
|
|
25
|
+
assertNoRetiredRuleJournal();
|
|
25
26
|
const pending = await pendingTransactionEntries();
|
|
26
27
|
validate();
|
|
27
|
-
if (hasPendingAdoption()) {
|
|
28
|
-
if (pending.length) {
|
|
29
|
-
const { recoverAdoptionFilesOnStartup } = await import("./ignore-adoption-recovery.js");
|
|
30
|
-
validate();
|
|
31
|
-
await recoverAdoptionFilesOnStartup(ctx, signal, validate);
|
|
32
|
-
validate();
|
|
33
|
-
}
|
|
34
|
-
if (ctx.hasUI)
|
|
35
|
-
ctx.ui.notify("Ignore-rule adoption is pending. Resume from the originating setup with /sync pull.", "warning");
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
28
|
if (!pending.some((entry) => entry.isDirectory()))
|
|
39
29
|
return;
|
|
40
30
|
const { recoverSnapshotTransactionsOnStartup } = await import("../snapshot/snapshot-transaction.js");
|
|
41
31
|
validate();
|
|
42
32
|
const settings = await readLocalConfigObject();
|
|
43
33
|
validate();
|
|
44
|
-
const config = settings?.activeSyncSetup ?
|
|
45
|
-
validate();
|
|
34
|
+
const config = settings?.activeSyncSetup ? configFromSettings(settings) : undefined;
|
|
46
35
|
const sessionDir = config?.scope === "agent-directory"
|
|
47
36
|
? await effectiveSessionRoot(ctx, config, signal)
|
|
48
37
|
: sessionDirFromContext(ctx);
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { validateSnapshotIgnoreRules } from "../ignore/snapshot-ignore-rules.js";
|
|
3
2
|
import { regenerateSnapshotIdentity } from "../snapshot/snapshot.js";
|
|
4
3
|
import { assertAgentDirectorySnapshotBound } from "../snapshot/snapshot-bounds.js";
|
|
5
|
-
import {
|
|
6
|
-
import { isIgnoreSnapshotVersion, isSupportedSnapshotVersion, } from "../snapshot/snapshot-types.js";
|
|
4
|
+
import { isSupportedSnapshotVersion, } from "../snapshot/snapshot-types.js";
|
|
7
5
|
import { jsonEqual, parseSettingsDocument, renderSettingsMembers, } from "./json-document.js";
|
|
8
6
|
import { normalizeLocalFields } from "./local-field-policy.js";
|
|
9
|
-
import { compileSyncPolicyExclude, configuredSnapshotPathMatcher, validateSnapshotSelection } from "./sync-policy.js";
|
|
7
|
+
import { compileSyncPolicyExclude, configuredSnapshotPathMatcher, requireLegacyTransferPolicy, validateSnapshotSelection, } from "./sync-policy.js";
|
|
10
8
|
export { normalizeLocalFields } from "./local-field-policy.js";
|
|
11
9
|
/** Shared transport contract: older snapshots cannot carry portable policy metadata. */
|
|
12
10
|
export function validateSnapshotFieldPolicy(snapshot) {
|
|
11
|
+
requireLegacyTransferPolicy(snapshot);
|
|
13
12
|
if (!isSupportedSnapshotVersion(snapshot.version))
|
|
14
13
|
throw new Error("Unsupported snapshot format.");
|
|
15
14
|
if (snapshot.version === 1 && snapshot.localFields !== undefined)
|
|
@@ -20,75 +19,15 @@ export function validateSnapshotFieldPolicy(snapshot) {
|
|
|
20
19
|
normalizeLocalFields(snapshot.localFields);
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
|
-
export function validateIgnoreSnapshotSessionFlag(selection, syncSessions) {
|
|
24
|
-
if ((syncSessions !== undefined && typeof syncSessions !== "boolean") ||
|
|
25
|
-
(syncSessions === true && !selection.sessions))
|
|
26
|
-
throw new Error("Invalid ignore snapshot session metadata.");
|
|
27
|
-
}
|
|
28
|
-
export function validateIgnoreSnapshotIdentity({ id, createdAt, machine, profile, }) {
|
|
29
|
-
if (typeof id !== "string" ||
|
|
30
|
-
id.length > 512 ||
|
|
31
|
-
id === "." ||
|
|
32
|
-
id === ".." ||
|
|
33
|
-
!/^[A-Za-z0-9._-]+(?![\s\S])/u.test(id) ||
|
|
34
|
-
typeof createdAt !== "string" ||
|
|
35
|
-
createdAt.length > 64 ||
|
|
36
|
-
/[\p{Cc}\p{Cs}]/u.test(createdAt) ||
|
|
37
|
-
Number.isNaN(Date.parse(createdAt)) ||
|
|
38
|
-
typeof machine !== "string" ||
|
|
39
|
-
machine.length > 256 ||
|
|
40
|
-
/[\p{Cc}\p{Cs}]/u.test(machine) ||
|
|
41
|
-
typeof profile !== "string" ||
|
|
42
|
-
!profile ||
|
|
43
|
-
profile.length > 256 ||
|
|
44
|
-
/[\p{Cc}\p{Cs}]/u.test(profile))
|
|
45
|
-
throw new Error("Invalid ignore snapshot identity.");
|
|
46
|
-
}
|
|
47
|
-
function validateIgnoreSnapshotEnvelope(snapshot, selection) {
|
|
48
|
-
validateIgnoreSnapshotIdentity(snapshot);
|
|
49
|
-
validateIgnoreSnapshotSessionFlag(selection, snapshot.syncSessions);
|
|
50
|
-
if (!Array.isArray(snapshot.files) ||
|
|
51
|
-
Object.keys(snapshot).some((key) => ![
|
|
52
|
-
"version",
|
|
53
|
-
"id",
|
|
54
|
-
"createdAt",
|
|
55
|
-
"machine",
|
|
56
|
-
"profile",
|
|
57
|
-
"syncSessions",
|
|
58
|
-
"selection",
|
|
59
|
-
"ignoreRules",
|
|
60
|
-
"localFields",
|
|
61
|
-
"files",
|
|
62
|
-
].includes(key)))
|
|
63
|
-
throw new Error("Invalid ignore snapshot payload.");
|
|
64
|
-
}
|
|
65
|
-
function validateIgnoreSnapshotFiles(files) {
|
|
66
|
-
for (const file of files) {
|
|
67
|
-
if (Object.keys(file).length !== 3 ||
|
|
68
|
-
!Object.hasOwn(file, "path") ||
|
|
69
|
-
!Object.hasOwn(file, "contentBase64") ||
|
|
70
|
-
!Object.hasOwn(file, "sha256") ||
|
|
71
|
-
typeof file.sha256 !== "string" ||
|
|
72
|
-
file.sha256.length !== 64)
|
|
73
|
-
throw new Error("Invalid ignore snapshot file.");
|
|
74
|
-
assertSnapshotFilePayload(file, "Ignore snapshot file checksum or encoding mismatch.");
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/** Portable transport images must not carry values declared machine-local. Physical journal images are different. */
|
|
78
22
|
export function validatePortableSnapshot(snapshot) {
|
|
79
23
|
validateSnapshotFieldPolicy(snapshot);
|
|
80
24
|
validateSnapshotSelection(snapshot);
|
|
81
25
|
const selection = snapshot.selection;
|
|
82
|
-
const policy = validateSnapshotIgnoreRules(snapshot);
|
|
83
|
-
if (selection?.version === 4)
|
|
84
|
-
validateIgnoreSnapshotEnvelope(snapshot, selection);
|
|
85
26
|
if (selection?.scope) {
|
|
86
|
-
const selected = configuredSnapshotPathMatcher(
|
|
27
|
+
const selected = configuredSnapshotPathMatcher(selection);
|
|
87
28
|
if (snapshot.files.some((file) => typeof file?.path !== "string" || !selected(file.path)))
|
|
88
29
|
throw new Error("Portable snapshot retains excluded or unsafe agent-directory paths.");
|
|
89
30
|
assertAgentDirectorySnapshotBound(snapshot.files);
|
|
90
|
-
if (isIgnoreSnapshotVersion(snapshot.version))
|
|
91
|
-
validateIgnoreSnapshotFiles(snapshot.files);
|
|
92
31
|
}
|
|
93
32
|
else {
|
|
94
33
|
const excludedPath = compileSyncPolicyExclude(selection ?? {});
|
|
@@ -12,8 +12,6 @@ import { assertUnexcludedTargets } from "../snapshot/snapshot-exclude-safety.js"
|
|
|
12
12
|
import { assertCanonicalMutationTargets } from "../snapshot/snapshot-mutation-queues.js";
|
|
13
13
|
import { sessionStorageRoot } from "../snapshot/snapshot-paths.js";
|
|
14
14
|
import { snapshotBase64Size } from "../snapshot/snapshot-payload.js";
|
|
15
|
-
import { recheckScopedImage, scopedTransactionImage } from "../snapshot/snapshot-transaction-images.js";
|
|
16
|
-
import { ignorePolicyValidator } from "../snapshot/snapshot-transaction-policy.js";
|
|
17
15
|
import { syncDirectory } from "../state/json-file.js";
|
|
18
16
|
import { syncMutationParents } from "../state/mutation-directory-sync.js";
|
|
19
17
|
import { ContinuousError } from "./continuous-errors.js";
|
|
@@ -254,12 +252,11 @@ async function assertFilesystemTarget(root, relative, options, removedTargets =
|
|
|
254
252
|
}
|
|
255
253
|
/** Roll forward only while each target is still its reviewed preimage or committed postimage. */
|
|
256
254
|
export async function applyMergedSnapshot(before, after, protectedPaths, options, validate, protectedTarget) {
|
|
257
|
-
const validateIgnore = ignorePolicyValidator(options);
|
|
258
255
|
const root = agentDir();
|
|
259
256
|
if (options.scope === "agent-directory" && options.sessionDir === undefined) {
|
|
260
257
|
options = {
|
|
261
258
|
...options,
|
|
262
|
-
sessionDir: sessionStorageRoot(root, await agentDirectoryConfiguredSessionDir(options.signal, root
|
|
259
|
+
sessionDir: sessionStorageRoot(root, await agentDirectoryConfiguredSessionDir(options.signal, root)),
|
|
263
260
|
};
|
|
264
261
|
options.validateMutation?.();
|
|
265
262
|
options.signal?.throwIfAborted();
|
|
@@ -283,7 +280,8 @@ export async function applyMergedSnapshot(before, after, protectedPaths, options
|
|
|
283
280
|
const targetSet = new Set(targets);
|
|
284
281
|
await assertDistinctMergedTargets(root, paths, new Set(changed), options, protectedTarget, new Set(Object.keys(afterHashes)));
|
|
285
282
|
await assertCanonicalMutationTargets(targets, options);
|
|
286
|
-
|
|
283
|
+
if (options.scope === "agent-directory")
|
|
284
|
+
await assertUnexcludedTargets(root, targets, options);
|
|
287
285
|
// Existing case aliases share Pi's non-reentrant realpath queue. Reserve the
|
|
288
286
|
// missing destination separately only after deleting its reviewed preimage.
|
|
289
287
|
const targetsByQueue = new Map();
|
|
@@ -315,8 +313,6 @@ export async function applyMergedSnapshot(before, after, protectedPaths, options
|
|
|
315
313
|
if (target)
|
|
316
314
|
return withFileMutationQueue(target, () => acquire(index + 1));
|
|
317
315
|
await validate();
|
|
318
|
-
if (validateIgnore)
|
|
319
|
-
await validateIgnore();
|
|
320
316
|
await assertCanonicalMergedTargets(root, changed, options);
|
|
321
317
|
await validate();
|
|
322
318
|
const current = await createSnapshot(before.profile, options);
|
|
@@ -383,8 +379,6 @@ export async function applyMergedSnapshot(before, after, protectedPaths, options
|
|
|
383
379
|
const removedTargets = new Set([...removed].map((item) => snapshotTarget(root, item, options.sessionDir)));
|
|
384
380
|
await assertCanonicalMergedTargets(root, changed, options);
|
|
385
381
|
await validate();
|
|
386
|
-
if (options.validateApplyReview)
|
|
387
|
-
await options.validateApplyReview();
|
|
388
382
|
const requireReviewedHash = (relative, hash) => {
|
|
389
383
|
if (hash !== beforeHashes[relative] && hash !== afterHashes[relative])
|
|
390
384
|
throw new Error("Local content changed at the apply boundary; journal retained, newer bytes untouched.");
|
|
@@ -394,20 +388,11 @@ export async function applyMergedSnapshot(before, after, protectedPaths, options
|
|
|
394
388
|
const relative = relativeByTarget.get(target);
|
|
395
389
|
if (!relative)
|
|
396
390
|
throw new Error("Unowned merge target.");
|
|
397
|
-
if (
|
|
391
|
+
if (options.scope === "agent-directory") {
|
|
398
392
|
await assertCanonicalMutationTargets([target], options);
|
|
399
393
|
await assertUnexcludedTargets(root, [target], options);
|
|
400
394
|
}
|
|
401
395
|
await assertFilesystemTarget(root, relative, options, removedTargets, currentHashes);
|
|
402
|
-
if (validateIgnore) {
|
|
403
|
-
const image = await scopedTransactionImage(target, options);
|
|
404
|
-
if (image.kind === "directory" && (!removed.has(relative) || image.children.length))
|
|
405
|
-
throw new Error("Reviewed directory has remaining contents; journal retained for review.");
|
|
406
|
-
requireReviewedHash(relative, image.kind === "file" ? image.value.slice("file:".length) : undefined);
|
|
407
|
-
await validateIgnore();
|
|
408
|
-
await recheckScopedImage(target, image, options);
|
|
409
|
-
return image.kind;
|
|
410
|
-
}
|
|
411
396
|
await validate();
|
|
412
397
|
let kind = "missing";
|
|
413
398
|
let hash;
|
|
@@ -451,12 +436,10 @@ export async function applyMergedSnapshot(before, after, protectedPaths, options
|
|
|
451
436
|
for (const target of plan.deletes) {
|
|
452
437
|
let kind = await revalidateTarget(target);
|
|
453
438
|
try {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
}
|
|
459
|
-
if (kind !== "missing" && checkApplyImage)
|
|
439
|
+
const stat = await fs.lstat(target);
|
|
440
|
+
await validate();
|
|
441
|
+
kind = stat.isDirectory() ? "directory" : "file";
|
|
442
|
+
if (checkApplyImage)
|
|
460
443
|
await requireReviewedApplyImage();
|
|
461
444
|
if (kind === "directory")
|
|
462
445
|
await fs.rmdir(target); // Only an empty, reviewed directory may be replaced.
|
|
@@ -491,10 +474,6 @@ export async function applyMergedSnapshot(before, after, protectedPaths, options
|
|
|
491
474
|
// Writers registered after deletion must finish first; never accept their
|
|
492
475
|
// bytes as our own, even if they match a recognizable pre/postimage.
|
|
493
476
|
await requireAbsentDestinations();
|
|
494
|
-
if (deferredTargets.length && options.validateApplyReview)
|
|
495
|
-
await options.validateApplyReview();
|
|
496
|
-
if (validateIgnore)
|
|
497
|
-
await validateIgnore();
|
|
498
477
|
await writeTargets();
|
|
499
478
|
}
|
|
500
479
|
await requireAbsentDestinations();
|
|
@@ -509,8 +488,6 @@ export async function applyMergedSnapshot(before, after, protectedPaths, options
|
|
|
509
488
|
const relative = relativeByTarget.get(item.target);
|
|
510
489
|
if (!relative)
|
|
511
490
|
throw new Error("Unowned merge write target.");
|
|
512
|
-
if (validateIgnore)
|
|
513
|
-
await validateIgnore();
|
|
514
491
|
await assertFilesystemTarget(root, relative, options, new Set());
|
|
515
492
|
if (checkApplyImage)
|
|
516
493
|
await requireReviewedApplyImage();
|
|
@@ -1,65 +1,15 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import {
|
|
5
|
-
import { isIgnoreSnapshotVersion } from "../snapshot/snapshot-types.js";
|
|
4
|
+
import { retiredIgnorePolicy } from "../settings/retired-ignore-policy.js";
|
|
6
5
|
import { readJsonIfExists, syncDirectory, writeJson } from "../state/json-file.js";
|
|
7
|
-
import {
|
|
8
|
-
import { confirmMergeReview } from "../ui/merge-review.js";
|
|
9
|
-
import { safeTerminalText } from "../ui/terminal-text.js";
|
|
6
|
+
import { statePathForConfig, syncStateFingerprint } from "../state/sync-state-store.js";
|
|
10
7
|
import { normalizeSyncExclude } from "./exclude-policy.js";
|
|
11
8
|
import { planFileMerge } from "./file-merge-planner.js";
|
|
12
9
|
import { portableSnapshot, sameLocalFields, validatePortableSnapshot, validateSnapshotFieldPolicy, } from "./local-fields.js";
|
|
13
|
-
import {
|
|
10
|
+
import { configuredSnapshotPathMatcher, sameSnapshotSelection, syncDirectoryPolicyKey, validateSnapshotSelection, } from "./sync-policy.js";
|
|
14
11
|
import { fileHashMap, sameHashes } from "./sync-state.js";
|
|
15
|
-
export function mergeJournalPolicy(config) {
|
|
16
|
-
const localPolicyKey = recoveryPolicyKey(config);
|
|
17
|
-
const ignoreSource = config.ignorePolicy ? ignoreSourceBinding(config.ignorePolicy) : undefined;
|
|
18
|
-
if (localPolicyKey)
|
|
19
|
-
return { version: 3, localPolicyKey, ...(ignoreSource ? { ignoreSource } : {}) };
|
|
20
|
-
return ignoreSource ? { version: 2, ignoreSource } : { version: 1 };
|
|
21
|
-
}
|
|
22
|
-
function ignoreRecoveryPolicy(journal) {
|
|
23
|
-
return {
|
|
24
|
-
version: journal.version === 3 ? BOUND_DIRECTORY_JOURNAL_VERSION : IGNORE_POLICY_JOURNAL_VERSION,
|
|
25
|
-
ignoreSource: journal.ignoreSource,
|
|
26
|
-
localPolicyKey: journal.localPolicyKey,
|
|
27
|
-
selection: journal.upload.selection,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
export function assertMergeJournalPolicy(journal, config) {
|
|
31
|
-
if (journal.localPolicyKey !== recoveryPolicyKey(config))
|
|
32
|
-
throw new Error("Pending merge lacks matching setup or ignore-file policy evidence; preserve its journal for reviewed recovery.");
|
|
33
|
-
if (journal.version === 1 && !config.ignorePolicy && config.pathPolicy !== "ignore-file")
|
|
34
|
-
return;
|
|
35
|
-
if (journal.ignoreSource || config.ignorePolicy || config.pathPolicy === "ignore-file")
|
|
36
|
-
assertRecoveryPolicy(ignoreRecoveryPolicy(journal), config);
|
|
37
|
-
try {
|
|
38
|
-
const identity = JSON.parse(journal.identity);
|
|
39
|
-
if (!Array.isArray(identity) ||
|
|
40
|
-
typeof identity[1] !== "string" ||
|
|
41
|
-
journal.identity !== mergeJournalIdentity(config, identity[1]))
|
|
42
|
-
throw new Error("Inconsistent merge identity.");
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
throw new Error("Pending merge belongs to a different setup or local policy; preserve its journal.");
|
|
46
|
-
}
|
|
47
|
-
const configured = configuredSnapshotPathMatcher(config);
|
|
48
|
-
const excluded = compileSyncPolicyExclude(config);
|
|
49
|
-
if (!journal.applyOnly && journal.upload.files.some((file) => excluded(file.path)))
|
|
50
|
-
throw new Error("Pending publication contains protected paths; preserve its journal.");
|
|
51
|
-
for (const snapshot of [
|
|
52
|
-
journal.before,
|
|
53
|
-
journal.after,
|
|
54
|
-
journal.accepted,
|
|
55
|
-
journal.ignoreSource && !journal.applyOnly ? journal.upload : undefined,
|
|
56
|
-
]) {
|
|
57
|
-
if (snapshot?.files.some((file) => !configured(file.path)))
|
|
58
|
-
throw new Error("Pending merge contains paths outside the current ignore-file policy; preserve its journal.");
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
12
|
export function mergeJournalIdentity(config, backendIdentity) {
|
|
62
|
-
const localPolicyKey = recoveryPolicyKey(config);
|
|
63
13
|
return JSON.stringify([
|
|
64
14
|
config.setupName,
|
|
65
15
|
backendIdentity,
|
|
@@ -70,7 +20,6 @@ export function mergeJournalIdentity(config, backendIdentity) {
|
|
|
70
20
|
: config.exclude === undefined
|
|
71
21
|
? []
|
|
72
22
|
: ["exclude", normalizeSyncExclude(config.exclude).map((rule) => rule.toLowerCase())]),
|
|
73
|
-
...(localPolicyKey ? [localPolicyKey] : []),
|
|
74
23
|
]);
|
|
75
24
|
}
|
|
76
25
|
export function mergeJournalPath(config) {
|
|
@@ -92,13 +41,10 @@ export async function readMergeJournal(config) {
|
|
|
92
41
|
}
|
|
93
42
|
if (journal === undefined)
|
|
94
43
|
return;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
(
|
|
98
|
-
|
|
99
|
-
(journal.version === 3
|
|
100
|
-
? typeof journal.localPolicyKey !== "string" || !/^[0-9a-f]{64}$/u.test(journal.localPolicyKey)
|
|
101
|
-
: journal.localPolicyKey !== undefined) ||
|
|
44
|
+
const version = journal?.version;
|
|
45
|
+
if (journal && (version === 2 || version === 3 || Object.hasOwn(journal, "ignoreSource")))
|
|
46
|
+
throw retiredIgnorePolicy("recovery");
|
|
47
|
+
if (journal?.version !== 1 ||
|
|
102
48
|
typeof journal.identity !== "string" ||
|
|
103
49
|
typeof journal.backup !== "string" ||
|
|
104
50
|
typeof journal.stateIdentity !== "string" ||
|
|
@@ -127,11 +73,6 @@ export async function readMergeJournal(config) {
|
|
|
127
73
|
throw new Error("Unsupported or damaged merge journal; preserve it and review recovery before syncing.");
|
|
128
74
|
// Verify every path and byte, including the unmanaged remote files retained for publication.
|
|
129
75
|
try {
|
|
130
|
-
if (journal.ignoreSource !== undefined) {
|
|
131
|
-
validateJournalPolicy(ignoreRecoveryPolicy(journal));
|
|
132
|
-
if ([journal.expectedHead.selection, journal.committedHead?.selection].some((selection) => selection !== undefined && !sameSnapshotSelection(selection, journal.upload.selection)))
|
|
133
|
-
throw new Error("Inconsistent merge head policy.");
|
|
134
|
-
}
|
|
135
76
|
const pinnedPaths = new Set(journal.progress?.groups.flatMap((group) => group.paths) ?? []);
|
|
136
77
|
for (const snapshot of [
|
|
137
78
|
journal.before,
|
|
@@ -141,10 +82,7 @@ export async function readMergeJournal(config) {
|
|
|
141
82
|
]) {
|
|
142
83
|
validateSnapshotFieldPolicy(snapshot);
|
|
143
84
|
validateSnapshotSelection(snapshot);
|
|
144
|
-
if ((
|
|
145
|
-
? !isIgnoreSnapshotVersion(snapshot.version) ||
|
|
146
|
-
!sameSnapshotSelection(snapshot.selection, journal.upload.selection)
|
|
147
|
-
: ![1, 2, 3, 4, 5].includes(snapshot.version)) ||
|
|
85
|
+
if (![1, 2, 3, 4, 5].includes(snapshot.version) ||
|
|
148
86
|
typeof snapshot.id !== "string" ||
|
|
149
87
|
typeof snapshot.profile !== "string" ||
|
|
150
88
|
snapshot.files.length > 16_384 ||
|
|
@@ -241,12 +179,6 @@ export async function retireMergeJournal(config) {
|
|
|
241
179
|
const journal = await readMergeJournal(config);
|
|
242
180
|
if (!journal)
|
|
243
181
|
return;
|
|
244
|
-
assertMergeJournalPolicy(journal, config);
|
|
245
|
-
const validateIgnore = ignorePolicyValidator(config);
|
|
246
|
-
if (validateIgnore)
|
|
247
|
-
await validateIgnore();
|
|
248
|
-
if (journal.ignoreSource)
|
|
249
|
-
throw new Error(ignoreMergeRecoveryGuidance);
|
|
250
182
|
await archiveMergeJournal(config);
|
|
251
183
|
}
|
|
252
184
|
async function archiveMergeJournal(config) {
|
|
@@ -254,41 +186,6 @@ async function archiveMergeJournal(config) {
|
|
|
254
186
|
await fs.rename(file, `${file}.${randomUUID()}.resolved`);
|
|
255
187
|
await syncDirectory(path.dirname(file));
|
|
256
188
|
}
|
|
257
|
-
export async function reviewInactiveIgnoreMerge(ctx, config, backend, journal, head, options, validateFresh, isCurrent) {
|
|
258
|
-
if (!isCurrent ||
|
|
259
|
-
options.auto ||
|
|
260
|
-
options.background ||
|
|
261
|
-
options.agentAcceptance ||
|
|
262
|
-
options.yes ||
|
|
263
|
-
!ctx.hasUI ||
|
|
264
|
-
(ctx.mode !== "tui" && ctx.mode !== "rpc")) {
|
|
265
|
-
throw new Error(ignoreMergeRecoveryGuidance);
|
|
266
|
-
}
|
|
267
|
-
await validateFresh();
|
|
268
|
-
if (!(await confirmMergeReview(ctx, "Archive the inactive merge journal?", [
|
|
269
|
-
`Setup: ${safeTerminalText(config.setupName)}`,
|
|
270
|
-
"The original remote head and accepted baseline still match the journal, but local files changed.",
|
|
271
|
-
"Archive only the journal. Keep its backup and all current local and remote files. Do not change the baseline.",
|
|
272
|
-
"Run Sync now again to review a fresh plan.",
|
|
273
|
-
].join("\n"), options.signal, isCurrent, "archive journal only")))
|
|
274
|
-
return "cancelled";
|
|
275
|
-
const state = await readStateForConfig(config);
|
|
276
|
-
await validateFresh();
|
|
277
|
-
const latest = await backend.readHead(options.signal);
|
|
278
|
-
if (!isCurrent())
|
|
279
|
-
return "cancelled";
|
|
280
|
-
await validateFresh();
|
|
281
|
-
if (!sameMergeRecoveryHead(backend, head, latest) ||
|
|
282
|
-
syncStateFingerprint(state) !== journal.stateIdentity ||
|
|
283
|
-
syncStateFingerprint(await readStateForConfig(config)) !== journal.stateIdentity) {
|
|
284
|
-
throw new Error("Remote head or sync baseline changed during recovery review; journal and backup retained.");
|
|
285
|
-
}
|
|
286
|
-
await validateFresh();
|
|
287
|
-
await archiveMergeJournal(config);
|
|
288
|
-
if (!options.silent && isCurrent())
|
|
289
|
-
ctx.ui.notify("Archived the inactive merge journal. Local files, remote files, baseline and backup were kept. Run Sync now again for a fresh plan.", "info");
|
|
290
|
-
return "archived";
|
|
291
|
-
}
|
|
292
189
|
export function sameMergeRecoveryHead(backend, left, right) {
|
|
293
190
|
if (!left || !right)
|
|
294
191
|
return left === right;
|
|
@@ -297,17 +194,10 @@ export function sameMergeRecoveryHead(backend, left, right) {
|
|
|
297
194
|
left.snapshotRef === right.snapshotRef &&
|
|
298
195
|
sameSnapshotSelection(left.selection, right.selection));
|
|
299
196
|
}
|
|
300
|
-
const ignoreMergeRecoveryGuidance = "An ignore-file merged transfer needs recovery; directional --force cannot bypass it. Inactive journal archiving requires foreground review where supported; --yes does not approve it. Preserve the journal, backup and current files if recovery is unavailable. Do not downgrade or restore old bytes blindly.";
|
|
301
197
|
export async function requireNoMergeJournal(config, options = {}) {
|
|
302
198
|
const journal = await readMergeJournal(config);
|
|
303
199
|
if (!journal)
|
|
304
200
|
return;
|
|
305
|
-
assertMergeJournalPolicy(journal, config);
|
|
306
|
-
const validateIgnore = ignorePolicyValidator(config);
|
|
307
|
-
if (validateIgnore)
|
|
308
|
-
await validateIgnore();
|
|
309
|
-
if (journal.ignoreSource)
|
|
310
|
-
throw new Error(ignoreMergeRecoveryGuidance);
|
|
311
201
|
if (!options.force) {
|
|
312
202
|
throw new Error("A merged transfer needs recovery. Run /sync sync to reconcile it. If newer local edits or remote revisions prevent recovery, review /sync diff and explicitly choose push --force or pull --force; the selected directional result will archive the old journal, not restore old bytes. Keep its backup; do not downgrade while recovery is pending.");
|
|
313
203
|
}
|