@narumitw/pi-sync 0.50.3 → 0.51.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/README.md +4 -1
  2. package/dist/chunks/{chunk-6LP3MCR2.ts → chunk-2JZFHNLM.ts} +3 -5
  3. package/dist/chunks/chunk-2JZFHNLM.ts.map +7 -0
  4. package/dist/chunks/{chunk-LCRI3ABW.ts → chunk-2RZSQWBH.ts} +8 -19
  5. package/dist/chunks/chunk-2RZSQWBH.ts.map +7 -0
  6. package/dist/chunks/{chunk-IJ6FJFA5.ts → chunk-4AIHXRKE.ts} +11 -17
  7. package/dist/chunks/chunk-4AIHXRKE.ts.map +7 -0
  8. package/dist/chunks/{chunk-C7XY5NF5.ts → chunk-4MPIH46N.ts} +29 -51
  9. package/dist/chunks/chunk-4MPIH46N.ts.map +7 -0
  10. package/dist/chunks/{chunk-5B3FXBLE.ts → chunk-6546TS54.ts} +16 -20
  11. package/dist/chunks/chunk-6546TS54.ts.map +7 -0
  12. package/dist/chunks/{chunk-Q2TUM5X6.ts → chunk-6NT3YFGY.ts} +2 -2
  13. package/dist/chunks/chunk-6NT3YFGY.ts.map +7 -0
  14. package/dist/chunks/{chunk-2B2ELUF5.ts → chunk-7D5SF7P3.ts} +1 -1
  15. package/dist/chunks/chunk-7D5SF7P3.ts.map +7 -0
  16. package/dist/chunks/{chunk-YDWUZVPN.ts → chunk-7KHKWL3Q.ts} +28 -47
  17. package/dist/chunks/chunk-7KHKWL3Q.ts.map +7 -0
  18. package/dist/chunks/{chunk-ZI5MXMEX.ts → chunk-BVVP33U5.ts} +2 -4
  19. package/dist/chunks/chunk-BVVP33U5.ts.map +7 -0
  20. package/dist/chunks/{chunk-SZWBGPID.ts → chunk-DM4X4FIA.ts} +8 -13
  21. package/dist/chunks/chunk-DM4X4FIA.ts.map +7 -0
  22. package/dist/chunks/{chunk-SL64RLXR.ts → chunk-DZUSTGQV.ts} +8 -16
  23. package/dist/chunks/chunk-DZUSTGQV.ts.map +7 -0
  24. package/dist/chunks/{chunk-YHEMENKV.ts → chunk-E42GXD6D.ts} +13 -19
  25. package/dist/chunks/chunk-E42GXD6D.ts.map +7 -0
  26. package/dist/chunks/{chunk-Z4DQF6L3.ts → chunk-ECYCNZOE.ts} +1 -1
  27. package/dist/chunks/chunk-ECYCNZOE.ts.map +7 -0
  28. package/dist/chunks/{chunk-OEX4ABY6.ts → chunk-EEJPYTWE.ts} +11 -21
  29. package/dist/chunks/chunk-EEJPYTWE.ts.map +7 -0
  30. package/dist/chunks/{chunk-CPEHGXJV.ts → chunk-G4RUXRWZ.ts} +3 -5
  31. package/dist/chunks/chunk-G4RUXRWZ.ts.map +7 -0
  32. package/dist/chunks/{chunk-T2B5IU74.ts → chunk-HGJH56KR.ts} +4 -4
  33. package/dist/chunks/chunk-HGJH56KR.ts.map +7 -0
  34. package/dist/chunks/{chunk-JAAKLL6M.ts → chunk-IVXEDPAD.ts} +10 -34
  35. package/dist/chunks/chunk-IVXEDPAD.ts.map +7 -0
  36. package/dist/chunks/chunk-K3RIEL6J.ts +20 -0
  37. package/dist/chunks/chunk-K3RIEL6J.ts.map +7 -0
  38. package/dist/chunks/{chunk-LTBWGSBV.ts → chunk-MSSW6F3R.ts} +1 -1
  39. package/dist/chunks/chunk-MSSW6F3R.ts.map +7 -0
  40. package/dist/chunks/{chunk-T3HH3UEJ.ts → chunk-OVDTF5CH.ts} +4 -10
  41. package/dist/chunks/chunk-OVDTF5CH.ts.map +7 -0
  42. package/dist/chunks/{chunk-NJFUIVYL.ts → chunk-PWMWOJP4.ts} +1 -1
  43. package/dist/chunks/chunk-PWMWOJP4.ts.map +7 -0
  44. package/dist/chunks/{chunk-HUDQATCL.ts → chunk-Q32CQWPM.ts} +6 -8
  45. package/dist/chunks/chunk-Q32CQWPM.ts.map +7 -0
  46. package/dist/chunks/{chunk-ETTRJDNP.ts → chunk-QLSN7AGX.ts} +6 -13
  47. package/dist/chunks/chunk-QLSN7AGX.ts.map +7 -0
  48. package/dist/chunks/{chunk-THMF4BVL.ts → chunk-SWUXA3MH.ts} +1 -1
  49. package/dist/chunks/chunk-SWUXA3MH.ts.map +7 -0
  50. package/dist/chunks/{chunk-TEN2ZBJV.ts → chunk-T2SJD3N7.ts} +2 -4
  51. package/dist/chunks/chunk-T2SJD3N7.ts.map +7 -0
  52. package/dist/chunks/{chunk-AUSDLD6F.ts → chunk-T56RNRZJ.ts} +10 -26
  53. package/dist/chunks/chunk-T56RNRZJ.ts.map +7 -0
  54. package/dist/chunks/{chunk-DHVFS4QK.ts → chunk-UA7RXOIT.ts} +37 -90
  55. package/dist/chunks/chunk-UA7RXOIT.ts.map +7 -0
  56. package/dist/chunks/{chunk-D5X27LCA.ts → chunk-UETBKTDI.ts} +1 -1
  57. package/dist/chunks/chunk-UETBKTDI.ts.map +7 -0
  58. package/dist/chunks/{chunk-CHH26D4F.ts → chunk-YFADF5ZQ.ts} +7 -6
  59. package/dist/chunks/chunk-YFADF5ZQ.ts.map +7 -0
  60. package/dist/chunks/{chunk-CCSN3F47.ts → chunk-YPXGU5OR.ts} +4 -4
  61. package/dist/chunks/chunk-YPXGU5OR.ts.map +7 -0
  62. package/dist/chunks/{file-selection-FTTKAOYX.ts → file-selection-RAVHRYFG.ts} +14 -26
  63. package/dist/chunks/file-selection-RAVHRYFG.ts.map +7 -0
  64. package/dist/chunks/{git-backend-GMVS4PD4.ts → git-backend-IAANDL3K.ts} +41 -104
  65. package/dist/chunks/git-backend-IAANDL3K.ts.map +7 -0
  66. package/dist/chunks/manager-result-dispatcher-OTUMQM26.ts +23 -0
  67. package/dist/chunks/{manager-ui-IPAOAWZA.ts → manager-ui-763NEKJY.ts} +124 -251
  68. package/dist/chunks/manager-ui-763NEKJY.ts.map +7 -0
  69. package/dist/chunks/remote-selection-ui-TZTJF32Y.ts +22 -0
  70. package/dist/chunks/{s3-backend-66O4FGBH.ts → s3-backend-XGXUOPUN.ts} +23 -54
  71. package/dist/chunks/s3-backend-XGXUOPUN.ts.map +7 -0
  72. package/dist/chunks/{setup-switch-IS2PEZ3J.ts → setup-switch-5G2VNJHL.ts} +9 -9
  73. package/dist/chunks/{setup-wizard-JUJZYNNM.ts → setup-wizard-YIEWGX32.ts} +12 -12
  74. package/dist/chunks/setup-wizard-YIEWGX32.ts.map +7 -0
  75. package/dist/chunks/{snapshot-HKEWCVK6.ts → snapshot-JL5DFSXI.ts} +5 -5
  76. package/dist/chunks/sync-inspection-P3ENJLNF.ts +20 -0
  77. package/dist/chunks/{sync-operations-LBX3GKCM.ts → sync-operations-AR76EB6C.ts} +85 -201
  78. package/dist/chunks/sync-operations-AR76EB6C.ts.map +7 -0
  79. package/dist/chunks/{sync-state-Q2FTXTW6.ts → sync-state-VHJUZ4YG.ts} +6 -6
  80. package/dist/chunks/{webdav-backend-ECIKD7SO.ts → webdav-backend-3EGUONAT.ts} +20 -51
  81. package/dist/chunks/webdav-backend-3EGUONAT.ts.map +7 -0
  82. package/dist/index.ts +49 -74
  83. package/dist/index.ts.map +3 -3
  84. package/docs/settings.md +9 -0
  85. package/package.json +61 -62
  86. package/src/backends/backend-factory.ts +15 -15
  87. package/src/backends/backend-identity.ts +31 -31
  88. package/src/backends/backend-types.ts +42 -42
  89. package/src/backends/git/git-backend.ts +714 -788
  90. package/src/backends/git/git-config.ts +104 -111
  91. package/src/backends/git/git-runner.ts +230 -247
  92. package/src/backends/git/git-storage.ts +228 -245
  93. package/src/backends/s3/s3-backend.ts +408 -441
  94. package/src/backends/s3/s3-client.ts +288 -333
  95. package/src/backends/sync-backend.ts +65 -65
  96. package/src/backends/webdav/webdav-backend.ts +542 -589
  97. package/src/backends/webdav/webdav-client.ts +292 -316
  98. package/src/backends/webdav/webdav-config.ts +57 -68
  99. package/src/commands/command-execution.ts +270 -289
  100. package/src/commands/command-handler.ts +160 -163
  101. package/src/commands/command-types.ts +13 -13
  102. package/src/commands/command.ts +190 -196
  103. package/src/commands/setup-completions.ts +1 -1
  104. package/src/paths.ts +47 -47
  105. package/src/settings/config-errors.ts +4 -5
  106. package/src/settings/config-file.ts +473 -506
  107. package/src/settings/config.ts +171 -174
  108. package/src/settings/settings-management.ts +191 -216
  109. package/src/settings/settings-store.ts +63 -77
  110. package/src/settings/settings-types.ts +78 -75
  111. package/src/settings/settings-validation.ts +328 -364
  112. package/src/snapshot/session-paths.ts +41 -55
  113. package/src/snapshot/snapshot-apply.ts +197 -229
  114. package/src/snapshot/snapshot-codec.ts +29 -31
  115. package/src/snapshot/snapshot-paths.ts +4 -6
  116. package/src/snapshot/snapshot-transaction.ts +161 -170
  117. package/src/snapshot/snapshot-types.ts +24 -24
  118. package/src/snapshot/snapshot.ts +310 -343
  119. package/src/state/json-file.ts +11 -11
  120. package/src/state/lock.ts +226 -242
  121. package/src/state/lockfile-fs.ts +20 -20
  122. package/src/state/operation-availability.ts +36 -41
  123. package/src/state/state-directory.ts +171 -173
  124. package/src/state/state-types.ts +15 -15
  125. package/src/state/sync-state-store.ts +23 -23
  126. package/src/sync/automatic-sync.ts +75 -80
  127. package/src/sync/remote-snapshot.ts +52 -60
  128. package/src/sync/setup-switch.ts +99 -114
  129. package/src/sync/signals.ts +3 -5
  130. package/src/sync/startup-check.ts +97 -111
  131. package/src/sync/sync-decision.ts +76 -80
  132. package/src/sync/sync-error-guidance.ts +41 -48
  133. package/src/sync/sync-errors.ts +10 -10
  134. package/src/sync/sync-inspection.ts +29 -33
  135. package/src/sync/sync-loaders.ts +28 -36
  136. package/src/sync/sync-mutations.ts +510 -622
  137. package/src/sync/sync-operations.ts +7 -7
  138. package/src/sync/sync-policy.ts +296 -326
  139. package/src/sync/sync-queries.ts +175 -194
  140. package/src/sync/sync-state.ts +74 -100
  141. package/src/sync-extension.ts +89 -101
  142. package/src/sync.ts +26 -26
  143. package/src/types.ts +37 -37
  144. package/src/ui/automatic-sync-summary.ts +1 -3
  145. package/src/ui/cancellable-operation.ts +89 -101
  146. package/src/ui/file-selection.ts +250 -274
  147. package/src/ui/manager-attention.ts +51 -63
  148. package/src/ui/manager-recovery.ts +48 -57
  149. package/src/ui/manager-result-dispatcher.ts +62 -76
  150. package/src/ui/manager-state.ts +200 -232
  151. package/src/ui/manager-ui.ts +264 -362
  152. package/src/ui/remote-selection-ui.ts +547 -588
  153. package/src/ui/secret-input.ts +197 -205
  154. package/src/ui/settings-ui.ts +175 -172
  155. package/src/ui/setup/git-ui.ts +232 -261
  156. package/src/ui/setup/s3-credentials-ui.ts +58 -65
  157. package/src/ui/setup/s3-ui.ts +171 -195
  158. package/src/ui/setup/setup-actions.ts +91 -101
  159. package/src/ui/setup/setup-location-ui.ts +121 -137
  160. package/src/ui/setup/setup-name-ui.ts +27 -27
  161. package/src/ui/setup/setup-prompts.ts +65 -65
  162. package/src/ui/setup/setup-review.ts +58 -59
  163. package/src/ui/setup/setup-switcher.ts +156 -160
  164. package/src/ui/setup/setup-wizard.ts +28 -28
  165. package/src/ui/setup/text-input.ts +54 -58
  166. package/src/ui/setup/webdav-ui.ts +246 -293
  167. package/src/ui/storage-connections-ui.ts +317 -369
  168. package/src/ui/sync-attention.ts +148 -164
  169. package/src/ui/sync-format.ts +110 -121
  170. package/src/ui/sync-resolution-ui.ts +147 -153
  171. package/src/ui/sync-setups-ui.ts +218 -238
  172. package/src/ui/sync-status.ts +17 -0
  173. package/src/ui/terminal-text.ts +2 -2
  174. package/dist/chunks/chunk-2B2ELUF5.ts.map +0 -7
  175. package/dist/chunks/chunk-5B3FXBLE.ts.map +0 -7
  176. package/dist/chunks/chunk-6LP3MCR2.ts.map +0 -7
  177. package/dist/chunks/chunk-AUSDLD6F.ts.map +0 -7
  178. package/dist/chunks/chunk-C7XY5NF5.ts.map +0 -7
  179. package/dist/chunks/chunk-CCSN3F47.ts.map +0 -7
  180. package/dist/chunks/chunk-CHH26D4F.ts.map +0 -7
  181. package/dist/chunks/chunk-CPEHGXJV.ts.map +0 -7
  182. package/dist/chunks/chunk-D5X27LCA.ts.map +0 -7
  183. package/dist/chunks/chunk-DHVFS4QK.ts.map +0 -7
  184. package/dist/chunks/chunk-ETTRJDNP.ts.map +0 -7
  185. package/dist/chunks/chunk-HUDQATCL.ts.map +0 -7
  186. package/dist/chunks/chunk-IJ6FJFA5.ts.map +0 -7
  187. package/dist/chunks/chunk-JAAKLL6M.ts.map +0 -7
  188. package/dist/chunks/chunk-LCRI3ABW.ts.map +0 -7
  189. package/dist/chunks/chunk-LTBWGSBV.ts.map +0 -7
  190. package/dist/chunks/chunk-NJFUIVYL.ts.map +0 -7
  191. package/dist/chunks/chunk-OEX4ABY6.ts.map +0 -7
  192. package/dist/chunks/chunk-Q2TUM5X6.ts.map +0 -7
  193. package/dist/chunks/chunk-SL64RLXR.ts.map +0 -7
  194. package/dist/chunks/chunk-SZWBGPID.ts.map +0 -7
  195. package/dist/chunks/chunk-T2B5IU74.ts.map +0 -7
  196. package/dist/chunks/chunk-T3HH3UEJ.ts.map +0 -7
  197. package/dist/chunks/chunk-TEN2ZBJV.ts.map +0 -7
  198. package/dist/chunks/chunk-THMF4BVL.ts.map +0 -7
  199. package/dist/chunks/chunk-YDWUZVPN.ts.map +0 -7
  200. package/dist/chunks/chunk-YHEMENKV.ts.map +0 -7
  201. package/dist/chunks/chunk-Z4DQF6L3.ts.map +0 -7
  202. package/dist/chunks/chunk-ZI5MXMEX.ts.map +0 -7
  203. package/dist/chunks/file-selection-FTTKAOYX.ts.map +0 -7
  204. package/dist/chunks/git-backend-GMVS4PD4.ts.map +0 -7
  205. package/dist/chunks/manager-result-dispatcher-ASKGOSW5.ts +0 -22
  206. package/dist/chunks/manager-ui-IPAOAWZA.ts.map +0 -7
  207. package/dist/chunks/remote-selection-ui-QDNR7WEI.ts +0 -21
  208. package/dist/chunks/s3-backend-66O4FGBH.ts.map +0 -7
  209. package/dist/chunks/setup-wizard-JUJZYNNM.ts.map +0 -7
  210. package/dist/chunks/sync-inspection-CST2KL65.ts +0 -20
  211. package/dist/chunks/sync-operations-LBX3GKCM.ts.map +0 -7
  212. package/dist/chunks/webdav-backend-ECIKD7SO.ts.map +0 -7
  213. /package/dist/chunks/{manager-result-dispatcher-ASKGOSW5.ts.map → manager-result-dispatcher-OTUMQM26.ts.map} +0 -0
  214. /package/dist/chunks/{remote-selection-ui-QDNR7WEI.ts.map → remote-selection-ui-TZTJF32Y.ts.map} +0 -0
  215. /package/dist/chunks/{setup-switch-IS2PEZ3J.ts.map → setup-switch-5G2VNJHL.ts.map} +0 -0
  216. /package/dist/chunks/{snapshot-HKEWCVK6.ts.map → snapshot-JL5DFSXI.ts.map} +0 -0
  217. /package/dist/chunks/{sync-inspection-CST2KL65.ts.map → sync-inspection-P3ENJLNF.ts.map} +0 -0
  218. /package/dist/chunks/{sync-state-Q2FTXTW6.ts.map → sync-state-VHJUZ4YG.ts.map} +0 -0
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/ui/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 { loadConfig } from \"../settings/config.js\";\nimport { localConfigPath } from \"../settings/config-file.js\";\nimport { updateSyncSetup } from \"../settings/settings-management.js\";\nimport { agentDir } from \"../snapshot/session-paths.js\";\nimport {\n\tBUILT_IN_SYNC_ROOTS,\n\tisSafeCustomIncludePath,\n\tnormalizeSyncInclude,\n\tsyncIncludeSelection,\n} from \"../sync/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, \"?\");\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,QAAQ;AAEf,SAAS,YAAY,eAAe;AAYpC,IAAM,kBAAkB;AACxB,IAAM,gBAAgB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;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/backends/git/git-backend.ts", "../../src/backends/git/git-runner.ts", "../../src/backends/git/git-storage.ts"],
4
- "sourcesContent": ["import { createHash, randomUUID } from \"node:crypto\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { posixJoin } from \"../../paths.js\";\nimport type { Snapshot, SnapshotFile } from \"../../snapshot/snapshot-types.js\";\nimport { stateDir } from \"../../state/state-directory.js\";\nimport { syncErrorGuidance } from \"../../sync/sync-error-guidance.js\";\nimport type { ResolvedGitBackend } from \"../backend-types.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 {\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\";\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 = path.resolve(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\t\t{\n\t\t\t\tkey: \"git-scope\",\n\t\t\t\tlevel: \"info\",\n\t\t\t\tmessage:\n\t\t\t\t\t\"git check scope: read remote snapshots and inspect the local cache. Write access is not tested.\",\n\t\t\t},\n\t\t];\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 [\n\t\t\t\t{\n\t\t\t\t\tkey: \"git-version\",\n\t\t\t\t\tlevel: \"error\",\n\t\t\t\t\tmessage: syncErrorGuidance(new Error(this.safeError(error))),\n\t\t\t\t},\n\t\t\t];\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: ${syncErrorGuidance(new Error(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\tthrowIfAborted(signal);\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\tthrowIfAborted(signal);\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 === \"./\" ? \"\" : 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\tlet started = false;\n\tconst operation = previous\n\t\t.catch(() => undefined)\n\t\t.then(() => {\n\t\t\tthrowIfAborted(signal);\n\t\t\tstarted = true;\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} catch (error) {\n\t\t// A queued job can cancel immediately, but a running job owns a child/cache\n\t\t// mutation. Drain its bounded cleanup before releasing outer sync guards.\n\t\tif (started) await tail;\n\t\tthrow error;\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 type { Snapshot, SnapshotSelection } from \"../../snapshot/snapshot-types.js\";\nimport { portableSnapshotSelection, snapshotSelectionInclude } from \"../../sync/sync-policy.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;AAEpB,IAAM,qBAAqB;AAC3B,IAAM,uBAAuB,OAAO;AAkB7B,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAE1C,YACC,SACS,UACA,QACT,SACC;AACD,UAAM,SAAS,OAAO;AAJb;AACA;AAIT,SAAK,OAAO;AAAA,EACb;AAAA,EANU;AAAA,EACA;AAAA,EAJD,OAAO;AAUjB;AAEA,eAAsB,OAAO,MAAgB,UAAyB,CAAC,GAA0B;AAChG,iBAAe,QAAQ,MAAM;AAC7B,QAAM,YAAYA,SAAQ,aAAa,UAAU,QAAQ;AACzD,QAAM,eAAe;AAAA,IACpB;AAAA,IACA,kBAAkB,SAAS;AAAA,IAC3B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACA,MAAI,QAAQ,kBAAmB,cAAa,KAAK,MAAM,4BAA4B;AACnF,QAAM,cAAc;AAAA,IACnB,GAAI,QAAQ,SAAS,CAAC,aAAa,QAAQ,MAAM,EAAE,IAAI,CAAC;AAAA,IACxD,GAAG;AAAA,IACH,GAAG;AAAA,EACJ;AACA,QAAM,uBAAuB,O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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-YHEMENKV.ts";
6
- import "./chunk-YDWUZVPN.ts";
7
- import "./chunk-HUDQATCL.ts";
8
- import "./chunk-T2B5IU74.ts";
9
- import "./chunk-LTBWGSBV.ts";
10
- import "./chunk-LCRI3ABW.ts";
11
- import "./chunk-C7XY5NF5.ts";
12
- import "./chunk-6LP3MCR2.ts";
13
- import "./chunk-TEN2ZBJV.ts";
14
- import "./chunk-2B2ELUF5.ts";
15
- import "./chunk-OEX4ABY6.ts";
16
- import "./chunk-THMF4BVL.ts";
17
- import "./chunk-T3HH3UEJ.ts";
18
- import "./chunk-JAAKLL6M.ts";
19
- export {
20
- dispatchManagerResult
21
- };
22
- //# sourceMappingURL=manager-result-dispatcher-ASKGOSW5.ts.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/ui/manager-ui.ts", "../../src/state/operation-availability.ts", "../../src/ui/manager-attention.ts", "../../src/ui/manager-recovery.ts", "../../src/ui/manager-state.ts", "../../src/ui/sync-setups-ui.ts", "../../src/ui/settings-ui.ts", "../../src/ui/storage-connections-ui.ts", "../../src/ui/setup/setup-switcher.ts", "../../src/ui/setup/setup-actions.ts"],
4
- "sourcesContent": ["import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { type ActionMenuItem, defineMenu, runMenu } from \"@narumitw/pi-tui-kit\";\nimport { loadConfig } from \"../settings/config.js\";\nimport { operationBlocksChanges, operationCanRecover } from \"../state/operation-availability.js\";\nimport { type RunRoute, runCancellableOperation } from \"./cancellable-operation.js\";\nimport {\n\tattentionMainMenuItems,\n\tblockedSyncMenuItem,\n\ttype SyncManagerAttentionOptions,\n\tshowManagerAttention,\n} from \"./manager-attention.js\";\nimport { recoverSyncAccess } from \"./manager-recovery.js\";\nimport { dispatchManagerResult } from \"./manager-result-dispatcher.js\";\nimport { describeManagerState } from \"./manager-state.js\";\nimport { showSyncSettings } from \"./settings-ui.js\";\nimport { showSyncSetupManager } from \"./setup/setup-actions.js\";\nimport { showSetupSwitcher } from \"./setup/setup-switcher.js\";\nimport { showStorageConnections } from \"./storage-connections-ui.js\";\nimport { observationMatchesConfig } from \"./sync-attention.js\";\n\nexport async function showSyncManager(\n\tctx: ExtensionCommandContext,\n\trunRoute: RunRoute,\n\tsessionSignal?: AbortSignal,\n\toptions: SyncManagerAttentionOptions = {},\n): Promise<void> {\n\tif (!ctx.hasUI) {\n\t\tawait runRoute(\"help\");\n\t\treturn;\n\t}\n\ttype Screen = \"main\" | \"more\" | \"recovery\";\n\ttype Action =\n\t\t| \"review-attention\"\n\t\t| \"sync\"\n\t\t| \"switch\"\n\t\t| \"diff\"\n\t\t| \"settings\"\n\t\t| \"pull\"\n\t\t| \"push\"\n\t\t| \"setups\"\n\t\t| \"connections\"\n\t\t| \"history\"\n\t\t| \"doctor\"\n\t\t| \"unlock\"\n\t\t| \"recover\"\n\t\t| \"refresh\"\n\t\t| \"help\"\n\t\t| \"init\"\n\t\t| \"back\";\n\tinterface State {\n\t\tmanager: Awaited<ReturnType<typeof describeManagerState>>;\n\t}\n\tconst menu = defineMenu<State, Screen, Action, ExtensionCommandContext>({\n\t\tstart: \"main\",\n\t\tscreens: {\n\t\t\tmain: ({ state }) => {\n\t\t\t\tconst attentionItems = attentionMainMenuItems(state.manager);\n\t\t\t\tconst managerItems = state.manager.actions.map(\n\t\t\t\t\t(label) => blockedSyncMenuItem(label, state.manager) ?? syncMainMenuItem(label),\n\t\t\t\t);\n\t\t\t\tconst operationFirst =\n\t\t\t\t\tstate.manager.operation !== undefined && state.manager.operation.kind !== \"free\";\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"actions\",\n\t\t\t\t\ttitle: \"Manage sync\",\n\t\t\t\t\tlines: state.manager.title.split(\"\\n\").slice(1),\n\t\t\t\t\titems: operationFirst\n\t\t\t\t\t\t? [...managerItems, ...attentionItems]\n\t\t\t\t\t\t: [...attentionItems, ...managerItems],\n\t\t\t\t\thint: \"close\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tmore: () => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: \"More options\",\n\t\t\t\titems: [\n\t\t\t\t\t{ id: \"pull\", label: \"Pull from remote\u2026\", action: \"pull\" },\n\t\t\t\t\t{ id: \"push\", label: \"Push to remote\u2026\", action: \"push\" },\n\t\t\t\t\t{ id: \"setups\", label: \"Sync setups\u2026\", action: \"setups\" },\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"connections\",\n\t\t\t\t\t\tlabel: \"Storage connections\u2026\",\n\t\t\t\t\t\taction: \"connections\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"doctor\",\n\t\t\t\t\t\tlabel: \"Check setup\",\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"Check current setup access. WebDAV also probes writes and repairs history.\",\n\t\t\t\t\t\taction: \"doctor\",\n\t\t\t\t\t},\n\t\t\t\t\t{ id: \"recovery\", label: \"History & recovery\u2026\", to: \"recovery\" },\n\t\t\t\t\t{ id: \"help\", label: \"Help\", action: \"help\" },\n\t\t\t\t\t{ id: \"back\", label: \"Back\", action: \"back\" },\n\t\t\t\t],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\trecovery: ({ state }) => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: \"History & recovery\",\n\t\t\t\titems: [\n\t\t\t\t\t{ id: \"history\", label: \"Browse history\", action: \"history\" },\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"doctor\",\n\t\t\t\t\t\tlabel: \"Check setup\",\n\t\t\t\t\t\tdescription: \"WebDAV also probes writes and repairs history.\",\n\t\t\t\t\t\taction: \"doctor\",\n\t\t\t\t\t},\n\t\t\t\t\t...(state.manager.operation && operationCanRecover(state.manager.operation)\n\t\t\t\t\t\t? [{ id: \"unlock\", label: \"Recover stale operation\", action: \"unlock\" as const }]\n\t\t\t\t\t\t: []),\n\t\t\t\t\t{ id: \"back\", label: \"Back\", action: \"back\" },\n\t\t\t\t],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\t\"review-attention\": async () => {\n\t\t\t\tconst attention = options.getAttention?.();\n\t\t\t\tif (!attention) {\n\t\t\t\t\tconst observation = options.getObservation?.();\n\t\t\t\t\tif (!observation) return { kind: \"stay\" };\n\t\t\t\t\t// A head-only observation is not an authoritative decision. Load a fresh\n\t\t\t\t\t// snapshot only after the user activates the existing review flow.\n\t\t\t\t\tconst { showRemoteSelectionReview } = await import(\"./remote-selection-ui.js\");\n\t\t\t\t\tif (sessionSignal?.aborted) return { kind: \"close\" };\n\t\t\t\t\tconst config = await loadConfig();\n\t\t\t\t\tif (sessionSignal?.aborted) return { kind: \"close\" };\n\t\t\t\t\tif (\n\t\t\t\t\t\toptions.getObservation?.() !== observation ||\n\t\t\t\t\t\t!observationMatchesConfig(observation, config)\n\t\t\t\t\t) {\n\t\t\t\t\t\toptions.onObservationInvalidated?.();\n\t\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t\t}\n\t\t\t\t\t// Keep the check-time hint on cancellation or failure. Route commits and\n\t\t\t\t\t// the manager's config/baseline reconciliation own invalidation.\n\t\t\t\t\tconst result = await showRemoteSelectionReview(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tobservation.setupName,\n\t\t\t\t\t\tsessionSignal,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\torigin: \"sync\",\n\t\t\t\t\t\t\trunRoute,\n\t\t\t\t\t\t\tonSelectionResolved: () => {\n\t\t\t\t\t\t\t\tif (!sessionSignal?.aborted && options.getObservation?.() === observation)\n\t\t\t\t\t\t\t\t\toptions.onObservationInvalidated?.();\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t\tif (sessionSignal?.aborted) return { kind: \"close\" };\n\t\t\t\t\tif (result.kind === \"route-result\") {\n\t\t\t\t\t\treturn dispatchManagerResult(ctx, result.result, result.route, runRoute, sessionSignal);\n\t\t\t\t\t}\n\t\t\t\t\treturn { kind: result.kind === \"closed\" || result.kind === \"stale\" ? \"close\" : \"stay\" };\n\t\t\t\t}\n\t\t\t\tconst disposition = await showManagerAttention(\n\t\t\t\t\tctx,\n\t\t\t\t\tattention,\n\t\t\t\t\trunRoute,\n\t\t\t\t\tsessionSignal,\n\t\t\t\t\t() => options.onSelectionResolved?.(attention),\n\t\t\t\t);\n\t\t\t\treturn { kind: disposition };\n\t\t\t},\n\t\t\tsync: async () => {\n\t\t\t\tconst pendingAttention = options.getAttention?.();\n\t\t\t\tif (pendingAttention) {\n\t\t\t\t\tconst activeConfig = await loadConfig();\n\t\t\t\t\tif (sessionSignal?.aborted) return { kind: \"close\" };\n\t\t\t\t\tif (pendingAttention.decision.setupName === activeConfig.setupName) {\n\t\t\t\t\t\tctx.ui.notify(\"Review synced content before starting Sync now.\", \"warning\");\n\t\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst result = await runCancellableOperation(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"Checking current sync setup\u2026\",\n\t\t\t\t\t\"sync\",\n\t\t\t\t\trunRoute,\n\t\t\t\t\t{\n\t\t\t\t\t\tcommitAware: true,\n\t\t\t\t\t\tsignal: sessionSignal,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tconst disposition = await dispatchManagerResult(\n\t\t\t\t\tctx,\n\t\t\t\t\tresult,\n\t\t\t\t\t\"sync\",\n\t\t\t\t\trunRoute,\n\t\t\t\t\tsessionSignal,\n\t\t\t\t);\n\t\t\t\treturn disposition.kind === \"close\" ? { kind: \"close\" } : { kind: \"stay\" };\n\t\t\t},\n\t\t\tswitch: async () => {\n\t\t\t\tconst result = await showSetupSwitcher(ctx, runRoute, undefined, sessionSignal);\n\t\t\t\treturn result === \"pull-attempted\" || result === \"closed\"\n\t\t\t\t\t? { kind: \"close\" }\n\t\t\t\t\t: { kind: \"stay\" };\n\t\t\t},\n\t\t\tdiff: async () => {\n\t\t\t\tconst result = await runCancellableOperation(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"Checking current sync setup\u2026\",\n\t\t\t\t\t\"diff\",\n\t\t\t\t\trunRoute,\n\t\t\t\t\t{ signal: sessionSignal },\n\t\t\t\t);\n\t\t\t\treturn result.kind === \"closed\" ? { kind: \"close\" } : { kind: \"stay\" };\n\t\t\t},\n\t\t\tsettings: async () => {\n\t\t\t\tawait showSyncSettings(ctx, runRoute, sessionSignal);\n\t\t\t\treturn { kind: \"stay\" };\n\t\t\t},\n\t\t\tpull: async () => {\n\t\t\t\tconst result = await runCancellableOperation(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"Checking remote changes\u2026\",\n\t\t\t\t\t\"pull\",\n\t\t\t\t\trunRoute,\n\t\t\t\t\t{\n\t\t\t\t\t\tcommitAware: true,\n\t\t\t\t\t\tcancelledMessage: \"Pull check cancelled; no local files were changed.\",\n\t\t\t\t\t\tsignal: sessionSignal,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tconst disposition = await dispatchManagerResult(\n\t\t\t\t\tctx,\n\t\t\t\t\tresult,\n\t\t\t\t\t\"pull\",\n\t\t\t\t\trunRoute,\n\t\t\t\t\tsessionSignal,\n\t\t\t\t);\n\t\t\t\treturn disposition.kind === \"close\" ? { kind: \"close\" } : { kind: \"stay\" };\n\t\t\t},\n\t\t\tpush: async () => {\n\t\t\t\tconst result = await runCancellableOperation(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"Preparing push preview\u2026\",\n\t\t\t\t\t\"push\",\n\t\t\t\t\trunRoute,\n\t\t\t\t\t{\n\t\t\t\t\t\tcommitAware: true,\n\t\t\t\t\t\tcancelledMessage: \"Push preparation cancelled; no remote files were changed.\",\n\t\t\t\t\t\tsignal: sessionSignal,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tconst disposition = await dispatchManagerResult(\n\t\t\t\t\tctx,\n\t\t\t\t\tresult,\n\t\t\t\t\t\"push\",\n\t\t\t\t\trunRoute,\n\t\t\t\t\tsessionSignal,\n\t\t\t\t);\n\t\t\t\treturn disposition.kind === \"close\" ? { kind: \"close\" } : { kind: \"stay\" };\n\t\t\t},\n\t\t\tsetups: async () => {\n\t\t\t\tconst result = await showSyncSetupManager(ctx, runRoute, sessionSignal);\n\t\t\t\treturn result === \"exit\" ? { kind: \"close\" } : { kind: \"stay\" };\n\t\t\t},\n\t\t\tconnections: async () => {\n\t\t\t\tawait showStorageConnections(ctx, sessionSignal);\n\t\t\t\treturn { kind: \"stay\" };\n\t\t\t},\n\t\t\thistory: async () => {\n\t\t\t\tawait runRoute(\"history\");\n\t\t\t\treturn { kind: \"stay\" };\n\t\t\t},\n\t\t\tdoctor: async () => {\n\t\t\t\tconst result = await runCancellableOperation(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"Checking setup access\u2026\",\n\t\t\t\t\t\"doctor\",\n\t\t\t\t\trunRoute,\n\t\t\t\t\t{ signal: sessionSignal },\n\t\t\t\t);\n\t\t\t\treturn { kind: result.kind === \"closed\" ? \"close\" : \"stay\" };\n\t\t\t},\n\t\t\tunlock: async ({ state, signal: actionSignal }) => {\n\t\t\t\tconst result = await recoverSyncAccess(\n\t\t\t\t\tctx,\n\t\t\t\t\tstate.manager,\n\t\t\t\t\trunRoute,\n\t\t\t\t\tsessionSignal,\n\t\t\t\t\tactionSignal,\n\t\t\t\t);\n\t\t\t\tif (result === \"close\") return { kind: \"close\" };\n\t\t\t\treturn result === \"restored\" ? { kind: \"to\", screen: \"main\" } : { kind: \"stay\" };\n\t\t\t},\n\t\t\trecover: async ({ state, signal: actionSignal }) => {\n\t\t\t\tconst result = await recoverSyncAccess(\n\t\t\t\t\tctx,\n\t\t\t\t\tstate.manager,\n\t\t\t\t\trunRoute,\n\t\t\t\t\tsessionSignal,\n\t\t\t\t\tactionSignal,\n\t\t\t\t);\n\t\t\t\treturn { kind: result === \"close\" ? \"close\" : \"stay\" };\n\t\t\t},\n\t\t\trefresh: async () => ({ kind: \"stay\" }),\n\t\t\thelp: async () => {\n\t\t\t\tawait runRoute(\"help\");\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tinit: async () => {\n\t\t\t\tawait runRoute(\"init\");\n\t\t\t\treturn { kind: \"stay\" };\n\t\t\t},\n\t\t\tback: async () => ({ kind: \"back\" }),\n\t\t},\n\t});\n\tawait runMenu(ctx, menu, {\n\t\tgetState: async () => {\n\t\t\tconst pendingAttention = options.getAttention?.();\n\t\t\tconst observation = options.getObservation?.();\n\t\t\tconst manager = await describeManagerState(\n\t\t\t\tsessionSignal,\n\t\t\t\tpendingAttention,\n\t\t\t\tundefined,\n\t\t\t\tobservation,\n\t\t\t);\n\t\t\tif (sessionSignal?.aborted) return { manager };\n\t\t\t// A busy operation suppresses baseline reads, not the stored check-time hint.\n\t\t\tif (\n\t\t\t\tobservation &&\n\t\t\t\toptions.getObservation?.() === observation &&\n\t\t\t\t!manager.observation &&\n\t\t\t\t!(manager.operation && operationBlocksChanges(manager.operation))\n\t\t\t) {\n\t\t\t\toptions.onObservationInvalidated?.();\n\t\t\t}\n\t\t\tif (pendingAttention && options.getAttention?.() === pendingAttention && !manager.attention) {\n\t\t\t\toptions.onSelectionResolved?.(pendingAttention);\n\t\t\t}\n\t\t\treturn { manager };\n\t\t},\n\t\tsignal: sessionSignal,\n\t\tisCurrent: () => !sessionSignal?.aborted,\n\t});\n}\n\nfunction syncMainMenuItem(\n\tlabel: string,\n): ActionMenuItem<\n\t\"main\" | \"more\" | \"recovery\",\n\t| \"sync\"\n\t| \"switch\"\n\t| \"diff\"\n\t| \"settings\"\n\t| \"setups\"\n\t| \"connections\"\n\t| \"recover\"\n\t| \"refresh\"\n\t| \"help\"\n\t| \"init\"\n> {\n\tif (label === \"More\u2026\") return { id: \"more\", label, to: \"more\" };\n\tif (label === \"History & recovery\u2026\") return { id: \"recovery\", label, to: \"recovery\" };\n\tconst actions = new Map<\n\t\tstring,\n\t\t| \"sync\"\n\t\t| \"switch\"\n\t\t| \"diff\"\n\t\t| \"settings\"\n\t\t| \"setups\"\n\t\t| \"connections\"\n\t\t| \"recover\"\n\t\t| \"refresh\"\n\t\t| \"help\"\n\t\t| \"init\"\n\t>([\n\t\t[\"Sync now (recommended)\", \"sync\"],\n\t\t[\"Switch sync setup\", \"switch\"],\n\t\t[\"Status & changes\", \"diff\"],\n\t\t[\"Settings\", \"settings\"],\n\t\t[\"Restore sync access\u2026 (recommended)\", \"recover\"],\n\t\t[\"Refresh operation status\", \"refresh\"],\n\t\t[\"Sync setups\u2026\", \"setups\"],\n\t\t[\"Storage connections\u2026\", \"connections\"],\n\t\t[\"Help\", \"help\"],\n\t\t[\"Set up sync\", \"init\"],\n\t\t[\"Use existing settings\", \"init\"],\n\t]);\n\treturn { id: actions.get(label) ?? \"help\", label, action: actions.get(label) ?? \"help\" };\n}\n", "import { errorMessage } from \"../sync/sync-errors.js\";\nimport { inspectLock, isLockGuardHeld, isStaleLock, type LockInspection } from \"./lock.js\";\nimport type { LockFile } from \"./state-types.js\";\n\nexport type OperationAvailability =\n\t| { kind: \"free\" }\n\t| { kind: \"live\"; lock: LockFile }\n\t| { kind: \"busy\"; lock?: LockFile; metadata: LockInspection[\"status\"] }\n\t| { kind: \"recoverable-stale\"; lock: LockFile }\n\t| { kind: \"recoverable-unreadable\" }\n\t| { kind: \"inspection-error\"; message: string };\n\ninterface OperationInspectionDependencies {\n\tinspectMetadata(): Promise<LockInspection>;\n\tinspectGuard(): Promise<boolean>;\n}\n\nconst DEFAULT_INSPECTION_DEPENDENCIES: OperationInspectionDependencies = {\n\tinspectMetadata: inspectLock,\n\tinspectGuard: isLockGuardHeld,\n};\n\nexport async function inspectOperationAvailability(\n\tdependencies: OperationInspectionDependencies = DEFAULT_INSPECTION_DEPENDENCIES,\n): Promise<OperationAvailability> {\n\ttry {\n\t\tconst metadata = await dependencies.inspectMetadata();\n\t\tconst guardHeld = await dependencies.inspectGuard();\n\t\treturn classifyOperationAvailability(metadata, guardHeld);\n\t} catch (error) {\n\t\treturn { kind: \"inspection-error\", message: errorMessage(error) };\n\t}\n}\n\nexport function classifyOperationAvailability(\n\tmetadata: LockInspection,\n\tguardHeld: boolean,\n): OperationAvailability {\n\tif (metadata.status === \"valid\" && !isStaleLock(metadata.lock)) {\n\t\treturn { kind: \"live\", lock: metadata.lock };\n\t}\n\tif (guardHeld) {\n\t\treturn {\n\t\t\tkind: \"busy\",\n\t\t\tmetadata: metadata.status,\n\t\t\t...(metadata.status === \"valid\" ? { lock: metadata.lock } : {}),\n\t\t};\n\t}\n\tif (metadata.status === \"valid\") {\n\t\treturn { kind: \"recoverable-stale\", lock: metadata.lock };\n\t}\n\tif (metadata.status === \"unreadable\") return { kind: \"recoverable-unreadable\" };\n\treturn { kind: \"free\" };\n}\n\nexport function operationBlocksChanges(availability: OperationAvailability) {\n\treturn availability.kind !== \"free\";\n}\n\nexport function operationCanRecover(availability: OperationAvailability) {\n\treturn (\n\t\tavailability.kind === \"recoverable-stale\" || availability.kind === \"recoverable-unreadable\"\n\t);\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport type { ActionMenuItem } from \"@narumitw/pi-tui-kit\";\nimport type { StartupObservation } from \"../sync/sync-inspection.js\";\nimport type { RunRoute } from \"./cancellable-operation.js\";\nimport { dispatchManagerResult } from \"./manager-result-dispatcher.js\";\nimport type { ManagerDescription } from \"./manager-state.js\";\nimport type { SyncAttentionState } from \"./sync-attention.js\";\n\nexport interface SyncManagerAttentionOptions {\n\tgetObservation?: () => StartupObservation | undefined;\n\tonObservationInvalidated?: () => void;\n\tgetAttention?: () => SyncAttentionState | undefined;\n\tonSelectionResolved?: (expected: SyncAttentionState) => void;\n}\n\nexport function attentionMainMenuItems(\n\tmanager: ManagerDescription,\n): ActionMenuItem<\"main\" | \"more\" | \"recovery\", \"review-attention\">[] {\n\tif (!manager.attention && manager.observation?.inspection.selectionState?.kind !== \"different\")\n\t\treturn [];\n\tconst disabled = manager.attentionReviewDisabled === true;\n\treturn [\n\t\t{\n\t\t\tid: \"review-attention\",\n\t\t\tlabel: \"Review synced content (recommended)\",\n\t\t\taction: \"review-attention\",\n\t\t\t...(disabled\n\t\t\t\t? {\n\t\t\t\t\t\tdisabled: true,\n\t\t\t\t\t\tdisabledReason: \"Finish or recover the active operation first.\",\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t},\n\t];\n}\n\nexport function blockedSyncMenuItem(\n\tlabel: string,\n\tmanager: ManagerDescription,\n): ActionMenuItem<\"main\" | \"more\" | \"recovery\", \"sync\"> | undefined {\n\tif (label !== \"Sync now (recommended)\" || !manager.attentionBlocksSync) return undefined;\n\treturn {\n\t\tid: \"sync\",\n\t\tlabel,\n\t\tdescription: \"Review first.\",\n\t\taction: \"sync\",\n\t\tdisabled: true,\n\t\tdisabledReason: \"Review synced content first.\",\n\t};\n}\n\nexport async function showManagerAttention(\n\tctx: ExtensionCommandContext,\n\tattention: SyncAttentionState,\n\trunRoute: RunRoute,\n\tsignal: AbortSignal | undefined,\n\tonSelectionResolved: (() => void) | undefined,\n): Promise<\"close\" | \"stay\"> {\n\tconst { showRemoteSelectionReview } = await import(\"./remote-selection-ui.js\");\n\tif (signal?.aborted) return \"close\";\n\tconst review = await showRemoteSelectionReview(\n\t\tctx,\n\t\tattention.decision.setupName,\n\t\tsignal,\n\t\tundefined,\n\t\t{\n\t\t\tdecision: attention.decision,\n\t\t\torigin: attention.origin,\n\t\t\trunRoute,\n\t\t\tonSelectionResolved,\n\t\t},\n\t);\n\tif (review.kind === \"route-result\") {\n\t\tconst disposition = await dispatchManagerResult(\n\t\t\tctx,\n\t\t\treview.result,\n\t\t\treview.route,\n\t\t\trunRoute,\n\t\t\tsignal,\n\t\t\t{ onSelectionResolved },\n\t\t);\n\t\treturn disposition.kind;\n\t}\n\treturn review.kind === \"closed\" || review.kind === \"stale\" ? \"close\" : \"stay\";\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { runConfirmation } from \"@narumitw/pi-tui-kit\";\nimport {\n\tinspectOperationAvailability,\n\toperationCanRecover,\n} from \"../state/operation-availability.js\";\nimport { errorMessage } from \"../sync/sync-errors.js\";\nimport type { RunRoute } from \"./cancellable-operation.js\";\nimport type { ManagerDescription } from \"./manager-state.js\";\nimport { safeTerminalText } from \"./terminal-text.js\";\n\nexport type RecoveryDisposition = \"restored\" | \"stay\" | \"close\";\n\nexport async function recoverSyncAccess(\n\tctx: ExtensionCommandContext,\n\tmanager: ManagerDescription,\n\trunRoute: RunRoute,\n\tsessionSignal: AbortSignal | undefined,\n\tactionSignal: AbortSignal,\n): Promise<RecoveryDisposition> {\n\tconst operation = manager.operation;\n\tif (!operation || !operationCanRecover(operation)) {\n\t\tctx.ui.notify(\n\t\t\t\"Operation status changed. Refresh the manager before retrying recovery.\",\n\t\t\t\"warning\",\n\t\t);\n\t\treturn \"stay\";\n\t}\n\tconst signal = sessionSignal ? AbortSignal.any([sessionSignal, actionSignal]) : actionSignal;\n\tif (signal.aborted) return \"close\";\n\tconst unreadable = operation.kind === \"recoverable-unreadable\";\n\tconst details = unreadable\n\t\t? \"Pi-sync cannot verify who owns the unreadable lock. Close other Pi sessions that may be syncing before continuing.\"\n\t\t: `The recorded ${safeTerminalText(operation.lock.command)} operation (pid ${operation.lock.pid}) appears to have stopped. Close other Pi sessions that may still be syncing before continuing.`;\n\tconst confirmation = await runConfirmation(ctx, {\n\t\ttitle: \"Restore sync access?\",\n\t\tmessage: [\n\t\t\tdetails,\n\t\t\t\"\",\n\t\t\t\"This removes only the local operation lock.\",\n\t\t\t\"It does not change settings, local files, sync state, or remote data.\",\n\t\t].join(\"\\n\"),\n\t\tconfirmLabel: \"Remove local lock and continue\",\n\t\tcancelLabel: \"Cancel\",\n\t\tsignal,\n\t\tisCurrent: () => !signal.aborted,\n\t\tonError: (_currentCtx, error) => {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Recovery confirmation failed: ${safeTerminalText(errorMessage(error))}`,\n\t\t\t\t\"error\",\n\t\t\t);\n\t\t},\n\t});\n\tif (confirmation.kind === \"stale\") return \"close\";\n\tif (confirmation.kind === \"closed\") {\n\t\tif (confirmation.reason === \"close\") return \"close\";\n\t\tif (!signal.aborted) {\n\t\t\tctx.ui.notify(\"Recovery cancelled; the local operation lock was not changed.\", \"info\");\n\t\t}\n\t\treturn \"stay\";\n\t}\n\tif (confirmation.kind !== \"confirmed\") return \"stay\";\n\tif (signal.aborted) return \"close\";\n\tawait runRoute(unreadable ? \"unlock --stale\" : \"unlock\", signal);\n\tif (signal.aborted) return \"close\";\n\tconst latest = await inspectOperationAvailability();\n\tif (signal.aborted) return \"close\";\n\treturn latest.kind === \"free\" ? \"restored\" : \"stay\";\n}\n", "import { truncateToWidth } from \"@earendil-works/pi-tui\";\nimport { loadConfig } from \"../settings/config.js\";\nimport { activeLocalConfigPath } from \"../settings/config-file.js\";\nimport { readLocalConfigObject } from \"../settings/settings-store.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport { isCloudflareR2Endpoint, ownRecord } from \"../settings/settings-validation.js\";\nimport {\n\tinspectOperationAvailability,\n\ttype OperationAvailability,\n\toperationBlocksChanges,\n\toperationCanRecover,\n} from \"../state/operation-availability.js\";\nimport { readStateForConfig, syncStateFingerprint } from \"../state/sync-state-store.js\";\nimport { errorMessage } from \"../sync/sync-errors.js\";\nimport type { StartupObservation } from \"../sync/sync-inspection.js\";\nimport { compareSyncInclude, syncIncludeSelection } from \"../sync/sync-policy.js\";\nimport { automaticSyncSummary } from \"./automatic-sync-summary.js\";\nimport {\n\tobservationMatchesConfig,\n\tobservationSummary,\n\ttype SyncAttentionState,\n\tsyncAttentionMatchesConfig,\n} from \"./sync-attention.js\";\nimport { countValidSyncSetups } from \"./sync-setups-ui.js\";\nimport { safeTerminalText } from \"./terminal-text.js\";\n\nexport const MAIN_MENU_ACTIONS = [\n\t\"Sync now (recommended)\",\n\t\"Switch sync setup\",\n\t\"Status & changes\",\n\t\"Settings\",\n\t\"More\u2026\",\n] as const;\n\nexport interface ManagerDescription {\n\ttitle: string;\n\tactions: string[];\n\toperation?: OperationAvailability;\n\tattention?: SyncAttentionState;\n\tobservation?: StartupObservation;\n\tattentionBlocksSync?: boolean;\n\tattentionReviewDisabled?: boolean;\n}\n\nexport async function describeManagerState(\n\tsignal?: AbortSignal,\n\tattention?: SyncAttentionState,\n\tinspectOperation: () => Promise<OperationAvailability> = inspectOperationAvailability,\n\tobservation?: StartupObservation,\n): Promise<ManagerDescription> {\n\tlet raw: Record<string, unknown> | undefined;\n\ttry {\n\t\traw = await readLocalConfigObject();\n\t} catch (error) {\n\t\treturn {\n\t\t\ttitle: [\n\t\t\t\t\"Manage sync\",\n\t\t\t\t\"\",\n\t\t\t\t\"Settings file needs repair. Automatic sync and settings writes are paused.\",\n\t\t\t\t`Error: ${safeTerminalText(errorMessage(error))}`,\n\t\t\t\t`File: ${safeTerminalText(await activeLocalConfigPath())}`,\n\t\t\t\t\"\",\n\t\t\t\t\"Repair the JSON file, then reopen /sync.\",\n\t\t\t].join(\"\\n\"),\n\t\t\tactions: [\"Help\"],\n\t\t};\n\t}\n\tif (!raw) {\n\t\treturn {\n\t\t\ttitle: [\"Manage sync\", \"\", \"Not set up.\", \"\", \"What do you want to do?\"].join(\"\\n\"),\n\t\t\tactions: [\"Set up sync\", \"Help\"],\n\t\t};\n\t}\n\tconst configuredTargets = ownRecord(raw.syncSetups);\n\tif (raw.version === 3 && configuredTargets && Object.keys(configuredTargets).length === 0) {\n\t\treturn {\n\t\t\ttitle: [\n\t\t\t\t\"Manage sync\",\n\t\t\t\t\"\",\n\t\t\t\t\"No sync setups are configured.\",\n\t\t\t\t\"Add a sync setup using an existing storage connection.\",\n\t\t\t\t\"\",\n\t\t\t\t\"What do you want to do?\",\n\t\t\t].join(\"\\n\"),\n\t\t\tactions: [\"Sync setups\u2026\", \"Storage connections\u2026\", \"Help\"],\n\t\t};\n\t}\n\ttry {\n\t\tconst config = await loadConfig();\n\t\tconst operation = await inspectOperation();\n\t\tconst changesBlocked = operationBlocksChanges(operation);\n\t\tconst selection = syncIncludeSelection(config.include);\n\t\tlet currentAttention: SyncAttentionState | undefined;\n\t\tif (attention) {\n\t\t\ttry {\n\t\t\t\tconst attentionConfig =\n\t\t\t\t\tattention.decision.setupName === config.setupName\n\t\t\t\t\t\t? config\n\t\t\t\t\t\t: await loadConfig(attention.decision.setupName);\n\t\t\t\tif (syncAttentionMatchesConfig(attention, attentionConfig)) currentAttention = attention;\n\t\t\t} catch {\n\t\t\t\tcurrentAttention = undefined;\n\t\t\t}\n\t\t\tif (signal?.aborted) throw signal.reason;\n\t\t}\n\t\tconst attentionComparison = currentAttention\n\t\t\t? compareSyncInclude(\n\t\t\t\t\tcurrentAttention.decision.localInclude,\n\t\t\t\t\tcurrentAttention.decision.remoteInclude,\n\t\t\t\t)\n\t\t\t: undefined;\n\t\tconst noSyncedContent = config.include.length === 0;\n\t\tconst syncState = changesBlocked\n\t\t\t? undefined\n\t\t\t: await readStateForConfig(config).catch(() => undefined);\n\t\tconst currentObservation =\n\t\t\tobservation &&\n\t\t\tobservationMatchesConfig(observation, config) &&\n\t\t\tsyncState &&\n\t\t\tsyncStateFingerprint(syncState) === observation.inspection.stateIdentity\n\t\t\t\t? observation\n\t\t\t\t: undefined;\n\t\tconst lastAppliedSnapshot = changesBlocked\n\t\t\t? \"Unavailable while operations are locked\"\n\t\t\t: syncState?.lastAppliedSnapshot\n\t\t\t\t? safeTerminalText(syncState.lastAppliedSnapshot)\n\t\t\t\t: syncState\n\t\t\t\t\t? \"Never synced\"\n\t\t\t\t\t: \"Unavailable\";\n\t\tconst canSwitch = (await countValidSyncSetups(configuredTargets, signal)) > 1;\n\t\tconst mainActions = MAIN_MENU_ACTIONS.filter(\n\t\t\t(action) => action !== \"Switch sync setup\" || canSwitch,\n\t\t);\n\t\tconst ordinaryTitle = [\n\t\t\t\"Manage sync\",\n\t\t\t\"\",\n\t\t\t`Current sync setup: ${safeTerminalText(config.setupName)}`,\n\t\t\t`Storage: ${backendStorageDescription(config)}`,\n\t\t\t`Included: ${selection.builtIns.length} built-in group${selection.builtIns.length === 1 ? \"\" : \"s\"} \u00B7 ${selection.custom.length} extra path${selection.custom.length === 1 ? \"\" : \"s\"} \u00B7 Sessions ${selection.sessions ? \"on\" : \"off\"}`,\n\t\t\t`Automatic sync: ${automaticSyncSummary(config.automatic)}`,\n\t\t\t`Last applied: ${lastAppliedSnapshot}`,\n\t\t\t...(currentAttention\n\t\t\t\t? [\n\t\t\t\t\t\tcurrentAttention.decision.setupName === config.setupName\n\t\t\t\t\t\t\t? \"Sync status: Review needed\"\n\t\t\t\t\t\t\t: `Sync status: Review needed for setup ${safeTerminalText(currentAttention.decision.setupName)}`,\n\t\t\t\t\t\tattentionComparison?.remoteOnly.length === 0 &&\n\t\t\t\t\t\tattentionComparison.localOnly.length === 0\n\t\t\t\t\t\t\t? \"Only the synced-content order differs.\"\n\t\t\t\t\t\t\t: `Remote-only paths: ${attentionComparison?.remoteOnly.length ?? 0} \u00B7 Device-only paths: ${attentionComparison?.localOnly.length ?? 0}`,\n\t\t\t\t\t\t\"Nothing has been changed.\",\n\t\t\t\t\t]\n\t\t\t\t: currentObservation\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t`Startup check (${safeTerminalText(currentObservation.checkedAt)}): ${observationSummary(currentObservation)}`,\n\t\t\t\t\t\t\t\"Check-time observation only; synchronization rechecks current content.\",\n\t\t\t\t\t\t]\n\t\t\t\t\t: [\"Remote status: Not checked\"]),\n\t\t\t...(noSyncedContent\n\t\t\t\t? [\n\t\t\t\t\t\t\"\",\n\t\t\t\t\t\t\"No included content is selected. Choose included content in Settings before syncing.\",\n\t\t\t\t\t]\n\t\t\t\t: []),\n\t\t\t\"\",\n\t\t\t\"What do you want to do?\",\n\t\t];\n\t\treturn {\n\t\t\ttitle: (changesBlocked\n\t\t\t\t? [\"Manage sync\", ...operationStatusLines(operation)]\n\t\t\t\t: ordinaryTitle\n\t\t\t).join(\"\\n\"),\n\t\t\tactions: operationActions(operation, noSyncedContent, canSwitch, mainActions),\n\t\t\toperation,\n\t\t\t...(currentObservation ? { observation: currentObservation } : {}),\n\t\t\t...(currentAttention\n\t\t\t\t? {\n\t\t\t\t\t\tattention: currentAttention,\n\t\t\t\t\t\tattentionBlocksSync: currentAttention.decision.setupName === config.setupName,\n\t\t\t\t\t\tattentionReviewDisabled: changesBlocked,\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t};\n\t} catch (error) {\n\t\tif (signal?.aborted) throw error;\n\t\treturn {\n\t\t\ttitle: [\n\t\t\t\t\"Manage sync\",\n\t\t\t\t\"\",\n\t\t\t\t\"Settings need attention. Automatic sync is paused.\",\n\t\t\t\t`Current sync setup: ${safeTerminalText(typeof raw.activeSyncSetup === \"string\" ? raw.activeSyncSetup : \"none\")}`,\n\t\t\t\t`Error: ${safeTerminalText(errorMessage(error))}`,\n\t\t\t\t`File: ${safeTerminalText(await activeLocalConfigPath())}`,\n\t\t\t\t\"\",\n\t\t\t\t\"What do you want to do?\",\n\t\t\t].join(\"\\n\"),\n\t\t\tactions: [\"Sync setups\u2026\", \"Storage connections\u2026\", \"History & recovery\u2026\", \"Help\"],\n\t\t};\n\t}\n}\n\nfunction operationActions(\n\toperation: OperationAvailability,\n\tnoSyncedContent: boolean,\n\tcanSwitch: boolean,\n\tmainActions: string[],\n) {\n\tif (operationCanRecover(operation)) {\n\t\treturn [\n\t\t\t\"Restore sync access\u2026 (recommended)\",\n\t\t\t\"Status & changes\",\n\t\t\t\"History & recovery\u2026\",\n\t\t\t\"Help\",\n\t\t];\n\t}\n\tif (operation.kind !== \"free\") {\n\t\treturn [\"Refresh operation status\", \"Status & changes\", \"History & recovery\u2026\", \"Help\"];\n\t}\n\treturn noSyncedContent\n\t\t? [\"Settings\", ...(canSwitch ? [\"Switch sync setup\"] : []), \"Status & changes\", \"More\u2026\"]\n\t\t: mainActions;\n}\n\nfunction operationStatusLines(operation: OperationAvailability): string[] {\n\tswitch (operation.kind) {\n\t\tcase \"free\":\n\t\t\treturn [];\n\t\tcase \"live\": {\n\t\t\tconst command = truncateToWidth(safeTerminalText(operation.lock.command), 16, \"\u2026\");\n\t\t\treturn [\n\t\t\t\t`Running: ${command} (pid ${operation.lock.pid}). Wait, then refresh; Settings and More return.`,\n\t\t\t];\n\t\t}\n\t\tcase \"busy\":\n\t\t\treturn [\n\t\t\t\t\"Pi-sync may be starting or finishing. Wait, then refresh; Settings and More remain unavailable.\",\n\t\t\t];\n\t\tcase \"recoverable-stale\":\n\t\t\treturn [\n\t\t\t\t\"Sync paused: old lock remains. Close other Pi sessions then restore; Settings and More return.\",\n\t\t\t];\n\t\tcase \"recoverable-unreadable\":\n\t\t\treturn [\n\t\t\t\t\"Sync paused: owner unknown. Close other Pi sessions then restore; Settings and More return.\",\n\t\t\t];\n\t\tcase \"inspection-error\":\n\t\t\treturn [\n\t\t\t\t\"Lock check failed. Fix path access, then refresh; Settings and More remain unavailable.\",\n\t\t\t];\n\t}\n}\n\nexport function backendStorageDescription(config: AnySyncConfig) {\n\tconst connection = safeTerminalText(config.connectionName);\n\tswitch (config.backend.type) {\n\t\tcase \"s3\": {\n\t\t\tconst type =\n\t\t\t\tconfig.backend.profile.kind === \"r2\" ||\n\t\t\t\tisCloudflareR2Endpoint(config.backend.profile.endpoint)\n\t\t\t\t\t? \"Cloudflare R2\"\n\t\t\t\t\t: \"S3-compatible\";\n\t\t\treturn `${type} \u00B7 ${connection} \u00B7 ${safeTerminalText(config.backend.destination.bucket)}`;\n\t\t}\n\t\tcase \"webdav\":\n\t\t\treturn `WebDAV \u00B7 ${connection} \u00B7 ${safeTerminalText(config.backend.destination.path)}`;\n\t\tcase \"git\":\n\t\t\treturn `Git \u00B7 ${connection} \u00B7 ${safeTerminalText(config.backend.destination.branch)}`;\n\t}\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, runMenu } from \"@narumitw/pi-tui-kit\";\nimport { loadConfig } from \"../settings/config.js\";\nimport { readLocalConfigObject } from \"../settings/settings-store.js\";\nimport { ownRecord } from \"../settings/settings-validation.js\";\nimport { syncErrorGuidance } from \"../sync/sync-error-guidance.js\";\nimport { syncIncludeSelection } from \"../sync/sync-policy.js\";\nimport { safeTerminalText } from \"./terminal-text.js\";\n\nexport async function countValidSyncSetups(\n\tsetups: Record<string, unknown> | undefined,\n\tsignal?: AbortSignal,\n) {\n\tlet count = 0;\n\tfor (const name of Object.keys(setups ?? {})) {\n\t\tthrowIfAborted(signal);\n\t\tlet valid = false;\n\t\ttry {\n\t\t\tawait loadConfig(name);\n\t\t\tvalid = true;\n\t\t} catch {\n\t\t\t// Invalid setups stay visible in management but are not switchable.\n\t\t}\n\t\tthrowIfAborted(signal);\n\t\tif (valid) count += 1;\n\t}\n\treturn count;\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\ntype SyncSetupActions = {\n\tadd(signal?: AbortSignal): Promise<void>;\n\tedit(name: string, signal?: AbortSignal): Promise<void>;\n\tmakeCurrent(name: string, signal?: AbortSignal): Promise<\"exit\" | undefined>;\n\tremove(name: string, signal?: AbortSignal): Promise<void>;\n};\n\ninterface SetupMenuState {\n\tsetups: Record<string, unknown>;\n\tactive?: string;\n\tselected?: {\n\t\tname: string;\n\t\tdetail: string[];\n\t\tvalid: boolean;\n\t\tremoveUnavailable: boolean;\n\t};\n}\n\nexport async function showSyncSetups(\n\tctx: ExtensionCommandContext,\n\tactions: SyncSetupActions,\n\tsignal?: AbortSignal,\n): Promise<\"exit\" | undefined> {\n\tlet selectedName: string | undefined;\n\tlet exit = false;\n\tconst nameById = new Map<string, string>();\n\ttype Screen = \"list\" | \"detail\";\n\ttype Action = \"add\" | \"select\" | \"make-current\" | \"edit\" | \"remove\" | \"back\";\n\tconst menu = defineMenu<SetupMenuState, Screen, Action, ExtensionCommandContext>({\n\t\tstart: \"list\",\n\t\tscreens: {\n\t\t\tlist: ({ state }) => {\n\t\t\t\tnameById.clear();\n\t\t\t\tconst names = Object.keys(state.setups).sort((left, right) => left.localeCompare(right));\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"actions\",\n\t\t\t\t\ttitle: \"Sync setups\",\n\t\t\t\t\tlines: [\"What to sync, where to store it, and when to sync.\"],\n\t\t\t\t\titems: [\n\t\t\t\t\t\t{ id: \"add\", label: \"Add sync setup\", action: \"add\" },\n\t\t\t\t\t\t...names.map((name, index) => {\n\t\t\t\t\t\t\tconst id = `setup:${index}`;\n\t\t\t\t\t\t\tnameById.set(id, name);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\tlabel: `${safeTerminalText(name)}${name === state.active ? \" (current)\" : \"\"}`,\n\t\t\t\t\t\t\t\tdescription: setupSummary(state.setups[name]),\n\t\t\t\t\t\t\t\taction: \"select\" as const,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tdetail: ({ state }) => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: state.selected\n\t\t\t\t\t? `Sync setup \u201C${safeTerminalText(state.selected.name)}\u201D`\n\t\t\t\t\t: \"Sync setup\",\n\t\t\t\tlines: state.selected?.detail ?? [\"This sync setup no longer exists.\"],\n\t\t\t\titems: state.selected\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t...(!state.selected.name ||\n\t\t\t\t\t\t\tstate.selected.name === state.active ||\n\t\t\t\t\t\t\t!state.selected.valid\n\t\t\t\t\t\t\t\t? []\n\t\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tid: \"make-current\",\n\t\t\t\t\t\t\t\t\t\t\tlabel: \"Make current\u2026\",\n\t\t\t\t\t\t\t\t\t\t\taction: \"make-current\" as const,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t{ id: \"edit\", label: \"Edit storage location\u2026\", action: \"edit\" },\n\t\t\t\t\t\t\t...(state.selected.removeUnavailable\n\t\t\t\t\t\t\t\t? []\n\t\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tid: \"remove\",\n\t\t\t\t\t\t\t\t\t\t\tlabel: \"Remove sync setup\u2026\",\n\t\t\t\t\t\t\t\t\t\t\taction: \"remove\" as const,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t{ id: \"back\", label: \"Back\", action: \"back\" },\n\t\t\t\t\t\t]\n\t\t\t\t\t: [{ id: \"back\", label: \"Back\", action: \"back\" }],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\tadd: async () => {\n\t\t\t\ttry {\n\t\t\t\t\tawait actions.add(signal);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!signal?.aborted) {\n\t\t\t\t\t\tctx.ui.notify(`Sync setup was not added: ${menuErrorMessage(error)}`, \"error\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn { kind: \"stay\" };\n\t\t\t},\n\t\t\tselect: async ({ itemId }) => {\n\t\t\t\tselectedName = nameById.get(itemId);\n\t\t\t\treturn selectedName ? { kind: \"to\", screen: \"detail\" } : { kind: \"rejected\" };\n\t\t\t},\n\t\t\t\"make-current\": async () => {\n\t\t\t\tif (!selectedName) return { kind: \"rejected\" };\n\t\t\t\ttry {\n\t\t\t\t\texit = (await actions.makeCurrent(selectedName, signal)) === \"exit\";\n\t\t\t\t\treturn exit ? { kind: \"close\" } : { kind: \"stay\" };\n\t\t\t\t} catch (error) {\n\t\t\t\t\tnotifySetupChangeError(ctx, selectedName, error, signal);\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t},\n\t\t\tedit: async () => {\n\t\t\t\tif (!selectedName) return { kind: \"rejected\" };\n\t\t\t\ttry {\n\t\t\t\t\tawait actions.edit(selectedName, signal);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tnotifySetupChangeError(ctx, selectedName, error, signal);\n\t\t\t\t}\n\t\t\t\treturn { kind: \"stay\" };\n\t\t\t},\n\t\t\tremove: async () => {\n\t\t\t\tif (!selectedName) return { kind: \"rejected\" };\n\t\t\t\tconst name = selectedName;\n\t\t\t\ttry {\n\t\t\t\t\tawait actions.remove(name, signal);\n\t\t\t\t\tselectedName = undefined;\n\t\t\t\t\treturn { kind: \"back\" };\n\t\t\t\t} catch (error) {\n\t\t\t\t\tnotifySetupChangeError(ctx, name, error, signal);\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t},\n\t\t\tback: async () => {\n\t\t\t\tselectedName = undefined;\n\t\t\t\treturn { kind: \"back\" };\n\t\t\t},\n\t\t},\n\t});\n\tawait runMenu(ctx, menu, {\n\t\tgetState: async () => loadSetupMenuState(selectedName, signal),\n\t\tsignal,\n\t\tisCurrent: () => !signal?.aborted,\n\t});\n\treturn exit ? \"exit\" : undefined;\n}\n\nasync function loadSetupMenuState(\n\tselectedName: string | undefined,\n\tsignal?: AbortSignal,\n): Promise<SetupMenuState> {\n\tconst raw = await readLocalConfigObject();\n\tthrowIfAborted(signal);\n\tconst setups = ownRecord(raw?.syncSetups) ?? {};\n\tconst active = typeof raw?.activeSyncSetup === \"string\" ? raw.activeSyncSetup : undefined;\n\tif (!selectedName || !ownRecord(setups[selectedName])) return { setups, active };\n\tconst setupCount = Object.keys(setups).length;\n\tconst isCurrent = selectedName === active;\n\tlet detail: string[];\n\tlet valid = true;\n\ttry {\n\t\tconst config = await loadConfig(selectedName);\n\t\tthrowIfAborted(signal);\n\t\tconst selection = syncIncludeSelection(config.include);\n\t\tdetail = [\n\t\t\t`Status: ${isCurrent ? \"Current\" : \"Not current\"}`,\n\t\t\t`Storage connection: ${safeTerminalText(config.connectionName)}`,\n\t\t\t`Endpoint: ${storageEndpoint(config)}`,\n\t\t\t`Storage location: ${storageLocation(config)}`,\n\t\t\t`Included content: ${selection.builtIns.length} built-in groups \u00B7 ${selection.custom.length} extra paths`,\n\t\t\t`Sessions: ${selection.sessions ? \"On \u2014 privacy-sensitive\" : \"Off\"}`,\n\t\t\t`Automatic sync: ${config.automatic ? \"On\" : \"Off\"}`,\n\t\t\tisCurrent\n\t\t\t\t? \"Edit included content and automatic sync in /sync \u2192 Settings.\"\n\t\t\t\t: \"To edit included content or automatic sync, make this setup current, then open /sync \u2192 Settings.\",\n\t\t];\n\t} catch (error) {\n\t\tvalid = false;\n\t\tdetail = [\n\t\t\t`Status: Invalid${isCurrent ? \" current setup\" : \"\"}`,\n\t\t\t`Reason: ${menuErrorMessage(error)}`,\n\t\t\t\"Make current and sync are unavailable until this setup is repaired.\",\n\t\t];\n\t}\n\tconst removeUnavailable = isCurrent && setupCount > 1;\n\tif (removeUnavailable) detail.push(\"Remove unavailable: switch to another setup first.\");\n\treturn {\n\t\tsetups,\n\t\tactive,\n\t\tselected: { name: selectedName, detail, valid, removeUnavailable },\n\t};\n}\n\nfunction notifySetupChangeError(\n\tctx: ExtensionCommandContext,\n\tname: string,\n\terror: unknown,\n\tsignal?: AbortSignal,\n) {\n\tif (signal?.aborted) return;\n\tctx.ui.notify(\n\t\t`Sync setup \u201C${safeTerminalText(name)}\u201D was not changed: ${menuErrorMessage(error)}`,\n\t\t\"error\",\n\t);\n}\n\nfunction menuErrorMessage(error: unknown) {\n\treturn syncErrorGuidance(error);\n}\n\nfunction setupSummary(value: unknown) {\n\tconst storage = ownRecord(ownRecord(value)?.storage);\n\tif (!storage || typeof storage.connection !== \"string\") return \"Invalid storage reference\";\n\treturn safeTerminalText(\n\t\t`${storage.connection} \u00B7 ${storage.bucket ?? storage.branch ?? \"WebDAV\"} \u00B7 ${storage.path ?? \"missing path\"}`,\n\t);\n}\n\nfunction storageEndpoint(config: Awaited<ReturnType<typeof loadConfig>>) {\n\tswitch (config.backend.type) {\n\t\tcase \"s3\":\n\t\t\treturn safeTerminalText(config.backend.profile.endpoint);\n\t\tcase \"git\":\n\t\t\treturn safeTerminalText(config.backend.profile.remote);\n\t\tcase \"webdav\":\n\t\t\treturn safeTerminalText(config.backend.profile.url);\n\t}\n}\n\nfunction storageLocation(config: Awaited<ReturnType<typeof loadConfig>>) {\n\tswitch (config.backend.type) {\n\t\tcase \"s3\":\n\t\t\treturn safeTerminalText(`${config.backend.destination.bucket}/${config.storagePath}`);\n\t\tcase \"git\":\n\t\t\treturn safeTerminalText(`Git \u00B7 ${config.backend.destination.branch}:${config.storagePath}`);\n\t\tcase \"webdav\":\n\t\t\treturn safeTerminalText(`WebDAV \u00B7 ${config.storagePath}`);\n\t}\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, runMenu } from \"@narumitw/pi-tui-kit\";\nimport { loadConfig } from \"../settings/config.js\";\nimport { localConfigPath } from \"../settings/config-file.js\";\nimport { updateSyncSetup } from \"../settings/settings-management.js\";\nimport { updateLocalConfig } from \"../settings/settings-store.js\";\nimport {\n\tSETUP_SWITCH_ACTION_OPTIONS,\n\tsaveOnSwitch,\n\tsetupSwitchActionFromLabel,\n\tsetupSwitchActionLabel,\n} from \"../sync/setup-switch.js\";\nimport type { RunRoute } from \"./cancellable-operation.js\";\nimport { dispatchManagerResult } from \"./manager-result-dispatcher.js\";\nimport { AUTOMATIC_SYNC_DESCRIPTION } from \"./setup/setup-prompts.js\";\nimport { safeTerminalText } from \"./terminal-text.js\";\n\nexport type SyncSettingsRoute = RunRoute;\n\nexport async function showSyncSettings(\n\tctx: ExtensionCommandContext,\n\trunRoute: SyncSettingsRoute,\n\tsignal?: AbortSignal,\n) {\n\tif (ctx.mode !== \"tui\") {\n\t\tctx.ui.notify(`Edit pi-sync settings manually: ${safeTerminalText(localConfigPath())}`, \"info\");\n\t\treturn;\n\t}\n\tconst initial = await loadConfig();\n\tif (signal?.aborted) return;\n\tconst setupName = initial.setupName;\n\ttype Action = \"automatic\" | \"skip-secret-scan\" | \"on-switch\" | \"include\" | \"remote-include\";\n\tconst menu = defineMenu<\n\t\tAwaited<ReturnType<typeof loadConfig>>,\n\t\t\"settings\",\n\t\tAction,\n\t\tExtensionCommandContext\n\t>({\n\t\tstart: \"settings\",\n\t\tscreens: {\n\t\t\tsettings: ({ state }) => ({\n\t\t\t\tkind: \"settings\",\n\t\t\t\ttitle: \"Pi Sync Settings\",\n\t\t\t\tlines: [\n\t\t\t\t\t`Sync setup: ${safeTerminalText(state.setupName)} \u00B7 Storage connection: ${safeTerminalText(state.connectionName)}`,\n\t\t\t\t],\n\t\t\t\titems: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"automatic\",\n\t\t\t\t\t\tlabel: \"Automatic sync\",\n\t\t\t\t\t\tdescription: AUTOMATIC_SYNC_DESCRIPTION,\n\t\t\t\t\t\tcurrentValue: state.automatic ? \"On\" : \"Off\",\n\t\t\t\t\t\tvalues: [\"On\", \"Off\"],\n\t\t\t\t\t\taction: \"automatic\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"skipSecretScan\",\n\t\t\t\t\t\tlabel: \"Skip secret scan (all setups)\",\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"All setups: allow pushes without checking managed local files for possible secrets.\",\n\t\t\t\t\t\tcurrentValue: state.skipSecretScan ? \"On\" : \"Off\",\n\t\t\t\t\t\tvalues: [\"On\", \"Off\"],\n\t\t\t\t\t\taction: \"skip-secret-scan\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"onSwitch\",\n\t\t\t\t\t\tlabel: \"After switching setup (all setups)\",\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"All setups: ask before a pull review, open it automatically, or switch without pulling.\",\n\t\t\t\t\t\tcurrentValue: setupSwitchActionLabel(state.onSwitch),\n\t\t\t\t\t\tvalues: SETUP_SWITCH_ACTION_OPTIONS.map(({ label }) => label),\n\t\t\t\t\t\taction: \"on-switch\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"include\",\n\t\t\t\t\t\tlabel: \"Included content\",\n\t\t\t\t\t\tdescription: `${state.include.length} selected path${state.include.length === 1 ? \"\" : \"s\"}. Choose which paths this setup syncs.`,\n\t\t\t\t\t\tcurrentValue: \"Open editor\",\n\t\t\t\t\t\taction: \"include\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"remoteInclude\",\n\t\t\t\t\t\tlabel: \"Compare synced content\",\n\t\t\t\t\t\tdescription: \"Review this device and remote content lists before choosing either one.\",\n\t\t\t\t\t\tcurrentValue: \"Review\",\n\t\t\t\t\t\taction: \"remote-include\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\tautomatic: async ({ value, signal: actionSignal }) => {\n\t\t\t\tconst automatic = value === \"On\";\n\t\t\t\tconst mutationSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;\n\t\t\t\ttry {\n\t\t\t\t\tconst latest = await loadConfig(setupName);\n\t\t\t\t\tif (mutationSignal.aborted) return { kind: \"rejected\" };\n\t\t\t\t\tif (latest.automatic === automatic) return { kind: \"stay\" };\n\t\t\t\t\tawait updateSyncSetup(\n\t\t\t\t\t\tsetupName,\n\t\t\t\t\t\t(setup) => ({ ...setup, sync: { ...setup.sync, automatic } }),\n\t\t\t\t\t\t{ signal: mutationSignal },\n\t\t\t\t\t);\n\t\t\t\t\tif (mutationSignal.aborted) return { kind: \"rejected\" };\n\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t`Automatic sync ${automatic ? \"enabled\" : \"disabled\"} for \u201C${safeTerminalText(setupName)}\u201D.`,\n\t\t\t\t\t\t\"info\",\n\t\t\t\t\t);\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!mutationSignal.aborted) notifySaveFailure(ctx, error);\n\t\t\t\t\treturn { kind: \"rejected\" };\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"skip-secret-scan\": async ({ value, signal: actionSignal }) => {\n\t\t\t\tconst skipSecretScan = value === \"On\";\n\t\t\t\tconst mutationSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;\n\t\t\t\ttry {\n\t\t\t\t\tconst latest = await loadConfig(setupName);\n\t\t\t\t\tif (mutationSignal.aborted) return { kind: \"rejected\" };\n\t\t\t\t\tif (latest.skipSecretScan === skipSecretScan) return { kind: \"stay\" };\n\t\t\t\t\tawait updateLocalConfig((settings) => ({ ...settings, skipSecretScan }), mutationSignal);\n\t\t\t\t\tif (mutationSignal.aborted) return { kind: \"rejected\" };\n\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t`Secret scan ${skipSecretScan ? \"disabled\" : \"enabled\"} for pushes in all setups.`,\n\t\t\t\t\t\t\"info\",\n\t\t\t\t\t);\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!mutationSignal.aborted) notifySaveFailure(ctx, error);\n\t\t\t\t\treturn { kind: \"rejected\" };\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"on-switch\": async ({ value, signal: actionSignal }) => {\n\t\t\t\tconst action = value ? setupSwitchActionFromLabel(value) : undefined;\n\t\t\t\tif (!action) return { kind: \"rejected\" };\n\t\t\t\tconst mutationSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;\n\t\t\t\ttry {\n\t\t\t\t\tconst latest = await loadConfig(setupName);\n\t\t\t\t\tif (mutationSignal.aborted) return { kind: \"rejected\" };\n\t\t\t\t\tif (latest.onSwitch === action) return { kind: \"stay\" };\n\t\t\t\t\tawait saveOnSwitch(action, mutationSignal);\n\t\t\t\t\tif (mutationSignal.aborted) return { kind: \"rejected\" };\n\t\t\t\t\tctx.ui.notify(`After switching setup: ${value}.`, \"info\");\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!mutationSignal.aborted) notifySaveFailure(ctx, error);\n\t\t\t\t\treturn { kind: \"rejected\" };\n\t\t\t\t}\n\t\t\t},\n\t\t\tinclude: async ({ signal: actionSignal }) => {\n\t\t\t\tconst editorSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;\n\t\t\t\tawait runRoute(\"files\", editorSignal, undefined, setupName);\n\t\t\t\treturn editorSignal.aborted ? { kind: \"rejected\" } : { kind: \"stay\" };\n\t\t\t},\n\t\t\t\"remote-include\": async ({ signal: actionSignal }) => {\n\t\t\t\tconst reviewSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;\n\t\t\t\tconst { showRemoteSelectionReview } = await import(\"./remote-selection-ui.js\");\n\t\t\t\tif (reviewSignal.aborted) return { kind: \"rejected\" };\n\t\t\t\tconst review = await showRemoteSelectionReview(ctx, setupName, reviewSignal, undefined, {\n\t\t\t\t\torigin: \"settings\",\n\t\t\t\t\trunRoute,\n\t\t\t\t});\n\t\t\t\tif (reviewSignal.aborted) return { kind: \"rejected\" };\n\t\t\t\tif (review.kind === \"route-result\") {\n\t\t\t\t\tconst disposition = await dispatchManagerResult(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\treview.result,\n\t\t\t\t\t\treview.route,\n\t\t\t\t\t\trunRoute,\n\t\t\t\t\t\treviewSignal,\n\t\t\t\t\t);\n\t\t\t\t\treturn disposition.kind === \"close\" ? { kind: \"close\" } : { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\treturn review.kind === \"closed\" || review.kind === \"stale\"\n\t\t\t\t\t? { kind: \"close\" }\n\t\t\t\t\t: { kind: \"stay\" };\n\t\t\t},\n\t\t},\n\t});\n\tawait runMenu(ctx, menu, {\n\t\tgetState: () => loadConfig(setupName),\n\t\tsignal,\n\t\tisCurrent: () => !signal?.aborted,\n\t});\n}\n\nfunction notifySaveFailure(ctx: ExtensionCommandContext, error: unknown) {\n\tctx.ui.notify(\n\t\t`Pi Sync settings save failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\"error\",\n\t);\n}\n", "import { isDeepStrictEqual } from \"node:util\";\nimport type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, runMenu } from \"@narumitw/pi-tui-kit\";\nimport {\n\taddStorageConnection,\n\tremoveStorageConnection,\n\tupdateStorageConnection,\n} from \"../settings/settings-management.js\";\nimport { readLocalConfigObject } from \"../settings/settings-store.js\";\nimport {\n\tisCloudflareR2Endpoint,\n\tnormalizeS3Endpoint,\n\townRecord,\n} from \"../settings/settings-validation.js\";\nimport { syncErrorGuidance } from \"../sync/sync-error-guidance.js\";\nimport { showAddGitStorageProfile, showEditGitStorageProfile } from \"./setup/git-ui.js\";\nimport {\n\tapplyS3CredentialUpdate,\n\tchooseS3Credentials,\n\tchooseS3CredentialUpdate,\n} from \"./setup/s3-credentials-ui.js\";\nimport { promptResourceName } from \"./setup/setup-prompts.js\";\nimport { saveReviewedDraft } from \"./setup/setup-review.js\";\nimport { requiredInput, requiredValueInput } from \"./setup/text-input.js\";\nimport { showAddWebDavStorageProfile, showEditWebDavStorageProfile } from \"./setup/webdav-ui.js\";\nimport { safeTerminalText } from \"./terminal-text.js\";\n\nexport async function showStorageConnections(ctx: ExtensionCommandContext, signal?: AbortSignal) {\n\tlet selectedName: string | undefined;\n\tconst nameById = new Map<string, string>();\n\ttype Screen = \"list\" | \"detail\";\n\ttype Action = \"add\" | \"select\" | \"edit\" | \"remove\" | \"back\";\n\tconst menu = defineMenu<\n\t\tAwaited<ReturnType<typeof loadStorageMenuState>>,\n\t\tScreen,\n\t\tAction,\n\t\tExtensionCommandContext\n\t>({\n\t\tstart: \"list\",\n\t\tscreens: {\n\t\t\tlist: ({ state }) => {\n\t\t\t\tnameById.clear();\n\t\t\t\tconst names = Object.keys(state.profiles).sort((left, right) => left.localeCompare(right));\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"actions\",\n\t\t\t\t\ttitle: \"Storage connections\",\n\t\t\t\t\tlines: state.version3\n\t\t\t\t\t\t? [\"Server addresses and sign-in details, reusable across sync setups.\"]\n\t\t\t\t\t\t: [\"Create version 3 settings before managing storage connections.\"],\n\t\t\t\t\titems: state.version3\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t{ id: \"add\", label: \"Add storage connection\", action: \"add\" as const },\n\t\t\t\t\t\t\t\t...names.map((name, index) => {\n\t\t\t\t\t\t\t\t\tconst id = `connection:${index}`;\n\t\t\t\t\t\t\t\t\tnameById.set(id, name);\n\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\t\t\tlabel: safeTerminalText(name),\n\t\t\t\t\t\t\t\t\t\tdescription: connectionSummary(ownRecord(state.profiles[name]) ?? {}),\n\t\t\t\t\t\t\t\t\t\taction: \"select\" as const,\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: [],\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tdetail: ({ state }) => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: state.selected\n\t\t\t\t\t? `Storage connection \u201C${safeTerminalText(state.selected.name)}\u201D`\n\t\t\t\t\t: \"Storage connection\",\n\t\t\t\tlines: state.selected?.lines ?? [\"This storage connection no longer exists.\"],\n\t\t\t\titems: state.selected\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t{ id: \"edit\", label: \"Edit storage connection\u2026\", action: \"edit\" },\n\t\t\t\t\t\t\t...(state.selected.usedBy.length === 0\n\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tid: \"remove\",\n\t\t\t\t\t\t\t\t\t\t\tlabel: \"Remove storage connection\u2026\",\n\t\t\t\t\t\t\t\t\t\t\taction: \"remove\" as const,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t\t{ id: \"back\", label: \"Back\", action: \"back\" },\n\t\t\t\t\t\t]\n\t\t\t\t\t: [{ id: \"back\", label: \"Back\", action: \"back\" }],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\tadd: async () => {\n\t\t\t\ttry {\n\t\t\t\t\tawait showAddStorageConnection(ctx, signal);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!signal?.aborted) {\n\t\t\t\t\t\tctx.ui.notify(`Storage connection was not added: ${syncErrorGuidance(error)}`, \"error\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn { kind: \"stay\" };\n\t\t\t},\n\t\t\tselect: async ({ itemId }) => {\n\t\t\t\tselectedName = nameById.get(itemId);\n\t\t\t\treturn selectedName ? { kind: \"to\", screen: \"detail\" } : { kind: \"rejected\" };\n\t\t\t},\n\t\t\tedit: async ({ state }) => {\n\t\t\t\tif (!state.selected || state.selected.name !== selectedName) return { kind: \"rejected\" };\n\t\t\t\ttry {\n\t\t\t\t\tawait editStorageConnection(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tstate.selected.name,\n\t\t\t\t\t\tstate.selected.profile,\n\t\t\t\t\t\tstate.selected.usedBy,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tnotifyConnectionError(ctx, state.selected.name, error, signal);\n\t\t\t\t}\n\t\t\t\treturn { kind: \"stay\" };\n\t\t\t},\n\t\t\tremove: async ({ state }) => {\n\t\t\t\tif (!state.selected || state.selected.name !== selectedName) return { kind: \"rejected\" };\n\t\t\t\tconst name = state.selected.name;\n\t\t\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\t\t\"Remove storage connection?\",\n\t\t\t\t\t`Remove local storage connection \u201C${safeTerminalText(name)}\u201D? Remote data and history are not deleted.`,\n\t\t\t\t\t{ signal },\n\t\t\t\t);\n\t\t\t\tif (!confirmed || signal?.aborted) return { kind: \"rejected\" };\n\t\t\t\ttry {\n\t\t\t\t\tawait removeStorageConnection(name, signal);\n\t\t\t\t\tctx.ui.notify(`Removed storage connection \u201C${safeTerminalText(name)}\u201D.`, \"info\");\n\t\t\t\t\tselectedName = undefined;\n\t\t\t\t\treturn { kind: \"back\" };\n\t\t\t\t} catch (error) {\n\t\t\t\t\tnotifyConnectionError(ctx, name, error, signal);\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t},\n\t\t\tback: async () => {\n\t\t\t\tselectedName = undefined;\n\t\t\t\treturn { kind: \"back\" };\n\t\t\t},\n\t\t},\n\t});\n\tawait runMenu(ctx, menu, {\n\t\tgetState: () => loadStorageMenuState(selectedName, signal),\n\t\tsignal,\n\t\tisCurrent: () => !signal?.aborted,\n\t});\n}\n\nasync function loadStorageMenuState(selectedName: string | undefined, signal?: AbortSignal) {\n\tconst raw = await readLocalConfigObject();\n\tif (signal?.aborted) throw signal.reason;\n\tconst profiles = ownRecord(raw?.storageConnections) ?? {};\n\tconst profile = selectedName ? ownRecord(profiles[selectedName]) : undefined;\n\tif (!selectedName || !profile) {\n\t\treturn { version3: raw?.version === 3, profiles, selected: undefined };\n\t}\n\tconst usedBy = referencingSetups(raw, selectedName);\n\treturn {\n\t\tversion3: raw?.version === 3,\n\t\tprofiles,\n\t\tselected: {\n\t\t\tname: selectedName,\n\t\t\tprofile,\n\t\t\tusedBy,\n\t\t\tlines: [\n\t\t\t\t`Type: ${connectionType(profile)}`,\n\t\t\t\t`Endpoint: ${connectionEndpoint(profile)}`,\n\t\t\t\t`Credentials: ${credentialSource(profile)}`,\n\t\t\t\t`Used by: ${usedBy.length > 0 ? usedBy.map(safeTerminalText).join(\", \") : \"No sync setups\"}`,\n\t\t\t\t...(usedBy.length > 0\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t\"Remove unavailable: remove the listed sync setups first. Switch away from a current setup before removing it if other setups remain.\",\n\t\t\t\t\t\t]\n\t\t\t\t\t: []),\n\t\t\t],\n\t\t},\n\t};\n}\n\nfunction notifyConnectionError(\n\tctx: ExtensionCommandContext,\n\tname: string,\n\terror: unknown,\n\tsignal?: AbortSignal,\n) {\n\tif (signal?.aborted) return;\n\tctx.ui.notify(\n\t\t`Storage connection \u201C${safeTerminalText(name)}\u201D was not changed: ${syncErrorGuidance(error)}`,\n\t\t\"error\",\n\t);\n}\n\nasync function editStorageConnection(\n\tctx: ExtensionCommandContext,\n\tname: string,\n\tprofile: Record<string, unknown>,\n\tusedBy: string[],\n\tsignal?: AbortSignal,\n) {\n\tif (ctx.mode !== \"tui\") {\n\t\tctx.ui.notify(\n\t\t\t\"Editing storage connections requires TUI mode for safe credential handling. Edit the private version 3 settings file instead.\",\n\t\t\t\"warning\",\n\t\t);\n\t\treturn;\n\t}\n\tif (profile.type === \"webdav\") {\n\t\tawait showEditWebDavStorageProfile(\n\t\t\tctx,\n\t\t\tname,\n\t\t\t{ ...profile, kind: \"webdav\", ...(ownRecord(profile.credentials) ?? {}) },\n\t\t\tsignal,\n\t\t\tusedBy,\n\t\t);\n\t\treturn;\n\t}\n\tif (profile.type === \"git\") {\n\t\tawait showEditGitStorageProfile(ctx, name, { ...profile, kind: \"git\" }, signal, usedBy);\n\t\treturn;\n\t}\n\tconst endpoint = await requiredInput(\n\t\tctx,\n\t\t\"Endpoint\",\n\t\tString(profile.endpoint ?? \"https://s3.example.com\"),\n\t\tsignal,\n\t\tnormalizeS3Endpoint,\n\t);\n\tif (!endpoint || signal?.aborted) return;\n\tconst region = await requiredInput(\n\t\tctx,\n\t\t\"Region\\n\\nUse your bucket's region; Cloudflare R2 uses auto.\",\n\t\tString(profile.region ?? \"auto\"),\n\t\tsignal,\n\t);\n\tif (!region || signal?.aborted) return;\n\tconst storedCredentials = ownRecord(profile.credentials) ?? {};\n\tconst credentials = await chooseS3CredentialUpdate(\n\t\tctx,\n\t\t{ ...profile, ...storedCredentials },\n\t\tsignal,\n\t);\n\tif (!credentials || signal?.aborted) return;\n\tconst saved = await saveReviewedDraft(\n\t\tctx,\n\t\t\"Review storage connection\",\n\t\t[\n\t\t\t`Storage connection: ${safeTerminalText(name)}`,\n\t\t\t`Endpoint: ${safeTerminalText(String(profile.endpoint ?? \"missing\"))} \u2192 ${safeTerminalText(endpoint)}`,\n\t\t\t`Region: ${safeTerminalText(String(profile.region ?? \"auto\"))} \u2192 ${safeTerminalText(region)}`,\n\t\t\t`Credentials: ${safeTerminalText(credentials.summary)}`,\n\t\t\t`Affected sync setups: ${usedBy.length > 0 ? usedBy.map(safeTerminalText).join(\", \") : \"None\"}`,\n\t\t\t\"Saving changes future storage access for every affected setup; it does not move remote data.\",\n\t\t],\n\t\t\"Save storage connection\",\n\t\t(saveSignal) =>\n\t\t\tupdateStorageConnection(\n\t\t\t\tname,\n\t\t\t\t(current) => {\n\t\t\t\t\tif (current.type !== \"s3\" || !isDeepStrictEqual(current, profile)) {\n\t\t\t\t\t\tthrow new Error(\"Storage connection changed while it was open; reopen it.\");\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...current,\n\t\t\t\t\t\tendpoint,\n\t\t\t\t\t\tregion,\n\t\t\t\t\t\tcredentials: applyS3CredentialUpdate(\n\t\t\t\t\t\t\tcurrent.credentials,\n\t\t\t\t\t\t\tcredentials,\n\t\t\t\t\t\t) as typeof current.credentials,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\tusedBy,\n\t\t\t\tsaveSignal,\n\t\t\t),\n\t\tsignal,\n\t);\n\tif (!saved || signal?.aborted) return;\n\tctx.ui.notify(`Saved storage connection \u201C${safeTerminalText(name)}\u201D.`, \"info\");\n}\n\nexport async function showAddStorageConnection(ctx: ExtensionCommandContext, signal?: AbortSignal) {\n\tif (ctx.mode !== \"tui\") {\n\t\tctx.ui.notify(\n\t\t\t\"Adding storage connections requires TUI mode for safe credential handling. Edit the private version 3 settings file instead.\",\n\t\t\t\"warning\",\n\t\t);\n\t\treturn false;\n\t}\n\tconst preset = await ctx.ui.select(\n\t\t\"Storage type\",\n\t\t[\"Cloudflare R2\", \"Other S3-compatible storage\", \"WebDAV\", \"Git\", \"Cancel\"],\n\t\t{ signal },\n\t);\n\tif (signal?.aborted || !preset || preset === \"Cancel\") return false;\n\tif (preset === \"WebDAV\") return showAddWebDavStorageProfile(ctx, signal);\n\tif (preset === \"Git\") return showAddGitStorageProfile(ctx, signal);\n\tconst name = await promptResourceName(\n\t\tctx,\n\t\t\"storage connection\",\n\t\tpreset === \"Cloudflare R2\" ? \"r2\" : \"s3\",\n\t\tsignal,\n\t);\n\tif (!name || signal?.aborted) return false;\n\tconst endpoint = await requiredValueInput(\n\t\tctx,\n\t\t\"S3 API endpoint\\n\\nUse the API URL from your storage provider, not its web console.\",\n\t\tpreset === \"Cloudflare R2\"\n\t\t\t? \"https://<account-id>.r2.cloudflarestorage.com\"\n\t\t\t: \"https://s3.example.com\",\n\t\tsignal,\n\t\tnormalizeS3Endpoint,\n\t);\n\tif (!endpoint || signal?.aborted) return false;\n\tconst region =\n\t\tpreset === \"Cloudflare R2\"\n\t\t\t? \"auto\"\n\t\t\t: await requiredInput(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"Region\\n\\nUse the region assigned to your bucket by the provider.\",\n\t\t\t\t\t\"us-east-1\",\n\t\t\t\t\tsignal,\n\t\t\t\t);\n\tif (!region || signal?.aborted) return false;\n\tconst credentials = await chooseS3Credentials(ctx, signal);\n\tif (!credentials || signal?.aborted) return false;\n\tconst saved = await saveReviewedDraft(\n\t\tctx,\n\t\t\"Review storage connection\",\n\t\t[\n\t\t\t`Name: ${safeTerminalText(name)}`,\n\t\t\t`Type: ${preset}`,\n\t\t\t`Endpoint: ${safeTerminalText(endpoint)}`,\n\t\t\t`Region: ${safeTerminalText(region)}`,\n\t\t\t`Credentials: ${safeTerminalText(credentials.summary)}`,\n\t\t\t\"Adding a connection does not contact remote storage or start syncing.\",\n\t\t],\n\t\t\"Add storage connection\",\n\t\t(saveSignal) =>\n\t\t\taddStorageConnection(\n\t\t\t\tname,\n\t\t\t\t{\n\t\t\t\t\ttype: \"s3\",\n\t\t\t\t\tendpoint,\n\t\t\t\t\tregion,\n\t\t\t\t\tcredentials: {\n\t\t\t\t\t\taccessKeyId: credentials.profileFields.accessKeyId ?? \"\",\n\t\t\t\t\t\tsecretAccessKey: credentials.profileFields.secretAccessKey ?? \"\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tsaveSignal,\n\t\t\t),\n\t\tsignal,\n\t);\n\tif (!saved) return false;\n\tif (signal?.aborted) return true;\n\tctx.ui.notify(`Added storage connection \u201C${safeTerminalText(name)}\u201D.`, \"info\");\n\treturn true;\n}\n\nfunction referencingSetups(raw: Record<string, unknown> | undefined, connection: string) {\n\treturn Object.entries(ownRecord(raw?.syncSetups) ?? {})\n\t\t.filter(([, value]) => ownRecord(ownRecord(value)?.storage)?.connection === connection)\n\t\t.map(([name]) => name)\n\t\t.sort((left, right) => left.localeCompare(right));\n}\n\nexport function connectionSummary(profile: Record<string, unknown>) {\n\treturn `${connectionType(profile)} \u00B7 ${connectionEndpoint(profile)}`;\n}\n\nfunction connectionType(profile: Record<string, unknown>) {\n\tif (profile.type === \"git\") return \"Git\";\n\tif (profile.type === \"webdav\") return \"WebDAV\";\n\tif (\n\t\tprofile.type === \"s3\" &&\n\t\ttypeof profile.endpoint === \"string\" &&\n\t\tisCloudflareR2Endpoint(profile.endpoint)\n\t) {\n\t\treturn \"Cloudflare R2\";\n\t}\n\treturn \"S3-compatible\";\n}\n\nfunction connectionEndpoint(profile: Record<string, unknown>) {\n\tconst value =\n\t\tprofile.type === \"git\"\n\t\t\t? profile.remote\n\t\t\t: profile.type === \"webdav\"\n\t\t\t\t? profile.url\n\t\t\t\t: profile.endpoint;\n\tif (typeof value !== \"string\" || value.length === 0) return \"Missing\";\n\tif (profile.type === \"git\") return safeTerminalText(value);\n\ttry {\n\t\tconst url = new URL(value);\n\t\treturn safeTerminalText(`${url.origin}${url.pathname}`);\n\t} catch {\n\t\treturn \"Invalid\";\n\t}\n}\n\nfunction credentialSource(profile: Record<string, unknown>) {\n\tif (profile.type === \"git\") return \"Git credential helper or SSH configuration\";\n\tconst credentials = ownRecord(profile.credentials);\n\tif (profile.type === \"webdav\") return credentials?.password ? \"Settings file\" : \"Missing\";\n\tif (credentials?.accessKeyId && credentials.secretAccessKey) return \"Settings file\";\n\treturn \"Missing\";\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, runMenu } from \"@narumitw/pi-tui-kit\";\nimport { loadConfig, syncConfigReviewIdentity } from \"../../settings/config.js\";\nimport { loadOnSwitch, readLocalConfigObject } from \"../../settings/settings-store.js\";\nimport type { AnySyncConfig } from \"../../settings/settings-types.js\";\nimport { ownRecord } from \"../../settings/settings-validation.js\";\nimport { useSyncSetup } from \"../../sync/setup-switch.js\";\nimport { errorMessage } from \"../../sync/sync-errors.js\";\nimport { automaticSyncSummary } from \"../automatic-sync-summary.js\";\nimport { type RunRoute, runCancellableOperation } from \"../cancellable-operation.js\";\nimport { dispatchManagerResult } from \"../manager-result-dispatcher.js\";\nimport { backendStorageDescription } from \"../manager-state.js\";\nimport { safeTerminalText } from \"../terminal-text.js\";\n\nasync function selectSetupForSwitch(\n\tctx: ExtensionCommandContext,\n\traw: Record<string, unknown>,\n\ttargets: Record<string, unknown>,\n\tactive: string | undefined,\n\tsignal?: AbortSignal,\n) {\n\tlet selectedName: string | undefined;\n\tconst nameById = new Map<string, string>();\n\tconst profiles = ownRecord(raw.storageConnections);\n\tconst menu = defineMenu<undefined, \"setups\", \"select\", ExtensionCommandContext>({\n\t\tstart: \"setups\",\n\t\tscreens: {\n\t\t\tsetups: () => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: \"Switch sync setup\",\n\t\t\t\tlines: [`Current sync setup: ${safeTerminalText(active ?? \"none\")}`],\n\t\t\t\titems: Object.keys(targets)\n\t\t\t\t\t.sort((left, right) => left.localeCompare(right))\n\t\t\t\t\t.map((candidate, index) => {\n\t\t\t\t\t\tconst target = ownRecord(targets[candidate]);\n\t\t\t\t\t\tconst storage = ownRecord(target?.storage);\n\t\t\t\t\t\tconst profileName =\n\t\t\t\t\t\t\ttypeof storage?.connection === \"string\" ? storage.connection : undefined;\n\t\t\t\t\t\tconst profile = profileName && profiles ? ownRecord(profiles[profileName]) : undefined;\n\t\t\t\t\t\tconst location = profile\n\t\t\t\t\t\t\t? profile.type === \"git\"\n\t\t\t\t\t\t\t\t? `${String(storage?.branch ?? \"missing branch\")}:${String(storage?.path ?? \"missing path\")}`\n\t\t\t\t\t\t\t\t: profile.type === \"s3\"\n\t\t\t\t\t\t\t\t\t? `${String(storage?.bucket ?? \"missing bucket\")}/${String(storage?.path ?? \"missing path\")}`\n\t\t\t\t\t\t\t\t\t: String(storage?.path ?? \"missing path\")\n\t\t\t\t\t\t\t: `invalid: missing connection ${profileName ?? \"reference\"}`;\n\t\t\t\t\t\tconst id = `setup:${index}`;\n\t\t\t\t\t\tnameById.set(id, candidate);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tlabel: `${safeTerminalText(candidate)}${candidate === active ? \" (current)\" : \"\"}`,\n\t\t\t\t\t\t\tdescription: `${safeTerminalText(profileName ?? \"unknown\")} \u00B7 ${safeTerminalText(location)}`,\n\t\t\t\t\t\t\taction: \"select\" as const,\n\t\t\t\t\t\t};\n\t\t\t\t\t}),\n\t\t\t\thint: \"close\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\tselect: async ({ itemId }) => {\n\t\t\t\tselectedName = nameById.get(itemId);\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 selectedName;\n}\n\nexport async function showSetupSwitcher(\n\tctx: ExtensionCommandContext,\n\trunRoute: RunRoute,\n\tselectedName?: string,\n\tsignal?: AbortSignal,\n) {\n\tconst raw = await readLocalConfigObject();\n\tif (signal?.aborted) return false;\n\tif (raw?.version !== 3) {\n\t\tctx.ui.notify(\"Add a second sync setup before switching setups.\", \"info\");\n\t\treturn false;\n\t}\n\tconst targets = ownRecord(raw.syncSetups);\n\tif (!targets) {\n\t\tctx.ui.notify(\"No sync setups are configured.\", \"warning\");\n\t\treturn false;\n\t}\n\tconst active = typeof raw.activeSyncSetup === \"string\" ? raw.activeSyncSetup : undefined;\n\tlet name = selectedName;\n\tif (!name) {\n\t\tname = await selectSetupForSwitch(ctx, raw, targets, active, signal);\n\t\tif (!name) return false;\n\t}\n\tif (!name || !Object.hasOwn(targets, name)) {\n\t\tctx.ui.notify(\n\t\t\t`Sync setup \u201C${safeTerminalText(name ?? \"unknown\")}\u201D no longer exists.`,\n\t\t\t\"warning\",\n\t\t);\n\t\treturn false;\n\t}\n\tif (name === active) {\n\t\tctx.ui.notify(`Sync setup \u201C${safeTerminalText(name)}\u201D is already current.`, \"info\");\n\t\treturn false;\n\t}\n\tlet config: AnySyncConfig;\n\ttry {\n\t\tconfig = await loadConfig(name);\n\t\tif (signal?.aborted) return false;\n\t} catch (error) {\n\t\tctx.ui.notify(\n\t\t\t`Cannot use sync setup \u201C${safeTerminalText(name)}\u201D: ${safeTerminalText(errorMessage(error))}`,\n\t\t\t\"error\",\n\t\t);\n\t\treturn false;\n\t}\n\tconst onSwitch = await loadOnSwitch();\n\tif (signal?.aborted) return false;\n\tconst switchEffect =\n\t\tonSwitch === \"ask-before-pull\"\n\t\t\t? \"After switching, pi-sync will ask whether to review a pull for this setup.\"\n\t\t\t: onSwitch === \"pull-after-switch\"\n\t\t\t\t? \"After switching, pi-sync will check this setup and show exact changes before applying them.\"\n\t\t\t\t: \"After switching, pi-sync will not pull or modify synced files.\";\n\tconst confirmed = await ctx.ui.confirm(\n\t\t\"Switch sync setup?\",\n\t\t[\n\t\t\t`From: ${safeTerminalText(active ?? \"none\")}`,\n\t\t\t`To: ${safeTerminalText(name)}`,\n\t\t\t`Storage: ${backendStorageDescription(config)}`,\n\t\t\t`Included content: ${config.include.length} paths`,\n\t\t\t`Automatic sync: ${automaticSyncSummary(config.automatic)} \u00B7 Sessions: ${config.include.includes(\"sessions\") ? \"On\" : \"Off\"}`,\n\t\t\t\"\",\n\t\t\tswitchEffect,\n\t\t].join(\"\\n\"),\n\t\t{ signal },\n\t);\n\tif (signal?.aborted || !confirmed) return false;\n\ttry {\n\t\tlet pullClosed = false;\n\t\tconst result = await useSyncSetup(\n\t\t\tctx,\n\t\t\tname,\n\t\t\tasync (selectedTarget) => {\n\t\t\t\tconst pullResult = await runCancellableOperation(\n\t\t\t\t\tctx,\n\t\t\t\t\t`Pulling sync setup \u201C${safeTerminalText(name)}\u201D\u2026`,\n\t\t\t\t\t\"pull\",\n\t\t\t\t\trunRoute,\n\t\t\t\t\t{\n\t\t\t\t\t\tcommitAware: true,\n\t\t\t\t\t\tcancelledMessage: null,\n\t\t\t\t\t\ttarget: selectedTarget,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tconst disposition = await dispatchManagerResult(ctx, pullResult, \"pull\", runRoute, signal);\n\t\t\t\tif (pullResult.kind === \"closed\" || pullResult.kind.endsWith(\"required\")) {\n\t\t\t\t\tpullClosed = disposition.kind === \"close\";\n\t\t\t\t}\n\t\t\t\tif (disposition.appliedRoute === \"pull\") return \"applied\";\n\t\t\t\tif (pullResult.kind === \"completed\") return pullResult.outcome;\n\t\t\t\treturn pullResult.kind === \"cancelled\" ? \"cancelled\" : undefined;\n\t\t\t},\n\t\t\tonSwitch,\n\t\t\tsignal,\n\t\t\tsyncConfigReviewIdentity(config),\n\t\t);\n\t\tif (pullClosed) return \"closed\";\n\t\treturn result.pullApplied ? \"pull-attempted\" : \"switched\";\n\t} catch (error) {\n\t\tif (signal?.aborted) return false;\n\t\tctx.ui.notify(\n\t\t\t`Sync setup \u201C${safeTerminalText(name)}\u201D was not switched: ${safeTerminalText(errorMessage(error))}`,\n\t\t\t\"error\",\n\t\t);\n\t\treturn false;\n\t}\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { refreshTargetCompletions } from \"../../commands/setup-completions.js\";\nimport { loadPartialConfig } from \"../../settings/config.js\";\nimport { removeSyncSetup } from \"../../settings/settings-management.js\";\nimport { readLocalConfigObject } from \"../../settings/settings-store.js\";\nimport { ownRecord } from \"../../settings/settings-validation.js\";\nimport type { RunRoute } from \"../cancellable-operation.js\";\nimport { showAddStorageConnection } from \"../storage-connections-ui.js\";\nimport { showSyncSetups } from \"../sync-setups-ui.js\";\nimport { safeTerminalText } from \"../terminal-text.js\";\nimport { showAddGitTarget, showEditGitTarget } from \"./git-ui.js\";\nimport { showAddS3Target, showEditS3Target } from \"./s3-ui.js\";\nimport { promptResourceName } from \"./setup-prompts.js\";\nimport { showSetupSwitcher } from \"./setup-switcher.js\";\nimport { showAddWebDavTarget, showEditWebDavTarget } from \"./webdav-ui.js\";\n\nexport async function showSyncSetupManager(\n\tctx: ExtensionCommandContext,\n\trunRoute: RunRoute,\n\tsignal?: AbortSignal,\n) {\n\treturn showSyncSetups(\n\t\tctx,\n\t\t{\n\t\t\tadd: async (setupSignal) => {\n\t\t\t\tawait showAddTarget(ctx, setupSignal);\n\t\t\t},\n\t\t\tedit: async (name, setupSignal) => {\n\t\t\t\tawait showEditTarget(ctx, name, setupSignal);\n\t\t\t},\n\t\t\tmakeCurrent: async (name, setupSignal) => {\n\t\t\t\tconst result = await showSetupSwitcher(ctx, runRoute, name, setupSignal);\n\t\t\t\treturn result === \"pull-attempted\" || result === \"closed\" ? \"exit\" : undefined;\n\t\t\t},\n\t\t\tremove: async (name, setupSignal) => {\n\t\t\t\tawait showRemoveTarget(ctx, name, setupSignal);\n\t\t\t},\n\t\t},\n\t\tsignal,\n\t);\n}\n\nasync function showAddTarget(ctx: ExtensionCommandContext, signal?: AbortSignal) {\n\tlet raw = await readLocalConfigObject();\n\tif (signal?.aborted) return;\n\tif (!raw) return void ctx.ui.notify(\"Set up the first sync setup before adding another.\", \"info\");\n\tif (raw.version !== 3) {\n\t\tctx.ui.notify(\n\t\t\t\"Version 1 and version 2 settings are unsupported and are never migrated.\",\n\t\t\t\"error\",\n\t\t);\n\t\treturn;\n\t}\n\tlet profiles = ownRecord(raw.storageConnections) ?? {};\n\tconst name = await promptResourceName(ctx, \"sync setup\", \"work\", signal);\n\tif (!name) return;\n\tconst createConnection = \"Add a new storage connection\u2026\";\n\tlet profile = await ctx.ui.select(\n\t\t\"Choose a storage connection\\n\\nReuse a server address and sign-in details. A new connection is saved separately and remains if you cancel this setup.\",\n\t\t[...Object.keys(profiles).sort(), createConnection, \"Cancel\"],\n\t\t{ signal },\n\t);\n\tif (signal?.aborted || !profile || profile === \"Cancel\") return;\n\tif (profile === createConnection) {\n\t\tconst previousNames = new Set(Object.keys(profiles));\n\t\tif (!(await showAddStorageConnection(ctx, signal))) return;\n\t\tif (signal?.aborted) return;\n\t\traw = (await readLocalConfigObject()) ?? raw;\n\t\tif (signal?.aborted) return;\n\t\tprofiles = ownRecord(raw.storageConnections) ?? {};\n\t\tprofile = Object.keys(profiles).find((candidate) => !previousNames.has(candidate));\n\t\tif (!profile) return;\n\t\tctx.ui.notify(\n\t\t\t`Connection \u201C${safeTerminalText(profile)}\u201D saved. Cancelling setup will keep this connection.`,\n\t\t\t\"info\",\n\t\t);\n\t}\n\tconst storageKind = ownRecord(profiles[profile])?.type;\n\tif (storageKind === \"webdav\") {\n\t\tconst saved = await showAddWebDavTarget(ctx, name, profile, signal);\n\t\tif (signal?.aborted) return;\n\t\tif (saved) await refreshTargetCompletions();\n\t\treturn;\n\t}\n\tif (storageKind === \"git\") {\n\t\tconst saved = await showAddGitTarget(ctx, name, profile, signal);\n\t\tif (signal?.aborted) return;\n\t\tif (saved) await refreshTargetCompletions();\n\t\treturn;\n\t}\n\tawait showAddS3Target(ctx, raw, profile, name, signal);\n}\n\nasync function showEditTarget(ctx: ExtensionCommandContext, name: string, signal?: AbortSignal) {\n\tconst partial = await loadPartialConfig(name);\n\tif (signal?.aborted) return;\n\tif (!partial.setupName) {\n\t\tctx.ui.notify(\"Create version 3 settings before editing a named sync setup.\", \"info\");\n\t\treturn;\n\t}\n\tif (partial.storageKind === \"webdav\") {\n\t\tawait showEditWebDavTarget(ctx, partial, signal);\n\t\treturn;\n\t}\n\tif (partial.storageKind === \"git\") {\n\t\tawait showEditGitTarget(ctx, partial, signal);\n\t\treturn;\n\t}\n\tawait showEditS3Target(ctx, partial, signal);\n}\n\nasync function showRemoveTarget(ctx: ExtensionCommandContext, name: string, signal?: AbortSignal) {\n\tconst confirmed = await ctx.ui.confirm(\n\t\t\"Remove sync setup?\",\n\t\t`Remove local sync setup \u201C${safeTerminalText(name)}\u201D? Remote data and history are not deleted.`,\n\t\t{ signal },\n\t);\n\tif (signal?.aborted || !confirmed) return;\n\tawait removeSyncSetup(name, signal);\n\tif (signal?.aborted) return;\n\tawait refreshTargetCompletions();\n\tif (signal?.aborted) return;\n\tctx.ui.notify(\n\t\t`Removed sync setup \u201C${safeTerminalText(name)}\u201D; remote data was not deleted.`,\n\t\t\"info\",\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAA8B,cAAAA,aAAY,WAAAC,gBAAe;;;ACgBzD,IAAM,kCAAmE;AAAA,EACxE,iBAAiB;AAAA,EACjB,cAAc;AACf;AAEA,eAAsB,6BACrB,eAAgD,iCACf;AACj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M;AAAA,EACjC,CAAC;AACD,SAAO,EAAE,IAAI,QAAQ,IAAI,KAAK,KAAK,QAAQ,OAAO,QAAQ,QAAQ,IAAI,KAAK,KAAK,OAAO;AACxF;",
6
- "names": ["defineMenu", "runMenu", "defineMenu", "runMenu", "defineMenu", "runMenu", "defineMenu", "runMenu", "defineMenu", "runMenu", "defineMenu", "runMenu", "defineMenu", "runMenu", "defineMenu", "runMenu"]
7
- }
@@ -1,21 +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
- showRemoteSelectionReview
5
- } from "./chunk-YDWUZVPN.ts";
6
- import "./chunk-HUDQATCL.ts";
7
- import "./chunk-T2B5IU74.ts";
8
- import "./chunk-LTBWGSBV.ts";
9
- import "./chunk-LCRI3ABW.ts";
10
- import "./chunk-C7XY5NF5.ts";
11
- import "./chunk-6LP3MCR2.ts";
12
- import "./chunk-TEN2ZBJV.ts";
13
- import "./chunk-2B2ELUF5.ts";
14
- import "./chunk-OEX4ABY6.ts";
15
- import "./chunk-THMF4BVL.ts";
16
- import "./chunk-T3HH3UEJ.ts";
17
- import "./chunk-JAAKLL6M.ts";
18
- export {
19
- showRemoteSelectionReview
20
- };
21
- //# sourceMappingURL=remote-selection-ui-QDNR7WEI.ts.map