@narumitw/pi-sync 0.58.1 → 0.59.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 (182) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +9 -5
  3. package/dist/chunks/{agent-candidate-U2NU3GUX.ts → agent-candidate-ZHN7FTZT.ts} +9 -8
  4. package/dist/chunks/{agent-plan-3YXDIJXO.ts → agent-plan-ILFEUJ2E.ts} +12 -11
  5. package/dist/chunks/{agent-plan-3YXDIJXO.ts.map → agent-plan-ILFEUJ2E.ts.map} +1 -1
  6. package/dist/chunks/{agent-refusal-retry-476YGNU5.ts → agent-refusal-retry-HRMHCX2A.ts} +9 -8
  7. package/dist/chunks/{agent-refusal-retry-476YGNU5.ts.map → agent-refusal-retry-HRMHCX2A.ts.map} +1 -1
  8. package/dist/chunks/{agent-store-7GINKTS7.ts → agent-store-CCKN4DPR.ts} +3 -3
  9. package/dist/chunks/{agent-sync-2R4GG2MF.ts → agent-sync-EGA2I5W7.ts} +4 -4
  10. package/dist/chunks/{chunk-CQD2TJHE.ts → chunk-25QCU3LY.ts} +4 -4
  11. package/dist/chunks/{chunk-OJARL2TG.ts → chunk-2UKUKIBI.ts} +4 -4
  12. package/dist/chunks/{chunk-REMGB255.ts → chunk-2ZZJXITS.ts} +16 -5
  13. package/dist/chunks/chunk-2ZZJXITS.ts.map +7 -0
  14. package/dist/chunks/chunk-3JTZF7Z5.ts +77 -0
  15. package/dist/chunks/chunk-3JTZF7Z5.ts.map +7 -0
  16. package/dist/chunks/{chunk-DN4IA7MR.ts → chunk-4NVHHDN2.ts} +2 -2
  17. package/dist/chunks/{chunk-AKMV47YC.ts → chunk-6OFMB6KK.ts} +2 -2
  18. package/dist/chunks/{chunk-45COPAK7.ts → chunk-6XU5HZAN.ts} +6 -6
  19. package/dist/chunks/{chunk-45COPAK7.ts.map → chunk-6XU5HZAN.ts.map} +2 -2
  20. package/dist/chunks/{chunk-Y4UVXOLQ.ts → chunk-6YGRZSCN.ts} +15 -10
  21. package/dist/chunks/chunk-6YGRZSCN.ts.map +7 -0
  22. package/dist/chunks/{chunk-XEODG2PE.ts → chunk-76HID27T.ts} +2 -2
  23. package/dist/chunks/{chunk-7A35ZAVO.ts → chunk-7WYF2KUO.ts} +174 -122
  24. package/dist/chunks/chunk-7WYF2KUO.ts.map +7 -0
  25. package/dist/chunks/{chunk-MMQIEDZ6.ts → chunk-APDNHB2T.ts} +78 -35
  26. package/dist/chunks/chunk-APDNHB2T.ts.map +7 -0
  27. package/dist/chunks/{chunk-U6GXGY5G.ts → chunk-DTPELCPW.ts} +4 -4
  28. package/dist/chunks/{chunk-TZC7GDJE.ts → chunk-ILXMZ2HU.ts} +4 -4
  29. package/dist/chunks/{chunk-CBLTWXAU.ts → chunk-LA3HQMFG.ts} +2 -1
  30. package/dist/chunks/{chunk-CBLTWXAU.ts.map → chunk-LA3HQMFG.ts.map} +2 -2
  31. package/dist/chunks/{chunk-ESKOPQVB.ts → chunk-MKC3PXCN.ts} +53 -32
  32. package/dist/chunks/chunk-MKC3PXCN.ts.map +7 -0
  33. package/dist/chunks/{chunk-MG66XM5U.ts → chunk-NGW4JMBF.ts} +63 -19
  34. package/dist/chunks/chunk-NGW4JMBF.ts.map +7 -0
  35. package/dist/chunks/{chunk-TIMWN2RH.ts → chunk-OQBE2OMB.ts} +13 -14
  36. package/dist/chunks/chunk-OQBE2OMB.ts.map +7 -0
  37. package/dist/chunks/{chunk-MKSMJPVA.ts → chunk-P3YD4ONV.ts} +22 -6
  38. package/dist/chunks/chunk-P3YD4ONV.ts.map +7 -0
  39. package/dist/chunks/{chunk-JYILGR3K.ts → chunk-PQ75RPUP.ts} +3 -3
  40. package/dist/chunks/{chunk-FLHCOJCD.ts → chunk-QQVK2XFC.ts} +13 -6
  41. package/dist/chunks/chunk-QQVK2XFC.ts.map +7 -0
  42. package/dist/chunks/{chunk-WQMYV4DW.ts → chunk-RDOX3VH5.ts} +5 -5
  43. package/dist/chunks/{chunk-6O3EDBRL.ts → chunk-S7D6XWHI.ts} +2 -2
  44. package/dist/chunks/{chunk-7ZIYU5QS.ts → chunk-SHPNS7FM.ts} +7 -7
  45. package/dist/chunks/{chunk-7ZIYU5QS.ts.map → chunk-SHPNS7FM.ts.map} +2 -2
  46. package/dist/chunks/{chunk-GNYGNHFF.ts → chunk-T2TYBLXK.ts} +2 -2
  47. package/dist/chunks/{chunk-6LD5KX55.ts → chunk-UZSDS4HF.ts} +13 -6
  48. package/dist/chunks/chunk-UZSDS4HF.ts.map +7 -0
  49. package/dist/chunks/{chunk-5TSCBBPP.ts → chunk-VPODHKOX.ts} +3 -3
  50. package/dist/chunks/{chunk-BEST45H2.ts → chunk-WEKGW7HV.ts} +17 -8
  51. package/dist/chunks/chunk-WEKGW7HV.ts.map +7 -0
  52. package/dist/chunks/{chunk-KYTT7KV4.ts → chunk-WUHRVSWI.ts} +87 -37
  53. package/dist/chunks/chunk-WUHRVSWI.ts.map +7 -0
  54. package/dist/chunks/{chunk-OVBAW7KV.ts → chunk-XZ3ZTHKR.ts} +19 -9
  55. package/dist/chunks/chunk-XZ3ZTHKR.ts.map +7 -0
  56. package/dist/chunks/{chunk-S5OCYVPS.ts → chunk-YEULK7MK.ts} +3 -3
  57. package/dist/chunks/{command-handler-MRXE5AKK.ts → command-handler-SDGKIQH2.ts} +16 -14
  58. package/dist/chunks/command-handler-SDGKIQH2.ts.map +7 -0
  59. package/dist/chunks/{config-HYG7G5EM.ts → config-J5VZUY4J.ts} +4 -3
  60. package/dist/chunks/{conflict-artifacts-J6WSDCWP.ts → conflict-artifacts-MYSH3L2J.ts} +10 -9
  61. package/dist/chunks/{conflict-review-GXA6Y7KY.ts → conflict-review-J6ZSPNWL.ts} +21 -20
  62. package/dist/chunks/{conflict-review-GXA6Y7KY.ts.map → conflict-review-J6ZSPNWL.ts.map} +1 -1
  63. package/dist/chunks/{continuous-record-EPHGR2DU.ts → continuous-record-OM64J27R.ts} +4 -4
  64. package/dist/chunks/{continuous-sync-FAFNLEUW.ts → continuous-sync-BH5SWIRV.ts} +22 -17
  65. package/dist/chunks/continuous-sync-BH5SWIRV.ts.map +7 -0
  66. package/dist/chunks/{file-selection-IELTXSGZ.ts → file-selection-7HEVPO4T.ts} +11 -8
  67. package/dist/chunks/file-selection-7HEVPO4T.ts.map +7 -0
  68. package/dist/chunks/{git-backend-KHD36W27.ts → git-backend-6CKI6CUG.ts} +12 -15
  69. package/dist/chunks/{git-backend-KHD36W27.ts.map → git-backend-6CKI6CUG.ts.map} +2 -2
  70. package/dist/chunks/{local-fields-JEKAPZKD.ts → local-fields-SR7PH66U.ts} +6 -5
  71. package/dist/chunks/{manager-result-dispatcher-XCYPW7RC.ts → manager-result-dispatcher-CXUP5WDP.ts} +15 -14
  72. package/dist/chunks/{manager-ui-AY34N4UY.ts → manager-ui-65ZETN6F.ts} +168 -51
  73. package/dist/chunks/manager-ui-65ZETN6F.ts.map +7 -0
  74. package/dist/chunks/{merge-baseline-store-65GKUMXI.ts → merge-baseline-store-4Y2X7P2D.ts} +4 -3
  75. package/dist/chunks/{remote-selection-ui-MYM2YCPF.ts → remote-selection-ui-W55BQDJQ.ts} +14 -13
  76. package/dist/chunks/{s3-backend-L24UZ6IK.ts → s3-backend-FDK7JSDQ.ts} +8 -7
  77. package/dist/chunks/{s3-backend-L24UZ6IK.ts.map → s3-backend-FDK7JSDQ.ts.map} +1 -1
  78. package/dist/chunks/{setup-switch-KLGESLQX.ts → setup-switch-AB27ADDI.ts} +5 -4
  79. package/dist/chunks/{setup-wizard-ZQAK35BP.ts → setup-wizard-5FILKFLQ.ts} +6 -5
  80. package/dist/chunks/{setup-wizard-ZQAK35BP.ts.map → setup-wizard-5FILKFLQ.ts.map} +1 -1
  81. package/dist/chunks/{snapshot-RGNDYT6A.ts → snapshot-G3W2GOGB.ts} +5 -4
  82. package/dist/chunks/{snapshot-transaction-26BQO36S.ts → snapshot-transaction-SGRUWT73.ts} +6 -5
  83. package/dist/chunks/{sync-inspection-MOMLGUTD.ts → sync-inspection-MDYHZHT7.ts} +10 -9
  84. package/dist/chunks/{sync-operations-45APGOL3.ts → sync-operations-ZAUP65FH.ts} +40 -29
  85. package/dist/chunks/sync-operations-ZAUP65FH.ts.map +7 -0
  86. package/dist/chunks/{sync-state-7L4NT7W2.ts → sync-state-H4TFZZ7S.ts} +7 -6
  87. package/dist/chunks/{webdav-backend-3ZCACILP.ts → webdav-backend-UNMIAXM5.ts} +7 -6
  88. package/dist/chunks/{webdav-backend-3ZCACILP.ts.map → webdav-backend-UNMIAXM5.ts.map} +1 -1
  89. package/dist/index.ts +26 -19
  90. package/dist/index.ts.map +2 -2
  91. package/docs/exclude-policy-audit.md +54 -0
  92. package/docs/exclude-review-ledger.md +36 -0
  93. package/docs/tui-contract.md +1 -1
  94. package/package.json +2 -1
  95. package/skills/configure-pi-sync/SKILL.md +4 -3
  96. package/skills/configure-pi-sync/references/configuration.md +72 -13
  97. package/src/backends/git/git-storage.ts +12 -11
  98. package/src/commands/command-execution.ts +2 -2
  99. package/src/settings/config.ts +9 -3
  100. package/src/settings/settings-management.ts +4 -3
  101. package/src/settings/settings-types.ts +4 -1
  102. package/src/settings/settings-validation.ts +8 -4
  103. package/src/snapshot/session-paths.ts +1 -0
  104. package/src/snapshot/snapshot-apply.ts +23 -7
  105. package/src/snapshot/snapshot-codec.ts +12 -3
  106. package/src/snapshot/snapshot-exclude-safety.ts +44 -0
  107. package/src/snapshot/snapshot-transaction.ts +12 -0
  108. package/src/snapshot/snapshot-types.ts +4 -4
  109. package/src/snapshot/snapshot.ts +71 -30
  110. package/src/state/merge-baseline-store.ts +9 -1
  111. package/src/state/state-types.ts +1 -0
  112. package/src/sync/automatic-sync.ts +7 -2
  113. package/src/sync/continuous-watch.ts +4 -2
  114. package/src/sync/exclude-policy.ts +84 -0
  115. package/src/sync/local-fields.ts +15 -4
  116. package/src/sync/merge-apply.ts +6 -1
  117. package/src/sync/merge-journal.ts +12 -3
  118. package/src/sync/merged-sync.ts +17 -12
  119. package/src/sync/partial-progress.ts +1 -0
  120. package/src/sync/remote-snapshot.ts +7 -8
  121. package/src/sync/sync-decision.ts +11 -1
  122. package/src/sync/sync-inspection.ts +3 -1
  123. package/src/sync/sync-mutations.ts +11 -4
  124. package/src/sync/sync-policy.ts +101 -37
  125. package/src/sync/sync-queries.ts +13 -3
  126. package/src/sync/sync-state.ts +16 -10
  127. package/src/ui/excluded-paths-ui.ts +106 -0
  128. package/src/ui/file-selection.ts +6 -3
  129. package/src/ui/manager-state.ts +11 -5
  130. package/src/ui/remote-selection-ui.ts +73 -10
  131. package/src/ui/settings-ui.ts +20 -5
  132. package/src/ui/setup/setup-actions.ts +1 -1
  133. package/src/ui/setup/setup-switcher.ts +3 -2
  134. package/src/ui/storage-connections-ui.ts +2 -2
  135. package/src/ui/sync-attention.ts +17 -3
  136. package/src/ui/sync-format.ts +13 -1
  137. package/dist/chunks/chunk-6LD5KX55.ts.map +0 -7
  138. package/dist/chunks/chunk-7A35ZAVO.ts.map +0 -7
  139. package/dist/chunks/chunk-BEST45H2.ts.map +0 -7
  140. package/dist/chunks/chunk-ESKOPQVB.ts.map +0 -7
  141. package/dist/chunks/chunk-FLHCOJCD.ts.map +0 -7
  142. package/dist/chunks/chunk-KYTT7KV4.ts.map +0 -7
  143. package/dist/chunks/chunk-MG66XM5U.ts.map +0 -7
  144. package/dist/chunks/chunk-MKSMJPVA.ts.map +0 -7
  145. package/dist/chunks/chunk-MMQIEDZ6.ts.map +0 -7
  146. package/dist/chunks/chunk-OVBAW7KV.ts.map +0 -7
  147. package/dist/chunks/chunk-REMGB255.ts.map +0 -7
  148. package/dist/chunks/chunk-TIMWN2RH.ts.map +0 -7
  149. package/dist/chunks/chunk-Y4UVXOLQ.ts.map +0 -7
  150. package/dist/chunks/command-handler-MRXE5AKK.ts.map +0 -7
  151. package/dist/chunks/continuous-sync-FAFNLEUW.ts.map +0 -7
  152. package/dist/chunks/file-selection-IELTXSGZ.ts.map +0 -7
  153. package/dist/chunks/manager-ui-AY34N4UY.ts.map +0 -7
  154. package/dist/chunks/sync-operations-45APGOL3.ts.map +0 -7
  155. /package/dist/chunks/{agent-candidate-U2NU3GUX.ts.map → agent-candidate-ZHN7FTZT.ts.map} +0 -0
  156. /package/dist/chunks/{agent-store-7GINKTS7.ts.map → agent-store-CCKN4DPR.ts.map} +0 -0
  157. /package/dist/chunks/{agent-sync-2R4GG2MF.ts.map → agent-sync-EGA2I5W7.ts.map} +0 -0
  158. /package/dist/chunks/{chunk-CQD2TJHE.ts.map → chunk-25QCU3LY.ts.map} +0 -0
  159. /package/dist/chunks/{chunk-OJARL2TG.ts.map → chunk-2UKUKIBI.ts.map} +0 -0
  160. /package/dist/chunks/{chunk-DN4IA7MR.ts.map → chunk-4NVHHDN2.ts.map} +0 -0
  161. /package/dist/chunks/{chunk-AKMV47YC.ts.map → chunk-6OFMB6KK.ts.map} +0 -0
  162. /package/dist/chunks/{chunk-XEODG2PE.ts.map → chunk-76HID27T.ts.map} +0 -0
  163. /package/dist/chunks/{chunk-U6GXGY5G.ts.map → chunk-DTPELCPW.ts.map} +0 -0
  164. /package/dist/chunks/{chunk-TZC7GDJE.ts.map → chunk-ILXMZ2HU.ts.map} +0 -0
  165. /package/dist/chunks/{chunk-JYILGR3K.ts.map → chunk-PQ75RPUP.ts.map} +0 -0
  166. /package/dist/chunks/{chunk-WQMYV4DW.ts.map → chunk-RDOX3VH5.ts.map} +0 -0
  167. /package/dist/chunks/{chunk-6O3EDBRL.ts.map → chunk-S7D6XWHI.ts.map} +0 -0
  168. /package/dist/chunks/{chunk-GNYGNHFF.ts.map → chunk-T2TYBLXK.ts.map} +0 -0
  169. /package/dist/chunks/{chunk-5TSCBBPP.ts.map → chunk-VPODHKOX.ts.map} +0 -0
  170. /package/dist/chunks/{chunk-S5OCYVPS.ts.map → chunk-YEULK7MK.ts.map} +0 -0
  171. /package/dist/chunks/{config-HYG7G5EM.ts.map → config-J5VZUY4J.ts.map} +0 -0
  172. /package/dist/chunks/{conflict-artifacts-J6WSDCWP.ts.map → conflict-artifacts-MYSH3L2J.ts.map} +0 -0
  173. /package/dist/chunks/{continuous-record-EPHGR2DU.ts.map → continuous-record-OM64J27R.ts.map} +0 -0
  174. /package/dist/chunks/{local-fields-JEKAPZKD.ts.map → local-fields-SR7PH66U.ts.map} +0 -0
  175. /package/dist/chunks/{manager-result-dispatcher-XCYPW7RC.ts.map → manager-result-dispatcher-CXUP5WDP.ts.map} +0 -0
  176. /package/dist/chunks/{merge-baseline-store-65GKUMXI.ts.map → merge-baseline-store-4Y2X7P2D.ts.map} +0 -0
  177. /package/dist/chunks/{remote-selection-ui-MYM2YCPF.ts.map → remote-selection-ui-W55BQDJQ.ts.map} +0 -0
  178. /package/dist/chunks/{setup-switch-KLGESLQX.ts.map → setup-switch-AB27ADDI.ts.map} +0 -0
  179. /package/dist/chunks/{snapshot-RGNDYT6A.ts.map → snapshot-G3W2GOGB.ts.map} +0 -0
  180. /package/dist/chunks/{snapshot-transaction-26BQO36S.ts.map → snapshot-transaction-SGRUWT73.ts.map} +0 -0
  181. /package/dist/chunks/{sync-inspection-MOMLGUTD.ts.map → sync-inspection-MDYHZHT7.ts.map} +0 -0
  182. /package/dist/chunks/{sync-state-7L4NT7W2.ts.map → sync-state-H4TFZZ7S.ts.map} +0 -0
@@ -10,7 +10,7 @@ import { throwIfAborted } from "../sync/signals.js";
10
10
  import { syncErrorGuidance } from "../sync/sync-error-guidance.js";
11
11
  import { isSyncDecisionRequiredError, SetupPullRequiresUiError } from "../sync/sync-errors.js";
12
12
  import type { SyncLoaders } from "../sync/sync-loaders.js";
13
- import { RemoteSelectionMismatchError } from "../sync/sync-policy.js";
13
+ import { RemoteSelectionMismatchError, syncSessionsSelected } from "../sync/sync-policy.js";
14
14
  import { automaticSyncSummary } from "../ui/automatic-sync-summary.js";
15
15
  import type { RunRouteResult } from "../ui/cancellable-operation.js";
16
16
  import { trackOperationDialogs } from "../ui/operation-dialogs.js";
@@ -272,7 +272,7 @@ async function showConfig(ctx: ExtensionCommandContext, options: CommandOptions)
272
272
  `autonomous sync: ${config.agentMode ? "On" : "Off"}`,
273
273
  `continuous sync: ${config.continuous ? (config.agentMode ? "On" : "paused; Autonomous sync is Off") : "Off"}`,
274
274
  `included content: ${config.include.join(", ") || "none"}`,
275
- `sessions: ${config.include.includes("sessions") ? "included" : "not included"}`,
275
+ `sessions: ${syncSessionsSelected(config) ? "included" : "not included"}`,
276
276
  `settings file: ${localConfigPath()}`,
277
277
  ...warnings,
278
278
  ].join("\n"),
@@ -2,8 +2,9 @@ import { createHash } from "node:crypto";
2
2
  import { backendIdentityCoordinates } from "../backends/backend-identity.js";
3
3
  import { normalizeGitBranch, normalizeGitDirectory, normalizeGitRemote } from "../backends/git/git-config.js";
4
4
  import { normalizeWebDavPath, normalizeWebDavUrl } from "../backends/webdav/webdav-config.js";
5
+ import { normalizeSyncExclude } from "../sync/exclude-policy.js";
5
6
  import { normalizeLocalFields } from "../sync/local-field-policy.js";
6
- import { normalizeSyncInclude } from "../sync/sync-policy.js";
7
+ import { normalizeSyncInclude, syncSessionsSelected } from "../sync/sync-policy.js";
7
8
  import { localConfigPath, readActiveLocalConfigDocumentForRepair } from "./config-file.js";
8
9
  import { requireSettings } from "./settings-store.js";
9
10
  import type {
@@ -78,6 +79,7 @@ export async function loadPartialConfig(setupName?: string): Promise<PartialConf
78
79
  setupName: config.setupName,
79
80
  ...storageReviewFromConfig(config),
80
81
  include: [...config.include],
82
+ ...(config.exclude === undefined ? {} : { exclude: [...config.exclude] }),
81
83
  automatic: config.automatic,
82
84
  automaticTransfer: config.automaticTransfer ?? false,
83
85
  agentMode: config.agentMode ?? false,
@@ -124,6 +126,9 @@ export function syncConfigReviewIdentity(config: AnySyncConfig) {
124
126
  config.partialSync ?? false,
125
127
  // Preserve existing Off identities and cached candidates across the upgrade.
126
128
  ...(config.continuous ? ["continuous"] : []),
129
+ ...(config.exclude === undefined
130
+ ? []
131
+ : ["exclude", normalizeSyncExclude(config.exclude).map((rule) => rule.toLowerCase())]),
127
132
  ]);
128
133
  }
129
134
 
@@ -169,6 +174,7 @@ function resolveSyncConfig(
169
174
  storagePath,
170
175
  snapshotIdentity: namespace,
171
176
  include,
177
+ ...(setup.sync.exclude === undefined ? {} : { exclude: normalizeSyncExclude(setup.sync.exclude) }),
172
178
  automatic: setup.sync.automatic,
173
179
  automaticTransfer: setup.sync.automaticTransfer ?? false,
174
180
  agentMode: setup.sync.agentMode ?? false,
@@ -238,8 +244,8 @@ export function sessionTokenWarnings(config: { endpoint?: string; sessionToken?:
238
244
  ];
239
245
  }
240
246
 
241
- export function syncSessionsWarnings(config: { include: readonly string[] }) {
242
- if (!config.include.includes("sessions")) return [];
247
+ export function syncSessionsWarnings(config: { include: readonly string[]; exclude?: readonly string[] }) {
248
+ if (!syncSessionsSelected(config)) return [];
243
249
  return [
244
250
  "sessions: included; Pi session JSONL can contain prompts, tool output, file paths, images, and secrets. Sync sessions only to storage you trust.",
245
251
  ];
@@ -125,6 +125,7 @@ export async function updateSyncSetup(
125
125
  expectedInclude?: readonly string[];
126
126
  expectedConnection?: StorageConnectionSettings;
127
127
  expectedConfigFingerprint?: string;
128
+ upgradeExclude?: boolean;
128
129
  signal?: AbortSignal;
129
130
  } = {},
130
131
  ) {
@@ -169,7 +170,7 @@ export async function updateSyncSetup(
169
170
  }
170
171
  const nextSetups = { ...settings.syncSetups, [name]: nextSetup };
171
172
  assertUniqueLocations(nextSetups, settings.storageConnections);
172
- return { ...settings, syncSetups: nextSetups };
173
+ return { ...settings, ...(options.upgradeExclude ? { version: 6 as const } : {}), syncSetups: nextSetups };
173
174
  }, options.signal);
174
175
  }
175
176
 
@@ -207,8 +208,8 @@ export async function removeStorageConnection(name: string, signal?: AbortSignal
207
208
 
208
209
  async function updateSettings(update: (settings: PiSyncSettingsV3) => PiSyncSettingsV3, signal?: AbortSignal) {
209
210
  return updateLocalConfig((settings) => {
210
- if (settings.version !== 3 && settings.version !== 4 && settings.version !== 5) {
211
- throw new Error("Storage connections and sync setups require version 3 or 4 or 5 pi-sync settings.");
211
+ if (settings.version !== 3 && settings.version !== 4 && settings.version !== 5 && settings.version !== 6) {
212
+ throw new Error("Storage connections and sync setups require version 3, 4, 5 or 6 pi-sync settings.");
212
213
  }
213
214
  return update(settings);
214
215
  }, signal);
@@ -78,6 +78,7 @@ export type SyncSetupStorageSettings =
78
78
 
79
79
  export interface SyncPolicySettings {
80
80
  include: string[];
81
+ exclude?: string[];
81
82
  automatic: boolean;
82
83
  /** Explicit opt-in, separate from the legacy observe/shutdown policy. */
83
84
  automaticTransfer?: boolean;
@@ -100,7 +101,7 @@ export interface SyncSetupSettings {
100
101
  }
101
102
 
102
103
  export interface PiSyncSettingsV3 {
103
- version: 3 | 4 | 5;
104
+ version: 3 | 4 | 5 | 6;
104
105
  activeSyncSetup?: string;
105
106
  onSwitch: OnSwitchAction;
106
107
  skipSecretScan?: boolean;
@@ -118,6 +119,7 @@ export interface SyncConfig<Backend extends ResolvedSyncBackend = ResolvedS3Back
118
119
  /** Snapshot/wire identity retained behind the settings normalization boundary. */
119
120
  snapshotIdentity: string;
120
121
  include: string[];
122
+ exclude?: string[];
121
123
  automatic: boolean;
122
124
  automaticTransfer?: boolean;
123
125
  agentMode?: boolean;
@@ -143,6 +145,7 @@ export interface PartialConfig {
143
145
  storageKind: StorageConnectionType;
144
146
  storagePath: string;
145
147
  include: string[];
148
+ exclude?: string[];
146
149
  automatic: boolean;
147
150
  automaticTransfer?: boolean;
148
151
  agentMode?: boolean;
@@ -12,6 +12,7 @@ import {
12
12
  normalizeWebDavUrl,
13
13
  validateWebDavCredentials,
14
14
  } from "../backends/webdav/webdav-config.js";
15
+ import { normalizeSyncExclude } from "../sync/exclude-policy.js";
15
16
  import { normalizeLocalFields } from "../sync/local-field-policy.js";
16
17
  import { normalizeSyncInclude } from "../sync/sync-policy.js";
17
18
  import { localConfigPath } from "./config-file.js";
@@ -34,9 +35,9 @@ export function normalizeOnSwitch(value: unknown): OnSwitchAction {
34
35
  }
35
36
 
36
37
  export function validateSettingsDocument(value: Record<string, unknown>): PiSyncSettingsV3 {
37
- if (value.version !== 3 && value.version !== 4 && value.version !== 5) {
38
+ if (value.version !== 3 && value.version !== 4 && value.version !== 5 && value.version !== 6) {
38
39
  throw new Error(
39
- `Unsupported pi-sync settings: version 3 or 4 or 5 is required. Keep the existing ${path.basename(localConfigPath())} for recovery and use a compatible pi-sync client or review a separate supported setup; do not downgrade portable field policies. pi-sync will not migrate or overwrite unsupported settings.`,
40
+ `Unsupported pi-sync settings: version 3, 4, 5 or 6 is required. Keep the existing ${path.basename(localConfigPath())} for recovery and use a compatible pi-sync client or review a separate supported setup; do not downgrade portable field policies. pi-sync will not migrate or overwrite unsupported settings.`,
40
41
  );
41
42
  }
42
43
  rejectLegacyFields(
@@ -101,12 +102,14 @@ export function validateSettingsDocument(value: Record<string, unknown>): PiSync
101
102
  }
102
103
  for (const setup of Object.values(syncSetups)) {
103
104
  const policy = (setup as SyncSetupSettings).sync;
104
- if (policy.localFields !== undefined && value.version !== 4 && value.version !== 5)
105
+ if (policy.localFields !== undefined && value.version !== 4 && value.version !== 5 && value.version !== 6)
105
106
  throw new Error("localFields requires explicit settings version 4; older binaries must refuse portable state.");
106
107
  }
107
108
  for (const setup of Object.values(syncSetups)) {
108
109
  const policy = (setup as SyncSetupSettings).sync;
109
- if ((policy.mergeContent || policy.partialSync) && value.version !== 5)
110
+ if (policy.exclude !== undefined && value.version !== 6)
111
+ throw new Error("sync.exclude requires explicit settings version 6; older clients must refuse excluded content.");
112
+ if ((policy.mergeContent || policy.partialSync) && value.version !== 5 && value.version !== 6)
110
113
  throw new Error("Content/partial sync requires explicit settings version 5.");
111
114
  }
112
115
  validateUniqueRemoteSyncSetups(syncSetups, storageConnections);
@@ -216,6 +219,7 @@ function validateSyncSetup(name: string, value: Record<string, unknown>, connect
216
219
  throw new Error(`Invalid pi-sync settings: sync setup “${name}” is missing sync.include.`);
217
220
  }
218
221
  const include = normalizeSyncInclude(sync.include);
222
+ normalizeSyncExclude(sync.exclude);
219
223
  const localFields = normalizeLocalFields(sync.localFields);
220
224
  if (localFields.length > 0 && !include.includes("settings.json"))
221
225
  throw new Error("Nonempty localFields requires settings.json in sync.include.");
@@ -105,6 +105,7 @@ export function snapshotOptionsForContext(
105
105
  ): SnapshotOptions {
106
106
  return {
107
107
  include: config.include,
108
+ ...(config.exclude === undefined ? {} : { exclude: config.exclude }),
108
109
  sessionDir: sessionDirFromContext(ctx),
109
110
  };
110
111
  }
@@ -4,6 +4,7 @@ import fs from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import { assertWithinRoot, isDeniedPath, isPathInside, parentPaths, safeJoin, toPosix } from "../paths.js";
6
6
  import { syncDirectory } from "../state/json-file.js";
7
+ import { compileSyncExclude } from "../sync/exclude-policy.js";
7
8
  import { agentDir } from "./session-paths.js";
8
9
  import {
9
10
  createSnapshot,
@@ -13,6 +14,7 @@ import {
13
14
  snapshotIncludesSessions,
14
15
  snapshotTarget,
15
16
  } from "./snapshot.js";
17
+ import { assertUnexcludedTargets } from "./snapshot-exclude-safety.js";
16
18
  import { applySnapshotTransaction, recoverPendingSnapshotTransactions } from "./snapshot-transaction.js";
17
19
  import type { Snapshot, SnapshotApplyPlan, SnapshotOptions } from "./snapshot-types.js";
18
20
 
@@ -30,6 +32,7 @@ export async function applySnapshot(
30
32
  options: Pick<
31
33
  SnapshotOptions,
32
34
  | "include"
35
+ | "exclude"
33
36
  | "sessionDir"
34
37
  | "syncFiles"
35
38
  | "syncSessions"
@@ -41,16 +44,21 @@ export async function applySnapshot(
41
44
  ) {
42
45
  const root = agentDir();
43
46
  const { sessionDir } = options;
47
+ const excluded = compileSyncExclude(options.exclude);
48
+ snapshot = { ...snapshot, files: snapshot.files.filter((file) => !excluded(file.path)) };
44
49
  const transactionOptions = {
45
50
  sessionDir,
51
+ exclude: options.exclude,
46
52
  signal: options.signal,
47
53
  validateMutation: options.validateMutation,
48
54
  protectedTargets: [...protectedRelativePaths].map((relative) => snapshotTarget(root, relative, sessionDir)),
49
55
  expectedPreimages: new Map(
50
- Object.entries(options.expectedFileHashes ?? {}).map(([relative, hash]) => [
51
- snapshotTarget(root, relative, sessionDir),
52
- hash === null ? "missing" : `file:${hash}`,
53
- ]),
56
+ Object.entries(options.expectedFileHashes ?? {})
57
+ .filter(([relative]) => !excluded(relative))
58
+ .map(([relative, hash]) => [
59
+ snapshotTarget(root, relative, sessionDir),
60
+ hash === null ? "missing" : `file:${hash}`,
61
+ ]),
54
62
  ),
55
63
  };
56
64
  options.validateMutation?.();
@@ -64,7 +72,7 @@ export async function applySnapshot(
64
72
  root,
65
73
  protectSnapshotApplyPlan(
66
74
  root,
67
- preflightSnapshotApply(root, snapshot, current, { sessionDir }),
75
+ preflightSnapshotApply(root, snapshot, current, { sessionDir, exclude: options.exclude }),
68
76
  protectedRelativePaths,
69
77
  sessionDir,
70
78
  ),
@@ -79,12 +87,13 @@ export function preflightSnapshotApply(
79
87
  root: string,
80
88
  snapshot: Snapshot,
81
89
  current: Snapshot,
82
- options: { sessionDir?: string } = {},
90
+ options: { sessionDir?: string; exclude?: string[] } = {},
83
91
  ): SnapshotApplyPlan {
84
92
  const seenPaths = new Set<string>();
85
93
  const remotePaths = new Set<string>();
86
94
  const writes: Array<{ target: string; content: Buffer }> = [];
87
95
  const deletes: string[] = [];
96
+ const excluded = compileSyncExclude(options.exclude);
88
97
 
89
98
  for (const file of snapshot.files) {
90
99
  const normalized = toPosix(file.path);
@@ -94,6 +103,7 @@ export function preflightSnapshotApply(
94
103
  if (isSessionPath(normalized) && !isSessionFilePath(normalized)) {
95
104
  throw new Error(`Unsafe session path in snapshot: ${file.path}`);
96
105
  }
106
+ if (excluded(normalized)) continue;
97
107
  if (seenPaths.has(normalized)) throw new Error(`Duplicate path in snapshot: ${normalized}`);
98
108
  seenPaths.add(normalized);
99
109
  remotePaths.add(normalized);
@@ -107,6 +117,7 @@ export function preflightSnapshotApply(
107
117
  const deletePaths = new Set<string>();
108
118
  for (const file of current.files) {
109
119
  const normalized = toPosix(file.path);
120
+ if (excluded(normalized)) continue;
110
121
  if (!remotePaths.has(normalized)) {
111
122
  deletePaths.add(snapshotTarget(root, normalized, options.sessionDir));
112
123
  }
@@ -205,7 +216,7 @@ function decodeBase64Strict(value: string, filePath: string) {
205
216
  return Buffer.from(value, "base64");
206
217
  }
207
218
 
208
- type MutationGuards = Pick<SnapshotOptions, "signal" | "validateMutation">;
219
+ type MutationGuards = Pick<SnapshotOptions, "signal" | "validateMutation" | "exclude">;
209
220
 
210
221
  export async function preflightSnapshotMutations(
211
222
  root: string,
@@ -213,6 +224,11 @@ export async function preflightSnapshotMutations(
213
224
  sessionDir?: string,
214
225
  options: MutationGuards = {},
215
226
  ) {
227
+ assertMutationCurrent(options);
228
+ await assertUnexcludedTargets(root, [...plan.deletes, ...plan.writes.map((item) => item.target)], {
229
+ ...options,
230
+ sessionDir,
231
+ });
216
232
  assertMutationCurrent(options);
217
233
  const deletePaths = new Set(plan.deletes);
218
234
  for (const target of plan.deletes) {
@@ -3,7 +3,7 @@ import { pipeline } from "node:stream/promises";
3
3
  import { promisify } from "node:util";
4
4
  import { createGunzip, gzip } from "node:zlib";
5
5
  import { throwIfAborted } from "../sync/signals.js";
6
- import { snapshotSelectionInclude } from "../sync/sync-policy.js";
6
+ import { snapshotSelectionInclude, validateSnapshotSelection } from "../sync/sync-policy.js";
7
7
  import type { Snapshot } from "./snapshot-types.js";
8
8
 
9
9
  const VERSION = 1;
@@ -12,6 +12,11 @@ const gzipAsync = promisify(gzip);
12
12
 
13
13
  export async function encodeSnapshot(snapshot: Snapshot) {
14
14
  snapshotSelectionInclude(snapshot);
15
+ validateSnapshotSelection(snapshot);
16
+ if (snapshot.version === 4) {
17
+ const { validatePortableSnapshot } = await import("../sync/local-fields.js");
18
+ validatePortableSnapshot(snapshot);
19
+ }
15
20
  return gzipAsync(Buffer.from(JSON.stringify(snapshot), "utf8"));
16
21
  }
17
22
 
@@ -37,10 +42,14 @@ export async function decodeSnapshot(
37
42
  await pipeline(Readable.from([buffer]), createGunzip(), sink, { signal: options.signal });
38
43
  throwIfAborted(options.signal);
39
44
  const parsed = JSON.parse(Buffer.concat(chunks, total).toString("utf8")) as Snapshot;
40
- if ((parsed.version !== VERSION && parsed.version !== 2 && parsed.version !== 3) || !Array.isArray(parsed.files)) {
45
+ if (
46
+ (parsed.version !== VERSION && parsed.version !== 2 && parsed.version !== 3 && parsed.version !== 4) ||
47
+ !Array.isArray(parsed.files)
48
+ ) {
41
49
  throw new Error("Unsupported snapshot format.");
42
50
  }
43
- if (parsed.version === 2 || parsed.version === 3) {
51
+ validateSnapshotSelection(parsed);
52
+ if (parsed.version === 2 || parsed.version === 3 || parsed.version === 4) {
44
53
  const { normalizeLocalFields, validatePortableSnapshot } = await import("../sync/local-fields.js");
45
54
  validatePortableSnapshot(parsed);
46
55
  if (parsed.localFields !== undefined) parsed.localFields = normalizeLocalFields(parsed.localFields);
@@ -0,0 +1,44 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { isPathInside, toPosix } from "../paths.js";
4
+ import { compileSyncExclude } from "../sync/exclude-policy.js";
5
+ import { sessionStorageRoot } from "./snapshot-paths.js";
6
+
7
+ /** Metadata-only preflight: an ancestor replacement must not capture/remove excluded descendants. */
8
+ export async function assertUnexcludedTargets(
9
+ root: string,
10
+ targets: Iterable<string>,
11
+ options: { exclude?: readonly string[]; sessionDir?: string; signal?: AbortSignal; validateMutation?: () => void },
12
+ ) {
13
+ if (!options.exclude?.length) return;
14
+ const excluded = compileSyncExclude(options.exclude);
15
+ const sessionRoot = sessionStorageRoot(root, options.sessionDir);
16
+ let visited = 0;
17
+ const validate = () => {
18
+ options.signal?.throwIfAborted();
19
+ options.validateMutation?.();
20
+ };
21
+ async function visit(target: string): Promise<void> {
22
+ validate();
23
+ if (++visited > 16_384)
24
+ throw new Error("Exclude safety preflight exceeds its path bound; review a smaller transfer.");
25
+ const candidates: string[] = [];
26
+ if (isPathInside(root, target)) candidates.push(toPosix(path.relative(root, target)));
27
+ if (isPathInside(sessionRoot, target)) candidates.push(`sessions/${toPosix(path.relative(sessionRoot, target))}`);
28
+ if (candidates.some(excluded))
29
+ throw new Error("Transfer would replace an excluded path or directory descendant; no replacement is authorized.");
30
+ try {
31
+ const stat = await fs.lstat(target);
32
+ validate();
33
+ if (!stat.isDirectory() || stat.isSymbolicLink()) return;
34
+ const names = await fs.readdir(target);
35
+ validate();
36
+ for (const name of names) await visit(path.join(target, name));
37
+ } catch (error) {
38
+ validate();
39
+ const code = (error as NodeJS.ErrnoException).code;
40
+ if (code !== "ENOENT" && code !== "ENOTDIR") throw error;
41
+ }
42
+ }
43
+ for (const target of new Set(targets)) await visit(target);
44
+ }
@@ -7,9 +7,11 @@ import { syncDirectory, writeJson } from "../state/json-file.js";
7
7
  import { withLock } from "../state/lock.js";
8
8
  import { syncMutationParents } from "../state/mutation-directory-sync.js";
9
9
  import { stateDir } from "../state/state-directory.js";
10
+ import { normalizeSyncExclude, sameSyncExclude } from "../sync/exclude-policy.js";
10
11
  import { mergePathIdentity } from "../sync/file-merge-planner.js";
11
12
  import { agentDir, configuredSessionDir } from "./session-paths.js";
12
13
  import { caseReplacementSpelling, coalesceCaseReplacements, isCaseReplacement } from "./snapshot-case-replacement.js";
14
+ import { assertUnexcludedTargets } from "./snapshot-exclude-safety.js";
13
15
  import { withMissingTargetQueues, withTargetQueues } from "./snapshot-mutation-queues.js";
14
16
  import { sessionStorageRoot } from "./snapshot-paths.js";
15
17
  import {
@@ -42,6 +44,7 @@ interface TransactionEntry {
42
44
  }
43
45
  interface TransactionJournal {
44
46
  version: number;
47
+ exclude?: string[];
45
48
  /** Version 6: durable files are accepted; surviving evidence permits cleanup only. */
46
49
  completed?: boolean;
47
50
  root: string;
@@ -52,6 +55,7 @@ interface TransactionJournal {
52
55
  }
53
56
  interface TransactionOptions {
54
57
  sessionDir?: string;
58
+ exclude?: readonly string[];
55
59
  signal?: AbortSignal;
56
60
  validateMutation?: () => void;
57
61
  protectedTargets?: readonly string[];
@@ -70,6 +74,7 @@ export async function applySnapshotTransaction(plan: SnapshotApplyPlan, options:
70
74
  if (targets.length > 16_384)
71
75
  throw new Error("Snapshot transaction exceeds its target bound; review a smaller transfer.");
72
76
  return withTargetQueues(targets, options, async (heldKeys) => {
77
+ await assertUnexcludedTargets(agentDir(), targets, options);
73
78
  options.signal?.throwIfAborted();
74
79
  if (
75
80
  targets.some((target) =>
@@ -291,6 +296,8 @@ export async function recoverPendingSnapshotTransactions(options: TransactionOpt
291
296
  options.signal?.throwIfAborted();
292
297
  }
293
298
  validateJournal(directory, journal, sessionDir);
299
+ if (!journal.completed && !sameSyncExclude(journal.exclude, options.exclude))
300
+ throw new Error("Pending transaction has a different exclude policy; preserve its backup for reviewed recovery.");
294
301
  if (journal.completed) {
295
302
  await removeTransaction(directory);
296
303
  continue;
@@ -385,6 +392,7 @@ async function prepareTransaction(
385
392
  const journal: TransactionJournal = {
386
393
  version: sessionRootTransition ? 7 : replacements.size ? 5 : JOURNAL_VERSION,
387
394
  root,
395
+ ...(options.exclude === undefined ? {} : { exclude: normalizeSyncExclude(options.exclude) }),
388
396
  sessionRoot: sessionRootTransition ? effectiveRoot : sessionRoot,
389
397
  sessionRootTransition,
390
398
  entries,
@@ -611,6 +619,7 @@ async function removeOwnedTarget(
611
619
  options: TransactionOptions,
612
620
  restoringBefore?: string,
613
621
  ) {
622
+ await assertUnexcludedTargets(journal.root, [entry.target], options);
614
623
  const current = await verifyTarget(directory, entry, journal);
615
624
  options.validateMutation?.();
616
625
  options.signal?.throwIfAborted();
@@ -790,6 +799,9 @@ function validateJournal(directory: string, journal: TransactionJournal, session
790
799
  journal.entries.length > 16_384
791
800
  )
792
801
  throw new Error("Unsupported pi-sync transaction journal; preserve evidence for review.");
802
+ if (journal.exclude !== undefined && !Array.isArray(journal.exclude))
803
+ throw new Error("Invalid transaction exclude policy; preserve evidence.");
804
+ normalizeSyncExclude(journal.exclude);
793
805
  if (journal.completed !== undefined && (![6, 7].includes(journal.version) || journal.completed !== true))
794
806
  throw new Error("Invalid transaction completion evidence.");
795
807
  const root = path.resolve(agentDir());
@@ -4,10 +4,9 @@ export interface SnapshotFile {
4
4
  sha256: string;
5
5
  }
6
6
 
7
- export interface SnapshotSelection {
8
- version: 1;
9
- include: string[];
10
- }
7
+ export type SnapshotSelection =
8
+ | { version: 1; include: string[]; exclude?: never }
9
+ | { version: 2; include: string[]; exclude: string[] };
11
10
 
12
11
  export interface Snapshot {
13
12
  version: number;
@@ -30,6 +29,7 @@ export interface SnapshotOptions {
30
29
  /** Reviewed regular-file preimages; null means the path was absent. Checked under mutation queues. */
31
30
  expectedFileHashes?: Readonly<Record<string, string | null>>;
32
31
  include?: string[];
32
+ exclude?: string[];
33
33
  sessionDir?: string;
34
34
  /** Temporary internal projections while snapshot storage remains wire-compatible. */
35
35
  syncFiles?: string[];