@narumitw/pi-sync 0.67.3 → 0.68.1

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 (175) hide show
  1. package/CHANGELOG.md +13 -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-CQ4DMLH3.ts → chunk-WQXUZSY5.ts} +25 -83
  21. package/dist/chunks/chunk-WQXUZSY5.ts.map +7 -0
  22. package/dist/chunks/{chunk-JREGWM2B.ts → chunk-XNUARYLR.ts} +1 -2
  23. package/dist/chunks/{command-handler-WF2TDDRZ.ts → command-handler-5LDTCUJE.ts} +64 -59
  24. package/dist/chunks/command-handler-5LDTCUJE.ts.map +7 -0
  25. package/dist/chunks/{conflict-review-GWEL4S6C.ts → conflict-review-SZ3AWTX6.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-OTI4JDQ2.ts} +5 -5
  37. package/dist/chunks/{sync-operations-AGNL7QXA.ts → sync-operations-ZUYJLWUN.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 +81 -65
  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/ui/sync-format.js +1 -1
  86. package/dist/daemon/dist/engine-service.js +60 -219
  87. package/dist/daemon/dist/foreground-queue-outcome.js +0 -4
  88. package/dist/daemon/dist/legacy-consent-guard.js +34 -0
  89. package/dist/daemon/dist/server.js +4 -8
  90. package/dist/daemon/dist/service-host.js +4 -10
  91. package/dist/daemon/package.json +1 -1
  92. package/dist/index.ts +45 -46
  93. package/dist/index.ts.map +3 -3
  94. package/docs/continuous-sync-verification.md +1 -1
  95. package/docs/daemon-migration.md +7 -5
  96. package/docs/tui-contract.md +4 -6
  97. package/package.json +2 -3
  98. package/skills/configure-pi-sync/SKILL.md +18 -77
  99. package/skills/configure-pi-sync/references/configuration.md +60 -77
  100. package/src/commands/command-execution.ts +13 -29
  101. package/src/commands/command-handler.ts +0 -4
  102. package/src/commands/command.ts +2 -1
  103. package/src/daemon/directional-recovery.ts +4 -33
  104. package/src/daemon/pi-client.ts +28 -90
  105. package/src/settings/config.ts +0 -1
  106. package/src/sync/setup-switch.ts +1 -4
  107. package/src/sync-extension.ts +10 -24
  108. package/src/ui/cancellable-operation.ts +2 -13
  109. package/src/ui/excluded-paths-ui.ts +1 -4
  110. package/src/ui/file-selection.ts +0 -5
  111. package/src/ui/manager-state.ts +12 -75
  112. package/src/ui/manager-ui.ts +7 -96
  113. package/src/ui/remote-selection-ui.ts +29 -130
  114. package/src/ui/settings-ui.ts +169 -388
  115. package/src/ui/setup/setup-actions.ts +4 -16
  116. package/src/ui/setup/setup-prompts.ts +12 -49
  117. package/src/ui/setup/setup-switcher.ts +8 -14
  118. package/src/ui/storage-connections-ui.ts +21 -32
  119. package/src/ui/sync-setups-ui.ts +27 -53
  120. package/dist/chunks/chunk-2MUAR5GH.ts.map +0 -7
  121. package/dist/chunks/chunk-33EDXDLC.ts +0 -106
  122. package/dist/chunks/chunk-33EDXDLC.ts.map +0 -7
  123. package/dist/chunks/chunk-AVTW6WNP.ts.map +0 -7
  124. package/dist/chunks/chunk-CQ4DMLH3.ts.map +0 -7
  125. package/dist/chunks/chunk-DGVZYS7T.ts.map +0 -7
  126. package/dist/chunks/chunk-EJDDRS6O.ts +0 -17
  127. package/dist/chunks/chunk-EJDDRS6O.ts.map +0 -7
  128. package/dist/chunks/chunk-KNEUL4XN.ts +0 -30
  129. package/dist/chunks/chunk-KNEUL4XN.ts.map +0 -7
  130. package/dist/chunks/chunk-PUSMSKIM.ts.map +0 -7
  131. package/dist/chunks/chunk-WFBHWYI6.ts +0 -18
  132. package/dist/chunks/chunk-WFBHWYI6.ts.map +0 -7
  133. package/dist/chunks/chunk-X344HTVV.ts.map +0 -7
  134. package/dist/chunks/command-handler-WF2TDDRZ.ts.map +0 -7
  135. package/dist/chunks/config-P54GGMXY.ts +0 -39
  136. package/dist/chunks/continuous-record-3SKJ6I3V.ts +0 -23
  137. package/dist/chunks/continuous-record-3SKJ6I3V.ts.map +0 -7
  138. package/dist/chunks/continuous-storage-3EU6I7Z3.ts +0 -27
  139. package/dist/chunks/continuous-storage-3EU6I7Z3.ts.map +0 -7
  140. package/dist/chunks/file-selection-GASCVN45.ts.map +0 -7
  141. package/dist/chunks/ignore-file-ui-BEZZZIEE.ts +0 -21
  142. package/dist/chunks/manager-ui-FS4QIKRA.ts.map +0 -7
  143. package/dist/chunks/merge-review-C2KETZKY.ts +0 -11
  144. package/dist/chunks/merge-review-C2KETZKY.ts.map +0 -7
  145. package/dist/chunks/remote-selection-ui-DOYKUMER.ts.map +0 -7
  146. package/dist/chunks/setup-switch-JZDFQPVW.ts.map +0 -7
  147. package/dist/daemon/dist/engine/ignore/adoption-journal.js +0 -146
  148. package/dist/daemon/dist/engine/ignore/effective-ignore-policy.js +0 -33
  149. package/dist/daemon/dist/engine/ignore/ignore-edit.js +0 -102
  150. package/dist/daemon/dist/engine/ignore/ignore-initialization.js +0 -288
  151. package/dist/daemon/dist/engine/ignore/ignore-migration-prompt.js +0 -139
  152. package/dist/daemon/dist/engine/ignore/ignore-settings.js +0 -391
  153. package/dist/daemon/dist/engine/ignore/ignore-source.js +0 -250
  154. package/dist/daemon/dist/engine/ignore/snapshot-ignore-rules.js +0 -39
  155. package/dist/daemon/dist/engine/sync/ignore-adoption-recovery.js +0 -50
  156. package/dist/daemon/dist/engine/sync/ignore-adoption.js +0 -416
  157. package/dist/daemon/dist/engine/sync/ignore-publication.js +0 -23
  158. package/dist/daemon/dist/engine/ui/ignore-rule-preview.js +0 -18
  159. package/dist/daemon/dist/monitor.js +0 -344
  160. package/src/ui/agent-mode-setting.ts +0 -99
  161. package/src/ui/ignore-file-guidance.ts +0 -7
  162. package/src/ui/ignore-file-ui.ts +0 -105
  163. package/src/ui/ignore-migration-prompt.ts +0 -65
  164. package/src/ui/settings-review.ts +0 -26
  165. /package/dist/chunks/{chunk-HLJIRWFL.ts.map → chunk-BCDBT4X3.ts.map} +0 -0
  166. /package/dist/chunks/{chunk-WBIOSK76.ts.map → chunk-R7PN3KIY.ts.map} +0 -0
  167. /package/dist/chunks/{chunk-3Q3DMMID.ts.map → chunk-TLYT6HVI.ts.map} +0 -0
  168. /package/dist/chunks/{chunk-JREGWM2B.ts.map → chunk-XNUARYLR.ts.map} +0 -0
  169. /package/dist/chunks/{conflict-review-GWEL4S6C.ts.map → conflict-review-SZ3AWTX6.ts.map} +0 -0
  170. /package/dist/chunks/{config-P54GGMXY.ts.map → manager-result-dispatcher-A4IWLS4J.ts.map} +0 -0
  171. /package/dist/chunks/{chunk-ECUCXF5Y.ts.map → merge-review-LWMUE5IW.ts.map} +0 -0
  172. /package/dist/chunks/{ignore-file-ui-BEZZZIEE.ts.map → remote-selection-ui-F6NJBQ3Y.ts.map} +0 -0
  173. /package/dist/chunks/{manager-result-dispatcher-BXN46NRC.ts.map → setup-switch-7LMIRMZ7.ts.map} +0 -0
  174. /package/dist/chunks/{sync-inspection-DI5J6EUH.ts.map → sync-inspection-OTI4JDQ2.ts.map} +0 -0
  175. /package/dist/chunks/{sync-operations-AGNL7QXA.ts.map → sync-operations-ZUYJLWUN.ts.map} +0 -0
@@ -3,7 +3,7 @@ import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { isPathInside, toPosix } from "../paths.js";
5
5
  import { mergePathIdentity } from "../sync/file-merge-planner.js";
6
- import { compileSyncPolicyExclude, compileSyncPolicyTraversal, configuredSnapshotPathMatcher, isIgnoreControlPath, } from "../sync/sync-policy.js";
6
+ import { compileSyncPolicyExclude, compileSyncPolicyTraversal, configuredSnapshotPathMatcher, } from "../sync/sync-policy.js";
7
7
  import { sessionStorageRoot } from "./snapshot-paths.js";
8
8
  function directoryStat(absolute) {
9
9
  try {
@@ -56,75 +56,31 @@ export function agentDirectoryAnchor(root, boundary) {
56
56
  }
57
57
  return anchor;
58
58
  }
59
- export function agentDirectorySessionRoot(root, sessionDir, ignorePolicy, reservedIgnoreNames) {
59
+ export function agentDirectorySessionRoot(root, sessionDir) {
60
60
  const sessionRoot = sessionStorageRoot(root, sessionDir);
61
61
  if (physicalRelative(sessionRoot, root) !== undefined)
62
62
  throw new Error("Pi session storage overlaps the agent directory root.");
63
63
  const relative = physicalRelative(root, sessionRoot);
64
64
  if (relative !== undefined) {
65
- const logical = toPosix(relative);
66
65
  const canTraverse = compileSyncPolicyTraversal({ scope: "agent-directory", include: ["sessions"] });
67
- const reserved = ignorePolicy || reservedIgnoreNames
68
- ? new Set([
69
- ...(ignorePolicy ? [ignorePolicy.filename, ...ignorePolicy.reservedNames] : []),
70
- ...(reservedIgnoreNames ?? []),
71
- ].map((name) => name.toLowerCase()))
72
- : undefined;
73
- if (!canTraverse(logical) || (reserved && isIgnoreControlPath(logical, reserved)))
66
+ if (!canTraverse(toPosix(relative)))
74
67
  throw new Error("Pi session storage overlaps protected agent files.");
75
68
  }
76
69
  return sessionRoot;
77
70
  }
78
- export function agentDirectoryPhysicalSessionPath(root, sessionDir, ignorePolicy, reservedIgnoreNames) {
79
- const sessionRoot = agentDirectorySessionRoot(root, sessionDir, ignorePolicy, reservedIgnoreNames);
71
+ export function agentDirectoryPhysicalSessionPath(root, sessionDir) {
72
+ const sessionRoot = agentDirectorySessionRoot(root, sessionDir);
80
73
  const nested = physicalRelative(root, sessionRoot) !== undefined;
81
74
  return (relativePath) => nested && physicalRelative(sessionRoot, path.resolve(root, relativePath)) !== undefined;
82
75
  }
83
- async function realpathWithMissingTail(target) {
84
- let ancestor = path.resolve(target);
85
- for (;;) {
86
- try {
87
- const resolved = await fs.realpath(ancestor);
88
- return path.resolve(resolved, path.relative(ancestor, target));
89
- }
90
- catch (error) {
91
- const code = error.code;
92
- const parent = path.dirname(ancestor);
93
- if (parent === ancestor || (code !== "ENOENT" && code !== "ENOTDIR"))
94
- throw error;
95
- ancestor = parent;
96
- }
97
- }
98
- }
99
- export function reservedIgnoreTargetGuard(root, options) {
100
- if (options.reservedIgnoreNames === undefined)
101
- return undefined;
102
- const reserved = new Set(options.reservedIgnoreNames);
103
- function check(agentRoot, target) {
104
- const relative = physicalRelative(agentRoot, target);
105
- if (physicalRelative(target, agentRoot) !== undefined ||
106
- (relative !== undefined && isIgnoreControlPath(toPosix(relative), reserved)))
107
- throw new Error("Transfer would access a protected ignore rule path or its ancestor.");
108
- }
109
- return async (target) => {
110
- check(root, target);
111
- const canonicalRoot = await realpathWithMissingTail(root);
112
- const canonicalTarget = await realpathWithMissingTail(target);
113
- check(canonicalRoot, canonicalTarget);
114
- return canonicalTarget;
115
- };
116
- }
117
76
  /** Metadata-only preflight: an ancestor replacement must not capture/remove excluded descendants. */
118
77
  export async function assertUnexcludedTargets(root, targets, options, { recursive = true } = {}) {
119
78
  const wholeDirectory = options.scope === "agent-directory";
120
- const guardReserved = reservedIgnoreTargetGuard(root, options);
121
- if (!wholeDirectory &&
122
- !guardReserved &&
123
- (options.exclude === undefined || (Array.isArray(options.exclude) && !options.exclude.length)))
79
+ if (!wholeDirectory && (options.exclude === undefined || (Array.isArray(options.exclude) && !options.exclude.length)))
124
80
  return;
125
81
  const excluded = compileSyncPolicyExclude(options);
126
82
  const sessionRoot = wholeDirectory
127
- ? agentDirectorySessionRoot(root, options.sessionDir, options.ignorePolicy, options.reservedIgnoreNames)
83
+ ? agentDirectorySessionRoot(root, options.sessionDir)
128
84
  : sessionStorageRoot(root, options.sessionDir);
129
85
  const configured = configuredSnapshotPathMatcher(options);
130
86
  let visited = 0;
@@ -137,16 +93,11 @@ export async function assertUnexcludedTargets(root, targets, options, { recursiv
137
93
  if (++visited > 16_384)
138
94
  throw new Error("Exclude safety preflight exceeds its path bound; review a smaller transfer.");
139
95
  };
140
- function refuse() {
96
+ const refuse = () => {
141
97
  throw new Error("Transfer would replace an excluded path or directory descendant; no replacement is authorized.");
142
- }
98
+ };
143
99
  async function visit(target) {
144
100
  validate();
145
- if (guardReserved) {
146
- await guardReserved(target);
147
- validate();
148
- }
149
- let logicalPath;
150
101
  let sessionPath;
151
102
  if (wholeDirectory) {
152
103
  if (physicalRelative(target, sessionRoot) !== undefined)
@@ -154,16 +105,14 @@ export async function assertUnexcludedTargets(root, targets, options, { recursiv
154
105
  const sessionRelative = physicalRelative(sessionRoot, target);
155
106
  if (sessionRelative !== undefined) {
156
107
  sessionPath = `sessions/${toPosix(sessionRelative)}`;
157
- logicalPath = sessionPath;
108
+ if (excluded(sessionPath))
109
+ refuse();
158
110
  }
159
111
  else {
160
112
  const relative = physicalRelative(root, target);
161
- if (!relative || /^sessions(?:\/|$)/iu.test(toPosix(relative)))
113
+ if (relative === undefined || /^sessions(?:\/|$)/iu.test(toPosix(relative)) || excluded(toPosix(relative)))
162
114
  refuse();
163
- logicalPath = toPosix(relative);
164
115
  }
165
- if (!options.ignorePolicy && excluded(logicalPath))
166
- refuse();
167
116
  }
168
117
  else {
169
118
  const candidates = [];
@@ -171,28 +120,22 @@ export async function assertUnexcludedTargets(root, targets, options, { recursiv
171
120
  candidates.push(toPosix(path.relative(root, target)));
172
121
  if (isPathInside(sessionRoot, target))
173
122
  candidates.push(`sessions/${toPosix(path.relative(sessionRoot, target))}`);
174
- if (candidates.some((candidate) => excluded(candidate)))
123
+ if (candidates.some(excluded))
175
124
  refuse();
176
125
  }
177
- let observed;
126
+ let stat;
178
127
  try {
179
- observed = await fs.lstat(target);
128
+ stat = await fs.lstat(target);
180
129
  }
181
130
  catch (error) {
131
+ validate();
182
132
  const code = error.code;
183
- if (code !== "ENOENT" && code !== "ENOTDIR") {
184
- validate();
133
+ if (code !== "ENOENT" && code !== "ENOTDIR")
185
134
  throw error;
186
- }
135
+ return;
187
136
  }
188
137
  validate();
189
- if (options.ignorePolicy && logicalPath !== undefined && excluded(logicalPath, observed?.isDirectory()))
190
- refuse();
191
- if (!observed)
192
- return;
193
- const stat = observed;
194
- if ((wholeDirectory && !stat.isDirectory() && (!stat.isFile() || stat.nlink !== 1)) ||
195
- (guardReserved && stat.isFile() && stat.nlink !== 1)) {
138
+ if (wholeDirectory && !stat.isDirectory() && (!stat.isFile() || stat.nlink !== 1)) {
196
139
  throw new Error("Refusing an unsafe symlink, hard link, or special file during snapshot mutation.");
197
140
  }
198
141
  if (sessionPath && stat.isFile() && !configured(sessionPath))
@@ -294,7 +294,7 @@ export async function recheckScopedImage(target, image, guards) {
294
294
  else if (await lstat(target, guards))
295
295
  changedImage();
296
296
  }
297
- export async function removeScopedImage(target, image, guards, validateIgnorePolicy) {
297
+ export async function removeScopedImage(target, image, guards) {
298
298
  if (image.kind === "missing")
299
299
  return;
300
300
  async function remove(target, node) {
@@ -303,18 +303,12 @@ export async function removeScopedImage(target, image, guards, validateIgnorePol
303
303
  const observed = await scopedTransactionImage(target, guards);
304
304
  if (observed.kind !== "file" || !sameObservation(node.stat, observed.stat) || observed.value !== node.value)
305
305
  changedImage();
306
- if (validateIgnorePolicy) {
307
- await validateIgnorePolicy();
308
- await recheck(target, node.stat, guards);
309
- }
310
306
  validate(guards);
311
307
  await fs.unlink(target);
312
308
  return;
313
309
  }
314
310
  for (const [name, child] of node.children)
315
311
  await remove(path.join(target, name), child);
316
- if (validateIgnorePolicy)
317
- await validateIgnorePolicy();
318
312
  await recheck(target, node.stat, guards, true);
319
313
  validate(guards);
320
314
  await fs.rmdir(target);
@@ -1,10 +1,10 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
- import { DEFAULT_IGNORE_FILENAME, validateIgnoreFilename } from "../ignore/ignore-source.js";
4
3
  import { assertWithinRoot, isDeniedPath, isPathInside } from "../paths.js";
4
+ import { retiredIgnorePolicy } from "../settings/retired-ignore-policy.js";
5
5
  import { normalizeSyncExclude, sameSyncExclude } from "../sync/exclude-policy.js";
6
6
  import { mergePathIdentity } from "../sync/file-merge-planner.js";
7
- import { localIgnorePolicyKey, portableSnapshotSelection, sameSnapshotSelection, selectionForSnapshot, syncDirectoryPolicyKey, } from "../sync/sync-policy.js";
7
+ import { portableSnapshotSelection, syncDirectoryPolicyKey } from "../sync/sync-policy.js";
8
8
  import { agentDir } from "./session-paths.js";
9
9
  import { isCaseReplacement } from "./snapshot-case-replacement.js";
10
10
  import { sessionStorageRoot } from "./snapshot-paths.js";
@@ -12,22 +12,11 @@ import { validateSessionRootTransition } from "./snapshot-root-transition.js";
12
12
  export const LEGACY_AGENT_DIRECTORY_JOURNAL_VERSION = 8;
13
13
  export const FIXED_WORKSPACE_JOURNAL_VERSION = 9;
14
14
  export const AGENT_DIRECTORY_JOURNAL_VERSION = 10;
15
- export const IGNORE_POLICY_JOURNAL_VERSION = 11;
16
- export const BOUND_DIRECTORY_JOURNAL_VERSION = 12;
17
- export const BOUND_INCLUDED_PATHS_JOURNAL_VERSION = 13;
18
- function isLocallyBoundJournal(journal) {
19
- return (journal.version === BOUND_DIRECTORY_JOURNAL_VERSION || journal.version === BOUND_INCLUDED_PATHS_JOURNAL_VERSION);
20
- }
21
- export function recoveryPolicyKey(options) {
22
- return options.setupName || options.reservedIgnoreNames !== undefined ? localIgnorePolicyKey(options) : undefined;
23
- }
24
15
  export function isScopedJournal(journal) {
25
16
  return [
26
17
  LEGACY_AGENT_DIRECTORY_JOURNAL_VERSION,
27
18
  FIXED_WORKSPACE_JOURNAL_VERSION,
28
19
  AGENT_DIRECTORY_JOURNAL_VERSION,
29
- IGNORE_POLICY_JOURNAL_VERSION,
30
- BOUND_DIRECTORY_JOURNAL_VERSION,
31
20
  ].includes(journal.version);
32
21
  }
33
22
  function usesSlottedWorkspace(journal) {
@@ -39,81 +28,11 @@ export function isRecoveryStageId(value) {
39
28
  export function isScopedIdentity(value) {
40
29
  return typeof value === "string" && /^\d{1,20}:[1-9]\d{0,19}:\d{1,20}$/u.test(value);
41
30
  }
42
- export function ignoreSourceBinding(policy) {
43
- const filename = validateIgnoreFilename(policy.filename);
44
- if (typeof policy.sourceDigest !== "string" ||
45
- policy.sourceDigest.length !== 64 ||
46
- !/^[0-9a-f]{64}$/u.test(policy.sourceDigest))
47
- throw new Error("Invalid ignore policy source digest.");
48
- return {
49
- version: 1,
50
- filename,
51
- sourceDigest: policy.sourceDigest,
52
- reservedNames: [
53
- ...new Set([DEFAULT_IGNORE_FILENAME, filename, ...policy.reservedNames].map((name) => validateIgnoreFilename(name).toLowerCase())),
54
- ].sort(),
55
- };
56
- }
57
- function sameIgnoreSource(left, right) {
58
- return (left.version === right.version &&
59
- left.filename === right.filename &&
60
- left.sourceDigest === right.sourceDigest &&
61
- left.reservedNames.length === right.reservedNames.length &&
62
- left.reservedNames.every((name, index) => name === right.reservedNames[index]));
63
- }
64
- export class StaleIgnorePolicyError extends Error {
65
- }
66
- export function ignorePolicyValidator(options) {
67
- const scopedIgnore = options.ignorePolicy !== undefined || options.version === 4;
68
- if (!scopedIgnore && options.reservedIgnoreNames === undefined && !options.validateIgnorePolicy)
69
- return;
70
- const validateIgnorePolicy = options.validateIgnorePolicy;
71
- if ((scopedIgnore && (!options.ignorePolicy || options.scope !== "agent-directory")) ||
72
- typeof validateIgnorePolicy !== "function")
73
- throw new Error("Ignore-file mutation requires an explicit local policy and a freshness check.");
74
- return async () => {
75
- options.validateMutation?.();
76
- options.signal?.throwIfAborted();
77
- try {
78
- const pending = validateIgnorePolicy();
79
- if (typeof pending?.then !== "function")
80
- throw new Error("The ignore policy freshness check must be async.");
81
- await pending;
82
- }
83
- catch (cause) {
84
- throw new StaleIgnorePolicyError("Pi Sync ignore policy changed or could not be verified; preserve any transaction evidence and reopen the review.", { cause });
85
- }
86
- options.validateMutation?.();
87
- options.signal?.throwIfAborted();
88
- };
89
- }
90
31
  export function validateJournalPolicy(journal) {
91
- if (!journal ||
92
- (![1, 2, 3, 4, 5, 6, 7].includes(journal.version) && !isScopedJournal(journal) && !isLocallyBoundJournal(journal)))
32
+ if (journal && ([11, 12, 13].includes(journal.version) || Object.hasOwn(journal, "ignoreSource")))
33
+ throw retiredIgnorePolicy("recovery");
34
+ if (!journal || (![1, 2, 3, 4, 5, 6, 7].includes(journal.version) && !isScopedJournal(journal)))
93
35
  throw new Error("Unsupported pi-sync transaction journal; preserve evidence for review.");
94
- if (isLocallyBoundJournal(journal)
95
- ? typeof journal.localPolicyKey !== "string" || !/^[0-9a-f]{64}$/u.test(journal.localPolicyKey)
96
- : journal.localPolicyKey !== undefined)
97
- throw new Error("Invalid transaction local policy binding; preserve evidence for review.");
98
- if (journal.version === IGNORE_POLICY_JOURNAL_VERSION ||
99
- (journal.version === BOUND_DIRECTORY_JOURNAL_VERSION && journal.selection?.version === 4)) {
100
- const binding = journal.ignoreSource;
101
- try {
102
- if (journal.exclude === undefined &&
103
- portableSnapshotSelection(journal.selection).version === 4 &&
104
- binding &&
105
- Array.isArray(binding.reservedNames) &&
106
- Object.keys(binding).length === 4 &&
107
- sameIgnoreSource(binding, ignoreSourceBinding(binding)))
108
- return;
109
- }
110
- catch (cause) {
111
- throw new Error("Invalid ignore-file transaction policy; preserve evidence for review.", { cause });
112
- }
113
- throw new Error("Invalid ignore-file transaction policy; preserve evidence for review.");
114
- }
115
- if (journal.ignoreSource !== undefined)
116
- throw new Error("Unsupported transaction ignore source binding; preserve evidence for review.");
117
36
  if (isScopedJournal(journal)) {
118
37
  if (journal.exclude !== undefined || portableSnapshotSelection(journal.selection).version !== 3)
119
38
  throw new Error("Invalid agent-directory transaction policy; preserve evidence.");
@@ -126,18 +45,6 @@ export function validateJournalPolicy(journal) {
126
45
  normalizeSyncExclude(journal.exclude);
127
46
  }
128
47
  export function assertRecoveryPolicy(journal, options) {
129
- const localKey = recoveryPolicyKey(options);
130
- if (journal.localPolicyKey !== localKey)
131
- throw new Error("Pending transaction has different setup or ignore policy evidence; preserve its backup for reviewed recovery.");
132
- if (journal.ignoreSource || options.ignorePolicy || options.version === 4) {
133
- if (journal.ignoreSource &&
134
- options.scope === "agent-directory" &&
135
- options.ignorePolicy &&
136
- sameIgnoreSource(journal.ignoreSource, ignoreSourceBinding(options.ignorePolicy)) &&
137
- sameSnapshotSelection(journal.selection, selectionForSnapshot(undefined, undefined, options)))
138
- return;
139
- throw new Error("Pending transaction has a different ignore-file policy; preserve its backup for reviewed recovery.");
140
- }
141
48
  const directoryKey = syncDirectoryPolicyKey(journal.selection ?? {});
142
49
  const effectiveDirectoryKey = syncDirectoryPolicyKey(options);
143
50
  if (directoryKey !== undefined
@@ -153,14 +60,13 @@ export function validateJournal(directory, journal, sessionDir) {
153
60
  if (!Array.isArray(journal.entries) || journal.entries.length > 16_384)
154
61
  throw new Error("Unsupported pi-sync transaction journal; preserve evidence for review.");
155
62
  if (journal.completed !== undefined &&
156
- ((!wholeDirectory && ![6, 7, BOUND_INCLUDED_PATHS_JOURNAL_VERSION].includes(journal.version)) ||
157
- journal.completed !== true))
63
+ ((!wholeDirectory && ![6, 7].includes(journal.version)) || journal.completed !== true))
158
64
  throw new Error("Invalid transaction completion evidence.");
159
65
  const root = path.resolve(agentDir());
160
66
  if (typeof journal.root !== "string" || path.resolve(journal.root) !== root)
161
67
  throw new Error("Transaction root no longer matches the Pi agent directory.");
162
68
  if (journal.sessionRootTransition !== undefined) {
163
- if (![7, BOUND_INCLUDED_PATHS_JOURNAL_VERSION].includes(journal.version) || typeof journal.sessionRoot !== "string")
69
+ if (![7].includes(journal.version) || typeof journal.sessionRoot !== "string")
164
70
  throw new Error("Invalid session root-transition version.");
165
71
  validateSessionRootTransition(journal.sessionRootTransition);
166
72
  }
@@ -191,7 +97,7 @@ export function validateJournal(directory, journal, sessionDir) {
191
97
  assertWithinRoot(directory, path.join(directory, "before", entry.backupName));
192
98
  assertAllowedTarget(root, journal.sessionRoot, entry.target);
193
99
  if (entry.afterTarget !== undefined &&
194
- ((!wholeDirectory && ![5, 6, 7, BOUND_INCLUDED_PATHS_JOURNAL_VERSION].includes(journal.version)) ||
100
+ ((!wholeDirectory && ![5, 6, 7].includes(journal.version)) ||
195
101
  typeof entry.afterTarget !== "string" ||
196
102
  !isCaseReplacement(root, entry.target, entry.afterTarget) ||
197
103
  path.resolve(entry.afterTarget) !== entry.afterTarget ||