@narumitw/pi-sync 0.67.3 → 0.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +26 -48
  3. package/dist/chunks/{chunk-XUZV4OGI.ts → chunk-335XTMMZ.ts} +3 -2
  4. package/dist/chunks/{chunk-XUZV4OGI.ts.map → chunk-335XTMMZ.ts.map} +2 -2
  5. package/dist/chunks/{chunk-PUSMSKIM.ts → chunk-AYGMIMCV.ts} +2 -11
  6. package/dist/chunks/chunk-AYGMIMCV.ts.map +7 -0
  7. package/dist/chunks/{chunk-HLJIRWFL.ts → chunk-BCDBT4X3.ts} +7 -7
  8. package/dist/chunks/{chunk-AVTW6WNP.ts → chunk-FQKWGVMA.ts} +20 -54
  9. package/dist/chunks/chunk-FQKWGVMA.ts.map +7 -0
  10. package/dist/chunks/{chunk-DGVZYS7T.ts → chunk-FR6A7ASZ.ts} +8 -11
  11. package/dist/chunks/chunk-FR6A7ASZ.ts.map +7 -0
  12. package/dist/chunks/{chunk-3NS4PMCI.ts → chunk-J52GYZO6.ts} +2 -8
  13. package/dist/chunks/{chunk-3NS4PMCI.ts.map → chunk-J52GYZO6.ts.map} +2 -2
  14. package/dist/chunks/{chunk-2MUAR5GH.ts → chunk-KAIVTJIQ.ts} +7 -10
  15. package/dist/chunks/chunk-KAIVTJIQ.ts.map +7 -0
  16. package/dist/chunks/{chunk-WBIOSK76.ts → chunk-R7PN3KIY.ts} +1 -2
  17. package/dist/chunks/{chunk-3Q3DMMID.ts → chunk-TLYT6HVI.ts} +8 -8
  18. package/dist/chunks/{chunk-X344HTVV.ts → chunk-WCGLU526.ts} +39 -118
  19. package/dist/chunks/chunk-WCGLU526.ts.map +7 -0
  20. package/dist/chunks/{chunk-JREGWM2B.ts → chunk-XNUARYLR.ts} +1 -2
  21. package/dist/chunks/{chunk-CQ4DMLH3.ts → chunk-YV2R5SJU.ts} +21 -81
  22. package/dist/chunks/chunk-YV2R5SJU.ts.map +7 -0
  23. package/dist/chunks/{command-handler-WF2TDDRZ.ts → command-handler-S6BRZMPW.ts} +64 -59
  24. package/dist/chunks/command-handler-S6BRZMPW.ts.map +7 -0
  25. package/dist/chunks/{conflict-review-GWEL4S6C.ts → conflict-review-3XMYDJIK.ts} +2 -2
  26. package/dist/chunks/{file-selection-GASCVN45.ts → file-selection-4BOQBXS7.ts} +10 -17
  27. package/dist/chunks/file-selection-4BOQBXS7.ts.map +7 -0
  28. package/dist/chunks/{manager-result-dispatcher-BXN46NRC.ts → manager-result-dispatcher-A4IWLS4J.ts} +7 -7
  29. package/dist/chunks/{manager-ui-FS4QIKRA.ts → manager-ui-KHMCSLLV.ts} +114 -581
  30. package/dist/chunks/manager-ui-KHMCSLLV.ts.map +7 -0
  31. package/dist/chunks/{chunk-ECUCXF5Y.ts → merge-review-LWMUE5IW.ts} +2 -3
  32. package/dist/chunks/{remote-selection-ui-DOYKUMER.ts → remote-selection-ui-F6NJBQ3Y.ts} +6 -6
  33. package/dist/chunks/{setup-switch-JZDFQPVW.ts → setup-switch-7LMIRMZ7.ts} +6 -6
  34. package/dist/chunks/{setup-wizard-PI45SF2C.ts → setup-wizard-2NRPR433.ts} +11 -16
  35. package/dist/chunks/{setup-wizard-PI45SF2C.ts.map → setup-wizard-2NRPR433.ts.map} +1 -1
  36. package/dist/chunks/{sync-inspection-DI5J6EUH.ts → sync-inspection-QGM54YCM.ts} +5 -5
  37. package/dist/chunks/{sync-operations-AGNL7QXA.ts → sync-operations-DTQMKVRQ.ts} +2 -2
  38. package/dist/daemon/dist/build-id.json +1 -1
  39. package/dist/daemon/dist/cli.js +22 -3
  40. package/dist/daemon/dist/client-transport.js +2 -0
  41. package/dist/daemon/dist/client.js +2 -10
  42. package/dist/daemon/dist/consent.js +13 -135
  43. package/dist/daemon/dist/engine/backends/git/git-backend.js +4 -17
  44. package/dist/daemon/dist/engine/backends/git/git-storage.js +11 -44
  45. package/dist/daemon/dist/engine/backends/s3/s3-backend.js +6 -6
  46. package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +6 -6
  47. package/dist/daemon/dist/engine/settings/config.js +16 -149
  48. package/dist/daemon/dist/engine/settings/retired-ignore-policy.js +16 -0
  49. package/dist/daemon/dist/engine/settings/retired-ignore-recovery.js +14 -0
  50. package/dist/daemon/dist/engine/settings/settings-management.js +2 -10
  51. package/dist/daemon/dist/engine/settings/settings-validation.js +8 -21
  52. package/dist/daemon/dist/engine/snapshot/session-paths.js +13 -41
  53. package/dist/daemon/dist/engine/snapshot/snapshot-apply.js +8 -24
  54. package/dist/daemon/dist/engine/snapshot/snapshot-codec.js +7 -11
  55. package/dist/daemon/dist/engine/snapshot/snapshot-exclude-safety.js +19 -76
  56. package/dist/daemon/dist/engine/snapshot/snapshot-transaction-images.js +1 -7
  57. package/dist/daemon/dist/engine/snapshot/snapshot-transaction-policy.js +8 -102
  58. package/dist/daemon/dist/engine/snapshot/snapshot-transaction.js +20 -100
  59. package/dist/daemon/dist/engine/snapshot/snapshot-types.js +1 -11
  60. package/dist/daemon/dist/engine/snapshot/snapshot.js +26 -78
  61. package/dist/daemon/dist/engine/state/sync-state-store.js +5 -1
  62. package/dist/daemon/dist/engine/sync/agent-plan.js +0 -1
  63. package/dist/daemon/dist/engine/sync/agent-policy.js +1 -1
  64. package/dist/daemon/dist/engine/sync/conflict-review.js +0 -2
  65. package/dist/daemon/dist/engine/sync/continuous-sync.js +2 -17
  66. package/dist/daemon/dist/engine/sync/continuous-watch.js +3 -7
  67. package/dist/daemon/dist/engine/sync/directional-action.js +3 -21
  68. package/dist/daemon/dist/engine/sync/initialization.js +4 -15
  69. package/dist/daemon/dist/engine/sync/local-fields.js +4 -65
  70. package/dist/daemon/dist/engine/sync/merge-apply.js +8 -31
  71. package/dist/daemon/dist/engine/sync/merge-journal.js +8 -118
  72. package/dist/daemon/dist/engine/sync/merged-sync.js +12 -70
  73. package/dist/daemon/dist/engine/sync/push-review.js +1 -16
  74. package/dist/daemon/dist/engine/sync/remote-snapshot.js +48 -65
  75. package/dist/daemon/dist/engine/sync/startup-bootstrap.js +3 -3
  76. package/dist/daemon/dist/engine/sync/sync-error-guidance.js +1 -1
  77. package/dist/daemon/dist/engine/sync/sync-inspection.js +1 -2
  78. package/dist/daemon/dist/engine/sync/sync-mutations.js +25 -118
  79. package/dist/daemon/dist/engine/sync/sync-policy.js +26 -150
  80. package/dist/daemon/dist/engine/sync/sync-queries.js +1 -8
  81. package/dist/daemon/dist/engine/sync/sync-rollback.js +12 -50
  82. package/dist/daemon/dist/engine/sync/sync-state.js +2 -15
  83. package/dist/daemon/dist/engine/sync/transfer-freshness.js +7 -17
  84. package/dist/daemon/dist/engine/sync/transfer-size-limits.js +3 -7
  85. package/dist/daemon/dist/engine-service.js +60 -219
  86. package/dist/daemon/dist/foreground-queue-outcome.js +0 -4
  87. package/dist/daemon/dist/legacy-consent-guard.js +34 -0
  88. package/dist/daemon/dist/server.js +4 -8
  89. package/dist/daemon/dist/service-host.js +3 -9
  90. package/dist/daemon/package.json +1 -1
  91. package/dist/index.ts +45 -46
  92. package/dist/index.ts.map +3 -3
  93. package/docs/continuous-sync-verification.md +1 -1
  94. package/docs/daemon-migration.md +7 -5
  95. package/docs/tui-contract.md +4 -6
  96. package/package.json +2 -3
  97. package/skills/configure-pi-sync/SKILL.md +18 -77
  98. package/skills/configure-pi-sync/references/configuration.md +58 -75
  99. package/src/commands/command-execution.ts +13 -29
  100. package/src/commands/command-handler.ts +0 -4
  101. package/src/commands/command.ts +2 -1
  102. package/src/daemon/directional-recovery.ts +4 -33
  103. package/src/daemon/pi-client.ts +20 -88
  104. package/src/settings/config.ts +0 -1
  105. package/src/sync/setup-switch.ts +1 -4
  106. package/src/sync-extension.ts +10 -24
  107. package/src/ui/cancellable-operation.ts +2 -13
  108. package/src/ui/excluded-paths-ui.ts +1 -4
  109. package/src/ui/file-selection.ts +0 -5
  110. package/src/ui/manager-state.ts +12 -75
  111. package/src/ui/manager-ui.ts +7 -96
  112. package/src/ui/remote-selection-ui.ts +29 -130
  113. package/src/ui/settings-ui.ts +169 -388
  114. package/src/ui/setup/setup-actions.ts +4 -16
  115. package/src/ui/setup/setup-prompts.ts +12 -49
  116. package/src/ui/setup/setup-switcher.ts +8 -14
  117. package/src/ui/storage-connections-ui.ts +21 -32
  118. package/src/ui/sync-setups-ui.ts +27 -53
  119. package/dist/chunks/chunk-2MUAR5GH.ts.map +0 -7
  120. package/dist/chunks/chunk-33EDXDLC.ts +0 -106
  121. package/dist/chunks/chunk-33EDXDLC.ts.map +0 -7
  122. package/dist/chunks/chunk-AVTW6WNP.ts.map +0 -7
  123. package/dist/chunks/chunk-CQ4DMLH3.ts.map +0 -7
  124. package/dist/chunks/chunk-DGVZYS7T.ts.map +0 -7
  125. package/dist/chunks/chunk-EJDDRS6O.ts +0 -17
  126. package/dist/chunks/chunk-EJDDRS6O.ts.map +0 -7
  127. package/dist/chunks/chunk-KNEUL4XN.ts +0 -30
  128. package/dist/chunks/chunk-KNEUL4XN.ts.map +0 -7
  129. package/dist/chunks/chunk-PUSMSKIM.ts.map +0 -7
  130. package/dist/chunks/chunk-WFBHWYI6.ts +0 -18
  131. package/dist/chunks/chunk-WFBHWYI6.ts.map +0 -7
  132. package/dist/chunks/chunk-X344HTVV.ts.map +0 -7
  133. package/dist/chunks/command-handler-WF2TDDRZ.ts.map +0 -7
  134. package/dist/chunks/config-P54GGMXY.ts +0 -39
  135. package/dist/chunks/continuous-record-3SKJ6I3V.ts +0 -23
  136. package/dist/chunks/continuous-record-3SKJ6I3V.ts.map +0 -7
  137. package/dist/chunks/continuous-storage-3EU6I7Z3.ts +0 -27
  138. package/dist/chunks/continuous-storage-3EU6I7Z3.ts.map +0 -7
  139. package/dist/chunks/file-selection-GASCVN45.ts.map +0 -7
  140. package/dist/chunks/ignore-file-ui-BEZZZIEE.ts +0 -21
  141. package/dist/chunks/manager-ui-FS4QIKRA.ts.map +0 -7
  142. package/dist/chunks/merge-review-C2KETZKY.ts +0 -11
  143. package/dist/chunks/merge-review-C2KETZKY.ts.map +0 -7
  144. package/dist/chunks/remote-selection-ui-DOYKUMER.ts.map +0 -7
  145. package/dist/chunks/setup-switch-JZDFQPVW.ts.map +0 -7
  146. package/dist/daemon/dist/engine/ignore/adoption-journal.js +0 -146
  147. package/dist/daemon/dist/engine/ignore/effective-ignore-policy.js +0 -33
  148. package/dist/daemon/dist/engine/ignore/ignore-edit.js +0 -102
  149. package/dist/daemon/dist/engine/ignore/ignore-initialization.js +0 -288
  150. package/dist/daemon/dist/engine/ignore/ignore-migration-prompt.js +0 -139
  151. package/dist/daemon/dist/engine/ignore/ignore-settings.js +0 -391
  152. package/dist/daemon/dist/engine/ignore/ignore-source.js +0 -250
  153. package/dist/daemon/dist/engine/ignore/snapshot-ignore-rules.js +0 -39
  154. package/dist/daemon/dist/engine/sync/ignore-adoption-recovery.js +0 -50
  155. package/dist/daemon/dist/engine/sync/ignore-adoption.js +0 -416
  156. package/dist/daemon/dist/engine/sync/ignore-publication.js +0 -23
  157. package/dist/daemon/dist/engine/ui/ignore-rule-preview.js +0 -18
  158. package/dist/daemon/dist/monitor.js +0 -344
  159. package/src/ui/agent-mode-setting.ts +0 -99
  160. package/src/ui/ignore-file-guidance.ts +0 -7
  161. package/src/ui/ignore-file-ui.ts +0 -105
  162. package/src/ui/ignore-migration-prompt.ts +0 -65
  163. package/src/ui/settings-review.ts +0 -26
  164. /package/dist/chunks/{chunk-HLJIRWFL.ts.map → chunk-BCDBT4X3.ts.map} +0 -0
  165. /package/dist/chunks/{chunk-WBIOSK76.ts.map → chunk-R7PN3KIY.ts.map} +0 -0
  166. /package/dist/chunks/{chunk-3Q3DMMID.ts.map → chunk-TLYT6HVI.ts.map} +0 -0
  167. /package/dist/chunks/{chunk-JREGWM2B.ts.map → chunk-XNUARYLR.ts.map} +0 -0
  168. /package/dist/chunks/{conflict-review-GWEL4S6C.ts.map → conflict-review-3XMYDJIK.ts.map} +0 -0
  169. /package/dist/chunks/{config-P54GGMXY.ts.map → manager-result-dispatcher-A4IWLS4J.ts.map} +0 -0
  170. /package/dist/chunks/{chunk-ECUCXF5Y.ts.map → merge-review-LWMUE5IW.ts.map} +0 -0
  171. /package/dist/chunks/{ignore-file-ui-BEZZZIEE.ts.map → remote-selection-ui-F6NJBQ3Y.ts.map} +0 -0
  172. /package/dist/chunks/{manager-result-dispatcher-BXN46NRC.ts.map → setup-switch-7LMIRMZ7.ts.map} +0 -0
  173. /package/dist/chunks/{sync-inspection-DI5J6EUH.ts.map → sync-inspection-QGM54YCM.ts.map} +0 -0
  174. /package/dist/chunks/{sync-operations-AGNL7QXA.ts.map → sync-operations-DTQMKVRQ.ts.map} +0 -0
@@ -1,250 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { constants, lstatSync } from "node:fs";
3
- import fs from "node:fs/promises";
4
- import path from "node:path";
5
- import ignore from "ignore";
6
- import { isDeniedPath } from "../paths.js";
7
- export const DEFAULT_IGNORE_FILENAME = ".syncignore";
8
- export const DEFAULT_IGNORE_CREATION_RECORD = ".pi-sync.json.syncignore-creation";
9
- export const DEFAULT_IGNORE_RULES = "/auth.json\n/git/\n/npm/\n/sessions/\n/truth.json\n";
10
- export const MAX_IGNORE_BYTES = 64 * 1024;
11
- const MAX_MATCH_PATH_BYTES = 4_096;
12
- const MATCH_CACHE_PATH_BUDGET = 2_048;
13
- const RESERVED_FILENAMES = new Set([
14
- "auth.json",
15
- "auth.json.lock",
16
- "trust.json",
17
- "trust.json.lock",
18
- "settings.json",
19
- "settings.json.lock",
20
- "models.json",
21
- "models-store.json",
22
- "models-store.json.lock",
23
- "keybindings.json",
24
- "agents.md",
25
- "system.md",
26
- "append_system.md",
27
- "crashes.json",
28
- "pi-debug.log",
29
- "extensions",
30
- "skills",
31
- "prompts",
32
- "themes",
33
- "npm",
34
- "sessions",
35
- ]);
36
- export function validateIgnoreFilename(value) {
37
- if (typeof value !== "string" || !/^[A-Za-z0-9._ -]{1,255}$/u.test(value) || /^[ ]|[. ]$/u.test(value)) {
38
- throw new Error("Invalid sync.ignoreFile: use one safe filename in the Pi agent directory.");
39
- }
40
- const lower = value.toLowerCase();
41
- if (/^(?:con|prn|aux|nul|com[0-9]|lpt[0-9]) *(?:\.|$)/u.test(lower) ||
42
- (lower === DEFAULT_IGNORE_FILENAME && value !== DEFAULT_IGNORE_FILENAME) ||
43
- RESERVED_FILENAMES.has(lower) ||
44
- isDeniedPath(lower)) {
45
- throw new Error(`Invalid sync.ignoreFile: "${value}" is a reserved filename.`);
46
- }
47
- return value;
48
- }
49
- export class IgnoreCreationPendingError extends Error {
50
- constructor() {
51
- super(`unfinished creation record "${DEFAULT_IGNORE_CREATION_RECORD}"; retry confirmed setup or migration to verify the starter file, or repair the incomplete creation first`);
52
- }
53
- }
54
- export async function readIgnoreSource(root, filename = DEFAULT_IGNORE_FILENAME, signal) {
55
- signal?.throwIfAborted();
56
- filename = validateIgnoreFilename(filename);
57
- try {
58
- const absoluteRoot = path.resolve(root);
59
- const rootStat = await fs.lstat(absoluteRoot, { bigint: true });
60
- if (!rootStat.isDirectory())
61
- throw new Error("the Pi agent directory is not a regular directory");
62
- const canonicalRoot = await fs.realpath(absoluteRoot);
63
- const checkRoot = async () => {
64
- const currentRealpath = await fs.realpath(absoluteRoot);
65
- const current = await fs.lstat(absoluteRoot, { bigint: true });
66
- if (currentRealpath !== canonicalRoot || !current.isDirectory() || !sameIdentity(rootStat, current))
67
- changed();
68
- signal?.throwIfAborted();
69
- checkCreationRecord();
70
- };
71
- const target = path.join(canonicalRoot, filename);
72
- const checkCreationRecord = () => {
73
- if (filename === DEFAULT_IGNORE_FILENAME &&
74
- lstatSync(path.join(canonicalRoot, DEFAULT_IGNORE_CREATION_RECORD), { throwIfNoEntry: false })) {
75
- throw new IgnoreCreationPendingError();
76
- }
77
- };
78
- checkCreationRecord();
79
- const before = await statIfPresent(target);
80
- await checkRoot();
81
- if (!before) {
82
- if (filename !== DEFAULT_IGNORE_FILENAME)
83
- throw new Error("the selected file does not exist");
84
- checkCreationRecord();
85
- if (lstatSync(target, { throwIfNoEntry: false }))
86
- changed();
87
- signal?.throwIfAborted();
88
- return {
89
- filename,
90
- text: DEFAULT_IGNORE_RULES,
91
- sourceDigest: ignoreSourceDigest(filename, false, Buffer.from(DEFAULT_IGNORE_RULES)),
92
- present: false,
93
- };
94
- }
95
- if (!before.isFile() || before.nlink !== 1n)
96
- throw new Error("use a regular file with no symlinks or hard links");
97
- assertIgnoreSize(before.size);
98
- if ((await fs.realpath(target)) !== target)
99
- throw new Error("use the exact on-disk filename, not a path alias");
100
- const bytes = await readIgnoreBytes(target, before, checkRoot, signal);
101
- await checkRoot();
102
- checkCreationRecord();
103
- const current = lstatSync(target, { bigint: true, throwIfNoEntry: false });
104
- if (!current || !sameFile(before, current))
105
- changed();
106
- signal?.throwIfAborted();
107
- let text;
108
- try {
109
- text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
110
- }
111
- catch (cause) {
112
- throw new Error("the file is not valid UTF-8", { cause });
113
- }
114
- if (text.includes("\0"))
115
- throw new Error("the file contains NUL characters");
116
- return {
117
- filename,
118
- text,
119
- sourceDigest: ignoreSourceDigest(filename, true, bytes),
120
- present: true,
121
- identity: ignoreFileIdentity(before),
122
- };
123
- }
124
- catch (cause) {
125
- signal?.throwIfAborted();
126
- const detail = cause.code
127
- ? "could not verify or read the file"
128
- : cause.message;
129
- throw new Error(`Ignore file "${filename}": ${detail}.`, { cause });
130
- }
131
- }
132
- async function statIfPresent(target) {
133
- try {
134
- return await fs.lstat(target, { bigint: true });
135
- }
136
- catch (error) {
137
- if (error.code === "ENOENT")
138
- return undefined;
139
- throw error;
140
- }
141
- }
142
- export function ignoreFileIdentity(stat) {
143
- return `${stat.dev}:${stat.ino}:${stat.birthtimeNs}`;
144
- }
145
- export function sameIdentity(left, right) {
146
- return left.dev === right.dev && left.ino === right.ino && left.birthtimeNs === right.birthtimeNs;
147
- }
148
- export function sameFile(left, right) {
149
- return (sameIdentity(left, right) &&
150
- left.mode === right.mode &&
151
- left.uid === right.uid &&
152
- left.gid === right.gid &&
153
- left.nlink === right.nlink &&
154
- left.size === right.size &&
155
- left.mtimeNs === right.mtimeNs &&
156
- left.ctimeNs === right.ctimeNs);
157
- }
158
- function changed() {
159
- throw new Error("the file or Pi agent directory changed during the read; retry");
160
- }
161
- async function readIgnoreBytes(target, before, checkRoot, signal) {
162
- signal?.throwIfAborted();
163
- const flags = constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0);
164
- const handle = await fs.open(target, flags);
165
- try {
166
- if (!sameFile(before, await handle.stat({ bigint: true })))
167
- changed();
168
- await checkRoot();
169
- const buffer = Buffer.alloc(Number(before.size) + 1);
170
- let count = 0;
171
- while (count < buffer.length) {
172
- signal?.throwIfAborted();
173
- const { bytesRead } = await handle.read(buffer, count, buffer.length - count, count);
174
- if (bytesRead === 0)
175
- break;
176
- count += bytesRead;
177
- }
178
- if (count !== Number(before.size))
179
- changed();
180
- if (!sameFile(before, await fs.lstat(target, { bigint: true })))
181
- changed();
182
- await checkRoot();
183
- if (!sameFile(before, await handle.stat({ bigint: true })))
184
- changed();
185
- return buffer.subarray(0, count);
186
- }
187
- finally {
188
- await handle.close();
189
- }
190
- }
191
- function assertIgnoreSize(bytes) {
192
- if (bytes > MAX_IGNORE_BYTES)
193
- throw new Error(`rules exceed the ${MAX_IGNORE_BYTES}-byte limit`);
194
- }
195
- export function ignoreSourceDigest(filename, present, bytes) {
196
- return createHash("sha256")
197
- .update("pi-sync-ignore-source-v1\0")
198
- .update(filename)
199
- .update(present ? "\0present\0" : "\0absent\0")
200
- .update(bytes)
201
- .digest("hex");
202
- }
203
- export function ignorePolicyFingerprint(text, sessions) {
204
- return createHash("sha256")
205
- .update(JSON.stringify(["pi-sync-ignore-policy-v1", sessions, text]))
206
- .digest("hex");
207
- }
208
- function gitByteString(value) {
209
- return Buffer.from(value, "utf8").toString("latin1");
210
- }
211
- export function compileIgnoreRules(text) {
212
- assertIgnoreSize(Buffer.byteLength(text, "utf8"));
213
- if (!text.isWellFormed() || text.includes("\0"))
214
- throw new Error("Ignore rules must be UTF-8 text without NULs.");
215
- const rules = text.replace(/^\uFEFF/u, "");
216
- for (const [index, line] of rules.split("\n").entries()) {
217
- if (line.startsWith("#"))
218
- continue;
219
- for (let position = 0; position < line.length; position++) {
220
- if (line[position] !== "\\")
221
- continue;
222
- if (line[++position] === "/") {
223
- throw new Error(`Ignore rule on line ${index + 1} uses an unsupported escaped path separator.`);
224
- }
225
- }
226
- }
227
- const compiled = ignore({ ignorecase: false }).add(gitByteString(rules));
228
- let matcher = ignore({ ignorecase: false }).add(compiled);
229
- let cachedPathUpperBound = 0;
230
- return (relativePath, directory = false) => {
231
- if (Buffer.byteLength(relativePath, "utf8") > MAX_MATCH_PATH_BYTES) {
232
- throw new Error(`Ignore matching path exceeds the ${MAX_MATCH_PATH_BYTES}-byte limit.`);
233
- }
234
- const segments = relativePath.split("/");
235
- if (!relativePath.isWellFormed() ||
236
- relativePath.includes("\\") ||
237
- relativePath.includes("\0") ||
238
- /^[a-z]:/iu.test(relativePath) ||
239
- segments.some((part) => !part || part === "." || part === "..")) {
240
- throw new Error("Ignore matching requires a canonical relative path with / separators.");
241
- }
242
- if (cachedPathUpperBound + segments.length > MATCH_CACHE_PATH_BUDGET) {
243
- matcher = ignore({ ignorecase: false }).add(compiled);
244
- cachedPathUpperBound = 0;
245
- }
246
- cachedPathUpperBound += segments.length;
247
- const serializedPath = gitByteString(relativePath);
248
- return matcher.ignores(directory ? `${serializedPath}/` : serializedPath);
249
- };
250
- }
@@ -1,39 +0,0 @@
1
- import { RULES_SNAPSHOT_VERSION } from "../snapshot/snapshot-types.js";
2
- import { compileIgnoreRules, DEFAULT_IGNORE_FILENAME, ignorePolicyFingerprint, ignoreSourceDigest, validateIgnoreFilename, } from "./ignore-source.js";
3
- export function validateSnapshotIgnoreRules(snapshot) {
4
- if (snapshot.version !== RULES_SNAPSHOT_VERSION) {
5
- if (Object.hasOwn(snapshot, "ignoreRules"))
6
- throw new Error("Unexpected snapshot ignore rules.");
7
- return;
8
- }
9
- const selection = snapshot.selection;
10
- if (selection?.version !== 4 || !Object.hasOwn(snapshot, "ignoreRules"))
11
- throw new Error("Missing snapshot ignore policy.");
12
- const rules = snapshot.ignoreRules;
13
- if (rules === null)
14
- return;
15
- if (!rules ||
16
- typeof rules !== "object" ||
17
- !Object.hasOwn(rules, "text") ||
18
- !Object.hasOwn(rules, "filename") ||
19
- Object.keys(rules).length !== 2 ||
20
- typeof rules.text !== "string")
21
- throw new Error("Invalid snapshot ignore rules.");
22
- const filename = validateIgnoreFilename(rules.filename);
23
- const matches = compileIgnoreRules(rules.text);
24
- if (matches(filename) || ignorePolicyFingerprint(rules.text, selection.sessions) !== selection.fingerprint)
25
- throw new Error("Snapshot ignore rules do not match the published policy.");
26
- return {
27
- filename,
28
- fingerprint: selection.fingerprint,
29
- sessions: selection.sessions,
30
- sourceDigest: ignoreSourceDigest(filename, true, Buffer.from(rules.text)),
31
- reservedNames: [...new Set([DEFAULT_IGNORE_FILENAME, filename.toLowerCase()])].sort(),
32
- matches,
33
- };
34
- }
35
- export function selectSnapshotIgnoreRules(source, policy) {
36
- if (!source.present || source.filename !== policy.filename || source.sourceDigest !== policy.sourceDigest)
37
- throw new Error("Ignore file changed before publication; reopen the review.");
38
- return policy.matches(source.filename) ? null : { filename: source.filename, text: source.text };
39
- }
@@ -1,50 +0,0 @@
1
- import { loadAdoptionJournal, verifyAdoptionBackup } from "../ignore/adoption-journal.js";
2
- import { compileIgnoreRules, ignorePolicyFingerprint, ignoreSourceDigest } from "../ignore/ignore-source.js";
3
- import { loadConfigForCheck } from "../settings/config.js";
4
- import { resolvedSnapshotOptionsForContext } from "../snapshot/session-paths.js";
5
- import { recoverPendingSnapshotTransactions } from "../snapshot/snapshot-transaction.js";
6
- import { pendingTransactionEntries } from "../snapshot/snapshot-transaction-directory.js";
7
- import { withLock } from "../state/lock.js";
8
- import { readStateForConfig, syncStateFingerprint } from "../state/sync-state-store.js";
9
- import { adoptionSettingsFingerprint } from "./ignore-adoption.js";
10
- export async function recoverAdoptionFilesOnStartup(ctx, signal, validate) {
11
- await withLock("recovery", async () => {
12
- validate();
13
- if (!(await pendingTransactionEntries()).length)
14
- return;
15
- const journal = await loadAdoptionJournal();
16
- if (!journal)
17
- throw new Error("Adoption recovery evidence changed; restart Pi Sync before editing files.");
18
- const config = await loadConfigForCheck(journal.setupName, signal);
19
- const policy = config.ignorePolicy;
20
- const stale = () => new Error("Pending adoption and file transaction no longer match. Preserve both journals.");
21
- if (!policy ||
22
- adoptionSettingsFingerprint(config) !== journal.setupFingerprint ||
23
- policy.filename !== journal.filename ||
24
- config.ignoreSourceIdentity !== journal.sourceIdentity ||
25
- policy.fingerprint !== ignorePolicyFingerprint(journal.beforeRules, policy.sessions) ||
26
- syncStateFingerprint(await readStateForConfig(config)) !== journal.stateFingerprint)
27
- throw stale();
28
- const options = await resolvedSnapshotOptionsForContext(ctx, config, signal);
29
- if (options.sessionDir !== journal.sessionDir)
30
- throw stale();
31
- await verifyAdoptionBackup(journal, signal);
32
- validate();
33
- const current = ctx.sessionManager.getSessionFile?.();
34
- await recoverPendingSnapshotTransactions({
35
- ...options,
36
- ignorePolicy: {
37
- ...policy,
38
- fingerprint: ignorePolicyFingerprint(journal.afterRules, policy.sessions),
39
- sourceDigest: ignoreSourceDigest(journal.filename, true, Buffer.from(journal.afterRules)),
40
- matches: compileIgnoreRules(journal.afterRules),
41
- },
42
- validateMutation: validate,
43
- protectedTargets: [...(ctx.protectedSessionFiles ?? []), ...(current ? [current] : [])],
44
- });
45
- validate();
46
- if ((await pendingTransactionEntries()).length)
47
- throw stale();
48
- validate();
49
- }, { reclaimStale: true });
50
- }