@narumitw/pi-sync 0.49.14 → 0.50.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 (209) hide show
  1. package/README.md +134 -241
  2. package/dist/chunks/chunk-2B2ELUF5.ts +29 -0
  3. package/dist/chunks/chunk-2B2ELUF5.ts.map +7 -0
  4. package/dist/chunks/chunk-6LP3MCR2.ts +115 -0
  5. package/dist/chunks/chunk-6LP3MCR2.ts.map +7 -0
  6. package/dist/chunks/chunk-6UHKGALE.ts +134 -0
  7. package/dist/chunks/chunk-6UHKGALE.ts.map +7 -0
  8. package/dist/chunks/{chunk-RGJ6SOYR.ts → chunk-AUSDLD6F.ts} +4 -4
  9. package/dist/chunks/chunk-AUSDLD6F.ts.map +7 -0
  10. package/dist/chunks/{chunk-3NDD5QPM.ts → chunk-AXXS2BPA.ts} +9 -9
  11. package/dist/chunks/chunk-AXXS2BPA.ts.map +7 -0
  12. package/dist/chunks/{chunk-APZVBSM6.ts → chunk-C7XY5NF5.ts} +214 -365
  13. package/dist/chunks/chunk-C7XY5NF5.ts.map +7 -0
  14. package/dist/chunks/{chunk-4U6AFLJB.ts → chunk-CHH26D4F.ts} +3 -2
  15. package/dist/chunks/chunk-CHH26D4F.ts.map +7 -0
  16. package/dist/chunks/chunk-CPEHGXJV.ts +50 -0
  17. package/dist/chunks/chunk-CPEHGXJV.ts.map +7 -0
  18. package/dist/chunks/{chunk-5MQ76BK5.ts → chunk-D5X27LCA.ts} +2 -2
  19. package/dist/chunks/chunk-D5X27LCA.ts.map +7 -0
  20. package/dist/chunks/{chunk-LJDSHNS3.ts → chunk-GWMHAQG4.ts} +4 -4
  21. package/dist/chunks/chunk-GWMHAQG4.ts.map +7 -0
  22. package/dist/chunks/{chunk-FR6CVXAL.ts → chunk-HUDQATCL.ts} +25 -25
  23. package/dist/chunks/chunk-HUDQATCL.ts.map +7 -0
  24. package/dist/chunks/{chunk-YQ6UW7IF.ts → chunk-JAAKLL6M.ts} +2 -2
  25. package/dist/chunks/chunk-JAAKLL6M.ts.map +7 -0
  26. package/dist/chunks/chunk-JSYMGJQQ.ts +51 -0
  27. package/dist/chunks/chunk-JSYMGJQQ.ts.map +7 -0
  28. package/dist/chunks/chunk-L7TBO32M.ts +25 -0
  29. package/dist/chunks/chunk-L7TBO32M.ts.map +7 -0
  30. package/dist/chunks/{chunk-4F3W4CSC.ts → chunk-LCRI3ABW.ts} +22 -8
  31. package/dist/chunks/chunk-LCRI3ABW.ts.map +7 -0
  32. package/dist/chunks/chunk-LTBWGSBV.ts +12 -0
  33. package/dist/chunks/chunk-LTBWGSBV.ts.map +7 -0
  34. package/dist/chunks/chunk-NJFUIVYL.ts +17 -0
  35. package/dist/chunks/chunk-NJFUIVYL.ts.map +7 -0
  36. package/dist/chunks/{chunk-EWX3TPLQ.ts → chunk-OEX4ABY6.ts} +39 -37
  37. package/dist/chunks/chunk-OEX4ABY6.ts.map +7 -0
  38. package/dist/chunks/chunk-OUHGBFYF.ts +1255 -0
  39. package/dist/chunks/chunk-OUHGBFYF.ts.map +7 -0
  40. package/dist/chunks/{chunk-HGV24P4T.ts → chunk-Q2TUM5X6.ts} +3 -3
  41. package/dist/chunks/chunk-Q2TUM5X6.ts.map +7 -0
  42. package/dist/chunks/{chunk-BHJUISB4.ts → chunk-SL64RLXR.ts} +8 -6
  43. package/dist/chunks/chunk-SL64RLXR.ts.map +7 -0
  44. package/dist/chunks/chunk-T3HH3UEJ.ts +96 -0
  45. package/dist/chunks/chunk-T3HH3UEJ.ts.map +7 -0
  46. package/dist/chunks/chunk-TEN2ZBJV.ts +101 -0
  47. package/dist/chunks/chunk-TEN2ZBJV.ts.map +7 -0
  48. package/dist/chunks/chunk-THMF4BVL.ts +18 -0
  49. package/dist/chunks/chunk-THMF4BVL.ts.map +7 -0
  50. package/dist/chunks/{chunk-LONPFFNP.ts → chunk-X5OM6GXT.ts} +9 -7
  51. package/dist/chunks/chunk-X5OM6GXT.ts.map +7 -0
  52. package/dist/chunks/chunk-XBX4HBLG.ts +57 -0
  53. package/dist/chunks/chunk-XBX4HBLG.ts.map +7 -0
  54. package/dist/chunks/{chunk-5WJNWFTG.ts → chunk-YKJHPTGO.ts} +23 -55
  55. package/dist/chunks/chunk-YKJHPTGO.ts.map +7 -0
  56. package/dist/chunks/chunk-Z4DQF6L3.ts +12 -0
  57. package/dist/chunks/chunk-Z4DQF6L3.ts.map +7 -0
  58. package/dist/chunks/{chunk-F5QL2GPY.ts → chunk-ZI5MXMEX.ts} +5 -99
  59. package/dist/chunks/chunk-ZI5MXMEX.ts.map +7 -0
  60. package/dist/chunks/{file-selection-4UABOP44.ts → file-selection-FTTKAOYX.ts} +10 -7
  61. package/dist/chunks/file-selection-FTTKAOYX.ts.map +7 -0
  62. package/dist/chunks/{git-backend-E3UOUUOM.ts → git-backend-OQW46G2X.ts} +42 -17
  63. package/dist/chunks/git-backend-OQW46G2X.ts.map +7 -0
  64. package/dist/chunks/manager-result-dispatcher-U23ODD32.ts +22 -0
  65. package/dist/chunks/manager-ui-ABATHC36.ts +1680 -0
  66. package/dist/chunks/manager-ui-ABATHC36.ts.map +7 -0
  67. package/dist/chunks/remote-selection-ui-ZE3TY67S.ts +21 -0
  68. package/dist/chunks/{s3-backend-3QZGO2EF.ts → s3-backend-3P33LQHU.ts} +96 -18
  69. package/dist/chunks/s3-backend-3P33LQHU.ts.map +7 -0
  70. package/dist/chunks/{setup-switch-X3W3FALZ.ts → setup-switch-IS2PEZ3J.ts} +9 -9
  71. package/dist/chunks/setup-wizard-VB3VDOV5.ts +89 -0
  72. package/dist/chunks/setup-wizard-VB3VDOV5.ts.map +7 -0
  73. package/dist/chunks/{snapshot-WBSV4MQG.ts → snapshot-HKEWCVK6.ts} +7 -6
  74. package/dist/chunks/sync-inspection-FEP4L5TR.ts +20 -0
  75. package/dist/chunks/{sync-operations-MPAFVVHA.ts → sync-operations-ONJ27QRL.ts} +381 -299
  76. package/dist/chunks/sync-operations-ONJ27QRL.ts.map +7 -0
  77. package/dist/chunks/{sync-state-36H7ULG2.ts → sync-state-Q2FTXTW6.ts} +6 -6
  78. package/dist/chunks/sync-state-Q2FTXTW6.ts.map +7 -0
  79. package/dist/chunks/{webdav-backend-ZD5RHRIU.ts → webdav-backend-ECIKD7SO.ts} +26 -13
  80. package/dist/chunks/webdav-backend-ECIKD7SO.ts.map +7 -0
  81. package/dist/index.ts +477 -342
  82. package/dist/index.ts.map +4 -4
  83. package/docs/settings.md +211 -0
  84. package/package.json +6 -8
  85. package/src/{backend-factory.ts → backends/backend-factory.ts} +4 -4
  86. package/src/backends/backend-identity.ts +40 -0
  87. package/src/backends/backend-types.ts +81 -0
  88. package/src/{git-backend.ts → backends/git/git-backend.ts} +43 -19
  89. package/src/{git-config.ts → backends/git/git-config.ts} +1 -0
  90. package/src/{git-storage.ts → backends/git/git-storage.ts} +2 -2
  91. package/src/{s3-backend.ts → backends/s3/s3-backend.ts} +45 -9
  92. package/src/{s3-client.ts → backends/s3/s3-client.ts} +56 -8
  93. package/src/{sync-backend.ts → backends/sync-backend.ts} +1 -1
  94. package/src/{webdav-backend.ts → backends/webdav/webdav-backend.ts} +22 -10
  95. package/src/{webdav-client.ts → backends/webdav/webdav-client.ts} +1 -1
  96. package/src/{webdav-config.ts → backends/webdav/webdav-config.ts} +1 -0
  97. package/src/commands/command-execution.ts +330 -0
  98. package/src/commands/command-handler.ts +201 -0
  99. package/src/commands/command-types.ts +18 -0
  100. package/src/{command.ts → commands/command.ts} +2 -1
  101. package/src/commands/setup-completions.ts +6 -0
  102. package/src/settings/config.ts +238 -0
  103. package/src/{settings-management.ts → settings/settings-management.ts} +40 -14
  104. package/src/settings/settings-store.ts +109 -0
  105. package/src/settings/settings-types.ts +128 -0
  106. package/src/settings/settings-validation.ts +443 -0
  107. package/src/snapshot/session-paths.ts +84 -0
  108. package/src/{snapshot-apply.ts → snapshot/snapshot-apply.ts} +3 -3
  109. package/src/{snapshot-codec.ts → snapshot/snapshot-codec.ts} +2 -2
  110. package/src/{snapshot-transaction.ts → snapshot/snapshot-transaction.ts} +5 -4
  111. package/src/snapshot/snapshot-types.ts +38 -0
  112. package/src/{snapshot.ts → snapshot/snapshot.ts} +39 -20
  113. package/src/state/json-file.ts +20 -0
  114. package/src/{lock.ts → state/lock.ts} +3 -2
  115. package/src/{operation-availability.ts → state/operation-availability.ts} +2 -2
  116. package/src/state/state-types.ts +20 -0
  117. package/src/state/sync-state-store.ts +62 -0
  118. package/src/sync/automatic-sync.ts +103 -0
  119. package/src/{remote-snapshot.ts → sync/remote-snapshot.ts} +27 -4
  120. package/src/{setup-switch.ts → sync/setup-switch.ts} +6 -7
  121. package/src/sync/signals.ts +10 -0
  122. package/src/sync/startup-check.ts +128 -0
  123. package/src/{sync-decision.ts → sync/sync-decision.ts} +6 -3
  124. package/src/sync/sync-error-guidance.ts +53 -0
  125. package/src/sync/sync-inspection.ts +51 -0
  126. package/src/sync/sync-loaders.ts +54 -0
  127. package/src/{sync-operations.ts → sync/sync-mutations.ts} +41 -330
  128. package/src/sync/sync-operations.ts +12 -0
  129. package/src/{sync-policy.ts → sync/sync-policy.ts} +2 -2
  130. package/src/sync/sync-queries.ts +235 -0
  131. package/src/{sync-state.ts → sync/sync-state.ts} +5 -4
  132. package/src/sync-extension.ts +64 -708
  133. package/src/sync.ts +8 -8
  134. package/src/types.ts +47 -284
  135. package/src/ui/automatic-sync-summary.ts +6 -0
  136. package/src/{cancellable-operation.ts → ui/cancellable-operation.ts} +4 -4
  137. package/src/{file-selection.ts → ui/file-selection.ts} +5 -3
  138. package/src/{manager-attention.ts → ui/manager-attention.ts} +5 -1
  139. package/src/{manager-recovery.ts → ui/manager-recovery.ts} +6 -2
  140. package/src/{manager-state.ts → ui/manager-state.ts} +35 -14
  141. package/src/ui/manager-ui.ts +386 -0
  142. package/src/{remote-selection-ui.ts → ui/remote-selection-ui.ts} +21 -13
  143. package/src/{secret-input.ts → ui/secret-input.ts} +22 -4
  144. package/src/{settings-ui.ts → ui/settings-ui.ts} +42 -11
  145. package/src/ui/setup/git-ui.ts +293 -0
  146. package/src/{s3-credentials-ui.ts → ui/setup/s3-credentials-ui.ts} +13 -21
  147. package/src/ui/setup/s3-ui.ts +217 -0
  148. package/src/ui/setup/setup-actions.ts +127 -0
  149. package/src/ui/setup/setup-location-ui.ts +167 -0
  150. package/src/ui/setup/setup-name-ui.ts +34 -0
  151. package/src/ui/setup/setup-prompts.ts +92 -0
  152. package/src/ui/setup/setup-review.ts +70 -0
  153. package/src/ui/setup/setup-switcher.ts +181 -0
  154. package/src/ui/setup/setup-wizard.ts +39 -0
  155. package/src/ui/setup/text-input.ts +78 -0
  156. package/src/ui/setup/webdav-ui.ts +330 -0
  157. package/src/{storage-connections-ui.ts → ui/storage-connections-ui.ts} +99 -69
  158. package/src/{sync-attention.ts → ui/sync-attention.ts} +75 -6
  159. package/src/{sync-format.ts → ui/sync-format.ts} +7 -13
  160. package/src/{sync-resolution-ui.ts → ui/sync-resolution-ui.ts} +4 -3
  161. package/src/{sync-setups-ui.ts → ui/sync-setups-ui.ts} +23 -10
  162. package/src/ui/terminal-text.ts +4 -0
  163. package/dist/chunks/chunk-3NDD5QPM.ts.map +0 -7
  164. package/dist/chunks/chunk-4F3W4CSC.ts.map +0 -7
  165. package/dist/chunks/chunk-4U6AFLJB.ts.map +0 -7
  166. package/dist/chunks/chunk-5MQ76BK5.ts.map +0 -7
  167. package/dist/chunks/chunk-5WJNWFTG.ts.map +0 -7
  168. package/dist/chunks/chunk-APZVBSM6.ts.map +0 -7
  169. package/dist/chunks/chunk-BHJUISB4.ts.map +0 -7
  170. package/dist/chunks/chunk-EWX3TPLQ.ts.map +0 -7
  171. package/dist/chunks/chunk-F5QL2GPY.ts.map +0 -7
  172. package/dist/chunks/chunk-FR6CVXAL.ts.map +0 -7
  173. package/dist/chunks/chunk-HGV24P4T.ts.map +0 -7
  174. package/dist/chunks/chunk-JNOOSPEW.ts +0 -82
  175. package/dist/chunks/chunk-JNOOSPEW.ts.map +0 -7
  176. package/dist/chunks/chunk-LJDSHNS3.ts.map +0 -7
  177. package/dist/chunks/chunk-LONPFFNP.ts.map +0 -7
  178. package/dist/chunks/chunk-RGJ6SOYR.ts.map +0 -7
  179. package/dist/chunks/chunk-W64NEHXT.ts +0 -167
  180. package/dist/chunks/chunk-W64NEHXT.ts.map +0 -7
  181. package/dist/chunks/chunk-YQ6UW7IF.ts.map +0 -7
  182. package/dist/chunks/file-selection-4UABOP44.ts.map +0 -7
  183. package/dist/chunks/git-backend-E3UOUUOM.ts.map +0 -7
  184. package/dist/chunks/manager-result-dispatcher-RNRQA3PW.ts +0 -18
  185. package/dist/chunks/manager-ui-QO2P4V3Z.ts +0 -2757
  186. package/dist/chunks/manager-ui-QO2P4V3Z.ts.map +0 -7
  187. package/dist/chunks/remote-selection-ui-LHSAGKGA.ts +0 -17
  188. package/dist/chunks/s3-backend-3QZGO2EF.ts.map +0 -7
  189. package/dist/chunks/sync-operations-MPAFVVHA.ts.map +0 -7
  190. package/dist/chunks/webdav-backend-ZD5RHRIU.ts.map +0 -7
  191. package/src/config.ts +0 -910
  192. package/src/git-ui.ts +0 -307
  193. package/src/manager-helpers.ts +0 -64
  194. package/src/manager-ui.ts +0 -997
  195. package/src/webdav-ui.ts +0 -421
  196. /package/dist/chunks/{manager-result-dispatcher-RNRQA3PW.ts.map → manager-result-dispatcher-U23ODD32.ts.map} +0 -0
  197. /package/dist/chunks/{remote-selection-ui-LHSAGKGA.ts.map → remote-selection-ui-ZE3TY67S.ts.map} +0 -0
  198. /package/dist/chunks/{setup-switch-X3W3FALZ.ts.map → setup-switch-IS2PEZ3J.ts.map} +0 -0
  199. /package/dist/chunks/{snapshot-WBSV4MQG.ts.map → snapshot-HKEWCVK6.ts.map} +0 -0
  200. /package/dist/chunks/{sync-state-36H7ULG2.ts.map → sync-inspection-FEP4L5TR.ts.map} +0 -0
  201. /package/src/{git-runner.ts → backends/git/git-runner.ts} +0 -0
  202. /package/src/{config-errors.ts → settings/config-errors.ts} +0 -0
  203. /package/src/{config-file.ts → settings/config-file.ts} +0 -0
  204. /package/src/{snapshot-paths.ts → snapshot/snapshot-paths.ts} +0 -0
  205. /package/src/{lock-policy.ts → state/lock-policy.ts} +0 -0
  206. /package/src/{lockfile-fs.ts → state/lockfile-fs.ts} +0 -0
  207. /package/src/{state-directory.ts → state/state-directory.ts} +0 -0
  208. /package/src/{sync-errors.ts → sync/sync-errors.ts} +0 -0
  209. /package/src/{manager-result-dispatcher.ts → ui/manager-result-dispatcher.ts} +0 -0
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/sync-state.ts"],
4
- "sourcesContent": ["import { toPosix } from \"./paths.js\";\nimport {\n\tcanonicalSnapshotPathForConfig,\n\tfilterSnapshotForConfigPolicy,\n\tisConfiguredSnapshotPath,\n\tisSessionPath,\n} from \"./snapshot.js\";\nimport type { RemoteHead } from \"./sync-backend.js\";\nimport {\n\tcustomIncludePathsByLower,\n\tincludeFromSelectionConfig,\n\tnormalizeSyncInclude,\n\ttype SyncSelectionConfig,\n} from \"./sync-policy.js\";\nimport type { Snapshot, SyncState } from \"./types.js\";\n\ntype SyncPolicyConfig = SyncSelectionConfig;\n\nexport function hasLocalChanges(local: Snapshot, state: SyncState, config: SyncPolicyConfig) {\n\treturn !sameHashes(fileHashMap(local), stateHashMapForConfig(state, config));\n}\n\nexport function remoteChangedSinceState(\n\thead: RemoteHead | undefined,\n\tstate: SyncState,\n\tconfig: SyncPolicyConfig,\n\tsameRevision: (left: string, right: string) => boolean,\n) {\n\tif (!head) return Boolean(state.lastAppliedSnapshot);\n\tif (head.snapshotId !== state.lastAppliedSnapshot) return true;\n\tif (state.lastRemoteRevision && !sameRevision(head.revision, state.lastRemoteRevision))\n\t\treturn true;\n\tif (syncIncludeChanged(state, config)) return true;\n\treturn (\n\t\tincludeFromSelectionConfig(config).includes(\"sessions\") &&\n\t\t!state.include?.includes(\"sessions\") &&\n\t\thead.syncSessions\n\t);\n}\n\nexport function hasRemoteChanges(\n\tremote: Snapshot,\n\tstate: SyncState,\n\tconfig: SyncPolicyConfig,\n\tignoredPaths = new Set<string>(),\n) {\n\tif (remote.id === state.lastAppliedSnapshot && !syncPolicyChanged(state, config)) return false;\n\treturn !snapshotHashesMatchState(\n\t\tfilterSnapshotForConfigPolicy(remote, config),\n\t\tstate,\n\t\tconfig,\n\t\tignoredPaths,\n\t);\n}\n\nexport function sameHashes(left: Record<string, string>, right: Record<string, string>) {\n\tconst keys = new Set([...Object.keys(left), ...Object.keys(right)]);\n\tfor (const key of keys) if (left[key] !== right[key]) return false;\n\treturn true;\n}\n\nexport function fileHashMap(snapshot: Snapshot) {\n\treturn Object.fromEntries(snapshot.files.map((file) => [file.path, file.sha256]));\n}\n\nfunction stateHashMapForConfig(state: SyncState, config: SyncPolicyConfig) {\n\tconst includePaths = customIncludePathsByLower(includeFromSelectionConfig(config));\n\treturn Object.fromEntries(\n\t\tObject.entries(state.lastFileHashes)\n\t\t\t.filter(([filePath]) => isConfiguredSnapshotPath(filePath, config))\n\t\t\t.map(([filePath, hash]) => [canonicalSnapshotPathForConfig(filePath, includePaths), hash]),\n\t);\n}\n\nexport function snapshotHashesMatchState(\n\tsnapshot: Snapshot,\n\tstate: SyncState,\n\tconfig: SyncPolicyConfig,\n\tignoredPaths = new Set<string>(),\n) {\n\treturn sameHashes(\n\t\twithoutHashPaths(fileHashMap(snapshot), ignoredPaths),\n\t\twithoutHashPaths(stateHashMapForConfig(state, config), ignoredPaths),\n\t);\n}\n\nexport function snapshotsMatch(left: Snapshot, right: Snapshot) {\n\treturn (\n\t\tleft.syncSessions === right.syncSessions && sameHashes(fileHashMap(left), fileHashMap(right))\n\t);\n}\n\nfunction withoutHashPaths(hashes: Record<string, string>, ignoredPaths: Set<string>) {\n\tif (ignoredPaths.size === 0) return hashes;\n\treturn Object.fromEntries(\n\t\tObject.entries(hashes).filter(([filePath]) => !ignoredPaths.has(toPosix(filePath))),\n\t);\n}\n\nexport function syncPolicyChanged(state: SyncState, config: SyncPolicyConfig) {\n\treturn syncIncludeChanged(state, config);\n}\n\nexport function shouldRefreshSyncedState(\n\tremote: Snapshot,\n\thead: RemoteHead | undefined,\n\tstate: SyncState,\n\tconfig: SyncPolicyConfig,\n\tsameRevision: (left: string, right: string) => boolean,\n) {\n\treturn (\n\t\tremote.id !== state.lastAppliedSnapshot ||\n\t\tBoolean(\n\t\t\thead && (!state.lastRemoteRevision || !sameRevision(head.revision, state.lastRemoteRevision)),\n\t\t) ||\n\t\tsyncPolicyChanged(state, config)\n\t);\n}\n\nfunction syncIncludeChanged(state: SyncState, config: SyncPolicyConfig) {\n\tconst stored = state.include\n\t\t? normalizeSyncInclude(state.include)\n\t\t: includeFromSelectionConfig(state);\n\tconst current = includeFromSelectionConfig(config);\n\treturn stored.length !== current.length || stored.some((item, index) => item !== current[index]);\n}\n\nexport function settingsHashMap(snapshot: Snapshot) {\n\treturn Object.fromEntries(\n\t\tsnapshot.files\n\t\t\t.filter((file) => !isSessionPath(file.path))\n\t\t\t.map((file) => [file.path, file.sha256]),\n\t);\n}\n\nexport function sessionHashMap(snapshot: Snapshot) {\n\treturn Object.fromEntries(\n\t\tsnapshot.files\n\t\t\t.filter((file) => isSessionPath(file.path))\n\t\t\t.map((file) => [file.path, file.sha256]),\n\t);\n}\n\nexport function settingsHashMapFromState(state: SyncState) {\n\treturn Object.fromEntries(\n\t\tObject.entries(state.lastFileHashes).filter(([filePath]) => !isSessionPath(filePath)),\n\t);\n}\n\nexport function settingsHashesMatchState(remote: Snapshot, state: SyncState) {\n\treturn sameHashes(settingsHashMap(remote), settingsHashMapFromState(state));\n}\n\nexport function canPullRemoteSettingsOnFirstSync(local: Snapshot, remote: Snapshot) {\n\tconst remoteSettings = settingsHashMap(remote);\n\treturn Object.entries(settingsHashMap(local)).every(\n\t\t([filePath, hash]) => remoteSettings[filePath] === hash,\n\t);\n}\n\nexport function canPullRemoteSessionsOnFirstSync(local: Snapshot, remote: Snapshot) {\n\tconst localSessions = sessionHashMap(local);\n\tconst remoteSessions = sessionHashMap(remote);\n\treturn Object.entries(localSessions).every(\n\t\t([filePath, hash]) => remoteSessions[filePath] === hash,\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;AAkBO,SAAS,gBAAgB,OAAiB,OAAkB,QAA0B;AAC5F,SAAO,CAAC,WAAW,YAAY,KAAK,GAAG,sBAAsB,OAAO,MAAM,CAAC;AAC5E;AAEO,SAAS,wBACf,MACA,OACA,QACA,cACC;AACD,MAAI,CAAC,KAAM,QAAO,QAAQ,MAAM,mBAAmB;AACnD,MAAI,KAAK,eAAe,MAAM,oBAAqB,QAAO;AAC1D,MAAI,MAAM,sBAAsB,CAAC,aAAa,KAAK,UAAU,MAAM,kBAAkB;AACpF,WAAO;AACR,MAAI,mBAAmB,OAAO,MAAM,EAAG,QAAO;AAC9C,SACC,2BAA2B,MAAM,EAAE,SAAS,UAAU,KACtD,CAAC,MAAM,SAAS,SAAS,UAAU,KACnC,KAAK;AAEP;AAEO,SAAS,iBACf,QACA,OACA,QACA,eAAe,oBAAI,IAAY,GAC9B;AACD,MAAI,OAAO,OAAO,MAAM,uBAAuB,CAAC,kBAAkB,OAAO,MAAM,EAAG,QAAO;AACzF,SAAO,CAAC;AAAA,IACP,8BAA8B,QAAQ,MAAM;AAAA,IAC5C;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEO,SAAS,WAAW,MAA8B,OAA+B;AACvF,QAAM,OAAO,oBAAI,IAAI,CAAC,GAAG,OAAO,KAAK,IAAI,GAAG,GAAG,OAAO,KAAK,KAAK,CAAC,CAAC;AAClE,aAAW,OAAO,KAAM,KAAI,KAAK,GAAG,MAAM,MAAM,GAAG,EAAG,QAAO;AAC7D,SAAO;AACR;AAEO,SAAS,YAAY,UAAoB;AAC/C,SAAO,OAAO,YAAY,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,MAAM,KAAK,MAAM,CAAC,CAAC;AACjF;AAEA,SAAS,sBAAsB,OAAkB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generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
- import {
4
- fileHashMap
5
- } from "./chunk-RGJ6SOYR.ts";
6
- import {
7
- agentDir
8
- } from "./chunk-APZVBSM6.ts";
9
- import {
10
- inspectRemoteSelection
11
- } from "./chunk-YQ6UW7IF.ts";
12
-
13
- // src/sync-errors.ts
14
- var SetupPullRequiresUiError = class extends Error {
15
- };
16
- var SyncDecisionRequiredError = class extends Error {
17
- decision;
18
- constructor(decision) {
19
- super(decision.directMessage);
20
- this.name = "SyncDecisionRequiredError";
21
- this.decision = decision;
22
- }
23
- };
24
- function isSyncDecisionRequiredError(error) {
25
- return error instanceof SyncDecisionRequiredError;
26
- }
27
- function errorMessage(error) {
28
- const message = error instanceof Error ? error.message : String(error);
29
- return message.replace(/[\u0000-\u001f\u007f-\u009f]/gu, "?");
30
- }
31
-
32
- // src/sync-format.ts
33
- function formatDiff(local, remote) {
34
- const localMap = fileHashMap(local);
35
- const remoteMap = fileHashMap(remote);
36
- const allPaths = [.../* @__PURE__ */ new Set([...Object.keys(localMap), ...Object.keys(remoteMap)])].sort();
37
- const lines = [
38
- `local: ${local.files.length} files`,
39
- `remote: ${remote.id} (${remote.files.length} files)`,
40
- ""
41
- ];
42
- let changed = 0;
43
- for (const filePath of allPaths) {
44
- if (!localMap[filePath]) {
45
- lines.push(`Remote only: ${filePath}`);
46
- changed += 1;
47
- } else if (!remoteMap[filePath]) {
48
- lines.push(`Local only: ${filePath}`);
49
- changed += 1;
50
- } else if (localMap[filePath] !== remoteMap[filePath]) {
51
- lines.push(`Different: ${filePath}`);
52
- changed += 1;
53
- }
54
- }
55
- if (changed === 0) lines.push("No file differences.");
56
- return lines.join("\n");
57
- }
58
- function formatSnapshotOnlyDiff(title, snapshot) {
59
- return [`${title}: ${snapshot.id}`, ...snapshot.files.map((file) => `Add: ${file.path}`)].join(
60
- "\n"
61
- );
62
- }
63
- function formatPushSummary(config, destination, upload, head, preservedRemoteFileCount = 0, remote) {
64
- return [
65
- `Sync setup: ${safeTerminalText(config.setupName)}`,
66
- `Storage location: ${safeTerminalText(destination)}`,
67
- `Upload ${upload.files.length} files from ${safeTerminalText(agentDir())}.`,
68
- `Sessions: ${upload.syncSessions ? "included \u2014 may contain private conversations" : "not included"}`,
69
- head ? `Remote latest: ${head.snapshotId}` : "Remote latest: empty",
70
- "Publication effect: the backend's active head will reference the new immutable snapshot.",
71
- ...remote && inspectRemoteSelection(config.include, remote).kind === "different" ? [
72
- "Included-content policy effect: replace the differing remote selection with this setup's local selection."
73
- ] : [],
74
- formatPublicationPreview(remote, upload),
75
- preservedRemoteFileCount > 0 ? `Possible secrets in locally managed files were scanned before this prompt; ${preservedRemoteFileCount} preserved remote file(s) were not rescanned.` : "Possible secrets were scanned before this prompt."
76
- ].join("\n");
77
- }
78
- function formatApplyPreview(local, remote) {
79
- return formatDirectionalChanges(local, remote, {
80
- add: "Add locally",
81
- update: "Update locally",
82
- remove: "Remove locally"
83
- });
84
- }
85
- function formatPullSummary(config, destination, local, remote, protectedSessionCount) {
86
- return [
87
- `Sync setup: ${safeTerminalText(config.setupName)}`,
88
- `Storage location: ${safeTerminalText(destination)}`,
89
- `Snapshot: ${safeTerminalText(remote.id)}`,
90
- `Sessions: ${remote.syncSessions ? "included \u2014 may contain private conversations" : "not included"}`,
91
- `Protected live sessions: ${protectedSessionCount || "none"}`,
92
- formatApplyPreview(local, remote),
93
- "A local backup is created before these writes/deletes. The remote active snapshot is unchanged."
94
- ].join("\n");
95
- }
96
- function formatRollbackSummary(config, destination, local, remote, requestedSnapshot, protectedSessionCount) {
97
- return [
98
- `Sync setup: ${safeTerminalText(config.setupName)}`,
99
- `Storage location: ${safeTerminalText(destination)}`,
100
- `Snapshot: ${safeTerminalText(requestedSnapshot)}`,
101
- `Sessions: ${remote.syncSessions ? "included \u2014 may contain private conversations" : "not included"}`,
102
- `Protected live sessions: ${protectedSessionCount || "none"}`,
103
- formatApplyPreview(local, remote),
104
- "A local backup is created before applying; the backend's active head will change."
105
- ].join("\n");
106
- }
107
- function formatPublicationPreview(remote, upload) {
108
- if (!remote) {
109
- return ["Remote is empty.", ...upload.files.map((file) => `Add remotely: ${file.path}`)].join(
110
- "\n"
111
- );
112
- }
113
- return formatDirectionalChanges(remote, upload, {
114
- add: "Add remotely",
115
- update: "Update remotely",
116
- remove: "Remove remotely"
117
- });
118
- }
119
- function formatDirectionalChanges(before, after, labels) {
120
- const beforeMap = fileHashMap(before);
121
- const afterMap = fileHashMap(after);
122
- const paths = [.../* @__PURE__ */ new Set([...Object.keys(beforeMap), ...Object.keys(afterMap)])].sort();
123
- const lines = [];
124
- for (const filePath of paths) {
125
- if (!beforeMap[filePath]) lines.push(`${labels.add}: ${filePath}`);
126
- else if (!afterMap[filePath]) lines.push(`${labels.remove}: ${filePath}`);
127
- else if (beforeMap[filePath] !== afterMap[filePath])
128
- lines.push(`${labels.update}: ${filePath}`);
129
- }
130
- if (lines.length === 0) lines.push("No file changes.");
131
- return lines.join("\n");
132
- }
133
- function countPreservedRemoteFiles(local, upload) {
134
- const localPaths = new Set(local.files.map((file) => file.path));
135
- return upload.files.filter((file) => !localPaths.has(file.path)).length;
136
- }
137
- function publicationCapabilityDescription(capability) {
138
- switch (capability) {
139
- case "lease-protected":
140
- return "lease-protected (exact expected-ref update)";
141
- case "atomic-conditional":
142
- return "atomic-conditional (verified atomic precondition)";
143
- case "conditional-required":
144
- return "conditional-required (read-only until atomic preconditions are verified)";
145
- case "read-check-write-verify":
146
- return "read-check-write-verify (visible races rejected; simultaneous unseen races remain possible)";
147
- }
148
- }
149
- function safeTerminalText(value) {
150
- return value.replace(/[\u0000-\u001f\u007f-\u009f]/gu, "?");
151
- }
152
-
153
- export {
154
- SetupPullRequiresUiError,
155
- SyncDecisionRequiredError,
156
- isSyncDecisionRequiredError,
157
- errorMessage,
158
- formatDiff,
159
- formatSnapshotOnlyDiff,
160
- formatPushSummary,
161
- formatPullSummary,
162
- formatRollbackSummary,
163
- countPreservedRemoteFiles,
164
- publicationCapabilityDescription,
165
- safeTerminalText
166
- };
167
- //# sourceMappingURL=chunk-W64NEHXT.ts.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/sync-errors.ts", "../../src/sync-format.ts"],
4
- "sourcesContent": ["import type { SyncDecision } from \"./sync-decision.js\";\n\nexport class SetupPullRequiresUiError extends Error {}\n\nexport class SyncDecisionRequiredError extends Error {\n\treadonly decision: SyncDecision;\n\n\tconstructor(decision: SyncDecision) {\n\t\tsuper(decision.directMessage);\n\t\tthis.name = \"SyncDecisionRequiredError\";\n\t\tthis.decision = decision;\n\t}\n}\n\nexport function isSyncDecisionRequiredError(error: unknown): error is SyncDecisionRequiredError {\n\treturn error instanceof SyncDecisionRequiredError;\n}\n\nexport function errorMessage(error: unknown) {\n\tconst message = error instanceof Error ? error.message : String(error);\n\t// biome-ignore lint/suspicious/noControlCharactersInRegex: Escape untrusted terminal controls.\n\treturn message.replace(/[\\u0000-\\u001f\\u007f-\\u009f]/gu, \"?\");\n}\n", "import { agentDir } from \"./config.js\";\n\nexport { errorMessage } from \"./sync-errors.js\";\n\nimport type { PublicationCapability, RemoteHead } from \"./sync-backend.js\";\nimport { inspectRemoteSelection } from \"./sync-policy.js\";\nimport { fileHashMap } from \"./sync-state.js\";\nimport type { CommonSyncConfig, Snapshot } from \"./types.js\";\n\nexport function formatDiff(local: Snapshot, remote: Snapshot) {\n\tconst localMap = fileHashMap(local);\n\tconst remoteMap = fileHashMap(remote);\n\tconst allPaths = [...new Set([...Object.keys(localMap), ...Object.keys(remoteMap)])].sort();\n\tconst lines = [\n\t\t`local: ${local.files.length} files`,\n\t\t`remote: ${remote.id} (${remote.files.length} files)`,\n\t\t\"\",\n\t];\n\tlet changed = 0;\n\tfor (const filePath of allPaths) {\n\t\tif (!localMap[filePath]) {\n\t\t\tlines.push(`Remote only: ${filePath}`);\n\t\t\tchanged += 1;\n\t\t} else if (!remoteMap[filePath]) {\n\t\t\tlines.push(`Local only: ${filePath}`);\n\t\t\tchanged += 1;\n\t\t} else if (localMap[filePath] !== remoteMap[filePath]) {\n\t\t\tlines.push(`Different: ${filePath}`);\n\t\t\tchanged += 1;\n\t\t}\n\t}\n\tif (changed === 0) lines.push(\"No file differences.\");\n\treturn lines.join(\"\\n\");\n}\n\nexport function formatSnapshotOnlyDiff(title: string, snapshot: Snapshot) {\n\treturn [`${title}: ${snapshot.id}`, ...snapshot.files.map((file) => `Add: ${file.path}`)].join(\n\t\t\"\\n\",\n\t);\n}\n\nexport function formatPushSummary(\n\tconfig: CommonSyncConfig,\n\tdestination: string,\n\tupload: Snapshot,\n\thead: RemoteHead | undefined,\n\tpreservedRemoteFileCount = 0,\n\tremote?: Snapshot,\n) {\n\treturn [\n\t\t`Sync setup: ${safeTerminalText(config.setupName)}`,\n\t\t`Storage location: ${safeTerminalText(destination)}`,\n\t\t`Upload ${upload.files.length} files from ${safeTerminalText(agentDir())}.`,\n\t\t`Sessions: ${upload.syncSessions ? \"included \u2014 may contain private conversations\" : \"not included\"}`,\n\t\thead ? `Remote latest: ${head.snapshotId}` : \"Remote latest: empty\",\n\t\t\"Publication effect: the backend's active head will reference the new immutable snapshot.\",\n\t\t...(remote && inspectRemoteSelection(config.include, remote).kind === \"different\"\n\t\t\t? [\n\t\t\t\t\t\"Included-content policy effect: replace the differing remote selection with this setup's local selection.\",\n\t\t\t\t]\n\t\t\t: []),\n\t\tformatPublicationPreview(remote, upload),\n\t\tpreservedRemoteFileCount > 0\n\t\t\t? `Possible secrets in locally managed files were scanned before this prompt; ${preservedRemoteFileCount} preserved remote file(s) were not rescanned.`\n\t\t\t: \"Possible secrets were scanned before this prompt.\",\n\t].join(\"\\n\");\n}\n\nexport function formatApplyPreview(local: Snapshot, remote: Snapshot) {\n\treturn formatDirectionalChanges(local, remote, {\n\t\tadd: \"Add locally\",\n\t\tupdate: \"Update locally\",\n\t\tremove: \"Remove locally\",\n\t});\n}\n\nexport function formatPullSummary(\n\tconfig: CommonSyncConfig,\n\tdestination: string,\n\tlocal: Snapshot,\n\tremote: Snapshot,\n\tprotectedSessionCount: number,\n) {\n\treturn [\n\t\t`Sync setup: ${safeTerminalText(config.setupName)}`,\n\t\t`Storage location: ${safeTerminalText(destination)}`,\n\t\t`Snapshot: ${safeTerminalText(remote.id)}`,\n\t\t`Sessions: ${remote.syncSessions ? \"included \u2014 may contain private conversations\" : \"not included\"}`,\n\t\t`Protected live sessions: ${protectedSessionCount || \"none\"}`,\n\t\tformatApplyPreview(local, remote),\n\t\t\"A local backup is created before these writes/deletes. The remote active snapshot is unchanged.\",\n\t].join(\"\\n\");\n}\n\nexport function formatRollbackSummary(\n\tconfig: CommonSyncConfig,\n\tdestination: string,\n\tlocal: Snapshot,\n\tremote: Snapshot,\n\trequestedSnapshot: string,\n\tprotectedSessionCount: number,\n) {\n\treturn [\n\t\t`Sync setup: ${safeTerminalText(config.setupName)}`,\n\t\t`Storage location: ${safeTerminalText(destination)}`,\n\t\t`Snapshot: ${safeTerminalText(requestedSnapshot)}`,\n\t\t`Sessions: ${remote.syncSessions ? \"included \u2014 may contain private conversations\" : \"not included\"}`,\n\t\t`Protected live sessions: ${protectedSessionCount || \"none\"}`,\n\t\tformatApplyPreview(local, remote),\n\t\t\"A local backup is created before applying; the backend's active head will change.\",\n\t].join(\"\\n\");\n}\n\nfunction formatPublicationPreview(remote: Snapshot | undefined, upload: Snapshot) {\n\tif (!remote) {\n\t\treturn [\"Remote is empty.\", ...upload.files.map((file) => `Add remotely: ${file.path}`)].join(\n\t\t\t\"\\n\",\n\t\t);\n\t}\n\treturn formatDirectionalChanges(remote, upload, {\n\t\tadd: \"Add remotely\",\n\t\tupdate: \"Update remotely\",\n\t\tremove: \"Remove remotely\",\n\t});\n}\n\nfunction formatDirectionalChanges(\n\tbefore: Snapshot,\n\tafter: Snapshot,\n\tlabels: { add: string; update: string; remove: string },\n) {\n\tconst beforeMap = fileHashMap(before);\n\tconst afterMap = fileHashMap(after);\n\tconst paths = [...new Set([...Object.keys(beforeMap), ...Object.keys(afterMap)])].sort();\n\tconst lines: string[] = [];\n\tfor (const filePath of paths) {\n\t\tif (!beforeMap[filePath]) lines.push(`${labels.add}: ${filePath}`);\n\t\telse if (!afterMap[filePath]) lines.push(`${labels.remove}: ${filePath}`);\n\t\telse if (beforeMap[filePath] !== afterMap[filePath])\n\t\t\tlines.push(`${labels.update}: ${filePath}`);\n\t}\n\tif (lines.length === 0) lines.push(\"No file changes.\");\n\treturn lines.join(\"\\n\");\n}\n\nexport function countPreservedRemoteFiles(local: Snapshot, upload: Snapshot) {\n\tconst localPaths = new Set(local.files.map((file) => file.path));\n\treturn upload.files.filter((file) => !localPaths.has(file.path)).length;\n}\n\nexport function publicationCapabilityDescription(capability: PublicationCapability) {\n\tswitch (capability) {\n\t\tcase \"lease-protected\":\n\t\t\treturn \"lease-protected (exact expected-ref update)\";\n\t\tcase \"atomic-conditional\":\n\t\t\treturn \"atomic-conditional (verified atomic precondition)\";\n\t\tcase \"conditional-required\":\n\t\t\treturn \"conditional-required (read-only until atomic preconditions are verified)\";\n\t\tcase \"read-check-write-verify\":\n\t\t\treturn \"read-check-write-verify (visible races rejected; simultaneous unseen races remain possible)\";\n\t}\n}\n\nexport function safeTerminalText(value: string) {\n\t// biome-ignore lint/suspicious/noControlCharactersInRegex: Escape untrusted terminal controls.\n\treturn value.replace(/[\\u0000-\\u001f\\u007f-\\u009f]/gu, \"?\");\n}\n\nexport function redact(value: string) {\n\treturn value.length <= 8 ? \"configured\" : `${value.slice(0, 4)}\u2026${value.slice(-4)}`;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;AAEO,IAAM,2BAAN,cAAuC,MAAM;AAAC;AAE9C,IAAM,4BAAN,cAAwC,MAAM;AAAA,EAC3C;AAAA,EAET,YAAY,UAAwB;AACnC,UAAM,SAAS,aAAa;AAC5B,SAAK,OAAO;AACZ,SAAK,WAAW;AAAA,EACjB;AACD;AAEO,SAAS,4BAA4B,OAAoD;AAC/F,SAAO,iBAAiB;AACzB;AAEO,SAAS,a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AA,IACnB,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,EACT;AACD;AAEO,SAAS,iBAAiB,OAAe;AAE/C,SAAO,MAAM,QAAQ,kCAAkC,GAAG;AAC3D;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/paths.ts", "../../src/sync-policy.ts"],
4
- "sourcesContent": ["import path from \"node:path\";\n\nexport function isDeniedPath(relativePath: string) {\n\tconst normalized = toPosix(relativePath);\n\tconst lower = normalized.toLowerCase();\n\tconst segments = lower.split(\"/\");\n\tconst base = path.posix.basename(lower);\n\treturn (\n\t\tsegments.includes(\"node_modules\") ||\n\t\tsegments.includes(\".git\") ||\n\t\tsegments.includes(\".pisync\") ||\n\t\tsegments.includes(\"pi-sync\") ||\n\t\tsegments.includes(\".pi-sync-state-migration.lock\") ||\n\t\tbase === \".env\" ||\n\t\tbase.startsWith(\".env.\") ||\n\t\tbase.endsWith(\".env\") ||\n\t\tbase.includes(\"secret\") ||\n\t\tbase.includes(\"token\") ||\n\t\tbase === \"pi-sync.json\" ||\n\t\tbase.startsWith(\"pi-sync.json.\") ||\n\t\tbase.startsWith(\".pi-sync.json.\") ||\n\t\tbase === \"pi-sync.local.json\" ||\n\t\tbase.startsWith(\"pi-sync.local.json.\") ||\n\t\tbase.startsWith(\".pi-sync.local.json.\")\n\t);\n}\n\nexport function isPathInside(parent: string, child: string) {\n\tconst relative = path.relative(path.resolve(parent), path.resolve(child));\n\treturn relative === \"\" || (!relative.startsWith(\"..\") && !path.isAbsolute(relative));\n}\n\nexport function safeJoin(root: string, relativePath: string) {\n\tconst target = path.resolve(root, relativePath);\n\tassertWithinRoot(root, target, relativePath);\n\treturn target;\n}\n\nexport function assertWithinRoot(root: string, target: string, label = target) {\n\tconst resolvedRoot = path.resolve(root);\n\tconst resolvedTarget = path.resolve(target);\n\tif (resolvedTarget !== resolvedRoot && !resolvedTarget.startsWith(`${resolvedRoot}${path.sep}`)) {\n\t\tthrow new Error(`Unsafe path in snapshot: ${label}`);\n\t}\n}\n\nexport function encodeKey(key: string) {\n\treturn key.split(\"/\").map(encodeURIComponent).join(\"/\");\n}\n\nexport function posixJoin(...parts: string[]) {\n\treturn parts\n\t\t.map((part) => trimSlashes(part))\n\t\t.filter(Boolean)\n\t\t.join(\"/\");\n}\n\nexport function parentPaths(relativePath: string) {\n\tconst results: string[] = [];\n\tlet index = relativePath.lastIndexOf(\"/\");\n\twhile (index > 0) {\n\t\tresults.push(relativePath.slice(0, index));\n\t\tindex = relativePath.lastIndexOf(\"/\", index - 1);\n\t}\n\treturn results;\n}\n\nexport function toPosix(value: string) {\n\treturn value.split(path.sep).join(\"/\");\n}\n\nfunction trimSlashes(value: string) {\n\treturn value.replace(/^\\/+|\\/+$/g, \"\");\n}\n\nexport function safeName(value: string) {\n\treturn value.replace(/[^A-Za-z0-9._-]/g, \"_\");\n}\n", "import path from \"node:path\";\nimport { isDeniedPath, toPosix } from \"./paths.js\";\nimport type { Snapshot, SnapshotSelection } from \"./types.js\";\n\nexport const BUILT_IN_SYNC_ROOTS = [\n\t\"settings.json\",\n\t\"keybindings.json\",\n\t\"models.json\",\n\t\"AGENTS.md\",\n\t\"APPEND_SYSTEM.md\",\n\t\"skills\",\n\t\"prompts\",\n\t\"themes\",\n\t\"extensions\",\n] as const;\n\nexport const DEFAULT_SYNC_INCLUDE = [...BUILT_IN_SYNC_ROOTS] as const;\nexport type BuiltInSyncFile = (typeof BUILT_IN_SYNC_ROOTS)[number];\nconst SNAPSHOT_SELECTION_VERSION = 1;\nconst MAX_SYNC_INCLUDE_ITEMS = 1_024;\nconst MAX_SYNC_INCLUDE_PATH_BYTES = 4_096;\nconst MAX_SYNC_INCLUDE_TOTAL_BYTES = 256 * 1_024;\n\ninterface IncludePathNode {\n\tselected?: string;\n\tchildren: Map<string, IncludePathNode>;\n}\n\nconst BUILT_IN_BY_LOWER = new Map<string, BuiltInSyncFile>(\n\tBUILT_IN_SYNC_ROOTS.map((fileName) => [fileName.toLowerCase(), fileName]),\n);\nconst TOP_LEVEL_FILE_PATHS = new Map<string, string>(\n\tBUILT_IN_SYNC_ROOTS.filter((fileName) => fileName.includes(\".\")).map((fileName) => [\n\t\tfileName.toLowerCase(),\n\t\tfileName,\n\t]),\n);\nconst TOP_LEVEL_DIRS = new Set<string>(\n\tBUILT_IN_SYNC_ROOTS.filter((fileName) => !fileName.includes(\".\")),\n);\nconst RESERVED_TOP_LEVEL_NAMES = new Set<string>([...BUILT_IN_BY_LOWER.keys(), \"sessions\"]);\n\nexport function normalizeSyncInclude(value: unknown): string[] {\n\tif (!Array.isArray(value)) {\n\t\tthrow new Error(\"Invalid pi-sync settings: sync.include must be an array.\");\n\t}\n\tif (value.length > MAX_SYNC_INCLUDE_ITEMS) {\n\t\tthrow new Error(\n\t\t\t`Invalid pi-sync settings: sync.include has too many items; limit: ${MAX_SYNC_INCLUDE_ITEMS}.`,\n\t\t);\n\t}\n\tconst result: string[] = [];\n\tconst seen = new Set<string>();\n\tconst pathRoot: IncludePathNode = { children: new Map() };\n\tlet totalBytes = 0;\n\tfor (const item of value) {\n\t\tif (typeof item !== \"string\") {\n\t\t\tthrow new Error(\"Invalid pi-sync settings: sync.include items must be strings.\");\n\t\t}\n\t\tconst itemBytes = Buffer.byteLength(item, \"utf8\");\n\t\tif (itemBytes > MAX_SYNC_INCLUDE_PATH_BYTES) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid pi-sync settings: sync.include item is too long; limit: ${MAX_SYNC_INCLUDE_PATH_BYTES} bytes.`,\n\t\t\t);\n\t\t}\n\t\ttotalBytes += itemBytes;\n\t\tif (totalBytes > MAX_SYNC_INCLUDE_TOTAL_BYTES) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid pi-sync settings: sync.include is too large; limit: ${MAX_SYNC_INCLUDE_TOTAL_BYTES} bytes.`,\n\t\t\t);\n\t\t}\n\t\tconst trimmed = item.trim();\n\t\tconst builtIn = BUILT_IN_BY_LOWER.get(trimmed.toLowerCase());\n\t\tconst normalized = builtIn ?? (trimmed.toLowerCase() === \"sessions\" ? \"sessions\" : trimmed);\n\t\tif (!builtIn && normalized !== \"sessions\") validateAgentRelativeInclude(normalized);\n\t\tconst identity = normalized.toLowerCase();\n\t\tif (seen.has(identity)) {\n\t\t\tthrow new Error(`Invalid pi-sync settings: duplicate sync.include item: ${item}`);\n\t\t}\n\t\taddIncludePath(pathRoot, identity, item);\n\t\tseen.add(identity);\n\t\tresult.push(normalized);\n\t}\n\treturn result;\n}\n\nfunction addIncludePath(root: IncludePathNode, identity: string, source: string) {\n\tlet node = root;\n\tfor (const segment of identity.split(\"/\")) {\n\t\tif (node.selected !== undefined) throwOverlappingInclude(source);\n\t\tlet child = node.children.get(segment);\n\t\tif (!child) {\n\t\t\tchild = { children: new Map() };\n\t\t\tnode.children.set(segment, child);\n\t\t}\n\t\tnode = child;\n\t}\n\tif (node.children.size > 0) throwOverlappingInclude(source);\n\tnode.selected = identity;\n}\n\nfunction throwOverlappingInclude(item: string): never {\n\tthrow new Error(\n\t\t`Invalid pi-sync settings: overlapping sync.include items are ambiguous: ${item}`,\n\t);\n}\n\nfunction validateAgentRelativeInclude(value: string) {\n\tconst normalized = toPosix(value);\n\tconst topLevel = normalized.split(\"/\")[0]?.toLowerCase();\n\tif (\n\t\t!normalized ||\n\t\tnormalized === \".\" ||\n\t\tnormalized === \"..\" ||\n\t\tnormalized.startsWith(\"../\") ||\n\t\tpath.posix.isAbsolute(normalized) ||\n\t\tnormalized.includes(\"\\\\\") ||\n\t\tpath.posix.normalize(normalized) !== normalized ||\n\t\t// biome-ignore lint/suspicious/noControlCharactersInRegex: Include paths cannot contain controls.\n\t\t/[\\u0000-\\u001f\\u007f-\\u009f]/u.test(normalized)\n\t) {\n\t\tthrow new Error(\n\t\t\t`Invalid pi-sync settings: sync.include item must be a safe agent-relative path: ${value}`,\n\t\t);\n\t}\n\tif (isDeniedPath(normalized)) {\n\t\tthrow new Error(`Invalid pi-sync settings: ${value} cannot be synced.`);\n\t}\n\tif (topLevel && RESERVED_TOP_LEVEL_NAMES.has(topLevel)) {\n\t\tthrow new Error(\n\t\t\t`Invalid pi-sync settings: use the canonical ${topLevel} root instead of a nested sync.include path.`,\n\t\t);\n\t}\n}\n\nexport function portableSnapshotSelection(value: unknown): SnapshotSelection {\n\tconst selection = value as Partial<SnapshotSelection> | null;\n\tif (\n\t\t!selection ||\n\t\ttypeof selection !== \"object\" ||\n\t\tArray.isArray(selection) ||\n\t\tselection.version !== SNAPSHOT_SELECTION_VERSION ||\n\t\t!Object.hasOwn(selection, \"include\") ||\n\t\tObject.keys(selection).some((key) => key !== \"version\" && key !== \"include\")\n\t) {\n\t\tthrow new Error(\"Invalid snapshot selection policy.\");\n\t}\n\treturn {\n\t\tversion: SNAPSHOT_SELECTION_VERSION,\n\t\tinclude: normalizeSyncInclude(selection.include),\n\t};\n}\n\nexport function snapshotSelectionInclude(snapshot: Pick<Snapshot, \"selection\">) {\n\treturn snapshot.selection === undefined\n\t\t? undefined\n\t\t: portableSnapshotSelection(snapshot.selection).include;\n}\n\nexport function selectionForSnapshot(include: unknown): SnapshotSelection {\n\treturn { version: SNAPSHOT_SELECTION_VERSION, include: normalizeSyncInclude(include) };\n}\n\nexport function sameSyncInclude(left: unknown, right: unknown) {\n\tconst normalizedLeft = normalizeSyncInclude(left);\n\tconst normalizedRight = normalizeSyncInclude(right);\n\treturn (\n\t\tnormalizedLeft.length === normalizedRight.length &&\n\t\tnormalizedLeft.every((item, index) => item === normalizedRight[index])\n\t);\n}\n\nexport function compareSyncInclude(local: unknown, remote: unknown) {\n\tconst localInclude = normalizeSyncInclude(local);\n\tconst remoteInclude = normalizeSyncInclude(remote);\n\tconst localSet = new Set(localInclude);\n\tconst remoteSet = new Set(remoteInclude);\n\treturn {\n\t\tsame: sameSyncInclude(localInclude, remoteInclude),\n\t\tremoteOnly: remoteInclude.filter((item) => !localSet.has(item)),\n\t\tlocalOnly: localInclude.filter((item) => !remoteSet.has(item)),\n\t};\n}\n\nexport type RemoteSelectionState =\n\t| { kind: \"legacy\"; discovered: string[] }\n\t| { kind: \"same\"; include: string[] }\n\t| {\n\t\t\tkind: \"different\";\n\t\t\tinclude: string[];\n\t\t\tremoteOnly: string[];\n\t\t\tlocalOnly: string[];\n\t };\n\nexport function inspectRemoteSelection(\n\tlocalInclude: unknown,\n\tsnapshot: Pick<Snapshot, \"selection\" | \"files\">,\n): RemoteSelectionState {\n\tconst remoteInclude = snapshotSelectionInclude(snapshot);\n\tif (!remoteInclude) {\n\t\treturn { kind: \"legacy\", discovered: discoverLegacySnapshotInclude(snapshot) };\n\t}\n\tconst comparison = compareSyncInclude(localInclude, remoteInclude);\n\treturn comparison.same\n\t\t? { kind: \"same\", include: remoteInclude }\n\t\t: { kind: \"different\", include: remoteInclude, ...comparison };\n}\n\nexport interface RemoteSelectionDecision {\n\tsetupName: string;\n\tconfigIdentity: string;\n\tlocalInclude: readonly string[];\n\tremoteInclude: readonly string[];\n}\n\nexport class RemoteSelectionMismatchError extends Error {\n\treadonly decision: RemoteSelectionDecision;\n\treadonly setupName: string;\n\treadonly localInclude: string[];\n\treadonly remoteInclude: string[];\n\n\tconstructor(\n\t\tsetupName: string,\n\t\tlocalInclude: unknown,\n\t\tremoteInclude: unknown,\n\t\tconfigIdentity = JSON.stringify([setupName, normalizeSyncInclude(localInclude)]),\n\t) {\n\t\tconst local = normalizeSyncInclude(localInclude);\n\t\tconst remote = normalizeSyncInclude(remoteInclude);\n\t\tsuper(formatRemoteSelectionMismatch(setupName, local, remote));\n\t\tthis.name = \"RemoteSelectionMismatchError\";\n\t\tthis.setupName = setupName;\n\t\tthis.localInclude = local;\n\t\tthis.remoteInclude = remote;\n\t\tthis.decision = {\n\t\t\tsetupName,\n\t\t\tconfigIdentity,\n\t\t\tlocalInclude: [...local],\n\t\t\tremoteInclude: [...remote],\n\t\t};\n\t}\n}\n\nexport function remoteSelectionMismatch(\n\tconfig: { setupName: string; include: unknown },\n\tremoteInclude: unknown,\n\tconfigIdentity?: string,\n) {\n\treturn new RemoteSelectionMismatchError(\n\t\tconfig.setupName,\n\t\tconfig.include,\n\t\tremoteInclude,\n\t\tconfigIdentity,\n\t);\n}\n\nexport function formatRemoteSelectionMismatch(\n\tsetupName: string,\n\tlocalInclude: readonly string[],\n\tremoteInclude: readonly string[],\n) {\n\tconst comparison = compareSyncInclude(localInclude, remoteInclude);\n\tconst lines = [\n\t\t`Synced content differs for sync setup \u201C${stripTerminalControls(setupName)}\u201D.`,\n\t\t`Remote-only: ${comparison.remoteOnly.join(\", \") || \"none\"}`,\n\t\t`This-device-only: ${comparison.localOnly.join(\", \") || \"none\"}`,\n\t];\n\tif (comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0) {\n\t\tlines.push(\n\t\t\t\"Only ordering differs.\",\n\t\t\t`Remote order: ${remoteInclude.join(\", \") || \"none\"}`,\n\t\t\t`This device order: ${localInclude.join(\", \") || \"none\"}`,\n\t\t);\n\t}\n\tlines.push(\"Run /sync in TUI to review both content lists and choose what happens next.\");\n\treturn lines.join(\"\\n\");\n}\n\nfunction stripTerminalControls(value: string) {\n\t// biome-ignore lint/suspicious/noControlCharactersInRegex: Escape untrusted terminal controls.\n\treturn value.replace(/[\\u0000-\\u001f\\u007f-\\u009f]/gu, \"?\");\n}\n\nexport function discoverLegacySnapshotInclude(snapshot: Pick<Snapshot, \"files\">) {\n\tconst builtIns = new Set<BuiltInSyncFile>();\n\tconst custom = new Set<string>();\n\tlet sessions = false;\n\tfor (const file of snapshot.files) {\n\t\tconst normalized = toPosix(file.path);\n\t\tif (\n\t\t\t!normalized ||\n\t\t\tfile.path.includes(\"\\\\\") ||\n\t\t\tnormalized.length > 4096 ||\n\t\t\tnormalized.startsWith(\"../\") ||\n\t\t\tpath.posix.isAbsolute(normalized) ||\n\t\t\tpath.posix.normalize(normalized) !== normalized ||\n\t\t\t// biome-ignore lint/suspicious/noControlCharactersInRegex: Ignore unsafe legacy paths.\n\t\t\t/[\\u0000-\\u001f\\u007f-\\u009f]/u.test(normalized) ||\n\t\t\tisDeniedPath(normalized)\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst [topLevel, ...rest] = normalized.split(\"/\");\n\t\tif (!topLevel) continue;\n\t\tif (topLevel === \"sessions\" && rest.length > 0) {\n\t\t\tsessions = true;\n\t\t\tcontinue;\n\t\t}\n\t\tconst builtIn = BUILT_IN_BY_LOWER.get(topLevel.toLowerCase());\n\t\tif (\n\t\t\tbuiltIn &&\n\t\t\t((TOP_LEVEL_DIRS.has(builtIn) && rest.length > 0) ||\n\t\t\t\t(!TOP_LEVEL_DIRS.has(builtIn) && rest.length === 0))\n\t\t) {\n\t\t\tbuiltIns.add(builtIn);\n\t\t\tcontinue;\n\t\t}\n\t\tif (isSafeCustomIncludePath(topLevel)) custom.add(topLevel);\n\t}\n\treturn [\n\t\t...BUILT_IN_SYNC_ROOTS.filter((item) => builtIns.has(item)),\n\t\t...[...custom].sort((left, right) => left.localeCompare(right)),\n\t\t...(sessions ? [\"sessions\"] : []),\n\t];\n}\n\nexport function syncIncludeSelection(value: unknown) {\n\tconst include = normalizeSyncInclude(value);\n\tconst builtIns = include.filter((item): item is BuiltInSyncFile =>\n\t\tBUILT_IN_BY_LOWER.has(item.toLowerCase()),\n\t);\n\tconst custom = include.filter(\n\t\t(item) => item !== \"sessions\" && !BUILT_IN_BY_LOWER.has(item.toLowerCase()),\n\t);\n\treturn { include, builtIns, custom, sessions: include.includes(\"sessions\") };\n}\n\nexport function customIncludePathsByLower(value: unknown) {\n\treturn new Map(\n\t\tsyncIncludeSelection(value).custom.map((relativePath) => [\n\t\t\trelativePath.toLowerCase(),\n\t\t\trelativePath,\n\t\t]),\n\t);\n}\n\nexport interface SyncSelectionConfig {\n\tinclude?: unknown;\n\tsyncFiles?: unknown;\n\tsyncSessions?: boolean;\n\textraFiles?: unknown;\n}\n\nexport function includeFromSelectionConfig(config: SyncSelectionConfig) {\n\tif (config.include !== undefined) return normalizeSyncInclude(config.include);\n\treturn [\n\t\t...normalizeSyncFiles(config.syncFiles),\n\t\t...normalizeExtraFiles(config.extraFiles),\n\t\t...(config.syncSessions ? [\"sessions\"] : []),\n\t];\n}\n\nexport function isConfiguredSnapshotPath(\n\trelativePath: string,\n\tconfig: SyncSelectionConfig,\n\t_legacyExtraFiles?: Set<string>,\n) {\n\tconst normalized = toPosix(relativePath);\n\tconst selection = syncIncludeSelection(includeFromSelectionConfig(config));\n\tif (normalized.startsWith(\"sessions/\")) return selection.sessions;\n\tconst lower = normalized.toLowerCase();\n\tif (!normalized.includes(\"/\")) {\n\t\tconst builtIn = BUILT_IN_BY_LOWER.get(lower);\n\t\tif (builtIn) return selection.builtIns.includes(builtIn) && !TOP_LEVEL_DIRS.has(builtIn);\n\t}\n\tconst topLevel = normalized.slice(0, normalized.indexOf(\"/\"));\n\tif (selection.builtIns.includes(topLevel as BuiltInSyncFile) && TOP_LEVEL_DIRS.has(topLevel)) {\n\t\treturn true;\n\t}\n\treturn selection.custom.some((candidate) => {\n\t\tconst candidateLower = candidate.toLowerCase();\n\t\treturn lower === candidateLower || lower.startsWith(`${candidateLower}/`);\n\t});\n}\n\nexport function canonicalSnapshotPathForConfig(\n\trelativePath: string,\n\tincludePaths: Map<string, string>,\n) {\n\tconst normalized = toPosix(relativePath);\n\tconst lower = normalized.toLowerCase();\n\treturn TOP_LEVEL_FILE_PATHS.get(lower) ?? includePaths.get(lower) ?? normalized;\n}\n\nexport function isPreservableUnmanagedSnapshotPath(relativePath: string) {\n\tconst normalized = toPosix(relativePath);\n\tif (!normalized || isDeniedPath(normalized)) return false;\n\tif (normalized.startsWith(\"sessions/\")) return normalized.endsWith(\".jsonl\");\n\tif (!normalized.includes(\"/\")) {\n\t\tconst lower = normalized.toLowerCase();\n\t\treturn TOP_LEVEL_FILE_PATHS.has(lower) || !RESERVED_TOP_LEVEL_NAMES.has(lower);\n\t}\n\treturn true;\n}\n\nexport function isSafeCustomIncludePath(relativePath: string) {\n\ttry {\n\t\tvalidateAgentRelativeInclude(relativePath);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport function isBuiltInTopLevelFile(fileName: string) {\n\treturn TOP_LEVEL_FILE_PATHS.has(path.posix.basename(fileName).toLowerCase());\n}\n\n/** Compatibility projection for backend-neutral output while callers move to sync.include. */\nexport function normalizeSyncFiles(value: unknown): BuiltInSyncFile[] {\n\tif (value === undefined) return [...DEFAULT_SYNC_INCLUDE];\n\tif (Array.isArray(value)) {\n\t\treturn normalizeSyncInclude(value).filter((item): item is BuiltInSyncFile =>\n\t\t\tBUILT_IN_BY_LOWER.has(item.toLowerCase()),\n\t\t);\n\t}\n\tthrow new Error(\"Invalid pi-sync settings: expected an include array.\");\n}\n\n/** Compatibility projection for old rendering helpers; v3 persistence never writes this split field. */\nexport function normalizeExtraFiles(value: unknown) {\n\tif (!Array.isArray(value)) return [];\n\treturn value.filter(\n\t\t(item): item is string => typeof item === \"string\" && isSafeCustomIncludePath(item),\n\t);\n}\n\nexport const extraFilePathsByLower = customIncludePathsByLower;\nexport const isSafeExtraFileName = isSafeCustomIncludePath;\nexport const selectedSyncFileSet = (value: unknown) => new Set(normalizeSyncFiles(value));\n"],
5
- "mappings": ";;;;AAAA,OAAO,UAAU;AAEV,SAAS,aAAa,cAAsB;AAClD,QAAM,aAAa,QAAQ,YAAY;AACvC,QAAM,QAAQ,WAAW,YAAY;AACrC,QAAM,WAAW,MAAM,MAAM,GAAG;AAChC,QAAM,OAAO,KAAK,MAAM,SAAS,KAAK;AACtC,SACC,SAAS,SAAS,cAAc,KAChC,SAAS,SAAS,MAAM,KACxB,SAAS,SAAS,SAAS,KAC3B,SAAS,SAAS,SAAS,KAC3B,SAAS,SAAS,+BAA+B,KACjD,SAAS,UACT,KAAK,WAAW,OAAO,KACvB,KAAK,SAAS,MAAM,KACpB,KAAK,SAAS,QAAQ,KACtB,KA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AW,YAAY;AACrC,WAAO,qBAAqB,IAAI,KAAK,KAAK,CAAC,yBAAyB,IAAI,KAAK;AAAA,EAC9E;AACA,SAAO;AACR;AAEO,SAAS,wBAAwB,cAAsB;AAC7D,MAAI;AACH,iCAA6B,YAAY;AACzC,WAAO;AAAA,EACR,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAOO,SAAS,mBAAmB,OAAmC;AACrE,MAAI,UAAU,OAAW,QAAO,CAAC,GAAG,oBAAoB;AACxD,MAAI,MAAM,QAAQ,KAAK,GAAG;AACzB,WAAO,qBAAqB,KAAK,EAAE;AAAA,MAAO,CAAC,SAC1C,kBAAkB,IAAI,KAAK,YAAY,CAAC;AAAA,IACzC;AAAA,EACD;AACA,QAAM,IAAI,MAAM,sDAAsD;AACvE;AAGO,SAAS,oBAAoB,OAAgB;AACnD,MAAI,CAAC,MAAM,QAAQ,KAAK,EAAG,QAAO,CAAC;AACnC,SAAO,MAAM;AAAA,IACZ,CAAC,SAAyB,OAAO,SAAS,YAAY,wBAAwB,IAAI;AAAA,EACnF;AACD;",
6
- "names": ["path", "path"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/file-selection.ts"],
4
- "sourcesContent": ["import fs from \"node:fs/promises\";\nimport type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, runMenu } from \"@narumitw/pi-tui-kit\";\nimport { agentDir, loadConfig, localConfigPath } from \"./config.js\";\nimport { updateSyncSetup } from \"./settings-management.js\";\nimport {\n\tBUILT_IN_SYNC_ROOTS,\n\tisSafeCustomIncludePath,\n\tnormalizeSyncInclude,\n\tsyncIncludeSelection,\n} from \"./sync-policy.js\";\n\nconst BUILT_IN_PREFIX = \"builtin:\";\nconst CUSTOM_PREFIX = \"custom:\";\nconst SESSIONS_ID = \"sessions\";\nconst ADD_CUSTOM_ID = \"add-custom\";\n\ninterface SelectionDraft {\n\tbuiltIns: Set<string>;\n\tcustom: Set<string>;\n\tsessions: boolean;\n}\n\nexport async function showFileSelection(\n\tctx: ExtensionCommandContext,\n\tsetupName?: string,\n\tsignal?: AbortSignal,\n) {\n\tconst config = await loadConfig(setupName);\n\tif (signal?.aborted) return;\n\tconst selection = syncIncludeSelection(config.include);\n\tconst original: SelectionDraft = {\n\t\tbuiltIns: new Set(selection.builtIns),\n\t\tcustom: new Set(selection.custom),\n\t\tsessions: selection.sessions,\n\t};\n\tconst draft = cloneDraft(original);\n\tconst customCandidates = await listCustomCandidates(draft.custom);\n\n\tif (ctx.mode !== \"tui\") {\n\t\tctx.ui.notify(\n\t\t\t[\n\t\t\t\t`pi-sync included content for sync setup ${safeTerminalText(config.setupName)}:`,\n\t\t\t\t`include: ${config.include.map(safeTerminalText).join(\", \") || \"none\"}`,\n\t\t\t\t`Edit sync.include in ${safeTerminalText(localConfigPath())}.`,\n\t\t\t].join(\"\\n\"),\n\t\t\t\"info\",\n\t\t);\n\t\treturn;\n\t}\n\n\twhile (!signal?.aborted) {\n\t\tawait showDraftEditor(ctx, config.setupName, draft, customCandidates, signal);\n\t\tif (signal?.aborted || sameDraft(original, draft)) return;\n\t\tconst choice = await showDraftReview(ctx, original, draft, signal);\n\t\tif (signal?.aborted) return;\n\t\tif (choice === \"Continue editing\") continue;\n\t\tif (choice !== \"Save changes\") {\n\t\t\tctx.ui.notify(\"Included-content changes discarded.\", \"info\");\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tif (!original.sessions && draft.sessions) {\n\t\t\t\tconst acknowledged = await ctx.ui.confirm(\n\t\t\t\t\t\"Include session conversations?\",\n\t\t\t\t\t\"Session JSONL may contain prompts, tool output, file paths, images, and secrets. Continue only with storage you trust.\",\n\t\t\t\t\t{ signal },\n\t\t\t\t);\n\t\t\t\tif (signal?.aborted) return;\n\t\t\t\tif (!acknowledged) {\n\t\t\t\t\tctx.ui.notify(\"Session inclusion was not saved.\", \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst include = [\n\t\t\t\t...BUILT_IN_SYNC_ROOTS.filter((candidate) => draft.builtIns.has(candidate)),\n\t\t\t\t...draft.custom,\n\t\t\t\t...(draft.sessions ? [\"sessions\"] : []),\n\t\t\t];\n\t\t\tif (signal?.aborted) return;\n\t\t\tawait updateSyncSetup(\n\t\t\t\tconfig.setupName,\n\t\t\t\t(setup) => ({\n\t\t\t\t\t...setup,\n\t\t\t\t\tsync: { ...setup.sync, include },\n\t\t\t\t}),\n\t\t\t\t{ expectedInclude: config.include, signal },\n\t\t\t);\n\t\t\tif (signal?.aborted) return;\n\t\t\tctx.ui.notify(\n\t\t\t\t`Saved included content for sync setup \u201C${safeTerminalText(config.setupName)}\u201D. It applies to the next manual or automatic sync.`,\n\t\t\t\t\"info\",\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (signal?.aborted) return;\n\t\t\tctx.ui.notify(\n\t\t\t\t`Could not save pi-sync file selection: ${safeTerminalText(error instanceof Error ? error.message : String(error))}`,\n\t\t\t\t\"error\",\n\t\t\t);\n\t\t}\n\t\treturn;\n\t}\n}\n\nasync function showDraftEditor(\n\tctx: ExtensionCommandContext,\n\tsetupName: string,\n\tdraft: SelectionDraft,\n\tcustomCandidates: string[],\n\tsignal?: AbortSignal,\n) {\n\tconst menu = defineMenu<undefined, \"editor\", \"toggle\" | \"addCustom\", ExtensionCommandContext>({\n\t\tstart: \"editor\",\n\t\tscreens: {\n\t\t\teditor: () => ({\n\t\t\t\tkind: \"multiSelect\",\n\t\t\t\ttitle: `Included Content \u00B7 ${safeTerminalText(setupName)}`,\n\t\t\t\tlines: [\"Draft only \u00B7 leaving this screen opens Save, Discard, or Continue editing.\"],\n\t\t\t\tviewportSize: 12,\n\t\t\t\titems: [\n\t\t\t\t\t...BUILT_IN_SYNC_ROOTS.map((relativePath) => ({\n\t\t\t\t\t\tid: `${BUILT_IN_PREFIX}${relativePath}`,\n\t\t\t\t\t\tlabel: relativePath,\n\t\t\t\t\t\tdescription: relativePath.includes(\".\")\n\t\t\t\t\t\t\t? `Sync the top-level ${relativePath} file when present.`\n\t\t\t\t\t\t\t: `Recursively sync every safe file under ${relativePath}/.`,\n\t\t\t\t\t\tselected: draft.builtIns.has(relativePath),\n\t\t\t\t\t})),\n\t\t\t\t\t...customCandidates.map((relativePath) => ({\n\t\t\t\t\t\tid: `${CUSTOM_PREFIX}${relativePath}`,\n\t\t\t\t\t\tlabel: safeTerminalText(relativePath),\n\t\t\t\t\t\tdescription: \"Additional safe agent-relative file or directory.\",\n\t\t\t\t\t\tselected: draft.custom.has(relativePath),\n\t\t\t\t\t})),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: SESSIONS_ID,\n\t\t\t\t\t\tlabel: \"sessions\",\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"Session JSONL may contain prompts, tool output, paths, images, and secrets. Sync only to storage you trust.\",\n\t\t\t\t\t\tselected: draft.sessions,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\taction: \"toggle\",\n\t\t\t\tactions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: ADD_CUSTOM_ID,\n\t\t\t\t\t\tlabel: \"Add custom path\u2026\",\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"Include an agent-relative file or directory even when it exists only remotely.\",\n\t\t\t\t\t\taction: \"addCustom\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\thint: \"close\",\n\t\t\t\tdoneLabel: \"Review changes\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\ttoggle: async ({ itemId, selected }) => {\n\t\t\t\tupdateDraft(draft, itemId, selected === true);\n\t\t\t\treturn { kind: \"stay\" };\n\t\t\t},\n\t\t\taddCustom: async ({ ctx: actionCtx, signal: actionSignal }) => {\n\t\t\t\tconst entered = await actionCtx.ui.input(\n\t\t\t\t\t\"Add included content\",\n\t\t\t\t\t\"Agent-relative path, for example custom.toml or snippets\",\n\t\t\t\t\t{ signal: actionSignal },\n\t\t\t\t);\n\t\t\t\tif (actionSignal.aborted) return { kind: \"stay\" };\n\t\t\t\tconst requested = entered?.trim();\n\t\t\t\tif (!requested) return { kind: \"stay\" };\n\t\t\t\tconst existing = customCandidates.find(\n\t\t\t\t\t(candidate) => candidate.toLowerCase() === requested.toLowerCase(),\n\t\t\t\t);\n\t\t\t\tconst relativePath = existing ?? requested;\n\t\t\t\tif (draft.custom.has(relativePath)) return { kind: \"stay\" };\n\t\t\t\ttry {\n\t\t\t\t\tif (!isSafeCustomIncludePath(relativePath)) {\n\t\t\t\t\t\tthrow new Error(\"Enter a safe agent-relative file or directory path.\");\n\t\t\t\t\t}\n\t\t\t\t\tnormalizeSyncInclude([\n\t\t\t\t\t\t...draft.builtIns,\n\t\t\t\t\t\t...draft.custom,\n\t\t\t\t\t\t...(draft.sessions ? [\"sessions\"] : []),\n\t\t\t\t\t\trelativePath,\n\t\t\t\t\t]);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (actionSignal.aborted) return { kind: \"stay\" };\n\t\t\t\t\tactionCtx.ui.notify(\n\t\t\t\t\t\t`Could not add included content: ${safeTerminalText(error instanceof Error ? error.message : String(error))}`,\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t);\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\tif (!existing) {\n\t\t\t\t\tcustomCandidates.push(relativePath);\n\t\t\t\t\tcustomCandidates.sort((left, right) => left.localeCompare(right));\n\t\t\t\t}\n\t\t\t\tdraft.custom.add(relativePath);\n\t\t\t\treturn { kind: \"stay\" };\n\t\t\t},\n\t\t},\n\t});\n\tawait runMenu(ctx, menu, {\n\t\tgetState: () => undefined,\n\t\tsignal,\n\t\tisCurrent: () => !signal?.aborted,\n\t});\n}\n\nasync function showDraftReview(\n\tctx: ExtensionCommandContext,\n\toriginal: SelectionDraft,\n\tdraft: SelectionDraft,\n\tsignal?: AbortSignal,\n) {\n\tlet choice: \"Save changes\" | \"Discard changes\" | \"Continue editing\" | undefined;\n\tconst menu = defineMenu<undefined, \"review\", \"choose\", ExtensionCommandContext>({\n\t\tstart: \"review\",\n\t\tscreens: {\n\t\t\treview: () => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: \"Review included-content changes\",\n\t\t\t\tlines: formatDraftPreview(original, draft).split(\"\\n\").slice(2),\n\t\t\t\titems: [\n\t\t\t\t\t{ id: \"save\", label: \"Save changes\", action: \"choose\" },\n\t\t\t\t\t{ id: \"discard\", label: \"Discard changes\", action: \"choose\" },\n\t\t\t\t\t{ id: \"continue\", label: \"Continue editing\", action: \"choose\" },\n\t\t\t\t],\n\t\t\t\thint: \"close\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\tchoose: async ({ itemId }) => {\n\t\t\t\tchoice =\n\t\t\t\t\titemId === \"save\"\n\t\t\t\t\t\t? \"Save changes\"\n\t\t\t\t\t\t: itemId === \"continue\"\n\t\t\t\t\t\t\t? \"Continue editing\"\n\t\t\t\t\t\t\t: \"Discard changes\";\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t},\n\t});\n\tawait runMenu(ctx, menu, {\n\t\tgetState: () => undefined,\n\t\tsignal,\n\t\tisCurrent: () => !signal?.aborted,\n\t});\n\treturn choice;\n}\n\nfunction updateDraft(draft: SelectionDraft, id: string, included: boolean) {\n\tif (id.startsWith(BUILT_IN_PREFIX))\n\t\treturn updateSet(draft.builtIns, id.slice(BUILT_IN_PREFIX.length), included);\n\tif (id.startsWith(CUSTOM_PREFIX))\n\t\treturn updateSet(draft.custom, id.slice(CUSTOM_PREFIX.length), included);\n\tif (id === SESSIONS_ID) {\n\t\tdraft.sessions = included;\n\t\treturn;\n\t}\n\tthrow new Error(`Unknown file selection: ${id}`);\n}\n\nfunction updateSet(set: Set<string>, value: string, included: boolean) {\n\tif (included) set.add(value);\n\telse set.delete(value);\n}\n\nfunction formatDraftPreview(original: SelectionDraft, draft: SelectionDraft) {\n\tconst lines = [\"Review included-content changes\", \"\"];\n\tfor (const item of new Set([\n\t\t...original.builtIns,\n\t\t...draft.builtIns,\n\t\t...original.custom,\n\t\t...draft.custom,\n\t])) {\n\t\tconst before = original.builtIns.has(item) || original.custom.has(item);\n\t\tconst after = draft.builtIns.has(item) || draft.custom.has(item);\n\t\tif (before !== after) lines.push(`${after ? \"Include\" : \"Exclude\"}: ${safeTerminalText(item)}`);\n\t}\n\tif (original.sessions !== draft.sessions)\n\t\tlines.push(`${draft.sessions ? \"Include\" : \"Exclude\"}: sessions`);\n\tlines.push(\"\", \"Saving does not start a network sync.\");\n\treturn lines.join(\"\\n\");\n}\n\nasync function listCustomCandidates(configured: Set<string>) {\n\tconst candidates = new Map([...configured].map((item) => [item.toLowerCase(), item]));\n\ttry {\n\t\tfor (const entry of await fs.readdir(agentDir(), { withFileTypes: true })) {\n\t\t\tif ((!entry.isFile() && !entry.isDirectory()) || !isSafeCustomIncludePath(entry.name))\n\t\t\t\tcontinue;\n\t\t\tif (!candidates.has(entry.name.toLowerCase()))\n\t\t\t\tcandidates.set(entry.name.toLowerCase(), entry.name);\n\t\t}\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n\t}\n\treturn [...candidates.values()].sort((left, right) => left.localeCompare(right));\n}\n\nfunction cloneDraft(value: SelectionDraft): SelectionDraft {\n\treturn {\n\t\tbuiltIns: new Set(value.builtIns),\n\t\tcustom: new Set(value.custom),\n\t\tsessions: value.sessions,\n\t};\n}\n\nfunction sameDraft(left: SelectionDraft, right: SelectionDraft) {\n\treturn (\n\t\tleft.sessions === right.sessions &&\n\t\tsameSet(left.builtIns, right.builtIns) &&\n\t\tsameSet(left.custom, right.custom)\n\t);\n}\n\nfunction sameSet(left: Set<string>, right: Set<string>) {\n\treturn left.size === right.size && [...left].every((item) => right.has(item));\n}\n\nfunction safeTerminalText(value: string) {\n\t// biome-ignore lint/suspicious/noControlCharactersInRegex: Escape untrusted terminal controls.\n\treturn value.replace(/[\\u0000-\\u001f\\u007f-\\u009f]/gu,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EA,SAAS,QAAQ,MAAmB,OAAoB;AACvD,SAAO,KAAK,SAAS,MAAM,QAAQ,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,SAAS,MAAM,IAAI,IAAI,CAAC;AAC7E;AAEA,SAAS,iBAAiB,OAAe;AAExC,SAAO,MAAM,QAAQ,kCAAkC,GAAG;AAC3D;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/git-backend.ts", "../../src/git-runner.ts", "../../src/git-storage.ts"],
4
- "sourcesContent": ["import { createHash, randomUUID } from \"node:crypto\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport {\n\tnormalizeGitBranch,\n\tnormalizeGitDirectory,\n\tnormalizeGitRemote,\n\tnormalizeGitRemoteIdentity,\n\tvalidateGitNamespace,\n} from \"./git-config.js\";\nimport { GitCommandError, readGitBlobs, runGit } from \"./git-runner.js\";\nimport {\n\tGIT_MANIFEST_VERSION,\n\ttype GitManifest,\n\tMAX_GIT_MANIFEST_BYTES,\n\tMAX_GIT_TREE_OUTPUT_BYTES,\n\ttype PreparedGitFile,\n\tparseGitTree,\n\tprepareGitSnapshot,\n\trequireGitManifest,\n\tvalidateGitPublicationTree,\n\tvalidateGitSnapshot,\n} from \"./git-storage.js\";\nimport { posixJoin } from \"./paths.js\";\nimport { stateDir } from \"./state-directory.js\";\nimport {\n\ttype BackendDiagnostic,\n\ttype ExpectedRemoteHead,\n\ttype PublishSnapshotOptions,\n\ttype PublishSnapshotResult,\n\ttype RemoteHead,\n\ttype RemoteHistoryEntry,\n\ttype SyncBackend,\n\tSyncBackendConflictError,\n\tSyncBackendPublicationOutcomeUnknownError,\n} from \"./sync-backend.js\";\nimport type { ResolvedGitBackend, Snapshot, SnapshotFile } from \"./types.js\";\n\nconst COMMAND_TIMEOUT_MS = 30_000;\nconst POST_COMMIT_TIMEOUT_MS = 45_000;\nconst gitCacheMutationQueues = new Map<string, Promise<void>>();\n\nexport interface GitBackendOptions {\n\tcacheRoot?: string;\n\tallowLocalRemotes?: boolean;\n\tcommandTimeoutMs?: number;\n\tpostCommitTimeoutMs?: number;\n\t/** Deterministic fault injection used only by the local backend test suite. */\n\tafterPushForTest?: () => void | Promise<void>;\n\tafterLsRemoteForTest?: () => void | Promise<void>;\n\tafterPayloadWriteForTest?: () => void | Promise<void>;\n}\n\nexport class GitSyncBackend implements SyncBackend {\n\treadonly identity: string;\n\treadonly destination: string;\n\treadonly capability = \"lease-protected\" as const;\n\tprivate readonly cacheRoot: string;\n\tprivate readonly cacheDir: string;\n\tprivate readonly allowLocalRemotes: boolean;\n\tprivate readonly commandTimeoutMs: number;\n\tprivate readonly postCommitTimeoutMs: number;\n\tprivate readonly afterPushForTest?: () => void | Promise<void>;\n\tprivate readonly afterLsRemoteForTest?: () => void | Promise<void>;\n\tprivate readonly afterPayloadWriteForTest?: () => void | Promise<void>;\n\tprivate cacheReady?: Promise<void>;\n\n\tconstructor(\n\t\tprivate readonly config: ResolvedGitBackend,\n\t\toptions: GitBackendOptions = {},\n\t) {\n\t\tassertGitDestination(config);\n\t\tthis.allowLocalRemotes = options.allowLocalRemotes === true;\n\t\tif (!this.allowLocalRemotes) assertProductionRemote(config.profile.remote);\n\t\tthis.identity = gitBackendIdentity(config);\n\t\tthis.destination = gitDestination(config);\n\t\tthis.cacheRoot = options.cacheRoot ?? path.join(stateDir(), \"git\");\n\t\tthis.cacheDir = path.join(this.cacheRoot, this.identity.slice(\"git:\".length), \"repository.git\");\n\t\tthis.commandTimeoutMs = options.commandTimeoutMs ?? COMMAND_TIMEOUT_MS;\n\t\tthis.postCommitTimeoutMs = options.postCommitTimeoutMs ?? POST_COMMIT_TIMEOUT_MS;\n\t\tthis.afterPushForTest = options.afterPushForTest;\n\t\tthis.afterLsRemoteForTest = options.afterLsRemoteForTest;\n\t\tthis.afterPayloadWriteForTest = options.afterPayloadWriteForTest;\n\t}\n\n\tsameRevision(left: string, right: string) {\n\t\treturn decodeRevision(left, this.identity) === decodeRevision(right, this.identity);\n\t}\n\n\tasync readHead(signal?: AbortSignal): Promise<RemoteHead | undefined> {\n\t\tconst sha = await this.fetchRemoteHead(signal);\n\t\tif (!sha) return undefined;\n\t\tconst { manifest } = await this.readPublication(sha, signal);\n\t\treturn remoteHead(sha, manifest, this.identity);\n\t}\n\n\tasync readSnapshot(reference: string, signal?: AbortSignal): Promise<Snapshot> {\n\t\tconst head = await this.fetchRemoteHead(signal);\n\t\tif (!head) throw new Error(`Git snapshot publication was not found: ${reference}`);\n\t\tconst commit = await this.resolveSnapshotReference(reference, head, signal);\n\t\ttry {\n\t\t\tawait this.git([\"cat-file\", \"-e\", `${commit}^{commit}`], { signal });\n\t\t\tawait this.git([\"merge-base\", \"--is-ancestor\", commit, head], { signal });\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Git snapshot publication was not found: ${reference}`, { cause: error });\n\t\t}\n\t\tconst { manifest, payloadEntries } = await this.readPublication(commit, signal);\n\t\tlet blobs: Buffer[];\n\t\ttry {\n\t\t\tblobs = await readGitBlobs(\n\t\t\t\tpayloadEntries.map((entry) => entry.object),\n\t\t\t\t{\n\t\t\t\t\tgitDir: this.cacheDir,\n\t\t\t\t\tsignal,\n\t\t\t\t\ttimeoutMs: this.commandTimeoutMs,\n\t\t\t\t\tallowFileProtocol: this.allowLocalRemotes,\n\t\t\t\t\tmaxOutputBytes: manifest.files.reduce((total, file) => total + file.size, 0),\n\t\t\t\t},\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error && /exceeds/u.test(error.message)) {\n\t\t\t\tthrow new Error(\"Git snapshot file content exceeds its manifest size.\", { cause: error });\n\t\t\t}\n\t\t\tthrow this.redactedError(error);\n\t\t}\n\t\tthrowIfAborted(signal);\n\t\tconst files: SnapshotFile[] = manifest.files.map((file, index) => {\n\t\t\tconst content = blobs[index];\n\t\t\tif (!content || content.byteLength !== file.size || sha256(content) !== file.sha256) {\n\t\t\t\tthrow new Error(`Git snapshot file checksum or size mismatch: ${file.path}`);\n\t\t\t}\n\t\t\treturn { path: file.path, contentBase64: content.toString(\"base64\"), sha256: file.sha256 };\n\t\t});\n\t\tconst snapshot: Snapshot = {\n\t\t\tversion: manifest.snapshotVersion,\n\t\t\tid: manifest.snapshotId,\n\t\t\tcreatedAt: manifest.createdAt,\n\t\t\tmachine: manifest.machine,\n\t\t\tprofile: manifest.profile,\n\t\t\t...(manifest.snapshotSyncSessions === undefined\n\t\t\t\t? {}\n\t\t\t\t: { syncSessions: manifest.snapshotSyncSessions }),\n\t\t\t...(manifest.selection === undefined ? {} : { selection: manifest.selection }),\n\t\t\tfiles,\n\t\t};\n\t\tvalidateGitSnapshot(snapshot, manifest, this.config.destination.namespace);\n\t\treturn snapshot;\n\t}\n\n\tasync publishSnapshot(\n\t\tsnapshot: Snapshot,\n\t\texpected: ExpectedRemoteHead,\n\t\toptions: PublishSnapshotOptions = {},\n\t): Promise<PublishSnapshotResult> {\n\t\tthrowIfAborted(options.signal);\n\t\tconst files = prepareGitSnapshot(snapshot, this.config.destination.namespace);\n\t\tconst observed = await this.fetchRemoteHead(options.signal);\n\t\tif (!matchesExpected(observed, expected, this.identity)) {\n\t\t\tthrow new SyncBackendConflictError(\n\t\t\t\t\"Git remote changed while preparing publication. Run /sync status and retry.\",\n\t\t\t\t{ currentHead: observed ? await this.headForSha(observed, options.signal) : undefined },\n\t\t\t);\n\t\t}\n\t\tthrowIfAborted(options.signal);\n\t\tconst manifest: GitManifest = {\n\t\t\tversion: GIT_MANIFEST_VERSION,\n\t\t\tsnapshotVersion: snapshot.version,\n\t\t\tsnapshotId: snapshot.id,\n\t\t\tcreatedAt: snapshot.createdAt,\n\t\t\tmachine: snapshot.machine,\n\t\t\tprofile: snapshot.profile,\n\t\t\tsyncSessions:\n\t\t\t\tsnapshot.syncSessions === true ||\n\t\t\t\tsnapshot.files.some((file) => file.path.startsWith(\"sessions/\")),\n\t\t\t...(snapshot.syncSessions === undefined\n\t\t\t\t? {}\n\t\t\t\t: { snapshotSyncSessions: snapshot.syncSessions }),\n\t\t\t...(snapshot.selection === undefined ? {} : { selection: snapshot.selection }),\n\t\t\tfiles: files.map(({ path: filePath, sha256: fileSha, size }) => ({\n\t\t\t\tpath: filePath,\n\t\t\t\tsha256: fileSha,\n\t\t\t\tsize,\n\t\t\t})),\n\t\t};\n\t\tlet candidate: string;\n\t\ttry {\n\t\t\tcandidate = await this.createCommit(snapshot, files, manifest, observed, options.signal);\n\t\t} catch (error) {\n\t\t\tthrow this.redactedError(error);\n\t\t}\n\t\tthrowIfAborted(options.signal);\n\t\toptions.onCommit?.();\n\n\t\tconst ref = this.remoteRef();\n\t\tconst lease = `--force-with-lease=${ref}:${observed ?? \"\"}`;\n\t\tlet pushError: unknown;\n\t\ttry {\n\t\t\tawait this.git(\n\t\t\t\t[\n\t\t\t\t\t\"push\",\n\t\t\t\t\t\"--porcelain\",\n\t\t\t\t\t\"--no-verify\",\n\t\t\t\t\tlease,\n\t\t\t\t\tthis.config.profile.remote,\n\t\t\t\t\t`${candidate}:${ref}`,\n\t\t\t\t],\n\t\t\t\t{ timeoutMs: this.postCommitTimeoutMs },\n\t\t\t);\n\t\t\tawait this.afterPushForTest?.();\n\t\t} catch (error) {\n\t\t\tpushError = error;\n\t\t}\n\n\t\tlet current: string | undefined;\n\t\ttry {\n\t\t\tcurrent = await this.fetchRemoteHead(AbortSignal.timeout(this.postCommitTimeoutMs));\n\t\t} catch (error) {\n\t\t\tthrow new SyncBackendPublicationOutcomeUnknownError(\n\t\t\t\t`Git publication outcome is unknown: ${this.safeError(pushError ?? error)}`,\n\t\t\t\t{ cause: pushError ?? error },\n\t\t\t);\n\t\t}\n\t\tif (current !== candidate) {\n\t\t\tif (pushError && current === observed) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Git publication failed without updating the owned branch: ${this.safeError(pushError)}`,\n\t\t\t\t\t{\n\t\t\t\t\t\tcause: pushError,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow new SyncBackendConflictError(\n\t\t\t\tpushError\n\t\t\t\t\t? `Git publication lease was rejected: ${this.safeError(pushError)}`\n\t\t\t\t\t: \"Git remote changed immediately after publication.\",\n\t\t\t\t{\n\t\t\t\t\tphase: \"after-commit\",\n\t\t\t\t\tcurrentHead: current ? await this.headForSha(current) : undefined,\n\t\t\t\t\tcandidateMayHaveBeenActive: true,\n\t\t\t\t\tcause: pushError instanceof Error ? pushError : undefined,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\tconst head = await this.headForSha(candidate);\n\t\treturn { head, warnings: [] };\n\t}\n\n\tasync listHistory(signal?: AbortSignal): Promise<RemoteHistoryEntry[]> {\n\t\tconst sha = await this.fetchRemoteHead(signal);\n\t\tif (!sha) return [];\n\t\tconst result = await this.git(\n\t\t\t[\"rev-list\", \"--first-parent\", \"--reverse\", \"--max-count=100\", sha],\n\t\t\t{ signal },\n\t\t);\n\t\tconst commits = result.stdout.toString(\"utf8\").trim().split(\"\\n\").filter(Boolean);\n\t\tconst entries: RemoteHistoryEntry[] = [];\n\t\tfor (const commit of commits) {\n\t\t\tconst { manifest } = await this.readPublication(commit, signal);\n\t\t\tentries.push({\n\t\t\t\tsnapshotRef: commit,\n\t\t\t\tsnapshotId: manifest.snapshotId,\n\t\t\t\tcreatedAt: manifest.createdAt,\n\t\t\t\tmachine: manifest.machine,\n\t\t\t\tsyncSessions: manifest.syncSessions,\n\t\t\t});\n\t\t}\n\t\treturn entries;\n\t}\n\n\tasync diagnose(signal?: AbortSignal): Promise<BackendDiagnostic[]> {\n\t\tconst diagnostics: BackendDiagnostic[] = [];\n\t\ttry {\n\t\t\tconst version = await runGit([\"--version\"], {\n\t\t\t\tsignal,\n\t\t\t\ttimeoutMs: this.commandTimeoutMs,\n\t\t\t});\n\t\t\tconst versionText = version.stdout.toString(\"utf8\").trim();\n\t\t\tconst supported = isSupportedGitVersion(versionText);\n\t\t\tdiagnostics.push({\n\t\t\t\tkey: \"git-version\",\n\t\t\t\tlevel: supported ? \"info\" : \"error\",\n\t\t\t\tmessage: supported\n\t\t\t\t\t? versionText\n\t\t\t\t\t: `${versionText || \"unknown Git version\"}; pi-sync requires Git 2.30 or newer`,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\treturn [{ key: \"git-version\", level: \"error\", message: this.safeError(error) }];\n\t\t}\n\t\ttry {\n\t\t\tconst head = await this.readHead(signal);\n\t\t\tif (head) await this.readSnapshot(head.snapshotRef, signal);\n\t\t\tdiagnostics.push({\n\t\t\t\tkey: \"git-remote\",\n\t\t\t\tlevel: \"info\",\n\t\t\t\tmessage: head\n\t\t\t\t\t? `git remote: reachable; owned branch ${this.config.destination.branch} is valid`\n\t\t\t\t\t: `git remote: reachable; owned branch ${this.config.destination.branch} is not created yet`,\n\t\t\t});\n\t\t\tdiagnostics.push({\n\t\t\t\tkey: \"git-cache\",\n\t\t\t\tlevel: \"info\",\n\t\t\t\tmessage: \"git cache: private bare repository is healthy\",\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tdiagnostics.push({\n\t\t\t\tkey: \"git-remote\",\n\t\t\t\tlevel: \"error\",\n\t\t\t\tmessage: `git remote: ${this.safeError(error)}`,\n\t\t\t});\n\t\t}\n\t\treturn diagnostics;\n\t}\n\n\tprivate async resolveSnapshotReference(reference: string, head: string, signal?: AbortSignal) {\n\t\tif (isCommitSha(reference) || /^[0-9a-f]{64}$/u.test(reference)) {\n\t\t\trequireCommitSha(reference);\n\t\t\treturn reference;\n\t\t}\n\t\tif (!reference || reference.length > 512 || !/^[A-Za-z0-9._-]+$/u.test(reference)) {\n\t\t\tthrow new Error(\"Invalid Git publication reference.\");\n\t\t}\n\t\tconst result = await this.git([\"rev-list\", \"--first-parent\", \"--max-count=100\", head], {\n\t\t\tsignal,\n\t\t});\n\t\tconst commits = result.stdout.toString(\"utf8\").trim().split(\"\\n\").filter(Boolean);\n\t\tconst matches: string[] = [];\n\t\tfor (const commit of commits) {\n\t\t\tconst { manifest } = await this.readPublication(commit, signal);\n\t\t\tif (manifest.snapshotId === reference) matches.push(commit);\n\t\t}\n\t\tif (matches.length === 0) {\n\t\t\tthrow new Error(`Git snapshot publication was not found: ${reference}`);\n\t\t}\n\t\tif (matches.length > 1) {\n\t\t\tthrow new Error(\n\t\t\t\t`Git snapshot id is ambiguous; use a commit reference from /sync history: ${reference}`,\n\t\t\t);\n\t\t}\n\t\treturn matches[0] as string;\n\t}\n\n\tprivate async headForSha(sha: string, signal?: AbortSignal) {\n\t\tconst { manifest } = await this.readPublication(sha, signal);\n\t\treturn remoteHead(sha, manifest, this.identity);\n\t}\n\n\tprivate async fetchRemoteHead(signal?: AbortSignal) {\n\t\tawait this.ensureCache(signal);\n\t\tconst result = await this.git(\n\t\t\t[\"ls-remote\", \"--refs\", this.config.profile.remote, this.remoteRef()],\n\t\t\t{ signal },\n\t\t);\n\t\tconst line = result.stdout.toString(\"utf8\").trim();\n\t\tif (!line) return undefined;\n\t\tconst [sha, ref, ...extra] = line.split(/\\s+/u);\n\t\tif (extra.length > 0 || ref !== this.remoteRef() || !sha) {\n\t\t\tthrow new Error(\"Git remote returned a malformed owned-ref response.\");\n\t\t}\n\t\trequireCommitSha(sha);\n\t\tawait this.afterLsRemoteForTest?.();\n\t\treturn withGitCacheMutation(\n\t\t\tthis.cacheDir,\n\t\t\tasync () => {\n\t\t\t\tconst localRef = `refs/pisync/fetch/${process.pid}-${randomUUID()}`;\n\t\t\t\ttry {\n\t\t\t\t\tawait this.git(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"fetch\",\n\t\t\t\t\t\t\t\"--no-tags\",\n\t\t\t\t\t\t\t\"--force\",\n\t\t\t\t\t\t\tthis.config.profile.remote,\n\t\t\t\t\t\t\t`${this.remoteRef()}:${localRef}`,\n\t\t\t\t\t\t],\n\t\t\t\t\t\t{ signal },\n\t\t\t\t\t);\n\t\t\t\t\tconst fetched = (await this.git([\"rev-parse\", \"--verify\", localRef], { signal })).stdout\n\t\t\t\t\t\t.toString(\"utf8\")\n\t\t\t\t\t\t.trim();\n\t\t\t\t\trequireCommitSha(fetched);\n\t\t\t\t\treturn fetched;\n\t\t\t\t} finally {\n\t\t\t\t\tawait this.git([\"update-ref\", \"-d\", localRef], { timeoutMs: 5_000 }).catch(\n\t\t\t\t\t\t() => undefined,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t},\n\t\t\tsignal,\n\t\t);\n\t}\n\n\tprivate async readManifest(commit: string, signal?: AbortSignal): Promise<GitManifest> {\n\t\trequireCommitSha(commit);\n\t\tconst bytes = await this.showFile(commit, this.manifestPath(), signal, MAX_GIT_MANIFEST_BYTES);\n\t\tlet parsed: unknown;\n\t\ttry {\n\t\t\tparsed = JSON.parse(bytes.toString(\"utf8\"));\n\t\t} catch (error) {\n\t\t\tthrow new Error(\"Git publication manifest is malformed.\", { cause: error });\n\t\t}\n\t\treturn requireGitManifest(parsed);\n\t}\n\n\tprivate showFile(\n\t\tcommit: string,\n\t\tfilePath: string,\n\t\tsignal?: AbortSignal,\n\t\tmaxOutputBytes?: number,\n\t) {\n\t\treturn this.git([\"show\", `${commit}:${filePath}`], { signal, maxOutputBytes }).then(\n\t\t\t(result) => result.stdout,\n\t\t);\n\t}\n\n\tprivate async createCommit(\n\t\tsnapshot: Snapshot,\n\t\tfiles: PreparedGitFile[],\n\t\tmanifest: GitManifest,\n\t\tparent: string | undefined,\n\t\tsignal?: AbortSignal,\n\t) {\n\t\tconst manifestBytes = Buffer.from(`${JSON.stringify(manifest)}\\n`, \"utf8\");\n\t\tif (manifestBytes.byteLength > MAX_GIT_MANIFEST_BYTES) {\n\t\t\tthrow new Error(`Git publication manifest exceeds the ${MAX_GIT_MANIFEST_BYTES}-byte limit.`);\n\t\t}\n\t\tawait this.ensureCache(signal);\n\t\tconst temporaryDirectory = await fs.mkdtemp(path.join(path.dirname(this.cacheDir), \".index-\"));\n\t\tconst indexPath = path.join(temporaryDirectory, \"index\");\n\t\tconst payloadDirectory = path.join(temporaryDirectory, \"payloads\");\n\t\tconst env = { GIT_INDEX_FILE: indexPath };\n\t\ttry {\n\t\t\tawait fs.mkdir(payloadDirectory, { mode: 0o700 });\n\t\t\tconst uniqueFiles = [...new Map(files.map((file) => [file.sha256, file])).values()].sort(\n\t\t\t\t(left, right) => left.sha256.localeCompare(right.sha256),\n\t\t\t);\n\t\t\tfor (const file of uniqueFiles) {\n\t\t\t\tthrowIfAborted(signal);\n\t\t\t\tawait fs.writeFile(path.join(payloadDirectory, file.sha256), file.content, {\n\t\t\t\t\tflag: \"wx\",\n\t\t\t\t\tmode: 0o600,\n\t\t\t\t});\n\t\t\t}\n\t\t\tawait this.afterPayloadWriteForTest?.();\n\t\t\tthrowIfAborted(signal);\n\t\t\tconst hashed = await this.git([\"hash-object\", \"-w\", \"--no-filters\", \"--stdin-paths\"], {\n\t\t\t\tcwd: payloadDirectory,\n\t\t\t\tinput: uniqueFiles.map((file) => file.sha256).join(\"\\n\") + (uniqueFiles.length ? \"\\n\" : \"\"),\n\t\t\t\tsignal,\n\t\t\t\tmaxOutputBytes: Math.max(1024, uniqueFiles.length * 64),\n\t\t\t});\n\t\t\tconst objectIds = hashed.stdout.toString(\"utf8\").trim().split(\"\\n\").filter(Boolean);\n\t\t\tif (objectIds.length !== uniqueFiles.length || objectIds.some((id) => !isCommitSha(id))) {\n\t\t\t\tthrow new Error(\"Git hash-object returned a malformed payload response.\");\n\t\t\t}\n\t\t\tconst objectsBySha256 = new Map(\n\t\t\t\tuniqueFiles.map((file, index) => [file.sha256, objectIds[index] as string]),\n\t\t\t);\n\t\t\tconst manifestBlob = (\n\t\t\t\tawait this.git([\"hash-object\", \"-w\", \"--stdin\"], { input: manifestBytes, signal })\n\t\t\t).stdout\n\t\t\t\t.toString(\"utf8\")\n\t\t\t\t.trim();\n\t\t\tif (!isCommitSha(manifestBlob)) throw new Error(\"Git returned an invalid manifest blob id.\");\n\t\t\tawait this.git([\"read-tree\", \"--empty\"], { env, signal });\n\t\t\tconst indexLines = [\n\t\t\t\t`100644 ${manifestBlob}\\t${this.manifestPath()}`,\n\t\t\t\t...files.map((file) => {\n\t\t\t\t\tconst object = objectsBySha256.get(file.sha256);\n\t\t\t\t\tif (!object) throw new Error(\"Git payload object is missing after hashing.\");\n\t\t\t\t\treturn `100644 ${object}\\t${this.filePath(file.path)}`;\n\t\t\t\t}),\n\t\t\t];\n\t\t\tawait this.git([\"update-index\", \"-z\", \"--index-info\"], {\n\t\t\t\tenv,\n\t\t\t\tsignal,\n\t\t\t\tinput: Buffer.from(`${indexLines.join(\"\\0\")}\\0`, \"utf8\"),\n\t\t\t});\n\t\t\tconst tree = (await this.git([\"write-tree\"], { env, signal })).stdout.toString(\"utf8\").trim();\n\t\t\tconst date = Number.isNaN(Date.parse(snapshot.createdAt))\n\t\t\t\t? new Date().toISOString()\n\t\t\t\t: snapshot.createdAt;\n\t\t\tconst commit = await this.git(\n\t\t\t\t[\"commit-tree\", tree, ...(parent ? [\"-p\", parent] : []), \"-F\", \"-\"],\n\t\t\t\t{\n\t\t\t\t\tsignal,\n\t\t\t\t\tinput: `pi-sync snapshot ${snapshot.id}\\n`,\n\t\t\t\t\tenv: {\n\t\t\t\t\t\tGIT_AUTHOR_NAME: \"pi-sync\",\n\t\t\t\t\t\tGIT_AUTHOR_EMAIL: \"pi-sync@localhost\",\n\t\t\t\t\t\tGIT_COMMITTER_NAME: \"pi-sync\",\n\t\t\t\t\t\tGIT_COMMITTER_EMAIL: \"pi-sync@localhost\",\n\t\t\t\t\t\tGIT_AUTHOR_DATE: date,\n\t\t\t\t\t\tGIT_COMMITTER_DATE: date,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tconst sha = commit.stdout.toString(\"utf8\").trim();\n\t\t\trequireCommitSha(sha);\n\t\t\treturn sha;\n\t\t} finally {\n\t\t\tawait fs.rm(temporaryDirectory, { recursive: true, force: true });\n\t\t}\n\t}\n\n\tprivate ensureCache(signal?: AbortSignal) {\n\t\tif (!this.cacheReady) {\n\t\t\tconst operation = withGitCacheMutation(\n\t\t\t\tthis.cacheDir,\n\t\t\t\t() => this.initializeCache(signal),\n\t\t\t\tsignal,\n\t\t\t);\n\t\t\tconst wrapped = operation.catch((error) => {\n\t\t\t\tif (this.cacheReady === wrapped) this.cacheReady = undefined;\n\t\t\t\tthrow this.redactedError(error);\n\t\t\t});\n\t\t\tthis.cacheReady = wrapped;\n\t\t}\n\t\treturn this.cacheReady;\n\t}\n\n\tprivate async initializeCache(signal?: AbortSignal) {\n\t\tconst version = await runGit([\"--version\"], {\n\t\t\tsignal,\n\t\t\ttimeoutMs: this.commandTimeoutMs,\n\t\t});\n\t\tconst versionText = version.stdout.toString(\"utf8\").trim();\n\t\tif (!isSupportedGitVersion(versionText)) {\n\t\t\tthrow new Error(\n\t\t\t\t`${versionText || \"Unknown Git version\"}; pi-sync requires Git 2.30 or newer.`,\n\t\t\t);\n\t\t}\n\t\tconst parent = path.dirname(this.cacheDir);\n\t\tconst cacheParent = path.dirname(this.cacheRoot);\n\t\tawait assertNotSymlink(cacheParent, \"Git cache parent\");\n\t\tawait assertNotSymlink(this.cacheRoot, \"Git cache root\");\n\t\tawait fs.mkdir(this.cacheRoot, { recursive: true, mode: 0o700 });\n\t\tawait assertNotSymlink(cacheParent, \"Git cache parent\");\n\t\tawait assertNotSymlink(this.cacheRoot, \"Git cache root\");\n\t\tawait assertNotSymlink(parent, \"Git cache identity directory\");\n\t\tawait fs.mkdir(parent, { recursive: true, mode: 0o700 });\n\t\tawait assertNotSymlink(parent, \"Git cache identity directory\");\n\t\tlet recreate = false;\n\t\ttry {\n\t\t\tconst stat = await fs.lstat(this.cacheDir);\n\t\t\tif (stat.isSymbolicLink()) throw new Error(\"Refusing symlinked Git cache.\");\n\t\t\tif (!stat.isDirectory()) recreate = true;\n\t\t\telse {\n\t\t\t\ttry {\n\t\t\t\t\trecreate = !(await this.cacheUsesSha1(signal));\n\t\t\t\t} catch {\n\t\t\t\t\trecreate = true;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n\t\t}\n\t\tif (recreate) await fs.rm(this.cacheDir, { recursive: true, force: true });\n\t\ttry {\n\t\t\tawait fs.access(this.cacheDir);\n\t\t} catch {\n\t\t\ttry {\n\t\t\t\tawait runGit([\"init\", \"--bare\", \"--object-format=sha1\", this.cacheDir], {\n\t\t\t\t\tsignal,\n\t\t\t\t\ttimeoutMs: this.commandTimeoutMs,\n\t\t\t\t\tallowFileProtocol: this.allowLocalRemotes,\n\t\t\t\t});\n\t\t\t} catch (initError) {\n\t\t\t\tconst concurrent = await this.cacheUsesSha1(signal).catch(() => false);\n\t\t\t\tif (!concurrent) throw initError;\n\t\t\t}\n\t\t}\n\t\tif (process.platform !== \"win32\") await fs.chmod(parent, 0o700);\n\t}\n\n\tprivate async cacheUsesSha1(signal?: AbortSignal) {\n\t\tconst result = await this.git([\"rev-parse\", \"--is-bare-repository\", \"--show-object-format\"], {\n\t\t\tsignal,\n\t\t});\n\t\treturn result.stdout.toString(\"utf8\").trim() === \"true\\nsha1\";\n\t}\n\n\tprivate git(\n\t\targs: string[],\n\t\toptions: {\n\t\t\tcwd?: string;\n\t\t\tinput?: Buffer | string;\n\t\t\tenv?: NodeJS.ProcessEnv;\n\t\t\tsignal?: AbortSignal;\n\t\t\ttimeoutMs?: number;\n\t\t\tmaxOutputBytes?: number;\n\t\t} = {},\n\t) {\n\t\treturn runGit(args, {\n\t\t\tgitDir: this.cacheDir,\n\t\t\tallowFileProtocol: this.allowLocalRemotes,\n\t\t\ttimeoutMs: options.timeoutMs ?? this.commandTimeoutMs,\n\t\t\t...options,\n\t\t}).catch((error) => {\n\t\t\tthrow this.redactedError(error);\n\t\t});\n\t}\n\n\tprivate remoteRef() {\n\t\treturn `refs/heads/${this.config.destination.branch}`;\n\t}\n\n\tprivate publicationPath() {\n\t\treturn this.config.destination.directory;\n\t}\n\n\tprivate manifestPath() {\n\t\treturn posixJoin(this.publicationPath(), \"manifest.json\");\n\t}\n\n\tprivate filePath(filePath: string) {\n\t\treturn posixJoin(this.publicationPath(), \"files\", filePath);\n\t}\n\n\tprivate async readPublication(commit: string, signal?: AbortSignal) {\n\t\tconst manifest = await this.readManifest(commit, signal);\n\t\tconst entries = await this.readPublicationTree(commit, signal);\n\t\tconst payloadEntries = validateGitPublicationTree(\n\t\t\tentries,\n\t\t\tmanifest,\n\t\t\tthis.manifestPath(),\n\t\t\t(filePath) => this.filePath(filePath),\n\t\t);\n\t\treturn { manifest, payloadEntries };\n\t}\n\n\tprivate async readPublicationTree(commit: string, signal?: AbortSignal) {\n\t\tconst result = await this.git([\"ls-tree\", \"-r\", \"-z\", commit], {\n\t\t\tsignal,\n\t\t\tmaxOutputBytes: MAX_GIT_TREE_OUTPUT_BYTES,\n\t\t});\n\t\treturn parseGitTree(result.stdout);\n\t}\n\n\tprivate redactedError(error: unknown) {\n\t\tif (error instanceof Error && error.name === \"AbortError\") return error;\n\t\treturn new Error(this.safeError(error));\n\t}\n\n\tprivate safeError(error: unknown) {\n\t\tconst raw =\n\t\t\terror instanceof GitCommandError\n\t\t\t\t? error.stderr || error.message\n\t\t\t\t: error instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: String(error);\n\t\treturn redactGitError(raw, this.config.profile.remote, this.cacheDir);\n\t}\n}\n\nexport function gitBackendIdentity(config: ResolvedGitBackend) {\n\tlet remoteIdentity: string;\n\ttry {\n\t\tremoteIdentity = normalizeGitRemoteIdentity(config.profile.remote);\n\t} catch {\n\t\tremoteIdentity = config.profile.remote;\n\t}\n\tconst canonical = JSON.stringify([\n\t\tremoteIdentity,\n\t\tconfig.destination.branch,\n\t\tconfig.destination.directory,\n\t]);\n\treturn `git:${sha256(Buffer.from(canonical))}`;\n}\n\nfunction gitDestination(config: ResolvedGitBackend) {\n\tlet host = \"Git remote\";\n\tconst remote = config.profile.remote;\n\tif (remote.includes(\"://\")) {\n\t\ttry {\n\t\t\thost = new URL(remote).host;\n\t\t} catch {\n\t\t\thost = \"Git remote\";\n\t\t}\n\t} else {\n\t\tconst match = /^(?:[^@]+@)?(?<host>\\[[^\\]]+\\]|[^:]+):/u.exec(remote);\n\t\tif (match?.groups?.host) host = match.groups.host;\n\t}\n\treturn `${host} \u00B7 ${config.destination.branch}:${config.destination.directory}`;\n}\n\nfunction remoteHead(sha: string, manifest: GitManifest, identity: string): RemoteHead {\n\treturn {\n\t\tsnapshotRef: sha,\n\t\tsnapshotId: manifest.snapshotId,\n\t\trevision: `${identity}:${sha}`,\n\t\tcreatedAt: manifest.createdAt,\n\t\tmachine: manifest.machine,\n\t\tsyncSessions: manifest.syncSessions,\n\t\t...(manifest.selection === undefined ? {} : { selection: manifest.selection }),\n\t};\n}\n\nfunction matchesExpected(\n\tcurrent: string | undefined,\n\texpected: ExpectedRemoteHead,\n\tidentity: string,\n) {\n\tif (expected.kind === \"missing\") return current === undefined;\n\ttry {\n\t\treturn current === decodeRevision(expected.revision, identity);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction decodeRevision(revision: string, identity: string) {\n\tconst prefix = `${identity}:`;\n\tconst sha = revision.startsWith(prefix) ? revision.slice(prefix.length) : \"\";\n\tif (!/^[0-9a-f]{40}$/u.test(sha)) throw new Error(\"Invalid Git remote revision.\");\n\treturn sha;\n}\n\nfunction isCommitSha(value: string) {\n\treturn /^[0-9a-f]{40}$/u.test(value);\n}\n\nfunction requireCommitSha(value: string) {\n\tif (/^[0-9a-f]{64}$/u.test(value)) {\n\t\tthrow new Error(\"Unsupported Git SHA-256 repository; pi-sync currently requires SHA-1 refs.\");\n\t}\n\tif (!/^[0-9a-f]{40}$/u.test(value)) throw new Error(\"Invalid Git publication reference.\");\n}\n\nexport function isSupportedGitVersion(value: string) {\n\tconst match = /git version (\\d+)\\.(\\d+)/u.exec(value);\n\tif (!match) return false;\n\tconst major = Number(match[1]);\n\tconst minor = Number(match[2]);\n\treturn major > 2 || (major === 2 && minor >= 30);\n}\n\nfunction assertGitDestination(config: ResolvedGitBackend) {\n\ttry {\n\t\tif (\n\t\t\tnormalizeGitBranch(config.destination.branch) !== config.destination.branch ||\n\t\t\tnormalizeGitDirectory(config.destination.directory) !== config.destination.directory\n\t\t) {\n\t\t\tthrow new Error(\"Git storage location is not normalized.\");\n\t\t}\n\t\tvalidateGitNamespace(config.destination.namespace);\n\t} catch (error) {\n\t\tthrow new Error(\"Invalid Git storage location.\", { cause: error });\n\t}\n}\n\nfunction assertProductionRemote(remote: string) {\n\tlet normalized: string | undefined;\n\ttry {\n\t\tnormalized = normalizeGitRemote(remote);\n\t} catch (error) {\n\t\tthrow new Error(error instanceof Error ? error.message : \"Invalid Git remote.\", {\n\t\t\tcause: error,\n\t\t});\n\t}\n\tif (!normalized || normalized !== remote)\n\t\tthrow new Error(\"Invalid or non-normalized Git remote.\");\n}\n\nasync function withGitCacheMutation<T>(\n\tcacheDir: string,\n\trun: () => Promise<T>,\n\tsignal?: AbortSignal,\n): Promise<T> {\n\tconst previous = gitCacheMutationQueues.get(cacheDir) ?? Promise.resolve();\n\tconst operation = previous\n\t\t.catch(() => undefined)\n\t\t.then(() => {\n\t\t\tthrowIfAborted(signal);\n\t\t\treturn run();\n\t\t});\n\tconst tail = operation.then(\n\t\t() => undefined,\n\t\t() => undefined,\n\t);\n\tgitCacheMutationQueues.set(cacheDir, tail);\n\tvoid tail.then(() => {\n\t\tif (gitCacheMutationQueues.get(cacheDir) === tail) gitCacheMutationQueues.delete(cacheDir);\n\t});\n\tif (!signal) return operation;\n\tthrowIfAborted(signal);\n\tlet rejectAbort: ((reason: unknown) => void) | undefined;\n\tconst aborted = new Promise<never>((_resolve, reject) => {\n\t\trejectAbort = reject;\n\t});\n\tconst onAbort = () => rejectAbort?.(abortReason(signal));\n\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\tif (signal.aborted) onAbort();\n\ttry {\n\t\treturn await Promise.race([operation, aborted]);\n\t} finally {\n\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t}\n}\n\nasync function assertNotSymlink(target: string, label: string) {\n\ttry {\n\t\tconst stat = await fs.lstat(target);\n\t\tif (stat.isSymbolicLink()) throw new Error(`Refusing symlinked ${label}.`);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n\t}\n}\n\nfunction redactGitError(value: string, remote: string, cacheDir: string) {\n\treturn (\n\t\tvalue\n\t\t\t.replaceAll(remote, \"<git-remote>\")\n\t\t\t.replaceAll(cacheDir, \"<git-cache>\")\n\t\t\t.replace(/https:\\/\\/[^/@\\s]+@/gu, \"https://<credentials>@\")\n\t\t\t.replace(/\\b(password|token|authorization)=\\S+/giu, \"$1=<redacted>\")\n\t\t\t.replace(/\\bBearer\\s+\\S+/giu, \"Bearer <redacted>\")\n\t\t\t// biome-ignore lint/suspicious/noControlCharactersInRegex: sanitize untrusted process output.\n\t\t\t.replace(/[\\u0000-\\u001f\\u007f-\\u009f]/gu, \" \")\n\t\t\t.trim()\n\t\t\t.slice(0, 4096)\n\t);\n}\n\nfunction sha256(value: Buffer) {\n\treturn createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\nfunction abortReason(signal: AbortSignal) {\n\treturn signal.reason instanceof Error\n\t\t? signal.reason\n\t\t: new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n\nfunction throwIfAborted(signal?: AbortSignal) {\n\tif (signal?.aborted) throw abortReason(signal);\n}\n", "import { spawn } from \"node:child_process\";\nimport process from \"node:process\";\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\nconst DEFAULT_OUTPUT_LIMIT = 1024 * 1024;\n\nexport interface GitRunOptions {\n\tgitDir?: string;\n\tcwd?: string;\n\tinput?: Buffer | string;\n\tenv?: NodeJS.ProcessEnv;\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n\tmaxOutputBytes?: number;\n\tallowFileProtocol?: boolean;\n}\n\nexport interface GitRunResult {\n\tstdout: Buffer;\n\tstderr: Buffer;\n}\n\nexport class GitCommandError extends Error {\n\treadonly code = \"GIT_COMMAND_FAILED\";\n\tconstructor(\n\t\tmessage: string,\n\t\treadonly exitCode: number | null,\n\t\treadonly stderr: string,\n\t\toptions?: ErrorOptions,\n\t) {\n\t\tsuper(message, options);\n\t\tthis.name = \"GitCommandError\";\n\t}\n}\n\nexport async function runGit(args: string[], options: GitRunOptions = {}): Promise<GitRunResult> {\n\tthrowIfAborted(options.signal);\n\tconst hooksPath = process.platform === \"win32\" ? \"NUL\" : \"/dev/null\";\n\tconst protocolArgs = [\n\t\t\"-c\",\n\t\t`core.hooksPath=${hooksPath}`,\n\t\t\"-c\",\n\t\t\"gc.auto=0\",\n\t\t\"-c\",\n\t\t\"maintenance.auto=false\",\n\t\t\"-c\",\n\t\t\"protocol.allow=never\",\n\t\t\"-c\",\n\t\t\"protocol.https.allow=always\",\n\t\t\"-c\",\n\t\t\"protocol.ssh.allow=always\",\n\t];\n\tif (options.allowFileProtocol) protocolArgs.push(\"-c\", \"protocol.file.allow=always\");\n\tconst commandArgs = [\n\t\t...(options.gitDir ? [`--git-dir=${options.gitDir}`] : []),\n\t\t...protocolArgs,\n\t\t...args,\n\t];\n\tconst inheritedEnvironment = Object.fromEntries(\n\t\tObject.entries(process.env).filter(\n\t\t\t([key]) =>\n\t\t\t\t!key.startsWith(\"GIT_\") &&\n\t\t\t\tkey !== \"PAGER\" &&\n\t\t\t\tkey !== \"EDITOR\" &&\n\t\t\t\tkey !== \"VISUAL\" &&\n\t\t\t\tkey !== \"SSH_ASKPASS\" &&\n\t\t\t\tkey !== \"SSH_ASKPASS_REQUIRE\",\n\t\t),\n\t);\n\tconst allowedGitOverrides = new Set([\n\t\t\"GIT_INDEX_FILE\",\n\t\t\"GIT_AUTHOR_NAME\",\n\t\t\"GIT_AUTHOR_EMAIL\",\n\t\t\"GIT_AUTHOR_DATE\",\n\t\t\"GIT_COMMITTER_NAME\",\n\t\t\"GIT_COMMITTER_EMAIL\",\n\t\t\"GIT_COMMITTER_DATE\",\n\t]);\n\tconst suppliedEnvironment = Object.fromEntries(\n\t\tObject.entries(options.env ?? {}).filter(\n\t\t\t([key]) => !key.startsWith(\"GIT_\") || allowedGitOverrides.has(key),\n\t\t),\n\t);\n\tconst env: NodeJS.ProcessEnv = {\n\t\t...inheritedEnvironment,\n\t\t...suppliedEnvironment,\n\t\tLC_ALL: \"C\",\n\t\tLANG: \"C\",\n\t\tGIT_CONFIG_NOSYSTEM: \"1\",\n\t\tGIT_TERMINAL_PROMPT: \"0\",\n\t\tGCM_INTERACTIVE: \"Never\",\n\t\tGIT_PAGER: \"cat\",\n\t\tPAGER: \"cat\",\n\t\tGIT_EDITOR: \"true\",\n\t\tEDITOR: \"true\",\n\t\tVISUAL: \"true\",\n\t\tGIT_ASKPASS: \"\",\n\t\tSSH_ASKPASS: \"\",\n\t\tSSH_ASKPASS_REQUIRE: \"never\",\n\t\tGIT_SSH_COMMAND: \"ssh -oBatchMode=yes\",\n\t};\n\tconst child = spawn(\"git\", commandArgs, {\n\t\tcwd: options.cwd,\n\t\tenv,\n\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\tdetached: process.platform !== \"win32\",\n\t\twindowsHide: true,\n\t});\n\tconst stdout: Buffer[] = [];\n\tconst stderr: Buffer[] = [];\n\tlet total = 0;\n\tlet settled = false;\n\tlet terminationError: Error | undefined;\n\tlet escalationTimer: NodeJS.Timeout | undefined;\n\tconst limit = options.maxOutputBytes ?? DEFAULT_OUTPUT_LIMIT;\n\n\tconst terminate = (error: Error) => {\n\t\tif (settled || terminationError) return;\n\t\tterminationError = error;\n\t\tif (child.pid && process.platform !== \"win32\") {\n\t\t\ttry {\n\t\t\t\tprocess.kill(-child.pid, \"SIGTERM\");\n\t\t\t} catch {\n\t\t\t\tchild.kill(\"SIGTERM\");\n\t\t\t}\n\t\t} else {\n\t\t\tchild.kill(\"SIGTERM\");\n\t\t\tif (child.pid && process.platform === \"win32\") {\n\t\t\t\tconst killer = spawn(\"taskkill\", [\"/pid\", String(child.pid), \"/t\", \"/f\"], {\n\t\t\t\t\tstdio: \"ignore\",\n\t\t\t\t\twindowsHide: true,\n\t\t\t\t});\n\t\t\t\tkiller.on(\"error\", () => undefined);\n\t\t\t\tkiller.unref();\n\t\t\t}\n\t\t}\n\t\tescalationTimer = setTimeout(() => {\n\t\t\tif (settled) return;\n\t\t\tif (child.pid && process.platform !== \"win32\") {\n\t\t\t\ttry {\n\t\t\t\t\tprocess.kill(-child.pid, \"SIGKILL\");\n\t\t\t\t} catch {\n\t\t\t\t\tchild.kill(\"SIGKILL\");\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tchild.kill(\"SIGKILL\");\n\t\t\t}\n\t\t}, 2_000);\n\t};\n\tconst collect = (target: Buffer[]) => (chunk: Buffer) => {\n\t\ttotal += chunk.byteLength;\n\t\tif (total > limit) {\n\t\t\tterminate(new Error(`Git output exceeds the ${limit}-byte limit.`));\n\t\t\treturn;\n\t\t}\n\t\ttarget.push(Buffer.from(chunk));\n\t};\n\tchild.stdout.on(\"data\", collect(stdout));\n\tchild.stderr.on(\"data\", collect(stderr));\n\tchild.stdin.on(\"error\", () => undefined);\n\tchild.stdin.end(options.input);\n\tconst onAbort = () =>\n\t\tterminate(\n\t\t\toptions.signal?.reason instanceof Error\n\t\t\t\t? options.signal.reason\n\t\t\t\t: new DOMException(\"The operation was aborted\", \"AbortError\"),\n\t\t);\n\toptions.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\tconst timer = setTimeout(\n\t\t() =>\n\t\t\tterminate(\n\t\t\t\tnew Error(`Git command timed out after ${options.timeoutMs ?? DEFAULT_TIMEOUT_MS}ms.`),\n\t\t\t),\n\t\toptions.timeoutMs ?? DEFAULT_TIMEOUT_MS,\n\t);\n\n\tlet result: GitRunResult;\n\ttry {\n\t\tresult = await new Promise<GitRunResult>((resolve, reject) => {\n\t\t\tchild.once(\"error\", reject);\n\t\t\tchild.once(\"close\", (code) => {\n\t\t\t\tsettled = true;\n\t\t\t\tif (escalationTimer) clearTimeout(escalationTimer);\n\t\t\t\tconst stdoutBuffer = Buffer.concat(stdout);\n\t\t\t\tconst stderrBuffer = Buffer.concat(stderr);\n\t\t\t\tif (terminationError) {\n\t\t\t\t\treject(terminationError);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (code !== 0) {\n\t\t\t\t\tconst stderrText = stderrBuffer.toString(\"utf8\").trim();\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew GitCommandError(\n\t\t\t\t\t\t\tstderrText || `Git exited with status ${code ?? \"unknown\"}.`,\n\t\t\t\t\t\t\tcode,\n\t\t\t\t\t\t\tstderrText,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tresolve({ stdout: stdoutBuffer, stderr: stderrBuffer });\n\t\t\t});\n\t\t});\n\t} finally {\n\t\tclearTimeout(timer);\n\t\tif (escalationTimer) clearTimeout(escalationTimer);\n\t\toptions.signal?.removeEventListener(\"abort\", onAbort);\n\t}\n\treturn result;\n}\n\nexport function parseGitBlobBatch(output: Buffer, expectedCount: number, maxContentBytes: number) {\n\tif (!Number.isSafeInteger(expectedCount) || expectedCount < 0) {\n\t\tthrow new Error(\"Invalid Git batch object count.\");\n\t}\n\tif (!Number.isSafeInteger(maxContentBytes) || maxContentBytes < 0) {\n\t\tthrow new Error(\"Invalid Git batch content limit.\");\n\t}\n\tconst blobs: Buffer[] = [];\n\tlet offset = 0;\n\tlet contentBytes = 0;\n\tfor (let index = 0; index < expectedCount; index += 1) {\n\t\tconst headerEnd = output.indexOf(0x0a, offset);\n\t\tif (headerEnd < 0) throw new Error(\"Git cat-file batch response is truncated.\");\n\t\tconst header = output.subarray(offset, headerEnd).toString(\"utf8\");\n\t\tif (header.endsWith(\" missing\")) throw new Error(\"Git cat-file batch object is missing.\");\n\t\tconst match = /^(?<object>[0-9a-f]{40}) blob (?<size>0|[1-9][0-9]*)$/u.exec(header);\n\t\tif (!match?.groups) throw new Error(\"Git cat-file batch response is malformed.\");\n\t\tconst size = Number(match.groups.size);\n\t\tif (!Number.isSafeInteger(size)) throw new Error(\"Git cat-file batch size is malformed.\");\n\t\tcontentBytes += size;\n\t\tif (contentBytes > maxContentBytes) {\n\t\t\tthrow new Error(`Git cat-file batch content exceeds the ${maxContentBytes}-byte limit.`);\n\t\t}\n\t\tconst contentStart = headerEnd + 1;\n\t\tconst contentEnd = contentStart + size;\n\t\tif (contentEnd >= output.length) throw new Error(\"Git cat-file batch response is truncated.\");\n\t\tif (output[contentEnd] !== 0x0a) {\n\t\t\tthrow new Error(\"Git cat-file batch response is malformed.\");\n\t\t}\n\t\tblobs.push(Buffer.from(output.subarray(contentStart, contentEnd)));\n\t\toffset = contentEnd + 1;\n\t}\n\tif (offset !== output.length) throw new Error(\"Git cat-file batch response has trailing data.\");\n\treturn blobs;\n}\n\nexport async function readGitBlobs(\n\tobjects: string[],\n\toptions: Omit<GitRunOptions, \"input\" | \"maxOutputBytes\"> & { maxOutputBytes: number },\n) {\n\tif (objects.length === 0) return [];\n\tif (!Number.isSafeInteger(options.maxOutputBytes) || options.maxOutputBytes < 0) {\n\t\tthrow new Error(\"Invalid Git batch output limit.\");\n\t}\n\tif (objects.some((object) => !/^[0-9a-f]{40}$/u.test(object))) {\n\t\tthrow new Error(\"Invalid Git blob object id.\");\n\t}\n\tconst protocolOverhead = objects.length * 96;\n\tif (!Number.isSafeInteger(protocolOverhead + options.maxOutputBytes)) {\n\t\tthrow new Error(\"Invalid Git batch output limit.\");\n\t}\n\tconst result = await runGit([\"cat-file\", \"--batch\"], {\n\t\t...options,\n\t\tinput: `${objects.join(\"\\n\")}\\n`,\n\t\tmaxOutputBytes: options.maxOutputBytes + protocolOverhead,\n\t});\n\treturn parseGitBlobBatch(result.stdout, objects.length, options.maxOutputBytes);\n}\n\nfunction throwIfAborted(signal?: AbortSignal) {\n\tif (!signal?.aborted) return;\n\tthrow signal.reason instanceof Error\n\t\t? signal.reason\n\t\t: new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n", "import { createHash } from \"node:crypto\";\nimport { portableSnapshotSelection, snapshotSelectionInclude } from \"./sync-policy.js\";\nimport type { Snapshot, SnapshotSelection } from \"./types.js\";\n\nexport const GIT_MANIFEST_VERSION = 2;\nexport const MAX_GIT_MANIFEST_BYTES = 1024 * 1024;\nexport const MAX_GIT_TREE_OUTPUT_BYTES = 16 * 1024 * 1024;\nexport const MAX_GIT_PAYLOAD_BYTES = 100 * 1024 * 1024;\nexport const MAX_GIT_SNAPSHOT_BYTES = 512 * 1024 * 1024;\nconst SNAPSHOT_VERSION = 1;\n\nexport interface GitManifestFile {\n\tpath: string;\n\tsha256: string;\n\tsize: number;\n}\n\nexport interface GitManifest {\n\tversion: number;\n\tsnapshotVersion: number;\n\tsnapshotId: string;\n\tcreatedAt: string;\n\tmachine: string;\n\tprofile: string;\n\tsyncSessions: boolean;\n\tsnapshotSyncSessions?: boolean;\n\tselection?: SnapshotSelection;\n\tfiles: GitManifestFile[];\n}\n\nexport interface PreparedGitFile extends GitManifestFile {\n\tcontent: Buffer;\n}\n\nexport interface GitTreeEntry {\n\tmode: string;\n\ttype: string;\n\tobject: string;\n\tpath: string;\n}\n\nexport function isGitPayloadSizeAllowed(size: number) {\n\treturn Number.isSafeInteger(size) && size >= 0 && size <= MAX_GIT_PAYLOAD_BYTES;\n}\n\nexport function requireGitManifest(value: unknown): GitManifest {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) {\n\t\tthrow new Error(\"Git publication manifest is malformed.\");\n\t}\n\tconst manifest = value as Partial<GitManifest>;\n\tif (manifest.version === 1) {\n\t\tthrow new Error(\n\t\t\t\"Git publication uses the unsupported pre-release gzip format; recreate this pi-sync-owned test branch.\",\n\t\t);\n\t}\n\tif (\n\t\tmanifest.version !== GIT_MANIFEST_VERSION ||\n\t\tmanifest.snapshotVersion !== SNAPSHOT_VERSION ||\n\t\ttypeof manifest.snapshotId !== \"string\" ||\n\t\tmanifest.snapshotId.length > 512 ||\n\t\t!/^[A-Za-z0-9._-]+$/u.test(manifest.snapshotId) ||\n\t\ttypeof manifest.createdAt !== \"string\" ||\n\t\tmanifest.createdAt.length > 64 ||\n\t\thasControlCharacter(manifest.createdAt) ||\n\t\tNumber.isNaN(Date.parse(manifest.createdAt)) ||\n\t\ttypeof manifest.machine !== \"string\" ||\n\t\tmanifest.machine.length > 256 ||\n\t\thasControlCharacter(manifest.machine) ||\n\t\ttypeof manifest.profile !== \"string\" ||\n\t\tmanifest.profile.length === 0 ||\n\t\tmanifest.profile.length > 256 ||\n\t\thasControlCharacter(manifest.profile) ||\n\t\ttypeof manifest.syncSessions !== \"boolean\" ||\n\t\t(manifest.snapshotSyncSessions !== undefined &&\n\t\t\ttypeof manifest.snapshotSyncSessions !== \"boolean\") ||\n\t\t!Array.isArray(manifest.files) ||\n\t\t!hasExactKeys(manifest as Record<string, unknown>, [\n\t\t\t\"version\",\n\t\t\t\"snapshotVersion\",\n\t\t\t\"snapshotId\",\n\t\t\t\"createdAt\",\n\t\t\t\"machine\",\n\t\t\t\"profile\",\n\t\t\t\"syncSessions\",\n\t\t\t...(manifest.snapshotSyncSessions === undefined ? [] : [\"snapshotSyncSessions\"]),\n\t\t\t...(manifest.selection === undefined ? [] : [\"selection\"]),\n\t\t\t\"files\",\n\t\t])\n\t) {\n\t\tthrow new Error(\"Git publication manifest is malformed.\");\n\t}\n\tif (manifest.selection !== undefined) portableSnapshotSelection(manifest.selection);\n\tlet total = 0;\n\tconst paths = new Set<string>();\n\tfor (const rawFile of manifest.files) {\n\t\tif (!rawFile || typeof rawFile !== \"object\" || Array.isArray(rawFile)) {\n\t\t\tthrow new Error(\"Git publication manifest file is malformed.\");\n\t\t}\n\t\tconst file = rawFile as Partial<GitManifestFile>;\n\t\tif (\n\t\t\t!hasExactKeys(file as Record<string, unknown>, [\"path\", \"sha256\", \"size\"]) ||\n\t\t\t!isSafeSnapshotPath(file.path) ||\n\t\t\ttypeof file.sha256 !== \"string\" ||\n\t\t\t!/^[0-9a-f]{64}$/u.test(file.sha256) ||\n\t\t\ttypeof file.size !== \"number\" ||\n\t\t\t!isGitPayloadSizeAllowed(file.size) ||\n\t\t\tpaths.has(file.path)\n\t\t) {\n\t\t\tthrow new Error(\"Git publication manifest file is malformed.\");\n\t\t}\n\t\ttotal += file.size;\n\t\tif (!Number.isSafeInteger(total) || total > MAX_GIT_SNAPSHOT_BYTES) {\n\t\t\tthrow new Error(`Git snapshot content exceeds the ${MAX_GIT_SNAPSHOT_BYTES}-byte limit.`);\n\t\t}\n\t\tpaths.add(file.path);\n\t}\n\tassertNoPathConflicts([...paths]);\n\treturn manifest as GitManifest;\n}\n\nexport function validateGitSnapshot(snapshot: Snapshot, manifest: GitManifest, namespace: string) {\n\tconst prepared = prepareGitSnapshot(snapshot, namespace);\n\tconst syncSessions =\n\t\tsnapshot.syncSessions === true ||\n\t\tsnapshot.files.some((file) => file.path.startsWith(\"sessions/\"));\n\tif (\n\t\tsnapshot.id !== manifest.snapshotId ||\n\t\tsnapshot.createdAt !== manifest.createdAt ||\n\t\tsnapshot.machine !== manifest.machine ||\n\t\tsnapshot.profile !== manifest.profile ||\n\t\tsnapshot.syncSessions !== manifest.snapshotSyncSessions ||\n\t\tsyncSessions !== manifest.syncSessions ||\n\t\t!sameOptionalInclude(\n\t\t\tsnapshotSelectionInclude(snapshot),\n\t\t\tmanifest.selection === undefined\n\t\t\t\t? undefined\n\t\t\t\t: portableSnapshotSelection(manifest.selection).include,\n\t\t) ||\n\t\tprepared.length !== manifest.files.length ||\n\t\tprepared.some((file, index) => {\n\t\t\tconst expected = manifest.files[index];\n\t\t\treturn (\n\t\t\t\t!expected ||\n\t\t\t\tfile.path !== expected.path ||\n\t\t\t\tfile.sha256 !== expected.sha256 ||\n\t\t\t\tfile.size !== expected.size\n\t\t\t);\n\t\t})\n\t) {\n\t\tthrow new Error(\"Git snapshot identity does not match its publication manifest.\");\n\t}\n}\n\nexport function prepareGitSnapshot(snapshot: Snapshot, namespace: string) {\n\tsnapshotSelectionInclude(snapshot);\n\tif (\n\t\tsnapshot.version !== SNAPSHOT_VERSION ||\n\t\ttypeof snapshot.id !== \"string\" ||\n\t\t!snapshot.id ||\n\t\tsnapshot.id.length > 512 ||\n\t\t!/^[A-Za-z0-9._-]+$/u.test(snapshot.id) ||\n\t\tsnapshot.profile !== namespace ||\n\t\t!Array.isArray(snapshot.files) ||\n\t\ttypeof snapshot.createdAt !== \"string\" ||\n\t\t!snapshot.createdAt ||\n\t\tsnapshot.createdAt.length > 64 ||\n\t\thasControlCharacter(snapshot.createdAt) ||\n\t\tNumber.isNaN(Date.parse(snapshot.createdAt)) ||\n\t\ttypeof snapshot.machine !== \"string\" ||\n\t\tsnapshot.machine.length > 256 ||\n\t\thasControlCharacter(snapshot.machine)\n\t) {\n\t\tthrow new Error(\"Invalid Git snapshot publication.\");\n\t}\n\tconst paths = new Set<string>();\n\tconst prepared: PreparedGitFile[] = [];\n\tlet total = 0;\n\tfor (const file of snapshot.files) {\n\t\tif (\n\t\t\t!isSafeSnapshotPath(file.path) ||\n\t\t\ttypeof file.contentBase64 !== \"string\" ||\n\t\t\ttypeof file.sha256 !== \"string\" ||\n\t\t\t!/^[0-9a-f]{64}$/u.test(file.sha256) ||\n\t\t\tpaths.has(file.path)\n\t\t) {\n\t\t\tthrow new Error(\"Invalid Git snapshot file.\");\n\t\t}\n\t\tconst content = Buffer.from(file.contentBase64, \"base64\");\n\t\tif (content.toString(\"base64\") !== file.contentBase64 || sha256(content) !== file.sha256) {\n\t\t\tthrow new Error(\"Git snapshot file checksum mismatch.\");\n\t\t}\n\t\tif (!isGitPayloadSizeAllowed(content.byteLength)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Git snapshot file exceeds GitHub's ${MAX_GIT_PAYLOAD_BYTES}-byte regular-Git limit: ${file.path}`,\n\t\t\t);\n\t\t}\n\t\ttotal += content.byteLength;\n\t\tif (!Number.isSafeInteger(total) || total > MAX_GIT_SNAPSHOT_BYTES) {\n\t\t\tthrow new Error(`Git snapshot content exceeds the ${MAX_GIT_SNAPSHOT_BYTES}-byte limit.`);\n\t\t}\n\t\tpaths.add(file.path);\n\t\tprepared.push({ path: file.path, sha256: file.sha256, size: content.byteLength, content });\n\t}\n\tassertNoPathConflicts([...paths]);\n\treturn prepared;\n}\n\nexport function parseGitTree(output: Buffer): GitTreeEntry[] {\n\tif (output.byteLength === 0) return [];\n\tif (output.at(-1) !== 0) throw new Error(\"Git publication tree response is malformed.\");\n\treturn output\n\t\t.subarray(0, -1)\n\t\t.toString(\"utf8\")\n\t\t.split(\"\\0\")\n\t\t.map((line) => {\n\t\t\tconst match =\n\t\t\t\t/^(?<mode>[0-9]{6}) (?<type>blob|tree|commit) (?<object>[0-9a-f]{40})\\t(?<path>.+)$/u.exec(\n\t\t\t\t\tline,\n\t\t\t\t);\n\t\t\tif (!match?.groups || hasControlCharacter(match.groups.path)) {\n\t\t\t\tthrow new Error(\"Git publication tree response is malformed.\");\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tmode: match.groups.mode,\n\t\t\t\ttype: match.groups.type,\n\t\t\t\tobject: match.groups.object,\n\t\t\t\tpath: match.groups.path,\n\t\t\t};\n\t\t});\n}\n\nexport function validateGitPublicationTree(\n\tentries: GitTreeEntry[],\n\tmanifest: GitManifest,\n\tmanifestPath: string,\n\tfilePath: (path: string) => string,\n) {\n\tconst byPath = new Map<string, GitTreeEntry>();\n\tfor (const entry of entries) {\n\t\tif (byPath.has(entry.path)) throw new Error(\"Git publication tree contains duplicate paths.\");\n\t\tbyPath.set(entry.path, entry);\n\t}\n\tconst expectedPaths = [manifestPath, ...manifest.files.map((file) => filePath(file.path))];\n\tif (entries.length !== expectedPaths.length || expectedPaths.some((path) => !byPath.has(path))) {\n\t\tthrow new Error(\"Git publication tree has missing or extra files.\");\n\t}\n\tfor (const expectedPath of expectedPaths) {\n\t\tconst entry = byPath.get(expectedPath);\n\t\tif (entry?.mode !== \"100644\" || entry.type !== \"blob\") {\n\t\t\tthrow new Error(`Git publication tree contains a non-regular file: ${expectedPath}`);\n\t\t}\n\t}\n\treturn manifest.files.map((file) => byPath.get(filePath(file.path)) as GitTreeEntry);\n}\n\nfunction sameOptionalInclude(left: string[] | undefined, right: string[] | undefined) {\n\tif (!left || !right) return left === right;\n\treturn left.length === right.length && left.every((item, index) => item === right[index]);\n}\n\nfunction isSafeSnapshotPath(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\tvalue.length > 0 &&\n\t\tvalue.length <= 4096 &&\n\t\t!value.startsWith(\"/\") &&\n\t\t!value.includes(\"\\\\\") &&\n\t\t!hasControlCharacter(value) &&\n\t\tvalue\n\t\t\t.split(\"/\")\n\t\t\t.every(\n\t\t\t\t(segment) =>\n\t\t\t\t\tsegment && segment !== \".\" && segment !== \"..\" && segment.toLowerCase() !== \".git\",\n\t\t\t)\n\t);\n}\n\nfunction hasExactKeys(value: Record<string, unknown>, expected: string[]) {\n\tconst keys = Object.keys(value).sort();\n\tconst expectedKeys = [...expected].sort();\n\treturn (\n\t\tkeys.length === expectedKeys.length && keys.every((key, index) => key === expectedKeys[index])\n\t);\n}\n\nfunction assertNoPathConflicts(paths: string[]) {\n\tconst sorted = [...paths].sort();\n\tfor (let index = 1; index < sorted.length; index += 1) {\n\t\tconst parent = sorted[index - 1];\n\t\tconst child = sorted[index];\n\t\tif (parent && child?.startsWith(`${parent}/`)) {\n\t\t\tthrow new Error(`Git snapshot file path conflict: ${parent} and ${child}`);\n\t\t}\n\t}\n}\n\nfunction sha256(value: Buffer) {\n\treturn createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\nfunction hasControlCharacter(value: string) {\n\t// biome-ignore lint/suspicious/noControlCharactersInRegex: Reject untrusted terminal/ref controls.\n\treturn /[\\u0000-\\u001f\\u007f-\\u009f]/u.test(value);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,cAAAA,aAAY,kBAAkB;AACvC,OAAO,QAAQ;AACf,OAAO,UAAU;;;ACFjB,SAAS,aAAa;AACtB,OAAOC,cAAa;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AAI;AAEjB;AAEA,SAASC,QAAO,OAAe;AAC9B,SAAOC,YAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AACvD;AAEA,SAAS,YAAY,QAAqB;AACzC,SAAO,OAAO,kBAAkB,QAC7B,OAAO,SACP,IAAI,aAAa,6BAA6B,YAAY;AAC9D;AAEA,SAASF,gBAAe,QAAsB;AAC7C,MAAI,QAAQ,QAAS,OAAM,YAAY,MAAM;AAC9C;",
6
- "names": ["createHash", "process", "path", "throwIfAborted", "sha256", "createHash"]
7
- }
@@ -1,18 +0,0 @@
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
- dispatchManagerResult
5
- } from "./chunk-LONPFFNP.ts";
6
- import "./chunk-5WJNWFTG.ts";
7
- import "./chunk-4F3W4CSC.ts";
8
- import "./chunk-FR6CVXAL.ts";
9
- import "./chunk-W64NEHXT.ts";
10
- import "./chunk-RGJ6SOYR.ts";
11
- import "./chunk-EWX3TPLQ.ts";
12
- import "./chunk-APZVBSM6.ts";
13
- import "./chunk-F5QL2GPY.ts";
14
- import "./chunk-YQ6UW7IF.ts";
15
- export {
16
- dispatchManagerResult
17
- };
18
- //# sourceMappingURL=manager-result-dispatcher-RNRQA3PW.ts.map