@narumitw/pi-sync 0.70.7 → 0.71.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (734) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +33 -106
  3. package/dist/chunks/agent-plan-A6CS3XXA.ts +337 -0
  4. package/dist/chunks/agent-plan-A6CS3XXA.ts.map +7 -0
  5. package/dist/chunks/chunk-2BMTS5OW.ts +229 -0
  6. package/dist/chunks/chunk-2BMTS5OW.ts.map +7 -0
  7. package/dist/chunks/chunk-2G6GTIWW.ts +188 -0
  8. package/dist/chunks/chunk-2G6GTIWW.ts.map +7 -0
  9. package/dist/chunks/chunk-2YHXXWUF.ts +18 -0
  10. package/dist/chunks/chunk-2YHXXWUF.ts.map +7 -0
  11. package/dist/chunks/chunk-3GL7LBNB.ts +3 -0
  12. package/dist/chunks/chunk-3M3KQFSQ.ts +215 -0
  13. package/dist/chunks/chunk-3M3KQFSQ.ts.map +7 -0
  14. package/dist/chunks/chunk-3PFWVSV3.ts +3 -0
  15. package/dist/chunks/chunk-4S5CGN4M.ts +54 -0
  16. package/dist/chunks/chunk-4S5CGN4M.ts.map +7 -0
  17. package/dist/chunks/{chunk-H7VOTY5N.ts → chunk-53AFFVTT.ts} +2 -24
  18. package/dist/chunks/{chunk-H7VOTY5N.ts.map → chunk-53AFFVTT.ts.map} +1 -1
  19. package/dist/chunks/chunk-53IKSWLZ.ts +3 -0
  20. package/dist/chunks/{chunk-ZWP6HAYV.ts → chunk-5ERTMRNE.ts} +1 -1
  21. package/dist/chunks/chunk-5ERTMRNE.ts.map +7 -0
  22. package/dist/chunks/chunk-5WUWHDCJ.ts +12 -0
  23. package/dist/chunks/chunk-5WUWHDCJ.ts.map +7 -0
  24. package/dist/chunks/{chunk-WRS3SUNZ.ts → chunk-6VGQ6THO.ts} +8 -10
  25. package/dist/chunks/{chunk-WRS3SUNZ.ts.map → chunk-6VGQ6THO.ts.map} +1 -1
  26. package/dist/chunks/chunk-6WVJIIXQ.ts +154 -0
  27. package/dist/chunks/chunk-6WVJIIXQ.ts.map +7 -0
  28. package/dist/chunks/chunk-A3NEEVNA.ts +3 -0
  29. package/dist/chunks/chunk-A7KJUFLX.ts +2120 -0
  30. package/dist/chunks/chunk-A7KJUFLX.ts.map +7 -0
  31. package/dist/chunks/{chunk-4A34OGXY.ts → chunk-AA2G3HTW.ts} +12 -16
  32. package/dist/chunks/{chunk-4A34OGXY.ts.map → chunk-AA2G3HTW.ts.map} +1 -1
  33. package/dist/chunks/chunk-AITZUACB.ts +3 -0
  34. package/dist/chunks/chunk-AVLYLWA7.ts +1414 -0
  35. package/dist/chunks/chunk-AVLYLWA7.ts.map +7 -0
  36. package/dist/chunks/chunk-B4JNUYZ2.ts +12 -0
  37. package/dist/chunks/chunk-B4JNUYZ2.ts.map +7 -0
  38. package/dist/chunks/chunk-BEO3THWZ.ts +3 -0
  39. package/dist/chunks/chunk-BEO3THWZ.ts.map +7 -0
  40. package/dist/chunks/chunk-C2YD64T6.ts +167 -0
  41. package/dist/chunks/chunk-C2YD64T6.ts.map +7 -0
  42. package/dist/chunks/chunk-C66HLRRZ.ts +72 -0
  43. package/dist/chunks/chunk-C66HLRRZ.ts.map +7 -0
  44. package/dist/chunks/chunk-CFXAA65U.ts +53 -0
  45. package/dist/chunks/chunk-CFXAA65U.ts.map +7 -0
  46. package/dist/chunks/chunk-D34Y5JSL.ts +152 -0
  47. package/dist/chunks/chunk-D34Y5JSL.ts.map +7 -0
  48. package/dist/chunks/chunk-D3DMJSFU.ts +125 -0
  49. package/dist/chunks/chunk-D3DMJSFU.ts.map +7 -0
  50. package/dist/chunks/chunk-DFC3WJP5.ts +3 -0
  51. package/dist/chunks/chunk-DFC3WJP5.ts.map +7 -0
  52. package/dist/chunks/chunk-DH52CVRD.ts +2499 -0
  53. package/dist/chunks/chunk-DH52CVRD.ts.map +7 -0
  54. package/dist/chunks/chunk-DLA5RPFP.ts +50 -0
  55. package/dist/chunks/chunk-DLA5RPFP.ts.map +7 -0
  56. package/dist/chunks/chunk-ES4FIIHZ.ts +50 -0
  57. package/dist/chunks/chunk-ES4FIIHZ.ts.map +7 -0
  58. package/dist/chunks/chunk-ESUMO4TW.ts +55 -0
  59. package/dist/chunks/chunk-ESUMO4TW.ts.map +7 -0
  60. package/dist/chunks/chunk-FIEW5453.ts +77 -0
  61. package/dist/chunks/chunk-FIEW5453.ts.map +7 -0
  62. package/dist/chunks/chunk-FT45DX6E.ts +163 -0
  63. package/dist/chunks/chunk-FT45DX6E.ts.map +7 -0
  64. package/dist/chunks/chunk-G7U6BPP4.ts +137 -0
  65. package/dist/chunks/chunk-G7U6BPP4.ts.map +7 -0
  66. package/dist/chunks/{chunk-5BE6LBDC.ts → chunk-GC5XDUVA.ts} +25 -34
  67. package/dist/chunks/{chunk-5BE6LBDC.ts.map → chunk-GC5XDUVA.ts.map} +3 -3
  68. package/dist/chunks/{chunk-VERMBZGL.ts → chunk-GDA35HWZ.ts} +12 -14
  69. package/dist/chunks/{chunk-VERMBZGL.ts.map → chunk-GDA35HWZ.ts.map} +1 -1
  70. package/dist/chunks/chunk-HOFEC5FH.ts +54 -0
  71. package/dist/chunks/chunk-HOFEC5FH.ts.map +7 -0
  72. package/dist/chunks/{chunk-WE3KJ7JS.ts → chunk-IFJXUHHC.ts} +7 -7
  73. package/dist/chunks/chunk-INUH2UXN.ts +53 -0
  74. package/dist/chunks/chunk-INUH2UXN.ts.map +7 -0
  75. package/dist/chunks/chunk-JPLT2DG6.ts +122 -0
  76. package/dist/chunks/chunk-JPLT2DG6.ts.map +7 -0
  77. package/dist/chunks/chunk-KDTDGAOM.ts +76 -0
  78. package/dist/chunks/chunk-KDTDGAOM.ts.map +7 -0
  79. package/dist/chunks/chunk-LBDUDSHD.ts +3 -0
  80. package/dist/chunks/chunk-LBDUDSHD.ts.map +7 -0
  81. package/dist/chunks/{chunk-VQTYTUBU.ts → chunk-LHQIQIWL.ts} +4 -22
  82. package/dist/chunks/chunk-LHQIQIWL.ts.map +7 -0
  83. package/dist/chunks/chunk-MHERAG42.ts +150 -0
  84. package/dist/chunks/chunk-MHERAG42.ts.map +7 -0
  85. package/dist/chunks/chunk-MS6HLJFR.ts +61 -0
  86. package/dist/chunks/chunk-MS6HLJFR.ts.map +7 -0
  87. package/dist/chunks/{chunk-AXN3B5KC.ts → chunk-MTUR4H7S.ts} +31 -41
  88. package/dist/chunks/chunk-MTUR4H7S.ts.map +7 -0
  89. package/dist/chunks/chunk-NFW5HLKA.ts +84 -0
  90. package/dist/chunks/chunk-NFW5HLKA.ts.map +7 -0
  91. package/dist/chunks/chunk-NFZMKZ2D.ts +345 -0
  92. package/dist/chunks/chunk-NFZMKZ2D.ts.map +7 -0
  93. package/dist/chunks/chunk-OTI4XVCS.ts +618 -0
  94. package/dist/chunks/chunk-OTI4XVCS.ts.map +7 -0
  95. package/dist/chunks/chunk-QIL27OLJ.ts +28 -0
  96. package/dist/chunks/chunk-QIL27OLJ.ts.map +7 -0
  97. package/dist/chunks/chunk-QJTU5SCJ.ts +27 -0
  98. package/dist/chunks/chunk-QJTU5SCJ.ts.map +7 -0
  99. package/dist/chunks/chunk-QNU4RFCN.ts +225 -0
  100. package/dist/chunks/chunk-QNU4RFCN.ts.map +7 -0
  101. package/dist/chunks/chunk-QRSESWT2.ts +26 -0
  102. package/dist/chunks/chunk-QRSESWT2.ts.map +7 -0
  103. package/dist/chunks/chunk-RFJWUIV5.ts +1622 -0
  104. package/dist/chunks/chunk-RFJWUIV5.ts.map +7 -0
  105. package/dist/chunks/chunk-RRFW2UAD.ts +347 -0
  106. package/dist/chunks/chunk-RRFW2UAD.ts.map +7 -0
  107. package/dist/chunks/chunk-SD3D6BTF.ts +3 -0
  108. package/dist/chunks/chunk-SD3D6BTF.ts.map +7 -0
  109. package/dist/chunks/chunk-SPRHJBJC.ts +17 -0
  110. package/dist/chunks/chunk-SPRHJBJC.ts.map +7 -0
  111. package/dist/chunks/chunk-T22OVZSI.ts +347 -0
  112. package/dist/chunks/chunk-T22OVZSI.ts.map +7 -0
  113. package/dist/chunks/chunk-TAOYC2YG.ts +113 -0
  114. package/dist/chunks/chunk-TAOYC2YG.ts.map +7 -0
  115. package/dist/chunks/chunk-U6CORBHU.ts +205 -0
  116. package/dist/chunks/chunk-U6CORBHU.ts.map +7 -0
  117. package/dist/chunks/chunk-ULNEZ53E.ts +105 -0
  118. package/dist/chunks/chunk-ULNEZ53E.ts.map +7 -0
  119. package/dist/chunks/chunk-UPP54ATP.ts +3 -0
  120. package/dist/chunks/chunk-UPP54ATP.ts.map +7 -0
  121. package/dist/chunks/chunk-V66NV2HZ.ts +70 -0
  122. package/dist/chunks/chunk-V66NV2HZ.ts.map +7 -0
  123. package/dist/chunks/chunk-W3YS4Y2Q.ts +545 -0
  124. package/dist/chunks/chunk-W3YS4Y2Q.ts.map +7 -0
  125. package/dist/chunks/chunk-WETDHZAD.ts +815 -0
  126. package/dist/chunks/chunk-WETDHZAD.ts.map +7 -0
  127. package/dist/chunks/chunk-WT2722L4.ts +61 -0
  128. package/dist/chunks/chunk-WT2722L4.ts.map +7 -0
  129. package/dist/chunks/chunk-XHJ3AVIT.ts +12 -0
  130. package/dist/chunks/chunk-XHJ3AVIT.ts.map +7 -0
  131. package/dist/chunks/{chunk-HFMGK6A6.ts → chunk-YLVRV6NM.ts} +5 -5
  132. package/dist/chunks/chunk-YV776ZPN.ts +49 -0
  133. package/dist/chunks/chunk-YV776ZPN.ts.map +7 -0
  134. package/dist/chunks/chunk-YVHXQZIH.ts +411 -0
  135. package/dist/chunks/chunk-YVHXQZIH.ts.map +7 -0
  136. package/dist/chunks/chunk-ZWJMVLQ3.ts +3 -0
  137. package/dist/chunks/chunk-ZWJMVLQ3.ts.map +7 -0
  138. package/dist/chunks/chunk-ZWOKNJDT.ts +25 -0
  139. package/dist/chunks/chunk-ZWOKNJDT.ts.map +7 -0
  140. package/dist/chunks/{command-handler-DWWFIXSC.ts → command-handler-SMARANCT.ts} +128 -155
  141. package/dist/chunks/command-handler-SMARANCT.ts.map +7 -0
  142. package/dist/chunks/{chunk-LNZRNXNQ.ts → config-PUZS2ZBP.ts} +15 -6
  143. package/dist/chunks/config-PUZS2ZBP.ts.map +7 -0
  144. package/dist/chunks/conflict-artifacts-77PI6IXK.ts +33 -0
  145. package/dist/chunks/conflict-artifacts-77PI6IXK.ts.map +7 -0
  146. package/dist/chunks/conflict-review-HHGVL5TP.ts +188 -0
  147. package/dist/chunks/conflict-review-HHGVL5TP.ts.map +7 -0
  148. package/dist/chunks/conflict-review-OO57TGMR.ts +40 -0
  149. package/dist/chunks/conflict-review-OO57TGMR.ts.map +7 -0
  150. package/dist/chunks/continuous-record-QIIFQNKP.ts +277 -0
  151. package/dist/chunks/continuous-record-QIIFQNKP.ts.map +7 -0
  152. package/dist/chunks/debug-check-ETFFIDW5.ts +14 -0
  153. package/dist/chunks/debug-check-ETFFIDW5.ts.map +7 -0
  154. package/dist/chunks/debug-log-QGBO6XHF.ts +17 -0
  155. package/dist/chunks/debug-log-QGBO6XHF.ts.map +7 -0
  156. package/dist/chunks/debug-tool-execution-AIQAGPMJ.ts +95 -0
  157. package/dist/chunks/debug-tool-execution-AIQAGPMJ.ts.map +7 -0
  158. package/dist/chunks/{diff-review-GB4NO53B.ts → diff-review-QRHOHG5C.ts} +12 -5
  159. package/dist/chunks/diff-review-QRHOHG5C.ts.map +7 -0
  160. package/dist/chunks/{file-selection-DGC5UJVI.ts → file-selection-ZEBPDRHG.ts} +33 -16
  161. package/dist/chunks/{file-selection-DGC5UJVI.ts.map → file-selection-ZEBPDRHG.ts.map} +1 -1
  162. package/dist/chunks/git-backend-I2IJ5ULJ.ts +1151 -0
  163. package/dist/chunks/git-backend-I2IJ5ULJ.ts.map +7 -0
  164. package/dist/chunks/initialization-XGYWRNPQ.ts +106 -0
  165. package/dist/chunks/initialization-XGYWRNPQ.ts.map +7 -0
  166. package/dist/chunks/local-diff-review-OGZM3TA7.ts +525 -0
  167. package/dist/chunks/local-diff-review-OGZM3TA7.ts.map +7 -0
  168. package/dist/chunks/local-fields-PIKOEXWR.ts +31 -0
  169. package/dist/chunks/local-fields-PIKOEXWR.ts.map +7 -0
  170. package/dist/chunks/manager-result-dispatcher-72YGSLHL.ts +42 -0
  171. package/dist/chunks/manager-result-dispatcher-72YGSLHL.ts.map +7 -0
  172. package/dist/chunks/{manager-ui-3CQU37XY.ts → manager-ui-5SXPS4SE.ts} +130 -92
  173. package/dist/chunks/manager-ui-5SXPS4SE.ts.map +7 -0
  174. package/dist/chunks/merge-baseline-store-MI7SHGDH.ts +26 -0
  175. package/dist/chunks/merge-baseline-store-MI7SHGDH.ts.map +7 -0
  176. package/dist/chunks/merge-journal-46QC5N7D.ts +38 -0
  177. package/dist/chunks/merge-journal-46QC5N7D.ts.map +7 -0
  178. package/dist/chunks/{merge-review-DXSERTCK.ts → merge-review-RMDYVNBK.ts} +2 -2
  179. package/dist/chunks/remote-selection-ui-4BXJAZUD.ts +41 -0
  180. package/dist/chunks/remote-selection-ui-4BXJAZUD.ts.map +7 -0
  181. package/dist/chunks/s3-backend-ZRMOWH5R.ts +866 -0
  182. package/dist/chunks/s3-backend-ZRMOWH5R.ts.map +7 -0
  183. package/dist/chunks/session-push-55IV4IW3.ts +101 -0
  184. package/dist/chunks/session-push-55IV4IW3.ts.map +7 -0
  185. package/dist/chunks/setup-switch-DXDUBDQI.ts +43 -0
  186. package/dist/chunks/setup-switch-DXDUBDQI.ts.map +7 -0
  187. package/dist/chunks/{setup-wizard-FRIR2EOR.ts → setup-wizard-ICPQERAE.ts} +34 -18
  188. package/dist/chunks/{setup-wizard-FRIR2EOR.ts.map → setup-wizard-ICPQERAE.ts.map} +1 -1
  189. package/dist/chunks/{snapshot-ZUJJZCFW.ts → snapshot-HDARHOQZ.ts} +14 -8
  190. package/dist/chunks/snapshot-HDARHOQZ.ts.map +7 -0
  191. package/dist/chunks/snapshot-LZ6XKFA4.ts +63 -0
  192. package/dist/chunks/snapshot-LZ6XKFA4.ts.map +7 -0
  193. package/dist/chunks/snapshot-transaction-LYR5OFLR.ts +27 -0
  194. package/dist/chunks/snapshot-transaction-LYR5OFLR.ts.map +7 -0
  195. package/dist/chunks/sync-inspection-N6TELULU.ts +29 -0
  196. package/dist/chunks/sync-inspection-N6TELULU.ts.map +7 -0
  197. package/dist/chunks/sync-inspection-PMEXXLDK.ts +26 -0
  198. package/dist/chunks/sync-inspection-PMEXXLDK.ts.map +7 -0
  199. package/dist/chunks/sync-operations-KKSIS2CI.ts +69 -0
  200. package/dist/chunks/sync-operations-KKSIS2CI.ts.map +7 -0
  201. package/dist/chunks/sync-operations-VSMA5GSA.ts +47 -0
  202. package/dist/chunks/sync-operations-VSMA5GSA.ts.map +7 -0
  203. package/dist/chunks/{sync-state-QIT64TKV.ts → sync-state-72ZDKUQW.ts} +13 -5
  204. package/dist/chunks/sync-state-72ZDKUQW.ts.map +7 -0
  205. package/dist/chunks/{sync-state-store-TZE7XDV5.ts → sync-state-store-YTMAZQ3Z.ts} +8 -2
  206. package/dist/chunks/sync-state-store-YTMAZQ3Z.ts.map +7 -0
  207. package/dist/chunks/webdav-backend-3AZOECVQ.ts +948 -0
  208. package/dist/chunks/webdav-backend-3AZOECVQ.ts.map +7 -0
  209. package/dist/index.ts +271 -478
  210. package/dist/index.ts.map +4 -4
  211. package/docs/agent-continuous-hardening.md +3 -1
  212. package/docs/agent-quality-verification.md +3 -1
  213. package/docs/continuous-sync-verification.md +1 -1
  214. package/docs/daemon-migration.md +3 -1
  215. package/docs/daemon-retirement.md +15 -0
  216. package/docs/merge-implementation-audit.md +2 -0
  217. package/docs/settings-merge-audit.md +1 -1
  218. package/docs/tui-contract.md +12 -14
  219. package/package.json +1 -3
  220. package/skills/configure-pi-sync/SKILL.md +14 -60
  221. package/skills/configure-pi-sync/references/configuration.md +38 -46
  222. package/src/backends/backend-factory.ts +2 -2
  223. package/src/backends/backend-identity.ts +2 -2
  224. package/src/backends/backend-types.ts +1 -1
  225. package/src/backends/git/git-backend.ts +2 -2
  226. package/src/backends/git/git-config.ts +2 -2
  227. package/src/backends/git/git-runner.ts +2 -2
  228. package/src/backends/git/git-storage.ts +2 -2
  229. package/src/backends/s3/s3-backend.ts +2 -2
  230. package/src/backends/s3/s3-client.ts +2 -2
  231. package/src/backends/s3/s3-conditions.ts +2 -2
  232. package/src/backends/snapshot-pointer.ts +2 -2
  233. package/src/backends/sync-backend.ts +2 -2
  234. package/src/backends/webdav/webdav-backend.ts +2 -2
  235. package/src/backends/webdav/webdav-client.ts +2 -2
  236. package/src/backends/webdav/webdav-config.ts +2 -2
  237. package/src/commands/command-execution.ts +66 -62
  238. package/src/commands/command-handler.ts +3 -10
  239. package/src/commands/command-types.ts +1 -0
  240. package/src/commands/command.ts +3 -24
  241. package/src/engine/backends/backend-factory.ts +23 -0
  242. package/src/engine/backends/backend-identity.ts +40 -0
  243. package/src/engine/backends/backend-types.ts +75 -0
  244. package/src/engine/backends/git/git-backend.ts +863 -0
  245. package/src/engine/backends/git/git-config.ts +130 -0
  246. package/src/engine/backends/git/git-runner.ts +260 -0
  247. package/src/engine/backends/git/git-storage.ts +295 -0
  248. package/src/engine/backends/publication-encoding.ts +19 -0
  249. package/src/engine/backends/s3/s3-backend.ts +528 -0
  250. package/src/engine/backends/s3/s3-client.ts +398 -0
  251. package/src/engine/backends/s3/s3-conditions.ts +64 -0
  252. package/src/engine/backends/snapshot-pointer.ts +26 -0
  253. package/src/engine/backends/sync-backend.ts +133 -0
  254. package/src/engine/backends/webdav/webdav-backend.ts +691 -0
  255. package/src/engine/backends/webdav/webdav-client.ts +390 -0
  256. package/src/engine/backends/webdav/webdav-config.ts +82 -0
  257. package/src/engine/commands/command-types.ts +37 -0
  258. package/src/engine/debug-check.ts +83 -0
  259. package/src/engine/debug-log.ts +272 -0
  260. package/src/engine/diff-review-types.ts +16 -0
  261. package/src/engine/foreground-transfer.ts +15 -0
  262. package/src/engine/host.ts +95 -0
  263. package/src/engine/paths.ts +90 -0
  264. package/src/engine/record.ts +3 -0
  265. package/src/engine/settings/config-errors.ts +6 -0
  266. package/src/engine/settings/config-file.ts +907 -0
  267. package/src/engine/settings/config.ts +315 -0
  268. package/src/engine/settings/retired-ignore-policy.ts +15 -0
  269. package/src/engine/settings/retired-ignore-recovery.ts +18 -0
  270. package/src/engine/settings/settings-management.ts +261 -0
  271. package/src/engine/settings/settings-store.ts +48 -0
  272. package/src/engine/settings/settings-types.ts +164 -0
  273. package/src/engine/settings/settings-validation.ts +472 -0
  274. package/src/engine/snapshot/session-paths.ts +179 -0
  275. package/src/engine/snapshot/snapshot-apply.ts +443 -0
  276. package/src/engine/snapshot/snapshot-bounds.ts +23 -0
  277. package/src/engine/snapshot/snapshot-capture-limit.ts +110 -0
  278. package/src/engine/snapshot/snapshot-case-replacement.ts +77 -0
  279. package/src/engine/snapshot/snapshot-codec.ts +69 -0
  280. package/src/engine/snapshot/snapshot-difference.ts +25 -0
  281. package/src/engine/snapshot/snapshot-entry-projection.ts +101 -0
  282. package/src/engine/snapshot/snapshot-exclude-safety.ts +203 -0
  283. package/src/engine/snapshot/snapshot-mutation-queues.ts +152 -0
  284. package/src/engine/snapshot/snapshot-paths.ts +11 -0
  285. package/src/engine/snapshot/snapshot-payload.ts +50 -0
  286. package/src/engine/snapshot/snapshot-reviewed-preimages.ts +68 -0
  287. package/src/engine/snapshot/snapshot-root-transition.ts +170 -0
  288. package/src/engine/snapshot/snapshot-transaction-directory.ts +16 -0
  289. package/src/engine/snapshot/snapshot-transaction-images.ts +424 -0
  290. package/src/engine/snapshot/snapshot-transaction-plan.ts +69 -0
  291. package/src/engine/snapshot/snapshot-transaction-policy.ts +278 -0
  292. package/src/engine/snapshot/snapshot-transaction-stage.ts +342 -0
  293. package/src/engine/snapshot/snapshot-transaction-verification.ts +109 -0
  294. package/src/engine/snapshot/snapshot-transaction.ts +961 -0
  295. package/src/engine/snapshot/snapshot-types.ts +67 -0
  296. package/src/engine/snapshot/snapshot.ts +847 -0
  297. package/src/engine/state/json-file.ts +46 -0
  298. package/src/engine/state/lock.ts +421 -0
  299. package/src/engine/state/lockfile-fs.ts +25 -0
  300. package/src/engine/state/merge-baseline-store.ts +213 -0
  301. package/src/engine/state/mutation-directory-sync.ts +33 -0
  302. package/src/engine/state/operation-availability.ts +59 -0
  303. package/src/engine/state/state-directory.ts +245 -0
  304. package/src/engine/state/state-types.ts +26 -0
  305. package/src/engine/state/sync-state-store.ts +77 -0
  306. package/src/engine/sync/agent-candidate.ts +252 -0
  307. package/src/engine/sync/agent-plan.ts +114 -0
  308. package/{dist/daemon/dist/engine/sync/agent-policy.js → src/engine/sync/agent-policy.ts} +5 -3
  309. package/src/engine/sync/agent-refusal-retry.ts +53 -0
  310. package/src/engine/sync/agent-request.ts +17 -0
  311. package/src/engine/sync/agent-runner.ts +208 -0
  312. package/src/engine/sync/agent-store.ts +175 -0
  313. package/src/engine/sync/agent-sync.ts +145 -0
  314. package/src/engine/sync/apply-review.ts +63 -0
  315. package/src/engine/sync/conflict-artifact-ownership.ts +58 -0
  316. package/src/engine/sync/conflict-artifacts.ts +193 -0
  317. package/src/engine/sync/conflict-groups.ts +67 -0
  318. package/src/engine/sync/conflict-preview.ts +54 -0
  319. package/src/engine/sync/conflict-resolution.ts +93 -0
  320. package/src/engine/sync/conflict-retention.ts +71 -0
  321. package/src/engine/sync/conflict-review.ts +95 -0
  322. package/src/engine/sync/content-conflicts.ts +73 -0
  323. package/src/engine/sync/continuous-errors.ts +91 -0
  324. package/src/engine/sync/continuous-lease.ts +213 -0
  325. package/src/engine/sync/continuous-record.ts +255 -0
  326. package/src/engine/sync/continuous-storage.ts +63 -0
  327. package/src/engine/sync/continuous-sync.ts +646 -0
  328. package/src/engine/sync/continuous-watch.ts +123 -0
  329. package/src/engine/sync/diff-review-capture.ts +259 -0
  330. package/src/engine/sync/diff-review-preview.ts +111 -0
  331. package/src/engine/sync/diff-review-store.ts +72 -0
  332. package/src/engine/sync/directional-action.ts +169 -0
  333. package/src/engine/sync/directional-conflict.ts +53 -0
  334. package/src/engine/sync/exclude-policy.ts +88 -0
  335. package/src/engine/sync/field-migration.ts +39 -0
  336. package/src/engine/sync/file-merge-planner.ts +138 -0
  337. package/src/engine/sync/initialization.ts +81 -0
  338. package/src/engine/sync/json-document.ts +179 -0
  339. package/src/engine/sync/local-field-policy.ts +28 -0
  340. package/src/engine/sync/local-fields.ts +171 -0
  341. package/src/engine/sync/merge-acceptance.ts +56 -0
  342. package/src/engine/sync/merge-apply.ts +585 -0
  343. package/src/engine/sync/merge-journal.ts +259 -0
  344. package/src/engine/sync/merge-transfer-error.ts +68 -0
  345. package/src/engine/sync/merged-sync.ts +912 -0
  346. package/src/engine/sync/mutation-owner.ts +22 -0
  347. package/src/engine/sync/package-merge.ts +81 -0
  348. package/src/engine/sync/partial-progress.ts +56 -0
  349. package/src/engine/sync/pull-outcome.ts +16 -0
  350. package/src/engine/sync/push-review.ts +47 -0
  351. package/src/engine/sync/remote-snapshot.ts +185 -0
  352. package/src/engine/sync/resolver-stream.ts +34 -0
  353. package/src/engine/sync/session-merge.ts +192 -0
  354. package/src/engine/sync/session-push.ts +68 -0
  355. package/src/engine/sync/settings-conflicts.ts +64 -0
  356. package/src/engine/sync/settings-merge.ts +118 -0
  357. package/src/engine/sync/signals.ts +8 -0
  358. package/src/engine/sync/startup-recovery-evidence.ts +37 -0
  359. package/src/engine/sync/startup-timings.ts +135 -0
  360. package/src/engine/sync/sync-decision.ts +134 -0
  361. package/src/engine/sync/sync-error-guidance.ts +56 -0
  362. package/src/engine/sync/sync-errors.ts +50 -0
  363. package/src/engine/sync/sync-inspection.ts +61 -0
  364. package/src/engine/sync/sync-loaders.ts +14 -0
  365. package/src/engine/sync/sync-local.ts +117 -0
  366. package/src/engine/sync/sync-mutations.ts +940 -0
  367. package/src/engine/sync/sync-operations.ts +10 -0
  368. package/src/engine/sync/sync-policy.ts +695 -0
  369. package/src/engine/sync/sync-queries.ts +404 -0
  370. package/src/engine/sync/sync-rollback.ts +245 -0
  371. package/src/engine/sync/sync-state.ts +197 -0
  372. package/src/engine/sync/text-merge.ts +132 -0
  373. package/src/engine/sync/transfer-freshness.ts +151 -0
  374. package/src/engine/sync/transfer-size-limits.ts +100 -0
  375. package/src/engine/types.ts +45 -0
  376. package/src/engine/ui/merge-review.ts +14 -0
  377. package/src/engine/ui/merged-sync-summary.ts +111 -0
  378. package/src/engine/ui/sync-format.ts +222 -0
  379. package/src/engine/ui/sync-status.ts +29 -0
  380. package/src/engine/ui/terminal-text.ts +9 -0
  381. package/src/engine/ui/transfer-changes.ts +32 -0
  382. package/src/engine/ui/transfer-review.ts +28 -0
  383. package/src/paths.ts +2 -2
  384. package/src/runtime/identity.ts +152 -0
  385. package/src/runtime/legacy-owner.ts +223 -0
  386. package/src/runtime/lifecycle.ts +17 -0
  387. package/src/runtime/local-host.ts +157 -0
  388. package/src/{daemon/session-presence.ts → runtime/session-presence-binding.ts} +1 -2
  389. package/src/runtime/session-presence.ts +258 -0
  390. package/src/settings/config-errors.ts +2 -2
  391. package/src/settings/config-file.ts +2 -2
  392. package/src/settings/config.ts +2 -2
  393. package/src/settings/settings-management.ts +2 -2
  394. package/src/settings/settings-store.ts +2 -2
  395. package/src/settings/settings-types.ts +1 -1
  396. package/src/settings/settings-validation.ts +2 -2
  397. package/src/snapshot/session-paths.ts +2 -2
  398. package/src/snapshot/snapshot-apply.ts +2 -2
  399. package/src/snapshot/snapshot-case-replacement.ts +2 -2
  400. package/src/snapshot/snapshot-codec.ts +2 -2
  401. package/src/snapshot/snapshot-exclude-safety.ts +2 -2
  402. package/src/snapshot/snapshot-mutation-queues.ts +2 -2
  403. package/src/snapshot/snapshot-paths.ts +2 -2
  404. package/src/snapshot/snapshot-root-transition.ts +2 -2
  405. package/src/snapshot/snapshot-transaction-directory.ts +2 -2
  406. package/src/snapshot/snapshot-transaction-plan.ts +2 -2
  407. package/src/snapshot/snapshot-transaction.ts +2 -2
  408. package/src/snapshot/snapshot-types.ts +1 -1
  409. package/src/snapshot/snapshot.ts +2 -2
  410. package/src/state/json-file.ts +2 -2
  411. package/src/state/lock-policy.ts +2 -2
  412. package/src/state/lock.ts +2 -2
  413. package/src/state/lockfile-fs.ts +2 -2
  414. package/src/state/merge-baseline-store.ts +2 -2
  415. package/src/state/mutation-directory-sync.ts +2 -2
  416. package/src/state/operation-availability.ts +2 -2
  417. package/src/state/state-directory.ts +2 -2
  418. package/src/state/state-types.ts +1 -1
  419. package/src/state/sync-state-store.ts +2 -2
  420. package/src/sync/agent-candidate.ts +2 -2
  421. package/src/sync/agent-plan.ts +2 -2
  422. package/src/sync/agent-policy.ts +2 -2
  423. package/src/sync/agent-refusal-retry.ts +2 -2
  424. package/src/sync/agent-request.ts +2 -2
  425. package/src/sync/agent-runner.ts +2 -2
  426. package/src/sync/agent-store.ts +2 -2
  427. package/src/sync/agent-sync.ts +2 -2
  428. package/src/sync/apply-review.ts +2 -2
  429. package/src/sync/automatic-sync.ts +58 -120
  430. package/src/sync/conflict-artifact-ownership.ts +2 -2
  431. package/src/sync/conflict-artifacts.ts +2 -2
  432. package/src/sync/conflict-groups.ts +2 -2
  433. package/src/sync/conflict-preview.ts +2 -2
  434. package/src/sync/conflict-resolution.ts +2 -2
  435. package/src/sync/conflict-retention.ts +2 -2
  436. package/src/sync/conflict-review.ts +5 -2
  437. package/src/sync/content-conflicts.ts +2 -2
  438. package/src/sync/continuous-errors.ts +2 -2
  439. package/src/sync/continuous-lease.ts +2 -2
  440. package/src/sync/continuous-record.ts +2 -2
  441. package/src/sync/continuous-storage.ts +2 -2
  442. package/src/sync/continuous-sync.ts +2 -2
  443. package/src/sync/continuous-watch.ts +2 -2
  444. package/src/sync/debug-tool-execution.ts +21 -22
  445. package/src/sync/debug-tool.ts +10 -12
  446. package/src/sync/exclude-policy.ts +2 -2
  447. package/src/sync/field-migration.ts +2 -2
  448. package/src/sync/file-merge-planner.ts +2 -2
  449. package/src/sync/json-document.ts +2 -2
  450. package/src/sync/local-diff-review.ts +115 -0
  451. package/src/sync/local-field-policy.ts +2 -2
  452. package/src/sync/local-fields.ts +2 -2
  453. package/src/sync/local-recovery.ts +53 -0
  454. package/src/sync/merge-apply.ts +2 -2
  455. package/src/sync/merge-journal.ts +2 -2
  456. package/src/sync/merge-transfer-error.ts +2 -2
  457. package/src/sync/merged-sync.ts +2 -2
  458. package/src/sync/mutation-owner.ts +2 -2
  459. package/src/sync/package-merge.ts +2 -2
  460. package/src/sync/partial-progress.ts +2 -2
  461. package/src/sync/remote-snapshot.ts +2 -2
  462. package/src/sync/session-merge.ts +2 -2
  463. package/src/sync/settings-conflicts.ts +2 -2
  464. package/src/sync/settings-merge.ts +2 -2
  465. package/src/sync/signals.ts +2 -2
  466. package/src/sync/startup-timings.ts +2 -2
  467. package/src/sync/sync-decision.ts +2 -2
  468. package/src/sync/sync-error-guidance.ts +2 -2
  469. package/src/sync/sync-errors.ts +2 -2
  470. package/src/sync/sync-inspection.ts +46 -11
  471. package/src/sync/sync-local.ts +2 -2
  472. package/src/sync/sync-mutations.ts +2 -2
  473. package/src/sync/sync-operations.ts +143 -33
  474. package/src/sync/sync-policy.ts +2 -2
  475. package/src/sync/sync-queries.ts +2 -2
  476. package/src/sync/sync-state.ts +2 -2
  477. package/src/sync/text-merge.ts +2 -2
  478. package/src/sync-extension.ts +170 -340
  479. package/src/ui/cancellable-operation.ts +1 -1
  480. package/src/ui/diff-review.ts +4 -3
  481. package/src/ui/manager-ui.ts +2 -22
  482. package/dist/chunks/chunk-6YKOHBSC.ts +0 -18
  483. package/dist/chunks/chunk-6YKOHBSC.ts.map +0 -7
  484. package/dist/chunks/chunk-A43CJYG4.ts +0 -26
  485. package/dist/chunks/chunk-A43CJYG4.ts.map +0 -7
  486. package/dist/chunks/chunk-APZVJAEW.ts +0 -34
  487. package/dist/chunks/chunk-APZVJAEW.ts.map +0 -7
  488. package/dist/chunks/chunk-AXN3B5KC.ts.map +0 -7
  489. package/dist/chunks/chunk-GELYN4UC.ts +0 -14
  490. package/dist/chunks/chunk-GELYN4UC.ts.map +0 -7
  491. package/dist/chunks/chunk-HCXPNKPU.ts +0 -1553
  492. package/dist/chunks/chunk-HCXPNKPU.ts.map +0 -7
  493. package/dist/chunks/chunk-IBXEM35O.ts +0 -34
  494. package/dist/chunks/chunk-IBXEM35O.ts.map +0 -7
  495. package/dist/chunks/chunk-LNZRNXNQ.ts.map +0 -7
  496. package/dist/chunks/chunk-NXWHPVXR.ts +0 -26
  497. package/dist/chunks/chunk-NXWHPVXR.ts.map +0 -7
  498. package/dist/chunks/chunk-P4GI7LTT.ts +0 -20
  499. package/dist/chunks/chunk-P4GI7LTT.ts.map +0 -7
  500. package/dist/chunks/chunk-R3SAMXB6.ts +0 -60
  501. package/dist/chunks/chunk-R3SAMXB6.ts.map +0 -7
  502. package/dist/chunks/chunk-R7PN3KIY.ts +0 -22
  503. package/dist/chunks/chunk-R7PN3KIY.ts.map +0 -7
  504. package/dist/chunks/chunk-T3LABNHF.ts +0 -20
  505. package/dist/chunks/chunk-T3LABNHF.ts.map +0 -7
  506. package/dist/chunks/chunk-UMPA5S7X.ts +0 -11
  507. package/dist/chunks/chunk-UMPA5S7X.ts.map +0 -7
  508. package/dist/chunks/chunk-VQTYTUBU.ts.map +0 -7
  509. package/dist/chunks/chunk-ZO52JM4H.ts +0 -15
  510. package/dist/chunks/chunk-ZO52JM4H.ts.map +0 -7
  511. package/dist/chunks/chunk-ZWP6HAYV.ts.map +0 -7
  512. package/dist/chunks/client-debug-F4WFP2YJ.ts +0 -40
  513. package/dist/chunks/client-debug-F4WFP2YJ.ts.map +0 -7
  514. package/dist/chunks/command-handler-DWWFIXSC.ts.map +0 -7
  515. package/dist/chunks/conflict-review-HSERM245.ts +0 -18
  516. package/dist/chunks/conflict-review-HSERM245.ts.map +0 -7
  517. package/dist/chunks/debug-tool-execution-7N4H6K3X.ts +0 -67
  518. package/dist/chunks/debug-tool-execution-7N4H6K3X.ts.map +0 -7
  519. package/dist/chunks/diff-review-6IUIOYST.ts +0 -68
  520. package/dist/chunks/diff-review-6IUIOYST.ts.map +0 -7
  521. package/dist/chunks/diff-review-GB4NO53B.ts.map +0 -7
  522. package/dist/chunks/manager-result-dispatcher-6MOJPLIS.ts +0 -20
  523. package/dist/chunks/manager-ui-3CQU37XY.ts.map +0 -7
  524. package/dist/chunks/ownership-recovery-5KXAMFSL.ts +0 -59
  525. package/dist/chunks/ownership-recovery-5KXAMFSL.ts.map +0 -7
  526. package/dist/chunks/remote-selection-ui-2V53UBHM.ts +0 -19
  527. package/dist/chunks/setup-switch-WSKVGW7L.ts +0 -27
  528. package/dist/chunks/snapshot-ZUJJZCFW.ts.map +0 -7
  529. package/dist/chunks/snapshot-transaction-directory-F46JWRAU.ts +0 -13
  530. package/dist/chunks/snapshot-transaction-directory-F46JWRAU.ts.map +0 -7
  531. package/dist/chunks/state-directory-CMAIF34J.ts +0 -17
  532. package/dist/chunks/sync-inspection-CQDNC542.ts +0 -23
  533. package/dist/chunks/sync-inspection-CQDNC542.ts.map +0 -7
  534. package/dist/chunks/sync-operations-IF7LMWK6.ts +0 -52
  535. package/dist/chunks/sync-operations-IF7LMWK6.ts.map +0 -7
  536. package/dist/chunks/sync-state-QIT64TKV.ts.map +0 -7
  537. package/dist/daemon/LICENSE +0 -21
  538. package/dist/daemon/dist/build-id.json +0 -1
  539. package/dist/daemon/dist/build-version.js +0 -28
  540. package/dist/daemon/dist/child-sdk.mjs +0 -17
  541. package/dist/daemon/dist/cli.js +0 -156
  542. package/dist/daemon/dist/client-transport.js +0 -77
  543. package/dist/daemon/dist/client.js +0 -950
  544. package/dist/daemon/dist/consent.js +0 -304
  545. package/dist/daemon/dist/daemon-debug.js +0 -40
  546. package/dist/daemon/dist/daemon-recovery.js +0 -160
  547. package/dist/daemon/dist/daemon-startup.js +0 -350
  548. package/dist/daemon/dist/daemon-status.js +0 -57
  549. package/dist/daemon/dist/daemon-upgrade-error.js +0 -14
  550. package/dist/daemon/dist/diff-review-binding.js +0 -11
  551. package/dist/daemon/dist/diff-review-protocol.js +0 -85
  552. package/dist/daemon/dist/diff-review-rpc.js +0 -37
  553. package/dist/daemon/dist/diff-review-store.js +0 -89
  554. package/dist/daemon/dist/document.js +0 -6
  555. package/dist/daemon/dist/endpoint.js +0 -91
  556. package/dist/daemon/dist/engine/backends/backend-factory.js +0 -16
  557. package/dist/daemon/dist/engine/backends/backend-identity.js +0 -38
  558. package/dist/daemon/dist/engine/backends/backend-types.js +0 -1
  559. package/dist/daemon/dist/engine/backends/git/git-backend.js +0 -775
  560. package/dist/daemon/dist/engine/backends/git/git-config.js +0 -118
  561. package/dist/daemon/dist/engine/backends/git/git-runner.js +0 -237
  562. package/dist/daemon/dist/engine/backends/git/git-storage.js +0 -227
  563. package/dist/daemon/dist/engine/backends/publication-encoding.js +0 -19
  564. package/dist/daemon/dist/engine/backends/s3/s3-backend.js +0 -453
  565. package/dist/daemon/dist/engine/backends/s3/s3-client.js +0 -362
  566. package/dist/daemon/dist/engine/backends/s3/s3-conditions.js +0 -66
  567. package/dist/daemon/dist/engine/backends/snapshot-pointer.js +0 -22
  568. package/dist/daemon/dist/engine/backends/sync-backend.js +0 -39
  569. package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +0 -605
  570. package/dist/daemon/dist/engine/backends/webdav/webdav-client.js +0 -349
  571. package/dist/daemon/dist/engine/backends/webdav/webdav-config.js +0 -73
  572. package/dist/daemon/dist/engine/commands/command-types.js +0 -1
  573. package/dist/daemon/dist/engine/debug-check.js +0 -59
  574. package/dist/daemon/dist/engine/debug-log.js +0 -252
  575. package/dist/daemon/dist/engine/host.js +0 -20
  576. package/dist/daemon/dist/engine/paths.js +0 -77
  577. package/dist/daemon/dist/engine/settings/config-errors.js +0 -4
  578. package/dist/daemon/dist/engine/settings/config-file.js +0 -784
  579. package/dist/daemon/dist/engine/settings/config.js +0 -246
  580. package/dist/daemon/dist/engine/settings/retired-ignore-policy.js +0 -16
  581. package/dist/daemon/dist/engine/settings/retired-ignore-recovery.js +0 -14
  582. package/dist/daemon/dist/engine/settings/settings-management.js +0 -196
  583. package/dist/daemon/dist/engine/settings/settings-store.js +0 -41
  584. package/dist/daemon/dist/engine/settings/settings-types.js +0 -1
  585. package/dist/daemon/dist/engine/settings/settings-validation.js +0 -390
  586. package/dist/daemon/dist/engine/snapshot/session-paths.js +0 -146
  587. package/dist/daemon/dist/engine/snapshot/snapshot-apply.js +0 -347
  588. package/dist/daemon/dist/engine/snapshot/snapshot-bounds.js +0 -20
  589. package/dist/daemon/dist/engine/snapshot/snapshot-capture-limit.js +0 -99
  590. package/dist/daemon/dist/engine/snapshot/snapshot-case-replacement.js +0 -82
  591. package/dist/daemon/dist/engine/snapshot/snapshot-codec.js +0 -62
  592. package/dist/daemon/dist/engine/snapshot/snapshot-difference.js +0 -13
  593. package/dist/daemon/dist/engine/snapshot/snapshot-entry-projection.js +0 -78
  594. package/dist/daemon/dist/engine/snapshot/snapshot-exclude-safety.js +0 -205
  595. package/dist/daemon/dist/engine/snapshot/snapshot-mutation-queues.js +0 -153
  596. package/dist/daemon/dist/engine/snapshot/snapshot-paths.js +0 -11
  597. package/dist/daemon/dist/engine/snapshot/snapshot-payload.js +0 -42
  598. package/dist/daemon/dist/engine/snapshot/snapshot-reviewed-preimages.js +0 -60
  599. package/dist/daemon/dist/engine/snapshot/snapshot-root-transition.js +0 -138
  600. package/dist/daemon/dist/engine/snapshot/snapshot-transaction-directory.js +0 -16
  601. package/dist/daemon/dist/engine/snapshot/snapshot-transaction-images.js +0 -415
  602. package/dist/daemon/dist/engine/snapshot/snapshot-transaction-plan.js +0 -68
  603. package/dist/daemon/dist/engine/snapshot/snapshot-transaction-policy.js +0 -202
  604. package/dist/daemon/dist/engine/snapshot/snapshot-transaction-stage.js +0 -303
  605. package/dist/daemon/dist/engine/snapshot/snapshot-transaction-verification.js +0 -78
  606. package/dist/daemon/dist/engine/snapshot/snapshot-transaction.js +0 -830
  607. package/dist/daemon/dist/engine/snapshot/snapshot-types.js +0 -3
  608. package/dist/daemon/dist/engine/snapshot/snapshot.js +0 -695
  609. package/dist/daemon/dist/engine/state/json-file.js +0 -49
  610. package/dist/daemon/dist/engine/state/lock.js +0 -399
  611. package/dist/daemon/dist/engine/state/lockfile-fs.js +0 -13
  612. package/dist/daemon/dist/engine/state/merge-baseline-store.js +0 -198
  613. package/dist/daemon/dist/engine/state/mutation-directory-sync.js +0 -34
  614. package/dist/daemon/dist/engine/state/operation-availability.js +0 -40
  615. package/dist/daemon/dist/engine/state/state-directory.js +0 -227
  616. package/dist/daemon/dist/engine/state/state-types.js +0 -1
  617. package/dist/daemon/dist/engine/state/sync-state-store.js +0 -58
  618. package/dist/daemon/dist/engine/sync/agent-candidate.js +0 -207
  619. package/dist/daemon/dist/engine/sync/agent-plan.js +0 -84
  620. package/dist/daemon/dist/engine/sync/agent-refusal-retry.js +0 -39
  621. package/dist/daemon/dist/engine/sync/agent-request.js +0 -13
  622. package/dist/daemon/dist/engine/sync/agent-runner.js +0 -183
  623. package/dist/daemon/dist/engine/sync/agent-store.js +0 -177
  624. package/dist/daemon/dist/engine/sync/agent-sync.js +0 -139
  625. package/dist/daemon/dist/engine/sync/apply-review.js +0 -52
  626. package/dist/daemon/dist/engine/sync/conflict-artifact-ownership.js +0 -53
  627. package/dist/daemon/dist/engine/sync/conflict-artifacts.js +0 -158
  628. package/dist/daemon/dist/engine/sync/conflict-groups.js +0 -76
  629. package/dist/daemon/dist/engine/sync/conflict-preview.js +0 -53
  630. package/dist/daemon/dist/engine/sync/conflict-resolution.js +0 -53
  631. package/dist/daemon/dist/engine/sync/conflict-retention.js +0 -61
  632. package/dist/daemon/dist/engine/sync/conflict-review.js +0 -73
  633. package/dist/daemon/dist/engine/sync/content-conflicts.js +0 -70
  634. package/dist/daemon/dist/engine/sync/continuous-errors.js +0 -72
  635. package/dist/daemon/dist/engine/sync/continuous-lease.js +0 -206
  636. package/dist/daemon/dist/engine/sync/continuous-record.js +0 -199
  637. package/dist/daemon/dist/engine/sync/continuous-storage.js +0 -59
  638. package/dist/daemon/dist/engine/sync/continuous-sync.js +0 -549
  639. package/dist/daemon/dist/engine/sync/continuous-watch.js +0 -137
  640. package/dist/daemon/dist/engine/sync/diff-review-capture.js +0 -210
  641. package/dist/daemon/dist/engine/sync/diff-review-preview.js +0 -114
  642. package/dist/daemon/dist/engine/sync/directional-action.js +0 -101
  643. package/dist/daemon/dist/engine/sync/directional-conflict.js +0 -29
  644. package/dist/daemon/dist/engine/sync/exclude-policy.js +0 -86
  645. package/dist/daemon/dist/engine/sync/field-migration.js +0 -20
  646. package/dist/daemon/dist/engine/sync/file-merge-planner.js +0 -123
  647. package/dist/daemon/dist/engine/sync/initialization.js +0 -81
  648. package/dist/daemon/dist/engine/sync/json-document.js +0 -172
  649. package/dist/daemon/dist/engine/sync/local-field-policy.js +0 -26
  650. package/dist/daemon/dist/engine/sync/local-fields.js +0 -161
  651. package/dist/daemon/dist/engine/sync/merge-acceptance.js +0 -29
  652. package/dist/daemon/dist/engine/sync/merge-apply.js +0 -530
  653. package/dist/daemon/dist/engine/sync/merge-journal.js +0 -204
  654. package/dist/daemon/dist/engine/sync/merge-transfer-error.js +0 -64
  655. package/dist/daemon/dist/engine/sync/merged-sync.js +0 -655
  656. package/dist/daemon/dist/engine/sync/mutation-owner.js +0 -18
  657. package/dist/daemon/dist/engine/sync/package-merge.js +0 -82
  658. package/dist/daemon/dist/engine/sync/partial-progress.js +0 -41
  659. package/dist/daemon/dist/engine/sync/push-review.js +0 -18
  660. package/dist/daemon/dist/engine/sync/remote-snapshot.js +0 -119
  661. package/dist/daemon/dist/engine/sync/resolver-stream.js +0 -34
  662. package/dist/daemon/dist/engine/sync/session-merge.js +0 -178
  663. package/dist/daemon/dist/engine/sync/session-push.js +0 -56
  664. package/dist/daemon/dist/engine/sync/settings-conflicts.js +0 -56
  665. package/dist/daemon/dist/engine/sync/settings-merge.js +0 -93
  666. package/dist/daemon/dist/engine/sync/signals.js +0 -8
  667. package/dist/daemon/dist/engine/sync/startup-bootstrap.js +0 -105
  668. package/dist/daemon/dist/engine/sync/startup-recovery-evidence.js +0 -37
  669. package/dist/daemon/dist/engine/sync/startup-timings.js +0 -116
  670. package/dist/daemon/dist/engine/sync/sync-decision.js +0 -81
  671. package/dist/daemon/dist/engine/sync/sync-error-guidance.js +0 -74
  672. package/dist/daemon/dist/engine/sync/sync-errors.js +0 -38
  673. package/dist/daemon/dist/engine/sync/sync-inspection.js +0 -42
  674. package/dist/daemon/dist/engine/sync/sync-loaders.js +0 -8
  675. package/dist/daemon/dist/engine/sync/sync-local.js +0 -96
  676. package/dist/daemon/dist/engine/sync/sync-mutations.js +0 -723
  677. package/dist/daemon/dist/engine/sync/sync-operations.js +0 -3
  678. package/dist/daemon/dist/engine/sync/sync-policy.js +0 -530
  679. package/dist/daemon/dist/engine/sync/sync-queries.js +0 -316
  680. package/dist/daemon/dist/engine/sync/sync-rollback.js +0 -180
  681. package/dist/daemon/dist/engine/sync/sync-state.js +0 -119
  682. package/dist/daemon/dist/engine/sync/text-merge.js +0 -124
  683. package/dist/daemon/dist/engine/sync/transfer-freshness.js +0 -79
  684. package/dist/daemon/dist/engine/sync/transfer-size-limits.js +0 -88
  685. package/dist/daemon/dist/engine/types.js +0 -2
  686. package/dist/daemon/dist/engine/ui/merge-review.js +0 -7
  687. package/dist/daemon/dist/engine/ui/merged-sync-summary.js +0 -86
  688. package/dist/daemon/dist/engine/ui/sync-format.js +0 -123
  689. package/dist/daemon/dist/engine/ui/sync-status.js +0 -30
  690. package/dist/daemon/dist/engine/ui/terminal-text.js +0 -9
  691. package/dist/daemon/dist/engine/ui/transfer-changes.js +0 -24
  692. package/dist/daemon/dist/engine/ui/transfer-review.js +0 -18
  693. package/dist/daemon/dist/engine-service.js +0 -506
  694. package/dist/daemon/dist/foreground-queue-outcome.js +0 -9
  695. package/dist/daemon/dist/foreground-transfer.js +0 -10
  696. package/dist/daemon/dist/identity.js +0 -275
  697. package/dist/daemon/dist/idle-exit.js +0 -77
  698. package/dist/daemon/dist/index.js +0 -27
  699. package/dist/daemon/dist/legacy-consent-guard.js +0 -34
  700. package/dist/daemon/dist/lifecycle-log.js +0 -54
  701. package/dist/daemon/dist/lifecycle.js +0 -21
  702. package/dist/daemon/dist/model-signature.js +0 -7
  703. package/dist/daemon/dist/paged-review.js +0 -177
  704. package/dist/daemon/dist/participant-admission.js +0 -30
  705. package/dist/daemon/dist/participant-ledger.js +0 -149
  706. package/dist/daemon/dist/protocol.js +0 -108
  707. package/dist/daemon/dist/resolver-host.js +0 -78
  708. package/dist/daemon/dist/server.js +0 -1374
  709. package/dist/daemon/dist/service-host.js +0 -260
  710. package/dist/daemon/dist/session-presence.js +0 -207
  711. package/dist/daemon/dist/state-wait-jobs.js +0 -23
  712. package/dist/daemon/dist/state-wait.js +0 -34
  713. package/dist/daemon/dist/upgrade-repair.js +0 -55
  714. package/dist/daemon/package.json +0 -3
  715. package/dist/package.json +0 -6
  716. package/src/daemon/apply-gate.ts +0 -146
  717. package/src/daemon/client-debug.ts +0 -50
  718. package/src/daemon/daemon-status-ui.ts +0 -64
  719. package/src/daemon/diff-review.ts +0 -68
  720. package/src/daemon/directional-recovery.ts +0 -106
  721. package/src/daemon/ownership-recovery.ts +0 -50
  722. package/src/daemon/pi-client.ts +0 -1330
  723. package/src/daemon/queue-release-ui.ts +0 -88
  724. package/src/daemon/recovery.ts +0 -103
  725. package/src/daemon/startup-bootstrap-client.ts +0 -26
  726. /package/dist/chunks/{manager-result-dispatcher-6MOJPLIS.ts.map → chunk-3GL7LBNB.ts.map} +0 -0
  727. /package/dist/chunks/{remote-selection-ui-2V53UBHM.ts.map → chunk-3PFWVSV3.ts.map} +0 -0
  728. /package/dist/chunks/{setup-switch-WSKVGW7L.ts.map → chunk-53IKSWLZ.ts.map} +0 -0
  729. /package/dist/chunks/{state-directory-CMAIF34J.ts.map → chunk-A3NEEVNA.ts.map} +0 -0
  730. /package/dist/chunks/{sync-state-store-TZE7XDV5.ts.map → chunk-AITZUACB.ts.map} +0 -0
  731. /package/dist/chunks/{chunk-WE3KJ7JS.ts.map → chunk-IFJXUHHC.ts.map} +0 -0
  732. /package/dist/chunks/{chunk-HFMGK6A6.ts.map → chunk-YLVRV6NM.ts.map} +0 -0
  733. /package/dist/chunks/{merge-review-DXSERTCK.ts.map → merge-review-RMDYVNBK.ts.map} +0 -0
  734. /package/{dist/daemon/dist/engine/state/lock-policy.js → src/engine/state/lock-policy.ts} +0 -0
@@ -1,950 +0,0 @@
1
- import { createHash, randomUUID } from "node:crypto";
2
- import { setTimeout as delay } from "node:timers/promises";
3
- import { DaemonError, requestDaemon } from "./client-transport.js";
4
- import { sameDiffReviewBinding } from "./diff-review-binding.js";
5
- import { DIFF_REVIEW_REQUEST_MS, isDiffReviewId, parseDiffReviewInventory, readDiffReviewPreview, } from "./diff-review-protocol.js";
6
- import { isForegroundDirection, isForegroundQueueOutcome } from "./foreground-queue-outcome.js";
7
- import { canonicalRootGuard, readProcessBirth } from "./identity.js";
8
- import { withCleanup } from "./lifecycle.js";
9
- import { MAX_REVIEW_BYTES, OWNERSHIP_CLEANUP_REQUIRED, operationPrefix, REVIEW_PAGE_CHARS, record, UNKNOWN_JOB_RESULT, } from "./protocol.js";
10
- import { STATE_WAIT_FAILURE_LIMIT, stateWaitJobs, stateWaitResult } from "./state-wait-jobs.js";
11
- export { DaemonError, hello, requestDaemon } from "./client-transport.js";
12
- export { acquireStartupLock, checkUpgradeConsent, ensureDaemon, findDaemon, finishUpgrade, stopDaemon, waitForDaemonExit, } from "./daemon-startup.js";
13
- const MAX_COMPLETED_CALLBACKS = 4096;
14
- const RELEASE_ATTEMPT_MS = 2_000;
15
- const RELEASE_BUDGET_MS = 25_000;
16
- const RELEASE_MAX_ATTEMPTS = 20;
17
- const FOREGROUND_RPC_MS = 3_000;
18
- const FOREGROUND_DRAIN_MS = 30_000;
19
- const FOREGROUND_RECOVERY_MS = 45_000;
20
- const FOREGROUND_UNKNOWN_RESULT = "The daemon's transfer result could not be verified. Changes may have been made; recovery evidence was retained.";
21
- const TRANSIENT_RELEASE_ERRORS = new Set(["ECONNRESET", "ECONNREFUSED", "EPIPE", "ENOENT", "ETIMEDOUT", "EAGAIN"]);
22
- export class DaemonConnection {
23
- paths;
24
- identity;
25
- facts;
26
- options;
27
- cursor = 0;
28
- controller = new AbortController();
29
- callbacks = new Map();
30
- callbackIO = new AbortController();
31
- diffReviewIO;
32
- diffReviewPaused = false;
33
- diffReviewBinding;
34
- callbackTasks = new Set();
35
- updates = Promise.resolve();
36
- attached = false;
37
- admitting = false;
38
- observedContact;
39
- contactRevision = 0;
40
- lifecycleRevision = 0;
41
- resuming;
42
- resumeUncertain = false;
43
- pendingJobs = new Set();
44
- foregroundRecovery;
45
- observesState = false;
46
- stateRevision;
47
- terminalJobs = new Set();
48
- jobWaiters = new Map();
49
- uncertain = false;
50
- reportedError = false;
51
- commits = new Map();
52
- completedCallbacks = new Set();
53
- // Keep drain answers deduplicated even after the lifetime callback ledger fills.
54
- // The daemon limits each peer to 64 pending callbacks. A newer snapshot retires
55
- // releases it no longer lists, and older snapshots cannot add them back.
56
- completedReleases = new Set();
57
- pausing;
58
- disposing;
59
- polling;
60
- closed = false;
61
- constructor(paths, identity, facts, options) {
62
- this.paths = paths;
63
- this.identity = identity;
64
- this.facts = facts;
65
- this.options = options;
66
- }
67
- setFacts(facts) {
68
- const changed = !sameDiffReviewBinding(this.facts, facts);
69
- for (const key of Object.keys(this.facts))
70
- if (!Object.hasOwn(facts, key))
71
- delete this.facts[key];
72
- Object.assign(this.facts, facts);
73
- this.diffReviewBinding = { ...facts };
74
- if (changed)
75
- this.retireDiffReviewIO();
76
- }
77
- /** Latest owner observation, or undefined if contact is unsupported or not observed. */
78
- get contactState() {
79
- return this.observedContact;
80
- }
81
- /** An uncertain attempt must not be retried or turned into a new attach. */
82
- get contactResumeState() {
83
- return this.resumeUncertain ? "uncertain" : this.resuming ? "running" : "idle";
84
- }
85
- /** Original submitted jobs must finish (or be reconciled) before repairing contact. */
86
- get hasPendingWork() {
87
- return this.pendingJobs.size > 0 || this.uncertain || this.foregroundRecovery !== undefined;
88
- }
89
- async attach(signal) {
90
- if (this.closed ||
91
- this.hasPendingWork ||
92
- this.contactResumeState !== "idle" ||
93
- this.admitting ||
94
- this.pausing ||
95
- this.disposing)
96
- throw new Error("Daemon client is unavailable; reconnect after draining work.");
97
- this.admitting = true;
98
- this.diffReviewPaused = false;
99
- this.diffReviewBinding = undefined;
100
- this.retireDiffReviewIO();
101
- this.lifecycleRevision++;
102
- this.contactRevision++;
103
- const facts = { ...this.facts };
104
- const request = requestDaemon(this.paths, this.identity, "attach", facts, signal ? AbortSignal.any([signal, this.controller.signal]) : this.controller.signal, this.options.mergeReview ? { reviewDetails: 1 } : undefined);
105
- // Poll during attach: stopping a previous controller may need release answers
106
- // from this reattached participant before the attach response can complete.
107
- this.polling ??= this.poll();
108
- let admitted = false;
109
- try {
110
- const result = await request;
111
- admitted = true;
112
- if (this.closed || this.disposing)
113
- throw new Error("Daemon client closed during attach.");
114
- this.publishContact(this.consume(result));
115
- this.observesState = record(result) && result.stateWait === 1;
116
- this.stateRevision = undefined;
117
- this.terminalJobs.clear();
118
- this.attached = true;
119
- this.diffReviewBinding = facts;
120
- return this;
121
- }
122
- catch (error) {
123
- return withCleanup(async () => {
124
- throw error;
125
- }, async () => {
126
- try {
127
- await this.dispose();
128
- }
129
- catch (cleanupError) {
130
- if (!admitted &&
131
- !this.attached &&
132
- this.closed &&
133
- !this.callbacks.size &&
134
- !this.callbackTasks.size &&
135
- !this.completedCallbacks.size &&
136
- error instanceof DaemonError &&
137
- error.remote.name === "DaemonStoppingError") {
138
- // The fenced first attach owned no grants, and local tasks have drained.
139
- // Keep its retry marker even if the owner closes the cleanup transport.
140
- error.cause = cleanupError;
141
- return;
142
- }
143
- throw cleanupError;
144
- }
145
- });
146
- }
147
- finally {
148
- this.admitting = false;
149
- }
150
- }
151
- async update(facts) {
152
- const lifecycle = this.lifecycleRevision;
153
- if (this.admitting || this.pausing || this.disposing)
154
- throw new Error("Daemon client is changing; wait before updating facts.");
155
- facts = structuredClone(facts);
156
- const update = this.updates.then(async () => {
157
- if (this.closed || this.uncertain || this.resumeUncertain || lifecycle !== this.lifecycleRevision)
158
- throw new Error("Daemon client is unavailable; reconnect after draining work.");
159
- const revision = this.contactRevision;
160
- if (!this.diffReviewBinding || !sameDiffReviewBinding(this.diffReviewBinding, facts)) {
161
- this.diffReviewBinding = undefined;
162
- this.retireDiffReviewIO();
163
- }
164
- let result;
165
- try {
166
- result = await requestDaemon(this.paths, this.identity, "update", { facts }, this.controller.signal);
167
- }
168
- catch (error) {
169
- if (this.attached &&
170
- revision === this.contactRevision &&
171
- this.sameClient(facts) &&
172
- error instanceof DaemonError &&
173
- error.remote.name === "ClientContactExpiredError")
174
- this.publishContact("expired");
175
- throw error;
176
- }
177
- if (this.closed)
178
- throw new Error("Daemon client closed during update.");
179
- if (revision !== this.contactRevision)
180
- throw new Error("Daemon client changed during update.");
181
- const contact = this.consume(result);
182
- if (revision !== this.contactRevision)
183
- throw new Error("Daemon client changed during update.");
184
- this.setFacts(facts);
185
- this.publishContact(contact);
186
- });
187
- this.updates = update.catch(() => { });
188
- return update;
189
- }
190
- /** Resume this participant without replacing its callbacks, jobs, or polling. */
191
- async resumeContact(facts, signal) {
192
- signal?.throwIfAborted();
193
- if (this.contactResumeState !== "idle")
194
- throw new Error("Daemon contact resume is running or uncertain.");
195
- const check = () => {
196
- if (!this.attached || this.admitting || this.pausing || this.disposing || this.closed || this.hasPendingWork)
197
- throw new Error("Daemon client is unavailable; reconnect after draining work.");
198
- if (!this.sameClient(facts) || this.contactState !== "expired")
199
- throw new Error("No confirmed contact expiry for this daemon client.");
200
- };
201
- facts = structuredClone(facts);
202
- check();
203
- const resume = new AbortController();
204
- this.resuming = resume;
205
- const ownedSignal = signal ? AbortSignal.any([signal, resume.signal]) : resume.signal;
206
- let sent = false;
207
- const attempt = this.updates.then(async () => {
208
- ownedSignal.throwIfAborted();
209
- check();
210
- sent = true;
211
- const reply = await requestDaemon(this.paths, this.identity, "resume-contact", facts, ownedSignal);
212
- ownedSignal.throwIfAborted();
213
- const contact = this.consume(reply);
214
- ownedSignal.throwIfAborted();
215
- if (contact !== "active")
216
- throw new Error("Daemon did not confirm resumed contact.");
217
- this.setFacts(facts);
218
- this.publishContact(contact);
219
- });
220
- this.updates = attempt.catch(() => { });
221
- // Reject a queued repair on cancellation even if the earlier update has not finished.
222
- const cancellation = Promise.withResolvers();
223
- const abort = () => cancellation.reject(ownedSignal.reason);
224
- ownedSignal.addEventListener("abort", abort, { once: true });
225
- try {
226
- await Promise.race([attempt, cancellation.promise]);
227
- }
228
- catch (error) {
229
- if (sent) {
230
- // The protocol does not distinguish definite pre-publication refusal from a lost acknowledgement.
231
- this.resumeUncertain = true;
232
- for (const { controller, kind } of this.callbacks.values())
233
- if (kind !== "queue-release")
234
- controller.abort();
235
- }
236
- throw error;
237
- }
238
- finally {
239
- this.resuming = undefined;
240
- ownedSignal.removeEventListener("abort", abort);
241
- }
242
- }
243
- sameClient(facts) {
244
- return facts.id === this.facts.id && facts.pid === this.facts.pid && facts.generation === this.facts.generation;
245
- }
246
- async run(operation, payload, signal, onCommit, onSubmit) {
247
- if (this.closed ||
248
- this.uncertain ||
249
- this.foregroundRecovery ||
250
- this.contactResumeState !== "idle" ||
251
- this.pausing ||
252
- this.disposing ||
253
- this.contactState === "expired" ||
254
- this.contactState === "inactive")
255
- throw new Error("Daemon client is unavailable; confirm contact and drain work before submitting.");
256
- signal?.throwIfAborted();
257
- if (operation === "diff.review" && !this.hasConfirmedDiffReviewBinding())
258
- throw new Error("The daemon file review session is unconfirmed. Update session facts or reload Pi.");
259
- const { paths, identity } = this;
260
- const id = `${operationPrefix(identity)}${randomUUID()}`;
261
- const jobParams = { id, client: this.facts.id };
262
- const transport = this.controller.signal;
263
- const foreground = isForegroundDirection(operation);
264
- const assertRoot = foreground ? canonicalRootGuard(paths.root) : undefined;
265
- const generation = this.facts.generation;
266
- let birth;
267
- const rpc = async (method, params) => {
268
- if (!foreground)
269
- return requestDaemon(paths, identity, method, params, transport);
270
- const timeout = method === "cancel" ? FOREGROUND_DRAIN_MS : FOREGROUND_RPC_MS;
271
- const attempt = () => requestDaemon(paths, identity, method, params, AbortSignal.any([transport, AbortSignal.timeout(timeout)]));
272
- try {
273
- return await attempt();
274
- }
275
- catch (error) {
276
- if (transport.aborted ||
277
- error instanceof DaemonError ||
278
- method === "cancel" ||
279
- (method === "submit" && signal?.aborted))
280
- throw error;
281
- return attempt().catch((retryError) => {
282
- if (method === "submit")
283
- throw new AggregateError([error, retryError], FOREGROUND_UNKNOWN_RESULT);
284
- throw retryError;
285
- });
286
- }
287
- };
288
- this.pendingJobs.add(id);
289
- const abort = () => {
290
- void requestDaemon(paths, identity, "cancel", jobParams, transport).catch(() => { });
291
- };
292
- let terminal = false;
293
- const finish = (job) => {
294
- terminal = true;
295
- if (job.phase === "failed")
296
- throw new DaemonError(job.error ?? { name: "Error", message: "Daemon operation failed." });
297
- if (!foreground)
298
- signal?.throwIfAborted();
299
- if (operation === "diff.review") {
300
- try {
301
- return parseDiffReviewInventory(job.result);
302
- }
303
- catch (error) {
304
- abort();
305
- throw error;
306
- }
307
- }
308
- if (assertRoot && isForegroundQueueOutcome(job.result))
309
- this.foregroundRecovery = {
310
- job: id,
311
- generation,
312
- birth,
313
- assertRoot,
314
- };
315
- return job.result;
316
- };
317
- if (onCommit)
318
- this.commits.set(id, { notify: onCommit, signal });
319
- signal?.addEventListener("abort", abort, { once: true });
320
- if (signal?.aborted)
321
- abort();
322
- return withCleanup(async () => {
323
- try {
324
- onSubmit?.(id);
325
- }
326
- catch { }
327
- if (foreground) {
328
- birth = await readProcessBirth(identity.pid);
329
- signal?.throwIfAborted();
330
- transport.throwIfAborted();
331
- assertRoot?.();
332
- }
333
- let lostSubmit = false;
334
- try {
335
- await rpc("submit", { ...jobParams, operation, payload });
336
- }
337
- catch (error) {
338
- if (!foreground || error instanceof DaemonError || transport.aborted)
339
- throw error;
340
- lostSubmit = true;
341
- }
342
- let terminalObserved = this.observesState && !lostSubmit;
343
- if (terminalObserved && !this.terminalJobs.has(id)) {
344
- const completion = Promise.withResolvers();
345
- this.jobWaiters.set(id, completion);
346
- const keepAlive = setInterval(() => { }, 30_000);
347
- try {
348
- terminalObserved = (await completion.promise) === "terminal";
349
- }
350
- finally {
351
- this.jobWaiters.delete(id);
352
- clearInterval(keepAlive);
353
- }
354
- }
355
- while (!this.closed) {
356
- let reply;
357
- try {
358
- reply = await rpc("poll", { client: jobParams.client, cursor: this.cursor, job: id });
359
- }
360
- catch (error) {
361
- if (foreground && !transport.aborted) {
362
- const drained = await rpc("cancel", jobParams).catch(() => undefined);
363
- const job = drained;
364
- if (job?.id === id && (job.phase === "done" || job.phase === "failed"))
365
- return finish(job);
366
- this.markWorkUncertain();
367
- throw new Error(FOREGROUND_UNKNOWN_RESULT, { cause: error });
368
- }
369
- if (error instanceof DaemonError && error.message === UNKNOWN_JOB_RESULT)
370
- this.markWorkUncertain();
371
- throw error;
372
- }
373
- const job = record(reply) ? reply.job : undefined;
374
- const missing = terminalObserved && (job?.id !== id || (job.phase !== "done" && job.phase !== "failed"));
375
- if (missing)
376
- this.markWorkUncertain();
377
- this.consume(reply);
378
- if (missing)
379
- throw new Error(foreground ? FOREGROUND_UNKNOWN_RESULT : UNKNOWN_JOB_RESULT);
380
- if (job?.id === id && (job.phase === "done" || job.phase === "failed"))
381
- return finish(job);
382
- await this.wait(25, true);
383
- }
384
- throw new Error("Daemon client closed before operation completed.");
385
- }, async () => {
386
- signal?.removeEventListener("abort", abort);
387
- this.commits.delete(id);
388
- if (!terminal && !this.closed) {
389
- for (const callback of this.callbacks.values())
390
- if (callback.job === id && !callback.kind.startsWith("queue-"))
391
- callback.controller.abort();
392
- try {
393
- if (foreground) {
394
- if (!this.uncertain)
395
- await rpc("cancel", jobParams);
396
- }
397
- else
398
- await requestDaemon(paths, identity, "cancel", jobParams);
399
- }
400
- catch (error) {
401
- this.markWorkUncertain();
402
- throw new Error(foreground
403
- ? FOREGROUND_UNKNOWN_RESULT
404
- : "Operation outcome is uncertain; reload to reconnect and reconcile, never replay the write.", { cause: error });
405
- }
406
- }
407
- })
408
- .catch((error) => {
409
- if (operation !== "diff.review")
410
- throw error;
411
- if (error instanceof DaemonError && error.remote.properties?.code === OWNERSHIP_CLEANUP_REQUIRED) {
412
- throw new DaemonError({
413
- name: "Error",
414
- message: "Daemon ownership cleanup must be confirmed before opening a file review.",
415
- properties: { code: OWNERSHIP_CLEANUP_REQUIRED },
416
- });
417
- }
418
- if (this.uncertain)
419
- throw new Error("The daemon diff review outcome is uncertain. Reload Pi to reconnect before opening a review.");
420
- signal?.throwIfAborted();
421
- if (error instanceof DaemonError && error.message === "Unsupported engine operation.")
422
- throw new DaemonError({ name: "Error", message: "Unsupported engine operation." });
423
- throw new Error("Could not open the daemon diff review. Check the connection and try again.");
424
- })
425
- .finally(() => {
426
- this.pendingJobs.delete(id);
427
- });
428
- }
429
- retireDiffReviewIO() {
430
- const io = this.diffReviewIO;
431
- this.diffReviewIO = undefined;
432
- io?.abort();
433
- }
434
- hasConfirmedDiffReviewBinding() {
435
- return this.diffReviewBinding !== undefined && sameDiffReviewBinding(this.diffReviewBinding, this.facts);
436
- }
437
- canReadDiffReview() {
438
- return (this.attached &&
439
- !this.admitting &&
440
- !this.closed &&
441
- !this.pausing &&
442
- !this.diffReviewPaused &&
443
- this.hasConfirmedDiffReviewBinding() &&
444
- !this.disposing &&
445
- !this.uncertain &&
446
- this.contactResumeState === "idle" &&
447
- this.contactState !== "expired" &&
448
- this.contactState !== "inactive" &&
449
- this.facts.mode === "tui" &&
450
- this.facts.hasUI);
451
- }
452
- async diffReviewRequest(method, id, fileId, signal, stale, decode) {
453
- signal?.throwIfAborted();
454
- if (!isDiffReviewId(id) || (method === "diff-review-read" && !isDiffReviewId(fileId)))
455
- throw new Error("Invalid diff review identity.");
456
- if (!this.canReadDiffReview())
457
- return stale;
458
- const binding = { ...this.facts };
459
- this.diffReviewIO ??= new AbortController();
460
- const io = this.diffReviewIO;
461
- const current = () => this.diffReviewIO === io && this.canReadDiffReview() && sameDiffReviewBinding(binding, this.facts);
462
- const owned = AbortSignal.any([
463
- this.controller.signal,
464
- io.signal,
465
- AbortSignal.timeout(DIFF_REVIEW_REQUEST_MS),
466
- ...(signal ? [signal] : []),
467
- ]);
468
- let reply;
469
- try {
470
- reply = await requestDaemon(this.paths, this.identity, method, { client: binding.id, generation: binding.generation, id, fileId }, owned);
471
- owned.throwIfAborted();
472
- }
473
- catch {
474
- signal?.throwIfAborted();
475
- if (!current())
476
- return stale;
477
- throw new Error("Daemon file review request failed. Try again or reopen the review.");
478
- }
479
- return current() ? decode(reply) : stale;
480
- }
481
- readDiffReview(id, fileId, signal) {
482
- return this.diffReviewRequest("diff-review-read", id, fileId, signal, { kind: "stale" }, readDiffReviewPreview);
483
- }
484
- closeDiffReview(id, signal) {
485
- return this.diffReviewRequest("diff-review-close", id, undefined, signal, undefined, (reply) => {
486
- if (reply !== true)
487
- throw new Error("Invalid daemon diff review release acknowledgement.");
488
- });
489
- }
490
- canRecoverForeground(job) {
491
- return !this.foregroundRecovery?.attempted && this.ownsForegroundRecovery(job);
492
- }
493
- ownsForegroundRecovery(job) {
494
- const target = this.foregroundRecovery;
495
- return (!!target &&
496
- target.job === job &&
497
- target.generation === this.facts.generation &&
498
- this.attached &&
499
- !this.closed &&
500
- !this.admitting &&
501
- !this.disposing &&
502
- !this.pausing &&
503
- this.pendingJobs.size === 0 &&
504
- !this.uncertain &&
505
- this.contactResumeState === "idle");
506
- }
507
- async recoverForeground(job, signal) {
508
- signal.throwIfAborted();
509
- const target = this.foregroundRecovery;
510
- if (!target || !this.canRecoverForeground(job))
511
- throw new Error("The current Pi session could not verify a completed transfer for daemon recovery.");
512
- target.assertRoot();
513
- target.attempted = true;
514
- const facts = { ...this.facts };
515
- const lifecycle = this.lifecycleRevision;
516
- const owned = AbortSignal.any([signal, this.controller.signal, AbortSignal.timeout(FOREGROUND_RECOVERY_MS)]);
517
- const { stopDaemonAfterForegroundQueueFailure } = await import("./daemon-recovery.js");
518
- owned.throwIfAborted();
519
- if (lifecycle !== this.lifecycleRevision ||
520
- !sameDiffReviewBinding(facts, this.facts) ||
521
- this.foregroundRecovery !== target ||
522
- !this.ownsForegroundRecovery(job))
523
- throw new Error("The current Pi session could not verify a completed transfer for daemon recovery.");
524
- target.assertRoot();
525
- await stopDaemonAfterForegroundQueueFailure(this.paths, this.identity, { ...target, client: facts.id }, owned);
526
- await this.closeLocal();
527
- target.assertRoot();
528
- }
529
- markWorkUncertain() {
530
- this.uncertain = true;
531
- this.retireDiffReviewIO();
532
- for (const callback of this.callbacks.values())
533
- if (callback.kind !== "queue-release")
534
- callback.controller.abort();
535
- }
536
- publishContact(contact) {
537
- this.contactRevision++;
538
- this.observedContact = contact;
539
- if (contact === "expired" || contact === "inactive")
540
- this.retireDiffReviewIO();
541
- }
542
- consume(reply) {
543
- if (!record(reply) ||
544
- typeof reply.cursor !== "number" ||
545
- !Number.isSafeInteger(reply.cursor) ||
546
- reply.cursor < 0 ||
547
- !Array.isArray(reply.callbacks) ||
548
- !Array.isArray(reply.events))
549
- throw new Error("Invalid daemon poll response.");
550
- const { contact } = reply;
551
- if (contact !== undefined && contact !== "active" && contact !== "expired" && contact !== "inactive")
552
- throw new Error("Invalid daemon contact state.");
553
- if (reply.cursor < this.cursor)
554
- return contact;
555
- for (const event of reply.events)
556
- if (event.id > this.cursor) {
557
- if (event.kind === "commit" && record(event.payload) && typeof event.payload.job === "string") {
558
- const current = this.commits.get(event.payload.job);
559
- this.commits.delete(event.payload.job);
560
- if (current && !current.signal?.aborted)
561
- current.notify();
562
- }
563
- this.options.event?.(event);
564
- }
565
- const latest = reply.cursor >= this.cursor;
566
- const present = new Set(reply.callbacks.map((callback) => callback.id));
567
- if (reply.cursor > this.cursor) {
568
- for (const id of this.completedReleases)
569
- if (!present.has(id))
570
- this.completedReleases.delete(id);
571
- this.cursor = reply.cursor;
572
- }
573
- for (const [id, pending] of this.callbacks) {
574
- if (pending.releaseCursor !== undefined) {
575
- // A job poll and the background poll can arrive out of order.
576
- if (!latest || reply.cursor <= pending.releaseCursor)
577
- continue;
578
- if (present.has(id)) {
579
- pending.releaseCursor = reply.cursor;
580
- continue;
581
- }
582
- }
583
- else if (present.has(id))
584
- continue;
585
- pending.controller.abort(new DOMException("Callback is no longer current", "AbortError"));
586
- }
587
- for (const callback of reply.callbacks) {
588
- if (this.callbacks.has(callback.id) || this.completedCallbacks.has(callback.id))
589
- continue;
590
- const release = callback.kind === "queue-release";
591
- if (release && (!latest || this.completedReleases.has(callback.id)))
592
- continue;
593
- if (this.completedCallbacks.size + this.callbacks.size >= MAX_COMPLETED_CALLBACKS)
594
- this.uncertain = true;
595
- const controller = new AbortController();
596
- const foreground = this.pendingJobs.has(callback.job);
597
- const reviewOwner = callback.review?.offer !== undefined
598
- ? { facts: { ...this.facts }, lifecycle: this.lifecycleRevision }
599
- : undefined;
600
- this.callbacks.set(callback.id, {
601
- controller,
602
- kind: callback.kind,
603
- job: callback.job,
604
- ...(release && { releaseCursor: reply.cursor }),
605
- });
606
- const task = (async () => {
607
- let value;
608
- let failed = false;
609
- try {
610
- if ((this.uncertain || this.resumeUncertain) && callback.kind !== "queue-release")
611
- throw new Error("Client is draining uncertain work.");
612
- value = await (reviewOwner
613
- ? this.performExactReview(callback, controller.signal, reviewOwner)
614
- : this.performCallback(callback, controller.signal));
615
- }
616
- catch {
617
- failed = true;
618
- }
619
- if (release) {
620
- if (!failed && value === true) {
621
- await this.deliverRelease(callback, foreground, controller.signal);
622
- return;
623
- }
624
- failed = true;
625
- }
626
- try {
627
- await requestDaemon(this.paths, this.identity, "answer", {
628
- client: reviewOwner?.facts.id ?? this.facts.id,
629
- id: callback.id,
630
- ...(reviewOwner ? { generation: reviewOwner.facts.generation } : {}),
631
- ...(failed || (reviewOwner && !this.ownsExactReview(callback, controller.signal, reviewOwner))
632
- ? { error: "Client callback cancelled or failed." }
633
- : { value }),
634
- }, this.callbackIO.signal);
635
- }
636
- finally {
637
- if (release)
638
- this.reportRelease(callback, foreground, "unconfirmed");
639
- }
640
- })()
641
- .catch((error) => {
642
- if (!this.closed && !controller.signal.aborted)
643
- this.reportError(error);
644
- })
645
- .finally(() => {
646
- if (this.completedCallbacks.size < MAX_COMPLETED_CALLBACKS)
647
- this.completedCallbacks.add(callback.id);
648
- else if (release && !controller.signal.aborted)
649
- this.completedReleases.add(callback.id);
650
- this.callbacks.delete(callback.id);
651
- this.callbackTasks.delete(task);
652
- });
653
- this.callbackTasks.add(task);
654
- }
655
- return contact;
656
- }
657
- reportRelease(callback, foreground, state) {
658
- if (this.callbackIO.signal.aborted)
659
- return;
660
- try {
661
- this.options.queueRelease?.({ id: callback.id, job: callback.job, foreground, state });
662
- }
663
- catch {
664
- // Presentation must not own a queue or a callback task.
665
- }
666
- }
667
- async deliverRelease(callback, foreground, pending) {
668
- const signal = AbortSignal.any([pending, this.callbackIO.signal]);
669
- const deadline = performance.now() + RELEASE_BUDGET_MS;
670
- let retrying = false;
671
- let state = "unconfirmed";
672
- try {
673
- for (let attempt = 0; attempt < RELEASE_MAX_ATTEMPTS; attempt++) {
674
- const remaining = Math.floor(deadline - performance.now());
675
- if (remaining <= 0 || signal.aborted)
676
- break;
677
- const controller = new AbortController();
678
- const timer = setTimeout(() => controller.abort(), Math.min(remaining, RELEASE_ATTEMPT_MS));
679
- timer.unref?.();
680
- try {
681
- await requestDaemon(this.paths, this.identity, "answer", { client: this.facts.id, id: callback.id, value: true }, AbortSignal.any([signal, controller.signal]));
682
- state = "finished";
683
- return;
684
- }
685
- catch (error) {
686
- if (signal.aborted)
687
- break;
688
- if (error instanceof DaemonError) {
689
- // The v1 server uses this reply for absent as well as foreign callbacks.
690
- // Do not infer whether the original release succeeded.
691
- if (error.message === "Stale or foreign callback response.")
692
- state = "finished";
693
- return;
694
- }
695
- if (!controller.signal.aborted &&
696
- (!(error instanceof Error) || !TRANSIENT_RELEASE_ERRORS.has(error.code ?? "")))
697
- return;
698
- }
699
- finally {
700
- clearTimeout(timer);
701
- }
702
- if (!retrying) {
703
- retrying = true;
704
- this.reportRelease(callback, foreground, "retrying");
705
- }
706
- const wait = Math.min(100 * 2 ** attempt, 2_000, deadline - performance.now());
707
- if (wait <= 0 || attempt + 1 >= RELEASE_MAX_ATTEMPTS)
708
- break;
709
- await delay(wait, undefined, { signal, ref: false }).catch(() => { });
710
- }
711
- }
712
- finally {
713
- if (pending.aborted && !this.callbackIO.signal.aborted)
714
- state = "finished";
715
- if (retrying || state === "unconfirmed")
716
- this.reportRelease(callback, foreground, state);
717
- }
718
- }
719
- ownsExactReview(callback, signal, owner) {
720
- return (!signal.aborted &&
721
- !this.callbackIO.signal.aborted &&
722
- owner.lifecycle === this.lifecycleRevision &&
723
- !this.closed &&
724
- !this.pausing &&
725
- !this.disposing &&
726
- !this.uncertain &&
727
- this.contactResumeState === "idle" &&
728
- this.contactState !== "expired" &&
729
- this.contactState !== "inactive" &&
730
- this.callbacks.get(callback.id)?.controller.signal === signal &&
731
- sameDiffReviewBinding(owner.facts, this.facts));
732
- }
733
- async performExactReview(callback, signal, owner) {
734
- const present = this.options.mergeReview;
735
- if (!present)
736
- throw new Error("Exact review offer requires an opted-in presenter.");
737
- const owned = AbortSignal.any([signal, this.callbackIO.signal]);
738
- const requireCurrent = () => {
739
- owned.throwIfAborted();
740
- if (!this.ownsExactReview(callback, signal, owner))
741
- throw new Error("Exact review participant changed.");
742
- };
743
- owned.throwIfAborted();
744
- const { presentPagedReview, reviewScope } = await import("./paged-review.js");
745
- requireCurrent();
746
- return presentPagedReview(reviewScope(this.identity, owner.facts, callback), callback, owned, present, (params, pageSignal) => {
747
- requireCurrent();
748
- return requestDaemon(this.paths, this.identity, "review-page", params, pageSignal);
749
- });
750
- }
751
- async performCallback(callback, signal) {
752
- const reference = callback.review;
753
- if (!reference)
754
- return this.options.callback(callback, signal);
755
- if (callback.kind !== "merge-review" ||
756
- !record(callback.payload) ||
757
- !Number.isSafeInteger(reference.pages) ||
758
- reference.pages < 1 ||
759
- reference.pages > Math.ceil(MAX_REVIEW_BYTES / REVIEW_PAGE_CHARS) ||
760
- !Number.isSafeInteger(reference.bytes) ||
761
- reference.bytes > MAX_REVIEW_BYTES ||
762
- reference.bytes < 1 ||
763
- !/^[a-f0-9]{64}$/u.test(reference.sha256))
764
- throw new Error("Invalid exact-review reference.");
765
- const ownedSignal = AbortSignal.any([signal, this.callbackIO.signal]);
766
- const pages = [];
767
- for (let index = 0; index < reference.pages; index++) {
768
- ownedSignal.throwIfAborted();
769
- const page = await requestDaemon(this.paths, this.identity, "review-page", { client: this.facts.id, id: callback.id, index }, ownedSignal);
770
- ownedSignal.throwIfAborted();
771
- if (!record(page) ||
772
- page.id !== callback.id ||
773
- page.index !== index ||
774
- typeof page.content !== "string" ||
775
- page.content.length > REVIEW_PAGE_CHARS)
776
- throw new Error("Invalid exact-review page.");
777
- pages.push(page.content);
778
- }
779
- const content = pages.join("");
780
- if (Buffer.byteLength(content) !== reference.bytes ||
781
- createHash("sha256").update(content).digest("hex") !== reference.sha256)
782
- throw new Error("Exact-review contents changed; approval was refused.");
783
- ownedSignal.throwIfAborted();
784
- return this.options.callback({ ...callback, review: undefined, payload: { ...callback.payload, content } }, signal);
785
- }
786
- async wait(ms, keepAlive = false) {
787
- const signal = this.controller.signal;
788
- signal.throwIfAborted();
789
- await new Promise((resolve, reject) => {
790
- const timer = setTimeout(done, ms);
791
- if (!keepAlive)
792
- timer.unref?.();
793
- const abort = () => {
794
- clearTimeout(timer);
795
- signal.removeEventListener("abort", abort);
796
- reject(signal.reason);
797
- };
798
- function done() {
799
- signal.removeEventListener("abort", abort);
800
- resolve();
801
- }
802
- signal.addEventListener("abort", abort, { once: true });
803
- });
804
- }
805
- reportError(error) {
806
- if (this.reportedError)
807
- return;
808
- this.reportedError = true;
809
- try {
810
- this.options.error?.(error);
811
- }
812
- catch {
813
- /* Error presentation must not own a task. */
814
- }
815
- }
816
- async observeState() {
817
- const jobs = stateWaitJobs(this.jobWaiters);
818
- const reply = await requestDaemon(this.paths, this.identity, "state-wait", {
819
- client: this.facts.id,
820
- generation: this.facts.generation,
821
- cursor: this.cursor,
822
- revision: this.stateRevision,
823
- jobs,
824
- }, this.controller.signal, { onSocket: (socket) => socket.unref() });
825
- return stateWaitResult(reply);
826
- }
827
- async poll() {
828
- await withCleanup(() => this.pollUntilClosed(), async () => {
829
- for (const waiter of this.jobWaiters.values())
830
- waiter.reject(this.controller.signal.reason ?? new Error("Daemon client closed."));
831
- });
832
- }
833
- async pollUntilClosed() {
834
- let failures = 0;
835
- while (!this.closed) {
836
- try {
837
- const revision = this.contactRevision;
838
- const state = this.observesState && !this.admitting ? await this.observeState() : undefined;
839
- const reply = state?.reply ??
840
- (await requestDaemon(this.paths, this.identity, "poll", { client: this.facts.id, cursor: this.cursor }, this.controller.signal));
841
- // An older poll must not undo typed update expiry or a successful resume.
842
- if (revision === this.contactRevision) {
843
- if (state?.missing.some((id) => this.jobWaiters.has(id)))
844
- this.markWorkUncertain();
845
- const contact = this.consume(reply);
846
- if (state) {
847
- this.stateRevision = state.version;
848
- this.terminalJobs = new Set(state.finished);
849
- for (const id of state.missing)
850
- this.jobWaiters.get(id)?.reject(new Error(UNKNOWN_JOB_RESULT));
851
- for (const id of state.finished)
852
- this.jobWaiters.get(id)?.resolve("terminal");
853
- }
854
- this.reportedError = false;
855
- if (revision === this.contactRevision &&
856
- this.attached &&
857
- !this.admitting &&
858
- !this.pausing &&
859
- !this.disposing &&
860
- !this.closed) {
861
- // A new observation fences older facts replies; identical polls do not.
862
- if (contact !== this.observedContact)
863
- this.publishContact(contact);
864
- if (contact !== undefined)
865
- this.options.contact?.(contact);
866
- }
867
- }
868
- failures = 0;
869
- if (!state)
870
- await this.wait(100);
871
- }
872
- catch (error) {
873
- if (this.closed)
874
- return;
875
- if (++failures >= STATE_WAIT_FAILURE_LIMIT)
876
- for (const waiter of this.jobWaiters.values())
877
- waiter.resolve("poll");
878
- if (this.attached)
879
- this.reportError(error);
880
- try {
881
- await this.wait(100);
882
- }
883
- catch {
884
- return;
885
- }
886
- }
887
- }
888
- }
889
- async pause() {
890
- if (this.closed || this.disposing)
891
- throw new Error("Daemon client is closed.");
892
- if (this.pausing)
893
- return this.pausing;
894
- this.resuming?.abort(new DOMException("Client paused", "AbortError"));
895
- this.retireDiffReviewIO();
896
- this.lifecycleRevision++;
897
- this.contactRevision++;
898
- this.pausing = (async () => {
899
- const reply = await requestDaemon(this.paths, this.identity, "pause", { client: this.facts.id });
900
- if (this.closed || this.disposing)
901
- return;
902
- const contact = this.consume(reply);
903
- this.diffReviewPaused = true;
904
- if (!this.disposing)
905
- this.publishContact(contact);
906
- })().finally(() => {
907
- this.pausing = undefined;
908
- });
909
- return this.pausing;
910
- }
911
- async dispose(handoff) {
912
- if (this.disposing)
913
- return this.disposing;
914
- if (this.closed)
915
- return;
916
- this.resuming?.abort(new DOMException("Client disposed", "AbortError"));
917
- this.retireDiffReviewIO();
918
- this.lifecycleRevision++;
919
- this.contactRevision++;
920
- this.disposing = (async () => {
921
- this.polling ??= this.poll();
922
- // Cancel UI before drain, but keep polling for acknowledged queue-release callbacks.
923
- for (const { controller, kind } of this.callbacks.values())
924
- if (!kind.startsWith("queue-"))
925
- controller.abort();
926
- try {
927
- const reply = await requestDaemon(this.paths, this.identity, handoff ? "handoff" : "detach", {
928
- client: this.facts.id,
929
- generation: this.facts.generation,
930
- pid: this.facts.pid,
931
- handoff,
932
- });
933
- this.consume(reply);
934
- }
935
- finally {
936
- await this.closeLocal();
937
- }
938
- })();
939
- return this.disposing;
940
- }
941
- async closeLocal() {
942
- this.closed = true;
943
- this.retireDiffReviewIO();
944
- this.controller.abort(new DOMException("Client disposed", "AbortError"));
945
- this.callbackIO.abort(new DOMException("Client callback transport disposed", "AbortError"));
946
- for (const { controller } of this.callbacks.values())
947
- controller.abort();
948
- await Promise.allSettled([this.polling, this.updates, ...this.callbackTasks]);
949
- }
950
- }