@narumitw/pi-sync 0.67.3 → 0.68.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 +13 -0
- package/README.md +26 -48
- 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-HLJIRWFL.ts → chunk-BCDBT4X3.ts} +7 -7
- package/dist/chunks/{chunk-AVTW6WNP.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-X344HTVV.ts → chunk-WCGLU526.ts} +39 -118
- package/dist/chunks/chunk-WCGLU526.ts.map +7 -0
- package/dist/chunks/{chunk-CQ4DMLH3.ts → chunk-WQXUZSY5.ts} +25 -83
- package/dist/chunks/chunk-WQXUZSY5.ts.map +7 -0
- package/dist/chunks/{chunk-JREGWM2B.ts → chunk-XNUARYLR.ts} +1 -2
- package/dist/chunks/{command-handler-WF2TDDRZ.ts → command-handler-5LDTCUJE.ts} +64 -59
- package/dist/chunks/command-handler-5LDTCUJE.ts.map +7 -0
- package/dist/chunks/{conflict-review-GWEL4S6C.ts → conflict-review-SZ3AWTX6.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-BXN46NRC.ts → manager-result-dispatcher-A4IWLS4J.ts} +7 -7
- package/dist/chunks/{manager-ui-FS4QIKRA.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-DOYKUMER.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-PI45SF2C.ts → setup-wizard-2NRPR433.ts} +11 -16
- package/dist/chunks/{setup-wizard-PI45SF2C.ts.map → setup-wizard-2NRPR433.ts.map} +1 -1
- package/dist/chunks/{sync-inspection-DI5J6EUH.ts → sync-inspection-OTI4JDQ2.ts} +5 -5
- package/dist/chunks/{sync-operations-AGNL7QXA.ts → sync-operations-ZUYJLWUN.ts} +2 -2
- package/dist/daemon/dist/build-id.json +1 -1
- package/dist/daemon/dist/cli.js +22 -3
- package/dist/daemon/dist/client-transport.js +2 -0
- package/dist/daemon/dist/client.js +2 -10
- package/dist/daemon/dist/consent.js +13 -135
- 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 +12 -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 +25 -118
- package/dist/daemon/dist/engine/sync/sync-policy.js +26 -150
- package/dist/daemon/dist/engine/sync/sync-queries.js +81 -65
- 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/ui/sync-format.js +1 -1
- package/dist/daemon/dist/engine-service.js +60 -219
- package/dist/daemon/dist/foreground-queue-outcome.js +0 -4
- package/dist/daemon/dist/legacy-consent-guard.js +34 -0
- package/dist/daemon/dist/server.js +4 -8
- package/dist/daemon/dist/service-host.js +4 -10
- package/dist/daemon/package.json +1 -1
- package/dist/index.ts +45 -46
- package/dist/index.ts.map +3 -3
- package/docs/continuous-sync-verification.md +1 -1
- package/docs/daemon-migration.md +7 -5
- package/docs/tui-contract.md +4 -6
- package/package.json +2 -3
- package/skills/configure-pi-sync/SKILL.md +18 -77
- package/skills/configure-pi-sync/references/configuration.md +60 -77
- package/src/commands/command-execution.ts +13 -29
- package/src/commands/command-handler.ts +0 -4
- package/src/commands/command.ts +2 -1
- package/src/daemon/directional-recovery.ts +4 -33
- package/src/daemon/pi-client.ts +28 -90
- package/src/settings/config.ts +0 -1
- package/src/sync/setup-switch.ts +1 -4
- package/src/sync-extension.ts +10 -24
- 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-33EDXDLC.ts +0 -106
- package/dist/chunks/chunk-33EDXDLC.ts.map +0 -7
- package/dist/chunks/chunk-AVTW6WNP.ts.map +0 -7
- package/dist/chunks/chunk-CQ4DMLH3.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-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-WFBHWYI6.ts +0 -18
- package/dist/chunks/chunk-WFBHWYI6.ts.map +0 -7
- package/dist/chunks/chunk-X344HTVV.ts.map +0 -7
- package/dist/chunks/command-handler-WF2TDDRZ.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-BEZZZIEE.ts +0 -21
- package/dist/chunks/manager-ui-FS4QIKRA.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-DOYKUMER.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-HLJIRWFL.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-GWEL4S6C.ts.map → conflict-review-SZ3AWTX6.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-BEZZZIEE.ts.map → remote-selection-ui-F6NJBQ3Y.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-BXN46NRC.ts.map → setup-switch-7LMIRMZ7.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-DI5J6EUH.ts.map → sync-inspection-OTI4JDQ2.ts.map} +0 -0
- /package/dist/chunks/{sync-operations-AGNL7QXA.ts.map → sync-operations-ZUYJLWUN.ts.map} +0 -0
|
@@ -1,416 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { lstatSync, renameSync, statSync } from "node:fs";
|
|
3
|
-
import fs from "node:fs/promises";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { getEngineRoot, withEngineMutationQueue } from "../host.js";
|
|
6
|
-
import { adoptionJournalFingerprint, assertCurrentAdoptionJournal, completeAdoptionJournal, createAdoptionJournal, recordInstalledIdentity, verifyAdoptionBackup, } from "../ignore/adoption-journal.js";
|
|
7
|
-
import { DEFAULT_IGNORE_FILENAME, ignoreFileIdentity, ignorePolicyFingerprint, ignoreSourceDigest, readIgnoreSource, sameFile, } from "../ignore/ignore-source.js";
|
|
8
|
-
import { validateSnapshotIgnoreRules } from "../ignore/snapshot-ignore-rules.js";
|
|
9
|
-
import { loadConfigForCheck, syncConfigReviewFingerprint, syncSettingsConfigFingerprint } from "../settings/config.js";
|
|
10
|
-
import { readActiveLocalConfigDocumentForRepair, withLockedLocalConfigDocument } from "../settings/config-file.js";
|
|
11
|
-
import { validateSettingsDocument } from "../settings/settings-validation.js";
|
|
12
|
-
import { effectiveSessionRoot, requireStableMergeSessionRoot } from "../snapshot/session-paths.js";
|
|
13
|
-
import { createSnapshot, filterSnapshotForConfigPolicy, regenerateSnapshotIdentity } from "../snapshot/snapshot.js";
|
|
14
|
-
import { appliedFileHashMap, applySnapshot } from "../snapshot/snapshot-apply.js";
|
|
15
|
-
import { recoverPendingSnapshotTransactions } from "../snapshot/snapshot-transaction.js";
|
|
16
|
-
import { pendingTransactionEntries } from "../snapshot/snapshot-transaction-directory.js";
|
|
17
|
-
import { syncDirectory } from "../state/json-file.js";
|
|
18
|
-
import { readStateForConfig, syncStateFingerprint, writeStateForConfig } from "../state/sync-state-store.js";
|
|
19
|
-
import { formatRuleChanges } from "../ui/ignore-rule-preview.js";
|
|
20
|
-
import { formatPullSummary, formatTransferReview } from "../ui/sync-format.js";
|
|
21
|
-
import { snapshotPathLabel } from "../ui/terminal-text.js";
|
|
22
|
-
import { confirmTransferReview } from "../ui/transfer-review.js";
|
|
23
|
-
import { inspectCaseCleanup, revalidateCaseCleanup } from "./apply-review.js";
|
|
24
|
-
import { checkpointDirectionalAction, localRestoreGuidance, notifyDirectionalSuccess } from "./directional-action.js";
|
|
25
|
-
import { overlayLocalFields, portableSnapshot, sameLocalFields } from "./local-fields.js";
|
|
26
|
-
import { readMergeJournal } from "./merge-journal.js";
|
|
27
|
-
import { readSnapshotForHead, sameRemoteHead } from "./remote-snapshot.js";
|
|
28
|
-
import { backupDirectionalSnapshot, captureMutationOwner, maybeReload, protectedSessionPaths } from "./sync-local.js";
|
|
29
|
-
import { acceptedSelection, fileHashMap, rawSnapshotHashIdentity, sameHashes } from "./sync-state.js";
|
|
30
|
-
import { checkLiveProtection } from "./transfer-freshness.js";
|
|
31
|
-
import { requireTransferSize, selectedPullImage, transferSizeLimitsEnabled } from "./transfer-size-limits.js";
|
|
32
|
-
export function canReviewAdoption(ctx, options) {
|
|
33
|
-
return (ctx.hasUI &&
|
|
34
|
-
(ctx.mode === "tui" || ctx.mode === "rpc") &&
|
|
35
|
-
!options.auto &&
|
|
36
|
-
!options.background &&
|
|
37
|
-
!options.yes &&
|
|
38
|
-
!options.agentRetryRefusal);
|
|
39
|
-
}
|
|
40
|
-
export function adoptionSettingsFingerprint(config) {
|
|
41
|
-
return syncConfigReviewFingerprint({ ...config, ignorePolicy: undefined, ignoreSourceIdentity: undefined });
|
|
42
|
-
}
|
|
43
|
-
function scopeChangeReview(label, paths) {
|
|
44
|
-
if (!paths.length)
|
|
45
|
-
return { lines: [], content: "" };
|
|
46
|
-
return {
|
|
47
|
-
lines: [`${label}: ${paths.length} file(s). View details for paths.`],
|
|
48
|
-
content: paths.map((name) => `${label}: ${snapshotPathLabel(name)}`).join("\n"),
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
async function assertDedicatedSource(config, filename) {
|
|
52
|
-
const doc = await readActiveLocalConfigDocumentForRepair();
|
|
53
|
-
if (!doc)
|
|
54
|
-
throw new Error("Sync setup no longer exists; reopen Pull.");
|
|
55
|
-
const settings = validateSettingsDocument(doc.parsed);
|
|
56
|
-
if (Object.entries(settings.syncSetups).some(([name, setup]) => name !== config.setupName &&
|
|
57
|
-
setup.sync.pathPolicy === "ignore-file" &&
|
|
58
|
-
(setup.sync.ignoreFile ?? DEFAULT_IGNORE_FILENAME).toLowerCase() === filename.toLowerCase()))
|
|
59
|
-
throw new Error("The ignore file is shared by other setups. Select a dedicated rule file before Pull.");
|
|
60
|
-
return doc;
|
|
61
|
-
}
|
|
62
|
-
function assertNotLiveRuleTarget(ctx, target, identity) {
|
|
63
|
-
const live = [...(ctx.protectedSessionFiles ?? []), ctx.sessionManager.getSessionFile?.()];
|
|
64
|
-
for (const entry of live) {
|
|
65
|
-
if (!entry)
|
|
66
|
-
continue;
|
|
67
|
-
const stat = statSync(entry, { bigint: true, throwIfNoEntry: false });
|
|
68
|
-
if (path.resolve(entry) === target || (stat && ignoreFileIdentity(stat) === identity))
|
|
69
|
-
throw new Error("The rule file is a protected live session; Pull cannot replace it.");
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
export async function adoptRemoteRules(input) {
|
|
73
|
-
const { ctx, options, config, state, backend, head, remote, snapshotOptions, validateMutation } = input;
|
|
74
|
-
const signal = options.signal;
|
|
75
|
-
const validateCommittedOwner = captureMutationOwner(ctx);
|
|
76
|
-
if (!canReviewAdoption(ctx, options) || !config.ignorePolicy)
|
|
77
|
-
throw new Error("Rule adoption requires a reviewed foreground Pull.");
|
|
78
|
-
const remotePolicy = validateSnapshotIgnoreRules(remote);
|
|
79
|
-
if (!remotePolicy || !remote.ignoreRules) {
|
|
80
|
-
throw new Error(remote.ignoreRules === null
|
|
81
|
-
? "Remote rules exclude their own file. Match the publisher's rules manually before Pull."
|
|
82
|
-
: "Remote snapshot does not contain rule text. Match the publisher's rules or publish a new snapshot first.");
|
|
83
|
-
}
|
|
84
|
-
const { text } = remote.ignoreRules;
|
|
85
|
-
const { filename, sessions, reservedNames } = config.ignorePolicy;
|
|
86
|
-
if (sessions !== remotePolicy.sessions)
|
|
87
|
-
throw new Error("Sessions opt-in differs. Review your local Sessions setting and reopen Pull.");
|
|
88
|
-
if (remotePolicy.matches(filename))
|
|
89
|
-
throw new Error("The remote rules exclude this setup's rule filename. Review a matching rule filename before Pull.");
|
|
90
|
-
if (!sameLocalFields(config.localFields, remote.localFields))
|
|
91
|
-
throw new Error("Machine-local field policy differs. Match that policy before adopting remote ignore rules.");
|
|
92
|
-
const root = getEngineRoot();
|
|
93
|
-
const target = path.join(root, filename);
|
|
94
|
-
const source = await readIgnoreSource(root, filename, signal);
|
|
95
|
-
if (!source.present ||
|
|
96
|
-
source.identity !== config.ignoreSourceIdentity ||
|
|
97
|
-
source.sourceDigest !== config.ignorePolicy.sourceDigest)
|
|
98
|
-
throw new Error("Local ignore source changed; reopen Pull.");
|
|
99
|
-
const doc = await assertDedicatedSource(config, filename);
|
|
100
|
-
validateMutation();
|
|
101
|
-
assertNotLiveRuleTarget(ctx, target, source.identity);
|
|
102
|
-
if (state.unresolved?.length || (await readMergeJournal(config)))
|
|
103
|
-
throw new Error("Resolve or recover pending merge work before adopting rules.");
|
|
104
|
-
const adoptedPolicy = {
|
|
105
|
-
...remotePolicy,
|
|
106
|
-
filename,
|
|
107
|
-
reservedNames,
|
|
108
|
-
sourceDigest: ignoreSourceDigest(filename, true, Buffer.from(text)),
|
|
109
|
-
};
|
|
110
|
-
const setupFingerprint = adoptionSettingsFingerprint(config);
|
|
111
|
-
const settingsFreshness = syncSettingsConfigFingerprint(config);
|
|
112
|
-
const stateFingerprint = syncStateFingerprint(state);
|
|
113
|
-
const sessionDir = snapshotOptions.sessionDir;
|
|
114
|
-
const protectedPaths = protectedSessionPaths(ctx, sessionDir);
|
|
115
|
-
const remoteFilesIdentity = rawSnapshotHashIdentity(remote);
|
|
116
|
-
const resuming = input.journal !== undefined;
|
|
117
|
-
let current = input.journal;
|
|
118
|
-
if (current &&
|
|
119
|
-
(current.setupName !== config.setupName ||
|
|
120
|
-
current.setupFingerprint !== setupFingerprint ||
|
|
121
|
-
current.filename !== filename ||
|
|
122
|
-
current.afterRules !== text ||
|
|
123
|
-
current.remoteFilesIdentity !== remoteFilesIdentity ||
|
|
124
|
-
current.sessionDir !== sessionDir ||
|
|
125
|
-
!sameRemoteHead(backend, current.head, head) ||
|
|
126
|
-
(source.text === text
|
|
127
|
-
? current.installedIdentity !== source.identity
|
|
128
|
-
: current.beforeRules !== source.text || current.sourceIdentity !== source.identity)))
|
|
129
|
-
throw new Error("Pending rule adoption no longer matches this setup, source, or remote. Preserve its journal.");
|
|
130
|
-
if (!current && (await pendingTransactionEntries()).length)
|
|
131
|
-
throw new Error("Recover the pending file transaction before adopting rules.");
|
|
132
|
-
const policyConfig = { ...config, ignorePolicy: adoptedPolicy };
|
|
133
|
-
const validateSource = async () => {
|
|
134
|
-
validateMutation();
|
|
135
|
-
const latest = await loadConfigForCheck(config.setupName, signal);
|
|
136
|
-
validateMutation();
|
|
137
|
-
if (getEngineRoot() !== root ||
|
|
138
|
-
latest.configDocumentFingerprint !== config.configDocumentFingerprint ||
|
|
139
|
-
syncSettingsConfigFingerprint(latest) !== settingsFreshness ||
|
|
140
|
-
latest.ignoreSourceIdentity !== source.identity ||
|
|
141
|
-
latest.ignorePolicy?.sourceDigest !== source.sourceDigest)
|
|
142
|
-
throw new Error("Local rules or settings changed during Pull; reopen the review.");
|
|
143
|
-
assertNotLiveRuleTarget(ctx, target, source.identity);
|
|
144
|
-
checkLiveProtection(ctx, sessionDir, protectedPaths);
|
|
145
|
-
};
|
|
146
|
-
const projected = {
|
|
147
|
-
...snapshotOptions,
|
|
148
|
-
ignorePolicy: adoptedPolicy,
|
|
149
|
-
ignoreSourceIdentity: current?.sourceIdentity ?? source.identity,
|
|
150
|
-
validateMutation,
|
|
151
|
-
validateIgnorePolicy: validateSource,
|
|
152
|
-
};
|
|
153
|
-
const logical = portableSnapshot(filterSnapshotForConfigPolicy(remote, policyConfig, projected), config.localFields);
|
|
154
|
-
let before = await createSnapshot(config.snapshotIdentity, projected);
|
|
155
|
-
let physical = overlayLocalFields(logical, before, config.localFields);
|
|
156
|
-
const prior = current ? undefined : await createSnapshot(config.snapshotIdentity, snapshotOptions);
|
|
157
|
-
const beforePaths = new Set(before.files.map((file) => file.path));
|
|
158
|
-
const priorPaths = new Set(prior?.files.map((file) => file.path));
|
|
159
|
-
const left = prior?.files.filter((file) => !beforePaths.has(file.path)).map((file) => file.path) ?? [];
|
|
160
|
-
const incomingPaths = new Set(physical.files.map((file) => file.path));
|
|
161
|
-
const newlyRemoved = before.files
|
|
162
|
-
.filter((file) => !priorPaths.has(file.path) && !protectedPaths.has(file.path) && !incomingPaths.has(file.path))
|
|
163
|
-
.map((file) => file.path);
|
|
164
|
-
const caseCleanup = current ? [] : await inspectCaseCleanup(physical, projected);
|
|
165
|
-
requireStableMergeSessionRoot(before, physical, config.scope);
|
|
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();
|
|
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
|
|
174
|
-
? ["Resume from the recorded snapshot, not the current remote head. Local evidence must still match."]
|
|
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);
|
|
176
|
-
if (!approved)
|
|
177
|
-
return "cancelled";
|
|
178
|
-
await checkpointDirectionalAction(options, {
|
|
179
|
-
direction: "pull",
|
|
180
|
-
config,
|
|
181
|
-
state,
|
|
182
|
-
local: before,
|
|
183
|
-
remote,
|
|
184
|
-
head,
|
|
185
|
-
sessionDir,
|
|
186
|
-
protectedPaths,
|
|
187
|
-
});
|
|
188
|
-
validateMutation();
|
|
189
|
-
const validateHead = async () => {
|
|
190
|
-
if (resuming)
|
|
191
|
-
return;
|
|
192
|
-
const latestHead = await backend.readHead(signal);
|
|
193
|
-
validateMutation();
|
|
194
|
-
if (!sameRemoteHead(backend, head, latestHead))
|
|
195
|
-
throw new Error("Remote changed during Pull; reopen the review.");
|
|
196
|
-
};
|
|
197
|
-
const validateContext = async () => {
|
|
198
|
-
await validateHead();
|
|
199
|
-
if ((await effectiveSessionRoot(ctx, config, signal)) !== sessionDir)
|
|
200
|
-
throw new Error("Session storage changed; reopen Pull.");
|
|
201
|
-
await validateSource();
|
|
202
|
-
};
|
|
203
|
-
const latest = await readSnapshotForHead(backend, head, signal, config);
|
|
204
|
-
if (latest.version !== remote.version ||
|
|
205
|
-
latest.ignoreRules?.text !== text ||
|
|
206
|
-
latest.ignoreRules.filename !== remote.ignoreRules.filename ||
|
|
207
|
-
!sameLocalFields(latest.localFields, remote.localFields) ||
|
|
208
|
-
rawSnapshotHashIdentity(latest) !== remoteFilesIdentity)
|
|
209
|
-
throw new Error("The reviewed remote snapshot changed; reopen Pull.");
|
|
210
|
-
if (current) {
|
|
211
|
-
await verifyAdoptionBackup(current, signal);
|
|
212
|
-
await assertCurrentAdoptionJournal(current);
|
|
213
|
-
}
|
|
214
|
-
await validateContext();
|
|
215
|
-
const refresh = async () => {
|
|
216
|
-
const next = await createSnapshot(config.snapshotIdentity, projected);
|
|
217
|
-
await validateSource();
|
|
218
|
-
return next;
|
|
219
|
-
};
|
|
220
|
-
let commitStarted = false;
|
|
221
|
-
const markCommit = () => {
|
|
222
|
-
if (!commitStarted)
|
|
223
|
-
options.onCommit?.();
|
|
224
|
-
commitStarted = true;
|
|
225
|
-
};
|
|
226
|
-
if (current && (await pendingTransactionEntries()).length) {
|
|
227
|
-
if (source.text === text || current.stateFingerprint !== stateFingerprint)
|
|
228
|
-
throw new Error("Pending local files and rule adoption cannot be reconciled; preserve both journals.");
|
|
229
|
-
markCommit();
|
|
230
|
-
await recoverPendingSnapshotTransactions({ ...projected, protectedTargets: liveSessionFiles(ctx) });
|
|
231
|
-
before = await refresh();
|
|
232
|
-
physical = overlayLocalFields(logical, before, config.localFields);
|
|
233
|
-
}
|
|
234
|
-
if (!current) {
|
|
235
|
-
await revalidateCaseCleanup(caseCleanup, physical, projected);
|
|
236
|
-
if (!sameHashes(fileHashMap(await refresh()), fileHashMap(before)))
|
|
237
|
-
throw new Error("Local files changed; reopen Pull.");
|
|
238
|
-
const backup = await backupDirectionalSnapshot(regenerateSnapshotIdentity(before), signal);
|
|
239
|
-
await validateContext();
|
|
240
|
-
if (syncStateFingerprint(await readStateForConfig(config)) !== stateFingerprint)
|
|
241
|
-
throw new Error("Baseline changed; reopen Pull.");
|
|
242
|
-
await backup.validate();
|
|
243
|
-
await validateSource();
|
|
244
|
-
current = {
|
|
245
|
-
version: 1,
|
|
246
|
-
setupName: config.setupName,
|
|
247
|
-
setupFingerprint,
|
|
248
|
-
stateFingerprint,
|
|
249
|
-
filename,
|
|
250
|
-
sourceIdentity: source.identity,
|
|
251
|
-
beforeRules: source.text,
|
|
252
|
-
afterRules: text,
|
|
253
|
-
beforeFiles: fileHashMap(before),
|
|
254
|
-
afterFiles: appliedFileHashMap(physical, before, protectedPaths),
|
|
255
|
-
head,
|
|
256
|
-
remoteFilesIdentity,
|
|
257
|
-
sessionDir,
|
|
258
|
-
backupId: path.basename(backup.backupPath, ".json.gz"),
|
|
259
|
-
backupDigest: backup.digest,
|
|
260
|
-
};
|
|
261
|
-
markCommit();
|
|
262
|
-
await createAdoptionJournal(current);
|
|
263
|
-
}
|
|
264
|
-
let journal = current;
|
|
265
|
-
const installedHashes = journal.afterFiles;
|
|
266
|
-
const stateFor = (acceptedConfig) => ({
|
|
267
|
-
version: 1,
|
|
268
|
-
profile: config.snapshotIdentity,
|
|
269
|
-
lastAppliedSnapshot: head.snapshotId,
|
|
270
|
-
lastRemoteRevision: head.revision,
|
|
271
|
-
lastFileHashes: config.localFields?.length
|
|
272
|
-
? { ...installedHashes, "settings.json": fileHashMap(logical)["settings.json"] }
|
|
273
|
-
: installedHashes,
|
|
274
|
-
...acceptedSelection(acceptedConfig),
|
|
275
|
-
...(config.localFields !== undefined ? { localFields: config.localFields } : {}),
|
|
276
|
-
});
|
|
277
|
-
const hashes = fileHashMap(await refresh());
|
|
278
|
-
if (resuming && source.identity !== journal.installedIdentity)
|
|
279
|
-
checkSize();
|
|
280
|
-
if (source.text !== text && journal.stateFingerprint !== stateFingerprint)
|
|
281
|
-
throw new Error("Baseline changed after the reviewed Pull. Preserve its journal.");
|
|
282
|
-
if (!sameHashes(hashes, journal.afterFiles)) {
|
|
283
|
-
if (source.text === text ||
|
|
284
|
-
!sameHashes(hashes, journal.beforeFiles) ||
|
|
285
|
-
!sameHashes(appliedFileHashMap(physical, before, protectedPaths), journal.afterFiles))
|
|
286
|
-
throw new Error("Local files changed after the reviewed Pull. Preserve its journal.");
|
|
287
|
-
markCommit();
|
|
288
|
-
if (!journal.installedIdentity)
|
|
289
|
-
options.directionalAction?.setAdoptionResume?.(adoptionJournalFingerprint(journal));
|
|
290
|
-
await applySnapshot(physical, protectedPaths, {
|
|
291
|
-
...projected,
|
|
292
|
-
reviewedLocal: before,
|
|
293
|
-
validateApplyReview: async () => {
|
|
294
|
-
await validateContext();
|
|
295
|
-
await assertCurrentAdoptionJournal(journal);
|
|
296
|
-
if (syncStateFingerprint(await readStateForConfig(config)) !== journal.stateFingerprint)
|
|
297
|
-
throw new Error("Baseline changed at Pull's commit boundary.");
|
|
298
|
-
},
|
|
299
|
-
});
|
|
300
|
-
options.directionalAction?.setAdoptionResume?.(undefined);
|
|
301
|
-
}
|
|
302
|
-
await validateContext();
|
|
303
|
-
if (!sameHashes(fileHashMap(await refresh()), journal.afterFiles))
|
|
304
|
-
throw new Error("Installed files changed before rule adoption completed; preserve the journal.");
|
|
305
|
-
markCommit();
|
|
306
|
-
if (source.text !== text) {
|
|
307
|
-
await withEngineMutationQueue(target, async () => {
|
|
308
|
-
await validateContext();
|
|
309
|
-
if (!sameHashes(fileHashMap(await refresh()), installedHashes))
|
|
310
|
-
throw new Error("Local files changed while reserving the rule file; preserve the journal.");
|
|
311
|
-
await withLockedLocalConfigDocument(async (latest, recheck) => {
|
|
312
|
-
if (!latest?.bytes.equals(doc.bytes) || JSON.stringify(latest.identity) !== JSON.stringify(doc.identity))
|
|
313
|
-
throw new Error("Sync settings changed; preserve the journal.");
|
|
314
|
-
await installRuleFile(ctx, root, target, source.identity, source.sourceDigest, filename, text, signal, async (identity) => {
|
|
315
|
-
journal = await recordInstalledIdentity(journal, identity);
|
|
316
|
-
await validateHead();
|
|
317
|
-
}, () => {
|
|
318
|
-
recheck();
|
|
319
|
-
validateMutation();
|
|
320
|
-
checkLiveProtection(ctx, sessionDir, protectedPaths);
|
|
321
|
-
});
|
|
322
|
-
}, signal, true);
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
else {
|
|
326
|
-
await syncDirectory(root);
|
|
327
|
-
validateCommittedOwner();
|
|
328
|
-
}
|
|
329
|
-
const installed = await loadConfigForCheck(config.setupName);
|
|
330
|
-
if (installed.configDocumentFingerprint !== config.configDocumentFingerprint ||
|
|
331
|
-
adoptionSettingsFingerprint(installed) !== setupFingerprint ||
|
|
332
|
-
installed.ignorePolicy?.fingerprint !== ignorePolicyFingerprint(text, sessions) ||
|
|
333
|
-
installed.ignorePolicy?.sourceDigest !== adoptedPolicy.sourceDigest ||
|
|
334
|
-
installed.ignoreSourceIdentity !== journal.installedIdentity)
|
|
335
|
-
throw new Error("Cannot verify the installed rule file. Preserve the adoption journal.");
|
|
336
|
-
const finalState = stateFor(installed);
|
|
337
|
-
const latestFingerprint = syncStateFingerprint(await readStateForConfig(installed));
|
|
338
|
-
const validateFinal = () => {
|
|
339
|
-
validateCommittedOwner();
|
|
340
|
-
checkLiveProtection(ctx, sessionDir, protectedPaths);
|
|
341
|
-
};
|
|
342
|
-
validateFinal();
|
|
343
|
-
const installedFiles = await createSnapshot(config.snapshotIdentity, {
|
|
344
|
-
...projected,
|
|
345
|
-
ignorePolicy: installed.ignorePolicy,
|
|
346
|
-
ignoreSourceIdentity: installed.ignoreSourceIdentity,
|
|
347
|
-
validateMutation: validateFinal,
|
|
348
|
-
validateIgnorePolicy: installed.validateIgnorePolicy,
|
|
349
|
-
});
|
|
350
|
-
if (!sameHashes(fileHashMap(installedFiles), installedHashes))
|
|
351
|
-
throw new Error("Local files changed during adoption. Preserve the journal.");
|
|
352
|
-
await installed.validateIgnorePolicy?.();
|
|
353
|
-
validateFinal();
|
|
354
|
-
if (latestFingerprint === journal.stateFingerprint)
|
|
355
|
-
await writeStateForConfig(installed, finalState, logical, validateFinal);
|
|
356
|
-
else if (latestFingerprint !== syncStateFingerprint(finalState))
|
|
357
|
-
throw new Error("Baseline changed during installation; preserve the adoption journal.");
|
|
358
|
-
validateFinal();
|
|
359
|
-
const archive = await completeAdoptionJournal(journal);
|
|
360
|
-
validateFinal();
|
|
361
|
-
if (!signal?.aborted) {
|
|
362
|
-
notifyDirectionalSuccess(ctx, options, [
|
|
363
|
-
`Adopted remote rules and pulled snapshot ${snapshotPathLabel(head.snapshotId)}.`,
|
|
364
|
-
localRestoreGuidance(path.join(path.dirname(archive), `${journal.backupId}.json.gz`)),
|
|
365
|
-
`Previous rule text: ${snapshotPathLabel(archive)}.`,
|
|
366
|
-
].join("\n"));
|
|
367
|
-
if (!options.directionalAction && options.reload)
|
|
368
|
-
await maybeReload(ctx, signal, validateFinal);
|
|
369
|
-
}
|
|
370
|
-
return "applied";
|
|
371
|
-
}
|
|
372
|
-
function liveSessionFiles(ctx) {
|
|
373
|
-
const current = ctx.sessionManager.getSessionFile?.();
|
|
374
|
-
return [...(ctx.protectedSessionFiles ?? []), ...(current ? [current] : [])];
|
|
375
|
-
}
|
|
376
|
-
async function installRuleFile(ctx, root, target, identity, digest, filename, text, signal, recordIdentity, validate) {
|
|
377
|
-
const before = lstatSync(target, { bigint: true });
|
|
378
|
-
const temporary = path.join(root, `.pi-sync.json.${randomUUID()}.ignore-adopt`);
|
|
379
|
-
const handle = await fs.open(temporary, "wx", 0o600);
|
|
380
|
-
let temporaryIdentity;
|
|
381
|
-
try {
|
|
382
|
-
let staged;
|
|
383
|
-
try {
|
|
384
|
-
temporaryIdentity = ignoreFileIdentity(await handle.stat({ bigint: true }));
|
|
385
|
-
await handle.writeFile(text, "utf8");
|
|
386
|
-
if (process.platform !== "win32")
|
|
387
|
-
await handle.chmod(Number(before.mode & 511n));
|
|
388
|
-
await handle.sync();
|
|
389
|
-
staged = await handle.stat({ bigint: true });
|
|
390
|
-
}
|
|
391
|
-
finally {
|
|
392
|
-
await handle.close();
|
|
393
|
-
}
|
|
394
|
-
await recordIdentity(ignoreFileIdentity(staged));
|
|
395
|
-
const current = await readIgnoreSource(root, filename, signal);
|
|
396
|
-
validate();
|
|
397
|
-
signal?.throwIfAborted();
|
|
398
|
-
const after = lstatSync(target, { bigint: true });
|
|
399
|
-
assertNotLiveRuleTarget(ctx, target, identity);
|
|
400
|
-
const stagedNow = lstatSync(temporary, { bigint: true });
|
|
401
|
-
if (!sameFile(staged, stagedNow) ||
|
|
402
|
-
stagedNow.nlink !== 1n ||
|
|
403
|
-
!sameFile(before, after) ||
|
|
404
|
-
!current.present ||
|
|
405
|
-
current.identity !== identity ||
|
|
406
|
-
current.sourceDigest !== digest)
|
|
407
|
-
throw new Error("Local rule file changed; preserve the adoption journal.");
|
|
408
|
-
renameSync(temporary, target);
|
|
409
|
-
await syncDirectory(root);
|
|
410
|
-
}
|
|
411
|
-
finally {
|
|
412
|
-
const remaining = lstatSync(temporary, { bigint: true, throwIfNoEntry: false });
|
|
413
|
-
if (remaining && ignoreFileIdentity(remaining) === temporaryIdentity)
|
|
414
|
-
await fs.rm(temporary, { force: true });
|
|
415
|
-
}
|
|
416
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { getEngineRoot } from "../host.js";
|
|
2
|
-
import { readIgnoreSource } from "../ignore/ignore-source.js";
|
|
3
|
-
import { selectSnapshotIgnoreRules } from "../ignore/snapshot-ignore-rules.js";
|
|
4
|
-
import { regenerateSnapshotIdentity } from "../snapshot/snapshot.js";
|
|
5
|
-
import { RULES_SNAPSHOT_VERSION } from "../snapshot/snapshot-types.js";
|
|
6
|
-
import { safeTerminalText } from "../ui/terminal-text.js";
|
|
7
|
-
export async function withPublishedIgnoreRules(snapshot, config, signal) {
|
|
8
|
-
const policy = config.ignorePolicy;
|
|
9
|
-
if (!policy)
|
|
10
|
-
return snapshot;
|
|
11
|
-
const source = await readIgnoreSource(getEngineRoot(), policy.filename, signal);
|
|
12
|
-
if (!source.present || source.identity !== config.ignoreSourceIdentity)
|
|
13
|
-
throw new Error("Ignore file was replaced before publication; reopen the review.");
|
|
14
|
-
const ignoreRules = selectSnapshotIgnoreRules(source, policy);
|
|
15
|
-
return regenerateSnapshotIdentity({ ...snapshot, version: RULES_SNAPSHOT_VERSION, ignoreRules });
|
|
16
|
-
}
|
|
17
|
-
export function ignorePublicationNotice(snapshot) {
|
|
18
|
-
if (snapshot.ignoreRules === null)
|
|
19
|
-
return "The active rule file excludes itself; this snapshot omits its text.";
|
|
20
|
-
if (!snapshot.ignoreRules)
|
|
21
|
-
return undefined;
|
|
22
|
-
return `This snapshot includes ${safeTerminalText(snapshot.ignoreRules.filename)}. Its rules and comments will be retained in remote history. Peers must support snapshot version ${RULES_SNAPSHOT_VERSION}.`;
|
|
23
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { snapshotPathLabel } from "./terminal-text.js";
|
|
2
|
-
export function formatRuleChanges(before, after) {
|
|
3
|
-
if (before === after) {
|
|
4
|
-
const message = before === undefined ? "Rule text is unavailable on both sides." : "Rule text is unchanged.";
|
|
5
|
-
return { lines: [message], content: message };
|
|
6
|
-
}
|
|
7
|
-
const lines = (text, prefix) => text === undefined
|
|
8
|
-
? [`${prefix} (rule text not in snapshot)`]
|
|
9
|
-
: text.split(/(?<=\n)/u).map((line) => `${prefix} ${snapshotPathLabel(JSON.stringify(line))}`);
|
|
10
|
-
return {
|
|
11
|
-
lines: ["Rule text changes. View details for the exact lines."],
|
|
12
|
-
content: [
|
|
13
|
-
"Rule text (− before, + after; JSON quotes show whitespace):",
|
|
14
|
-
...lines(before, "-"),
|
|
15
|
-
...lines(after, "+"),
|
|
16
|
-
].join("\n"),
|
|
17
|
-
};
|
|
18
|
-
}
|