@narumitw/pi-sync 0.63.1 → 0.64.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.
Files changed (127) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +12 -5
  3. package/dist/chunks/{chunk-HLCML3OW.ts → chunk-4VKWHVUO.ts} +4 -3
  4. package/dist/chunks/chunk-4VKWHVUO.ts.map +7 -0
  5. package/dist/chunks/{chunk-27F5W7DX.ts → chunk-DAZZ5BEJ.ts} +3 -1
  6. package/dist/chunks/chunk-DAZZ5BEJ.ts.map +7 -0
  7. package/dist/chunks/{chunk-V76KCWHO.ts → chunk-F3VODLVQ.ts} +3 -3
  8. package/dist/chunks/{chunk-VQ47JBLF.ts → chunk-FI2F5JBS.ts} +2 -2
  9. package/dist/chunks/{chunk-LBNC5AOM.ts → chunk-NDEZ52SS.ts} +12 -12
  10. package/dist/chunks/{chunk-B5F3JLD3.ts → chunk-RW44KNFD.ts} +304 -70
  11. package/dist/chunks/chunk-RW44KNFD.ts.map +7 -0
  12. package/dist/chunks/{chunk-EXDWEFIJ.ts → chunk-TJ7YNITN.ts} +5 -5
  13. package/dist/chunks/{chunk-HSCAFOT5.ts → chunk-TZMVSTAM.ts} +5 -5
  14. package/dist/chunks/{chunk-SXCH4Q5O.ts → chunk-VPSC7BXM.ts} +3 -3
  15. package/dist/chunks/{chunk-POWOMJ7S.ts → chunk-YT6PDRMM.ts} +58 -31
  16. package/dist/chunks/chunk-YT6PDRMM.ts.map +7 -0
  17. package/dist/chunks/{command-handler-GMRRFWOL.ts → command-handler-N45GY7AV.ts} +39 -27
  18. package/dist/chunks/command-handler-N45GY7AV.ts.map +7 -0
  19. package/dist/chunks/{conflict-review-JWEA7DPQ.ts → conflict-review-5E4M44BA.ts} +2 -2
  20. package/dist/chunks/{file-selection-KID23GAD.ts → file-selection-DDQN4LVD.ts} +9 -9
  21. package/dist/chunks/{manager-result-dispatcher-GDB74IOP.ts → manager-result-dispatcher-FKW55L7I.ts} +5 -5
  22. package/dist/chunks/{manager-ui-T5J5WG7T.ts → manager-ui-EV23DPZQ.ts} +75 -57
  23. package/dist/chunks/manager-ui-EV23DPZQ.ts.map +7 -0
  24. package/dist/chunks/{merge-review-OQDXNTJU.ts → merge-review-6YSLSMGS.ts} +3 -2
  25. package/dist/chunks/ownership-recovery-UDDHSDSZ.ts +59 -0
  26. package/dist/chunks/ownership-recovery-UDDHSDSZ.ts.map +7 -0
  27. package/dist/chunks/{remote-selection-ui-GPITNEBF.ts → remote-selection-ui-N4NMWFT2.ts} +4 -4
  28. package/dist/chunks/{setup-switch-L54X5U5I.ts → setup-switch-HY7K3442.ts} +4 -4
  29. package/dist/chunks/{setup-wizard-LL6YMGUR.ts → setup-wizard-LEKDQ3HK.ts} +9 -9
  30. package/dist/chunks/{sync-inspection-SRU6HGGK.ts → sync-inspection-OS2LVOLV.ts} +5 -5
  31. package/dist/chunks/{sync-operations-UGSCONZ7.ts → sync-operations-D3MDJUQQ.ts} +2 -2
  32. package/dist/daemon/dist/cli.js +2 -0
  33. package/dist/daemon/dist/client-transport.js +66 -0
  34. package/dist/daemon/dist/client.js +116 -86
  35. package/dist/daemon/dist/consent.js +33 -11
  36. package/dist/daemon/dist/daemon-debug.js +33 -0
  37. package/dist/daemon/dist/daemon-recovery.js +75 -0
  38. package/dist/daemon/dist/engine/backends/git/git-backend.js +39 -12
  39. package/dist/daemon/dist/engine/backends/git/git-runner.js +6 -1
  40. package/dist/daemon/dist/engine/backends/git/git-storage.js +5 -9
  41. package/dist/daemon/dist/engine/backends/publication-encoding.js +19 -0
  42. package/dist/daemon/dist/engine/backends/s3/s3-backend.js +10 -12
  43. package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +15 -26
  44. package/dist/daemon/dist/engine/backends/webdav/webdav-client.js +10 -0
  45. package/dist/daemon/dist/engine/debug-log.js +134 -0
  46. package/dist/daemon/dist/engine/paths.js +7 -1
  47. package/dist/daemon/dist/engine/settings/config-file.js +62 -17
  48. package/dist/daemon/dist/engine/settings/config.js +49 -14
  49. package/dist/daemon/dist/engine/snapshot/snapshot-apply.js +30 -8
  50. package/dist/daemon/dist/engine/snapshot/snapshot-codec.js +3 -1
  51. package/dist/daemon/dist/engine/snapshot/snapshot-payload.js +32 -0
  52. package/dist/daemon/dist/engine/snapshot/snapshot-transaction-images.js +34 -0
  53. package/dist/daemon/dist/engine/snapshot/snapshot-transaction.js +50 -7
  54. package/dist/daemon/dist/engine/snapshot/snapshot.js +64 -25
  55. package/dist/daemon/dist/engine/state/lock.js +157 -17
  56. package/dist/daemon/dist/engine/sync/continuous-sync.js +35 -11
  57. package/dist/daemon/dist/engine/sync/initialization.js +2 -2
  58. package/dist/daemon/dist/engine/sync/local-fields.js +42 -19
  59. package/dist/daemon/dist/engine/sync/merged-sync.js +13 -10
  60. package/dist/daemon/dist/engine/sync/remote-snapshot.js +18 -3
  61. package/dist/daemon/dist/engine/sync/session-push.js +13 -4
  62. package/dist/daemon/dist/engine/sync/startup-bootstrap.js +105 -0
  63. package/dist/daemon/dist/engine/sync/startup-recovery-evidence.js +37 -0
  64. package/dist/daemon/dist/engine/sync/startup-timings.js +80 -8
  65. package/dist/daemon/dist/engine/sync/sync-error-guidance.js +6 -1
  66. package/dist/daemon/dist/engine/sync/sync-inspection.js +4 -7
  67. package/dist/daemon/dist/engine/sync/sync-local.js +3 -1
  68. package/dist/daemon/dist/engine/sync/sync-mutations.js +9 -3
  69. package/dist/daemon/dist/engine/sync/sync-policy.js +9 -1
  70. package/dist/daemon/dist/engine/sync/sync-state.js +12 -4
  71. package/dist/daemon/dist/engine-service.js +54 -10
  72. package/dist/daemon/dist/identity.js +36 -6
  73. package/dist/daemon/dist/index.js +2 -1
  74. package/dist/daemon/dist/monitor.js +20 -1
  75. package/dist/daemon/dist/paged-review.js +177 -0
  76. package/dist/daemon/dist/participant-ledger.js +149 -0
  77. package/dist/daemon/dist/protocol.js +4 -0
  78. package/dist/daemon/dist/server.js +268 -120
  79. package/dist/daemon/dist/service-host.js +29 -9
  80. package/dist/daemon/dist/state-wait-jobs.js +23 -0
  81. package/dist/daemon/dist/state-wait.js +34 -0
  82. package/dist/daemon/package.json +1 -1
  83. package/dist/index.ts +128 -48
  84. package/dist/index.ts.map +2 -2
  85. package/docs/continuous-sync-verification.md +2 -0
  86. package/docs/daemon-migration.md +30 -2
  87. package/docs/tui-contract.md +7 -1
  88. package/package.json +2 -2
  89. package/skills/configure-pi-sync/references/configuration.md +23 -13
  90. package/src/commands/command-execution.ts +11 -3
  91. package/src/commands/command-handler.ts +10 -3
  92. package/src/commands/command.ts +3 -2
  93. package/src/daemon/client-debug.ts +45 -0
  94. package/src/daemon/ownership-recovery.ts +50 -0
  95. package/src/daemon/pi-client.ts +288 -63
  96. package/src/daemon/startup-bootstrap-client.ts +26 -0
  97. package/src/settings/config.ts +1 -0
  98. package/src/sync/automatic-sync.ts +61 -18
  99. package/src/sync/startup-check.ts +13 -5
  100. package/src/sync-extension.ts +46 -8
  101. package/src/ui/manager-state.ts +29 -21
  102. package/src/ui/manager-ui.ts +16 -1
  103. package/src/ui/merge-review.ts +52 -16
  104. package/src/ui/settings-ui.ts +2 -2
  105. package/src/ui/sync-confirmation.ts +16 -19
  106. package/src/ui/sync-setups-ui.ts +15 -12
  107. package/dist/chunks/chunk-27F5W7DX.ts.map +0 -7
  108. package/dist/chunks/chunk-B5F3JLD3.ts.map +0 -7
  109. package/dist/chunks/chunk-HLCML3OW.ts.map +0 -7
  110. package/dist/chunks/chunk-POWOMJ7S.ts.map +0 -7
  111. package/dist/chunks/command-handler-GMRRFWOL.ts.map +0 -7
  112. package/dist/chunks/manager-ui-T5J5WG7T.ts.map +0 -7
  113. /package/dist/chunks/{chunk-V76KCWHO.ts.map → chunk-F3VODLVQ.ts.map} +0 -0
  114. /package/dist/chunks/{chunk-VQ47JBLF.ts.map → chunk-FI2F5JBS.ts.map} +0 -0
  115. /package/dist/chunks/{chunk-LBNC5AOM.ts.map → chunk-NDEZ52SS.ts.map} +0 -0
  116. /package/dist/chunks/{chunk-EXDWEFIJ.ts.map → chunk-TJ7YNITN.ts.map} +0 -0
  117. /package/dist/chunks/{chunk-HSCAFOT5.ts.map → chunk-TZMVSTAM.ts.map} +0 -0
  118. /package/dist/chunks/{chunk-SXCH4Q5O.ts.map → chunk-VPSC7BXM.ts.map} +0 -0
  119. /package/dist/chunks/{conflict-review-JWEA7DPQ.ts.map → conflict-review-5E4M44BA.ts.map} +0 -0
  120. /package/dist/chunks/{file-selection-KID23GAD.ts.map → file-selection-DDQN4LVD.ts.map} +0 -0
  121. /package/dist/chunks/{manager-result-dispatcher-GDB74IOP.ts.map → manager-result-dispatcher-FKW55L7I.ts.map} +0 -0
  122. /package/dist/chunks/{merge-review-OQDXNTJU.ts.map → merge-review-6YSLSMGS.ts.map} +0 -0
  123. /package/dist/chunks/{remote-selection-ui-GPITNEBF.ts.map → remote-selection-ui-N4NMWFT2.ts.map} +0 -0
  124. /package/dist/chunks/{setup-switch-L54X5U5I.ts.map → setup-switch-HY7K3442.ts.map} +0 -0
  125. /package/dist/chunks/{setup-wizard-LL6YMGUR.ts.map → setup-wizard-LEKDQ3HK.ts.map} +0 -0
  126. /package/dist/chunks/{sync-inspection-SRU6HGGK.ts.map → sync-inspection-OS2LVOLV.ts.map} +0 -0
  127. /package/dist/chunks/{sync-operations-UGSCONZ7.ts.map → sync-operations-D3MDJUQQ.ts.map} +0 -0
@@ -24,6 +24,9 @@ const LOCKFILE_FS_ADAPTER = {
24
24
  utimesSync,
25
25
  };
26
26
  let configUpdateQueue = Promise.resolve();
27
+ let pendingMutations = 0;
28
+ let mutationGeneration = 0;
29
+ let localReadLock;
27
30
  let publishConfigFile = publishFileWithGuard;
28
31
  let beforeConfigPublicationHook = async () => undefined;
29
32
  let afterMissingConfigReadProbeHook = async () => undefined;
@@ -118,6 +121,31 @@ async function peekUnlocked(maxBytes, securePermissions = true) {
118
121
  const filePath = (await pathExists(canonicalPath)) ? canonicalPath : legacyLocalConfigPath();
119
122
  return readConfigDocumentIfExists(filePath, maxBytes, securePermissions);
120
123
  }
124
+ export async function readLocalConfigForDiagnostics(root) {
125
+ if (pendingMutations)
126
+ return undefined;
127
+ const generation = mutationGeneration;
128
+ const canonical = path.join(root, CONFIG_FILE_NAME);
129
+ const legacy = path.join(root, LEGACY_CONFIG_FILE_NAME);
130
+ const filePath = (await pathExists(canonical)) ? canonical : legacy;
131
+ if (filePath === legacy)
132
+ await assertNoInterruptedConfigReplacement(canonical);
133
+ const document = await readConfigDocumentIfExists(filePath, MAX_SETTINGS_BYTES, false);
134
+ if (!document)
135
+ return undefined;
136
+ const locked = () => pendingMutations ||
137
+ mutationGeneration !== generation ||
138
+ (localReadLock !== canonical && lstatSync(configMutationLockPath(canonical), { throwIfNoEntry: false }));
139
+ return {
140
+ document,
141
+ stillCurrent() {
142
+ if (locked())
143
+ return false;
144
+ assertCurrentDocument(document, canonical, legacy);
145
+ return !locked();
146
+ },
147
+ };
148
+ }
121
149
  async function readConfigDocumentIfExists(filePath, maxBytes, securePermissions = true) {
122
150
  const snapshot = await readConfigSnapshotIfExists(filePath, maxBytes, securePermissions);
123
151
  return snapshot ? { path: filePath, ...snapshot } : undefined;
@@ -136,7 +164,7 @@ export function withLockedLocalConfigDocument(run, signal, forWrite = false, { s
136
164
  assertCurrentDocument(document);
137
165
  });
138
166
  });
139
- });
167
+ }, forWrite);
140
168
  }
141
169
  export async function readMigratingLocalConfigDocument(validateForMigration) {
142
170
  const authority = engineHost().config;
@@ -158,17 +186,24 @@ export async function readMigratingLocalConfigDocument(validateForMigration) {
158
186
  }
159
187
  async function withLocalConfigReadLockIfNeeded(read) {
160
188
  if ((await pathExists(localConfigPath())) || (await pathExists(legacyLocalConfigPath()))) {
161
- return withLocalConfigFileLock(read);
189
+ return withLocalConfigFileLock(read, true);
162
190
  }
163
191
  await afterMissingConfigReadProbeHook();
164
192
  if (await pathExists(configMutationLockPath()))
165
- return withLocalConfigFileLock(read);
193
+ return withLocalConfigFileLock(read, true);
166
194
  await assertNoInterruptedConfigReplacement();
167
195
  return read();
168
196
  }
169
- function queueConfigOperation(run) {
197
+ function beginConfigMutation() {
198
+ pendingMutations++;
199
+ mutationGeneration++;
200
+ return () => pendingMutations--;
201
+ }
202
+ function queueConfigOperation(run, mayMutate = false) {
170
203
  // Mutation callbacks use the unlocked helpers below, never a queued public read.
171
- const operation = configUpdateQueue.then(run);
204
+ const finished = mayMutate ? beginConfigMutation() : undefined;
205
+ const queued = configUpdateQueue.then(run);
206
+ const operation = finished ? queued.finally(finished) : queued;
172
207
  configUpdateQueue = operation.then(() => undefined, () => undefined);
173
208
  return operation;
174
209
  }
@@ -218,7 +253,7 @@ export function updateLocalConfigDocument(defaultValue, update, validate, signal
218
253
  await installPrivateConfigExclusively(localConfigPath(), serializedConfig(next), signal, review);
219
254
  return next;
220
255
  });
221
- });
256
+ }, true);
222
257
  }
223
258
  export function createLocalConfigDocument(value, signal) {
224
259
  const authority = engineHost().config;
@@ -239,13 +274,13 @@ export function createLocalConfigDocument(value, signal) {
239
274
  throw error;
240
275
  }
241
276
  });
242
- });
277
+ }, true);
243
278
  }
244
279
  export function replaceLocalConfigDocument(document, value) {
245
280
  const authority = engineHost().config;
246
281
  if (authority)
247
282
  return authority.replace(document, value);
248
- return queueConfigOperation(() => withLocalConfigFileLock(() => replaceLocalConfigDocumentUnlocked(document, value)));
283
+ return queueConfigOperation(() => withLocalConfigFileLock(() => replaceLocalConfigDocumentUnlocked(document, value)), true);
249
284
  }
250
285
  async function replaceLocalConfigDocumentUnlocked(document, value, signal, review) {
251
286
  const nextBytes = serializedConfig(value);
@@ -353,6 +388,15 @@ async function prepareLocalConfigPath(validateForMigration) {
353
388
  if (!legacy)
354
389
  return canonicalPath;
355
390
  validateForMigration(legacy.parsed);
391
+ const finished = beginConfigMutation();
392
+ try {
393
+ return await migrateLegacyConfig(canonicalPath, legacyPath, legacy);
394
+ }
395
+ finally {
396
+ finished();
397
+ }
398
+ }
399
+ async function migrateLegacyConfig(canonicalPath, legacyPath, legacy) {
356
400
  let installedIdentity;
357
401
  try {
358
402
  installedIdentity = await installPrivateConfigExclusively(canonicalPath, legacy.bytes);
@@ -407,9 +451,7 @@ async function secureIgnoredLegacyIfPresent(filePath) {
407
451
  await handle?.close().catch(() => undefined);
408
452
  }
409
453
  }
410
- function assertCurrentDocument(document) {
411
- const canonical = localConfigPath();
412
- const legacy = legacyLocalConfigPath();
454
+ function assertCurrentDocument(document, canonical = localConfigPath(), legacy = legacyLocalConfigPath()) {
413
455
  const filePath = lstatSync(canonical, { throwIfNoEntry: false }) ? canonical : legacy;
414
456
  const before = lstatSync(filePath, { throwIfNoEntry: false });
415
457
  if (!document) {
@@ -568,7 +610,7 @@ async function configSnapshotStillMatches(filePath, snapshot) {
568
610
  return fileIdentityAndContentsMatch(filePath, snapshot.identity, snapshot.bytes);
569
611
  }
570
612
  export function quarantineAndRemoveConfigIfMatches(filePath, identity, expectedBytes) {
571
- return queueConfigOperation(() => withLocalConfigFileLock(() => quarantineAndRemoveConfigIfMatchesUnlocked(filePath, identity, expectedBytes)));
613
+ return queueConfigOperation(() => withLocalConfigFileLock(() => quarantineAndRemoveConfigIfMatchesUnlocked(filePath, identity, expectedBytes)), true);
572
614
  }
573
615
  async function quarantineAndRemoveConfigIfMatchesUnlocked(filePath, identity, expectedBytes) {
574
616
  const quarantinePath = path.join(path.dirname(filePath), `.${path.basename(filePath)}.${randomUUID()}.migration-retired`);
@@ -634,10 +676,10 @@ async function restoreQuarantinedConfig(filePath, quarantinePath) {
634
676
  // Preserve the quarantine rather than risk deleting settings that changed concurrently.
635
677
  }
636
678
  }
637
- function configMutationLockPath() {
638
- return `${localConfigPath()}.mutation-lock`;
679
+ function configMutationLockPath(configPath = localConfigPath()) {
680
+ return `${configPath}.mutation-lock`;
639
681
  }
640
- export async function withLocalConfigFileLock(run) {
682
+ export async function withLocalConfigFileLock(run, readOnly = false) {
641
683
  const configPath = localConfigPath();
642
684
  await fs.mkdir(path.dirname(configPath), { recursive: true });
643
685
  let compromisedError;
@@ -652,6 +694,8 @@ export async function withLocalConfigFileLock(run) {
652
694
  compromisedError = error;
653
695
  },
654
696
  });
697
+ if (readOnly)
698
+ localReadLock = configPath;
655
699
  try {
656
700
  await assertNoInterruptedConfigReplacement();
657
701
  const result = await run();
@@ -660,6 +704,8 @@ export async function withLocalConfigFileLock(run) {
660
704
  return result;
661
705
  }
662
706
  finally {
707
+ if (readOnly)
708
+ localReadLock = undefined;
663
709
  await release();
664
710
  }
665
711
  }
@@ -701,8 +747,7 @@ async function renameFileWithoutReplacement(source, destination, signal) {
701
747
  signal?.throwIfAborted();
702
748
  await fs.rename(source, destination);
703
749
  }
704
- async function assertNoInterruptedConfigReplacement() {
705
- const configPath = localConfigPath();
750
+ async function assertNoInterruptedConfigReplacement(configPath = localConfigPath()) {
706
751
  if (await pathExists(configPath))
707
752
  return;
708
753
  let names;
@@ -33,7 +33,7 @@ async function operationalConfig(document, setupName, signal) {
33
33
  return config;
34
34
  if (engineHost().ignoreFileOperationsAvailable === false)
35
35
  return requireLegacyOperationConfig(config);
36
- return resolveOperationPolicy(config, setupName, signal, document);
36
+ return resolveOperationPolicy(config, setupName, signal, document && { kind: "checked", document });
37
37
  }
38
38
  export async function loadSettingsConfig(setupName) {
39
39
  return configFromSettings(await readSettingsForCheck(), setupName);
@@ -56,10 +56,31 @@ export async function resolveIgnoreConfig(settings, setupName, signal) {
56
56
  signal?.throwIfAborted();
57
57
  return resolveOperationPolicy(configFromSettings(validateSettingsDocument(settings), setupName), setupName, signal);
58
58
  }
59
+ export function createSettingsConfigView(document) {
60
+ const settings = validateSettingsDocument(document.parsed);
61
+ const ignoreNames = reservedIgnoreFilenames(settings);
62
+ const metadata = (setupName) => projectSettingsConfig(settings, setupName, () => ignoreNames);
63
+ let fingerprint;
64
+ return {
65
+ activeSetupName: settings.activeSyncSetup,
66
+ setupNames: Object.keys(settings.syncSetups),
67
+ metadata,
68
+ async observe(setupName, signal) {
69
+ signal?.throwIfAborted();
70
+ const config = metadata(setupName);
71
+ if (!config.reservedIgnoreNames)
72
+ return config;
73
+ if (engineHost().ignoreFileOperationsAvailable === false)
74
+ return requireLegacyOperationConfig(config);
75
+ fingerprint ??= settingsDocumentFingerprint(document);
76
+ return resolveOperationPolicy(config, setupName, signal, { kind: "view", fingerprint });
77
+ },
78
+ };
79
+ }
59
80
  function settingsDocumentFingerprint(document) {
60
81
  return documentFingerprint(document && { bytes: document.bytes.toString("base64"), identity: document.identity });
61
82
  }
62
- async function resolveOperationPolicy(config, setupName, signal, original) {
83
+ async function resolveOperationPolicy(config, setupName, signal, settingsSource) {
63
84
  if (!config.reservedIgnoreNames)
64
85
  return config;
65
86
  const root = getEngineRoot();
@@ -68,8 +89,9 @@ async function resolveOperationPolicy(config, setupName, signal, original) {
68
89
  if (root !== getEngineRoot())
69
90
  throw new Error("The Pi agent directory changed; reopen the review before continuing.");
70
91
  };
71
- const configDocumentFingerprint = original && settingsDocumentFingerprint(original);
72
- const settingsFingerprint = syncCheckConfigFingerprint(config);
92
+ const original = settingsSource?.kind === "checked" ? settingsSource.document : undefined;
93
+ const configDocumentFingerprint = settingsSource?.kind === "view" ? settingsSource.fingerprint : original && settingsDocumentFingerprint(original);
94
+ const settingsFingerprint = settingsSource?.kind === "view" ? undefined : syncCheckConfigFingerprint(config);
73
95
  const validateSettings = (document) => {
74
96
  validateRoot();
75
97
  if ((original &&
@@ -81,16 +103,21 @@ async function resolveOperationPolicy(config, setupName, signal, original) {
81
103
  };
82
104
  const source = config.pathPolicy === "ignore-file" ? await readIgnoreSource(root, config.ignoreFile, signal) : undefined;
83
105
  validateRoot();
84
- if (original && source && !source.present) {
106
+ if (settingsSource && source && !source.present) {
85
107
  throw new Error(`Ignore file is missing: ${safeTerminalText(path.join(root, source.filename))}. Create it and reopen Pi Sync; starter rules are only a preview.`);
86
108
  }
87
109
  if (original && source)
88
110
  validateSettings(await readActiveLocalConfigDocumentForRepair());
89
- return {
111
+ const observed = {
90
112
  ...config,
91
113
  ...(configDocumentFingerprint ? { configDocumentFingerprint } : {}),
92
114
  ...(source ? { ignorePolicy: compileEffectiveIgnorePolicy(source, ignorePolicyInput(config)) } : {}),
93
115
  ...(source?.identity ? { ignoreSourceIdentity: source.identity } : {}),
116
+ };
117
+ if (settingsSource?.kind === "view")
118
+ return observed;
119
+ return {
120
+ ...observed,
94
121
  validateIgnorePolicy: async () => {
95
122
  validateRoot();
96
123
  await withLockedLocalConfigDocument(async (document, recheck) => {
@@ -121,7 +148,21 @@ function ignorePolicyInput(config) {
121
148
  configuredFilenames: config.reservedIgnoreNames ?? [],
122
149
  };
123
150
  }
151
+ function reservedIgnoreFilenames(settings) {
152
+ const names = new Set();
153
+ for (const { sync } of Object.values(settings.syncSetups)) {
154
+ if (sync.pathPolicy === "ignore-file")
155
+ names.add(validateIgnoreFilename(sync.ignoreFile ?? DEFAULT_IGNORE_FILENAME).toLowerCase());
156
+ }
157
+ if (names.size === 0)
158
+ return undefined;
159
+ names.add(DEFAULT_IGNORE_FILENAME);
160
+ return [...names].sort();
161
+ }
124
162
  export function configFromSettings(settings, setupName) {
163
+ return projectSettingsConfig(settings, setupName, () => reservedIgnoreFilenames(settings));
164
+ }
165
+ function projectSettingsConfig(settings, setupName, getReservedIgnoreNames) {
125
166
  const selectedName = setupName ?? settings.activeSyncSetup;
126
167
  if (!selectedName)
127
168
  throw new Error("No sync setups are configured.");
@@ -134,17 +175,11 @@ export function configFromSettings(settings, setupName) {
134
175
  if (!connection) {
135
176
  throw new Error(`Invalid pi-sync settings: sync setup “${selectedName}” references missing storage connection “${connectionName}”.`);
136
177
  }
137
- const ignoreNames = new Set();
138
- for (const { sync } of Object.values(settings.syncSetups)) {
139
- if (sync.pathPolicy === "ignore-file")
140
- ignoreNames.add(validateIgnoreFilename(sync.ignoreFile ?? DEFAULT_IGNORE_FILENAME).toLowerCase());
141
- }
142
- if (ignoreNames.size > 0)
143
- ignoreNames.add(DEFAULT_IGNORE_FILENAME);
178
+ const reservedIgnoreNames = getReservedIgnoreNames();
144
179
  return {
145
180
  ...resolveSyncConfig(selectedName, setup, connectionName, connection, settings.onSwitch, settings.skipSecretScan ?? false, settings.showStatus ?? true),
146
181
  debug: settings.debug ?? false,
147
- ...(ignoreNames.size > 0 ? { reservedIgnoreNames: [...ignoreNames].sort() } : {}),
182
+ ...(reservedIgnoreNames ? { reservedIgnoreNames } : {}),
148
183
  };
149
184
  }
150
185
  /** A validated setup-facing projection used by manager and settings UI. */
@@ -4,7 +4,8 @@ import path from "node:path";
4
4
  import { assertWithinRoot, isDeniedPath, isPathInside, parentPaths, safeJoin, toPosix } from "../paths.js";
5
5
  import { syncDirectory } from "../state/json-file.js";
6
6
  import { stateDir } from "../state/state-directory.js";
7
- import { compileSyncPolicyExclude, requireLegacyTransferPolicy, sameSnapshotSelection, selectionForSnapshot, } from "../sync/sync-policy.js";
7
+ import { collidingPaths } from "../sync/file-merge-planner.js";
8
+ import { assertSnapshotExcludesDebugLog, compileSyncPolicyExclude, requireLegacyTransferPolicy, sameSnapshotSelection, selectionForSnapshot, } from "../sync/sync-policy.js";
8
9
  import { agentDir } from "./session-paths.js";
9
10
  import { agentDirectoryConfiguredSessionDir, agentDirectoryInventory, createSnapshot, isSessionFilePath, isSessionPath, sessionStorageRoot, snapshotIncludesSessions, snapshotTarget, } from "./snapshot.js";
10
11
  import { assertAgentDirectorySnapshotBound } from "./snapshot-bounds.js";
@@ -12,7 +13,7 @@ import { assertProjectedAgentDirectoryBudget } from "./snapshot-entry-projection
12
13
  import { agentDirectoryPhysicalSessionPath, assertUnexcludedTargets } from "./snapshot-exclude-safety.js";
13
14
  import { decodeBase64Strict } from "./snapshot-payload.js";
14
15
  import { reviewedSnapshotPreimages } from "./snapshot-reviewed-preimages.js";
15
- import { applySnapshotTransaction, recoverPendingSnapshotTransactions } from "./snapshot-transaction.js";
16
+ import { applySnapshotTransaction, recoverPendingSnapshotTransactions, } from "./snapshot-transaction.js";
16
17
  import { ignorePolicyValidator } from "./snapshot-transaction-policy.js";
17
18
  import { IGNORE_SNAPSHOT_VERSION, } from "./snapshot-types.js";
18
19
  function sha256(value) {
@@ -22,6 +23,7 @@ function fileHashMap(snapshot) {
22
23
  return Object.fromEntries(snapshot.files.map((file) => [file.path, file.sha256]));
23
24
  }
24
25
  function assertSnapshotApplyPolicy(snapshot, options) {
26
+ assertSnapshotExcludesDebugLog(snapshot);
25
27
  if (snapshot.version !== IGNORE_SNAPSHOT_VERSION) {
26
28
  requireLegacyTransferPolicy(snapshot);
27
29
  if (options.ignorePolicy)
@@ -77,6 +79,16 @@ export async function applySnapshot(snapshot, protectedRelativePaths = new Set()
77
79
  ]);
78
80
  }
79
81
  const plan = await addTopLevelCaseVariantDeletes(root, protectSnapshotApplyPlan(root, preflightSnapshotApply(root, snapshot, current, options), protectedRelativePaths, sessionDir), snapshot, options);
82
+ const currentHashes = new Map(current.files.map(({ path, sha256 }) => [path, sha256]));
83
+ const dependencies = collidingPaths([...plan.deletes, ...plan.writes.map(({ target }) => target)].map(toPosix));
84
+ const unchangedHashes = new Map();
85
+ for (const file of snapshot.files) {
86
+ if (currentHashes.get(file.path) !== file.sha256)
87
+ continue;
88
+ const target = snapshotTarget(root, file.path, sessionDir);
89
+ if (!dependencies.has(toPosix(target)))
90
+ unchangedHashes.set(target, file.sha256);
91
+ }
80
92
  if (inventory) {
81
93
  assertProjectedAgentDirectoryBudget(inventory, {
82
94
  deletes: plan.deletes,
@@ -85,8 +97,10 @@ export async function applySnapshot(snapshot, protectedRelativePaths = new Set()
85
97
  { target: stateDir(root) },
86
98
  ],
87
99
  }, options);
88
- await preflightSnapshotMutations(root, plan, sessionDir, options);
89
100
  }
101
+ const skipped = inventory
102
+ ? await preflightSnapshotMutations(root, plan, sessionDir, options, unchangedHashes)
103
+ : undefined;
90
104
  if (options.reviewedLocal || inventory) {
91
105
  const images = reviewedSnapshotPreimages(root, sessionDir, current.files, plan, inventory);
92
106
  const reviewed = options.reviewedLocal;
@@ -102,9 +116,7 @@ export async function applySnapshot(snapshot, protectedRelativePaths = new Set()
102
116
  transactionOptions.expectedPreimages.set(target, image);
103
117
  }
104
118
  }
105
- if (!inventory)
106
- await preflightSnapshotMutations(root, plan, sessionDir, options);
107
- await applySnapshotTransaction(plan, transactionOptions);
119
+ await applySnapshotTransaction(plan, transactionOptions, skipped ?? (await preflightSnapshotMutations(root, plan, sessionDir, options, unchangedHashes)));
108
120
  return appliedFileHashMap(snapshot, current, protectedRelativePaths);
109
121
  }
110
122
  function sameReviewedFiles(scanned, reviewed) {
@@ -242,7 +254,8 @@ function excludedApplyPath(root, options) {
242
254
  return (relative) => excluded(relative) ||
243
255
  (/^sessions(?:\/|$)/iu.test(relative) ? !isSessionFilePath(relative) : physicalSessionPath(relative));
244
256
  }
245
- export async function preflightSnapshotMutations(root, plan, sessionDir, options = {}) {
257
+ export async function preflightSnapshotMutations(root, plan, sessionDir, options = {}, unchangedHashes) {
258
+ const skipped = [];
246
259
  assertMutationCurrent(options);
247
260
  await assertUnexcludedTargets(root, [...plan.deletes, ...plan.writes.map((item) => item.target)], {
248
261
  ...options,
@@ -255,9 +268,17 @@ export async function preflightSnapshotMutations(root, plan, sessionDir, options
255
268
  assertMutationCurrent(options);
256
269
  }
257
270
  for (const item of plan.writes) {
258
- await prepareSnapshotWrite(rootForTarget(root, item.target, sessionDir), item.target, deletePaths, options);
271
+ const stat = await prepareSnapshotWrite(rootForTarget(root, item.target, sessionDir), item.target, deletePaths, options);
259
272
  assertMutationCurrent(options);
273
+ const hash = unchangedHashes?.get(item.target);
274
+ if (hash !== undefined && stat?.isFile() && stat.nlink === 1) {
275
+ const canonical = await fs.realpath(item.target);
276
+ assertMutationCurrent(options);
277
+ if (canonical === item.target)
278
+ skipped.push({ ...item, preimage: `file:${hash}` });
279
+ }
260
280
  }
281
+ return skipped;
261
282
  }
262
283
  function assertMutationCurrent(options) {
263
284
  options.validateMutation?.();
@@ -296,6 +317,7 @@ async function prepareSnapshotWrite(root, target, deletePaths, options) {
296
317
  if (stat?.isDirectory() && !deletePaths.has(target)) {
297
318
  throw new Error(`Refusing to overwrite directory during snapshot apply: ${target}`);
298
319
  }
320
+ return stat;
299
321
  }
300
322
  async function ensureSafeDirectory(root, directory, deletePaths, options) {
301
323
  assertMutationCurrent(options);
@@ -4,7 +4,7 @@ import { pipeline } from "node:stream/promises";
4
4
  import { promisify } from "node:util";
5
5
  import { createGunzip, gzip } from "node:zlib";
6
6
  import { throwIfAborted } from "../sync/signals.js";
7
- import { snapshotSelectionInclude, validateSnapshotSelection } from "../sync/sync-policy.js";
7
+ import { assertSnapshotExcludesDebugLog, snapshotSelectionInclude, validateSnapshotSelection, } from "../sync/sync-policy.js";
8
8
  import { IGNORE_SNAPSHOT_VERSION, isSupportedSnapshotVersion } from "./snapshot-types.js";
9
9
  const VERSION = 1;
10
10
  const MAX_DECOMPRESSED_SNAPSHOT_BYTES = 512 * 1024 * 1024;
@@ -12,6 +12,7 @@ const gzipAsync = promisify(gzip);
12
12
  export async function encodeSnapshot(snapshot) {
13
13
  if (!isSupportedSnapshotVersion(snapshot?.version))
14
14
  throw new Error("Unsupported snapshot format.");
15
+ assertSnapshotExcludesDebugLog(snapshot);
15
16
  if (snapshot.version !== IGNORE_SNAPSHOT_VERSION)
16
17
  snapshotSelectionInclude(snapshot);
17
18
  validateSnapshotSelection(snapshot);
@@ -46,6 +47,7 @@ export async function decodeSnapshot(buffer, options = {}) {
46
47
  }
47
48
  if (parsed.version === IGNORE_SNAPSHOT_VERSION && !isUtf8(payload))
48
49
  throw new Error("Invalid snapshot UTF-8.");
50
+ assertSnapshotExcludesDebugLog(parsed);
49
51
  validateSnapshotSelection(parsed);
50
52
  if (parsed.version !== VERSION) {
51
53
  const { normalizeLocalFields, validatePortableSnapshot } = await import("../sync/local-fields.js");
@@ -1,3 +1,35 @@
1
+ import { createHash } from "node:crypto";
2
+ const checked = new WeakMap();
3
+ function checkPayload(file, message, materialize = false) {
4
+ const { contentBase64, sha256 } = file;
5
+ if (typeof contentBase64 !== "string" || typeof sha256 !== "string")
6
+ throw new Error(message);
7
+ const cacheable = Object.getOwnPropertyDescriptor(file, "contentBase64")?.value === contentBase64 &&
8
+ Object.getOwnPropertyDescriptor(file, "sha256")?.value === sha256;
9
+ const previous = cacheable ? checked.get(file) : undefined;
10
+ if (previous?.contentBase64 === contentBase64 && previous.sha256 === sha256)
11
+ return materialize ? Buffer.from(contentBase64, "base64") : undefined;
12
+ const content = Buffer.from(contentBase64, "base64");
13
+ if (content.toString("base64") !== contentBase64 || createHash("sha256").update(content).digest("hex") !== sha256)
14
+ throw new Error(message);
15
+ if (cacheable)
16
+ checked.set(file, { contentBase64, sha256 });
17
+ return content;
18
+ }
19
+ export function assertSnapshotFilePayload(file, message) {
20
+ checkPayload(file, message);
21
+ }
22
+ export function materializeSnapshotFilePayload(file, message) {
23
+ return checkPayload(file, message, true);
24
+ }
25
+ export function snapshotFileFromBlob(path, content, sha256, message) {
26
+ if (createHash("sha256").update(content).digest("hex") !== sha256)
27
+ throw new Error(message);
28
+ const contentBase64 = content.toString("base64");
29
+ const file = { path, contentBase64, sha256 };
30
+ checked.set(file, { contentBase64, sha256 });
31
+ return file;
32
+ }
1
33
  export function snapshotBase64Size(value, filePath) {
2
34
  if (typeof value !== "string" || value.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}(?![\s\S])/u.test(value))
3
35
  throw new Error(`Invalid base64 content in snapshot file: ${filePath}`);
@@ -125,6 +125,40 @@ async function readStableFile(target, original, guards, consume) {
125
125
  }
126
126
  await recheck(target, original, guards);
127
127
  }
128
+ export async function verifyUnchangedFile(target, content, guards) {
129
+ const stat = await lstat(target, guards);
130
+ if (!stat?.isFile() || stat.nlink !== 1n || stat.size !== BigInt(content.length))
131
+ skippedPreimageChanged();
132
+ await recheckUnchangedFile(target, stat, guards);
133
+ await readStableFile(target, stat, guards, (chunk, offset) => {
134
+ if (!chunk.equals(content.subarray(offset, offset + chunk.length)))
135
+ skippedPreimageChanged();
136
+ });
137
+ return stat;
138
+ }
139
+ export async function recheckUnchangedFile(target, stat, guards) {
140
+ validate(guards);
141
+ let canonical;
142
+ try {
143
+ canonical = await fs.realpath(target);
144
+ }
145
+ catch (error) {
146
+ validate(guards);
147
+ const code = error.code;
148
+ if (code === "ENOENT" || code === "ENOTDIR")
149
+ skippedPreimageChanged();
150
+ throw error;
151
+ }
152
+ validate(guards);
153
+ if (canonical !== target)
154
+ skippedPreimageChanged();
155
+ const current = await lstat(target, guards);
156
+ if (!current || !sameObservation(stat, current))
157
+ skippedPreimageChanged();
158
+ }
159
+ function skippedPreimageChanged() {
160
+ throw new Error("Skipped file preimage changed before apply; snapshot installation refused.");
161
+ }
128
162
  export async function readTransactionJournal(file, guards, maxBytes = MAX_TRANSACTION_JOURNAL_BYTES) {
129
163
  const stat = await lstat(file, guards);
130
164
  if (!stat)
@@ -9,15 +9,15 @@ import { normalizeSyncExclude } from "../sync/exclude-policy.js";
9
9
  import { mergePathIdentity } from "../sync/file-merge-planner.js";
10
10
  import { includeFromSelectionConfig, selectionForSnapshot } from "../sync/sync-policy.js";
11
11
  import { agentDir, configuredSessionDir } from "./session-paths.js";
12
- import { agentDirectoryConfiguredSessionDir } from "./snapshot.js";
12
+ import { agentDirectoryConfiguredSessionDir, scanAgentDirectoryInventory } from "./snapshot.js";
13
13
  import { caseReplacementSpelling, coalesceCaseReplacements } from "./snapshot-case-replacement.js";
14
- import { recheckAgentDirectoryBudget } from "./snapshot-entry-projection.js";
14
+ import { assertProjectedAgentDirectoryBudget, recheckAgentDirectoryBudget } from "./snapshot-entry-projection.js";
15
15
  import { assertUnexcludedTargets } from "./snapshot-exclude-safety.js";
16
16
  import { withMissingTargetQueues, withTargetQueues } from "./snapshot-mutation-queues.js";
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, recheckScopedImage, removeScopedImage, scopedDescendant, scopedIdentity, scopedPathIdentity, scopedTransactionImage, stableScopedIdentity, } from "./snapshot-transaction-images.js";
20
+ import { legacyImage, MAX_TRANSACTION_JOURNAL_BYTES, ownedScopedPostTree, readTransactionJournal, recheckScopedImage, recheckUnchangedFile, removeScopedImage, scopedDescendant, scopedIdentity, scopedPathIdentity, scopedTransactionImage, stableScopedIdentity, verifyUnchangedFile, } from "./snapshot-transaction-images.js";
21
21
  import { indexTransactionPlan } from "./snapshot-transaction-plan.js";
22
22
  import { AGENT_DIRECTORY_JOURNAL_VERSION, assertAllowedTarget, assertRecoveryPolicy, assertSafeParents, BOUND_DIRECTORY_JOURNAL_VERSION, BOUND_INCLUDED_PATHS_JOURNAL_VERSION, IGNORE_POLICY_JOURNAL_VERSION, ignorePolicyValidator, ignoreSourceBinding, isScopedJournal, isStrictlyInside, recoveryPolicyKey, StaleIgnorePolicyError, touchesProtectedTarget, transactionHasSessionTargets, validateJournal, validateJournalPolicy, } from "./snapshot-transaction-policy.js";
23
23
  import { assertNoUnclaimedLegacyStage, buildScopedRecoveryStage, cleanScopedLegacyStage, cleanScopedWorkspace, inspectScopedRecoveryStage, prepareLegacyRecoveryStage, recoveryStagePath, } from "./snapshot-transaction-stage.js";
@@ -25,7 +25,7 @@ import { verifyTarget } from "./snapshot-transaction-verification.js";
25
25
  const JOURNAL_VERSION = 4;
26
26
  class ScopedRemovalError extends Error {
27
27
  }
28
- export async function applySnapshotTransaction(plan, options = {}) {
28
+ 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") {
@@ -90,7 +90,10 @@ export async function applySnapshotTransaction(plan, options = {}) {
90
90
  expectedPreimages.set(target, evidence.image);
91
91
  }
92
92
  }
93
+ const skippedPreimages = new Map(skipped.map(({ target, preimage }) => [target, preimage]));
93
94
  for (const [target, expected] of expectedPreimages) {
95
+ if (skippedPreimages.get(target) === expected)
96
+ continue;
94
97
  if (scoped || options.reservedIgnoreNames?.length)
95
98
  await assertUnexcludedTargets(root, [target], options);
96
99
  const current = scoped ? (await scopedTransactionImage(target, options)).value : await legacyImage(target);
@@ -101,7 +104,29 @@ export async function applySnapshotTransaction(plan, options = {}) {
101
104
  }
102
105
  if (validateIgnorePolicy)
103
106
  await validateIgnorePolicy();
104
- const transaction = await prepareTransaction(coalesced.plan, targets, { ...options, expectedPreimages }, coalesced.replacements);
107
+ const mutationTargets = skipped.length ? targets.filter((target) => !skippedPreimages.has(target)) : targets;
108
+ const writes = skipped.length ? plan.writes.filter(({ target }) => !skippedPreimages.has(target)) : plan.writes;
109
+ if (mutationTargets.length === 0) {
110
+ if (options.validateApplyReview)
111
+ await options.validateApplyReview();
112
+ if (scoped) {
113
+ const pendingStateEntry = stateDir(root);
114
+ const inventory = await scanAgentDirectoryInventory(root, options, pendingStateEntry);
115
+ options.validateMutation?.();
116
+ options.signal?.throwIfAborted();
117
+ assertProjectedAgentDirectoryBudget(inventory, { deletes: [], writes: [{ target: pendingStateEntry }] }, options);
118
+ }
119
+ if (validateIgnorePolicy)
120
+ await validateIgnorePolicy();
121
+ await verifySkippedWrites(root, skipped, heldKeys, options);
122
+ options.validateMutation?.();
123
+ options.signal?.throwIfAborted();
124
+ return;
125
+ }
126
+ const mutationPlan = skipped.length
127
+ ? { ...coalesced.plan, writes: coalesced.plan.writes.filter(({ target }) => !skippedPreimages.has(target)) }
128
+ : coalesced.plan;
129
+ const transaction = await prepareTransaction(mutationPlan, mutationTargets, { ...options, expectedPreimages }, coalesced.replacements);
105
130
  const entriesByTarget = new Map(transaction.journal.entries.flatMap((entry) => [
106
131
  [entry.target, entry],
107
132
  ...(entry.afterTarget ? [[entry.afterTarget, entry]] : []),
@@ -135,7 +160,7 @@ export async function applySnapshotTransaction(plan, options = {}) {
135
160
  await retireRemovalIntent(transaction.directory, transaction.journal, transaction.journal.entries.filter((entry) => entry.removalPending && (entry.afterImage !== "missing" || (entry.postFiles?.length ?? 0) > 0)), options);
136
161
  // Only this uninterrupted call knows which deleted writes have not attempted installation yet.
137
162
  const uninstalledWrites = new Set(transaction.deletedWrites);
138
- for (const item of plan.writes) {
163
+ for (const item of writes) {
139
164
  options.signal?.throwIfAborted();
140
165
  const entry = entriesByTarget.get(item.target);
141
166
  if (!entry)
@@ -194,7 +219,7 @@ export async function applySnapshotTransaction(plan, options = {}) {
194
219
  }
195
220
  options.validateMutation?.();
196
221
  options.signal?.throwIfAborted();
197
- await syncMutationParents(targets, [transaction.journal.root, ...(transaction.journal.sessionRoot ? [transaction.journal.sessionRoot] : [])], options);
222
+ await syncMutationParents(mutationTargets, [transaction.journal.root, ...(transaction.journal.sessionRoot ? [transaction.journal.sessionRoot] : [])], options);
198
223
  options.validateMutation?.();
199
224
  options.signal?.throwIfAborted();
200
225
  if (validateIgnorePolicy)
@@ -202,6 +227,9 @@ export async function applySnapshotTransaction(plan, options = {}) {
202
227
  });
203
228
  if (validateIgnorePolicy)
204
229
  await validateIgnorePolicy();
230
+ await verifySkippedWrites(root, skipped, heldKeys, options);
231
+ options.validateMutation?.();
232
+ options.signal?.throwIfAborted();
205
233
  }
206
234
  catch (error) {
207
235
  // Aborted owners cannot roll back files after another session has replaced them.
@@ -226,6 +254,21 @@ export async function applySnapshotTransaction(plan, options = {}) {
226
254
  await completeTransaction(transaction.directory, transaction.journal);
227
255
  });
228
256
  }
257
+ async function verifySkippedWrites(root, skipped, heldKeys, options) {
258
+ if (!skipped.length)
259
+ return;
260
+ await assertUnexcludedTargets(root, skipped.map(({ target }) => target), options, { recursive: false });
261
+ const sessionRoot = options.sessionDir ? sessionStorageRoot(root, options.sessionDir) : undefined;
262
+ const verified = [];
263
+ for (const { target, content } of skipped) {
264
+ if (!heldKeys.has(target) || touchesProtectedTarget(target, options.protectedTargets))
265
+ throw new Error("Skipped file lost its transaction queue or session protection changed; review is required.");
266
+ await assertSafeParents(root, sessionRoot, target);
267
+ verified.push({ target, stat: await verifyUnchangedFile(target, content, options) });
268
+ }
269
+ for (const { target, stat } of verified)
270
+ await recheckUnchangedFile(target, stat, options);
271
+ }
229
272
  export async function recoverSnapshotTransactionsOnStartup(options = {}) {
230
273
  if (!(await pendingTransactionEntries()).some((entry) => entry.isDirectory()))
231
274
  return;