@narumitw/pi-sync 0.58.0 → 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 (183) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +12 -6
  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-MW6KUQYA.ts → chunk-2ZZJXITS.ts} +40 -10
  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-KCB6MCWS.ts → command-handler-SDGKIQH2.ts} +17 -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-FMZXKPX2.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 +3 -2
  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/commands/command-handler.ts +1 -0
  100. package/src/settings/config.ts +9 -3
  101. package/src/settings/settings-management.ts +4 -3
  102. package/src/settings/settings-types.ts +4 -1
  103. package/src/settings/settings-validation.ts +8 -4
  104. package/src/snapshot/session-paths.ts +1 -0
  105. package/src/snapshot/snapshot-apply.ts +23 -7
  106. package/src/snapshot/snapshot-codec.ts +12 -3
  107. package/src/snapshot/snapshot-exclude-safety.ts +44 -0
  108. package/src/snapshot/snapshot-transaction.ts +12 -0
  109. package/src/snapshot/snapshot-types.ts +4 -4
  110. package/src/snapshot/snapshot.ts +71 -30
  111. package/src/state/merge-baseline-store.ts +9 -1
  112. package/src/state/state-types.ts +1 -0
  113. package/src/sync/automatic-sync.ts +7 -2
  114. package/src/sync/continuous-watch.ts +4 -2
  115. package/src/sync/exclude-policy.ts +84 -0
  116. package/src/sync/local-fields.ts +15 -4
  117. package/src/sync/merge-apply.ts +6 -1
  118. package/src/sync/merge-journal.ts +12 -3
  119. package/src/sync/merged-sync.ts +17 -12
  120. package/src/sync/partial-progress.ts +1 -0
  121. package/src/sync/remote-snapshot.ts +7 -8
  122. package/src/sync/sync-decision.ts +11 -1
  123. package/src/sync/sync-inspection.ts +3 -1
  124. package/src/sync/sync-mutations.ts +11 -4
  125. package/src/sync/sync-policy.ts +101 -37
  126. package/src/sync/sync-queries.ts +13 -3
  127. package/src/sync/sync-state.ts +16 -10
  128. package/src/ui/excluded-paths-ui.ts +106 -0
  129. package/src/ui/file-selection.ts +6 -3
  130. package/src/ui/manager-state.ts +11 -5
  131. package/src/ui/remote-selection-ui.ts +73 -10
  132. package/src/ui/settings-ui.ts +20 -5
  133. package/src/ui/setup/setup-actions.ts +1 -1
  134. package/src/ui/setup/setup-switcher.ts +3 -2
  135. package/src/ui/storage-connections-ui.ts +2 -2
  136. package/src/ui/sync-attention.ts +46 -10
  137. package/src/ui/sync-format.ts +13 -1
  138. package/dist/chunks/chunk-6LD5KX55.ts.map +0 -7
  139. package/dist/chunks/chunk-7A35ZAVO.ts.map +0 -7
  140. package/dist/chunks/chunk-BEST45H2.ts.map +0 -7
  141. package/dist/chunks/chunk-ESKOPQVB.ts.map +0 -7
  142. package/dist/chunks/chunk-FLHCOJCD.ts.map +0 -7
  143. package/dist/chunks/chunk-KYTT7KV4.ts.map +0 -7
  144. package/dist/chunks/chunk-MG66XM5U.ts.map +0 -7
  145. package/dist/chunks/chunk-MKSMJPVA.ts.map +0 -7
  146. package/dist/chunks/chunk-MMQIEDZ6.ts.map +0 -7
  147. package/dist/chunks/chunk-MW6KUQYA.ts.map +0 -7
  148. package/dist/chunks/chunk-OVBAW7KV.ts.map +0 -7
  149. package/dist/chunks/chunk-TIMWN2RH.ts.map +0 -7
  150. package/dist/chunks/chunk-Y4UVXOLQ.ts.map +0 -7
  151. package/dist/chunks/command-handler-KCB6MCWS.ts.map +0 -7
  152. package/dist/chunks/continuous-sync-FAFNLEUW.ts.map +0 -7
  153. package/dist/chunks/file-selection-IELTXSGZ.ts.map +0 -7
  154. package/dist/chunks/manager-ui-FMZXKPX2.ts.map +0 -7
  155. package/dist/chunks/sync-operations-45APGOL3.ts.map +0 -7
  156. /package/dist/chunks/{agent-candidate-U2NU3GUX.ts.map → agent-candidate-ZHN7FTZT.ts.map} +0 -0
  157. /package/dist/chunks/{agent-store-7GINKTS7.ts.map → agent-store-CCKN4DPR.ts.map} +0 -0
  158. /package/dist/chunks/{agent-sync-2R4GG2MF.ts.map → agent-sync-EGA2I5W7.ts.map} +0 -0
  159. /package/dist/chunks/{chunk-CQD2TJHE.ts.map → chunk-25QCU3LY.ts.map} +0 -0
  160. /package/dist/chunks/{chunk-OJARL2TG.ts.map → chunk-2UKUKIBI.ts.map} +0 -0
  161. /package/dist/chunks/{chunk-DN4IA7MR.ts.map → chunk-4NVHHDN2.ts.map} +0 -0
  162. /package/dist/chunks/{chunk-AKMV47YC.ts.map → chunk-6OFMB6KK.ts.map} +0 -0
  163. /package/dist/chunks/{chunk-XEODG2PE.ts.map → chunk-76HID27T.ts.map} +0 -0
  164. /package/dist/chunks/{chunk-U6GXGY5G.ts.map → chunk-DTPELCPW.ts.map} +0 -0
  165. /package/dist/chunks/{chunk-TZC7GDJE.ts.map → chunk-ILXMZ2HU.ts.map} +0 -0
  166. /package/dist/chunks/{chunk-JYILGR3K.ts.map → chunk-PQ75RPUP.ts.map} +0 -0
  167. /package/dist/chunks/{chunk-WQMYV4DW.ts.map → chunk-RDOX3VH5.ts.map} +0 -0
  168. /package/dist/chunks/{chunk-6O3EDBRL.ts.map → chunk-S7D6XWHI.ts.map} +0 -0
  169. /package/dist/chunks/{chunk-GNYGNHFF.ts.map → chunk-T2TYBLXK.ts.map} +0 -0
  170. /package/dist/chunks/{chunk-5TSCBBPP.ts.map → chunk-VPODHKOX.ts.map} +0 -0
  171. /package/dist/chunks/{chunk-S5OCYVPS.ts.map → chunk-YEULK7MK.ts.map} +0 -0
  172. /package/dist/chunks/{config-HYG7G5EM.ts.map → config-J5VZUY4J.ts.map} +0 -0
  173. /package/dist/chunks/{conflict-artifacts-J6WSDCWP.ts.map → conflict-artifacts-MYSH3L2J.ts.map} +0 -0
  174. /package/dist/chunks/{continuous-record-EPHGR2DU.ts.map → continuous-record-OM64J27R.ts.map} +0 -0
  175. /package/dist/chunks/{local-fields-JEKAPZKD.ts.map → local-fields-SR7PH66U.ts.map} +0 -0
  176. /package/dist/chunks/{manager-result-dispatcher-XCYPW7RC.ts.map → manager-result-dispatcher-CXUP5WDP.ts.map} +0 -0
  177. /package/dist/chunks/{merge-baseline-store-65GKUMXI.ts.map → merge-baseline-store-4Y2X7P2D.ts.map} +0 -0
  178. /package/dist/chunks/{remote-selection-ui-MYM2YCPF.ts.map → remote-selection-ui-W55BQDJQ.ts.map} +0 -0
  179. /package/dist/chunks/{setup-switch-KLGESLQX.ts.map → setup-switch-AB27ADDI.ts.map} +0 -0
  180. /package/dist/chunks/{snapshot-RGNDYT6A.ts.map → snapshot-G3W2GOGB.ts.map} +0 -0
  181. /package/dist/chunks/{snapshot-transaction-26BQO36S.ts.map → snapshot-transaction-SGRUWT73.ts.map} +0 -0
  182. /package/dist/chunks/{sync-inspection-MOMLGUTD.ts.map → sync-inspection-MDYHZHT7.ts.map} +0 -0
  183. /package/dist/chunks/{sync-state-7L4NT7W2.ts.map → sync-state-H4TFZZ7S.ts.map} +0 -0
@@ -10,17 +10,20 @@ import { sessionStorageRoot } from "./snapshot-paths.js";
10
10
  export { isDeniedPath } from "../paths.js";
11
11
  export { sessionStorageRoot } from "./snapshot-paths.js";
12
12
 
13
+ import { compileSyncExclude } from "../sync/exclude-policy.js";
13
14
  import {
14
15
  canonicalSnapshotPathForConfig,
16
+ configuredSnapshotPathMatcher,
15
17
  customIncludePathsByLower,
16
18
  DEFAULT_SYNC_INCLUDE,
17
19
  includeFromSelectionConfig,
18
- isConfiguredSnapshotPath,
19
20
  isPreservableUnmanagedSnapshotPath,
20
21
  normalizeExtraFiles,
21
22
  normalizeSyncFiles,
22
23
  type SyncSelectionConfig,
24
+ sameSnapshotSelection,
23
25
  selectionForSnapshot,
26
+ snapshotSelectionExclude,
24
27
  snapshotSelectionInclude,
25
28
  syncIncludeSelection,
26
29
  } from "../sync/sync-policy.js";
@@ -71,7 +74,7 @@ function snapshotsMatch(left: Snapshot, right: Snapshot) {
71
74
  const rightHashes = new Map(right.files.map((file) => [file.path, file.sha256]));
72
75
  return (
73
76
  left.syncSessions === right.syncSessions &&
74
- sameOptionalInclude(snapshotSelectionInclude(left), snapshotSelectionInclude(right)) &&
77
+ sameSnapshotSelection(left.selection, right.selection) &&
75
78
  leftHashes.size === rightHashes.size &&
76
79
  [...leftHashes].every(([filePath, hash]) => rightHashes.get(filePath) === hash)
77
80
  );
@@ -93,19 +96,30 @@ export function regenerateSnapshotIdentity(snapshot: Snapshot): Snapshot {
93
96
  export async function createSnapshot(profile: string, options: SnapshotOptions = {}): Promise<Snapshot> {
94
97
  options.signal?.throwIfAborted();
95
98
  const include = effectiveInclude(options);
96
- const syncSessions = include.includes("sessions");
97
- const sessionDir = options.sessionDir ?? (await configuredSessionDir());
99
+ const excluded = compileSyncExclude(options.exclude);
100
+ const syncSessions = include.includes("sessions") && !excluded("sessions");
101
+ const needsSessionConfig = syncSessions || !excluded("settings.json");
102
+ const sessionDir = options.sessionDir ?? (needsSessionConfig ? await configuredSessionDir() : undefined);
98
103
  options.signal?.throwIfAborted();
99
- const files = await collectFiles(agentDir(), { include, sessionDir, signal: options.signal });
104
+ const files = await collectFiles(
105
+ agentDir(),
106
+ {
107
+ include,
108
+ exclude: options.exclude,
109
+ sessionDir,
110
+ signal: options.signal,
111
+ },
112
+ excluded,
113
+ );
100
114
  options.signal?.throwIfAborted();
101
115
  return {
102
- version: VERSION,
116
+ version: options.exclude === undefined ? VERSION : 4,
103
117
  id: snapshotId(),
104
118
  createdAt: new Date().toISOString(),
105
119
  machine: os.hostname(),
106
120
  profile,
107
121
  syncSessions,
108
- selection: selectionForSnapshot(include),
122
+ selection: selectionForSnapshot(include, options.exclude),
109
123
  files,
110
124
  };
111
125
  }
@@ -119,7 +133,11 @@ function effectiveInclude(options: SnapshotOptions) {
119
133
  ];
120
134
  }
121
135
 
122
- export async function collectFiles(root: string, options: SnapshotOptions = {}): Promise<SnapshotFile[]> {
136
+ export async function collectFiles(
137
+ root: string,
138
+ options: SnapshotOptions = {},
139
+ excluded = compileSyncExclude(options.exclude),
140
+ ): Promise<SnapshotFile[]> {
123
141
  const signal = options.signal;
124
142
  signal?.throwIfAborted();
125
143
  const results: SnapshotFile[] = [];
@@ -128,22 +146,28 @@ export async function collectFiles(root: string, options: SnapshotOptions = {}):
128
146
  const selection = syncIncludeSelection(effectiveInclude(options));
129
147
  const selectedFiles = new Set<string>(selection.builtIns);
130
148
  for (const entry of entries) {
131
- if (entry.isDirectory() && TOP_LEVEL_DIRS.has(entry.name) && selectedFiles.has(entry.name)) {
132
- await collectDirectory(results, root, entry.name, { signal });
149
+ if (
150
+ entry.isDirectory() &&
151
+ TOP_LEVEL_DIRS.has(entry.name) &&
152
+ selectedFiles.has(entry.name) &&
153
+ !excluded(entry.name)
154
+ ) {
155
+ await collectDirectory(results, root, entry.name, { signal, excluded });
133
156
  }
134
157
  }
135
158
  for (const fileName of TOP_LEVEL_FILES) {
136
- if (!selectedFiles.has(fileName)) continue;
159
+ if (!selectedFiles.has(fileName) || excluded(fileName)) continue;
137
160
  const entry = selectTopLevelFileEntry(entries, fileName);
138
161
  if (entry) await addFile(results, root, entry.name, fileName, signal);
139
162
  }
140
163
  for (const relativePath of selection.custom) {
141
- await collectIncludedPath(results, root, relativePath, signal);
164
+ if (!excluded(relativePath)) await collectIncludedPath(results, root, relativePath, signal, excluded);
142
165
  }
143
- if (selection.sessions) {
166
+ if (selection.sessions && !excluded("sessions")) {
144
167
  try {
145
168
  await collectDirectory(results, sessionStorageRoot(root, options.sessionDir), "", {
146
169
  sessionsOnly: true,
170
+ excluded,
147
171
  virtualPrefix: "sessions",
148
172
  signal,
149
173
  });
@@ -155,14 +179,20 @@ export async function collectFiles(root: string, options: SnapshotOptions = {}):
155
179
  return results.sort((left, right) => left.path.localeCompare(right.path));
156
180
  }
157
181
 
158
- async function collectIncludedPath(results: SnapshotFile[], root: string, relativePath: string, signal?: AbortSignal) {
182
+ async function collectIncludedPath(
183
+ results: SnapshotFile[],
184
+ root: string,
185
+ relativePath: string,
186
+ signal?: AbortSignal,
187
+ excluded?: (relativePath: string) => boolean,
188
+ ) {
159
189
  signal?.throwIfAborted();
160
190
  const absolutePath = safeJoin(root, relativePath);
161
191
  try {
162
192
  const stat = await fs.lstat(absolutePath);
163
193
  signal?.throwIfAborted();
164
194
  if (stat.isFile()) await addFile(results, root, relativePath, relativePath, signal);
165
- else if (stat.isDirectory()) await collectDirectory(results, root, relativePath, { signal });
195
+ else if (stat.isDirectory()) await collectDirectory(results, root, relativePath, { signal, excluded });
166
196
  } catch (error) {
167
197
  if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
168
198
  if (!relativePath.includes("/")) {
@@ -178,7 +208,12 @@ async function collectDirectory(
178
208
  results: SnapshotFile[],
179
209
  root: string,
180
210
  relativeDirectory: string,
181
- options: { sessionsOnly?: boolean; virtualPrefix?: string; signal?: AbortSignal } = {},
211
+ options: {
212
+ sessionsOnly?: boolean;
213
+ virtualPrefix?: string;
214
+ signal?: AbortSignal;
215
+ excluded?: (relativePath: string) => boolean;
216
+ } = {},
182
217
  ) {
183
218
  options.signal?.throwIfAborted();
184
219
  const absoluteDirectory = path.join(root, relativeDirectory);
@@ -186,7 +221,7 @@ async function collectDirectory(
186
221
  options.signal?.throwIfAborted();
187
222
  const relativePath = relativeDirectory ? posixJoin(relativeDirectory, entry.name) : entry.name;
188
223
  const snapshotPath = options.virtualPrefix ? posixJoin(options.virtualPrefix, relativePath) : relativePath;
189
- if (isDeniedPath(snapshotPath)) continue;
224
+ if (isDeniedPath(snapshotPath) || options.excluded?.(snapshotPath)) continue;
190
225
  if (entry.isDirectory()) {
191
226
  await collectDirectory(results, root, relativePath, options);
192
227
  } else if (entry.isFile() && (!options.sessionsOnly || isSessionFilePath(snapshotPath))) {
@@ -242,7 +277,8 @@ export function snapshotTarget(root: string, relativePath: string, configuredSes
242
277
  export function snapshotIncludesSessions(snapshot: Snapshot) {
243
278
  return (
244
279
  snapshot.syncSessions === true ||
245
- snapshotSelectionInclude(snapshot)?.includes("sessions") === true ||
280
+ (snapshotSelectionInclude(snapshot)?.includes("sessions") === true &&
281
+ !compileSyncExclude(snapshotSelectionExclude(snapshot))("sessions")) ||
246
282
  snapshot.files.some((file) => isSessionPath(file.path))
247
283
  );
248
284
  }
@@ -254,10 +290,13 @@ export function filterSnapshotForConfigPolicy(
254
290
  ) {
255
291
  const include = includeFromSelectionConfig(config);
256
292
  const includePaths = customIncludePathsByLower(include);
293
+ const exclude = config.exclude ?? (snapshot.version === 4 ? [] : undefined);
257
294
  const filtered = {
258
295
  ...snapshot,
259
- syncSessions: include.includes("sessions") ? snapshot.syncSessions : false,
260
- selection: selectionForSnapshot(include),
296
+ version: exclude === undefined ? snapshot.version : 4,
297
+ syncSessions:
298
+ include.includes("sessions") && !compileSyncExclude(exclude)("sessions") ? snapshot.syncSessions : false,
299
+ selection: selectionForSnapshot(include, exclude),
261
300
  files: canonicalizeSnapshotFilesForConfig(snapshot.files, config, includePaths),
262
301
  };
263
302
  if (!options.regenerateId || snapshotsMatch(snapshot, filtered)) return filtered;
@@ -276,9 +315,10 @@ function canonicalizeSnapshotFilesForConfig(
276
315
  ) {
277
316
  const configuredFiles: SnapshotFile[] = [];
278
317
  const extraCandidates = new Map<string, { exact: boolean; file: SnapshotFile; originalPath: string }>();
318
+ const configured = configuredSnapshotPathMatcher(config);
279
319
  for (const file of files) {
280
320
  const normalized = toPosix(file.path);
281
- if (!isSafeSnapshotPath(file.path) || !isConfiguredSnapshotPath(normalized, config)) {
321
+ if (!isSafeSnapshotPath(file.path) || !configured(normalized)) {
282
322
  continue;
283
323
  }
284
324
  if (normalized.includes("/")) {
@@ -325,7 +365,7 @@ export function snapshotWithoutSessions(snapshot: Snapshot) {
325
365
  createdAt: new Date().toISOString(),
326
366
  machine: os.hostname(),
327
367
  syncSessions: false,
328
- ...(include ? { selection: selectionForSnapshot(include) } : {}),
368
+ ...(include ? { selection: selectionForSnapshot(include, snapshotSelectionExclude(snapshot)) } : {}),
329
369
  files,
330
370
  };
331
371
  }
@@ -349,6 +389,8 @@ export function scanSnapshot(snapshot: Snapshot) {
349
389
  export function mergeRemotePreservedFiles(local: Snapshot, remote: Snapshot, config: SyncSelectionConfig) {
350
390
  const localPathNames = new Set(local.files.map((file) => file.path.toLowerCase()));
351
391
  const preservedPathNames = new Set<string>();
392
+ const configured = configuredSnapshotPathMatcher(config);
393
+ const excluded = compileSyncExclude(config.exclude);
352
394
  const preserved = remote.files.filter((file) => {
353
395
  const normalized = toPosix(file.path);
354
396
  const lower = normalized.toLowerCase();
@@ -356,7 +398,8 @@ export function mergeRemotePreservedFiles(local: Snapshot, remote: Snapshot, con
356
398
  localPathNames.has(lower) ||
357
399
  preservedPathNames.has(lower) ||
358
400
  !isSafeSnapshotPath(file.path) ||
359
- isConfiguredSnapshotPath(normalized, config) ||
401
+ configured(normalized) ||
402
+ excluded(normalized) ||
360
403
  !isPreservableUnmanagedSnapshotPath(normalized)
361
404
  ) {
362
405
  return false;
@@ -370,15 +413,17 @@ export function mergeRemotePreservedFiles(local: Snapshot, remote: Snapshot, con
370
413
  id: snapshotId(),
371
414
  createdAt: new Date().toISOString(),
372
415
  machine: os.hostname(),
373
- syncSessions: snapshotIncludesSessions(local) || snapshotIncludesSessions(remote),
416
+ syncSessions: !excluded("sessions") && (snapshotIncludesSessions(local) || snapshotIncludesSessions(remote)),
374
417
  files: [...local.files, ...preserved].sort((left, right) => left.path.localeCompare(right.path)),
375
418
  };
376
419
  }
377
420
 
378
421
  export function mergeRemoteSessionFiles(local: Snapshot, remote: Snapshot) {
422
+ const excluded = compileSyncExclude(snapshotSelectionExclude(local));
423
+ if (excluded("sessions")) return local;
379
424
  const remoteSessions = remote.files.filter((file) => {
380
425
  const normalized = toPosix(file.path);
381
- return isSessionFilePath(normalized) && isSafeSnapshotPath(file.path);
426
+ return isSessionFilePath(normalized) && isSafeSnapshotPath(file.path) && !excluded(normalized);
382
427
  });
383
428
  if (remoteSessions.length === 0 && !snapshotIncludesSessions(remote)) return local;
384
429
  const localInclude = snapshotSelectionInclude(local);
@@ -392,6 +437,7 @@ export function mergeRemoteSessionFiles(local: Snapshot, remote: Snapshot) {
392
437
  ? {
393
438
  selection: selectionForSnapshot(
394
439
  localInclude.includes("sessions") ? localInclude : [...localInclude, "sessions"],
440
+ snapshotSelectionExclude(local),
395
441
  ),
396
442
  }
397
443
  : {}),
@@ -400,8 +446,3 @@ export function mergeRemoteSessionFiles(local: Snapshot, remote: Snapshot) {
400
446
  ),
401
447
  };
402
448
  }
403
-
404
- function sameOptionalInclude(left: string[] | undefined, right: string[] | undefined) {
405
- if (!left || !right) return left === right;
406
- return left.length === right.length && left.every((item, index) => item === right[index]);
407
- }
@@ -4,6 +4,7 @@ import path from "node:path";
4
4
  import { backendIdentityCoordinates } from "../backends/backend-identity.js";
5
5
  import type { AnySyncConfig } from "../settings/settings-types.js";
6
6
  import type { Snapshot, SnapshotFile } from "../snapshot/snapshot-types.js";
7
+ import { compileSyncExclude, normalizeSyncExclude } from "../sync/exclude-policy.js";
7
8
  import { collidingPaths, planFileMerge } from "../sync/file-merge-planner.js";
8
9
  import { parseSettingsDocument } from "../sync/json-document.js";
9
10
  import { validateSession } from "../sync/session-merge.js";
@@ -38,6 +39,9 @@ function identity(config: AnySyncConfig) {
38
39
  backendIdentityCoordinates(config),
39
40
  config.include,
40
41
  config.localFields ?? [],
42
+ ...(config.exclude === undefined
43
+ ? []
44
+ : ["exclude", normalizeSyncExclude(config.exclude).map((rule) => rule.toLowerCase())]),
41
45
  ]);
42
46
  }
43
47
  function directory(config: AnySyncConfig) {
@@ -62,8 +66,10 @@ export async function stageMergeBaseline(
62
66
  previous?: SyncState,
63
67
  ) {
64
68
  const collisions = collidingPaths(snapshot.files.map((file) => file.path));
69
+ const excluded = compileSyncExclude(config.exclude);
65
70
  const files = snapshot.files.filter((file) => {
66
71
  return (
72
+ !excluded(file.path) &&
67
73
  !collisions.has(file.path) &&
68
74
  accepted.lastFileHashes[file.path] === file.sha256 &&
69
75
  (file.path === "settings.json" || config.mergeContent || (config.agentMode && isMergeTextPath(file.path))) &&
@@ -80,6 +86,7 @@ export async function stageMergeBaseline(
80
86
  }
81
87
  for (const ancestor of ancestors)
82
88
  if (
89
+ !excluded(ancestor.path) &&
83
90
  !collisions.has(ancestor.path) &&
84
91
  accepted.lastFileHashes[ancestor.path] === ancestor.sha256 &&
85
92
  !stagedPaths.has(ancestor.path)
@@ -143,7 +150,8 @@ export async function readMergeAncestors(config: AnySyncConfig, state: SyncState
143
150
  if ((error as NodeJS.ErrnoException).code === "ENOENT") return;
144
151
  throw new Error("Merge ancestor is invalid; preserve its private cache and review the conflict.");
145
152
  }
146
- return record.files;
153
+ const excluded = compileSyncExclude(config.exclude);
154
+ return record.files.filter((file) => !excluded(file.path));
147
155
  }
148
156
  /** A no-op must not skip seeding or repairing ancestors required by later merges. */
149
157
  export async function hasCurrentMergeBaseline(config: AnySyncConfig, snapshot: Snapshot, state: SyncState) {
@@ -6,6 +6,7 @@ export interface SyncState {
6
6
  lastRemoteEtag?: string;
7
7
  lastFileHashes: Record<string, string>;
8
8
  include?: string[];
9
+ exclude?: string[];
9
10
  localFields?: string[];
10
11
  lastObservedSnapshot?: string;
11
12
  lastObservedRevision?: string;
@@ -18,6 +18,7 @@ import { throwIfAborted } from "./signals.js";
18
18
  import { createStartupTimings, type StartupTimingPublisher } from "./startup-timings.js";
19
19
  import { errorMessage } from "./sync-errors.js";
20
20
  import type { SyncLoaders } from "./sync-loaders.js";
21
+ import { syncSessionsSelected } from "./sync-policy.js";
21
22
 
22
23
  const AUTO_SYNC_OPTIONS: CommandOptions = {
23
24
  yes: true,
@@ -52,7 +53,11 @@ export async function startSession(
52
53
  // Normal startup needs only the directory probe, not the recovery/snapshot graph.
53
54
  const { recoverSnapshotTransactionsOnStartup } = await import("../snapshot/snapshot-transaction.js");
54
55
  validateMutation();
56
+ const recoverySettings = await readLocalConfigObject();
57
+ validateMutation();
58
+ const recoverySetup = recoverySettings?.activeSyncSetup;
55
59
  await recoverSnapshotTransactionsOnStartup({
60
+ exclude: recoverySetup ? recoverySettings.syncSetups[recoverySetup]?.sync.exclude : undefined,
56
61
  signal,
57
62
  sessionDir: sessionDirFromContext(ctx),
58
63
  protectedTargets: currentFile ? [currentFile] : [],
@@ -98,12 +103,12 @@ export async function autoPushSessions(ctx: ExtensionContext, signal: AbortSigna
98
103
  const partial = await loadPartialConfig();
99
104
  throwIfAborted(signal);
100
105
  if (!partial.automatic) return;
101
- if (!partial.include.includes("sessions")) return;
106
+ if (!syncSessionsSelected(partial)) return;
102
107
  await ensureStateDir();
103
108
  throwIfAborted(signal);
104
109
  const config = await loadConfig();
105
110
  throwIfAborted(signal);
106
- if (!config.include.includes("sessions")) return;
111
+ if (!syncSessionsSelected(config)) return;
107
112
  const [operations, snapshotModule, syncStateModule] = await Promise.all([
108
113
  loaders.operations(),
109
114
  loaders.snapshot(),
@@ -2,8 +2,9 @@ import { type FSWatcher, watch } from "node:fs";
2
2
  import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { getAgentDir } from "@earendil-works/pi-coding-agent";
5
- import { isDeniedPath } from "../paths.js";
5
+ import { isDeniedPath, toPosix } from "../paths.js";
6
6
  import type { AnySyncConfig } from "../settings/settings-types.js";
7
+ import { compileSyncExclude } from "./exclude-policy.js";
7
8
 
8
9
  /** Hints only. The scheduler's periodic snapshot scan remains required. */
9
10
  export async function watchContinuous(
@@ -12,6 +13,7 @@ export async function watchContinuous(
12
13
  ): Promise<() => void> {
13
14
  const root = getAgentDir();
14
15
  const watchers: FSWatcher[] = [];
16
+ const excluded = compileSyncExclude(config.exclude);
15
17
  const selected = config.include.map((item) => path.resolve(root, item));
16
18
  const relevant = (target: string) =>
17
19
  selected.some(
@@ -25,7 +27,7 @@ export async function watchContinuous(
25
27
  const target = path.resolve(directory, String(file));
26
28
  if (target === path.join(root, "pi-sync.json")) changed(true);
27
29
  else if (isDeniedPath(path.relative(root, target))) return;
28
- else if (relevant(target)) changed(false);
30
+ else if (!excluded(toPosix(path.relative(root, target))) && relevant(target)) changed(false);
29
31
  });
30
32
  watcher.on("error", () => watcher.close());
31
33
  watchers.push(watcher);
@@ -0,0 +1,84 @@
1
+ import path from "node:path";
2
+ import { Minimatch } from "minimatch";
3
+
4
+ const MAX_RULES = 1_024;
5
+ const MAX_RULE_BYTES = 4_096;
6
+ const MAX_TOTAL_BYTES = 256 * 1_024;
7
+
8
+ /** Exclusions are a set; keep spelling for exact reviews, not filesystem lookup. */
9
+ export function normalizeSyncExclude(value: unknown): string[] {
10
+ if (value === undefined) return [];
11
+ if (!Array.isArray(value)) throw new Error("Invalid pi-sync settings: sync.exclude must be an array.");
12
+ if (value.length > MAX_RULES) throw new Error(`sync.exclude exceeds ${MAX_RULES} rules.`);
13
+ const seen = new Set<string>();
14
+ let total = 0;
15
+ const rules = value.map((item) => {
16
+ if (typeof item !== "string") throw new Error("sync.exclude rules must be strings.");
17
+ const bytes = Buffer.byteLength(item, "utf8");
18
+ total += bytes;
19
+ if (bytes > MAX_RULE_BYTES || total > MAX_TOTAL_BYTES) throw new Error("sync.exclude exceeds its byte limit.");
20
+ const rule = item.trim();
21
+ const segments = rule.split("/");
22
+ if (
23
+ !rule ||
24
+ path.posix.isAbsolute(rule) ||
25
+ path.win32.isAbsolute(rule) ||
26
+ /^[a-z]:/iu.test(rule) ||
27
+ rule.includes("\\") ||
28
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: Reject untrusted terminal controls.
29
+ /[\u0000-\u001f\u007f-\u009f]/u.test(item) ||
30
+ /^[!#]/u.test(rule) ||
31
+ /[[\]{}()]/u.test(rule) ||
32
+ segments.some(
33
+ (segment) => !segment || segment === "." || segment === ".." || (segment.includes("**") && segment !== "**"),
34
+ )
35
+ )
36
+ throw new Error(
37
+ "Invalid sync.exclude rule: use a safe relative path with only *, ?, and whole-segment ** globs.",
38
+ );
39
+ const key = rule.toLowerCase();
40
+ if (seen.has(key)) throw new Error("Duplicate sync.exclude rule (case-insensitive).");
41
+ seen.add(key);
42
+ return rule;
43
+ });
44
+ return rules.sort((left, right) => {
45
+ const a = left.toLowerCase();
46
+ const b = right.toLowerCase();
47
+ return a < b ? -1 : a > b ? 1 : 0;
48
+ });
49
+ }
50
+
51
+ export function sameSyncExclude(left: unknown, right: unknown) {
52
+ return (
53
+ JSON.stringify(normalizeSyncExclude(left).map((rule) => rule.toLowerCase())) ===
54
+ JSON.stringify(normalizeSyncExclude(right).map((rule) => rule.toLowerCase()))
55
+ );
56
+ }
57
+
58
+ /** Compile at the operation boundary and reuse for every file/directory. */
59
+ export function compileSyncExclude(value: unknown) {
60
+ const matchers = normalizeSyncExclude(value).map(
61
+ (rule) =>
62
+ // A trailing globstar also matches zero segments; ancestor matching owns its subtree.
63
+ new Minimatch(rule.replace(/(?:\/\*\*)+$/u, ""), {
64
+ dot: true,
65
+ nocase: true,
66
+ nonegate: true,
67
+ nocomment: true,
68
+ nobrace: true,
69
+ noext: true,
70
+ platform: "linux",
71
+ optimizationLevel: 0,
72
+ }),
73
+ );
74
+ return (relativePath: string): boolean => {
75
+ if (matchers.length === 0) return false;
76
+ for (let candidate = relativePath; candidate; ) {
77
+ if (matchers.some((matcher) => matcher.match(candidate))) return true;
78
+ const slash = candidate.lastIndexOf("/");
79
+ if (slash < 0) break;
80
+ candidate = candidate.slice(0, slash);
81
+ }
82
+ return false;
83
+ };
84
+ }
@@ -1,6 +1,7 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { regenerateSnapshotIdentity } from "../snapshot/snapshot.js";
3
3
  import type { Snapshot, SnapshotFile } from "../snapshot/snapshot-types.js";
4
+ import { compileSyncExclude } from "./exclude-policy.js";
4
5
  import {
5
6
  type JsonDocument,
6
7
  type JsonNode,
@@ -9,16 +10,17 @@ import {
9
10
  renderSettingsMembers,
10
11
  } from "./json-document.js";
11
12
  import { normalizeLocalFields } from "./local-field-policy.js";
13
+ import { snapshotSelectionExclude, validateSnapshotSelection } from "./sync-policy.js";
12
14
 
13
15
  export { normalizeLocalFields } from "./local-field-policy.js";
14
16
 
15
17
  /** Shared transport contract: older snapshots cannot carry portable policy metadata. */
16
18
  export function validateSnapshotFieldPolicy(snapshot: Pick<Snapshot, "version" | "localFields">) {
17
- if (snapshot.version !== 1 && snapshot.version !== 2 && snapshot.version !== 3)
19
+ if (snapshot.version !== 1 && snapshot.version !== 2 && snapshot.version !== 3 && snapshot.version !== 4)
18
20
  throw new Error("Unsupported snapshot format.");
19
21
  if (snapshot.version === 1 && snapshot.localFields !== undefined)
20
22
  throw new Error("Portable field policy requires snapshot version 2.");
21
- if (snapshot.version === 2 || snapshot.version === 3) {
23
+ if (snapshot.version === 2 || snapshot.version === 3 || snapshot.version === 4) {
22
24
  if (snapshot.version === 2 && snapshot.localFields === undefined)
23
25
  throw new Error("Snapshot version 2 requires explicit localFields rules.");
24
26
  normalizeLocalFields(snapshot.localFields);
@@ -27,7 +29,11 @@ export function validateSnapshotFieldPolicy(snapshot: Pick<Snapshot, "version" |
27
29
  /** Portable transport images must not carry values declared machine-local. Physical journal images are different. */
28
30
  export function validatePortableSnapshot(snapshot: Snapshot) {
29
31
  validateSnapshotFieldPolicy(snapshot);
30
- if ((snapshot.version !== 2 && snapshot.version !== 3) || !snapshot.localFields?.length) return;
32
+ validateSnapshotSelection(snapshot);
33
+ const excludedPath = compileSyncExclude(snapshotSelectionExclude(snapshot));
34
+ if (snapshot.files.some((file) => excludedPath(file.path)))
35
+ throw new Error("Portable snapshot retains excluded paths.");
36
+ if (snapshot.version === 1 || !snapshot.localFields?.length) return;
31
37
  try {
32
38
  for (const entry of snapshot.files) {
33
39
  if (typeof entry?.path !== "string" || entry.path.toLowerCase() !== "settings.json") continue;
@@ -70,7 +76,12 @@ export function portableSnapshot(snapshot: Snapshot, fields: string[] | undefine
70
76
  : value;
71
77
  return file(Buffer.from(`${JSON.stringify(canonical(object))}\n`));
72
78
  });
73
- return regenerateSnapshotIdentity({ ...snapshot, version: 2, localFields: [...excluded], files });
79
+ return regenerateSnapshotIdentity({
80
+ ...snapshot,
81
+ version: snapshot.version === 4 ? 4 : 2,
82
+ localFields: [...excluded],
83
+ files,
84
+ });
74
85
  }
75
86
  export function overlayLocalFields(portable: Snapshot, local: Snapshot, fields: string[] | undefined): Snapshot {
76
87
  if (!fields?.length) return portable;
@@ -5,6 +5,7 @@ import { withFileMutationQueue } from "@earendil-works/pi-coding-agent";
5
5
  import { agentDir } from "../snapshot/session-paths.js";
6
6
  import { createSnapshot, snapshotTarget } from "../snapshot/snapshot.js";
7
7
  import { preflightSnapshotApply, preflightSnapshotMutations } from "../snapshot/snapshot-apply.js";
8
+ import { assertUnexcludedTargets } from "../snapshot/snapshot-exclude-safety.js";
8
9
  import { assertCanonicalMutationTargets } from "../snapshot/snapshot-mutation-queues.js";
9
10
  import { sessionStorageRoot } from "../snapshot/snapshot-paths.js";
10
11
  import type { Snapshot, SnapshotOptions } from "../snapshot/snapshot-types.js";
@@ -25,6 +26,11 @@ export async function preflightMergedTargets(
25
26
  const afterHashes: Record<string, string> = Object.assign(Object.create(null), fileHashMap(after));
26
27
  const paths = [...new Set([...Object.keys(beforeHashes), ...Object.keys(afterHashes)])].sort();
27
28
  const changed = new Set(paths.filter((item) => beforeHashes[item] !== afterHashes[item]));
29
+ await assertUnexcludedTargets(
30
+ root,
31
+ [...changed].map((item) => snapshotTarget(root, item, options.sessionDir)),
32
+ options,
33
+ );
28
34
  await assertCanonicalMergedTargets(root, changed, options);
29
35
  await assertDistinctMergedTargets(root, paths, changed, options, protectedTarget, new Set(Object.keys(afterHashes)));
30
36
  const removed = replacementPaths(
@@ -138,7 +144,6 @@ async function assertReviewedTree(directory: string, relative: string, beforeHas
138
144
  .update(await fs.readFile(child))
139
145
  .digest("hex")
140
146
  ) {
141
- continue;
142
147
  } else {
143
148
  throw new Error("Reviewed directory contains unknown or changed files; publication refused.");
144
149
  }
@@ -6,6 +6,7 @@ import type { AnySyncConfig } from "../settings/settings-types.js";
6
6
  import type { Snapshot } from "../snapshot/snapshot-types.js";
7
7
  import { readJsonIfExists, syncDirectory, writeJson } from "../state/json-file.js";
8
8
  import { statePathForConfig, syncStateFingerprint } from "../state/sync-state-store.js";
9
+ import { normalizeSyncExclude } from "./exclude-policy.js";
9
10
  import { planFileMerge } from "./file-merge-planner.js";
10
11
  import {
11
12
  portableSnapshot,
@@ -36,7 +37,15 @@ export interface MergeJournal {
36
37
  }
37
38
 
38
39
  export function mergeJournalIdentity(config: AnySyncConfig, backendIdentity: string) {
39
- return JSON.stringify([config.setupName, backendIdentity, [...config.include].sort(), config.localFields ?? null]);
40
+ return JSON.stringify([
41
+ config.setupName,
42
+ backendIdentity,
43
+ [...config.include].sort(),
44
+ config.localFields ?? null,
45
+ ...(config.exclude === undefined
46
+ ? []
47
+ : ["exclude", normalizeSyncExclude(config.exclude).map((rule) => rule.toLowerCase())]),
48
+ ]);
40
49
  }
41
50
 
42
51
  export function mergeJournalPath(config: AnySyncConfig) {
@@ -95,7 +104,7 @@ export async function readMergeJournal(config: AnySyncConfig): Promise<MergeJour
95
104
  ]) {
96
105
  validateSnapshotFieldPolicy(snapshot);
97
106
  if (
98
- (snapshot.version !== 1 && snapshot.version !== 2 && snapshot.version !== 3) ||
107
+ (snapshot.version !== 1 && snapshot.version !== 2 && snapshot.version !== 3 && snapshot.version !== 4) ||
99
108
  typeof snapshot.id !== "string" ||
100
109
  typeof snapshot.profile !== "string" ||
101
110
  snapshot.files.length > 16_384 ||
@@ -115,7 +124,7 @@ export async function readMergeJournal(config: AnySyncConfig): Promise<MergeJour
115
124
  throw new Error("Invalid journal collision group.");
116
125
  }
117
126
  validatePortableSnapshot(journal.upload);
118
- if ((journal.upload.version === 2 || journal.upload.version === 3) && !journal.accepted)
127
+ if (journal.upload.version >= 2 && !journal.accepted)
119
128
  throw new Error("Portable merge journal requires an explicit accepted projection.");
120
129
  if (journal.accepted) validatePortableSnapshot(journal.accepted);
121
130
  } catch {