@narumitw/pi-sync 0.57.9 → 0.57.11

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 (169) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +7 -1
  3. package/dist/chunks/{agent-candidate-GNEYR225.ts → agent-candidate-OCDPRI5G.ts} +12 -9
  4. package/dist/chunks/{agent-plan-3L7CRFDM.ts → agent-plan-P5B5RGZ7.ts} +22 -18
  5. package/dist/chunks/{agent-plan-3L7CRFDM.ts.map → agent-plan-P5B5RGZ7.ts.map} +1 -1
  6. package/dist/chunks/{agent-refusal-retry-RPTMUQXK.ts → agent-refusal-retry-476YGNU5.ts} +11 -8
  7. package/dist/chunks/{agent-refusal-retry-RPTMUQXK.ts.map → agent-refusal-retry-476YGNU5.ts.map} +1 -1
  8. package/dist/chunks/{agent-store-55CZOCPX.ts → agent-store-RJSMNOYP.ts} +12 -11
  9. package/dist/chunks/{agent-store-55CZOCPX.ts.map → agent-store-RJSMNOYP.ts.map} +1 -1
  10. package/dist/chunks/agent-sync-EUK2CPSS.ts +22 -0
  11. package/dist/chunks/{chunk-U3XRI2HF.ts → chunk-3IYAPMST.ts} +11 -11
  12. package/dist/chunks/{chunk-B4QZBDBT.ts → chunk-45COPAK7.ts} +10 -3
  13. package/dist/chunks/chunk-45COPAK7.ts.map +7 -0
  14. package/dist/chunks/chunk-5SFMBY5P.ts +26 -0
  15. package/dist/chunks/chunk-5SFMBY5P.ts.map +7 -0
  16. package/dist/chunks/{chunk-ED3TYIVW.ts → chunk-5TSCBBPP.ts} +5 -5
  17. package/dist/chunks/{chunk-5QAE3G3K.ts → chunk-67INJPKR.ts} +6 -6
  18. package/dist/chunks/{chunk-IWZH5KYS.ts → chunk-6LD5KX55.ts} +10 -10
  19. package/dist/chunks/{chunk-AAEEHR7H.ts → chunk-6O3EDBRL.ts} +2 -2
  20. package/dist/chunks/{chunk-CRKTAPSL.ts → chunk-7A35ZAVO.ts} +333 -237
  21. package/dist/chunks/chunk-7A35ZAVO.ts.map +7 -0
  22. package/dist/chunks/{chunk-6FVVRTL5.ts → chunk-7OLLPPLU.ts} +77 -63
  23. package/dist/chunks/chunk-7OLLPPLU.ts.map +7 -0
  24. package/dist/chunks/{chunk-PQW6GS4J.ts → chunk-7ZIYU5QS.ts} +12 -10
  25. package/dist/chunks/{chunk-PQW6GS4J.ts.map → chunk-7ZIYU5QS.ts.map} +1 -1
  26. package/dist/chunks/{chunk-S7QS4AWK.ts → chunk-AKMV47YC.ts} +5 -5
  27. package/dist/chunks/chunk-AR2DGDUI.ts +55 -0
  28. package/dist/chunks/chunk-AR2DGDUI.ts.map +7 -0
  29. package/dist/chunks/{chunk-GNH73BJ5.ts → chunk-BEST45H2.ts} +7 -7
  30. package/dist/chunks/chunk-CBLTWXAU.ts +114 -0
  31. package/dist/chunks/chunk-CBLTWXAU.ts.map +7 -0
  32. package/dist/chunks/{chunk-GP5DU62N.ts → chunk-CPT2BN6N.ts} +2 -2
  33. package/dist/chunks/{chunk-UPNVIUBN.ts → chunk-DN4IA7MR.ts} +6 -6
  34. package/dist/chunks/{chunk-PG7NMFP2.ts → chunk-DRTC4PKM.ts} +8 -8
  35. package/dist/chunks/chunk-ESKOPQVB.ts +348 -0
  36. package/dist/chunks/chunk-ESKOPQVB.ts.map +7 -0
  37. package/dist/chunks/{chunk-MKKF4IMY.ts → chunk-F7E3VFXU.ts} +5 -5
  38. package/dist/chunks/{chunk-HUZ5CR4W.ts → chunk-FHE2DCA2.ts} +3 -52
  39. package/dist/chunks/chunk-FHE2DCA2.ts.map +7 -0
  40. package/dist/chunks/{chunk-UBV24CG4.ts → chunk-FLHCOJCD.ts} +3 -3
  41. package/dist/chunks/chunk-GNYGNHFF.ts +27 -0
  42. package/dist/chunks/chunk-GNYGNHFF.ts.map +7 -0
  43. package/dist/chunks/chunk-KYTT7KV4.ts +319 -0
  44. package/dist/chunks/chunk-KYTT7KV4.ts.map +7 -0
  45. package/dist/chunks/{chunk-A6HU4ERM.ts → chunk-MKSMJPVA.ts} +6 -23
  46. package/dist/chunks/chunk-MKSMJPVA.ts.map +7 -0
  47. package/dist/chunks/{chunk-ORGBI36T.ts → chunk-OJARL2TG.ts} +4 -4
  48. package/dist/chunks/{chunk-JCH3VXIO.ts → chunk-OKPPZA4D.ts} +150 -91
  49. package/dist/chunks/chunk-OKPPZA4D.ts.map +7 -0
  50. package/dist/chunks/{chunk-QO333NM4.ts → chunk-OVBAW7KV.ts} +180 -133
  51. package/dist/chunks/chunk-OVBAW7KV.ts.map +7 -0
  52. package/dist/chunks/{chunk-GSNPASKB.ts → chunk-Q23JJW7E.ts} +6 -6
  53. package/dist/chunks/{chunk-YK52VDXG.ts → chunk-TIMWN2RH.ts} +10 -8
  54. package/dist/chunks/{chunk-YK52VDXG.ts.map → chunk-TIMWN2RH.ts.map} +1 -1
  55. package/dist/chunks/{chunk-UOHR7LRO.ts → chunk-TZC7GDJE.ts} +10 -22
  56. package/dist/chunks/chunk-TZC7GDJE.ts.map +7 -0
  57. package/dist/chunks/chunk-X7R6DCVF.ts +28 -0
  58. package/dist/chunks/chunk-X7R6DCVF.ts.map +7 -0
  59. package/dist/chunks/{chunk-76NB4R7U.ts → chunk-XJHQPB3E.ts} +2 -2
  60. package/dist/chunks/{chunk-BDB4IDM3.ts → chunk-Y4UVXOLQ.ts} +8 -6
  61. package/dist/chunks/{chunk-BDB4IDM3.ts.map → chunk-Y4UVXOLQ.ts.map} +1 -1
  62. package/dist/chunks/{chunk-P7DD5PWZ.ts → chunk-ZDDBZH72.ts} +3 -3
  63. package/dist/chunks/command-handler-F2E7A5T5.ts +548 -0
  64. package/dist/chunks/command-handler-F2E7A5T5.ts.map +7 -0
  65. package/dist/chunks/{config-KGIYTTXQ.ts → config-HYG7G5EM.ts} +7 -6
  66. package/dist/chunks/{conflict-artifacts-FXFIIBCB.ts → conflict-artifacts-J6WSDCWP.ts} +13 -9
  67. package/dist/chunks/{conflict-review-3X37QEIT.ts → conflict-review-2QMO2K6Q.ts} +31 -25
  68. package/dist/chunks/{conflict-review-3X37QEIT.ts.map → conflict-review-2QMO2K6Q.ts.map} +1 -1
  69. package/dist/chunks/{continuous-record-SQJ47CXN.ts → continuous-record-AH7JGYKM.ts} +8 -7
  70. package/dist/chunks/{continuous-sync-Q6QUD6TY.ts → continuous-sync-VRMXCA5X.ts} +33 -28
  71. package/dist/chunks/{continuous-sync-Q6QUD6TY.ts.map → continuous-sync-VRMXCA5X.ts.map} +1 -1
  72. package/dist/chunks/{file-selection-3JJYOVNR.ts → file-selection-IELTXSGZ.ts} +11 -10
  73. package/dist/chunks/{file-selection-3JJYOVNR.ts.map → file-selection-IELTXSGZ.ts.map} +1 -1
  74. package/dist/chunks/{git-backend-NYKSG5X6.ts → git-backend-KHD36W27.ts} +15 -12
  75. package/dist/chunks/{git-backend-NYKSG5X6.ts.map → git-backend-KHD36W27.ts.map} +1 -1
  76. package/dist/chunks/{local-fields-6DGYOOIK.ts → local-fields-JEKAPZKD.ts} +9 -5
  77. package/dist/chunks/manager-result-dispatcher-6W52NM7F.ts +32 -0
  78. package/dist/chunks/{manager-ui-ZH6DEC2G.ts → manager-ui-LM7DSJ2Y.ts} +124 -67
  79. package/dist/chunks/manager-ui-LM7DSJ2Y.ts.map +7 -0
  80. package/dist/chunks/{merge-baseline-store-RFCAH7KL.ts → merge-baseline-store-65GKUMXI.ts} +6 -5
  81. package/dist/chunks/remote-selection-ui-TD4C4W3J.ts +31 -0
  82. package/dist/chunks/{s3-backend-F7PR5FB3.ts → s3-backend-L24UZ6IK.ts} +24 -18
  83. package/dist/chunks/s3-backend-L24UZ6IK.ts.map +7 -0
  84. package/dist/chunks/{setup-switch-E7PHKI6J.ts → setup-switch-PIPXYPCW.ts} +6 -7
  85. package/dist/chunks/{setup-wizard-OVHZYXNW.ts → setup-wizard-RR5U3SUB.ts} +8 -9
  86. package/dist/chunks/{setup-wizard-OVHZYXNW.ts.map → setup-wizard-RR5U3SUB.ts.map} +1 -1
  87. package/dist/chunks/{snapshot-THS5EY2L.ts → snapshot-RGNDYT6A.ts} +10 -6
  88. package/dist/chunks/snapshot-transaction-26BQO36S.ts +24 -0
  89. package/dist/chunks/sync-inspection-MOMLGUTD.ts +25 -0
  90. package/dist/chunks/sync-inspection-MOMLGUTD.ts.map +7 -0
  91. package/dist/chunks/{sync-operations-Y72GNIQ2.ts → sync-operations-CV3TULLD.ts} +66 -57
  92. package/dist/chunks/{sync-operations-Y72GNIQ2.ts.map → sync-operations-CV3TULLD.ts.map} +1 -1
  93. package/dist/chunks/{sync-state-CFL4RRRB.ts → sync-state-7L4NT7W2.ts} +8 -5
  94. package/dist/chunks/sync-state-7L4NT7W2.ts.map +7 -0
  95. package/dist/chunks/{webdav-backend-TGFUH3SF.ts → webdav-backend-3ZCACILP.ts} +15 -12
  96. package/dist/chunks/{webdav-backend-TGFUH3SF.ts.map → webdav-backend-3ZCACILP.ts.map} +1 -1
  97. package/dist/index.ts +54 -537
  98. package/dist/index.ts.map +3 -3
  99. package/package.json +2 -2
  100. package/skills/configure-pi-sync/references/configuration.md +8 -1
  101. package/src/backends/s3/s3-client.ts +8 -1
  102. package/src/commands/command-execution.ts +8 -3
  103. package/src/paths.ts +6 -1
  104. package/src/settings/config-file.ts +205 -118
  105. package/src/settings/config.ts +2 -2
  106. package/src/settings/settings-management.ts +15 -1
  107. package/src/settings/settings-store.ts +0 -14
  108. package/src/settings/settings-validation.ts +1 -1
  109. package/src/snapshot/session-paths.ts +15 -2
  110. package/src/snapshot/snapshot-mutation-queues.ts +142 -0
  111. package/src/snapshot/snapshot-transaction-directory.ts +16 -0
  112. package/src/snapshot/snapshot-transaction.ts +123 -137
  113. package/src/sync/automatic-sync.ts +12 -6
  114. package/src/sync/local-field-policy.ts +29 -0
  115. package/src/sync/local-fields.ts +3 -29
  116. package/src/sync/merge-apply.ts +6 -0
  117. package/src/sync/mutation-owner.ts +22 -0
  118. package/src/sync/startup-check.ts +3 -2
  119. package/src/sync/sync-loaders.ts +4 -0
  120. package/src/sync/sync-local.ts +2 -19
  121. package/src/sync-extension.ts +7 -2
  122. package/src/ui/cancellable-operation.ts +36 -13
  123. package/src/ui/manager-state.ts +3 -1
  124. package/src/ui/manager-ui.ts +76 -24
  125. package/src/ui/remote-selection-ui.ts +131 -82
  126. package/src/ui/settings-ui.ts +2 -1
  127. package/dist/chunks/chunk-6FVVRTL5.ts.map +0 -7
  128. package/dist/chunks/chunk-A6HU4ERM.ts.map +0 -7
  129. package/dist/chunks/chunk-B4QZBDBT.ts.map +0 -7
  130. package/dist/chunks/chunk-CRKTAPSL.ts.map +0 -7
  131. package/dist/chunks/chunk-HUZ5CR4W.ts.map +0 -7
  132. package/dist/chunks/chunk-JCH3VXIO.ts.map +0 -7
  133. package/dist/chunks/chunk-QO333NM4.ts.map +0 -7
  134. package/dist/chunks/chunk-QOFMXPM5.ts +0 -735
  135. package/dist/chunks/chunk-QOFMXPM5.ts.map +0 -7
  136. package/dist/chunks/chunk-UOHR7LRO.ts.map +0 -7
  137. package/dist/chunks/manager-result-dispatcher-HOCM2GDA.ts +0 -24
  138. package/dist/chunks/manager-ui-ZH6DEC2G.ts.map +0 -7
  139. package/dist/chunks/remote-selection-ui-YFPGYGNE.ts +0 -23
  140. package/dist/chunks/s3-backend-F7PR5FB3.ts.map +0 -7
  141. package/dist/chunks/sync-inspection-J25EEKZK.ts +0 -21
  142. /package/dist/chunks/{agent-candidate-GNEYR225.ts.map → agent-candidate-OCDPRI5G.ts.map} +0 -0
  143. /package/dist/chunks/{config-KGIYTTXQ.ts.map → agent-sync-EUK2CPSS.ts.map} +0 -0
  144. /package/dist/chunks/{chunk-U3XRI2HF.ts.map → chunk-3IYAPMST.ts.map} +0 -0
  145. /package/dist/chunks/{chunk-ED3TYIVW.ts.map → chunk-5TSCBBPP.ts.map} +0 -0
  146. /package/dist/chunks/{chunk-5QAE3G3K.ts.map → chunk-67INJPKR.ts.map} +0 -0
  147. /package/dist/chunks/{chunk-IWZH5KYS.ts.map → chunk-6LD5KX55.ts.map} +0 -0
  148. /package/dist/chunks/{chunk-AAEEHR7H.ts.map → chunk-6O3EDBRL.ts.map} +0 -0
  149. /package/dist/chunks/{chunk-S7QS4AWK.ts.map → chunk-AKMV47YC.ts.map} +0 -0
  150. /package/dist/chunks/{chunk-GNH73BJ5.ts.map → chunk-BEST45H2.ts.map} +0 -0
  151. /package/dist/chunks/{chunk-GP5DU62N.ts.map → chunk-CPT2BN6N.ts.map} +0 -0
  152. /package/dist/chunks/{chunk-UPNVIUBN.ts.map → chunk-DN4IA7MR.ts.map} +0 -0
  153. /package/dist/chunks/{chunk-PG7NMFP2.ts.map → chunk-DRTC4PKM.ts.map} +0 -0
  154. /package/dist/chunks/{chunk-MKKF4IMY.ts.map → chunk-F7E3VFXU.ts.map} +0 -0
  155. /package/dist/chunks/{chunk-UBV24CG4.ts.map → chunk-FLHCOJCD.ts.map} +0 -0
  156. /package/dist/chunks/{chunk-ORGBI36T.ts.map → chunk-OJARL2TG.ts.map} +0 -0
  157. /package/dist/chunks/{chunk-GSNPASKB.ts.map → chunk-Q23JJW7E.ts.map} +0 -0
  158. /package/dist/chunks/{chunk-76NB4R7U.ts.map → chunk-XJHQPB3E.ts.map} +0 -0
  159. /package/dist/chunks/{chunk-P7DD5PWZ.ts.map → chunk-ZDDBZH72.ts.map} +0 -0
  160. /package/dist/chunks/{conflict-artifacts-FXFIIBCB.ts.map → config-HYG7G5EM.ts.map} +0 -0
  161. /package/dist/chunks/{continuous-record-SQJ47CXN.ts.map → conflict-artifacts-J6WSDCWP.ts.map} +0 -0
  162. /package/dist/chunks/{local-fields-6DGYOOIK.ts.map → continuous-record-AH7JGYKM.ts.map} +0 -0
  163. /package/dist/chunks/{manager-result-dispatcher-HOCM2GDA.ts.map → local-fields-JEKAPZKD.ts.map} +0 -0
  164. /package/dist/chunks/{merge-baseline-store-RFCAH7KL.ts.map → manager-result-dispatcher-6W52NM7F.ts.map} +0 -0
  165. /package/dist/chunks/{remote-selection-ui-YFPGYGNE.ts.map → merge-baseline-store-65GKUMXI.ts.map} +0 -0
  166. /package/dist/chunks/{setup-switch-E7PHKI6J.ts.map → remote-selection-ui-TD4C4W3J.ts.map} +0 -0
  167. /package/dist/chunks/{snapshot-THS5EY2L.ts.map → setup-switch-PIPXYPCW.ts.map} +0 -0
  168. /package/dist/chunks/{sync-inspection-J25EEKZK.ts.map → snapshot-RGNDYT6A.ts.map} +0 -0
  169. /package/dist/chunks/{sync-state-CFL4RRRB.ts.map → snapshot-transaction-26BQO36S.ts.map} +0 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/ui/merged-sync-summary.ts", "../../src/ui/transfer-changes.ts", "../../src/sync/conflict-artifact-ownership.ts", "../../src/sync/conflict-resolution.ts", "../../src/sync/conflict-retention.ts", "../../src/sync/merge-apply.ts", "../../src/snapshot/snapshot-apply.ts", "../../src/sync/merge-transfer-error.ts", "../../src/sync/partial-progress.ts", "../../src/sync/settings-conflicts.ts", "../../src/ui/sync-format.ts", "../../src/sync/sync-decision.ts", "../../src/sync/merged-sync.ts"],
4
+ "sourcesContent": ["import { truncateToWidth } from \"@earendil-works/pi-tui\";\nimport type { PublicationCapability } from \"../backends/sync-backend.js\";\nimport type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport type { FileMergeDecision } from \"../sync/file-merge-planner.js\";\nimport { safeTerminalText, snapshotPathLabel } from \"./terminal-text.js\";\nimport { transferChanges as changes, type TransferChange as FileChange } from \"./transfer-changes.js\";\n\nexport interface MergedSyncSummaryInput {\n setupName: string;\n destination: string;\n localBefore: Snapshot;\n localAfter: Snapshot;\n remoteBefore: Snapshot;\n remoteAfter: Snapshot;\n publish: boolean;\n sessions: boolean;\n groups: readonly { paths: readonly string[] }[];\n decisions: readonly FileMergeDecision[];\n capability: PublicationCapability;\n}\n\n/** Presentation only: counts describe snapshot differences, not planner decisions. */\nexport function mergedSyncSummary(input: MergedSyncSummaryInput) {\n const local = changes(input.localBefore, input.localAfter);\n const remote = changes(input.remoteBefore, input.remoteAfter);\n const all = [...local, ...remote];\n const updatesOnly = all.length > 0 && all.every((change) => change.action === \"Update\");\n const verb = updatesOnly ? \"Update\" : \"Apply changes to\";\n const title =\n local.length && remote.length\n ? \"Apply local and remote changes?\"\n : all.length\n ? `${verb} ${all.length} ${local.length ? \"local\" : \"remote\"} ${all.length === 1 ? \"file\" : \"files\"}?`\n : input.publish\n ? \"Publish a new remote snapshot?\"\n : \"Pi Sync is already up to date.\";\n const confirmationLabel =\n local.length && remote.length\n ? \"apply local and remote changes\"\n : all.length\n ? `${updatesOnly ? \"update\" : \"apply changes to\"} ${local.length ? \"local\" : \"remote\"} ${all.length === 1 ? \"file\" : \"files\"}`\n : \"publish remote snapshot\";\n const sources = new Map(\n input.decisions.filter((item) => item.kind === \"accepted\").map((item) => [item.path, item.source]),\n );\n const label = (change: FileChange, side: \"local\" | \"remote\") => {\n const source = sources.get(change.path);\n const suffix =\n source === \"merged\"\n ? \" (merged content)\"\n : side === \"local\" && source === \"remote\"\n ? change.action === \"Delete\"\n ? \" (deleted remotely)\"\n : \" from remote\"\n : \"\";\n return `${change.action} ${snapshotPathLabel(change.path)}${suffix}`;\n };\n const section = (items: FileChange[], side: \"local\" | \"remote\", compact: boolean) => {\n const heading = side === \"local\" ? \"Local changes\" : \"Remote file changes\";\n if (!items.length) return [`${heading}: none`];\n const counts = [\"Add\", \"Update\", \"Delete\"].flatMap((action) => {\n const count = items.filter((item) => item.action === action).length;\n return count ? [`${count} ${action.toLowerCase()}`] : [];\n });\n return [\n `${heading}: ${counts.join(\", \")}`,\n ...(compact ? items.slice(0, 3) : items).map(\n (item) => ` ${compact ? truncateToWidth(label(item, side), 80) : label(item, side)}`,\n ),\n ...(compact && items.length > 3 ? [` ${items.length - 3} more files \u2014 View details`] : []),\n ];\n };\n const context = [`Setup: ${safeTerminalText(input.setupName)}`, `Remote: ${safeTerminalText(input.destination)}`];\n const safety = [\n `Remote snapshot publication: ${input.publish ? \"yes\" : \"no\"}`,\n \"Remote removals affect the active snapshot; retained history is not erased.\",\n `Sessions: ${input.sessions ? \"included \u2014 may contain private conversations\" : \"not included\"}`,\n input.groups.length\n ? `Unresolved groups: ${input.groups.length} \u2014 these paths stay unchanged on each side`\n : \"Conflicts: none\",\n ...(input.publish && input.capability === \"read-check-write-verify\"\n ? [\"Warning: simultaneous remote writes can still race; visible changes are rejected.\"]\n : []),\n ...(input.publish && input.capability === \"conditional-required\"\n ? [\"Remote publication requires verified conditional writes; verification failure stops the transfer.\"]\n : []),\n \"The current session is protected. A backup and recovery journal will be saved.\",\n \"Resources will not reload automatically.\",\n ];\n return {\n title,\n confirmationLabel,\n lines: [\n ...context.map((line) => truncateToWidth(line, 100)),\n ...section(local, \"local\", true),\n ...section(remote, \"remote\", true),\n ...safety,\n ],\n content: [\n ...context,\n \"\",\n ...section(local, \"local\", false),\n \"\",\n ...section(remote, \"remote\", false),\n \"\",\n ...safety,\n ...input.groups.flatMap((group) =>\n group.paths.map((filePath) => `Unchanged (unresolved): ${snapshotPathLabel(filePath)}`),\n ),\n ].join(\"\\n\"),\n };\n}\n", "import type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport { fileHashMap } from \"../sync/sync-state.js\";\n\nexport interface TransferChange {\n path: string;\n action: \"Add\" | \"Update\" | \"Delete\";\n}\n\n/** Compare effective before/after snapshots, not raw planner decisions. */\nexport function transferChanges(\n before: Snapshot | undefined,\n after: Snapshot,\n protectedPaths: ReadonlySet<string> = new Set(),\n): TransferChange[] {\n const beforeMap = before ? fileHashMap(before) : {};\n const afterMap = fileHashMap(after);\n return [...new Set([...Object.keys(beforeMap), ...Object.keys(afterMap)])]\n .sort()\n .flatMap((filePath): TransferChange[] => {\n if (protectedPaths.has(filePath)) return [];\n if (!Object.hasOwn(beforeMap, filePath)) return [{ path: filePath, action: \"Add\" }];\n if (!Object.hasOwn(afterMap, filePath)) return [{ path: filePath, action: \"Delete\" }];\n return beforeMap[filePath] !== afterMap[filePath] ? [{ path: filePath, action: \"Update\" }] : [];\n });\n}\n\nexport function transferCounts(changes: readonly TransferChange[]) {\n return {\n add: changes.filter((change) => change.action === \"Add\").length,\n update: changes.filter((change) => change.action === \"Update\").length,\n remove: changes.filter((change) => change.action === \"Delete\").length,\n };\n}\n", "import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport { syncDirectory } from \"../state/json-file.js\";\nimport { readStateForConfig, statePathForConfig } from \"../state/sync-state-store.js\";\nimport {\n type ConflictArtifact,\n type CreatedConflictArtifact,\n conflictArtifactFingerprint,\n conflictDirectory,\n} from \"./conflict-artifacts.js\";\nimport { readMergeJournal } from \"./merge-journal.js\";\n\n/** Attempt-owned cleanup only: unknown evidence remains the retention policy's responsibility. */\nexport async function releaseConflictArtifacts(\n config: AnySyncConfig,\n statePath: string,\n created: readonly CreatedConflictArtifact[],\n) {\n if (!created.length || statePathForConfig(config) !== statePath) return;\n try {\n const state = await readStateForConfig(config);\n if (statePathForConfig(config) !== statePath) return;\n const journal = await readMergeJournal(config);\n if (statePathForConfig(config) !== statePath) return;\n const referenced = new Set([\n ...(state.unresolved ?? []).map((group) => group.artifact),\n ...(journal?.progress?.groups ?? []).map((group) => group.artifact),\n ]);\n for (const lease of created) {\n if (referenced.has(lease.token) || lease.target !== path.join(conflictDirectory(config), `${lease.token}.json`))\n continue;\n try {\n const stat = await fs.lstat(lease.target);\n if (\n !stat.isFile() ||\n stat.nlink !== 1 ||\n stat.dev !== lease.dev ||\n stat.ino !== lease.ino ||\n stat.size !== lease.size\n )\n continue;\n const artifact = JSON.parse(await fs.readFile(lease.target, \"utf8\")) as ConflictArtifact;\n if (conflictArtifactFingerprint(artifact) !== lease.fingerprint || statePathForConfig(config) !== statePath)\n continue;\n const latest = await fs.lstat(lease.target);\n if (\n latest.dev !== lease.dev ||\n latest.ino !== lease.ino ||\n latest.nlink !== 1 ||\n statePathForConfig(config) !== statePath\n )\n continue;\n await fs.unlink(lease.target);\n await syncDirectory(path.dirname(lease.target));\n } catch {\n /* Missing, replaced or unreadable evidence is not ours to delete. */\n }\n }\n } catch {\n /* Invalid state/journal or unavailable storage cannot prove lack of references. */\n }\n}\n", "import type { RemoteHead, SyncBackend } from \"../backends/sync-backend.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport type { SyncState } from \"../state/state-types.js\";\nimport { syncStateFingerprint } from \"../state/sync-state-store.js\";\nimport { conflictArtifactFingerprint, readConflictArtifact } from \"./conflict-artifacts.js\";\nimport { type FileMergePlan, mergePathIdentity, planFileMerge } from \"./file-merge-planner.js\";\nimport { fileHashMap } from \"./sync-state.js\";\nexport interface ConflictResolution {\n token: string;\n group: number;\n source: \"local\" | \"remote\";\n stateIdentity: string;\n artifactIdentity: string;\n}\nexport async function resolveReviewedGroup(\n config: AnySyncConfig,\n backend: SyncBackend,\n state: SyncState,\n local: Snapshot,\n remote: Snapshot,\n head: RemoteHead,\n plan: FileMergePlan,\n resolution: ConflictResolution,\n protectedPaths: ReadonlySet<string>,\n): Promise<FileMergePlan> {\n const artifact = await readConflictArtifact(config, backend.identity, resolution.token);\n const group = artifact.groups[resolution.group];\n if (\n conflictArtifactFingerprint(artifact) !== resolution.artifactIdentity ||\n !group ||\n plan.kind !== \"planned\" ||\n !state.unresolved?.some(\n (item) => item.artifact === resolution.token && JSON.stringify(item.paths) === JSON.stringify(group.paths),\n ) ||\n syncStateFingerprint(state) !== resolution.stateIdentity ||\n state.lastObservedSnapshot !== head.snapshotId ||\n !state.lastObservedRevision ||\n !backend.sameRevision(state.lastObservedRevision, head.revision)\n )\n throw new Error(\"Conflict review is stale; refresh sync and review again.\");\n const ours = fileHashMap(local);\n const theirs = fileHashMap(remote);\n const oldOurs = fileHashMap(artifact.local);\n const oldTheirs = fileHashMap(artifact.remote);\n if (\n group.paths.some(\n (filePath) =>\n ours[filePath] !== oldOurs[filePath] ||\n theirs[filePath] !== oldTheirs[filePath] ||\n state.lastFileHashes[filePath] !== artifact.state.lastFileHashes[filePath],\n )\n )\n throw new Error(\"Conflict versions changed; no resolution was applied.\");\n if (\n group.paths.some((filePath) =>\n [...protectedPaths].some((value) => mergePathIdentity(value) === mergePathIdentity(filePath)),\n )\n )\n throw new Error(\n \"Current session conflict cannot be resolved from the loaded session; preserve evidence and close Pi.\",\n );\n const selected = resolution.source === \"local\" ? local : remote;\n const paths = new Set(group.paths);\n for (const snapshot of [selected, local]) {\n const layout = planFileMerge({\n baseline: {},\n local: snapshot.files.filter((file) => paths.has(file.path)),\n remote: [],\n selectionCompatible: true,\n });\n if (layout.kind !== \"planned\" || layout.conflicts.length)\n throw new Error(\n \"Selected/current local group still has path collisions; preserve evidence, repair the layout manually and refresh sync.\",\n );\n }\n const selectedFiles = new Map(selected.files.map((file) => [file.path, file]));\n const decisions = plan.decisions.map((item) =>\n paths.has(item.path)\n ? {\n kind: \"accepted\" as const,\n path: item.path,\n source: resolution.source,\n file: selectedFiles.get(item.path),\n }\n : item,\n );\n return {\n kind: \"planned\",\n decisions,\n conflicts: decisions.filter((item): item is Extract<typeof item, { kind: \"conflict\" }> => item.kind === \"conflict\"),\n };\n}\n", "import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport { syncDirectory } from \"../state/json-file.js\";\nimport type { SyncState } from \"../state/state-types.js\";\nimport { conflictDirectory, readConflictArtifact } from \"./conflict-artifacts.js\";\nimport { fileHashMap } from \"./sync-state.js\";\n/** Only after accepted state and journal retirement, under the operation lock. Unknown/unresolved evidence is never pruned. */\nexport async function pruneCompletedConflicts(\n config: AnySyncConfig,\n backend: string,\n state: SyncState,\n local: Snapshot,\n remote: Snapshot,\n validate: () => void,\n) {\n validate();\n const directory = conflictDirectory(config);\n let names: string[];\n try {\n const stat = await fs.lstat(directory);\n validate();\n if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error(\"Unsafe conflict retention directory.\");\n names = await fs.readdir(directory);\n validate();\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return;\n throw error;\n }\n const pinned = new Set(state.unresolved?.map((group) => group.artifact) ?? []);\n const ours = fileHashMap(local);\n const theirs = fileHashMap(remote);\n const completed: { token: string; modified: number }[] = [];\n for (const name of names) {\n validate();\n const token = name.replace(/\\.json$/u, \"\");\n if (!/^[a-f0-9-]{36}\\.json$/u.test(name) || pinned.has(token)) continue;\n try {\n const artifact = await readConflictArtifact(config, backend, token);\n validate();\n const originalLocal = fileHashMap(artifact.local);\n const originalRemote = fileHashMap(artifact.remote);\n if (\n !artifact.groups.every((group) =>\n group.paths.every(\n (filePath) =>\n state.lastFileHashes[filePath] === ours[filePath] &&\n ours[filePath] === theirs[filePath] &&\n (ours[filePath] === originalLocal[filePath] || ours[filePath] === originalRemote[filePath]),\n ),\n )\n )\n continue;\n const stat = await fs.lstat(path.join(directory, name));\n validate();\n if (stat.isFile()) completed.push({ token, modified: stat.mtimeMs });\n } catch {\n validate(); /* Corrupt/unknown evidence remains. */\n }\n }\n completed.sort((left, right) => right.modified - left.modified || left.token.localeCompare(right.token));\n for (const entry of completed.slice(32)) {\n validate();\n await fs.rm(path.join(directory, `${entry.token}.json`));\n validate();\n }\n if (completed.length > 32) {\n await syncDirectory(directory);\n validate();\n }\n}\n", "import { createHash, randomUUID } from \"node:crypto\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { withFileMutationQueue } from \"@earendil-works/pi-coding-agent\";\nimport { agentDir } from \"../snapshot/session-paths.js\";\nimport { createSnapshot, snapshotTarget } from \"../snapshot/snapshot.js\";\nimport { preflightSnapshotApply, preflightSnapshotMutations } from \"../snapshot/snapshot-apply.js\";\nimport { assertCanonicalMutationTargets } from \"../snapshot/snapshot-mutation-queues.js\";\nimport { sessionStorageRoot } from \"../snapshot/snapshot-paths.js\";\nimport type { Snapshot, SnapshotOptions } from \"../snapshot/snapshot-types.js\";\nimport { syncDirectory } from \"../state/json-file.js\";\nimport { syncMutationParents } from \"../state/mutation-directory-sync.js\";\nimport { mergePathIdentity } from \"./file-merge-planner.js\";\nimport { fileHashMap } from \"./sync-state.js\";\n\n/** Read-only filesystem applicability check before publishing a combined result. */\nexport async function preflightMergedTargets(\n before: Snapshot,\n after: Snapshot,\n options: SnapshotOptions,\n protectedTarget?: string,\n) {\n const root = agentDir();\n const beforeHashes: Record<string, string> = Object.assign(Object.create(null), fileHashMap(before));\n const afterHashes: Record<string, string> = Object.assign(Object.create(null), fileHashMap(after));\n const paths = [...new Set([...Object.keys(beforeHashes), ...Object.keys(afterHashes)])].sort();\n const changed = new Set(paths.filter((item) => beforeHashes[item] !== afterHashes[item]));\n await assertCanonicalMergedTargets(root, changed, options);\n await assertDistinctMergedTargets(root, paths, changed, options, protectedTarget, new Set(Object.keys(afterHashes)));\n const removed = replacementPaths(\n new Set(paths.filter((item) => changed.has(item) && !afterHashes[item])),\n afterHashes,\n );\n const removedTargets = new Set([...removed].map((item) => snapshotTarget(root, item, options.sessionDir)));\n for (const relative of paths) {\n if (changed.has(relative)) await assertFilesystemTarget(root, relative, options, removedTargets, beforeHashes);\n }\n await assertCanonicalMutationTargets(\n [...changed].map((relative) => snapshotTarget(root, relative, options.sessionDir)),\n options,\n );\n}\n\nfunction replacementPaths(removed: Set<string>, afterHashes: Readonly<Record<string, string>>) {\n for (const relative of [...removed]) {\n let parent = path.posix.dirname(relative);\n while (parent !== \".\") {\n if (afterHashes[parent]) {\n for (\n let directory = path.posix.dirname(relative);\n directory !== parent;\n directory = path.posix.dirname(directory)\n )\n removed.add(directory);\n removed.add(parent);\n break;\n }\n parent = path.posix.dirname(parent);\n }\n }\n return removed;\n}\n\n/** Snapshot collection canonicalizes top-level names, but merged journals own exact physical paths. */\nasync function assertCanonicalMergedTargets(root: string, changed: Iterable<string>, options: SnapshotOptions) {\n const topLevel = new Map(\n [...changed].filter((relative) => !relative.includes(\"/\")).map((relative) => [relative.toLowerCase(), relative]),\n );\n if (topLevel.size === 0) return;\n options.signal?.throwIfAborted();\n options.validateMutation?.();\n let names: string[];\n try {\n names = await fs.readdir(root);\n } catch (error) {\n options.signal?.throwIfAborted();\n options.validateMutation?.();\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n return;\n }\n options.signal?.throwIfAborted();\n options.validateMutation?.();\n for (const name of names) {\n const canonical = topLevel.get(name.toLowerCase());\n if (canonical !== undefined && name !== canonical)\n throw new Error(\n \"Merged target has a noncanonical case variant; normalize selected top-level file spelling before retrying. Journal retained if already committed.\",\n );\n }\n}\n\n/** Even an unchanged virtual alias must not describe different bytes for a changed physical file. */\nasync function assertDistinctMergedTargets(\n root: string,\n paths: string[],\n changed: ReadonlySet<string>,\n options: SnapshotOptions,\n protectedTarget?: string,\n finalPaths: ReadonlySet<string> = new Set(paths),\n) {\n const protectedKey = protectedTarget\n ? mergePathIdentity(await resolvedTargetIdentity(path.resolve(protectedTarget), options))\n : undefined;\n options.signal?.throwIfAborted();\n options.validateMutation?.();\n const keys = new Map<string, string>();\n for (const relative of paths) {\n options.signal?.throwIfAborted();\n const target = snapshotTarget(root, relative, options.sessionDir);\n const key = mergePathIdentity(await resolvedTargetIdentity(target, options));\n options.signal?.throwIfAborted();\n options.validateMutation?.();\n const existing = keys.get(key);\n if (\n existing &&\n (mergePathIdentity(existing) !== mergePathIdentity(relative) ||\n (finalPaths.has(existing) && finalPaths.has(relative)))\n )\n throw new Error(\"Merged paths resolve to the same file; reviewed directional recovery is required.\");\n if (key === protectedKey && changed.has(relative))\n throw new Error(\"A merged transfer targets the current session; review is required.\");\n keys.set(key, relative);\n }\n}\n\nasync function assertReviewedTree(directory: string, relative: string, beforeHashes: Readonly<Record<string, string>>) {\n for (const name of await fs.readdir(directory)) {\n const child = path.join(directory, name);\n const childRelative = `${relative}/${name}`;\n const stat = await fs.lstat(child);\n if (stat.isDirectory()) {\n await assertReviewedTree(child, childRelative, beforeHashes);\n } else if (\n stat.isFile() &&\n stat.nlink === 1 &&\n beforeHashes[childRelative] ===\n createHash(\"sha256\")\n .update(await fs.readFile(child))\n .digest(\"hex\")\n ) {\n continue;\n } else {\n throw new Error(\"Reviewed directory contains unknown or changed files; publication refused.\");\n }\n }\n}\n\nfunction hasBlockingFileAncestor(target: string, files: ReadonlySet<string>) {\n for (let parent = path.dirname(target); parent !== path.dirname(parent); parent = path.dirname(parent))\n if (files.has(parent)) return true;\n return false;\n}\n\nasync function resolvedTargetIdentity(target: string, options: SnapshotOptions) {\n // Resolve the nearest existing ancestor too: roots may alias even when a target is absent.\n let ancestor = target;\n while (true) {\n options.signal?.throwIfAborted();\n try {\n const resolved = await fs.realpath(ancestor);\n return path.resolve(resolved, path.relative(ancestor, target));\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code !== \"ENOENT\" && code !== \"ENOTDIR\") throw error;\n const parent = path.dirname(ancestor);\n if (parent === ancestor) return target;\n ancestor = parent;\n }\n }\n}\n\nasync function assertFilesystemTarget(\n root: string,\n relative: string,\n options: SnapshotOptions,\n removedTargets: ReadonlySet<string> = new Set(),\n beforeHashes?: Readonly<Record<string, string>>,\n) {\n const target = snapshotTarget(root, relative, options.sessionDir);\n const boundary =\n relative.startsWith(\"sessions/\") && options.sessionDir\n ? path.resolve(sessionStorageRoot(root, options.sessionDir))\n : path.resolve(root);\n for (\n let parent = path.dirname(target);\n mergePathIdentity(parent) !== mergePathIdentity(boundary);\n parent = path.dirname(parent)\n ) {\n options.signal?.throwIfAborted();\n if (path.dirname(parent) === parent) throw new Error(\"Unowned merged target.\");\n try {\n const stat = await fs.lstat(parent);\n if (\n (!stat.isDirectory() || stat.isSymbolicLink()) &&\n !(stat.isFile() && stat.nlink === 1 && removedTargets.has(parent))\n )\n throw new Error(\"Unsafe merge filesystem layout; review the selected paths before transfer.\");\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code !== \"ENOENT\") throw error;\n }\n }\n options.signal?.throwIfAborted();\n try {\n const stat = await fs.lstat(target);\n if ((!stat.isFile() && !removedTargets.has(target)) || (stat.isFile() && stat.nlink > 1))\n throw new Error(\"Merge target is non-regular or hard-linked; review a directional operation before transfer.\");\n if (stat.isDirectory() && beforeHashes) await assertReviewedTree(target, relative, beforeHashes);\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code !== \"ENOENT\" && !(code === \"ENOTDIR\" && removedTargets.size > 0)) throw error;\n }\n}\n\n/** Roll forward only while each target is still its reviewed preimage or committed postimage. */\nexport async function applyMergedSnapshot(\n before: Snapshot,\n after: Snapshot,\n protectedPaths: Set<string>,\n options: SnapshotOptions,\n validate: () => Promise<void>,\n protectedTarget?: string,\n) {\n const root = agentDir();\n const beforeHashes: Record<string, string> = Object.assign(Object.create(null), fileHashMap(before));\n const afterHashes: Record<string, string> = Object.assign(Object.create(null), fileHashMap(after));\n const paths = [...new Set([...Object.keys(beforeHashes), ...Object.keys(afterHashes)])].sort();\n const replacements = replacementPaths(\n new Set(paths.filter((item) => beforeHashes[item] && !afterHashes[item])),\n afterHashes,\n );\n const intermediateDirectories = [...replacements].filter((item) => !beforeHashes[item] && !afterHashes[item]);\n const changed = [\n ...new Set([...paths.filter((item) => beforeHashes[item] !== afterHashes[item]), ...intermediateDirectories]),\n ].sort();\n const protectedKeys = new Set([...protectedPaths].map(mergePathIdentity));\n if (changed.some((item) => protectedKeys.has(mergePathIdentity(item)))) {\n throw new Error(\"A merged transfer targets the current session; review is required.\");\n }\n // Exact file queues, not a directory pseudo-lock: Pi edit/write tools use these keys.\n const targets = changed.map((item) => snapshotTarget(root, item, options.sessionDir));\n const relativeByTarget = new Map(targets.map((target, index) => [target, changed[index]]));\n const targetSet = new Set(targets);\n await assertDistinctMergedTargets(\n root,\n paths,\n new Set(changed),\n options,\n protectedTarget,\n new Set(Object.keys(afterHashes)),\n );\n await assertCanonicalMutationTargets(targets, options);\n // Existing case aliases share Pi's non-reentrant realpath queue. Reserve the\n // missing destination separately only after deleting its reviewed preimage.\n const targetsByQueue = new Map<string, string[]>();\n const queueTargets: string[] = [];\n const deferredTargets: string[] = [];\n for (const target of targets) {\n let key = path.resolve(target);\n try {\n key = await fs.realpath(target);\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code !== \"ENOENT\" && code !== \"ENOTDIR\") throw error;\n }\n options.signal?.throwIfAborted();\n options.validateMutation?.();\n const aliases = targetsByQueue.get(key) ?? [];\n aliases.push(target);\n targetsByQueue.set(key, aliases);\n }\n for (const [key, aliases] of targetsByQueue) {\n queueTargets.push(key);\n if (aliases.length > 1) deferredTargets.push(...aliases.filter((target) => path.resolve(target) !== key));\n }\n async function acquire(index: number): Promise<void> {\n const target = queueTargets[index];\n if (target) return withFileMutationQueue(target, () => acquire(index + 1));\n await validate();\n await assertCanonicalMergedTargets(root, changed, options);\n await validate();\n const current = await createSnapshot(before.profile, options);\n const currentHashes: Record<string, string> = Object.assign(Object.create(null), fileHashMap(current));\n const blockingFiles = new Set(\n paths\n .filter(\n (relative) =>\n (beforeHashes[relative] && !afterHashes[relative]) ||\n (afterHashes[relative] && currentHashes[relative] === afterHashes[relative]),\n )\n .map((relative) => snapshotTarget(root, relative, options.sessionDir)),\n );\n for (const item of changed) {\n if (currentHashes[item] !== beforeHashes[item] && currentHashes[item] !== afterHashes[item]) {\n throw new Error(\n \"Local content changed during merged transfer; journal retained for review. No newer bytes were replaced.\",\n );\n }\n const target = snapshotTarget(root, item, options.sessionDir);\n try {\n const stat = await fs.lstat(target);\n if ((!stat.isFile() && !stat.isDirectory()) || (stat.isFile() && stat.nlink > 1))\n throw new Error(\"Merged transfer target is no longer an independent regular file.\");\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code !== \"ENOENT\" && !(code === \"ENOTDIR\" && hasBlockingFileAncestor(target, blockingFiles))) throw error;\n }\n }\n const plan = preflightSnapshotApply(root, after, current, options);\n plan.writes = plan.writes.filter((item) => targetSet.has(item.target));\n plan.deletes = plan.deletes.filter((target) => targetSet.has(target));\n await preflightSnapshotMutations(root, plan, options.sessionDir, options);\n const deletedTargets = new Set(plan.deletes);\n for (const relative of intermediateDirectories) {\n for (let parent = path.posix.dirname(relative); parent !== \".\"; parent = path.posix.dirname(parent)) {\n if (afterHashes[parent] && deletedTargets.has(snapshotTarget(root, parent, options.sessionDir))) {\n plan.deletes.push(snapshotTarget(root, relative, options.sessionDir));\n break;\n }\n }\n }\n // A parent must remain until every reviewed leaf and intermediate directory is gone.\n plan.deletes.sort(\n (left, right) => right.split(path.sep).length - left.split(path.sep).length || left.localeCompare(right),\n );\n const removed = replacementPaths(\n new Set(paths.filter((relative) => deletedTargets.has(snapshotTarget(root, relative, options.sessionDir)))),\n afterHashes,\n );\n const removedTargets = new Set([...removed].map((item) => snapshotTarget(root, item, options.sessionDir)));\n await assertCanonicalMergedTargets(root, changed, options);\n await validate();\n const revalidateTarget = async (target: string) => {\n await validate();\n const relative = relativeByTarget.get(target);\n if (!relative) throw new Error(\"Unowned merge target.\");\n await assertFilesystemTarget(root, relative, options, removedTargets, currentHashes);\n await validate();\n let hash: string | undefined;\n try {\n const stat = await fs.lstat(target);\n if (stat.isDirectory() && removed.has(relative)) {\n if ((await fs.readdir(target)).length)\n throw new Error(\"Reviewed directory has remaining contents; journal retained for review.\");\n } else {\n if (!stat.isFile() || stat.nlink > 1)\n throw new Error(\"Merged transfer target is no longer an independent regular file.\");\n hash = createHash(\"sha256\")\n .update(await fs.readFile(target))\n .digest(\"hex\");\n }\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n }\n options.signal?.throwIfAborted();\n options.validateMutation?.();\n if (hash !== beforeHashes[relative] && hash !== afterHashes[relative])\n throw new Error(\"Local content changed at the apply boundary; journal retained, newer bytes untouched.\");\n };\n for (const target of plan.deletes) {\n await revalidateTarget(target);\n try {\n const stat = await fs.lstat(target);\n await validate();\n if (stat.isDirectory())\n await fs.rmdir(target); // Only an empty, reviewed directory may be replaced.\n else await fs.rm(target, { force: true });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n }\n await syncDirectory(path.dirname(target));\n }\n const requireAbsentDestinations = async () => {\n await validate();\n for (const target of deferredTargets) {\n try {\n await fs.lstat(target);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n continue;\n }\n throw new Error(\"Case replacement destination changed before queue reservation; journal retained for review.\");\n }\n await validate();\n };\n async function acquireDestinations(index: number): Promise<void> {\n const target = deferredTargets[index];\n if (target) return withFileMutationQueue(target, () => acquireDestinations(index + 1));\n // Writers registered after deletion must finish first; never accept their\n // bytes as our own, even if they match a recognizable pre/postimage.\n await requireAbsentDestinations();\n await writeTargets();\n }\n await requireAbsentDestinations();\n await acquireDestinations(0);\n async function writeTargets() {\n for (const item of plan.writes) {\n await validate();\n const relative = relativeByTarget.get(item.target);\n if (!relative) throw new Error(\"Unowned merge write target.\");\n await assertFilesystemTarget(root, relative, options, new Set());\n await fs.mkdir(path.dirname(item.target), { recursive: true });\n const temporary = path.join(path.dirname(item.target), `.pi-sync.json.${randomUUID()}.apply`);\n let mode = 0o600;\n try {\n mode = (await fs.stat(item.target)).mode & 0o777;\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n }\n try {\n const handle = await fs.open(temporary, \"wx\", mode);\n try {\n await handle.writeFile(item.content);\n await handle.sync();\n } finally {\n await handle.close();\n }\n await revalidateTarget(item.target);\n await fs.rename(temporary, item.target);\n await syncDirectory(path.dirname(item.target));\n } finally {\n await fs.rm(temporary, { force: true });\n }\n }\n await syncMutationParents(\n targets,\n [root, ...(options.sessionDir ? [sessionStorageRoot(root, options.sessionDir)] : [])],\n options,\n );\n await validate();\n }\n }\n await acquire(0);\n}\n", "import { createHash } from \"node:crypto\";\nimport type { Dirent, Stats } from \"node:fs\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { assertWithinRoot, isDeniedPath, isPathInside, parentPaths, safeJoin, toPosix } from \"../paths.js\";\nimport { syncDirectory } from \"../state/json-file.js\";\nimport { agentDir } from \"./session-paths.js\";\nimport {\n createSnapshot,\n isSessionFilePath,\n isSessionPath,\n sessionStorageRoot,\n snapshotIncludesSessions,\n snapshotTarget,\n} from \"./snapshot.js\";\nimport { applySnapshotTransaction, recoverPendingSnapshotTransactions } from \"./snapshot-transaction.js\";\nimport type { Snapshot, SnapshotApplyPlan, SnapshotOptions } from \"./snapshot-types.js\";\n\nfunction sha256(value: Buffer) {\n return createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\nfunction fileHashMap(snapshot: Snapshot) {\n return Object.fromEntries(snapshot.files.map((file) => [file.path, file.sha256]));\n}\n\nexport async function applySnapshot(\n snapshot: Snapshot,\n protectedRelativePaths = new Set<string>(),\n options: Pick<\n SnapshotOptions,\n | \"include\"\n | \"sessionDir\"\n | \"syncFiles\"\n | \"syncSessions\"\n | \"extraFiles\"\n | \"signal\"\n | \"validateMutation\"\n | \"expectedFileHashes\"\n > = {},\n) {\n const root = agentDir();\n const { sessionDir } = options;\n const transactionOptions = {\n sessionDir,\n signal: options.signal,\n validateMutation: options.validateMutation,\n protectedTargets: [...protectedRelativePaths].map((relative) => snapshotTarget(root, relative, sessionDir)),\n expectedPreimages: new Map(\n Object.entries(options.expectedFileHashes ?? {}).map(([relative, hash]) => [\n snapshotTarget(root, relative, sessionDir),\n hash === null ? \"missing\" : `file:${hash}`,\n ]),\n ),\n };\n options.validateMutation?.();\n await recoverPendingSnapshotTransactions(transactionOptions);\n const current = await createSnapshot(snapshot.profile, {\n ...options,\n ...(options.include === undefined ? { syncSessions: snapshotIncludesSessions(snapshot) } : {}),\n sessionDir,\n });\n const plan = await addTopLevelCaseVariantDeletes(\n root,\n protectSnapshotApplyPlan(\n root,\n preflightSnapshotApply(root, snapshot, current, { sessionDir }),\n protectedRelativePaths,\n sessionDir,\n ),\n snapshot,\n );\n await preflightSnapshotMutations(root, plan, sessionDir, options);\n await applySnapshotTransaction(plan, transactionOptions);\n return appliedFileHashMap(snapshot, current, protectedRelativePaths);\n}\n\nexport function preflightSnapshotApply(\n root: string,\n snapshot: Snapshot,\n current: Snapshot,\n options: { sessionDir?: string } = {},\n): SnapshotApplyPlan {\n const seenPaths = new Set<string>();\n const remotePaths = new Set<string>();\n const writes: Array<{ target: string; content: Buffer }> = [];\n const deletes: string[] = [];\n\n for (const file of snapshot.files) {\n const normalized = toPosix(file.path);\n if (!isSafeSnapshotPath(file.path)) {\n throw new Error(`Unsafe path in snapshot: ${file.path}`);\n }\n if (isSessionPath(normalized) && !isSessionFilePath(normalized)) {\n throw new Error(`Unsafe session path in snapshot: ${file.path}`);\n }\n if (seenPaths.has(normalized)) throw new Error(`Duplicate path in snapshot: ${normalized}`);\n seenPaths.add(normalized);\n remotePaths.add(normalized);\n\n const target = snapshotTarget(root, normalized, options.sessionDir);\n const content = decodeBase64Strict(file.contentBase64, normalized);\n if (sha256(content) !== file.sha256) throw new Error(`Checksum mismatch in snapshot file: ${normalized}`);\n writes.push({ target, content });\n }\n\n const deletePaths = new Set<string>();\n for (const file of current.files) {\n const normalized = toPosix(file.path);\n if (!remotePaths.has(normalized)) {\n deletePaths.add(snapshotTarget(root, normalized, options.sessionDir));\n }\n for (const remotePath of parentPaths(normalized)) {\n if (remotePaths.has(remotePath)) {\n deletePaths.add(snapshotTarget(root, remotePath, options.sessionDir));\n }\n }\n }\n deletes.push(...deletePaths);\n\n return { writes, deletes };\n}\n\nexport function protectSnapshotApplyPlan(\n root: string,\n plan: SnapshotApplyPlan,\n protectedRelativePaths: Set<string>,\n sessionDir?: string,\n): SnapshotApplyPlan {\n if (protectedRelativePaths.size === 0) return plan;\n const protectedTargets = new Set(\n [...protectedRelativePaths].map((relativePath) => snapshotTarget(root, relativePath, sessionDir)),\n );\n return {\n writes: plan.writes.filter((item) => !protectedTargets.has(item.target)),\n deletes: plan.deletes.filter((target) => !protectedTargets.has(target)),\n };\n}\n\nexport async function addTopLevelCaseVariantDeletes(\n root: string,\n plan: SnapshotApplyPlan,\n snapshot: Pick<Snapshot, \"files\">,\n): Promise<SnapshotApplyPlan> {\n const topLevelPaths = new Map<string, string>();\n for (const file of snapshot.files) {\n const normalized = toPosix(file.path);\n if (!normalized.includes(\"/\") && isSafeSnapshotPath(file.path)) {\n topLevelPaths.set(normalized.toLowerCase(), normalized);\n }\n }\n if (topLevelPaths.size === 0) return plan;\n\n let entries: Dirent[];\n try {\n entries = await fs.readdir(root, { withFileTypes: true });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return plan;\n throw error;\n }\n\n const deletes = new Set(plan.deletes);\n for (const entry of entries) {\n const canonicalPath = topLevelPaths.get(entry.name.toLowerCase());\n if (canonicalPath && entry.name !== canonicalPath && (entry.isFile() || entry.isSymbolicLink())) {\n deletes.add(safeJoin(root, entry.name));\n }\n }\n return { ...plan, deletes: [...deletes] };\n}\n\nexport function appliedFileHashMap(snapshot: Snapshot, current: Snapshot, protectedRelativePaths: Set<string>) {\n const hashes = fileHashMap(snapshot);\n if (protectedRelativePaths.size === 0) return hashes;\n const currentHashes = fileHashMap(current);\n for (const relativePath of protectedRelativePaths) {\n const normalized = toPosix(relativePath);\n if (currentHashes[normalized]) {\n hashes[normalized] = currentHashes[normalized];\n } else {\n delete hashes[normalized];\n }\n }\n return hashes;\n}\n\nfunction isSafeSnapshotPath(relativePath: string) {\n if (relativePath.includes(\"\\\\\")) return false;\n const normalized = toPosix(relativePath);\n return (\n Boolean(normalized) &&\n normalized !== \".\" &&\n normalized !== \"..\" &&\n !normalized.startsWith(\"../\") &&\n !path.posix.isAbsolute(normalized) &&\n path.posix.normalize(normalized) === normalized &&\n !isDeniedPath(normalized)\n );\n}\n\nfunction decodeBase64Strict(value: string, filePath: string) {\n if (!/^[A-Za-z0-9+/]*={0,2}$/.test(value) || value.length % 4 !== 0) {\n throw new Error(`Invalid base64 content in snapshot file: ${filePath}`);\n }\n return Buffer.from(value, \"base64\");\n}\n\ntype MutationGuards = Pick<SnapshotOptions, \"signal\" | \"validateMutation\">;\n\nexport async function preflightSnapshotMutations(\n root: string,\n plan: { deletes: string[]; writes: Array<{ target: string; content: Buffer }> },\n sessionDir?: string,\n options: MutationGuards = {},\n) {\n assertMutationCurrent(options);\n const deletePaths = new Set(plan.deletes);\n for (const target of plan.deletes) {\n await assertNoSymlinkParents(rootForTarget(root, target, sessionDir), target, options);\n assertMutationCurrent(options);\n }\n for (const item of plan.writes) {\n await prepareSnapshotWrite(rootForTarget(root, item.target, sessionDir), item.target, deletePaths, options);\n assertMutationCurrent(options);\n }\n}\n\nfunction assertMutationCurrent(options: MutationGuards) {\n options.validateMutation?.();\n options.signal?.throwIfAborted();\n}\n\nasync function guardedStat(target: string, options: MutationGuards) {\n assertMutationCurrent(options);\n let stat: Stats;\n try {\n stat = await fs.lstat(target);\n } catch (error) {\n assertMutationCurrent(options);\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n throw error;\n }\n assertMutationCurrent(options);\n return stat;\n}\n\nfunction rootForTarget(root: string, target: string, sessionDir?: string) {\n const sessionRoot = sessionDir ? sessionStorageRoot(root, sessionDir) : undefined;\n if (sessionRoot && isPathInside(sessionRoot, target)) return sessionRoot;\n return root;\n}\n\nasync function prepareSnapshotWrite(root: string, target: string, deletePaths: Set<string>, options: MutationGuards) {\n const parentWillBeReplaced = await ensureSafeDirectory(root, path.dirname(target), deletePaths, options);\n assertMutationCurrent(options);\n if (parentWillBeReplaced) return;\n const stat = await guardedStat(target, options);\n assertMutationCurrent(options);\n if (stat?.isSymbolicLink()) throw new Error(`Refusing to overwrite symlink during snapshot apply: ${target}`);\n if (stat?.isDirectory() && !deletePaths.has(target)) {\n throw new Error(`Refusing to overwrite directory during snapshot apply: ${target}`);\n }\n}\n\nasync function ensureSafeDirectory(root: string, directory: string, deletePaths: Set<string>, options: MutationGuards) {\n assertMutationCurrent(options);\n assertWithinRoot(root, directory);\n const rootPath = path.resolve(root);\n const relative = path.relative(rootPath, path.resolve(directory));\n let current = rootPath;\n for (const part of relative.split(path.sep).filter(Boolean)) {\n current = path.join(current, part);\n const stat = await guardedStat(current, options);\n assertMutationCurrent(options);\n if (stat) {\n if (stat.isSymbolicLink()) throw new Error(`Refusing to follow symlink during snapshot apply: ${current}`);\n if (!stat.isDirectory()) {\n if (deletePaths.has(current)) return true;\n throw new Error(`Snapshot path parent is not a directory: ${current}`);\n }\n } else {\n await fs.mkdir(current);\n assertMutationCurrent(options);\n await syncDirectory(path.dirname(current));\n assertMutationCurrent(options);\n }\n }\n return false;\n}\n\nasync function assertNoSymlinkParents(root: string, target: string, options: MutationGuards) {\n assertMutationCurrent(options);\n assertWithinRoot(root, target);\n const rootPath = path.resolve(root);\n const relative = path.relative(rootPath, path.resolve(target));\n let current = rootPath;\n const parts = relative.split(path.sep).filter(Boolean);\n for (const part of parts.slice(0, -1)) {\n current = path.join(current, part);\n const stat = await guardedStat(current, options);\n assertMutationCurrent(options);\n if (!stat) return;\n if (stat.isSymbolicLink()) throw new Error(`Refusing to follow symlink during snapshot apply: ${current}`);\n if (!stat.isDirectory()) throw new Error(`Snapshot path parent is not a directory: ${current}`);\n }\n}\n", "import type { ResolvedSyncBackend } from \"../backends/backend-types.js\";\nimport { safeTerminalText } from \"../ui/terminal-text.js\";\n\nconst MAX_CAUSES = 4;\nconst MAX_DETAIL_LENGTH = 600;\n\n/** Only the sanitized message is displayed; retain the original cause for outcome handling. */\nexport function mergeTransferError(error: unknown, backend: ResolvedSyncBackend): Error {\n const messages: string[] = [];\n const seen = new Set<Error>();\n let current = error;\n while (current instanceof Error && !seen.has(current) && seen.size < MAX_CAUSES) {\n seen.add(current);\n const code = (current as NodeJS.ErrnoException).code;\n const status = (current as Error & { status?: unknown }).status;\n const metadata = [\n typeof code === \"string\" && /^[A-Z][A-Z0-9_]{1,63}$/u.test(code) ? code : undefined,\n typeof status === \"number\" && Number.isInteger(status) && status >= 100 && status <= 599\n ? `HTTP ${status}`\n : undefined,\n ].filter(Boolean);\n const message = `${current.message}${metadata.length ? ` (${metadata.join(\", \")})` : \"\"}`;\n if (message && !messages.includes(message)) messages.push(message);\n current = current.cause;\n }\n let detail = messages.join(\" \u2192 \") || \"No error details available.\";\n // Redact before truncation or terminal escaping, including overlapping and encoded credentials.\n for (const secret of credentialVariants(backend)) detail = detail.replaceAll(secret, \"[REDACTED]\");\n detail = detail.replace(/\\b(Bearer|Basic)\\s+[^\\s<>\"']+/giu, \"$1 [REDACTED]\");\n detail = safeTerminalText(detail);\n if (detail.length > MAX_DETAIL_LENGTH) detail = `${detail.slice(0, MAX_DETAIL_LENGTH)}\u2026 (details truncated)`;\n return new Error(\n `Merged transfer interrupted; journal and backup retained. Run /sync sync to reconcile before further mutations. Transfer failure: ${detail}`,\n { cause: error },\n );\n}\n\nfunction credentialVariants(backend: ResolvedSyncBackend): string[] {\n const secrets: string[] = [];\n let address: string;\n switch (backend.type) {\n case \"s3\":\n secrets.push(backend.profile.accessKeyId, backend.profile.secretAccessKey, backend.profile.sessionToken ?? \"\");\n address = backend.profile.endpoint;\n break;\n case \"webdav\":\n secrets.push(\n backend.profile.username,\n backend.profile.password,\n Buffer.from(`${backend.profile.username}:${backend.profile.password}`).toString(\"base64\"),\n );\n address = backend.profile.url;\n break;\n case \"git\":\n address = backend.profile.remote;\n break;\n }\n try {\n const url = new URL(address);\n secrets.push(url.username, url.password, ...url.searchParams.values());\n for (const value of [url.username, url.password]) secrets.push(decodeURIComponent(value));\n } catch {\n // Git SSH shorthand is not a URL; configured Git remotes cannot contain credentials.\n }\n return [\n ...new Set(\n secrets\n .filter(Boolean)\n .flatMap((value) => [value, encodeURIComponent(value), JSON.stringify(value).slice(1, -1)]),\n ),\n ].sort((left, right) => right.length - left.length);\n}\n", "import type { RemoteHead } from \"../backends/sync-backend.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport type { Snapshot, SnapshotFile } from \"../snapshot/snapshot-types.js\";\nimport type { SyncState } from \"../state/state-types.js\";\nimport type { FileMergeDecision } from \"./file-merge-planner.js\";\nimport { fileHashMap } from \"./sync-state.js\";\n/** Withholding preserves the complete local version, including explicit absence. */\nexport function acceptedMergeFiles(\n decisions: readonly FileMergeDecision[],\n localFiles: readonly SnapshotFile[],\n withheld: ReadonlySet<string>,\n) {\n const localByPath = new Map(localFiles.map((file) => [file.path, file]));\n return decisions.flatMap((decision) => {\n const file = withheld.has(decision.path)\n ? localByPath.get(decision.path)\n : decision.kind === \"accepted\"\n ? decision.file\n : undefined;\n return file ? [file] : [];\n });\n}\n\nexport interface PartialProgress {\n previous: SyncState;\n groups: { paths: string[]; artifact: string }[];\n}\nexport function progressState(\n config: AnySyncConfig,\n head: RemoteHead,\n snapshot: Snapshot,\n progress: PartialProgress,\n): SyncState {\n const withheld = new Set(progress.groups.flatMap((group) => group.paths));\n const current = fileHashMap(snapshot);\n const hashes = Object.assign(Object.create(null) as Record<string, string>, progress.previous.lastFileHashes);\n for (const key of new Set([...Object.keys(hashes), ...Object.keys(current)])) {\n if (withheld.has(key)) continue;\n const value = current[key];\n if (value === undefined) delete hashes[key];\n else hashes[key] = value;\n }\n return {\n ...progress.previous,\n version: 3,\n profile: config.snapshotIdentity,\n lastFileHashes: hashes,\n include: [...config.include],\n localFields: config.localFields,\n lastObservedSnapshot: head.snapshotId,\n lastObservedRevision: head.revision,\n unresolved: progress.groups,\n };\n}\n", "import { createHash } from \"node:crypto\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport { readMergeAncestor } from \"../state/merge-baseline-store.js\";\nimport type { SyncState } from \"../state/state-types.js\";\nimport type { FileMergePlan } from \"./file-merge-planner.js\";\nimport { mergeAcceptedSettingsPackages, mergeSettingsJson } from \"./settings-merge.js\";\n\nexport async function resolveSettingsConflicts(\n config: AnySyncConfig,\n state: SyncState,\n local: Snapshot,\n remote: Snapshot,\n plan: FileMergePlan,\n): Promise<{ plan: FileMergePlan; fields: string[] }> {\n if (plan.kind !== \"planned\") return { plan, fields: [] };\n const fields: string[] = [];\n const decisions = [...plan.decisions];\n for (let index = 0; index < decisions.length; index++) {\n const decision = decisions[index];\n if (decision?.path !== \"settings.json\") continue;\n if (decision.kind === \"conflict\" ? decision.reason !== \"both-changed\" : !config.agentMode) continue;\n const left = local.files.find((file) => file.path === decision.path);\n const right = remote.files.find((file) => file.path === decision.path);\n if (!left || !right) continue; // File deletion/addition is not a JSON field merge.\n const ancestor = await readMergeAncestor(config, state, decision.path);\n if (!ancestor) continue;\n const leftBytes = Buffer.from(left.contentBase64, \"base64\");\n const rightBytes = Buffer.from(right.contentBase64, \"base64\");\n let content: Buffer;\n if (decision.kind === \"accepted\") {\n if (!decision.file) continue;\n const patched = mergeAcceptedSettingsPackages(\n ancestor,\n leftBytes,\n rightBytes,\n Buffer.from(decision.file.contentBase64, \"base64\"),\n );\n if (!patched) continue;\n content = patched;\n } else {\n const merged = mergeSettingsJson(ancestor, leftBytes, rightBytes, undefined, Boolean(config.agentMode));\n if (merged.kind === \"review\") {\n fields.push(...merged.fields);\n continue;\n }\n content = merged.content;\n }\n decisions[index] = {\n kind: \"accepted\",\n path: decision.path,\n source: \"merged\",\n file: {\n path: decision.path,\n contentBase64: content.toString(\"base64\"),\n sha256: createHash(\"sha256\").update(content).digest(\"hex\"),\n },\n };\n }\n return {\n plan: { kind: \"planned\", decisions, conflicts: decisions.filter((decision) => decision.kind === \"conflict\") },\n fields,\n };\n}\n", "import type { PublicationCapability, RemoteHead } from \"../backends/sync-backend.js\";\nimport type { CommonSyncConfig } from \"../settings/settings-types.js\";\nimport { agentDir } from \"../snapshot/session-paths.js\";\nimport type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport { inspectRemoteSelection } from \"../sync/sync-policy.js\";\nimport { fileHashMap } from \"../sync/sync-state.js\";\nimport { safeTerminalText, snapshotPathLabel } from \"./terminal-text.js\";\nimport { transferChanges, transferCounts } from \"./transfer-changes.js\";\n\nexport function formatDiff(local: Snapshot, remote: Snapshot) {\n const localMap = fileHashMap(local);\n const remoteMap = fileHashMap(remote);\n const allPaths = [...new Set([...Object.keys(localMap), ...Object.keys(remoteMap)])].sort();\n const lines = [\n `local: ${local.files.length} files`,\n `remote: ${safeTerminalText(remote.id)} (${remote.files.length} files)`,\n \"\",\n ];\n let changed = 0;\n for (const filePath of allPaths) {\n if (!Object.hasOwn(localMap, filePath)) {\n lines.push(`Remote only: ${snapshotPathLabel(filePath)}`);\n changed += 1;\n } else if (!Object.hasOwn(remoteMap, filePath)) {\n lines.push(`Local only: ${snapshotPathLabel(filePath)}`);\n changed += 1;\n } else if (localMap[filePath] !== remoteMap[filePath]) {\n lines.push(`Different: ${snapshotPathLabel(filePath)}`);\n changed += 1;\n }\n }\n if (changed === 0) lines.push(\"No file differences.\");\n return lines.join(\"\\n\");\n}\n\nexport function formatSnapshotOnlyDiff(title: string, snapshot: Snapshot) {\n return [\n `${safeTerminalText(title)}: ${safeTerminalText(snapshot.id)}`,\n ...snapshot.files.map((file) => `Add: ${snapshotPathLabel(file.path)}`),\n ].join(\"\\n\");\n}\n\nexport function formatPushSummary(\n config: CommonSyncConfig,\n destination: string,\n upload: Snapshot,\n head: RemoteHead | undefined,\n preservedRemoteFileCount = 0,\n remote?: Snapshot,\n) {\n return [\n `Sync setup: ${safeTerminalText(config.setupName)}`,\n `Storage location: ${safeTerminalText(destination)}`,\n `Direction: Local \u2192 Remote. Source: ${safeTerminalText(agentDir())}.`,\n `Publish a snapshot containing ${upload.files.length} files; unchanged and preserved files are not counted as changes.`,\n `Sessions: ${upload.syncSessions ? \"included \u2014 may contain private conversations\" : \"not included\"}`,\n head ? `Remote latest: ${safeTerminalText(head.snapshotId)}` : \"Remote latest: empty\",\n \"Publication effect: the backend's active head will reference the new immutable snapshot. Removed paths leave the active snapshot; retained history is not erased.\",\n ...(remote && inspectRemoteSelection(config.include, remote).kind === \"different\"\n ? [\"Included-content policy effect: replace the differing remote selection with this setup's local selection.\"]\n : []),\n formatPublicationPreview(remote, upload),\n config.skipSecretScan\n ? \"Warning: possible-secret scanning is disabled for this push.\"\n : preservedRemoteFileCount > 0\n ? `Possible secrets in locally managed files were scanned before this prompt; ${preservedRemoteFileCount} preserved remote file(s) were not rescanned.`\n : \"Possible secrets were scanned before this prompt.\",\n ].join(\"\\n\");\n}\n\nexport function formatApplyPreview(\n local: Snapshot,\n remote: Snapshot,\n protectedPaths: ReadonlySet<string> = new Set(),\n additionalRemovals: readonly string[] = [],\n) {\n return formatDirectionalChanges(\n local,\n remote,\n {\n add: \"Add locally\",\n update: \"Update locally\",\n remove: \"Remove locally\",\n },\n protectedPaths,\n additionalRemovals,\n );\n}\n\nexport function formatPullSummary(\n config: CommonSyncConfig,\n destination: string,\n local: Snapshot,\n remote: Snapshot,\n protectedPaths: ReadonlySet<string>,\n additionalRemovals: readonly string[] = [],\n) {\n return [\n `Sync setup: ${safeTerminalText(config.setupName)}`,\n `Storage location: ${safeTerminalText(destination)}`,\n \"Direction: Remote \u2192 Local.\",\n `Snapshot: ${safeTerminalText(remote.id)}`,\n `Sessions: ${remote.syncSessions ? \"included \u2014 may contain private conversations\" : \"not included\"}`,\n `Protected live sessions: ${protectedPaths.size || \"none\"}`,\n formatApplyPreview(local, remote, protectedPaths, additionalRemovals),\n ...(additionalRemovals.length\n ? [\"Case-variant aliases listed above are removed before writing canonical paths.\"]\n : []),\n \"A local backup is created before these writes/deletes. The remote active snapshot is unchanged.\",\n ].join(\"\\n\");\n}\n\nexport function formatRollbackSummary(\n config: CommonSyncConfig,\n destination: string,\n local: Snapshot,\n remote: Snapshot,\n requestedSnapshot: string,\n protectedPaths: ReadonlySet<string>,\n additionalRemovals: readonly string[] = [],\n) {\n return [\n `Sync setup: ${safeTerminalText(config.setupName)}`,\n `Storage location: ${safeTerminalText(destination)}`,\n \"Direction: Historical snapshot \u2192 Local and remote active head.\",\n `Snapshot: ${safeTerminalText(requestedSnapshot)}`,\n `Sessions: ${remote.syncSessions ? \"included \u2014 may contain private conversations\" : \"not included\"}`,\n `Protected live sessions: ${protectedPaths.size || \"none\"}`,\n formatApplyPreview(local, remote, protectedPaths, additionalRemovals),\n ...(additionalRemovals.length\n ? [\"Case-variant aliases listed above are removed before writing canonical paths.\"]\n : []),\n \"A local backup is created before applying; the backend's active head will change.\",\n ].join(\"\\n\");\n}\n\nexport function formatPublicationPreview(remote: Snapshot | undefined, upload: Snapshot) {\n return formatDirectionalChanges(remote, upload, {\n add: \"Add remotely\",\n update: \"Update remotely\",\n remove: \"Remove remotely\",\n });\n}\n\nfunction formatDirectionalChanges(\n before: Snapshot | undefined,\n after: Snapshot,\n labels: { add: string; update: string; remove: string },\n protectedPaths: ReadonlySet<string> = new Set(),\n additionalRemovals: readonly string[] = [],\n) {\n const changes = transferChanges(before, after, protectedPaths);\n const known = new Set(changes.map((change) => change.path));\n for (const filePath of additionalRemovals) {\n if (!known.has(filePath) && !protectedPaths.has(filePath)) {\n changes.push({ path: filePath, action: \"Delete\" });\n known.add(filePath);\n }\n }\n const counts = transferCounts(changes);\n const label = { Add: labels.add, Update: labels.update, Delete: labels.remove };\n return [\n `Changes: ${counts.add} add \u00B7 ${counts.update} update \u00B7 ${counts.remove} remove`,\n ...changes.map((change) => `${label[change.action]}: ${snapshotPathLabel(change.path)}`),\n ...(changes.length ? [] : [\"No file changes.\"]),\n ].join(\"\\n\");\n}\n\nexport function countPreservedRemoteFiles(local: Snapshot, upload: Snapshot) {\n const localPaths = new Set(local.files.map((file) => file.path));\n return upload.files.filter((file) => !localPaths.has(file.path)).length;\n}\n\nexport function publicationCapabilityDescription(capability: PublicationCapability) {\n switch (capability) {\n case \"lease-protected\":\n return \"lease-protected (exact expected-ref update)\";\n case \"atomic-conditional\":\n return \"atomic-conditional (verified atomic precondition)\";\n case \"conditional-required\":\n return \"conditional-required (read-only until atomic preconditions are verified)\";\n case \"read-check-write-verify\":\n return \"read-check-write-verify (visible races rejected; simultaneous unseen races remain possible)\";\n }\n}\n\nexport function redact(value: string) {\n return value.length <= 8 ? \"configured\" : `${value.slice(0, 4)}\u2026${value.slice(-4)}`;\n}\n", "import { syncConfigReviewIdentity } from \"../settings/config.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport type { SyncState } from \"../state/state-types.js\";\nimport { formatDiff, formatSnapshotOnlyDiff } from \"../ui/sync-format.js\";\nimport { safeTerminalText } from \"../ui/terminal-text.js\";\nimport { SyncDecisionRequiredError } from \"./sync-errors.js\";\nimport { includeFromSelectionConfig } from \"./sync-policy.js\";\nimport { syncPolicyChanged } from \"./sync-state.js\";\n\nexport type SyncDecisionKind =\n | \"remote-or-policy-changed\"\n | \"both-changed\"\n | \"first-sync-settings-diverged\"\n | \"first-sync-sessions-diverged\"\n | \"remote-empty\";\n\nexport type SyncResolutionDirection = \"push\" | \"pull\";\n\nexport interface SyncDecision {\n kind: SyncDecisionKind;\n setupName: string;\n configIdentity: string;\n causes: {\n localChanged: boolean;\n remoteChanged: boolean;\n policyChanged: boolean;\n };\n previousInclude?: readonly string[];\n currentInclude: readonly string[];\n review: string;\n directions: readonly SyncResolutionDirection[];\n directMessage: string;\n}\n\nexport {\n isSyncDecisionRequiredError,\n SyncDecisionRequiredError,\n} from \"./sync-errors.js\";\n\ninterface CreateSyncDecisionOptions {\n kind: SyncDecisionKind;\n config: AnySyncConfig;\n state: SyncState;\n local: Snapshot;\n remote?: Snapshot;\n localChanged: boolean;\n remoteChanged: boolean;\n directMessage: string;\n}\n\nexport function createSyncDecision(options: CreateSyncDecisionOptions) {\n const { config, state, local, remote, kind } = options;\n const policyChanged = Boolean(state.lastAppliedSnapshot) && syncPolicyChanged(state, config);\n const previousInclude = includeFromSelectionConfig(state);\n const currentInclude = [...config.include];\n const causes = {\n localChanged: options.localChanged,\n remoteChanged: options.remoteChanged,\n policyChanged,\n };\n const causeLines =\n kind === \"first-sync-settings-diverged\"\n ? [\"This machine and the remote have different Pi settings on first sync.\"]\n : kind === \"first-sync-sessions-diverged\"\n ? [\"Pi settings match, but local and remote sessions differ on first sync.\"]\n : kind === \"remote-empty\"\n ? [\"The remote storage location is empty.\"]\n : [\n ...(causes.localChanged ? [\"Local content changed since the last sync.\"] : []),\n ...(causes.remoteChanged ? [\"Remote content changed since the last sync.\"] : []),\n ...(causes.policyChanged ? [\"Included content changed since the last sync.\"] : []),\n ];\n const comparison = remote\n ? formatDiff(local, remote)\n : formatSnapshotOnlyDiff(\"Remote is empty. Local push would upload\", local);\n const review = [\n `Sync setup: ${safeTerminalText(config.setupName)}`,\n \"\",\n \"Why a decision is required:\",\n ...causeLines,\n ...(policyChanged\n ? [\"\", `Previously included: ${safeList(previousInclude)}`, `Currently included: ${safeList(currentInclude)}`]\n : []),\n \"\",\n \"Observed differences:\",\n ...comparison.split(\"\\n\").map(safeTerminalText),\n ].join(\"\\n\");\n return new SyncDecisionRequiredError({\n kind,\n setupName: config.setupName,\n configIdentity: syncConfigReviewIdentity(config),\n causes,\n ...(policyChanged ? { previousInclude: [...previousInclude] } : {}),\n currentInclude,\n review,\n directions: kind === \"remote-empty\" ? [\"push\"] : [\"push\", \"pull\"],\n directMessage: options.directMessage,\n });\n}\n\nfunction safeList(values: readonly string[]) {\n return values.length > 0 ? values.map(safeTerminalText).join(\", \") : \"none\";\n}\n", "import type { ExtensionCommandContext, ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { createSyncBackend, type SyncBackendFactory } from \"../backends/backend-factory.js\";\nimport {\n expectedRemoteHead,\n type RemoteHead,\n type SyncBackend,\n SyncBackendConflictError,\n} from \"../backends/sync-backend.js\";\nimport type { CommandOptions } from \"../commands/command-types.js\";\nimport { loadConfig, syncCheckConfigFingerprint } from \"../settings/config.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport {\n effectiveSessionRoot,\n requireStableMergeSessionRoot,\n snapshotOptionsForContext,\n} from \"../snapshot/session-paths.js\";\nimport {\n createSnapshot,\n filterSnapshotForConfigPolicy,\n mergeRemotePreservedFiles,\n regenerateSnapshotIdentity,\n scanSnapshot,\n} from \"../snapshot/snapshot.js\";\nimport type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport {\n hasCurrentMergeBaseline,\n pruneMergeBaselines,\n readMergeAncestors,\n stageMergeBaseline,\n} from \"../state/merge-baseline-store.js\";\nimport {\n readStateForConfig,\n statePathForConfig,\n syncStateFingerprint,\n writeStateForConfig,\n} from \"../state/sync-state-store.js\";\nimport { confirmMergeReview } from \"../ui/merge-review.js\";\nimport { mergedSyncSummary } from \"../ui/merged-sync-summary.js\";\nimport { safeTerminalText } from \"../ui/terminal-text.js\";\nimport { startupTransferEnabled } from \"./agent-policy.js\";\nimport { releaseConflictArtifacts } from \"./conflict-artifact-ownership.js\";\nimport {\n type CreatedConflictArtifact,\n conflictGroups,\n readConflictArtifact,\n saveConflictArtifact,\n} from \"./conflict-artifacts.js\";\nimport { type ConflictResolution, resolveReviewedGroup } from \"./conflict-resolution.js\";\nimport { pruneCompletedConflicts } from \"./conflict-retention.js\";\nimport { resolveContentConflicts } from \"./content-conflicts.js\";\nimport { ContinuousError } from \"./continuous-errors.js\";\nimport { planFileMerge } from \"./file-merge-planner.js\";\nimport { overlayLocalFields, portableSnapshot, sameLocalFields } from \"./local-fields.js\";\nimport { applyMergedSnapshot, preflightMergedTargets } from \"./merge-apply.js\";\nimport {\n clearMergeJournal,\n type MergeJournal,\n mergeJournalIdentity,\n readMergeJournal,\n writeMergeJournal,\n} from \"./merge-journal.js\";\nimport { mergeTransferError } from \"./merge-transfer-error.js\";\nimport { acceptedMergeFiles, type PartialProgress, progressState } from \"./partial-progress.js\";\nimport {\n formatRemoteSelectionStatus,\n readSnapshotForHead,\n requireCompatibleRemoteSelection,\n} from \"./remote-snapshot.js\";\nimport { resolveSettingsConflicts } from \"./settings-conflicts.js\";\nimport { createStartupTimings, type StartupTimings } from \"./startup-timings.js\";\nimport { createSyncDecision } from \"./sync-decision.js\";\nimport { backupLocal, captureMutationOwner, protectedSessionPaths } from \"./sync-local.js\";\nimport { inspectRemoteSelection } from \"./sync-policy.js\";\nimport { fileHashMap, hasLocalChanges, hasRemoteChanges, sameHashes, syncPolicyChanged } from \"./sync-state.js\";\nimport { TEXT_MERGE_WORK_LIMIT } from \"./text-merge.js\";\n\nconst MAX_ATTEMPTS = 3;\n\n/** Established-baseline sync only. First-source selection remains in the existing command flow. */\nexport async function mergeSync(\n ctx: ExtensionContext | ExtensionCommandContext,\n options: CommandOptions,\n factory: SyncBackendFactory = createSyncBackend,\n resolution?: ConflictResolution,\n) {\n const timings = options.startupTimings ?? createStartupTimings();\n const sessionOwner = captureMutationOwner(ctx, options.signal);\n const validateOwner = (config?: AnySyncConfig) => {\n sessionOwner();\n options.background?.validate(config);\n };\n const isCurrent = () => {\n try {\n validateOwner();\n return true;\n } catch {\n return false;\n }\n };\n const validateRetryAuthorization = (config: AnySyncConfig) => {\n if (\n options.agentRetryRefusal &&\n (!config.agentMode || options.auto || options.background || !ctx.hasUI || ![\"tui\", \"rpc\"].includes(ctx.mode))\n )\n throw new Error(\"Refused-candidate retry requires foreground Agent mode in TUI or RPC.\");\n };\n const config = await loadConfig(options.setup);\n validateOwner(config);\n validateRetryAuthorization(config);\n const configToken = syncCheckConfigFingerprint(config);\n const modelToken = JSON.stringify(ctx.model);\n const sessionRoot = config.include.includes(\"sessions\") ? await effectiveSessionRoot(ctx) : undefined;\n validateOwner();\n const snapshotOptions = {\n ...snapshotOptionsForContext(ctx, config),\n sessionDir: sessionRoot,\n signal: options.signal,\n };\n const validate = () =>\n timings.measure(\"transfer authorization\", async () => {\n validateOwner();\n const latest = await loadConfig(options.setup);\n validateOwner(latest);\n validateRetryAuthorization(latest);\n if (configToken !== syncCheckConfigFingerprint(latest))\n throw new Error(\"Sync setup or settings changed during transfer; reopen sync.\");\n if (sessionRoot !== undefined) {\n const currentRoot = await effectiveSessionRoot(ctx);\n validateOwner();\n if (currentRoot !== sessionRoot)\n throw new Error(\"Session storage root changed during transfer; evidence retained for review.\");\n }\n if (config.agentMode && JSON.stringify(ctx.model) !== modelToken)\n throw new Error(\"Agent mode paused: selected model changed during transfer.\");\n if (options.auto && (!startupTransferEnabled(latest) || !ctx.isIdle()))\n throw new Error(\"Automatic transfer is no longer authorized at this idle boundary.\");\n });\n await validate();\n const backend = await timings.measure(\"transfer backend initialization\", () => factory(config));\n await validate();\n const pending = await timings.measure(\"transfer journal read\", () => readMergeJournal(config));\n await validate();\n if (pending && options.agentRetryRefusal)\n throw new Error(\"A pending merge journal requires ordinary Sync now before retrying a refused candidate.\");\n if (pending) {\n const recovered = await timings.measure(\"transfer journal recovery\", () =>\n completeJournal(\n ctx,\n config,\n backend,\n pending,\n validate,\n timings,\n options.signal,\n options.auto,\n options.background?.validate,\n ),\n );\n if (!recovered) {\n if ((options.auto || !options.silent) && !options.signal?.aborted)\n ctx.ui.notify(\n \"Interrupted candidate is not active; local content and baseline were unchanged. Evidence was reconciled without retrying publication. Run sync again for a fresh plan.\",\n \"warning\",\n );\n return \"cancelled\" as const;\n }\n if ((options.auto || !options.silent) && !options.signal?.aborted)\n ctx.ui.notify(\"Recovered the committed merged transfer. Run sync again to inspect newer changes.\", \"info\");\n return \"applied\" as const;\n }\n // Recovery above never publishes. This gate applies only to new autonomous transfers.\n if ((options.auto || config.agentMode) && backend.capability === \"read-check-write-verify\") {\n throw new Error(\n \"Automatic transfer requires conditional publication or a lease; this backend supports only read/check/write/verify. Disable Agent mode and use manual sync.\",\n );\n }\n const textBudget = { remaining: TEXT_MERGE_WORK_LIMIT };\n const createdArtifacts: CreatedConflictArtifact[] = [];\n const ownedStatePath = statePathForConfig(config);\n try {\n for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {\n await validate();\n const state = await timings.measure(\"transfer state read\", () => readStateForConfig(config));\n if (state.unresolved?.length && !config.partialSync)\n throw new Error(\n \"Partial progress remains unresolved; re-enable partial sync or review an explicit force direction.\",\n );\n const localRaw = await timings.measure(\"transfer local snapshot\", () =>\n createSnapshot(config.snapshotIdentity, snapshotOptions),\n );\n const local = portableSnapshot(localRaw, config.localFields);\n if (!sameLocalFields(state.localFields, config.localFields))\n throw new Error(\"Local-field rules changed; review and confirm a directional migration first.\");\n const head = await timings.measure(\"transfer remote head\", () => backend.readHead(options.signal));\n await validate();\n // This is a read-only shortcut, never authority to apply or publish. Pending\n // journals were handled above. Legacy/partial baselines retain the full path.\n if (\n options.auto &&\n !resolution &&\n !config.partialSync &&\n head &&\n state.lastAppliedSnapshot &&\n state.lastRemoteRevision &&\n !state.unresolved?.length &&\n head.snapshotId === state.lastAppliedSnapshot &&\n backend.sameRevision(head.revision, state.lastRemoteRevision) &&\n inspectRemoteSelection(config.include, { selection: head.selection, files: [] }).kind === \"same\" &&\n matchesAcceptedState(state, config, head, local)\n ) {\n const unchanged = await timings.measure(\"transfer unchanged verification\", async () => {\n if (!(await hasCurrentMergeBaseline(config, local, state))) return false;\n await validate();\n const currentLocal = await timings.measure(\"transfer local snapshot\", () =>\n createSnapshot(config.snapshotIdentity, snapshotOptions),\n );\n await validate();\n const currentState = await timings.measure(\"transfer state read\", () => readStateForConfig(config));\n await validate();\n return (\n sameHashes(fileHashMap(currentLocal), fileHashMap(localRaw)) &&\n syncStateFingerprint(currentState) === syncStateFingerprint(state)\n );\n });\n await validate();\n if (unchanged) {\n timings.markUnchanged();\n return \"applied\" as const;\n }\n }\n const rawRemote = head\n ? await timings.measure(\"transfer snapshot download\", () => readSnapshotForHead(backend, head, options.signal))\n : undefined;\n await validate();\n if (rawRemote) {\n const files = [...local.files, ...rawRemote.files];\n if (\n files.length > 16_384 ||\n files.reduce((bytes, file) => bytes + file.contentBase64.length * 0.75, 0) > 64 * 1024 * 1024\n ) {\n throw new Error(\n \"Merged transfer exceeds the 64 MiB / 16,384 input-file bound; review an explicit push or pull instead.\",\n );\n }\n }\n const remote = rawRemote\n ? portableSnapshot(filterSnapshotForConfigPolicy(rawRemote, config), rawRemote.localFields)\n : undefined;\n if (rawRemote) {\n requireCompatibleRemoteSelection(config, rawRemote);\n const validation = await timings.measure(\"transfer merge planning\", () =>\n planFileMerge({\n baseline: state.lastFileHashes,\n local: local.files,\n remote: rawRemote.files,\n selectionCompatible: true,\n }),\n );\n await validate();\n const managedPaths = new Set([\n ...Object.keys(state.lastFileHashes),\n ...[...local.files, ...(remote?.files ?? [])].map((file) => file.path),\n ]);\n if (\n validation.kind === \"planned\" &&\n validation.conflicts.some(\n (item) => item.reason === \"path-collision\" && (!config.partialSync || !managedPaths.has(item.path)),\n )\n )\n throw new Error(\"Remote snapshot contains path collisions; review a directional recovery before merging.\");\n }\n const review = (\n message: string,\n kind: \"both-changed\" | \"remote-empty\" | \"remote-or-policy-changed\" = \"both-changed\",\n ) =>\n createSyncDecision({\n kind,\n config,\n state,\n local,\n remote,\n localChanged: hasLocalChanges(local, state, config),\n remoteChanged: remote ? hasRemoteChanges(remote, state, config) : Boolean(state.lastAppliedSnapshot),\n directMessage: message,\n });\n if (!state.lastAppliedSnapshot) throw review(\"Choose the initial source before enabling automatic transfer.\");\n if (syncPolicyChanged(state, config))\n throw review(\"Included content changed; review the selection before merging.\", \"remote-or-policy-changed\");\n if (!head || !remote || !rawRemote)\n throw review(\"The established remote is missing; choose an explicit recovery direction.\", \"remote-empty\");\n const selectionState = inspectRemoteSelection(config.include, rawRemote);\n const selectionCompatible = selectionState.kind === \"same\";\n let plan = await timings.measure(\"transfer merge planning\", () =>\n planFileMerge({\n baseline: state.lastFileHashes,\n local: local.files,\n remote: remote.files,\n selectionCompatible,\n protectedPaths: protectedSessionPaths(ctx, sessionRoot),\n }),\n );\n await validate();\n let resolved = { plan, fields: [] as string[] };\n if (config.mergeSettings || config.agentMode) {\n try {\n resolved = await timings.measure(\"transfer settings merge\", () =>\n resolveSettingsConflicts(config, state, local, remote, plan),\n );\n } catch (error) {\n if (!config.partialSync) throw error;\n }\n }\n await validate();\n plan = await timings.measure(\"transfer content merge\", () =>\n resolveContentConflicts(config, state, local, remote, resolved.plan, protectedSessionPaths(ctx, sessionRoot), {\n textBudget,\n signal: options.signal,\n }),\n );\n await validate();\n if (resolution) {\n plan = await resolveReviewedGroup(\n config,\n backend,\n state,\n local,\n remote,\n head,\n plan,\n resolution,\n protectedSessionPaths(ctx, sessionRoot),\n );\n await validate();\n }\n if (config.agentMode && !resolution) {\n const { resolveAgentPlan } = await import(\"./agent-plan.js\");\n await validate();\n plan = await resolveAgentPlan(\n ctx,\n options,\n config,\n backend,\n state,\n local,\n localRaw,\n remote,\n head,\n plan,\n snapshotOptions,\n validate,\n );\n await validate();\n if (plan.kind !== \"planned\" || (plan.conflicts.length && !config.partialSync))\n throw new ContinuousError(\n \"unsafe\",\n \"Agent mode paused: unsupported or refused conflict groups remain; no transfer was performed.\",\n );\n }\n if (\n plan.kind !== \"planned\" ||\n (plan.conflicts.length && (!config.partialSync || (options.auto && !config.agentMode)))\n ) {\n const decision = review(\n selectionCompatible\n ? `Conflicting or protected paths require review; no merged transfer was performed. Use /sync diff and an explicit direction.${resolved.fields.length ? ` Settings fields: ${resolved.fields.map(safeTerminalText).join(\", \")}` : \"\"}`\n : \"Remote selection metadata is unavailable; review the included content and choose an explicit direction before merging.\",\n selectionCompatible ? \"both-changed\" : \"remote-or-policy-changed\",\n );\n if (!selectionCompatible)\n decision.decision.review += `\\n\\n${formatRemoteSelectionStatus(selectionState)}\\nAn explicit direction adopts this setup's included-content policy; no automatic merge was performed.`;\n throw decision;\n }\n if (plan.kind !== \"planned\") throw new Error(\"Cannot partition an unverified merge plan.\");\n const groups = conflictGroups(plan, config);\n const withheld = new Set(groups.flatMap((group) => group.paths));\n // Transfer plans defer artifact writes until approved review and freshness guards pass.\n // A no-transfer manual inspection can persist referenced conflict state directly.\n const persistProgress = async (): Promise<PartialProgress | undefined> => {\n if (!groups.length) return;\n let ancestors: import(\"../snapshot/snapshot-types.js\").SnapshotFile[] = [];\n try {\n ancestors = ((await readMergeAncestors(config, state)) ?? []).filter((file) => withheld.has(file.path));\n } catch {\n /* Retain unknown evidence; absence remains explicit. */\n }\n await validate();\n const previousArtifacts = new Map<\n string,\n {\n artifact: Awaited<ReturnType<typeof readConflictArtifact>>;\n local: ReturnType<typeof fileHashMap>;\n remote: ReturnType<typeof fileHashMap>;\n }\n >();\n for (const token of new Set(state.unresolved?.map((group) => group.artifact) ?? [])) {\n try {\n const artifact = await readConflictArtifact(config, backend.identity, token);\n previousArtifacts.set(token, {\n artifact,\n local: fileHashMap(artifact.local),\n remote: fileHashMap(artifact.remote),\n });\n } catch {\n /* Unknown evidence retained, never reused. */\n }\n await validate();\n }\n const localHashes = fileHashMap(local);\n const remoteHashes = fileHashMap(remote);\n const previousGroups = new Map(state.unresolved?.map((item) => [JSON.stringify(item.paths), item]));\n const pending = groups.map((group) => {\n const previous = previousGroups.get(JSON.stringify(group.paths));\n const original = previous ? previousArtifacts.get(previous.artifact) : undefined;\n if (!original || !previous) return { group };\n return group.paths.every(\n (filePath) =>\n localHashes[filePath] === original.local[filePath] &&\n remoteHashes[filePath] === original.remote[filePath] &&\n state.lastFileHashes[filePath] === original.artifact.state.lastFileHashes[filePath],\n )\n ? { group, artifact: previous.artifact }\n : { group };\n });\n let artifact: string | undefined;\n const newGroups = pending.filter((item) => !item.artifact).map((item) => item.group);\n const newPaths = new Set(newGroups.flatMap((group) => group.paths));\n if (newGroups.length)\n artifact = await saveConflictArtifact(\n config,\n backend.identity,\n {\n state,\n local: { ...local, files: local.files.filter((file) => newPaths.has(file.path)) },\n remote: { ...remote, files: remote.files.filter((file) => newPaths.has(file.path)) },\n ancestors: ancestors.filter((file) => newPaths.has(file.path)),\n groups: newGroups,\n observed: { snapshotId: head.snapshotId, revision: head.revision },\n },\n captureMutationOwner(ctx, options.signal),\n (created) => createdArtifacts.push(created),\n );\n await validate();\n return {\n previous: state,\n groups: pending.map((item) => ({ paths: item.group.paths, artifact: item.artifact ?? artifact ?? \"\" })),\n };\n };\n let progress: PartialProgress | undefined;\n const accepted = regenerateSnapshotIdentity({\n ...local,\n files: acceptedMergeFiles(plan.decisions, local.files, withheld),\n });\n const after = overlayLocalFields(accepted, localRaw, config.localFields);\n if (config.include.includes(\"sessions\")) requireStableMergeSessionRoot(localRaw, after);\n const publication = regenerateSnapshotIdentity({\n ...accepted,\n version: config.partialSync ? 3 : accepted.version,\n files: [\n ...accepted.files.filter((file) => !withheld.has(file.path)),\n ...remote.files.filter((file) => withheld.has(file.path)),\n ],\n });\n const upload = mergeRemotePreservedFiles(publication, rawRemote, config);\n const publish =\n !sameHashes(fileHashMap(publication), fileHashMap(remote)) ||\n Boolean(config.partialSync && rawRemote.version !== 3);\n const apply = !sameHashes(fileHashMap(localRaw), fileHashMap(after));\n if (!publish && !apply) {\n const beforeEvidence = await timings.measure(\"transfer remote head\", () => backend.readHead(options.signal));\n await validate();\n if (!beforeEvidence || !backend.sameRevision(beforeEvidence.revision, head.revision))\n throw new ContinuousError(\n \"stale\",\n \"Remote changed before baseline acceptance; retry from a fresh observation.\",\n );\n progress = await persistProgress();\n await validate();\n const currentLocal = await timings.measure(\"transfer local snapshot\", () =>\n createSnapshot(config.snapshotIdentity, snapshotOptions),\n );\n await validate();\n if (\n !sameHashes(fileHashMap(currentLocal), fileHashMap(localRaw)) ||\n syncStateFingerprint(await timings.measure(\"transfer state read\", () => readStateForConfig(config))) !==\n syncStateFingerprint(state)\n )\n throw new ContinuousError(\n \"stale\",\n \"Local content or baseline changed before baseline acceptance; retry from a fresh observation.\",\n );\n await validate();\n const currentHead = await timings.measure(\"transfer remote head\", () => backend.readHead(options.signal));\n await validate();\n if (!currentHead || !backend.sameRevision(currentHead.revision, head.revision))\n throw new ContinuousError(\n \"stale\",\n \"Remote changed before baseline acceptance; retry from a fresh observation.\",\n );\n await options.agentAcceptance?.commitCandidate?.();\n await validate();\n await timings.measure(\"transfer baseline write\", () =>\n writeAcceptedState(config, head, accepted, validate, progress),\n );\n await timings.measure(\"transfer cleanup\", () =>\n pruneMergeBaselines(\n config,\n acceptedState(config, head, accepted, progress),\n captureMutationOwner(ctx, options.signal),\n ),\n );\n await validate();\n await timings.measure(\"transfer cleanup\", () =>\n pruneCompletedConflicts(\n config,\n backend.identity,\n acceptedState(config, head, accepted, progress),\n accepted,\n remote,\n captureMutationOwner(ctx, options.signal),\n ),\n );\n await validate();\n if (!options.silent)\n ctx.ui.notify(\n progress\n ? `No independent transfer required; ${groups.length} conflict groups remain withheld. Review /sync conflicts.`\n : \"Pi Sync is already up to date.\",\n progress ? \"warning\" : \"info\",\n );\n return \"applied\" as const;\n }\n await timings.measure(\"transfer preflight\", () =>\n preflightMergedTargets(localRaw, after, snapshotOptions, ctx.sessionManager.getSessionFile?.()),\n );\n await validate();\n if (!config.skipSecretScan && scanSnapshot(upload).length)\n throw new ContinuousError(\n \"unsafe\",\n \"Refusing to merge possible secrets. Review managed content before syncing.\",\n );\n if (!options.yes && !config.agentMode) {\n const summary = mergedSyncSummary({\n setupName: config.setupName,\n destination: backend.destination,\n localBefore: localRaw,\n localAfter: after,\n remoteBefore: rawRemote,\n remoteAfter: upload,\n publish,\n sessions: config.include.includes(\"sessions\"),\n groups,\n decisions: plan.decisions,\n capability: backend.capability,\n });\n if (\n !(await confirmMergeReview(\n ctx,\n summary.title,\n summary.content,\n options.signal,\n isCurrent,\n summary.confirmationLabel,\n summary.lines,\n ))\n )\n return \"cancelled\" as const;\n }\n await validate();\n const refreshed = await timings.measure(\"transfer local snapshot\", () =>\n createSnapshot(config.snapshotIdentity, snapshotOptions),\n );\n if (!sameHashes(fileHashMap(refreshed), fileHashMap(localRaw)))\n throw new ContinuousError(\"stale\", \"Local content changed during review; no merged transfer was performed.\");\n if (\n syncStateFingerprint(await timings.measure(\"transfer state read\", () => readStateForConfig(config))) !==\n syncStateFingerprint(state)\n )\n throw new ContinuousError(\"stale\", \"Sync baseline changed during review; retry from a fresh observation.\");\n await validate();\n const refreshedHead = await timings.measure(\"transfer remote head\", () => backend.readHead(options.signal));\n await validate();\n if (!refreshedHead || !backend.sameRevision(refreshedHead.revision, head.revision))\n throw new ContinuousError(\"stale\", \"Remote changed during review; no merged transfer was performed.\");\n await options.agentAcceptance?.commitCandidate?.();\n await validate();\n progress = await persistProgress();\n await validate();\n const backup = await timings.measure(\"transfer backup\", () =>\n backupLocal(config.snapshotIdentity, snapshotOptions, options.signal),\n );\n await validate();\n const journal: MergeJournal = {\n version: 1,\n identity: mergeJournalIdentity(config, backend.identity),\n before: localRaw,\n after,\n accepted,\n ...(progress ? { progress } : {}),\n upload: publish ? upload : rawRemote,\n expectedHead: head,\n backup,\n stateIdentity: syncStateFingerprint(state),\n ...(sessionRoot !== undefined ? { sessionRoot } : {}),\n ...(!publish ? { committedHead: head, applyOnly: true } : {}),\n };\n await timings.measure(\"transfer journal write\", () => writeMergeJournal(config, journal));\n // No backend call has begun: a stale candidate can be retired without ambiguous publication.\n const atCommitState = syncStateFingerprint(\n await timings.measure(\"transfer state read\", () => readStateForConfig(config)),\n );\n await validate();\n const atCommit = await timings.measure(\"transfer local snapshot\", () =>\n createSnapshot(config.snapshotIdentity, snapshotOptions),\n );\n await validate();\n if (!sameHashes(fileHashMap(atCommit), fileHashMap(localRaw)) || atCommitState !== journal.stateIdentity) {\n await validate();\n await clearMergeJournal(config);\n throw new ContinuousError(\n \"stale\",\n \"Local content or baseline changed before publication; candidate retired without transfer. Review a fresh sync.\",\n );\n }\n // Backup/journal awaits can also change physical identity without changing any bytes.\n try {\n await timings.measure(\"transfer preflight\", () =>\n preflightMergedTargets(atCommit, after, snapshotOptions, ctx.sessionManager.getSessionFile?.()),\n );\n await validate();\n } catch (error) {\n await validate();\n await clearMergeJournal(config);\n throw error;\n }\n try {\n if (publish) {\n const result = await timings.measure(\"transfer remote publication\", () =>\n backend.publishSnapshot(upload, expectedRemoteHead(head), {\n signal: options.signal,\n onCommit: options.onCommit,\n }),\n );\n journal.committedHead = result.head;\n journal.warnings = result.warnings;\n await timings.measure(\"transfer journal write\", () => writeMergeJournal(config, journal));\n } else options.onCommit?.();\n } catch (error) {\n if (\n error instanceof SyncBackendConflictError &&\n error.phase === \"before-commit\" &&\n !error.candidateMayHaveBeenActive\n ) {\n await clearMergeJournal(config);\n if (attempt + 1 < MAX_ATTEMPTS) continue;\n throw new Error(\"Remote changed before commit in all three attempts; retry later.\", { cause: error });\n }\n // Cancellation before publication is safe only if no backend attempt began.\n // Every uncertain/after-commit outcome retains evidence and is never blindly retried.\n throw mergeTransferError(error, config.backend);\n }\n const completed = await timings.measure(\"transfer journal recovery\", () =>\n completeJournal(\n ctx,\n config,\n backend,\n journal,\n validate,\n timings,\n options.signal,\n options.auto,\n options.background?.validate,\n ),\n );\n if (!completed) {\n if (!options.signal?.aborted && (options.auto || !options.silent))\n ctx.ui.notify(\n \"Remote changed before local apply; candidate retired without transfer. Run sync again.\",\n \"warning\",\n );\n return \"cancelled\" as const;\n }\n if (!options.signal?.aborted && (options.auto || !options.silent))\n ctx.ui.notify(\n [\n `Synced independent changes for \u201C${safeTerminalText(config.setupName)}\u201D. ${apply ? \"Local files changed; reload or restart Pi when ready to use changed resources.\" : \"Remote updated.\"} No automatic reload.`,\n ...(progress\n ? [\n `Partial progress: ${groups.length} dependency groups remain unresolved; neither side's withheld versions or baseline hashes were replaced. Review /sync conflicts.`,\n ]\n : []),\n ...(journal.warnings ?? []).map(safeTerminalText),\n ].join(\"\\n\"),\n progress || journal.warnings?.length ? \"warning\" : \"info\",\n );\n return \"applied\" as const;\n }\n } finally {\n await timings.measure(\"transfer cleanup\", () => releaseConflictArtifacts(config, ownedStatePath, createdArtifacts));\n }\n}\n\nasync function completeJournal(\n ctx: ExtensionContext | ExtensionCommandContext,\n config: AnySyncConfig,\n backend: SyncBackend,\n journal: MergeJournal,\n validate: () => Promise<void>,\n timings: StartupTimings,\n signal?: AbortSignal,\n auto = false,\n validateBackground?: () => void,\n) {\n if (\n journal.identity !== mergeJournalIdentity(config, backend.identity) ||\n !sameLocalFields(journal.upload.localFields, config.localFields)\n )\n throw new Error(\n \"Merge journal belongs to a different setup, selection or local-field policy; preserve it for reviewed recovery.\",\n );\n await validate();\n const sessionRoot = config.include.includes(\"sessions\") ? await effectiveSessionRoot(ctx) : undefined;\n await validate();\n if (sessionRoot !== undefined && journal.sessionRoot !== sessionRoot) {\n throw new Error(\n \"Merge journal session root is missing or differs from this context; preserve evidence and use reviewed directional recovery.\",\n );\n }\n const snapshotOptions = { ...snapshotOptionsForContext(ctx, config), sessionDir: sessionRoot, signal };\n const head = await timings.measure(\"transfer remote head\", () => backend.readHead(signal));\n if (\n !journal.committedHead &&\n head &&\n (backend.sameRevision(head.revision, journal.expectedHead.revision) ||\n backend.matchesUncommittedRecoveryHead?.(head, journal.expectedHead))\n ) {\n await validate();\n const local = await timings.measure(\"transfer local snapshot\", () =>\n createSnapshot(config.snapshotIdentity, snapshotOptions),\n );\n if (\n !sameHashes(fileHashMap(local), fileHashMap(journal.before)) ||\n syncStateFingerprint(await timings.measure(\"transfer state read\", () => readStateForConfig(config))) !==\n journal.stateIdentity\n ) {\n throw new Error(\n \"Uncertain publication is not active, but local content or baseline changed; keep the journal for reviewed recovery.\",\n );\n }\n await clearMergeJournal(config);\n return false;\n }\n await validate();\n // Baseline publication is the durable completion boundary. A later remote revision\n // cannot undo that acceptance; retire only the journal for the recorded commit.\n if (journal.committedHead && (!head || !backend.sameRevision(head.revision, journal.committedHead.revision))) {\n const state = await timings.measure(\"transfer state read\", () => readStateForConfig(config));\n await validate();\n if (\n matchesAcceptedState(state, config, journal.committedHead, journal.accepted ?? journal.after, journal.progress)\n ) {\n await clearMergeJournal(config);\n await validate();\n await pruneMergeBaselines(config, state, captureMutationOwner(ctx, signal));\n await validate();\n return true;\n }\n }\n if (journal.applyOnly && (!head || !backend.sameRevision(head.revision, journal.expectedHead.revision))) {\n const local = await timings.measure(\"transfer local snapshot\", () =>\n createSnapshot(config.snapshotIdentity, snapshotOptions),\n );\n const state = await timings.measure(\"transfer state read\", () => readStateForConfig(config));\n await validate();\n if (\n sameHashes(fileHashMap(local), fileHashMap(journal.before)) &&\n syncStateFingerprint(state) === journal.stateIdentity\n ) {\n await clearMergeJournal(config);\n return false;\n }\n throw new Error(\"Apply-only remote head advanced after local changes; preserve the journal for reviewed recovery.\");\n }\n if (\n !head ||\n head.snapshotId !== journal.upload.id ||\n (journal.committedHead && !backend.sameRevision(head.revision, journal.committedHead.revision))\n ) {\n throw new Error(\n \"Publication outcome cannot be reconciled with the current remote head. Journal and backup retained; do not retry publication or restore old bytes blindly.\",\n );\n }\n const observed = await timings.measure(\"transfer snapshot download\", () =>\n readSnapshotForHead(backend, head, signal),\n );\n requireCompatibleRemoteSelection(config, observed);\n if (\n !sameHashes(fileHashMap(observed), fileHashMap(journal.upload)) ||\n JSON.stringify(observed.selection) !== JSON.stringify(journal.upload.selection)\n )\n throw new Error(\"Remote snapshot does not match the recorded merge publication.\");\n const state = await timings.measure(\"transfer state read\", () => readStateForConfig(config));\n if (matchesAcceptedState(state, config, head, journal.accepted ?? journal.after, journal.progress)) {\n await validate();\n await clearMergeJournal(config);\n await validate();\n await pruneMergeBaselines(config, state, captureMutationOwner(ctx, signal));\n await validate();\n return true;\n }\n if (syncStateFingerprint(state) !== journal.stateIdentity) {\n throw new Error(\"Sync baseline changed after the interrupted merge; preserve its journal and review recovery.\");\n }\n if (inspectRemoteSelection(config.include, observed).kind !== \"same\")\n throw new Error(\n \"Pending merge has unavailable remote selection metadata; preserve its journal and choose a reviewed explicit direction.\",\n );\n if (config.include.includes(\"sessions\")) requireStableMergeSessionRoot(journal.before, journal.after);\n await validate();\n const validateOwner = captureMutationOwner(ctx, signal);\n const validateMutation = () => {\n validateOwner();\n validateBackground?.();\n if (auto && !ctx.isIdle()) throw new Error(\"Automatic file apply is no longer idle; evidence retained.\");\n };\n await timings.measure(\"transfer local apply\", () =>\n applyMergedSnapshot(\n journal.before,\n journal.after,\n protectedSessionPaths(ctx, sessionRoot),\n { ...snapshotOptions, validateMutation },\n validate,\n ctx.sessionManager.getSessionFile?.(),\n ),\n );\n await validate();\n const headAtAcceptance = await timings.measure(\"transfer remote head\", () => backend.readHead(signal));\n await validate();\n if (!headAtAcceptance || !backend.sameRevision(headAtAcceptance.revision, head.revision))\n throw new Error(\"Remote changed during merged apply; journal and backup retained for review.\");\n await timings.measure(\"transfer baseline write\", () =>\n writeAcceptedState(config, head, journal.accepted ?? journal.after, validate, journal.progress),\n );\n await validate();\n await clearMergeJournal(config);\n await validate();\n await timings.measure(\"transfer cleanup\", () =>\n pruneMergeBaselines(\n config,\n acceptedState(config, head, journal.accepted ?? journal.after, journal.progress),\n captureMutationOwner(ctx, signal),\n ),\n );\n await validate();\n await timings.measure(\"transfer cleanup\", () =>\n pruneCompletedConflicts(\n config,\n backend.identity,\n acceptedState(config, head, journal.accepted ?? journal.after, journal.progress),\n journal.accepted ?? journal.after,\n journal.upload,\n captureMutationOwner(ctx, signal),\n ),\n );\n await validate();\n return true;\n}\n\n// Older valid journals may have accepted noncanonical JSON before projection normalization.\nfunction matchesAcceptedState(\n state: Awaited<ReturnType<typeof readStateForConfig>>,\n config: AnySyncConfig,\n head: RemoteHead,\n snapshot: Snapshot,\n progress?: PartialProgress,\n) {\n return [true, false].some(\n (canonical) =>\n syncStateFingerprint(state) === syncStateFingerprint(acceptedState(config, head, snapshot, progress, canonical)),\n );\n}\n\nfunction acceptedState(\n config: AnySyncConfig,\n head: RemoteHead,\n snapshot: Snapshot,\n progress?: PartialProgress,\n canonical = true,\n) {\n if (progress) return progressState(config, head, snapshot, progress);\n return {\n version: 1,\n profile: config.snapshotIdentity,\n lastAppliedSnapshot: head.snapshotId,\n lastRemoteRevision: head.revision,\n lastFileHashes: fileHashMap(canonical ? portableSnapshot(snapshot, config.localFields) : snapshot),\n include: [...config.include],\n ...(config.localFields !== undefined ? { localFields: config.localFields } : {}),\n };\n}\n\nasync function writeAcceptedState(\n config: AnySyncConfig,\n head: RemoteHead,\n snapshot: Snapshot,\n validate: () => Promise<void>,\n progress?: PartialProgress,\n) {\n const accepted = portableSnapshot(snapshot, config.localFields);\n const state = acceptedState(config, head, accepted, progress);\n await stageMergeBaseline(config, accepted, state, prog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AAS,OAAO;AAAA,IAChB,qBAAqB,KAAK;AAAA,IAC1B,oBAAoB,KAAK;AAAA,IACzB,gBAAgB,YAAY,YAAY,iBAAiB,UAAU,OAAO,WAAW,IAAI,QAAQ;AAAA,IACjG,SAAS,CAAC,GAAG,OAAO,OAAO;AAAA,IAC3B,GAAI,OAAO,gBAAgB,SAAY,EAAE,aAAa,OAAO,YAAY,IAAI,CAAC;AAAA,EAChF;AACF;AAEA,eAAe,mBACb,QACA,MACA,UACA,UACA,UACA;AACA,QAAM,WAAW,iBAAiB,UAAU,OAAO,WAAW;AAC9D,QAAM,QAAQ,cAAc,QAAQ,MAAM,UAAU,QAAQ;AAC5D,QAAM,mBAAmB,QAAQ,UAAU,OAAO,UAAU,QAAQ;AACpE,QAAM,SAAS;AACf,QAAM,oBAAoB,QAAQ,KAAK;AACvC,QAAM,SAAS;AACjB;",
6
+ "names": ["fs", "path", "fs", "path", "createHash", "fs", "path", "fs", "path", "fileHashMap", "fs", "path", "path", "fs", "createHash", "target", "index", "createHash", "createHash", "config", "artifact", "pending", "state"]
7
+ }
@@ -1,27 +1,29 @@
1
1
  // @generated by scripts/build-runtime.mjs; do not edit.
2
2
  // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
- import {
4
- createSyncBackend
5
- } from "./chunk-ORGBI36T.ts";
6
3
  import {
7
4
  fileHashMap,
8
5
  hasLocalChanges,
9
6
  remoteChangedSinceState
10
- } from "./chunk-BDB4IDM3.ts";
7
+ } from "./chunk-Y4UVXOLQ.ts";
8
+ import {
9
+ createSyncBackend
10
+ } from "./chunk-OJARL2TG.ts";
11
11
  import {
12
12
  createStartupTimings
13
13
  } from "./chunk-M6VQJIOU.ts";
14
14
  import {
15
15
  throwIfAborted
16
16
  } from "./chunk-PWMWOJP4.ts";
17
- import {
18
- createSnapshot,
19
- inspectRemoteSelection
20
- } from "./chunk-QOFMXPM5.ts";
21
17
  import {
22
18
  readStateForConfig,
23
19
  syncStateFingerprint
24
- } from "./chunk-UPNVIUBN.ts";
20
+ } from "./chunk-DN4IA7MR.ts";
21
+ import {
22
+ createSnapshot
23
+ } from "./chunk-ESKOPQVB.ts";
24
+ import {
25
+ inspectRemoteSelection
26
+ } from "./chunk-KYTT7KV4.ts";
25
27
 
26
28
  // src/sync/sync-inspection.ts
27
29
  import { createHash } from "node:crypto";
@@ -59,4 +61,4 @@ async function inspectSync(config, options, signal, factory = createSyncBackend,
59
61
  export {
60
62
  inspectSync
61
63
  };
62
- //# sourceMappingURL=chunk-PQW6GS4J.ts.map
64
+ //# sourceMappingURL=chunk-7ZIYU5QS.ts.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/sync/sync-inspection.ts"],
4
4
  "sourcesContent": ["import { createHash } from \"node:crypto\";\nimport { createSyncBackend, type SyncBackendFactory } from \"../backends/backend-factory.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport { createSnapshot } from \"../snapshot/snapshot.js\";\nimport type { SnapshotOptions } from \"../snapshot/snapshot-types.js\";\nimport { readStateForConfig, syncStateFingerprint } from \"../state/sync-state-store.js\";\nimport { throwIfAborted } from \"./signals.js\";\nimport { createStartupTimings, type StartupTimings } from \"./startup-timings.js\";\nimport { inspectRemoteSelection } from \"./sync-policy.js\";\nimport { fileHashMap, hasLocalChanges, remoteChangedSinceState } from \"./sync-state.js\";\n\n/** Advisory baseline-relative observation, never an authorization to transfer files. */\nexport async function inspectSync(\n config: AnySyncConfig,\n options: SnapshotOptions,\n signal?: AbortSignal,\n factory: SyncBackendFactory = createSyncBackend,\n timings: StartupTimings = createStartupTimings(),\n) {\n throwIfAborted(signal);\n const backend = await timings.measure(\"backend initialization\", () => factory(config));\n throwIfAborted(signal);\n const local = await timings.measure(\"local snapshot\", () =>\n createSnapshot(config.snapshotIdentity, { ...options, signal }),\n );\n throwIfAborted(signal);\n const state = await timings.measure(\"sync state read\", () => readStateForConfig(config));\n throwIfAborted(signal);\n const head = await timings.measure(\"remote head\", () => backend.readHead(signal));\n throwIfAborted(signal);\n const freshness: { localIdentity?: string } = {\n localIdentity: createHash(\"sha256\")\n .update(JSON.stringify(fileHashMap(local)))\n .digest(\"hex\"),\n };\n return {\n ...freshness,\n head,\n selectionState: head ? inspectRemoteSelection(config.include, { selection: head.selection, files: [] }) : undefined,\n localFiles: local.files.length,\n localChanged: hasLocalChanges(local, state, config),\n remoteChanged: remoteChangedSinceState(head, state, config, (left, right) => backend.sameRevision(left, right)),\n firstSync: !state.lastAppliedSnapshot,\n emptyInclude: config.include.length === 0,\n stateIdentity: syncStateFingerprint(state),\n destination: backend.destination,\n capability: backend.capability,\n };\n}\n\nexport type SyncInspection = Awaited<ReturnType<typeof inspectSync>>;\n\nexport interface StartupObservation {\n setupName: string;\n configIdentity: string;\n checkedAt: string;\n automaticTransfer?: boolean;\n inspection: SyncInspection;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAY3B,eAAsB,YACpB,QACA,SACA,QACA,UAA8B,mBAC9B,UAA0B,qBAAqB,GAC/C;AACA,iBAAe,MAAM;AACrB,QAAM,UAAU,MAAM,QAAQ,QAAQ,0BAA0B,MAAM,QAAQ,MAAM,CAAC;AACrF,iBAAe,MAAM;AACrB,QAAM,QAAQ,MAAM,QAAQ;AAAA,IAAQ;AAAA,IAAkB,MACpD,eAAe,OAAO,kBAAkB,EAAE,GAAG,SAAS,OAAO,CAAC;AAAA,EAChE;AACA,iBAAe,MAAM;AACrB,QAAM,QAAQ,MAAM,QAAQ,QAAQ,mBAAmB,MAAM,mBAAmB,MAAM,CAAC;AACvF,iBAAe,MAAM;AACrB,QAAM,OAAO,MAAM,QAAQ,QAAQ,eAAe,MAAM,QAAQ,SAAS,MAAM,CAAC;AAChF,iBAAe,MAAM;AACrB,QAAM,YAAwC;AAAA,IAC5C,eAAe,WAAW,QAAQ,EAC/B,OAAO,KAAK,UAAU,YAAY,KAAK,CAAC,CAAC,EACzC,OAAO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ACL,GAAG;AAAA,IACH;AAAA,IACA,gBAAgB,OAAO,uBAAuB,OAAO,SAAS,EAAE,WAAW,KAAK,WAAW,OAAO,CAAC,EAAE,CAAC,IAAI;AAAA,IAC1G,YAAY,MAAM,MAAM;AAAA,IACxB,cAAc,gBAAgB,OAAO,OAAO,MAAM;AAAA,IAClD,eAAe,wBAAwB,MAAM,OAAO,QAAQ,CAAC,MAAM,UAAU,QAAQ,aAAa,MAAM,KAAK,CAAC;AAAA,IAC9G,WAAW,CAAC,MAAM;AAAA,IAClB,cAAc,OAAO,QAAQ,WAAW;AAAA,IACxC,eAAe,qBAAqB,KAAK;AAAA,IACzC,aAAa,QAAQ;AAAA,IACrB,YAAY,QAAQ;AAAA,EACtB;AACF;",
6
6
  "names": []
7
7
  }
@@ -6,15 +6,15 @@ import {
6
6
  mergeSession,
7
7
  mergeText,
8
8
  readMergeAncestors
9
- } from "./chunk-IWZH5KYS.ts";
10
- import {
11
- mergePathIdentity
12
- } from "./chunk-76NB4R7U.ts";
9
+ } from "./chunk-6LD5KX55.ts";
13
10
  import {
14
11
  jsonEqual,
15
12
  parseSettingsDocument,
16
13
  renderSettingsMembers
17
14
  } from "./chunk-ZW5ZLGBI.ts";
15
+ import {
16
+ mergePathIdentity
17
+ } from "./chunk-XJHQPB3E.ts";
18
18
 
19
19
  // src/sync/content-conflicts.ts
20
20
  import { createHash } from "node:crypto";
@@ -212,4 +212,4 @@ export {
212
212
  mergeAcceptedSettingsPackages,
213
213
  mergeSettingsJson
214
214
  };
215
- //# sourceMappingURL=chunk-S7QS4AWK.ts.map
215
+ //# sourceMappingURL=chunk-AKMV47YC.ts.map
@@ -0,0 +1,55 @@
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
+
4
+ // src/state/json-file.ts
5
+ import { randomUUID } from "node:crypto";
6
+ import fs from "node:fs/promises";
7
+ import path from "node:path";
8
+ async function readJsonIfExists(filePath) {
9
+ try {
10
+ return JSON.parse(await fs.readFile(filePath, "utf8"));
11
+ } catch (error) {
12
+ if (error.code === "ENOENT") return void 0;
13
+ throw error;
14
+ }
15
+ }
16
+ async function writeJson(filePath, value, options = {}) {
17
+ const content = `${JSON.stringify(value, null, " ")}
18
+ `;
19
+ if (options.maxBytes !== void 0 && Buffer.byteLength(content) > options.maxBytes)
20
+ throw new Error(
21
+ "Private state document exceeds its storage bound; preserve existing evidence and use reviewed recovery."
22
+ );
23
+ await fs.mkdir(path.dirname(filePath), { recursive: true, mode: 448 });
24
+ const temp = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
25
+ try {
26
+ const handle = await fs.open(temp, "wx", 384);
27
+ try {
28
+ await handle.writeFile(content);
29
+ await handle.sync();
30
+ } finally {
31
+ await handle.close();
32
+ }
33
+ if (process.platform !== "win32") await fs.chmod(temp, 384);
34
+ await fs.rename(temp, filePath);
35
+ await syncDirectory(path.dirname(filePath));
36
+ } finally {
37
+ await fs.rm(temp, { force: true });
38
+ }
39
+ }
40
+ async function syncDirectory(directory) {
41
+ if (process.platform === "win32") return;
42
+ const handle = await fs.open(directory, "r");
43
+ try {
44
+ await handle.sync();
45
+ } finally {
46
+ await handle.close();
47
+ }
48
+ }
49
+
50
+ export {
51
+ readJsonIfExists,
52
+ writeJson,
53
+ syncDirectory
54
+ };
55
+ //# sourceMappingURL=chunk-AR2DGDUI.ts.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/state/json-file.ts"],
4
+ "sourcesContent": ["import { randomUUID } from \"node:crypto\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\nexport async function readJsonIfExists<T>(filePath: string): Promise<T | undefined> {\n try {\n return JSON.parse(await fs.readFile(filePath, \"utf8\")) as T;\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n throw error;\n }\n}\n\nexport async function writeJson(filePath: string, value: unknown, options: { maxBytes?: number } = {}) {\n const content = `${JSON.stringify(value, null, \"\\t\")}\\n`;\n if (options.maxBytes !== undefined && Buffer.byteLength(content) > options.maxBytes)\n throw new Error(\n \"Private state document exceeds its storage bound; preserve existing evidence and use reviewed recovery.\",\n );\n await fs.mkdir(path.dirname(filePath), { recursive: true, mode: 0o700 });\n const temp = `${filePath}.${process.pid}.${randomUUID()}.tmp`;\n try {\n const handle = await fs.open(temp, \"wx\", 0o600);\n try {\n await handle.writeFile(content);\n await handle.sync();\n } finally {\n await handle.close();\n }\n if (process.platform !== \"win32\") await fs.chmod(temp, 0o600);\n await fs.rename(temp, filePath);\n await syncDirectory(path.dirname(filePath));\n } finally {\n await fs.rm(temp, { force: true });\n }\n}\n\n/** POSIX rename/unlink durability; Windows does not expose directory fsync through Node. */\nexport async function syncDirectory(directory: string) {\n if (process.platform === \"win32\") return;\n const handle = await fs.open(directory, \"r\");\n try {\n await handle.sync();\n } finally {\n await handle.close();\n }\n}\n"],
5
+ "mappings": ";;;;AAAA,SAAS,kBAAkB;AAC3B,OAAO,QAAQ;AACf,OAAO,UAAU;AAEjB,eAAsB,iBAAoB,UAA0C;AAClF,MAAI;AACF,WAAO,KAAK,MAAM,MAAM,GAAG,SAAS,UAAU,MAAM,CAAC;AAAA,EACvD,SAAS,OAAO;AACd,QAAK,MAAgC,SAAS,SAAU,QAAO;AAC/D,UAAM;AAAA,EACR;AACF;AAEA,eAAsB,UAAU,UAAkB,OAAgB,UAAiC,CAAC,GAAG;AACrG,QAAM,UAAU,GAAG,KAAK,UAAU,OAAO,MAAM,GAAI,CAAC;AAAA;AACpD,MAAI,QAAQ,aAAa,UAAa,OAAO,WAAW,OAAO,IAAI,QAAQ;AACzE,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,QAAM,GAAG,MAAM,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,MAAM,MAAM,IAAM,CAAC;AACvE,QAAM,OAAO,GAAG,QAAQ,IAAI,QAAQ,GAAG,IAAI,WAAW,CAAC;AACvD,MAAI;AACF,UAAM,SAAS,MAAM,GAAG,KAAK,MAAM,MAAM,GAAK;AAC9C,QAAI;AACF,YAAM,OAAO,UAAU,OAAO;AAC9B,YAAM,OAAO,KAAK;AAAA,IACpB,UAAE;AACA,YAAM,OAAO,MAAM;AAAA,IACrB;AACA,QAAI,QAAQ,aAAa,QAAS,OAAM,GAAG,MAAM,MAAM,GAAK;AAC5D,UAAM,GAAG,OAAO,MAAM,QAAQ;AAC9B,UAAM,cAAc,KAAK,QAAQ,QAAQ,CAAC;AAAA,EAC5C,UAAE;AACA,UAAM,GAAG,GAAG,MAAM,EAAE,OAAO,KAAK,CAAC;AAAA,EACnC;AACF;AAGA,eAAsB,cAAc,WAAmB;AACrD,MAAI,QAAQ,aAAa,QAAS;AAClC,QAAM,SAAS,MAAM,GAAG,KAAK,WAAW,GAAG;AAC3C,MAAI;AACF,UAAM,OAAO,KAAK;AAAA,EACpB,UAAE;AACA,UAAM,OAAO,MAAM;AAAA,EACrB;AACF;",
6
+ "names": []
7
+ }
@@ -3,25 +3,25 @@
3
3
  import {
4
4
  fileHashMap,
5
5
  sameHashes
6
- } from "./chunk-BDB4IDM3.ts";
6
+ } from "./chunk-Y4UVXOLQ.ts";
7
7
  import {
8
8
  portableSnapshot,
9
9
  sameLocalFields,
10
10
  validatePortableSnapshot,
11
11
  validateSnapshotFieldPolicy
12
- } from "./chunk-A6HU4ERM.ts";
12
+ } from "./chunk-MKSMJPVA.ts";
13
13
  import {
14
14
  planFileMerge
15
- } from "./chunk-76NB4R7U.ts";
15
+ } from "./chunk-XJHQPB3E.ts";
16
16
  import {
17
17
  statePathForConfig,
18
18
  syncStateFingerprint
19
- } from "./chunk-UPNVIUBN.ts";
19
+ } from "./chunk-DN4IA7MR.ts";
20
20
  import {
21
21
  readJsonIfExists,
22
22
  syncDirectory,
23
23
  writeJson
24
- } from "./chunk-HUZ5CR4W.ts";
24
+ } from "./chunk-AR2DGDUI.ts";
25
25
 
26
26
  // src/sync/merge-journal.ts
27
27
  import { randomUUID } from "node:crypto";
@@ -94,7 +94,7 @@ async function readMergeJournal(config) {
94
94
  if (journal.progress) {
95
95
  const before = fileHashMap(journal.before);
96
96
  const after = fileHashMap(journal.after);
97
- const { readConflictArtifact } = await import("./conflict-artifacts-FXFIIBCB.ts");
97
+ const { readConflictArtifact } = await import("./conflict-artifacts-J6WSDCWP.ts");
98
98
  const backendIdentity = JSON.parse(journal.identity)[1];
99
99
  if (typeof backendIdentity !== "string") throw new Error("Invalid partial backend identity.");
100
100
  const byArtifact = /* @__PURE__ */ new Map();
@@ -150,4 +150,4 @@ export {
150
150
  retireMergeJournal,
151
151
  requireNoMergeJournal
152
152
  };
153
- //# sourceMappingURL=chunk-GNH73BJ5.ts.map
153
+ //# sourceMappingURL=chunk-BEST45H2.ts.map