@narumitw/pi-sync 0.57.9 → 0.57.10

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 (147) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +2 -0
  3. package/dist/chunks/{agent-candidate-GNEYR225.ts → agent-candidate-EYB35AGL.ts} +12 -9
  4. package/dist/chunks/{agent-plan-3L7CRFDM.ts → agent-plan-KO43GTOR.ts} +22 -18
  5. package/dist/chunks/{agent-plan-3L7CRFDM.ts.map → agent-plan-KO43GTOR.ts.map} +1 -1
  6. package/dist/chunks/{agent-refusal-retry-RPTMUQXK.ts → agent-refusal-retry-C2HQROTP.ts} +11 -8
  7. package/dist/chunks/{agent-refusal-retry-RPTMUQXK.ts.map → agent-refusal-retry-C2HQROTP.ts.map} +1 -1
  8. package/dist/chunks/{agent-store-55CZOCPX.ts → agent-store-UT52DS7B.ts} +12 -11
  9. package/dist/chunks/{agent-store-55CZOCPX.ts.map → agent-store-UT52DS7B.ts.map} +1 -1
  10. package/dist/chunks/agent-sync-VM3TXWA3.ts +22 -0
  11. package/dist/chunks/{chunk-6FVVRTL5.ts → chunk-2VSN3MFX.ts} +71 -63
  12. package/dist/chunks/{chunk-6FVVRTL5.ts.map → chunk-2VSN3MFX.ts.map} +1 -1
  13. package/dist/chunks/{chunk-PG7NMFP2.ts → chunk-4RLATUP4.ts} +7 -7
  14. package/dist/chunks/chunk-5SFMBY5P.ts +26 -0
  15. package/dist/chunks/chunk-5SFMBY5P.ts.map +7 -0
  16. package/dist/chunks/chunk-5WJQ6XOW.ts +27 -0
  17. package/dist/chunks/chunk-5WJQ6XOW.ts.map +7 -0
  18. package/dist/chunks/{chunk-GNH73BJ5.ts → chunk-66GAUVDL.ts} +7 -7
  19. package/dist/chunks/{chunk-UPNVIUBN.ts → chunk-73MDIVYJ.ts} +3 -3
  20. package/dist/chunks/{chunk-CRKTAPSL.ts → chunk-AAPAHANE.ts} +24 -29
  21. package/dist/chunks/chunk-AAPAHANE.ts.map +7 -0
  22. package/dist/chunks/{chunk-S7QS4AWK.ts → chunk-AO6EDUA6.ts} +5 -5
  23. package/dist/chunks/chunk-AR2DGDUI.ts +55 -0
  24. package/dist/chunks/chunk-AR2DGDUI.ts.map +7 -0
  25. package/dist/chunks/{chunk-JCH3VXIO.ts → chunk-BJXSCGQK.ts} +9 -9
  26. package/dist/chunks/{chunk-IWZH5KYS.ts → chunk-CDQGSZL3.ts} +7 -7
  27. package/dist/chunks/chunk-DFJGTVPX.ts +319 -0
  28. package/dist/chunks/chunk-DFJGTVPX.ts.map +7 -0
  29. package/dist/chunks/chunk-DO55XUNU.ts +104 -0
  30. package/dist/chunks/chunk-DO55XUNU.ts.map +7 -0
  31. package/dist/chunks/{chunk-ED3TYIVW.ts → chunk-DOJRPBQU.ts} +5 -5
  32. package/dist/chunks/{chunk-5QAE3G3K.ts → chunk-IMMMZUFC.ts} +6 -6
  33. package/dist/chunks/{chunk-B4QZBDBT.ts → chunk-JXWTEJS5.ts} +3 -3
  34. package/dist/chunks/{chunk-BDB4IDM3.ts → chunk-JY2RVOUL.ts} +8 -6
  35. package/dist/chunks/{chunk-BDB4IDM3.ts.map → chunk-JY2RVOUL.ts.map} +1 -1
  36. package/dist/chunks/{chunk-P7DD5PWZ.ts → chunk-M5IV3KL2.ts} +3 -3
  37. package/dist/chunks/{chunk-AAEEHR7H.ts → chunk-MDUORMCK.ts} +2 -2
  38. package/dist/chunks/{chunk-UBV24CG4.ts → chunk-MRIPZGPR.ts} +3 -3
  39. package/dist/chunks/{chunk-MKKF4IMY.ts → chunk-ODF2M4RF.ts} +5 -5
  40. package/dist/chunks/chunk-PHANBTVM.ts +348 -0
  41. package/dist/chunks/chunk-PHANBTVM.ts.map +7 -0
  42. package/dist/chunks/{chunk-GP5DU62N.ts → chunk-PWA3YN5Z.ts} +2 -2
  43. package/dist/chunks/{chunk-YK52VDXG.ts → chunk-QWV3XKNJ.ts} +10 -8
  44. package/dist/chunks/{chunk-YK52VDXG.ts.map → chunk-QWV3XKNJ.ts.map} +1 -1
  45. package/dist/chunks/{chunk-ORGBI36T.ts → chunk-RAMHGOX2.ts} +4 -4
  46. package/dist/chunks/{chunk-QO333NM4.ts → chunk-RX3WGWVL.ts} +5 -5
  47. package/dist/chunks/chunk-RX3WGWVL.ts.map +7 -0
  48. package/dist/chunks/{chunk-PQW6GS4J.ts → chunk-STVQQ5KG.ts} +12 -10
  49. package/dist/chunks/{chunk-PQW6GS4J.ts.map → chunk-STVQQ5KG.ts.map} +1 -1
  50. package/dist/chunks/{chunk-76NB4R7U.ts → chunk-TO2GMX3K.ts} +2 -2
  51. package/dist/chunks/{chunk-GSNPASKB.ts → chunk-U77DWNRH.ts} +6 -6
  52. package/dist/chunks/{chunk-U3XRI2HF.ts → chunk-UCD7TQDT.ts} +11 -11
  53. package/dist/chunks/{chunk-A6HU4ERM.ts → chunk-UGSSZWQ6.ts} +6 -23
  54. package/dist/chunks/chunk-UGSSZWQ6.ts.map +7 -0
  55. package/dist/chunks/chunk-X7R6DCVF.ts +28 -0
  56. package/dist/chunks/chunk-X7R6DCVF.ts.map +7 -0
  57. package/dist/chunks/{chunk-HUZ5CR4W.ts → chunk-YZ5BQNRZ.ts} +2 -51
  58. package/dist/chunks/{chunk-HUZ5CR4W.ts.map → chunk-YZ5BQNRZ.ts.map} +4 -4
  59. package/dist/chunks/{chunk-UOHR7LRO.ts → chunk-Z5O2TLNF.ts} +9 -21
  60. package/dist/chunks/chunk-Z5O2TLNF.ts.map +7 -0
  61. package/dist/chunks/command-handler-FO6F2APH.ts +543 -0
  62. package/dist/chunks/command-handler-FO6F2APH.ts.map +7 -0
  63. package/dist/chunks/{config-KGIYTTXQ.ts → config-B37W7FXW.ts} +5 -6
  64. package/dist/chunks/{conflict-artifacts-FXFIIBCB.ts → conflict-artifacts-6XGSSU5S.ts} +13 -9
  65. package/dist/chunks/{conflict-review-3X37QEIT.ts → conflict-review-BQSHSJB3.ts} +31 -25
  66. package/dist/chunks/{conflict-review-3X37QEIT.ts.map → conflict-review-BQSHSJB3.ts.map} +1 -1
  67. package/dist/chunks/{continuous-record-SQJ47CXN.ts → continuous-record-4DQ2EAZS.ts} +8 -7
  68. package/dist/chunks/{continuous-sync-Q6QUD6TY.ts → continuous-sync-ZT3UEQLK.ts} +33 -28
  69. package/dist/chunks/{continuous-sync-Q6QUD6TY.ts.map → continuous-sync-ZT3UEQLK.ts.map} +1 -1
  70. package/dist/chunks/{file-selection-3JJYOVNR.ts → file-selection-FBLKM25V.ts} +12 -10
  71. package/dist/chunks/{file-selection-3JJYOVNR.ts.map → file-selection-FBLKM25V.ts.map} +1 -1
  72. package/dist/chunks/{git-backend-NYKSG5X6.ts → git-backend-7PCWECRN.ts} +16 -12
  73. package/dist/chunks/{git-backend-NYKSG5X6.ts.map → git-backend-7PCWECRN.ts.map} +1 -1
  74. package/dist/chunks/{local-fields-6DGYOOIK.ts → local-fields-B6JWLPAE.ts} +10 -5
  75. package/dist/chunks/manager-result-dispatcher-NODX3KKH.ts +28 -0
  76. package/dist/chunks/{manager-ui-ZH6DEC2G.ts → manager-ui-DGRTG76I.ts} +46 -40
  77. package/dist/chunks/{manager-ui-ZH6DEC2G.ts.map → manager-ui-DGRTG76I.ts.map} +1 -1
  78. package/dist/chunks/{merge-baseline-store-RFCAH7KL.ts → merge-baseline-store-HL3VLMAM.ts} +6 -5
  79. package/dist/chunks/{remote-selection-ui-YFPGYGNE.ts → remote-selection-ui-OHMIQ32X.ts} +14 -10
  80. package/dist/chunks/{s3-backend-F7PR5FB3.ts → s3-backend-CJXBEWWU.ts} +21 -17
  81. package/dist/chunks/{s3-backend-F7PR5FB3.ts.map → s3-backend-CJXBEWWU.ts.map} +1 -1
  82. package/dist/chunks/{setup-switch-E7PHKI6J.ts → setup-switch-66GWMBNH.ts} +6 -7
  83. package/dist/chunks/{setup-wizard-OVHZYXNW.ts → setup-wizard-OHZXJVQZ.ts} +8 -9
  84. package/dist/chunks/{setup-wizard-OVHZYXNW.ts.map → setup-wizard-OHZXJVQZ.ts.map} +1 -1
  85. package/dist/chunks/{snapshot-THS5EY2L.ts → snapshot-VRHNAUUH.ts} +11 -6
  86. package/dist/chunks/snapshot-transaction-EUGA4VX6.ts +24 -0
  87. package/dist/chunks/sync-inspection-4WFQEJOE.ts +25 -0
  88. package/dist/chunks/sync-inspection-4WFQEJOE.ts.map +7 -0
  89. package/dist/chunks/{sync-operations-Y72GNIQ2.ts → sync-operations-X4AOXMBT.ts} +66 -57
  90. package/dist/chunks/{sync-operations-Y72GNIQ2.ts.map → sync-operations-X4AOXMBT.ts.map} +1 -1
  91. package/dist/chunks/{sync-state-CFL4RRRB.ts → sync-state-SWLSMK4G.ts} +9 -5
  92. package/dist/chunks/sync-state-SWLSMK4G.ts.map +7 -0
  93. package/dist/chunks/{webdav-backend-TGFUH3SF.ts → webdav-backend-2Q5ZEBST.ts} +16 -12
  94. package/dist/chunks/{webdav-backend-TGFUH3SF.ts.map → webdav-backend-2Q5ZEBST.ts.map} +1 -1
  95. package/dist/index.ts +54 -537
  96. package/dist/index.ts.map +3 -3
  97. package/package.json +2 -2
  98. package/src/settings/config.ts +1 -1
  99. package/src/settings/settings-validation.ts +1 -1
  100. package/src/snapshot/snapshot-transaction-directory.ts +16 -0
  101. package/src/snapshot/snapshot-transaction.ts +1 -12
  102. package/src/sync/automatic-sync.ts +12 -6
  103. package/src/sync/local-field-policy.ts +29 -0
  104. package/src/sync/local-fields.ts +3 -29
  105. package/src/sync/mutation-owner.ts +22 -0
  106. package/src/sync/startup-check.ts +3 -2
  107. package/src/sync/sync-loaders.ts +4 -0
  108. package/src/sync/sync-local.ts +2 -19
  109. package/src/sync-extension.ts +7 -2
  110. package/dist/chunks/chunk-A6HU4ERM.ts.map +0 -7
  111. package/dist/chunks/chunk-CRKTAPSL.ts.map +0 -7
  112. package/dist/chunks/chunk-QO333NM4.ts.map +0 -7
  113. package/dist/chunks/chunk-QOFMXPM5.ts +0 -735
  114. package/dist/chunks/chunk-QOFMXPM5.ts.map +0 -7
  115. package/dist/chunks/chunk-UOHR7LRO.ts.map +0 -7
  116. package/dist/chunks/manager-result-dispatcher-HOCM2GDA.ts +0 -24
  117. package/dist/chunks/sync-inspection-J25EEKZK.ts +0 -21
  118. /package/dist/chunks/{agent-candidate-GNEYR225.ts.map → agent-candidate-EYB35AGL.ts.map} +0 -0
  119. /package/dist/chunks/{config-KGIYTTXQ.ts.map → agent-sync-VM3TXWA3.ts.map} +0 -0
  120. /package/dist/chunks/{chunk-PG7NMFP2.ts.map → chunk-4RLATUP4.ts.map} +0 -0
  121. /package/dist/chunks/{chunk-GNH73BJ5.ts.map → chunk-66GAUVDL.ts.map} +0 -0
  122. /package/dist/chunks/{chunk-UPNVIUBN.ts.map → chunk-73MDIVYJ.ts.map} +0 -0
  123. /package/dist/chunks/{chunk-S7QS4AWK.ts.map → chunk-AO6EDUA6.ts.map} +0 -0
  124. /package/dist/chunks/{chunk-JCH3VXIO.ts.map → chunk-BJXSCGQK.ts.map} +0 -0
  125. /package/dist/chunks/{chunk-IWZH5KYS.ts.map → chunk-CDQGSZL3.ts.map} +0 -0
  126. /package/dist/chunks/{chunk-ED3TYIVW.ts.map → chunk-DOJRPBQU.ts.map} +0 -0
  127. /package/dist/chunks/{chunk-5QAE3G3K.ts.map → chunk-IMMMZUFC.ts.map} +0 -0
  128. /package/dist/chunks/{chunk-B4QZBDBT.ts.map → chunk-JXWTEJS5.ts.map} +0 -0
  129. /package/dist/chunks/{chunk-P7DD5PWZ.ts.map → chunk-M5IV3KL2.ts.map} +0 -0
  130. /package/dist/chunks/{chunk-AAEEHR7H.ts.map → chunk-MDUORMCK.ts.map} +0 -0
  131. /package/dist/chunks/{chunk-UBV24CG4.ts.map → chunk-MRIPZGPR.ts.map} +0 -0
  132. /package/dist/chunks/{chunk-MKKF4IMY.ts.map → chunk-ODF2M4RF.ts.map} +0 -0
  133. /package/dist/chunks/{chunk-GP5DU62N.ts.map → chunk-PWA3YN5Z.ts.map} +0 -0
  134. /package/dist/chunks/{chunk-ORGBI36T.ts.map → chunk-RAMHGOX2.ts.map} +0 -0
  135. /package/dist/chunks/{chunk-76NB4R7U.ts.map → chunk-TO2GMX3K.ts.map} +0 -0
  136. /package/dist/chunks/{chunk-GSNPASKB.ts.map → chunk-U77DWNRH.ts.map} +0 -0
  137. /package/dist/chunks/{chunk-U3XRI2HF.ts.map → chunk-UCD7TQDT.ts.map} +0 -0
  138. /package/dist/chunks/{conflict-artifacts-FXFIIBCB.ts.map → config-B37W7FXW.ts.map} +0 -0
  139. /package/dist/chunks/{continuous-record-SQJ47CXN.ts.map → conflict-artifacts-6XGSSU5S.ts.map} +0 -0
  140. /package/dist/chunks/{local-fields-6DGYOOIK.ts.map → continuous-record-4DQ2EAZS.ts.map} +0 -0
  141. /package/dist/chunks/{manager-result-dispatcher-HOCM2GDA.ts.map → local-fields-B6JWLPAE.ts.map} +0 -0
  142. /package/dist/chunks/{merge-baseline-store-RFCAH7KL.ts.map → manager-result-dispatcher-NODX3KKH.ts.map} +0 -0
  143. /package/dist/chunks/{remote-selection-ui-YFPGYGNE.ts.map → merge-baseline-store-HL3VLMAM.ts.map} +0 -0
  144. /package/dist/chunks/{setup-switch-E7PHKI6J.ts.map → remote-selection-ui-OHMIQ32X.ts.map} +0 -0
  145. /package/dist/chunks/{snapshot-THS5EY2L.ts.map → setup-switch-66GWMBNH.ts.map} +0 -0
  146. /package/dist/chunks/{sync-inspection-J25EEKZK.ts.map → snapshot-VRHNAUUH.ts.map} +0 -0
  147. /package/dist/chunks/{sync-state-CFL4RRRB.ts.map → snapshot-transaction-EUGA4VX6.ts.map} +0 -0
@@ -3,7 +3,7 @@
3
3
  import {
4
4
  runCancellableOperation,
5
5
  showRemoteSelectionReview
6
- } from "./chunk-JCH3VXIO.ts";
6
+ } from "./chunk-BJXSCGQK.ts";
7
7
  import {
8
8
  safeTerminalText
9
9
  } from "./chunk-AMJRUXFT.ts";
@@ -13,7 +13,7 @@ import {
13
13
  import {
14
14
  loadConfig,
15
15
  syncConfigReviewIdentity
16
- } from "./chunk-QO333NM4.ts";
16
+ } from "./chunk-RX3WGWVL.ts";
17
17
 
18
18
  // src/ui/sync-resolution-ui.ts
19
19
  import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
@@ -206,4 +206,4 @@ async function dispatchManagerResult(ctx, initialResult, origin, runRoute, signa
206
206
  export {
207
207
  dispatchManagerResult
208
208
  };
209
- //# sourceMappingURL=chunk-P7DD5PWZ.ts.map
209
+ //# sourceMappingURL=chunk-M5IV3KL2.ts.map
@@ -6,7 +6,7 @@ import {
6
6
  import {
7
7
  ensureStateDir,
8
8
  lockPath
9
- } from "./chunk-UPNVIUBN.ts";
9
+ } from "./chunk-73MDIVYJ.ts";
10
10
  import {
11
11
  LOCKFILE_FS_ADAPTER,
12
12
  LOCK_GUARD_STALE_MS,
@@ -255,4 +255,4 @@ export {
255
255
  isStaleLock,
256
256
  unlock
257
257
  };
258
- //# sourceMappingURL=chunk-AAEEHR7H.ts.map
258
+ //# sourceMappingURL=chunk-MDUORMCK.ts.map
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-PWMWOJP4.ts";
6
6
  import {
7
7
  snapshotSelectionInclude
8
- } from "./chunk-QOFMXPM5.ts";
8
+ } from "./chunk-DFJGTVPX.ts";
9
9
 
10
10
  // src/snapshot/snapshot-codec.ts
11
11
  import { Readable, Writable } from "node:stream";
@@ -42,7 +42,7 @@ async function decodeSnapshot(buffer, options = {}) {
42
42
  throw new Error("Unsupported snapshot format.");
43
43
  }
44
44
  if (parsed.version === 2 || parsed.version === 3) {
45
- const { normalizeLocalFields, validatePortableSnapshot } = await import("./local-fields-6DGYOOIK.ts");
45
+ const { normalizeLocalFields, validatePortableSnapshot } = await import("./local-fields-B6JWLPAE.ts");
46
46
  validatePortableSnapshot(parsed);
47
47
  if (parsed.localFields !== void 0) parsed.localFields = normalizeLocalFields(parsed.localFields);
48
48
  } else if (parsed.localFields !== void 0) throw new Error("Portable field policy requires snapshot version 2.");
@@ -54,4 +54,4 @@ export {
54
54
  encodeSnapshot,
55
55
  decodeSnapshot
56
56
  };
57
- //# sourceMappingURL=chunk-UBV24CG4.ts.map
57
+ //# sourceMappingURL=chunk-MRIPZGPR.ts.map
@@ -8,7 +8,7 @@ import {
8
8
  } from "./chunk-K3RIEL6J.ts";
9
9
  import {
10
10
  withLock
11
- } from "./chunk-AAEEHR7H.ts";
11
+ } from "./chunk-MDUORMCK.ts";
12
12
  import {
13
13
  ContinuousError
14
14
  } from "./chunk-DT7M4VQS.ts";
@@ -29,8 +29,8 @@ async function withAgentSyncLock(ctx, options, run) {
29
29
  if (!(error instanceof AgentResolutionRequired)) throw error;
30
30
  request = error;
31
31
  }
32
- const { withAgentClaim, readAgentCandidate, saveAgentCandidate, replaceRefusedAgentCandidate } = await import("./agent-store-55CZOCPX.ts");
33
- const { parseAgentCandidate } = await import("./agent-candidate-GNEYR225.ts");
32
+ const { withAgentClaim, readAgentCandidate, saveAgentCandidate, replaceRefusedAgentCandidate } = await import("./agent-store-UT52DS7B.ts");
33
+ const { parseAgentCandidate } = await import("./agent-candidate-EYB35AGL.ts");
34
34
  const { runAgentResolver } = await import("./agent-runner-WMSCKSCB.ts");
35
35
  return withAgentClaim(async (assertOwner) => {
36
36
  const clearStatus = () => setSyncStatus(ctx, void 0);
@@ -69,7 +69,7 @@ async function withAgentSyncLock(ctx, options, run) {
69
69
  expectedRefusal = parseAgentCandidate(JSON.stringify(cached), request.evidence);
70
70
  if (!expectedRefusal.results.some((row) => "refuse" in row))
71
71
  throw new Error("The current cached result is not a refusal. Use Sync now.");
72
- const { confirmAgentRefusalRetry } = await import("./agent-refusal-retry-RPTMUQXK.ts");
72
+ const { confirmAgentRefusalRetry } = await import("./agent-refusal-retry-C2HQROTP.ts");
73
73
  options.signal?.throwIfAborted();
74
74
  if (!await confirmAgentRefusalRetry(ctx, options.setup, request.evidence, validate, options.signal))
75
75
  return "cancelled";
@@ -137,4 +137,4 @@ async function withAgentSyncLock(ctx, options, run) {
137
137
  export {
138
138
  withAgentSyncLock
139
139
  };
140
- //# sourceMappingURL=chunk-MKKF4IMY.ts.map
140
+ //# sourceMappingURL=chunk-ODF2M4RF.ts.map
@@ -0,0 +1,348 @@
1
+ // @generated by scripts/build-runtime.mjs; do not edit.
2
+ // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
+ import {
4
+ DEFAULT_SYNC_INCLUDE,
5
+ canonicalSnapshotPathForConfig,
6
+ customIncludePathsByLower,
7
+ includeFromSelectionConfig,
8
+ isConfiguredSnapshotPath,
9
+ isPreservableUnmanagedSnapshotPath,
10
+ normalizeExtraFiles,
11
+ normalizeSyncFiles,
12
+ selectionForSnapshot,
13
+ snapshotSelectionInclude,
14
+ syncIncludeSelection
15
+ } from "./chunk-DFJGTVPX.ts";
16
+ import {
17
+ agentDir,
18
+ configuredSessionDir,
19
+ sessionStorageRoot
20
+ } from "./chunk-DO55XUNU.ts";
21
+ import {
22
+ isDeniedPath,
23
+ posixJoin,
24
+ safeJoin,
25
+ toPosix
26
+ } from "./chunk-YZ5BQNRZ.ts";
27
+
28
+ // src/snapshot/snapshot.ts
29
+ import { createHash, randomUUID } from "node:crypto";
30
+ import fs from "node:fs/promises";
31
+ import os from "node:os";
32
+ import path from "node:path";
33
+ var VERSION = 1;
34
+ var TOP_LEVEL_FILES = DEFAULT_SYNC_INCLUDE.filter((name) => name.includes("."));
35
+ var TOP_LEVEL_DIRS = new Set(DEFAULT_SYNC_INCLUDE.filter((name) => !name.includes(".")));
36
+ var SECRET_PATTERNS = [
37
+ /AWS_SECRET_ACCESS_KEY\s*[=:]\s*['"]?[A-Za-z0-9/+]{35,}/i,
38
+ /(ANTHROPIC|OPENAI|GEMINI|GOOGLE|FIRECRAWL|GITHUB|CLOUDFLARE|R2|S3)_[A-Z0-9_]*(KEY|TOKEN|SECRET)\s*[=:]\s*['"]?[^\s'"]{12,}/i,
39
+ /sk-ant-[A-Za-z0-9_-]{20,}/,
40
+ /sk-[A-Za-z0-9]{20,}/,
41
+ /gh[pousr]_[A-Za-z0-9_]{20,}/
42
+ ];
43
+ function selectTopLevelFileEntry(entries, fileName) {
44
+ const exact = entries.find((entry) => entry.isFile() && entry.name === fileName);
45
+ if (exact) return exact;
46
+ const lower = fileName.toLowerCase();
47
+ return entries.filter((entry) => entry.isFile() && entry.name.toLowerCase() === lower).sort((left, right) => left.name.localeCompare(right.name))[0];
48
+ }
49
+ function sha256(value) {
50
+ return createHash("sha256").update(value).digest("hex");
51
+ }
52
+ function isSafeSnapshotPath(relativePath) {
53
+ if (relativePath.includes("\\")) return false;
54
+ const normalized = toPosix(relativePath);
55
+ return Boolean(normalized) && normalized !== "." && normalized !== ".." && !normalized.startsWith("../") && !path.posix.isAbsolute(normalized) && path.posix.normalize(normalized) === normalized && !isDeniedPath(normalized);
56
+ }
57
+ function snapshotsMatch(left, right) {
58
+ const leftHashes = new Map(left.files.map((file) => [file.path, file.sha256]));
59
+ const rightHashes = new Map(right.files.map((file) => [file.path, file.sha256]));
60
+ return left.syncSessions === right.syncSessions && sameOptionalInclude(snapshotSelectionInclude(left), snapshotSelectionInclude(right)) && leftHashes.size === rightHashes.size && [...leftHashes].every(([filePath, hash]) => rightHashes.get(filePath) === hash);
61
+ }
62
+ function snapshotId() {
63
+ return `${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}-${randomUUID().slice(0, 8)}`;
64
+ }
65
+ function regenerateSnapshotIdentity(snapshot) {
66
+ return {
67
+ ...snapshot,
68
+ id: snapshotId(),
69
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
70
+ machine: os.hostname()
71
+ };
72
+ }
73
+ async function createSnapshot(profile, options = {}) {
74
+ options.signal?.throwIfAborted();
75
+ const include = effectiveInclude(options);
76
+ const syncSessions = include.includes("sessions");
77
+ const sessionDir = options.sessionDir ?? await configuredSessionDir();
78
+ options.signal?.throwIfAborted();
79
+ const files = await collectFiles(agentDir(), { include, sessionDir, signal: options.signal });
80
+ options.signal?.throwIfAborted();
81
+ return {
82
+ version: VERSION,
83
+ id: snapshotId(),
84
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
85
+ machine: os.hostname(),
86
+ profile,
87
+ syncSessions,
88
+ selection: selectionForSnapshot(include),
89
+ files
90
+ };
91
+ }
92
+ function effectiveInclude(options) {
93
+ if (options.include) return options.include;
94
+ return [
95
+ ...normalizeSyncFiles(options.syncFiles),
96
+ ...normalizeExtraFiles(options.extraFiles),
97
+ ...options.syncSessions ? ["sessions"] : []
98
+ ];
99
+ }
100
+ async function collectFiles(root, options = {}) {
101
+ const signal = options.signal;
102
+ signal?.throwIfAborted();
103
+ const results = [];
104
+ const entries = await fs.readdir(root, { withFileTypes: true });
105
+ signal?.throwIfAborted();
106
+ const selection = syncIncludeSelection(effectiveInclude(options));
107
+ const selectedFiles = new Set(selection.builtIns);
108
+ for (const entry of entries) {
109
+ if (entry.isDirectory() && TOP_LEVEL_DIRS.has(entry.name) && selectedFiles.has(entry.name)) {
110
+ await collectDirectory(results, root, entry.name, { signal });
111
+ }
112
+ }
113
+ for (const fileName of TOP_LEVEL_FILES) {
114
+ if (!selectedFiles.has(fileName)) continue;
115
+ const entry = selectTopLevelFileEntry(entries, fileName);
116
+ if (entry) await addFile(results, root, entry.name, fileName, signal);
117
+ }
118
+ for (const relativePath of selection.custom) {
119
+ await collectIncludedPath(results, root, relativePath, signal);
120
+ }
121
+ if (selection.sessions) {
122
+ try {
123
+ await collectDirectory(results, sessionStorageRoot(root, options.sessionDir), "", {
124
+ sessionsOnly: true,
125
+ virtualPrefix: "sessions",
126
+ signal
127
+ });
128
+ } catch (error) {
129
+ if (error.code !== "ENOENT") throw error;
130
+ }
131
+ }
132
+ signal?.throwIfAborted();
133
+ return results.sort((left, right) => left.path.localeCompare(right.path));
134
+ }
135
+ async function collectIncludedPath(results, root, relativePath, signal) {
136
+ signal?.throwIfAborted();
137
+ const absolutePath = safeJoin(root, relativePath);
138
+ try {
139
+ const stat = await fs.lstat(absolutePath);
140
+ signal?.throwIfAborted();
141
+ if (stat.isFile()) await addFile(results, root, relativePath, relativePath, signal);
142
+ else if (stat.isDirectory()) await collectDirectory(results, root, relativePath, { signal });
143
+ } catch (error) {
144
+ if (error.code !== "ENOENT") throw error;
145
+ if (!relativePath.includes("/")) {
146
+ const entries = await fs.readdir(root, { withFileTypes: true });
147
+ signal?.throwIfAborted();
148
+ const entry = selectTopLevelFileEntry(entries, relativePath);
149
+ if (entry) await addFile(results, root, entry.name, relativePath, signal);
150
+ }
151
+ }
152
+ }
153
+ async function collectDirectory(results, root, relativeDirectory, options = {}) {
154
+ options.signal?.throwIfAborted();
155
+ const absoluteDirectory = path.join(root, relativeDirectory);
156
+ for (const entry of await fs.readdir(absoluteDirectory, { withFileTypes: true })) {
157
+ options.signal?.throwIfAborted();
158
+ const relativePath = relativeDirectory ? posixJoin(relativeDirectory, entry.name) : entry.name;
159
+ const snapshotPath = options.virtualPrefix ? posixJoin(options.virtualPrefix, relativePath) : relativePath;
160
+ if (isDeniedPath(snapshotPath)) continue;
161
+ if (entry.isDirectory()) {
162
+ await collectDirectory(results, root, relativePath, options);
163
+ } else if (entry.isFile() && (!options.sessionsOnly || isSessionFilePath(snapshotPath))) {
164
+ await addFile(results, root, relativePath, snapshotPath, options.signal);
165
+ }
166
+ }
167
+ }
168
+ async function addFile(results, root, relativePath, snapshotPath = relativePath, signal) {
169
+ signal?.throwIfAborted();
170
+ if (!isSafeSnapshotPath(snapshotPath)) return;
171
+ const absolutePath = safeJoin(root, relativePath);
172
+ const content = await fs.readFile(absolutePath, { signal });
173
+ signal?.throwIfAborted();
174
+ results.push({
175
+ path: snapshotPath,
176
+ contentBase64: content.toString("base64"),
177
+ sha256: sha256(content)
178
+ });
179
+ }
180
+ function isSessionPath(relativePath) {
181
+ return toPosix(relativePath).startsWith("sessions/");
182
+ }
183
+ function isSessionFilePath(relativePath) {
184
+ const normalized = toPosix(relativePath);
185
+ return isSessionPath(normalized) && normalized.endsWith(".jsonl");
186
+ }
187
+ function sessionSnapshotPathFromAbsolute(sessionFile, configuredSessionDir2) {
188
+ const relativePath = toPosix(path.relative(sessionStorageRoot(agentDir(), configuredSessionDir2), sessionFile));
189
+ if (!relativePath || relativePath.startsWith("../") || path.posix.isAbsolute(relativePath)) {
190
+ return void 0;
191
+ }
192
+ const snapshotPath = posixJoin("sessions", relativePath);
193
+ return isSessionFilePath(snapshotPath) ? snapshotPath : void 0;
194
+ }
195
+ function snapshotTarget(root, relativePath, configuredSessionDir2) {
196
+ if (isSessionPath(relativePath)) {
197
+ return safeJoin(sessionStorageRoot(root, configuredSessionDir2), relativePath.slice("sessions/".length));
198
+ }
199
+ return safeJoin(root, relativePath);
200
+ }
201
+ function snapshotIncludesSessions(snapshot) {
202
+ return snapshot.syncSessions === true || snapshotSelectionInclude(snapshot)?.includes("sessions") === true || snapshot.files.some((file) => isSessionPath(file.path));
203
+ }
204
+ function filterSnapshotForConfigPolicy(snapshot, config, options = {}) {
205
+ const include = includeFromSelectionConfig(config);
206
+ const includePaths = customIncludePathsByLower(include);
207
+ const filtered = {
208
+ ...snapshot,
209
+ syncSessions: include.includes("sessions") ? snapshot.syncSessions : false,
210
+ selection: selectionForSnapshot(include),
211
+ files: canonicalizeSnapshotFilesForConfig(snapshot.files, config, includePaths)
212
+ };
213
+ if (!options.regenerateId || snapshotsMatch(snapshot, filtered)) return filtered;
214
+ return {
215
+ ...filtered,
216
+ id: snapshotId(),
217
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
218
+ machine: os.hostname()
219
+ };
220
+ }
221
+ function canonicalizeSnapshotFilesForConfig(files, config, includePaths) {
222
+ const configuredFiles = [];
223
+ const extraCandidates = /* @__PURE__ */ new Map();
224
+ for (const file of files) {
225
+ const normalized = toPosix(file.path);
226
+ if (!isSafeSnapshotPath(file.path) || !isConfiguredSnapshotPath(normalized, config)) {
227
+ continue;
228
+ }
229
+ if (normalized.includes("/")) {
230
+ configuredFiles.push(normalized === file.path ? file : { ...file, path: normalized });
231
+ continue;
232
+ }
233
+ const topLevelPath = canonicalSnapshotPathForConfig(normalized, includePaths);
234
+ const candidate = {
235
+ exact: normalized === topLevelPath,
236
+ file: { ...file, path: topLevelPath },
237
+ originalPath: normalized
238
+ };
239
+ const current = extraCandidates.get(topLevelPath.toLowerCase());
240
+ if (!current || isPreferredExtraCandidate(candidate, current)) {
241
+ extraCandidates.set(topLevelPath.toLowerCase(), candidate);
242
+ }
243
+ }
244
+ return [...configuredFiles, ...[...extraCandidates.values()].map((candidate) => candidate.file)].sort(
245
+ (left, right) => left.path.localeCompare(right.path)
246
+ );
247
+ }
248
+ function isPreferredExtraCandidate(left, right) {
249
+ if (left.exact !== right.exact) return left.exact;
250
+ return left.originalPath.localeCompare(right.originalPath) < 0;
251
+ }
252
+ function snapshotWithoutSessions(snapshot) {
253
+ const files = snapshot.files.filter((file) => !isSessionPath(file.path));
254
+ const include = snapshotSelectionInclude(snapshot)?.filter((item) => item !== "sessions");
255
+ if (files.length === snapshot.files.length && snapshot.syncSessions !== true && include?.length === snapshot.selection?.include.length) {
256
+ return snapshot;
257
+ }
258
+ return {
259
+ ...snapshot,
260
+ id: snapshotId(),
261
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
262
+ machine: os.hostname(),
263
+ syncSessions: false,
264
+ ...include ? { selection: selectionForSnapshot(include) } : {},
265
+ files
266
+ };
267
+ }
268
+ function scanSnapshot(snapshot) {
269
+ const findings = [];
270
+ for (const file of snapshot.files) {
271
+ const content = Buffer.from(file.contentBase64, "base64");
272
+ if (content.includes(0)) continue;
273
+ const text = content.toString("utf8");
274
+ for (const pattern of SECRET_PATTERNS) {
275
+ if (pattern.test(text)) {
276
+ findings.push(file.path);
277
+ break;
278
+ }
279
+ }
280
+ }
281
+ return findings;
282
+ }
283
+ function mergeRemotePreservedFiles(local, remote, config) {
284
+ const localPathNames = new Set(local.files.map((file) => file.path.toLowerCase()));
285
+ const preservedPathNames = /* @__PURE__ */ new Set();
286
+ const preserved = remote.files.filter((file) => {
287
+ const normalized = toPosix(file.path);
288
+ const lower = normalized.toLowerCase();
289
+ if (localPathNames.has(lower) || preservedPathNames.has(lower) || !isSafeSnapshotPath(file.path) || isConfiguredSnapshotPath(normalized, config) || !isPreservableUnmanagedSnapshotPath(normalized)) {
290
+ return false;
291
+ }
292
+ preservedPathNames.add(lower);
293
+ return true;
294
+ });
295
+ if (preserved.length === 0) return local;
296
+ return {
297
+ ...local,
298
+ id: snapshotId(),
299
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
300
+ machine: os.hostname(),
301
+ syncSessions: snapshotIncludesSessions(local) || snapshotIncludesSessions(remote),
302
+ files: [...local.files, ...preserved].sort((left, right) => left.path.localeCompare(right.path))
303
+ };
304
+ }
305
+ function mergeRemoteSessionFiles(local, remote) {
306
+ const remoteSessions = remote.files.filter((file) => {
307
+ const normalized = toPosix(file.path);
308
+ return isSessionFilePath(normalized) && isSafeSnapshotPath(file.path);
309
+ });
310
+ if (remoteSessions.length === 0 && !snapshotIncludesSessions(remote)) return local;
311
+ const localInclude = snapshotSelectionInclude(local);
312
+ return {
313
+ ...local,
314
+ id: snapshotId(),
315
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
316
+ machine: os.hostname(),
317
+ syncSessions: true,
318
+ ...localInclude ? {
319
+ selection: selectionForSnapshot(
320
+ localInclude.includes("sessions") ? localInclude : [...localInclude, "sessions"]
321
+ )
322
+ } : {},
323
+ files: [...local.files.filter((file) => !isSessionPath(file.path)), ...remoteSessions].sort(
324
+ (left, right) => left.path.localeCompare(right.path)
325
+ )
326
+ };
327
+ }
328
+ function sameOptionalInclude(left, right) {
329
+ if (!left || !right) return left === right;
330
+ return left.length === right.length && left.every((item, index) => item === right[index]);
331
+ }
332
+
333
+ export {
334
+ regenerateSnapshotIdentity,
335
+ createSnapshot,
336
+ collectFiles,
337
+ isSessionPath,
338
+ isSessionFilePath,
339
+ sessionSnapshotPathFromAbsolute,
340
+ snapshotTarget,
341
+ snapshotIncludesSessions,
342
+ filterSnapshotForConfigPolicy,
343
+ snapshotWithoutSessions,
344
+ scanSnapshot,
345
+ mergeRemotePreservedFiles,
346
+ mergeRemoteSessionFiles
347
+ };
348
+ //# sourceMappingURL=chunk-PHANBTVM.ts.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/snapshot/snapshot.ts"],
4
+ "sourcesContent": ["import { createHash, randomUUID } from \"node:crypto\";\nimport type { Dirent } from \"node:fs\";\nimport fs from \"node:fs/promises\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { isDeniedPath, posixJoin, safeJoin, toPosix } from \"../paths.js\";\nimport { agentDir, configuredSessionDir } from \"./session-paths.js\";\nimport { sessionStorageRoot } from \"./snapshot-paths.js\";\n\nexport { isDeniedPath } from \"../paths.js\";\nexport { sessionStorageRoot } from \"./snapshot-paths.js\";\n\nimport {\n canonicalSnapshotPathForConfig,\n customIncludePathsByLower,\n DEFAULT_SYNC_INCLUDE,\n includeFromSelectionConfig,\n isConfiguredSnapshotPath,\n isPreservableUnmanagedSnapshotPath,\n normalizeExtraFiles,\n normalizeSyncFiles,\n type SyncSelectionConfig,\n selectionForSnapshot,\n snapshotSelectionInclude,\n syncIncludeSelection,\n} from \"../sync/sync-policy.js\";\nimport type { Snapshot, SnapshotFile, SnapshotOptions } from \"./snapshot-types.js\";\n\nexport { canonicalSnapshotPathForConfig, isConfiguredSnapshotPath } from \"../sync/sync-policy.js\";\n\nconst VERSION = 1;\nconst TOP_LEVEL_FILES: readonly string[] = DEFAULT_SYNC_INCLUDE.filter((name) => name.includes(\".\"));\nconst TOP_LEVEL_DIRS = new Set<string>(DEFAULT_SYNC_INCLUDE.filter((name) => !name.includes(\".\")));\nconst SECRET_PATTERNS = [\n /AWS_SECRET_ACCESS_KEY\\s*[=:]\\s*['\"]?[A-Za-z0-9/+]{35,}/i,\n /(ANTHROPIC|OPENAI|GEMINI|GOOGLE|FIRECRAWL|GITHUB|CLOUDFLARE|R2|S3)_[A-Z0-9_]*(KEY|TOKEN|SECRET)\\s*[=:]\\s*['\"]?[^\\s'\"]{12,}/i,\n /sk-ant-[A-Za-z0-9_-]{20,}/,\n /sk-[A-Za-z0-9]{20,}/,\n /gh[pousr]_[A-Za-z0-9_]{20,}/,\n];\n\nfunction selectTopLevelFileEntry(entries: Dirent[], fileName: string) {\n const exact = entries.find((entry) => entry.isFile() && entry.name === fileName);\n if (exact) return exact;\n const lower = fileName.toLowerCase();\n return entries\n .filter((entry) => entry.isFile() && entry.name.toLowerCase() === lower)\n .sort((left, right) => left.name.localeCompare(right.name))[0];\n}\n\nfunction sha256(value: Buffer) {\n return createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\nfunction isSafeSnapshotPath(relativePath: string) {\n if (relativePath.includes(\"\\\\\")) return false;\n const normalized = toPosix(relativePath);\n return (\n Boolean(normalized) &&\n normalized !== \".\" &&\n normalized !== \"..\" &&\n !normalized.startsWith(\"../\") &&\n !path.posix.isAbsolute(normalized) &&\n path.posix.normalize(normalized) === normalized &&\n !isDeniedPath(normalized)\n );\n}\n\nfunction snapshotsMatch(left: Snapshot, right: Snapshot) {\n const leftHashes = new Map(left.files.map((file) => [file.path, file.sha256]));\n const rightHashes = new Map(right.files.map((file) => [file.path, file.sha256]));\n return (\n left.syncSessions === right.syncSessions &&\n sameOptionalInclude(snapshotSelectionInclude(left), snapshotSelectionInclude(right)) &&\n leftHashes.size === rightHashes.size &&\n [...leftHashes].every(([filePath, hash]) => rightHashes.get(filePath) === hash)\n );\n}\n\nfunction snapshotId() {\n return `${new Date().toISOString().replace(/[:.]/g, \"-\")}-${randomUUID().slice(0, 8)}`;\n}\n\nexport function regenerateSnapshotIdentity(snapshot: Snapshot): Snapshot {\n return {\n ...snapshot,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n };\n}\n\nexport async function createSnapshot(profile: string, options: SnapshotOptions = {}): Promise<Snapshot> {\n options.signal?.throwIfAborted();\n const include = effectiveInclude(options);\n const syncSessions = include.includes(\"sessions\");\n const sessionDir = options.sessionDir ?? (await configuredSessionDir());\n options.signal?.throwIfAborted();\n const files = await collectFiles(agentDir(), { include, sessionDir, signal: options.signal });\n options.signal?.throwIfAborted();\n return {\n version: VERSION,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n profile,\n syncSessions,\n selection: selectionForSnapshot(include),\n files,\n };\n}\n\nfunction effectiveInclude(options: SnapshotOptions) {\n if (options.include) return options.include;\n return [\n ...normalizeSyncFiles(options.syncFiles),\n ...normalizeExtraFiles(options.extraFiles),\n ...(options.syncSessions ? [\"sessions\"] : []),\n ];\n}\n\nexport async function collectFiles(root: string, options: SnapshotOptions = {}): Promise<SnapshotFile[]> {\n const signal = options.signal;\n signal?.throwIfAborted();\n const results: SnapshotFile[] = [];\n const entries = await fs.readdir(root, { withFileTypes: true });\n signal?.throwIfAborted();\n const selection = syncIncludeSelection(effectiveInclude(options));\n const selectedFiles = new Set<string>(selection.builtIns);\n for (const entry of entries) {\n if (entry.isDirectory() && TOP_LEVEL_DIRS.has(entry.name) && selectedFiles.has(entry.name)) {\n await collectDirectory(results, root, entry.name, { signal });\n }\n }\n for (const fileName of TOP_LEVEL_FILES) {\n if (!selectedFiles.has(fileName)) continue;\n const entry = selectTopLevelFileEntry(entries, fileName);\n if (entry) await addFile(results, root, entry.name, fileName, signal);\n }\n for (const relativePath of selection.custom) {\n await collectIncludedPath(results, root, relativePath, signal);\n }\n if (selection.sessions) {\n try {\n await collectDirectory(results, sessionStorageRoot(root, options.sessionDir), \"\", {\n sessionsOnly: true,\n virtualPrefix: \"sessions\",\n signal,\n });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n }\n }\n signal?.throwIfAborted();\n return results.sort((left, right) => left.path.localeCompare(right.path));\n}\n\nasync function collectIncludedPath(results: SnapshotFile[], root: string, relativePath: string, signal?: AbortSignal) {\n signal?.throwIfAborted();\n const absolutePath = safeJoin(root, relativePath);\n try {\n const stat = await fs.lstat(absolutePath);\n signal?.throwIfAborted();\n if (stat.isFile()) await addFile(results, root, relativePath, relativePath, signal);\n else if (stat.isDirectory()) await collectDirectory(results, root, relativePath, { signal });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n if (!relativePath.includes(\"/\")) {\n const entries = await fs.readdir(root, { withFileTypes: true });\n signal?.throwIfAborted();\n const entry = selectTopLevelFileEntry(entries, relativePath);\n if (entry) await addFile(results, root, entry.name, relativePath, signal);\n }\n }\n}\n\nasync function collectDirectory(\n results: SnapshotFile[],\n root: string,\n relativeDirectory: string,\n options: { sessionsOnly?: boolean; virtualPrefix?: string; signal?: AbortSignal } = {},\n) {\n options.signal?.throwIfAborted();\n const absoluteDirectory = path.join(root, relativeDirectory);\n for (const entry of await fs.readdir(absoluteDirectory, { withFileTypes: true })) {\n options.signal?.throwIfAborted();\n const relativePath = relativeDirectory ? posixJoin(relativeDirectory, entry.name) : entry.name;\n const snapshotPath = options.virtualPrefix ? posixJoin(options.virtualPrefix, relativePath) : relativePath;\n if (isDeniedPath(snapshotPath)) continue;\n if (entry.isDirectory()) {\n await collectDirectory(results, root, relativePath, options);\n } else if (entry.isFile() && (!options.sessionsOnly || isSessionFilePath(snapshotPath))) {\n await addFile(results, root, relativePath, snapshotPath, options.signal);\n }\n }\n}\n\nasync function addFile(\n results: SnapshotFile[],\n root: string,\n relativePath: string,\n snapshotPath = relativePath,\n signal?: AbortSignal,\n) {\n signal?.throwIfAborted();\n if (!isSafeSnapshotPath(snapshotPath)) return;\n const absolutePath = safeJoin(root, relativePath);\n const content = await fs.readFile(absolutePath, { signal });\n signal?.throwIfAborted();\n results.push({\n path: snapshotPath,\n contentBase64: content.toString(\"base64\"),\n sha256: sha256(content),\n });\n}\n\nexport function isSessionPath(relativePath: string) {\n return toPosix(relativePath).startsWith(\"sessions/\");\n}\n\nexport function isSessionFilePath(relativePath: string) {\n const normalized = toPosix(relativePath);\n return isSessionPath(normalized) && normalized.endsWith(\".jsonl\");\n}\n\nexport function sessionSnapshotPathFromAbsolute(sessionFile: string, configuredSessionDir?: string) {\n const relativePath = toPosix(path.relative(sessionStorageRoot(agentDir(), configuredSessionDir), sessionFile));\n if (!relativePath || relativePath.startsWith(\"../\") || path.posix.isAbsolute(relativePath)) {\n return undefined;\n }\n const snapshotPath = posixJoin(\"sessions\", relativePath);\n return isSessionFilePath(snapshotPath) ? snapshotPath : undefined;\n}\n\nexport function snapshotTarget(root: string, relativePath: string, configuredSessionDir?: string) {\n if (isSessionPath(relativePath)) {\n return safeJoin(sessionStorageRoot(root, configuredSessionDir), relativePath.slice(\"sessions/\".length));\n }\n return safeJoin(root, relativePath);\n}\n\nexport function snapshotIncludesSessions(snapshot: Snapshot) {\n return (\n snapshot.syncSessions === true ||\n snapshotSelectionInclude(snapshot)?.includes(\"sessions\") === true ||\n snapshot.files.some((file) => isSessionPath(file.path))\n );\n}\n\nexport function filterSnapshotForConfigPolicy(\n snapshot: Snapshot,\n config: SyncSelectionConfig,\n options: { regenerateId?: boolean } = {},\n) {\n const include = includeFromSelectionConfig(config);\n const includePaths = customIncludePathsByLower(include);\n const filtered = {\n ...snapshot,\n syncSessions: include.includes(\"sessions\") ? snapshot.syncSessions : false,\n selection: selectionForSnapshot(include),\n files: canonicalizeSnapshotFilesForConfig(snapshot.files, config, includePaths),\n };\n if (!options.regenerateId || snapshotsMatch(snapshot, filtered)) return filtered;\n return {\n ...filtered,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n };\n}\n\nfunction canonicalizeSnapshotFilesForConfig(\n files: SnapshotFile[],\n config: SyncSelectionConfig,\n includePaths: Map<string, string>,\n) {\n const configuredFiles: SnapshotFile[] = [];\n const extraCandidates = new Map<string, { exact: boolean; file: SnapshotFile; originalPath: string }>();\n for (const file of files) {\n const normalized = toPosix(file.path);\n if (!isSafeSnapshotPath(file.path) || !isConfiguredSnapshotPath(normalized, config)) {\n continue;\n }\n if (normalized.includes(\"/\")) {\n configuredFiles.push(normalized === file.path ? file : { ...file, path: normalized });\n continue;\n }\n const topLevelPath = canonicalSnapshotPathForConfig(normalized, includePaths);\n const candidate = {\n exact: normalized === topLevelPath,\n file: { ...file, path: topLevelPath },\n originalPath: normalized,\n };\n const current = extraCandidates.get(topLevelPath.toLowerCase());\n if (!current || isPreferredExtraCandidate(candidate, current)) {\n extraCandidates.set(topLevelPath.toLowerCase(), candidate);\n }\n }\n return [...configuredFiles, ...[...extraCandidates.values()].map((candidate) => candidate.file)].sort((left, right) =>\n left.path.localeCompare(right.path),\n );\n}\n\nfunction isPreferredExtraCandidate(\n left: { exact: boolean; originalPath: string },\n right: { exact: boolean; originalPath: string },\n) {\n if (left.exact !== right.exact) return left.exact;\n return left.originalPath.localeCompare(right.originalPath) < 0;\n}\n\nexport function snapshotWithoutSessions(snapshot: Snapshot) {\n const files = snapshot.files.filter((file) => !isSessionPath(file.path));\n const include = snapshotSelectionInclude(snapshot)?.filter((item) => item !== \"sessions\");\n if (\n files.length === snapshot.files.length &&\n snapshot.syncSessions !== true &&\n include?.length === snapshot.selection?.include.length\n ) {\n return snapshot;\n }\n return {\n ...snapshot,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n syncSessions: false,\n ...(include ? { selection: selectionForSnapshot(include) } : {}),\n files,\n };\n}\n\nexport function scanSnapshot(snapshot: Snapshot) {\n const findings: string[] = [];\n for (const file of snapshot.files) {\n const content = Buffer.from(file.contentBase64, \"base64\");\n if (content.includes(0)) continue;\n const text = content.toString(\"utf8\");\n for (const pattern of SECRET_PATTERNS) {\n if (pattern.test(text)) {\n findings.push(file.path);\n break;\n }\n }\n }\n return findings;\n}\n\nexport function mergeRemotePreservedFiles(local: Snapshot, remote: Snapshot, config: SyncSelectionConfig) {\n const localPathNames = new Set(local.files.map((file) => file.path.toLowerCase()));\n const preservedPathNames = new Set<string>();\n const preserved = remote.files.filter((file) => {\n const normalized = toPosix(file.path);\n const lower = normalized.toLowerCase();\n if (\n localPathNames.has(lower) ||\n preservedPathNames.has(lower) ||\n !isSafeSnapshotPath(file.path) ||\n isConfiguredSnapshotPath(normalized, config) ||\n !isPreservableUnmanagedSnapshotPath(normalized)\n ) {\n return false;\n }\n preservedPathNames.add(lower);\n return true;\n });\n if (preserved.length === 0) return local;\n return {\n ...local,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n syncSessions: snapshotIncludesSessions(local) || snapshotIncludesSessions(remote),\n files: [...local.files, ...preserved].sort((left, right) => left.path.localeCompare(right.path)),\n };\n}\n\nexport function mergeRemoteSessionFiles(local: Snapshot, remote: Snapshot) {\n const remoteSessions = remote.files.filter((file) => {\n const normalized = toPosix(file.path);\n return isSessionFilePath(normalized) && isSafeSnapshotPath(file.path);\n });\n if (remoteSessions.length === 0 && !snapshotIncludesSessions(remote)) return local;\n const localInclude = snapshotSelectionInclude(local);\n return {\n ...local,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n syncSessions: true,\n ...(localInclude\n ? {\n selection: selectionForSnapshot(\n localInclude.includes(\"sessions\") ? localInclude : [...localInclude, \"sessions\"],\n ),\n }\n : {}),\n files: [...local.files.filter((file) => !isSessionPath(file.path)), ...remoteSessions].sort((left, right) =>\n left.path.localeCompare(right.path),\n ),\n };\n}\n\nfunction sameOptionalInclude(left: string[] | undefined, right: string[] | undefined) {\n if (!left || !right) return left === right;\n return left.length === right.length && left.every((item, index) => item === right[index]);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,kBAAkB;AAEvC,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,OAAO,UAAU;AA0BjB,IAAM,UAAU;AAChB,IAAM,kBAAqC,qBAAqB,OAAO,CAAC,SAAS,KAAK,SAAS,GAAG,CAAC;AACnG,IAAM,iBAAiB,IAAI,IAAY,qBAAqB,OAAO,CAAC,SAAS,CAAC,KAAK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;AAAA,IACL,OAAO,CAAC,GAAG,MAAM,MAAM,OAAO,CAAC,SAAS,CAAC,cAAc,KAAK,IAAI,CAAC,GAAG,GAAG,cAAc,EAAE;AAAA,MAAK,CAAC,MAAM,UACjG,KAAK,KAAK,cAAc,MAAM,IAAI;AAAA,IACpC;AAAA,EACF;AACF;AAEA,SAAS,oBAAoB,MAA4B,OAA6B;AACpF,MAAI,CAAC,QAAQ,CAAC,MAAO,QAAO,SAAS;AACrC,SAAO,KAAK,WAAW,MAAM,UAAU,KAAK,MAAM,CAAC,MAAM,UAAU,SAAS,MAAM,KAAK,CAAC;AAC1F;",
6
+ "names": ["configuredSessionDir"]
7
+ }
@@ -16,7 +16,7 @@ import {
16
16
  syncConfigReviewIdentity,
17
17
  syncSetupReviewIdentity,
18
18
  updateLocalConfig
19
- } from "./chunk-QO333NM4.ts";
19
+ } from "./chunk-RX3WGWVL.ts";
20
20
  import {
21
21
  throwIfAborted
22
22
  } from "./chunk-PWMWOJP4.ts";
@@ -124,4 +124,4 @@ export {
124
124
  saveOnSwitch,
125
125
  useSyncSetup
126
126
  };
127
- //# sourceMappingURL=chunk-GP5DU62N.ts.map
127
+ //# sourceMappingURL=chunk-PWA3YN5Z.ts.map
@@ -1,25 +1,27 @@
1
1
  // @generated by scripts/build-runtime.mjs; do not edit.
2
2
  // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
+ import {
4
+ sameLocalFields,
5
+ validatePortableSnapshot
6
+ } from "./chunk-UGSSZWQ6.ts";
3
7
  import {
4
8
  safeTerminalText
5
9
  } from "./chunk-AMJRUXFT.ts";
6
10
  import {
7
11
  syncConfigReviewFingerprint
8
- } from "./chunk-QO333NM4.ts";
9
- import {
10
- sameLocalFields,
11
- validatePortableSnapshot
12
- } from "./chunk-A6HU4ERM.ts";
12
+ } from "./chunk-RX3WGWVL.ts";
13
13
  import {
14
14
  throwIfAborted
15
15
  } from "./chunk-PWMWOJP4.ts";
16
16
  import {
17
- filterSnapshotForConfigPolicy,
17
+ filterSnapshotForConfigPolicy
18
+ } from "./chunk-PHANBTVM.ts";
19
+ import {
18
20
  inspectRemoteSelection,
19
21
  remoteSelectionMismatch,
20
22
  sameSyncInclude,
21
23
  snapshotSelectionInclude
22
- } from "./chunk-QOFMXPM5.ts";
24
+ } from "./chunk-DFJGTVPX.ts";
23
25
 
24
26
  // src/sync/remote-snapshot.ts
25
27
  async function readSnapshotForHead(backend, head, signal) {
@@ -84,4 +86,4 @@ export {
84
86
  formatRemoteSelectionStatus,
85
87
  readRemoteSnapshot
86
88
  };
87
- //# sourceMappingURL=chunk-YK52VDXG.ts.map
89
+ //# sourceMappingURL=chunk-QWV3XKNJ.ts.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/sync/remote-snapshot.ts"],
4
4
  "sourcesContent": ["import type { RemoteHead, SyncBackend } from \"../backends/sync-backend.js\";\nimport { syncConfigReviewFingerprint } from \"../settings/config.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport { filterSnapshotForConfigPolicy } from \"../snapshot/snapshot.js\";\nimport type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport { safeTerminalText } from \"../ui/terminal-text.js\";\nimport { sameLocalFields, validatePortableSnapshot } from \"./local-fields.js\";\nimport { throwIfAborted } from \"./signals.js\";\nimport {\n inspectRemoteSelection,\n type RemoteSelectionState,\n remoteSelectionMismatch,\n sameSyncInclude,\n snapshotSelectionInclude,\n} from \"./sync-policy.js\";\n\nexport async function readSnapshotForHead(backend: SyncBackend, head: RemoteHead, signal?: AbortSignal) {\n const snapshot = await backend.readSnapshot(head.snapshotRef, signal);\n throwIfAborted(signal);\n validatePortableSnapshot(snapshot);\n if (snapshot.id !== head.snapshotId) {\n throw new Error(`Remote head ${head.snapshotId} resolved to unexpected snapshot ${snapshot.id}.`);\n }\n if (head.selection) {\n const snapshotInclude = snapshotSelectionInclude(snapshot);\n if (!snapshotInclude || !sameSyncInclude(head.selection.include, snapshotInclude)) {\n throw new Error(\"Remote head selection does not match its immutable snapshot.\");\n }\n }\n return snapshot;\n}\n\nexport function requireCompatibleRemoteSelection(config: AnySyncConfig, snapshot: Snapshot) {\n if (!sameLocalFields(config.localFields, snapshot.localFields))\n throw new Error(\n \"Remote local-field policy differs; confirm a reviewed directional migration. Old history is not erased.\",\n );\n const state = inspectRemoteSelection(config.include, snapshot);\n if (state.kind === \"different\") {\n throw remoteSelectionMismatch(config, state.include, syncConfigReviewFingerprint(config));\n }\n}\n\nexport function formatRemoteSelectionStatus(state: RemoteSelectionState | undefined) {\n if (!state) return \"remote included content: unavailable (remote is empty)\";\n if (state.kind === \"same\") return \"remote included content: matches this setup\";\n if (state.kind === \"legacy\") {\n return `remote included content: unavailable in legacy snapshot (${state.discovered.length} path${state.discovered.length === 1 ? \"\" : \"s\"} discovered, partial)`;\n }\n return [\n \"remote included content: differs from this setup\",\n `remote-only selection: ${safeList(state.remoteOnly)}`,\n `local-only selection: ${safeList(state.localOnly)}`,\n ].join(\"\\n\");\n}\n\nfunction safeList(values: readonly string[]) {\n return values.length > 0 ? values.map(safeTerminalText).join(\", \") : \"none\";\n}\n\nexport async function readRemoteSnapshot(\n backend: SyncBackend,\n config: AnySyncConfig,\n signal?: AbortSignal,\n options: { allowSelectionDifference?: boolean } = {},\n) {\n const head = await backend.readHead(signal);\n if (!head) return { head: undefined, snapshot: undefined, selectionState: undefined };\n const snapshot = await readSnapshotForHead(backend, head, signal);\n const selectionState = inspectRemoteSelection(config.include, snapshot);\n if (!options.allowSelectionDifference && selectionState.kind === \"different\") {\n const configIdentity = syncConfigReviewFingerprint(config);\n throw remoteSelectionMismatch(config, selectionState.include, configIdentity);\n }\n return {\n head,\n snapshot: filterSnapshotForConfigPolicy(snapshot, config),\n selectionState,\n };\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAgBA,eAAsB,oBAAoB,SAAsB,MAAkB,QAAsB;AACtG,QAAM,WAAW,MAAM,QAAQ,aAAa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I,CAAC,MAAO,QAAO;AACnB,MAAI,MAAM,SAAS,OAAQ,QAAO;AAClC,MAAI,MAAM,SAAS,UAAU;AAC3B,WAAO,4DAA4D,MAAM,WAAW,MAAM,QAAQ,MAAM,WAAW,WAAW,IAAI,KAAK,GAAG;AAAA,EAC5I;AACA,SAAO;AAAA,IACL;AAAA,IACA,0BAA0B,SAAS,MAAM,UAAU,CAAC;AAAA,IACpD,yBAAyB,SAAS,MAAM,SAAS,CAAC;AAAA,EACpD,EAAE,KAAK,IAAI;AACb;AAEA,SAAS,SAAS,QAA2B;AAC3C,SAAO,OAAO,SAAS,IAAI,OAAO,IAAI,gBAAgB,EAAE,KAAK,IAAI,IAAI;AACvE;AAEA,eAAsB,mBACpB,SACA,QACA,QACA,UAAkD,CAAC,GACnD;AACA,QAAM,OAAO,MAAM,QAAQ,SAAS,MAAM;AAC1C,MAAI,CAAC,KAAM,QAAO,EAAE,MAAM,QAAW,UAAU,QAAW,gBAAgB,OAAU;AACpF,QAAM,WAAW,MAAM,oBAAoB,SAAS,MAAM,MAAM;AAChE,QAAM,iBAAiB,uBAAuB,OAAO,SAAS,QAAQ;AACtE,MAAI,CAAC,QAAQ,4BAA4B,eAAe,SAAS,aAAa;AAC5E,UAAM,iBAAiB,4BAA4B,MAAM;AACzD,UAAM,wBAAwB,QAAQ,eAAe,SAAS,cAAc;AAAA,EAC9E;AACA,SAAO;AAAA,IACL;AAAA,IACA,UAAU,8BAA8B,UAAU,MAAM;AAAA,IACxD;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -5,15 +5,15 @@
5
5
  var createSyncBackend = async (config) => {
6
6
  switch (config.backend.type) {
7
7
  case "s3": {
8
- const { S3SyncBackend } = await import("./s3-backend-F7PR5FB3.ts");
8
+ const { S3SyncBackend } = await import("./s3-backend-CJXBEWWU.ts");
9
9
  return new S3SyncBackend(config.backend);
10
10
  }
11
11
  case "webdav": {
12
- const { WebDavSyncBackend } = await import("./webdav-backend-TGFUH3SF.ts");
12
+ const { WebDavSyncBackend } = await import("./webdav-backend-2Q5ZEBST.ts");
13
13
  return new WebDavSyncBackend(config.backend);
14
14
  }
15
15
  case "git": {
16
- const { GitSyncBackend } = await import("./git-backend-NYKSG5X6.ts");
16
+ const { GitSyncBackend } = await import("./git-backend-7PCWECRN.ts");
17
17
  return new GitSyncBackend(config.backend);
18
18
  }
19
19
  }
@@ -22,4 +22,4 @@ var createSyncBackend = async (config) => {
22
22
  export {
23
23
  createSyncBackend
24
24
  };
25
- //# sourceMappingURL=chunk-ORGBI36T.ts.map
25
+ //# sourceMappingURL=chunk-RAMHGOX2.ts.map
@@ -2,10 +2,7 @@
2
2
  // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
3
  import {
4
4
  normalizeLocalFields
5
- } from "./chunk-A6HU4ERM.ts";
6
- import {
7
- normalizeSyncInclude
8
- } from "./chunk-QOFMXPM5.ts";
5
+ } from "./chunk-X7R6DCVF.ts";
9
6
  import {
10
7
  backendIdentityCoordinates,
11
8
  normalizeEndpointIdentity,
@@ -20,6 +17,9 @@ import {
20
17
  normalizeGitRemote,
21
18
  normalizeGitRemoteIdentity
22
19
  } from "./chunk-T2SJD3N7.ts";
20
+ import {
21
+ normalizeSyncInclude
22
+ } from "./chunk-DFJGTVPX.ts";
23
23
 
24
24
  // src/settings/config.ts
25
25
  import { createHash } from "node:crypto";
@@ -1124,4 +1124,4 @@ export {
1124
1124
  isEnabled,
1125
1125
  isExplicitlyEnabled
1126
1126
  };
1127
- //# sourceMappingURL=chunk-QO333NM4.ts.map
1127
+ //# sourceMappingURL=chunk-RX3WGWVL.ts.map