@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
|
@@ -17,9 +17,9 @@ import { withMissingTargetQueues, withTargetQueues } from "./snapshot-mutation-q
|
|
|
17
17
|
import { sessionStorageRoot } from "./snapshot-paths.js";
|
|
18
18
|
import { prepareSessionRootTransition, resolveTransitionSessionRoot, stableAgentDirectorySettingsImage, } from "./snapshot-root-transition.js";
|
|
19
19
|
import { pendingTransactionEntries, transactionRoot } from "./snapshot-transaction-directory.js";
|
|
20
|
-
import { legacyImage, MAX_TRANSACTION_JOURNAL_BYTES, ownedScopedPostTree, readTransactionJournal,
|
|
20
|
+
import { legacyImage, MAX_TRANSACTION_JOURNAL_BYTES, ownedScopedPostTree, readTransactionJournal, recheckUnchangedFile, removeScopedImage, scopedDescendant, scopedIdentity, scopedPathIdentity, scopedTransactionImage, stableScopedIdentity, verifyUnchangedFile, } from "./snapshot-transaction-images.js";
|
|
21
21
|
import { indexTransactionPlan } from "./snapshot-transaction-plan.js";
|
|
22
|
-
import { AGENT_DIRECTORY_JOURNAL_VERSION, assertAllowedTarget, assertRecoveryPolicy, assertSafeParents,
|
|
22
|
+
import { AGENT_DIRECTORY_JOURNAL_VERSION, assertAllowedTarget, assertRecoveryPolicy, assertSafeParents, isScopedJournal, isStrictlyInside, touchesProtectedTarget, transactionHasSessionTargets, validateJournal, validateJournalPolicy, } from "./snapshot-transaction-policy.js";
|
|
23
23
|
import { assertNoUnclaimedLegacyStage, buildScopedRecoveryStage, cleanScopedLegacyStage, cleanScopedWorkspace, inspectScopedRecoveryStage, prepareLegacyRecoveryStage, recoveryStagePath, } from "./snapshot-transaction-stage.js";
|
|
24
24
|
import { verifyTarget } from "./snapshot-transaction-verification.js";
|
|
25
25
|
const JOURNAL_VERSION = 4;
|
|
@@ -29,10 +29,9 @@ export async function applySnapshotTransaction(plan, options = {}, skipped = [])
|
|
|
29
29
|
options.validateMutation?.();
|
|
30
30
|
const root = path.resolve(agentDir());
|
|
31
31
|
if (options.scope === "agent-directory") {
|
|
32
|
-
const sessionDir = options.sessionDir ?? (await agentDirectoryConfiguredSessionDir(options.signal, root
|
|
32
|
+
const sessionDir = options.sessionDir ?? (await agentDirectoryConfiguredSessionDir(options.signal, root));
|
|
33
33
|
options = { ...options, sessionDir: sessionStorageRoot(root, sessionDir) };
|
|
34
34
|
}
|
|
35
|
-
const validateIgnorePolicy = ignorePolicyValidator(options);
|
|
36
35
|
await recoverPendingSnapshotTransactions(options);
|
|
37
36
|
const coalesced = await coalesceCaseReplacements(root, plan);
|
|
38
37
|
options.validateMutation?.();
|
|
@@ -41,8 +40,6 @@ export async function applySnapshotTransaction(plan, options = {}, skipped = [])
|
|
|
41
40
|
if (targets.length > 16_384)
|
|
42
41
|
throw new Error("Snapshot transaction exceeds its target bound; review a smaller transfer.");
|
|
43
42
|
return withTargetQueues(targets, options, async (heldKeys) => {
|
|
44
|
-
if (validateIgnorePolicy)
|
|
45
|
-
await validateIgnorePolicy();
|
|
46
43
|
await assertUnexcludedTargets(root, [...targets, ...coalesced.replacements.values()], options);
|
|
47
44
|
options.signal?.throwIfAborted();
|
|
48
45
|
if (targets.some((target) => touchesProtectedTarget(target, options.protectedTargets)))
|
|
@@ -94,7 +91,7 @@ export async function applySnapshotTransaction(plan, options = {}, skipped = [])
|
|
|
94
91
|
for (const [target, expected] of expectedPreimages) {
|
|
95
92
|
if (skippedPreimages.get(target) === expected)
|
|
96
93
|
continue;
|
|
97
|
-
if (scoped
|
|
94
|
+
if (scoped)
|
|
98
95
|
await assertUnexcludedTargets(root, [target], options);
|
|
99
96
|
const current = scoped ? (await scopedTransactionImage(target, options)).value : await legacyImage(target);
|
|
100
97
|
options.validateMutation?.();
|
|
@@ -102,8 +99,6 @@ export async function applySnapshotTransaction(plan, options = {}, skipped = [])
|
|
|
102
99
|
if (current !== expected)
|
|
103
100
|
throw new Error("Reviewed file preimage changed before apply; snapshot installation refused.");
|
|
104
101
|
}
|
|
105
|
-
if (validateIgnorePolicy)
|
|
106
|
-
await validateIgnorePolicy();
|
|
107
102
|
const mutationTargets = skipped.length ? targets.filter((target) => !skippedPreimages.has(target)) : targets;
|
|
108
103
|
const writes = skipped.length ? plan.writes.filter(({ target }) => !skippedPreimages.has(target)) : plan.writes;
|
|
109
104
|
if (mutationTargets.length === 0) {
|
|
@@ -116,8 +111,6 @@ export async function applySnapshotTransaction(plan, options = {}, skipped = [])
|
|
|
116
111
|
options.signal?.throwIfAborted();
|
|
117
112
|
assertProjectedAgentDirectoryBudget(inventory, { deletes: [], writes: [{ target: pendingStateEntry }] }, options);
|
|
118
113
|
}
|
|
119
|
-
if (validateIgnorePolicy)
|
|
120
|
-
await validateIgnorePolicy();
|
|
121
114
|
await verifySkippedWrites(root, skipped, heldKeys, options);
|
|
122
115
|
options.validateMutation?.();
|
|
123
116
|
options.signal?.throwIfAborted();
|
|
@@ -151,12 +144,8 @@ export async function applySnapshotTransaction(plan, options = {}, skipped = [])
|
|
|
151
144
|
.flatMap((entry) => [entry.target, ...(entry.afterTarget ? [entry.afterTarget] : [])]), heldKeys, options, async () => {
|
|
152
145
|
if (options.validateApplyReview && transaction.journal.entries.some((entry) => entry.removalPending))
|
|
153
146
|
await options.validateApplyReview();
|
|
154
|
-
if (validateIgnorePolicy)
|
|
155
|
-
await validateIgnorePolicy();
|
|
156
147
|
if (scoped && plan.writes.length)
|
|
157
148
|
await recheckAgentDirectoryBudget(root, { deletes: [], writes: plan.writes }, options);
|
|
158
|
-
if (validateIgnorePolicy)
|
|
159
|
-
await validateIgnorePolicy();
|
|
160
149
|
await retireRemovalIntent(transaction.directory, transaction.journal, transaction.journal.entries.filter((entry) => entry.removalPending && (entry.afterImage !== "missing" || (entry.postFiles?.length ?? 0) > 0)), options);
|
|
161
150
|
// Only this uninterrupted call knows which deleted writes have not attempted installation yet.
|
|
162
151
|
const uninstalledWrites = new Set(transaction.deletedWrites);
|
|
@@ -166,13 +155,11 @@ export async function applySnapshotTransaction(plan, options = {}, skipped = [])
|
|
|
166
155
|
if (!entry)
|
|
167
156
|
throw new Error("Unowned transaction target.");
|
|
168
157
|
const deletedByThisCall = uninstalledWrites.delete(entry.target);
|
|
169
|
-
if (options.scope === "agent-directory"
|
|
158
|
+
if (options.scope === "agent-directory")
|
|
170
159
|
await assertUnexcludedTargets(transaction.journal.root, [item.target], options);
|
|
171
160
|
await verifyTarget(transaction.directory, entry, transaction.journal, options, deletedByThisCall);
|
|
172
161
|
options.validateMutation?.();
|
|
173
162
|
options.signal?.throwIfAborted();
|
|
174
|
-
if (validateIgnorePolicy)
|
|
175
|
-
await validateIgnorePolicy();
|
|
176
163
|
await fs.mkdir(path.dirname(item.target), { recursive: true });
|
|
177
164
|
options.validateMutation?.();
|
|
178
165
|
options.signal?.throwIfAborted();
|
|
@@ -196,18 +183,9 @@ export async function applySnapshotTransaction(plan, options = {}, skipped = [])
|
|
|
196
183
|
finally {
|
|
197
184
|
await handle.close();
|
|
198
185
|
}
|
|
199
|
-
|
|
186
|
+
await verifyTarget(transaction.directory, entry, transaction.journal, options, deletedByThisCall);
|
|
200
187
|
options.signal?.throwIfAborted();
|
|
201
188
|
options.validateMutation?.();
|
|
202
|
-
if (validateIgnorePolicy) {
|
|
203
|
-
await validateIgnorePolicy();
|
|
204
|
-
if (verified.scoped)
|
|
205
|
-
await recheckScopedImage(item.target, verified.scoped, options);
|
|
206
|
-
else {
|
|
207
|
-
await assertUnexcludedTargets(root, [item.target], options);
|
|
208
|
-
await verifyTarget(transaction.directory, entry, transaction.journal, options, deletedByThisCall);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
189
|
options.validateMutation?.();
|
|
212
190
|
options.signal?.throwIfAborted();
|
|
213
191
|
await fs.rename(temp, item.target);
|
|
@@ -222,11 +200,7 @@ export async function applySnapshotTransaction(plan, options = {}, skipped = [])
|
|
|
222
200
|
await syncMutationParents(mutationTargets, [transaction.journal.root, ...(transaction.journal.sessionRoot ? [transaction.journal.sessionRoot] : [])], options);
|
|
223
201
|
options.validateMutation?.();
|
|
224
202
|
options.signal?.throwIfAborted();
|
|
225
|
-
if (validateIgnorePolicy)
|
|
226
|
-
await validateIgnorePolicy();
|
|
227
203
|
});
|
|
228
|
-
if (validateIgnorePolicy)
|
|
229
|
-
await validateIgnorePolicy();
|
|
230
204
|
await verifySkippedWrites(root, skipped, heldKeys, options);
|
|
231
205
|
options.validateMutation?.();
|
|
232
206
|
options.signal?.throwIfAborted();
|
|
@@ -235,7 +209,7 @@ export async function applySnapshotTransaction(plan, options = {}, skipped = [])
|
|
|
235
209
|
// Aborted owners cannot roll back files after another session has replaced them.
|
|
236
210
|
if (options.signal?.aborted)
|
|
237
211
|
throw new Error("Snapshot apply cancelled; guarded transaction evidence retained for review.");
|
|
238
|
-
if (error instanceof ScopedRemovalError
|
|
212
|
+
if (error instanceof ScopedRemovalError)
|
|
239
213
|
throw error;
|
|
240
214
|
// Additional queues have been released. Recovery must reserve missing keys afresh.
|
|
241
215
|
if (changesQueueKey)
|
|
@@ -301,14 +275,13 @@ export async function recoverPendingSnapshotTransactions(options = {}) {
|
|
|
301
275
|
validateJournalPolicy(journal);
|
|
302
276
|
if (!journal.completed) {
|
|
303
277
|
assertRecoveryPolicy(journal, options);
|
|
304
|
-
ignorePolicyValidator(options);
|
|
305
278
|
}
|
|
306
279
|
let sessionDir = options.sessionDir;
|
|
307
280
|
if (sessionDir === undefined && !journal.completed) {
|
|
308
281
|
if (options.scope === "agent-directory")
|
|
309
|
-
sessionDir = await agentDirectoryConfiguredSessionDir(options.signal, agentDir()
|
|
282
|
+
sessionDir = await agentDirectoryConfiguredSessionDir(options.signal, agentDir());
|
|
310
283
|
else if (options.resolveConfiguredSessionDir && transactionHasSessionTargets(journal))
|
|
311
|
-
sessionDir = await configuredSessionDir(
|
|
284
|
+
sessionDir = await configuredSessionDir();
|
|
312
285
|
}
|
|
313
286
|
options.validateMutation?.();
|
|
314
287
|
options.signal?.throwIfAborted();
|
|
@@ -331,8 +304,6 @@ async function prepareTransaction(plan, targets, options, replacements = new Map
|
|
|
331
304
|
const { sessionDir } = options;
|
|
332
305
|
const root = path.resolve(agentDir());
|
|
333
306
|
const wholeDirectory = options.scope === "agent-directory";
|
|
334
|
-
const ignoreSource = options.ignorePolicy ? ignoreSourceBinding(options.ignorePolicy) : undefined;
|
|
335
|
-
const localPolicyKey = recoveryPolicyKey(options);
|
|
336
307
|
const sessionRoot = sessionDir || wholeDirectory ? path.resolve(sessionStorageRoot(root, sessionDir)) : undefined;
|
|
337
308
|
const indexed = indexTransactionPlan(plan, targets);
|
|
338
309
|
const directory = path.join(transactionRoot(), randomUUID());
|
|
@@ -344,7 +315,7 @@ async function prepareTransaction(plan, targets, options, replacements = new Map
|
|
|
344
315
|
options.validateMutation?.();
|
|
345
316
|
assertAllowedTarget(root, sessionRoot, target);
|
|
346
317
|
await assertSafeParents(root, sessionRoot, target);
|
|
347
|
-
if (wholeDirectory
|
|
318
|
+
if (wholeDirectory)
|
|
348
319
|
await assertUnexcludedTargets(root, [target], options);
|
|
349
320
|
const entry = { target, backupName: `${index}`, kind: "missing" };
|
|
350
321
|
if (replacements.has(target))
|
|
@@ -382,22 +353,14 @@ async function prepareTransaction(plan, targets, options, replacements = new Map
|
|
|
382
353
|
? undefined
|
|
383
354
|
: await prepareSessionRootTransition(directory, root, effectiveRoot, entries, plan, options);
|
|
384
355
|
const journal = {
|
|
385
|
-
version:
|
|
386
|
-
?
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
? AGENT_DIRECTORY_JOURNAL_VERSION
|
|
393
|
-
: sessionRootTransition
|
|
394
|
-
? 7
|
|
395
|
-
: replacements.size
|
|
396
|
-
? 5
|
|
397
|
-
: JOURNAL_VERSION,
|
|
356
|
+
version: wholeDirectory
|
|
357
|
+
? AGENT_DIRECTORY_JOURNAL_VERSION
|
|
358
|
+
: sessionRootTransition
|
|
359
|
+
? 7
|
|
360
|
+
: replacements.size
|
|
361
|
+
? 5
|
|
362
|
+
: JOURNAL_VERSION,
|
|
398
363
|
root,
|
|
399
|
-
ignoreSource,
|
|
400
|
-
localPolicyKey,
|
|
401
364
|
...(wholeDirectory
|
|
402
365
|
? { selection: selectionForSnapshot(includeFromSelectionConfig(options), options.exclude, options) }
|
|
403
366
|
: options.exclude === undefined
|
|
@@ -477,13 +440,8 @@ async function restoreTransaction(directory, journal, options, heldKeys) {
|
|
|
477
440
|
async function restoreQueuedTransaction(directory, journal, options, heldKeys) {
|
|
478
441
|
validateJournal(directory, journal, options.sessionDir);
|
|
479
442
|
const scoped = isScopedJournal(journal);
|
|
480
|
-
const validateIgnorePolicy = ignorePolicyValidator(options);
|
|
481
443
|
options.validateMutation?.();
|
|
482
444
|
options.signal?.throwIfAborted();
|
|
483
|
-
if (validateIgnorePolicy) {
|
|
484
|
-
assertRecoveryPolicy(journal, options);
|
|
485
|
-
await validateIgnorePolicy();
|
|
486
|
-
}
|
|
487
445
|
await assertUnexcludedTargets(journal.root, journal.entries.flatMap((entry) => [entry.target, ...(entry.afterTarget ? [entry.afterTarget] : [])]), options);
|
|
488
446
|
for (const entry of journal.entries) {
|
|
489
447
|
if (touchesProtectedTarget(entry.target, options.protectedTargets))
|
|
@@ -533,8 +491,6 @@ async function restoreQueuedTransaction(directory, journal, options, heldKeys) {
|
|
|
533
491
|
const spellingMatches = async () => !entry.afterTarget || (await caseReplacementSpelling(entry.target, entry.afterTarget)) === entry.target;
|
|
534
492
|
if (current === before && (await spellingMatches())) {
|
|
535
493
|
if (entry.recoveryWorkspace) {
|
|
536
|
-
if (validateIgnorePolicy)
|
|
537
|
-
await validateIgnorePolicy();
|
|
538
494
|
await cleanScopedWorkspace(directory, entry, options);
|
|
539
495
|
}
|
|
540
496
|
continue;
|
|
@@ -594,11 +550,6 @@ async function restoreQueuedTransaction(directory, journal, options, heldKeys) {
|
|
|
594
550
|
options.signal?.throwIfAborted();
|
|
595
551
|
if (atInstall === before && (await spellingMatches()))
|
|
596
552
|
return;
|
|
597
|
-
if (validateIgnorePolicy) {
|
|
598
|
-
await validateIgnorePolicy();
|
|
599
|
-
await assertUnexcludedTargets(journal.root, [entry.target], options);
|
|
600
|
-
await verifyTarget(directory, entry, journal, options, atRename === "missing");
|
|
601
|
-
}
|
|
602
553
|
options.validateMutation?.();
|
|
603
554
|
options.signal?.throwIfAborted();
|
|
604
555
|
await fs.rename(temporary, entry.target);
|
|
@@ -648,11 +599,6 @@ async function restoreQueuedTransaction(directory, journal, options, heldKeys) {
|
|
|
648
599
|
options.signal?.throwIfAborted();
|
|
649
600
|
if (atInstall === before)
|
|
650
601
|
return;
|
|
651
|
-
if (validateIgnorePolicy) {
|
|
652
|
-
await validateIgnorePolicy();
|
|
653
|
-
await assertUnexcludedTargets(journal.root, [entry.target], options);
|
|
654
|
-
await verifyTarget(directory, entry, journal, options, atRename === "missing");
|
|
655
|
-
}
|
|
656
602
|
options.validateMutation?.();
|
|
657
603
|
options.signal?.throwIfAborted();
|
|
658
604
|
await fs.rename(temporary, entry.target);
|
|
@@ -666,21 +612,14 @@ async function restoreQueuedTransaction(directory, journal, options, heldKeys) {
|
|
|
666
612
|
await syncMutationParents(journal.entries.map((entry) => entry.target), [journal.root, ...(journal.sessionRoot ? [journal.sessionRoot] : [])], options);
|
|
667
613
|
options.validateMutation?.();
|
|
668
614
|
options.signal?.throwIfAborted();
|
|
669
|
-
if (validateIgnorePolicy)
|
|
670
|
-
await validateIgnorePolicy();
|
|
671
615
|
await completeTransaction(directory, journal);
|
|
672
616
|
}
|
|
673
617
|
async function restoreScopedEntry(directory, journal, entry, options, heldKeys, before, spellingMatches) {
|
|
674
|
-
const validateIgnorePolicy = ignorePolicyValidator(options);
|
|
675
618
|
options.validateMutation?.();
|
|
676
619
|
options.signal?.throwIfAborted();
|
|
677
|
-
if (validateIgnorePolicy)
|
|
678
|
-
await validateIgnorePolicy();
|
|
679
620
|
await fs.mkdir(path.dirname(entry.target), { recursive: true });
|
|
680
621
|
await assertSafeParents(journal.root, journal.sessionRoot, entry.target);
|
|
681
622
|
if (!entry.vacantInstall) {
|
|
682
|
-
if (validateIgnorePolicy)
|
|
683
|
-
await validateIgnorePolicy();
|
|
684
623
|
await buildScopedRecoveryStage(directory, entry, options, () => persistJournal(directory, journal));
|
|
685
624
|
}
|
|
686
625
|
const verifyStage = async () => {
|
|
@@ -705,8 +644,6 @@ async function restoreScopedEntry(directory, journal, entry, options, heldKeys,
|
|
|
705
644
|
}))) {
|
|
706
645
|
const queueTargets = needsVacantTarget ? [entry.target, ...(entry.afterTarget ? [entry.afterTarget] : [])] : [];
|
|
707
646
|
await withMissingTargetQueues(queueTargets, heldKeys, options, async () => {
|
|
708
|
-
if (validateIgnorePolicy)
|
|
709
|
-
await validateIgnorePolicy();
|
|
710
647
|
const { value: atRename } = await verifyTarget(directory, entry, journal, options);
|
|
711
648
|
if (atRename === before && (await spellingMatches()))
|
|
712
649
|
return;
|
|
@@ -714,8 +651,6 @@ async function restoreScopedEntry(directory, journal, entry, options, heldKeys,
|
|
|
714
651
|
throw new Error("Transaction target changed after removal; preserve evidence for review.");
|
|
715
652
|
const stage = await verifyStage();
|
|
716
653
|
if (needsVacantTarget && !entry.vacantInstall) {
|
|
717
|
-
if (validateIgnorePolicy)
|
|
718
|
-
await validateIgnorePolicy();
|
|
719
654
|
entry.vacantInstall = stage.identity;
|
|
720
655
|
delete entry.removalPending;
|
|
721
656
|
delete entry.replacementStarted;
|
|
@@ -741,11 +676,6 @@ async function restoreScopedEntry(directory, journal, entry, options, heldKeys,
|
|
|
741
676
|
throw new Error("Transaction target changed before restoration; preserve evidence for review.");
|
|
742
677
|
options.validateMutation?.();
|
|
743
678
|
options.signal?.throwIfAborted();
|
|
744
|
-
if (validateIgnorePolicy && atInstall.scoped) {
|
|
745
|
-
await validateIgnorePolicy();
|
|
746
|
-
await recheckScopedImage(stage.payload, stage.image, options);
|
|
747
|
-
await recheckScopedImage(entry.target, atInstall.scoped, options);
|
|
748
|
-
}
|
|
749
679
|
await fs.rename(stage.payload, entry.target);
|
|
750
680
|
await syncDirectory(path.dirname(entry.target));
|
|
751
681
|
await syncDirectory(path.dirname(stage.payload));
|
|
@@ -754,16 +684,11 @@ async function restoreScopedEntry(directory, journal, entry, options, heldKeys,
|
|
|
754
684
|
});
|
|
755
685
|
}
|
|
756
686
|
}
|
|
757
|
-
if (validateIgnorePolicy)
|
|
758
|
-
await validateIgnorePolicy();
|
|
759
687
|
await cleanScopedWorkspace(directory, entry, options);
|
|
760
688
|
}
|
|
761
689
|
async function removeOwnedTarget(directory, entry, journal, options, { apply, restoringBefore } = {}) {
|
|
762
690
|
const scoped = isScopedJournal(journal);
|
|
763
|
-
const validateIgnorePolicy = ignorePolicyValidator(options);
|
|
764
691
|
try {
|
|
765
|
-
if (validateIgnorePolicy)
|
|
766
|
-
await validateIgnorePolicy();
|
|
767
692
|
await assertUnexcludedTargets(journal.root, [entry.target, ...(entry.afterTarget ? [entry.afterTarget] : [])], options);
|
|
768
693
|
const current = await verifyTarget(directory, entry, journal, options);
|
|
769
694
|
options.validateMutation?.();
|
|
@@ -818,14 +743,9 @@ async function removeOwnedTarget(directory, entry, journal, options, { apply, re
|
|
|
818
743
|
if (current.value !== verified.value)
|
|
819
744
|
throw new Error("Transaction removal image changed.");
|
|
820
745
|
await assertUnexcludedTargets(journal.root, [entry.target], options);
|
|
821
|
-
await removeScopedImage(entry.target, current.scoped, options
|
|
746
|
+
await removeScopedImage(entry.target, current.scoped, options);
|
|
822
747
|
}
|
|
823
748
|
else {
|
|
824
|
-
if (validateIgnorePolicy) {
|
|
825
|
-
await validateIgnorePolicy();
|
|
826
|
-
await assertUnexcludedTargets(journal.root, [entry.target], options);
|
|
827
|
-
await verifyTarget(directory, entry, journal, options);
|
|
828
|
-
}
|
|
829
749
|
options.validateMutation?.();
|
|
830
750
|
options.signal?.throwIfAborted();
|
|
831
751
|
await fs.rm(entry.target, { recursive: true, force: true });
|
|
@@ -834,7 +754,7 @@ async function removeOwnedTarget(directory, entry, journal, options, { apply, re
|
|
|
834
754
|
return true;
|
|
835
755
|
}
|
|
836
756
|
catch (error) {
|
|
837
|
-
if (!scoped
|
|
757
|
+
if (!scoped)
|
|
838
758
|
throw error;
|
|
839
759
|
throw new ScopedRemovalError("Scoped transaction removal stopped; preserve transaction and backup for review.", {
|
|
840
760
|
cause: error,
|
|
@@ -882,7 +802,7 @@ async function completeTransaction(directory, journal) {
|
|
|
882
802
|
// may only retry cleanup, never roll back already accepted files.
|
|
883
803
|
await writeJson(path.join(directory, "journal.json"), {
|
|
884
804
|
...journal,
|
|
885
|
-
version: isScopedJournal(journal)
|
|
805
|
+
version: isScopedJournal(journal) ? journal.version : journal.sessionRootTransition ? 7 : 6,
|
|
886
806
|
completed: true,
|
|
887
807
|
}, {
|
|
888
808
|
maxBytes: MAX_TRANSACTION_JOURNAL_BYTES,
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
export const IGNORE_SNAPSHOT_VERSION = 6;
|
|
2
|
-
export const RULES_SNAPSHOT_VERSION = 7;
|
|
3
|
-
export function isIgnoreSnapshotVersion(version) {
|
|
4
|
-
return version === IGNORE_SNAPSHOT_VERSION || version === RULES_SNAPSHOT_VERSION;
|
|
5
|
-
}
|
|
6
1
|
export function isSupportedSnapshotVersion(version) {
|
|
7
|
-
return
|
|
8
|
-
version === 2 ||
|
|
9
|
-
version === 3 ||
|
|
10
|
-
version === 4 ||
|
|
11
|
-
version === 5 ||
|
|
12
|
-
isIgnoreSnapshotVersion(version));
|
|
2
|
+
return version === 1 || version === 2 || version === 3 || version === 4 || version === 5;
|
|
13
3
|
}
|
|
@@ -6,13 +6,12 @@ import path from "node:path";
|
|
|
6
6
|
import { isDeniedPath, posixJoin, safeJoin, toPosix } from "../paths.js";
|
|
7
7
|
import { agentDir, configuredSessionDir, expandSessionDir } from "./session-paths.js";
|
|
8
8
|
import { assertAgentDirectorySettingsSize, MAX_AGENT_DIRECTORY_BYTES } from "./snapshot-bounds.js";
|
|
9
|
-
import { agentDirectoryAnchor, agentDirectoryPhysicalSessionPath, agentDirectorySessionRoot,
|
|
9
|
+
import { agentDirectoryAnchor, agentDirectoryPhysicalSessionPath, agentDirectorySessionRoot, } from "./snapshot-exclude-safety.js";
|
|
10
10
|
import { sessionStorageRoot } from "./snapshot-paths.js";
|
|
11
11
|
export { isDeniedPath } from "../paths.js";
|
|
12
12
|
export { sessionStorageRoot } from "./snapshot-paths.js";
|
|
13
13
|
import { compileSyncExclude } from "../sync/exclude-policy.js";
|
|
14
|
-
import { assertAgentDirectoryPathLayout, canonicalSnapshotPathForConfig, compileSyncPolicyExclude, compileSyncPolicyTraversal, configuredSnapshotPathMatcher, customIncludePathsByLower, DEFAULT_SYNC_INCLUDE, includeFromSelectionConfig,
|
|
15
|
-
import { IGNORE_SNAPSHOT_VERSION, } from "./snapshot-types.js";
|
|
14
|
+
import { assertAgentDirectoryPathLayout, canonicalSnapshotPathForConfig, compileSyncPolicyExclude, compileSyncPolicyTraversal, configuredSnapshotPathMatcher, customIncludePathsByLower, DEFAULT_SYNC_INCLUDE, includeFromSelectionConfig, isPreservableUnmanagedSnapshotPath, MAX_AGENT_DIRECTORY_ENTRIES, MAX_AGENT_DIRECTORY_FILES, normalizeExtraFiles, normalizeSyncFiles, requireLegacyTransferPolicy, sameSnapshotSelection, selectionForSnapshot, snapshotSelectionExclude, snapshotSelectionInclude, syncIncludeSelection, syncSessionsSelected, } from "../sync/sync-policy.js";
|
|
16
15
|
export { canonicalSnapshotPathForConfig, isConfiguredSnapshotPath } from "../sync/sync-policy.js";
|
|
17
16
|
const VERSION = 1;
|
|
18
17
|
const scanInventories = new WeakMap();
|
|
@@ -84,7 +83,7 @@ async function collectSnapshotFiles(options, materialize) {
|
|
|
84
83
|
const needsSessionConfig = syncSessions || !excluded("settings.json");
|
|
85
84
|
const sessionDir = options.scope === "agent-directory"
|
|
86
85
|
? options.sessionDir
|
|
87
|
-
: (options.sessionDir ?? (needsSessionConfig ? await configuredSessionDir(
|
|
86
|
+
: (options.sessionDir ?? (needsSessionConfig ? await configuredSessionDir() : undefined));
|
|
88
87
|
options.signal?.throwIfAborted();
|
|
89
88
|
const collectionOptions = { ...policy, sessionDir };
|
|
90
89
|
const collected = options.scope === "agent-directory"
|
|
@@ -123,18 +122,12 @@ export async function createSnapshot(profile, options = {}) {
|
|
|
123
122
|
options.signal?.throwIfAborted();
|
|
124
123
|
const selection = selectionForSnapshot(include, options.exclude, options);
|
|
125
124
|
const snapshot = {
|
|
126
|
-
version:
|
|
127
|
-
? IGNORE_SNAPSHOT_VERSION
|
|
128
|
-
: options.scope === "agent-directory"
|
|
129
|
-
? 5
|
|
130
|
-
: options.exclude === undefined
|
|
131
|
-
? VERSION
|
|
132
|
-
: 4,
|
|
125
|
+
version: options.scope === "agent-directory" ? 5 : options.exclude === undefined ? VERSION : 4,
|
|
133
126
|
id: snapshotId(),
|
|
134
127
|
createdAt: new Date().toISOString(),
|
|
135
128
|
machine: os.hostname(),
|
|
136
129
|
profile,
|
|
137
|
-
syncSessions:
|
|
130
|
+
syncSessions: syncSessions,
|
|
138
131
|
selection,
|
|
139
132
|
files,
|
|
140
133
|
};
|
|
@@ -160,8 +153,7 @@ export async function collectFiles(root, options = {}, excluded = compileSyncPol
|
|
|
160
153
|
}
|
|
161
154
|
async function collectSelectedFiles(root, options, excluded, materialize) {
|
|
162
155
|
const signal = options.signal;
|
|
163
|
-
const
|
|
164
|
-
const collection = { signal, excluded, guardReserved, materialize };
|
|
156
|
+
const collection = { signal, excluded, materialize };
|
|
165
157
|
signal?.throwIfAborted();
|
|
166
158
|
const results = [];
|
|
167
159
|
const entries = await fs.readdir(root, { withFileTypes: true });
|
|
@@ -260,14 +252,11 @@ async function readScannedFile(candidate, signal) {
|
|
|
260
252
|
await handle.close();
|
|
261
253
|
}
|
|
262
254
|
}
|
|
263
|
-
export async function agentDirectoryConfiguredSessionDir(signal, root = agentDir()
|
|
264
|
-
const content = await readAgentDirectorySettings(signal, root
|
|
255
|
+
export async function agentDirectoryConfiguredSessionDir(signal, root = agentDir()) {
|
|
256
|
+
const content = await readAgentDirectorySettings(signal, root);
|
|
265
257
|
return content === undefined ? undefined : agentDirectorySessionDirFromSettings(content);
|
|
266
258
|
}
|
|
267
|
-
export async function readAgentDirectorySettings(signal, root = agentDir()
|
|
268
|
-
const guardReserved = reservedIgnoreTargetGuard(root, options);
|
|
269
|
-
if (guardReserved)
|
|
270
|
-
await guardReserved(path.join(root, "settings.json"));
|
|
259
|
+
export async function readAgentDirectorySettings(signal, root = agentDir()) {
|
|
271
260
|
const absolute = path.resolve(root);
|
|
272
261
|
const canonical = path.join(await fs.realpath(path.dirname(absolute)), path.basename(absolute));
|
|
273
262
|
await identify(absolute, canonical, signal);
|
|
@@ -308,9 +297,9 @@ async function collectAgentDirectory(root, options, materialize, pendingStateEnt
|
|
|
308
297
|
const signal = options.signal;
|
|
309
298
|
const excluded = compileSyncPolicyExclude(options);
|
|
310
299
|
const canTraverse = compileSyncPolicyTraversal(options);
|
|
311
|
-
const sessionDir = options.sessionDir ?? (await agentDirectoryConfiguredSessionDir(signal, root
|
|
312
|
-
const isPhysicalSessionPath = agentDirectoryPhysicalSessionPath(root, sessionDir
|
|
313
|
-
const sessionRoot = agentDirectorySessionRoot(root, sessionDir
|
|
300
|
+
const sessionDir = options.sessionDir ?? (await agentDirectoryConfiguredSessionDir(signal, root));
|
|
301
|
+
const isPhysicalSessionPath = agentDirectoryPhysicalSessionPath(root, sessionDir);
|
|
302
|
+
const sessionRoot = agentDirectorySessionRoot(root, sessionDir);
|
|
314
303
|
const directories = [];
|
|
315
304
|
const candidates = [];
|
|
316
305
|
const entries = new Map();
|
|
@@ -342,7 +331,7 @@ async function collectAgentDirectory(root, options, materialize, pendingStateEnt
|
|
|
342
331
|
continue;
|
|
343
332
|
const candidate = await identify(path.join(directory.absolute, entry.name), path.join(directory.canonical, entry.name), signal);
|
|
344
333
|
if (entry.isDirectory()) {
|
|
345
|
-
if (!excluded(snapshotPath
|
|
334
|
+
if (!excluded(snapshotPath))
|
|
346
335
|
entries.set(candidate.absolute, "directory");
|
|
347
336
|
await walk(candidate, snapshotPath, sessions);
|
|
348
337
|
}
|
|
@@ -403,8 +392,7 @@ async function collectAgentDirectory(root, options, materialize, pendingStateEnt
|
|
|
403
392
|
}
|
|
404
393
|
for (const directory of directories)
|
|
405
394
|
await recheck(directory, signal);
|
|
406
|
-
if (options.sessionDir === undefined &&
|
|
407
|
-
(await agentDirectoryConfiguredSessionDir(signal, root, options)) !== sessionDir)
|
|
395
|
+
if (options.sessionDir === undefined && (await agentDirectoryConfiguredSessionDir(signal, root)) !== sessionDir)
|
|
408
396
|
changedScan();
|
|
409
397
|
const currentSessionDirectory = await identifySessionRoot();
|
|
410
398
|
if (Boolean(sessionDirectory) !== Boolean(currentSessionDirectory) ||
|
|
@@ -455,8 +443,6 @@ async function collectIncludedPath(results, root, relativePath, options) {
|
|
|
455
443
|
async function collectDirectory(results, root, relativeDirectory, options) {
|
|
456
444
|
options.signal?.throwIfAborted();
|
|
457
445
|
const absoluteDirectory = path.join(root, relativeDirectory);
|
|
458
|
-
if (options.guardReserved)
|
|
459
|
-
await options.guardReserved(absoluteDirectory);
|
|
460
446
|
options.signal?.throwIfAborted();
|
|
461
447
|
for (const entry of await fs.readdir(absoluteDirectory, { withFileTypes: true })) {
|
|
462
448
|
options.signal?.throwIfAborted();
|
|
@@ -472,22 +458,12 @@ async function collectDirectory(results, root, relativeDirectory, options) {
|
|
|
472
458
|
}
|
|
473
459
|
}
|
|
474
460
|
}
|
|
475
|
-
|
|
476
|
-
if (!guardReserved)
|
|
477
|
-
return fs.readFile(absolutePath, { signal });
|
|
478
|
-
signal?.throwIfAborted();
|
|
479
|
-
const canonical = await guardReserved(absolutePath);
|
|
480
|
-
const candidate = await identify(absolutePath, canonical, signal);
|
|
481
|
-
if (!candidate.stat.isFile() || candidate.stat.nlink !== 1)
|
|
482
|
-
changedScan();
|
|
483
|
-
return readScannedFile(candidate, signal);
|
|
484
|
-
}
|
|
485
|
-
async function addFile(results, root, relativePath, snapshotPath, { signal, guardReserved, materialize }) {
|
|
461
|
+
async function addFile(results, root, relativePath, snapshotPath, { signal, materialize }) {
|
|
486
462
|
signal?.throwIfAborted();
|
|
487
463
|
if (!isSafeSnapshotPath(snapshotPath))
|
|
488
464
|
return;
|
|
489
465
|
const absolutePath = safeJoin(root, relativePath);
|
|
490
|
-
const content = await
|
|
466
|
+
const content = await fs.readFile(absolutePath, { signal });
|
|
491
467
|
signal?.throwIfAborted();
|
|
492
468
|
results.push(materialize(snapshotPath, content));
|
|
493
469
|
}
|
|
@@ -515,42 +491,27 @@ export function snapshotTarget(root, relativePath, configuredSessionDir) {
|
|
|
515
491
|
export function snapshotIncludesSessions(snapshot) {
|
|
516
492
|
if (snapshot.selection?.version === 3)
|
|
517
493
|
return syncSessionsSelected(snapshot.selection);
|
|
518
|
-
if (snapshot.selection?.version === 4)
|
|
519
|
-
return snapshot.files.some((file) => isSessionPath(file.path));
|
|
520
494
|
return (snapshot.syncSessions === true ||
|
|
521
495
|
(snapshotSelectionInclude(snapshot)?.includes("sessions") === true &&
|
|
522
496
|
!compileSyncExclude(snapshotSelectionExclude(snapshot))("sessions")) ||
|
|
523
497
|
snapshot.files.some((file) => isSessionPath(file.path)));
|
|
524
498
|
}
|
|
525
499
|
export function filterSnapshotForConfigPolicy(snapshot, config, options = {}) {
|
|
500
|
+
requireLegacyTransferPolicy(snapshot);
|
|
526
501
|
const include = includeFromSelectionConfig(config);
|
|
527
502
|
const wholeDirectory = config.scope === "agent-directory";
|
|
528
|
-
if (!wholeDirectory || !config.ignorePolicy)
|
|
529
|
-
requireLegacyTransferPolicy(snapshot);
|
|
530
503
|
const exclude = config.exclude ?? (snapshot.version >= 4 ? [] : undefined);
|
|
531
|
-
const selection = selectionForSnapshot(include, exclude, config);
|
|
532
504
|
const files = wholeDirectory
|
|
533
505
|
? filterAgentDirectoryFiles(snapshot.files, config, options.sessionDir)
|
|
534
506
|
: canonicalizeSnapshotFilesForConfig(snapshot.files, config, customIncludePathsByLower(include));
|
|
535
|
-
const { ignoreRules: _ignoreRules, ...image } = snapshot;
|
|
536
507
|
const filtered = {
|
|
537
|
-
...
|
|
538
|
-
version:
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
? 5
|
|
542
|
-
: exclude === undefined
|
|
543
|
-
? snapshot.version
|
|
544
|
-
: 4,
|
|
545
|
-
syncSessions: selection.version === 4
|
|
546
|
-
? files.some((file) => isSessionPath(file.path))
|
|
547
|
-
: syncSessionsSelected(config)
|
|
548
|
-
? snapshot.syncSessions
|
|
549
|
-
: false,
|
|
550
|
-
selection,
|
|
508
|
+
...snapshot,
|
|
509
|
+
version: wholeDirectory ? 5 : exclude === undefined ? snapshot.version : 4,
|
|
510
|
+
syncSessions: syncSessionsSelected(config) ? snapshot.syncSessions : false,
|
|
511
|
+
selection: selectionForSnapshot(include, exclude, config),
|
|
551
512
|
files,
|
|
552
513
|
};
|
|
553
|
-
if (!options.regenerateId ||
|
|
514
|
+
if (!options.regenerateId || snapshotsMatch(snapshot, filtered))
|
|
554
515
|
return filtered;
|
|
555
516
|
return {
|
|
556
517
|
...filtered,
|
|
@@ -561,9 +522,7 @@ export function filterSnapshotForConfigPolicy(snapshot, config, options = {}) {
|
|
|
561
522
|
}
|
|
562
523
|
function filterAgentDirectoryFiles(files, config, sessionDir) {
|
|
563
524
|
const configured = configuredSnapshotPathMatcher(config);
|
|
564
|
-
const isPhysicalSessionPath = sessionDir
|
|
565
|
-
? agentDirectoryPhysicalSessionPath(agentDir(), sessionDir, config.ignorePolicy, config.reservedIgnoreNames)
|
|
566
|
-
: undefined;
|
|
525
|
+
const isPhysicalSessionPath = sessionDir ? agentDirectoryPhysicalSessionPath(agentDir(), sessionDir) : undefined;
|
|
567
526
|
const projected = files.filter((file) => {
|
|
568
527
|
if (!isSafeSnapshotPath(file.path) || !configured(file.path))
|
|
569
528
|
return false;
|
|
@@ -606,12 +565,11 @@ function isPreferredExtraCandidate(left, right) {
|
|
|
606
565
|
return left.originalPath.localeCompare(right.originalPath) < 0;
|
|
607
566
|
}
|
|
608
567
|
export function snapshotWithoutSessions(snapshot) {
|
|
609
|
-
requireLegacyTransferPolicy(snapshot);
|
|
610
568
|
const files = snapshot.files.filter((file) => !isSessionPath(file.path));
|
|
611
569
|
const include = snapshotSelectionInclude(snapshot)?.filter((item) => item !== "sessions");
|
|
612
570
|
if (files.length === snapshot.files.length &&
|
|
613
571
|
snapshot.syncSessions !== true &&
|
|
614
|
-
include?.length === snapshot.selection?.include
|
|
572
|
+
include?.length === snapshot.selection?.include.length) {
|
|
615
573
|
return snapshot;
|
|
616
574
|
}
|
|
617
575
|
return {
|
|
@@ -642,23 +600,13 @@ export function scanSnapshot(snapshot) {
|
|
|
642
600
|
}
|
|
643
601
|
}
|
|
644
602
|
}
|
|
645
|
-
if (snapshot.ignoreRules && SECRET_PATTERNS.some((pattern) => pattern.test(snapshot.ignoreRules?.text ?? "")))
|
|
646
|
-
findings.push(snapshot.ignoreRules.filename);
|
|
647
603
|
return findings;
|
|
648
604
|
}
|
|
649
605
|
export function mergeRemotePreservedFiles(local, remote, config, options = {}) {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
requireLegacyTransferPolicy(remote);
|
|
653
|
-
}
|
|
606
|
+
requireLegacyTransferPolicy(local);
|
|
607
|
+
requireLegacyTransferPolicy(remote);
|
|
654
608
|
if (config.scope === "agent-directory")
|
|
655
609
|
return filterSnapshotForConfigPolicy(local, config, { ...options, regenerateId: true });
|
|
656
|
-
if (config.reservedIgnoreNames !== undefined) {
|
|
657
|
-
const names = new Set(config.reservedIgnoreNames);
|
|
658
|
-
const files = local.files.filter((file) => !isIgnoreControlPath(toPosix(file.path), names));
|
|
659
|
-
if (files.length !== local.files.length)
|
|
660
|
-
local = regenerateSnapshotIdentity({ ...local, files });
|
|
661
|
-
}
|
|
662
610
|
const localPathNames = new Set(local.files.map((file) => file.path.toLowerCase()));
|
|
663
611
|
const preservedPathNames = new Set();
|
|
664
612
|
const configured = configuredSnapshotPathMatcher(config);
|
|
@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { backendIdentityCoordinates } from "../backends/backend-identity.js";
|
|
5
5
|
import { safeName } from "../paths.js";
|
|
6
|
+
import { retiredIgnorePolicy } from "../settings/retired-ignore-policy.js";
|
|
6
7
|
import { readJsonIfExists, writeJson } from "./json-file.js";
|
|
7
8
|
import { stateDir } from "./state-directory.js";
|
|
8
9
|
const STATE_VERSION = 2;
|
|
@@ -21,7 +22,10 @@ export async function writeState(profile, state) {
|
|
|
21
22
|
await writeJson(statePath(profile), state);
|
|
22
23
|
}
|
|
23
24
|
export async function readStateForConfig(config) {
|
|
24
|
-
|
|
25
|
+
const state = await readJsonIfExists(statePathForConfig(config));
|
|
26
|
+
if (state && Object.hasOwn(state, "ignorePolicyKey"))
|
|
27
|
+
throw retiredIgnorePolicy("baseline");
|
|
28
|
+
return (state ?? {
|
|
25
29
|
version: STATE_VERSION,
|
|
26
30
|
profile: config.snapshotIdentity,
|
|
27
31
|
lastFileHashes: {},
|
|
@@ -45,7 +45,6 @@ export async function resolveAgentPlan(ctx, options, config, backend, state, loc
|
|
|
45
45
|
1,
|
|
46
46
|
backend.identity,
|
|
47
47
|
syncConfigReviewIdentity(config),
|
|
48
|
-
...(config.configDocumentFingerprint ? [config.configDocumentFingerprint] : []),
|
|
49
48
|
syncStateFingerprint(state),
|
|
50
49
|
head.revision,
|
|
51
50
|
fileHashMap(localRaw),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** One policy for startup scheduling and commit-time authorization. */
|
|
2
2
|
export function startupTransferEnabled(config) {
|
|
3
|
-
return Boolean(config.automaticTransfer
|
|
3
|
+
return Boolean(config.automaticTransfer);
|
|
4
4
|
}
|
|
5
5
|
export const AGENT_TIMEOUT_MS = 20_000;
|
|
6
6
|
export const AGENT_INPUT_BYTES = 24 * 1024;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { truncateToWidth } from "@earendil-works/pi-tui";
|
|
2
2
|
import { createSyncBackend } from "../backends/backend-factory.js";
|
|
3
|
-
import { requireNoPendingAdoption } from "../ignore/adoption-journal.js";
|
|
4
3
|
import { loadConfig, syncCheckConfigFingerprint } from "../settings/config.js";
|
|
5
4
|
import { readStateForConfig, syncStateFingerprint } from "../state/sync-state-store.js";
|
|
6
5
|
import { confirmMergeReview } from "../ui/merge-review.js";
|
|
@@ -10,7 +9,6 @@ import { conflictPreview } from "./conflict-preview.js";
|
|
|
10
9
|
import { mergeSync } from "./merged-sync.js";
|
|
11
10
|
import { captureMutationOwner } from "./sync-local.js";
|
|
12
11
|
export async function showConflicts(ctx, options, factory = createSyncBackend) {
|
|
13
|
-
requireNoPendingAdoption();
|
|
14
12
|
const validate = captureMutationOwner(ctx, options.signal);
|
|
15
13
|
const config = await loadConfig(options.setup);
|
|
16
14
|
validate();
|