@kabmo-labs/kabmo 0.33.0 → 0.34.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 (211) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +785 -624
  3. package/dist/client/static/js/{CsvGrid-fncjbg6j.js → CsvGrid-vze4m5ag.js} +1 -1
  4. package/dist/client/static/js/{DocxView-c9v2vr3r.js → DocxView-jbf21gmh.js} +5 -5
  5. package/dist/client/static/js/{DrawioView-vxjksm12.js → DrawioView-b52qybx5.js} +2 -2
  6. package/dist/client/static/js/{ImageView-a3g5k226.js → ImageView-mdgzj8px.js} +1 -1
  7. package/dist/client/static/js/{LayoutWrapper-hnjfwsjh.js → LayoutWrapper-3c49dvtt.js} +2 -2
  8. package/dist/client/static/js/Modal-sqp864vd.js +38 -0
  9. package/dist/client/static/js/{PdfView-ksaes53y.js → PdfView-g06rxqb1.js} +1 -1
  10. package/dist/client/static/js/{SessionsView-30vcr95v.js → SessionsView-521adxyr.js} +1 -1
  11. package/dist/client/static/js/{SheetView-vc484scg.js → SheetView-h8xmsz7q.js} +22 -22
  12. package/dist/client/static/js/{SvgPreview-tph89jet.js → SvgPreview-1j4jvcvz.js} +1 -1
  13. package/dist/client/static/js/{abnfDiagram-O67JEVCF-xbar278c.js → abnfDiagram-O67JEVCF-pasxh4b6.js} +1 -1
  14. package/dist/client/static/js/architecture-7GRP2DOG-fc9kmq1w.js +1 -0
  15. package/dist/client/static/js/{architectureDiagram-NJMV4G6O-s171n2z6.js → architectureDiagram-NJMV4G6O-ms14g0bm.js} +4 -4
  16. package/dist/client/static/js/{blockDiagram-BEXU5L5S-gzx6rv9n.js → blockDiagram-BEXU5L5S-ycn78fcq.js} +4 -4
  17. package/dist/client/static/js/{c4Diagram-YGBWAQC7-7f00skch.js → c4Diagram-YGBWAQC7-vn2gpjfm.js} +5 -5
  18. package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-j79v95nc.js → classDiagram-v2-NBCMYWYE-fyrm1pr5.js} +4 -4
  19. package/dist/client/static/js/{cose-bilkent-JH36ORCC-5fkn7ee5.js → cose-bilkent-JH36ORCC-ea5nwvgq.js} +1 -1
  20. package/dist/client/static/js/cynefin-OW5HDTMX-a4t8992q.js +1 -0
  21. package/dist/client/static/js/{cynefinDiagram-VND7K2PF-cfs1yvrd.js → cynefinDiagram-VND7K2PF-j6bsjpre.js} +1 -1
  22. package/dist/client/static/js/{dagre-6A5THRUB-44bgc48p.js → dagre-6A5THRUB-4smdkwv8.js} +2 -2
  23. package/dist/client/static/js/{diagram-22UHCM2B-a4g4x83k.js → diagram-22UHCM2B-9sm4kqwc.js} +11 -11
  24. package/dist/client/static/js/{diagram-3UASUU5V-gm4rg5na.js → diagram-3UASUU5V-2h3qxaed.js} +1 -1
  25. package/dist/client/static/js/{diagram-ATOU4E4O-a95y41vk.js → diagram-ATOU4E4O-1981bc94.js} +3 -3
  26. package/dist/client/static/js/{diagram-CDSNMT55-t3j93mmc.js → diagram-CDSNMT55-3vgsxavc.js} +4 -4
  27. package/dist/client/static/js/{diagram-MLGK6HIB-c2wdez02.js → diagram-MLGK6HIB-c9gf2r3f.js} +2 -2
  28. package/dist/client/static/js/{diagram-MPIPVDR6-gya9jhs5.js → diagram-MPIPVDR6-gjqeq92d.js} +2 -2
  29. package/dist/client/static/js/{dockerfile-a7q6174s.js → dockerfile-8v935dkn.js} +1 -1
  30. package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-jjhkza6t.js → ebnfDiagram-ZINNZB2B-4vbsgh99.js} +1 -1
  31. package/dist/client/static/js/{elixir-rpa1g4gy.js → elixir-vcbg60wv.js} +1 -1
  32. package/dist/client/static/js/{elk-276RUBZZ-f7re45mw.js → elk-276RUBZZ-nca3t891.js} +1 -1
  33. package/dist/client/static/js/{erDiagram-OPXOYQCR-tpm9g5te.js → erDiagram-OPXOYQCR-5kfkev03.js} +2 -2
  34. package/dist/client/static/js/eventmodeling-NTZA5JFV-18bdrkv5.js +1 -0
  35. package/dist/client/static/js/flowDiagram-KWPJA3E3-fg0yqx0h.js +1 -0
  36. package/dist/client/static/js/{ganttDiagram-FUAMR5RP-fz43n12d.js → ganttDiagram-FUAMR5RP-mxc73wmq.js} +3 -3
  37. package/dist/client/static/js/gitGraph-4MIJSDKK-8fa6y40p.js +1 -0
  38. package/dist/client/static/js/{gitGraphDiagram-X574FWY7-f61hgbn6.js → gitGraphDiagram-X574FWY7-7en3ag0e.js} +12 -12
  39. package/dist/client/static/js/html-dbrwss36.js +1 -0
  40. package/dist/client/static/js/{index-m73za75e.js → index-0vm41je9.js} +3 -3
  41. package/dist/client/static/js/{index-eyzeya95.js → index-1b0t1428.js} +5 -5
  42. package/dist/client/static/js/{index-2x5f66t6.js → index-1ksg88qf.js} +1 -1
  43. package/dist/client/static/js/{index-sffjtm5w.js → index-231241f4.js} +9 -9
  44. package/dist/client/static/js/index-2mx9ej4k.css +1 -0
  45. package/dist/client/static/js/{index-8239j2v1.js → index-4g46wbdw.js} +1 -1
  46. package/dist/client/static/js/{index-1xqs14fr.js → index-4qwzxj81.js} +1 -1
  47. package/dist/client/static/js/{index-gcs49f3p.js → index-52rqxgya.js} +1 -1
  48. package/dist/client/static/js/{index-at6bhjyf.js → index-6sf2vsp2.js} +1 -1
  49. package/dist/client/static/js/{index-q2w6s8n7.js → index-7a64yjrm.js} +4 -4
  50. package/dist/client/static/js/{index-rg8jpbsw.js → index-8acv5b77.js} +2 -2
  51. package/dist/client/static/js/{index-js7t1vb1.js → index-a0fmsv1d.js} +5 -5
  52. package/dist/client/static/js/{index-w0fwb80e.js → index-ag2rmtas.js} +1 -1
  53. package/dist/client/static/js/{index-djmg1d7h.js → index-b29afsjh.js} +1 -1
  54. package/dist/client/static/js/{index-e4p4cd3r.js → index-c3ek61zv.js} +1 -1
  55. package/dist/client/static/js/{index-0e40xskg.js → index-cd65zqba.js} +1 -1
  56. package/dist/client/static/js/{index-zt75xpq0.js → index-cgzrpvzj.js} +204 -204
  57. package/dist/client/static/js/{index-0n5wwe60.js → index-ev3yt353.js} +2 -2
  58. package/dist/client/static/js/{index-9y3gjdj7.js → index-eyfcm0cy.js} +1 -1
  59. package/dist/client/static/js/{index-qsm2z36d.js → index-f7jhhqtk.js} +1 -1
  60. package/dist/client/static/js/{index-vw5k8csz.js → index-fta1y9pc.js} +50 -50
  61. package/dist/client/static/js/{index-ajs3jj6j.js → index-fvmfge3p.js} +1 -1
  62. package/dist/client/static/js/{index-pxv2nw9w.js → index-g2dyfze9.js} +1 -1
  63. package/dist/client/static/js/{index-bkye8mz4.js → index-h5bn97p6.js} +1 -1
  64. package/dist/client/static/js/{index-trm9x02n.js → index-j51d5a5m.js} +6 -6
  65. package/dist/client/static/js/{index-pbe4yed4.js → index-jsyekbx9.js} +2 -2
  66. package/dist/client/static/js/{index-gs6f0qwa.js → index-nccwxv0s.js} +2 -2
  67. package/dist/client/static/js/{index-d495kfm0.js → index-p0nz38bm.js} +1 -1
  68. package/dist/client/static/js/{index-sdtye3jy.js → index-pm6xxwz1.js} +2 -2
  69. package/dist/client/static/js/{index-3rcjx70v.js → index-ptcrwswj.js} +1 -1
  70. package/dist/client/static/js/{index-14vndmcr.js → index-ptcwae2n.js} +1 -1
  71. package/dist/client/static/js/{index-5tgq7aqx.js → index-r014brzs.js} +2 -2
  72. package/dist/client/static/js/{index-xj9649ac.js → index-ray2czf6.js} +7 -7
  73. package/dist/client/static/js/{index-apvkd37e.js → index-rs80cwsv.js} +3 -3
  74. package/dist/client/static/js/{index-vw4brsdx.js → index-rzxcj7cg.js} +1 -1
  75. package/dist/client/static/js/{index-a293pdg7.js → index-s7gkkkyz.js} +2 -2
  76. package/dist/client/static/js/{index-1a0zkj8h.js → index-sd66wv26.js} +2 -2
  77. package/dist/client/static/js/{index-ypx3qmhq.js → index-vhqe0y82.js} +1 -1
  78. package/dist/client/static/js/{index-9fjt5anh.js → index-vy6termr.js} +1 -1
  79. package/dist/client/static/js/{index-0tf0arsp.js → index-xx6mqpxm.js} +3 -3
  80. package/dist/client/static/js/{index-03h3bkcf.js → index-ybm2x4vh.js} +1 -1
  81. package/dist/client/static/js/info-A6RAGUB7-3hk844f7.js +1 -0
  82. package/dist/client/static/js/{infoDiagram-VRGFBTTK-1qj804sn.js → infoDiagram-VRGFBTTK-sef80132.js} +2 -2
  83. package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-4j4qsnzw.js → ishikawaDiagram-OU5B5YK6-yhvepp1q.js} +6 -6
  84. package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-j0brnfft.js → journeyDiagram-ZHPQQLJL-5w77y95w.js} +5 -5
  85. package/dist/client/static/js/{julia-4ghmfy3e.js → julia-d4j6wgvf.js} +1 -1
  86. package/dist/client/static/js/{kanban-definition-PNTS6WVX-qqc22br0.js → kanban-definition-PNTS6WVX-02znqtna.js} +6 -6
  87. package/dist/client/static/js/{mermaid.core-vv3wbe65.js → mermaid.core-a6e6vck4.js} +5 -5
  88. package/dist/client/static/js/{mindmap-definition-NLK3R4M7-y5b2z8zp.js → mindmap-definition-NLK3R4M7-y4n74q9x.js} +8 -8
  89. package/dist/client/static/js/one-dark-pro-vwhfpzr8.js +1 -0
  90. package/dist/client/static/js/one-light-y5t9x6zh.js +1 -0
  91. package/dist/client/static/js/packet-AYTQ26CC-4nj2yy10.js +1 -0
  92. package/dist/client/static/js/{pegDiagram-GJSIUBJH-0be07mqs.js → pegDiagram-GJSIUBJH-pr7ehgzb.js} +1 -1
  93. package/dist/client/static/js/{perl-sd00t4b4.js → perl-srptw5vm.js} +1 -1
  94. package/dist/client/static/js/{php-2zfyqa61.js → php-n89g3fk7.js} +1 -1
  95. package/dist/client/static/js/pie-WAS4IAKB-k7rde3f9.js +1 -0
  96. package/dist/client/static/js/{pieDiagram-5QR66LMP-544w86jk.js → pieDiagram-5QR66LMP-39wpsk08.js} +2 -2
  97. package/dist/client/static/js/{quadrantDiagram-O4NWA36T-p09e7z5s.js → quadrantDiagram-O4NWA36T-esm913km.js} +5 -5
  98. package/dist/client/static/js/radar-RG4KPBEZ-513dpw4f.js +1 -0
  99. package/dist/client/static/js/railroad-74A4TZTK-9bqnst9c.js +1 -0
  100. package/dist/client/static/js/railroad-abnf-HS5TGJTU-7367d5bv.js +1 -0
  101. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-b806b1mj.js +1 -0
  102. package/dist/client/static/js/railroad-peg-WCYAUIDC-5a67rwf8.js +1 -0
  103. package/dist/client/static/js/{railroadDiagram-XR7U4H2S-de830ed2.js → railroadDiagram-XR7U4H2S-wy2mgya6.js} +1 -1
  104. package/dist/client/static/js/{requirementDiagram-PLB6GJNP-b47d74p1.js → requirementDiagram-PLB6GJNP-6z9xdgbq.js} +2 -2
  105. package/dist/client/static/js/{ruby-v9qaqhby.js → ruby-r81ytgcm.js} +1 -1
  106. package/dist/client/static/js/{rust-fkt0qyrs.js → rust-frn3szvc.js} +1 -1
  107. package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-6ezc2fpj.js → sankeyDiagram-IPEJSGJF-rtmxk3ys.js} +4 -4
  108. package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-by5zqj6w.js → sequenceDiagram-PO4LG4MO-awzcrafg.js} +18 -18
  109. package/dist/client/static/js/{sizeCapture-INFHLROL-q85r06j6.js → sizeCapture-INFHLROL-03gy196j.js} +1 -1
  110. package/dist/client/static/js/sql-0e9mnrda.js +1 -0
  111. package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-ep5pyexs.js → stateDiagram-v2-GCMORJYK-an8v3q5n.js} +3 -3
  112. package/dist/client/static/js/{swimlanes-2SLR337P-95fcqkh8.js → swimlanes-2SLR337P-n9yb4wcs.js} +1 -1
  113. package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-xs2en5dv.js → swimlanesDiagram-TC7HE7FX-nx5nfnf0.js} +1 -1
  114. package/dist/client/static/js/{timeline-definition-EJHVYXUP-461e615g.js → timeline-definition-EJHVYXUP-jceb575g.js} +4 -4
  115. package/dist/client/static/js/treeView-Q6P3EWNA-kcy40evb.js +1 -0
  116. package/dist/client/static/js/treemap-WGGIJYW6-fsrvqxf4.js +1 -0
  117. package/dist/client/static/js/{usecaseDiagram-POWQR4AR-ftqfnvhg.js → usecaseDiagram-POWQR4AR-888h3100.js} +13 -13
  118. package/dist/client/static/js/{vennDiagram-UO4OBE2U-7t96h6ez.js → vennDiagram-UO4OBE2U-wbfz0rzv.js} +7 -7
  119. package/dist/client/static/js/{vue-j8vb9d7r.js → vue-c0rtg1wf.js} +1 -1
  120. package/dist/client/static/js/wardley-WFR3VGLG-36dmxww4.js +1 -0
  121. package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-0de8w8c6.js → wardleyDiagram-VNRHLVJA-rn8c5qf9.js} +4 -4
  122. package/dist/client/static/js/{xychartDiagram-PMCCYNJV-dez9phkf.js → xychartDiagram-PMCCYNJV-8sn1apt6.js} +5 -5
  123. package/package.json +4 -1
  124. package/src/client/components/auth/login-screen/index.tsx +1 -0
  125. package/src/client/components/common/MarkdownRenderer.tsx +9 -12
  126. package/src/client/components/settings/Modal.tsx +14 -84
  127. package/src/client/components/settings/Sidebar.tsx +3 -1
  128. package/src/client/components/settings/categories/ConnectSettings.tsx +105 -0
  129. package/src/client/components/settings/categories/connect-settings/DeviceTable.tsx +145 -0
  130. package/src/client/components/settings/categories/connect-settings/PairDialog.tsx +160 -0
  131. package/src/client/components/settings/categories/connect-settings/QrCode.tsx +73 -0
  132. package/src/client/components/settings/categories/connect-settings/ServerCard.tsx +94 -0
  133. package/src/client/components/settings/categories/connect-settings/TunnelRow.tsx +127 -0
  134. package/src/client/components/settings/category-content.tsx +116 -0
  135. package/src/client/components/workspace/chat-timeline/ChangedFilesSummary.test.tsx +120 -0
  136. package/src/client/components/workspace/chat-timeline/ChangedFilesSummary.tsx +56 -20
  137. package/src/client/components/workspace/chat-timeline/RunFooter.tsx +1 -0
  138. package/src/client/hooks/chat/timeline/change-stats.ts +57 -0
  139. package/src/client/hooks/connect/use-connect-status.ts +116 -0
  140. package/src/client/hooks/connect/use-pairing.ts +100 -0
  141. package/src/client/hooks/ui/clipboard.ts +26 -0
  142. package/src/client/tailwind.css +5 -0
  143. package/src/server/index.ts +2 -0
  144. package/src/server/lib/assets/font-css.server.test.ts +19 -0
  145. package/src/server/lib/auth/client-address.test.ts +58 -0
  146. package/src/server/lib/auth/client-address.ts +37 -3
  147. package/src/server/lib/auth/guard.ts +31 -4
  148. package/src/server/lib/auth/rate-limit.test.ts +25 -8
  149. package/src/server/lib/auth/rate-limit.ts +8 -5
  150. package/src/server/lib/connect/cloudflared.lifecycle.test.ts +88 -0
  151. package/src/server/lib/connect/cloudflared.server.test.ts +65 -0
  152. package/src/server/lib/connect/cloudflared.server.ts +206 -0
  153. package/src/server/lib/connect/devices.server.ts +192 -0
  154. package/src/server/lib/connect/identity.server.ts +81 -0
  155. package/src/server/lib/connect/pairing.server.test.ts +56 -0
  156. package/src/server/lib/connect/pairing.server.ts +113 -0
  157. package/src/server/lib/connect/qr.roundtrip.test.ts +106 -0
  158. package/src/server/lib/connect/qr.server.ts +36 -0
  159. package/src/server/lib/connect/run.server.ts +101 -0
  160. package/src/server/lib/connect/status.server.ts +177 -0
  161. package/src/server/lib/connect/tailscale.server.test.ts +117 -0
  162. package/src/server/lib/connect/tailscale.server.ts +172 -0
  163. package/src/server/lib/db/schema.ts +4 -0
  164. package/src/server/lib/omp/session/changes.test.ts +64 -1
  165. package/src/server/lib/omp/session/changes.ts +94 -1
  166. package/src/server/routes/connect/devices.ts +56 -0
  167. package/src/server/routes/connect/index.ts +15 -0
  168. package/src/server/routes/connect/pair-page.ts +177 -0
  169. package/src/server/routes/connect/pair.ts +158 -0
  170. package/src/server/routes/connect/status.ts +19 -0
  171. package/src/server/routes/connect/tunnels.ts +76 -0
  172. package/src/server/routes/health/probe.ts +5 -0
  173. package/src/server/routes/index.ts +2 -0
  174. package/src/server/routes/sessions/changes.test.ts +12 -3
  175. package/src/server/routes/sessions/changes.ts +27 -3
  176. package/src/server/routes/sessions/index.ts +2 -1
  177. package/src/shared/lib/connect/payload.test.ts +144 -0
  178. package/src/shared/lib/connect/payload.ts +229 -0
  179. package/src/shared/lib/connect/tier.test.ts +73 -0
  180. package/src/shared/lib/connect/tier.ts +105 -0
  181. package/src/shared/lib/connect/types.ts +99 -0
  182. package/src/shared/lib/markdown/fira-code-fonts.css +65 -6
  183. package/src/shared/lib/markdown/marked.ts +7 -4
  184. package/src/shared/lib/markdown/mermaid-actions.test.ts +78 -0
  185. package/src/shared/lib/markdown/mermaid-actions.ts +45 -0
  186. package/src/shared/lib/markdown/mermaid.ts +41 -7
  187. package/src/shared/lib/settings/sections.ts +6 -1
  188. package/src/shared/types/session-changes.ts +6 -0
  189. package/src/shared/types/settings/state.ts +2 -0
  190. package/dist/client/static/js/Modal-qtftcp2t.js +0 -38
  191. package/dist/client/static/js/architecture-7GRP2DOG-tavtgb8a.js +0 -1
  192. package/dist/client/static/js/cynefin-OW5HDTMX-cdh3n2z2.js +0 -1
  193. package/dist/client/static/js/eventmodeling-NTZA5JFV-as97tpyp.js +0 -1
  194. package/dist/client/static/js/flowDiagram-KWPJA3E3-ggm06d12.js +0 -1
  195. package/dist/client/static/js/gitGraph-4MIJSDKK-eqz7p9ng.js +0 -1
  196. package/dist/client/static/js/html-pv88ny12.js +0 -1
  197. package/dist/client/static/js/index-e94a1en0.css +0 -1
  198. package/dist/client/static/js/info-A6RAGUB7-4pkzh1qx.js +0 -1
  199. package/dist/client/static/js/one-dark-pro-hm3f56n1.js +0 -1
  200. package/dist/client/static/js/one-light-xrz49rct.js +0 -1
  201. package/dist/client/static/js/packet-AYTQ26CC-yg71sp88.js +0 -1
  202. package/dist/client/static/js/pie-WAS4IAKB-89wd6np0.js +0 -1
  203. package/dist/client/static/js/radar-RG4KPBEZ-avn0b8r9.js +0 -1
  204. package/dist/client/static/js/railroad-74A4TZTK-de27xv5w.js +0 -1
  205. package/dist/client/static/js/railroad-abnf-HS5TGJTU-rg4zzj7x.js +0 -1
  206. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-d84fhj8v.js +0 -1
  207. package/dist/client/static/js/railroad-peg-WCYAUIDC-dvf8xrmc.js +0 -1
  208. package/dist/client/static/js/sql-g8wcshpc.js +0 -1
  209. package/dist/client/static/js/treeView-Q6P3EWNA-mham0bh6.js +0 -1
  210. package/dist/client/static/js/treemap-WGGIJYW6-mxrxax86.js +0 -1
  211. package/dist/client/static/js/wardley-WFR3VGLG-8vrvh9p3.js +0 -1
@@ -0,0 +1,158 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * `POST /api/connect/pair` — mint a one-time code and its QR.
8
+ * `POST /api/connect/pair/claim` — redeem it for a device token.
9
+ *
10
+ * The two halves have different auth on purpose. Minting requires a session: it
11
+ * is the operator handing out access. Claiming is PUBLIC, because the device
12
+ * doing it has no cookie yet — the one-time secret IS the credential, and it is
13
+ * 32 random bytes with a two-minute life, so it cannot be guessed and cannot be
14
+ * replayed.
15
+ *
16
+ * The claim answers with the server's `serverId` so the device can confirm it
17
+ * reached the machine the QR named. A device that pinned an id and gets a
18
+ * different one must refuse the token it was just handed.
19
+ */
20
+
21
+ import { json, NO_STORE_HEADERS, type ActionFunctionArgs } from '@/server/lib/remix-compat';
22
+ import { connectIdentity } from '@/server/lib/connect/identity.server';
23
+ import { connectStatus } from '@/server/lib/connect/status.server';
24
+ import { createPairing, consumePairing } from '@/server/lib/connect/pairing.server';
25
+ import { mintDeviceToken, touchDevice, DEVICE_COOKIE } from '@/server/lib/connect/devices.server';
26
+ import { isSecureRequest } from '@/server/lib/auth/token';
27
+ import { qrMatrix } from '@/server/lib/connect/qr.server';
28
+ import { encodePairingFragment, encodePairingPayload, PAIRING_VERSION } from '@/shared/lib/connect/payload';
29
+ import { ROUTE_TIER } from '@/shared/lib/connect/tier';
30
+ import type { ConnectCandidate, ConnectRouteKind } from '@/shared/lib/connect/types';
31
+
32
+ const ROUTE_KINDS: readonly ConnectRouteKind[] = ['cloudflare', 'lan', 'tailscale'];
33
+
34
+ /**
35
+ * How long the device cookie lives, in seconds.
36
+ *
37
+ * 400 days is the longest Chrome honours; the token itself never expires, so this
38
+ * is the browser's cap rather than a policy. Revocation is the control that ends
39
+ * a pairing, not time.
40
+ */
41
+ const DEVICE_COOKIE_MAX_AGE = 400 * 24 * 60 * 60;
42
+
43
+ interface ClaimRequest {
44
+ action?: unknown;
45
+ pairingId?: unknown;
46
+ secret?: unknown;
47
+ name?: unknown;
48
+ platform?: unknown;
49
+ route?: unknown;
50
+ rttMs?: unknown;
51
+ }
52
+
53
+ export async function action({ request }: ActionFunctionArgs) {
54
+ if (request.method !== 'POST') {
55
+ return json({ error: 'Method not allowed' }, { status: 405, headers: NO_STORE_HEADERS });
56
+ }
57
+
58
+ const url = new URL(request.url);
59
+ const body = (await request.json().catch(() => null)) as ClaimRequest | null;
60
+ const isClaim = url.pathname.endsWith('/claim');
61
+
62
+ if (isClaim) {
63
+ const pairingId = typeof body?.pairingId === 'string' ? body.pairingId : '';
64
+ const secret = typeof body?.secret === 'string' ? body.secret : '';
65
+ if (!pairingId || !secret) {
66
+ return json({ error: 'Expected { pairingId, secret }' }, { status: 400, headers: NO_STORE_HEADERS });
67
+ }
68
+
69
+ const consumed = consumePairing(pairingId, secret);
70
+ if (!consumed.ok) {
71
+ return json({ error: consumed.reason }, { status: 410, headers: NO_STORE_HEADERS });
72
+ }
73
+
74
+ const name = typeof body?.name === 'string' ? body.name : 'Device';
75
+ const platform = typeof body?.platform === 'string' ? body.platform : 'unknown';
76
+ const device = await mintDeviceToken({ name, platform });
77
+
78
+ const route = ROUTE_KINDS.find((kind) => kind === body?.route);
79
+ const rttMs = typeof body?.rttMs === 'number' && Number.isFinite(body.rttMs) ? Math.round(body.rttMs) : null;
80
+ if (route && rttMs !== null) await touchDevice(device.id, { route, rttMs });
81
+
82
+ // The cookie is what a webview can actually send: it cannot attach an
83
+ // `Authorization` header to its own page requests or to a WebSocket upgrade.
84
+ // `HttpOnly` keeps it away from page script; `SameSite=Lax` is enough because
85
+ // every request that matters is same-origin.
86
+ //
87
+ // `Max-Age` is what makes pairing survive a restart. Without it the cookie is
88
+ // a SESSION cookie, which the browser drops when it closes — so a paired phone
89
+ // asked for a password again the next morning, and the whole point of pairing
90
+ // is that it does not. The token itself has no expiry in the database (only
91
+ // revocation), so the cookie's life is the browser's cap rather than a policy:
92
+ // 400 days is the longest Chrome honours.
93
+ const secure = isSecureRequest(request) ? '; Secure' : '';
94
+ return json(
95
+ {
96
+ deviceId: device.id,
97
+ token: device.token,
98
+ serverId: connectIdentity().serverId,
99
+ candidates: consumed.candidates,
100
+ },
101
+ {
102
+ headers: {
103
+ ...NO_STORE_HEADERS,
104
+ 'set-cookie': `${DEVICE_COOKIE}=${encodeURIComponent(device.token)}; Path=/; Max-Age=${DEVICE_COOKIE_MAX_AGE}; HttpOnly; SameSite=Lax${secure}`,
105
+ },
106
+ },
107
+ );
108
+ }
109
+
110
+ // Minting. Only the addresses that actually answer go into the code: a
111
+ // candidate the device cannot reach would make the first probe fail for no
112
+ // reason, and the page already shows the unavailable ones with their reason.
113
+ const status = await connectStatus();
114
+ const candidates: ConnectCandidate[] = status.addresses
115
+ .filter((address) => address.unavailable === null && address.url !== '')
116
+ .map((address) => ({ kind: address.kind, url: address.url }));
117
+
118
+ if (candidates.length === 0) {
119
+ return json(
120
+ {
121
+ error:
122
+ 'No reachable address to put in a pairing code. Turn on Tailscale Serve, or start this server with --lan.',
123
+ },
124
+ { status: 409, headers: NO_STORE_HEADERS },
125
+ );
126
+ }
127
+
128
+ const pairing = createPairing(candidates);
129
+ const payload = {
130
+ v: PAIRING_VERSION as 1,
131
+ pairingId: pairing.pairingId,
132
+ secret: pairing.secret,
133
+ serverId: status.serverId,
134
+ label: status.label,
135
+ expiresAt: pairing.expiresAt,
136
+ candidates,
137
+ };
138
+ const link = encodePairingPayload(payload);
139
+
140
+ // The QR carries the BROWSER link, not the deep link: a phone's camera app
141
+ // opens an https URL in the browser, which is what makes pairing work with no
142
+ // native scanner. The best candidate is the lowest tier — Tailscale before
143
+ // LAN, because the LAN origin is not a secure context.
144
+ const best = [...candidates].sort((left, right) => ROUTE_TIER[left.kind] - ROUTE_TIER[right.kind])[0];
145
+ const webLink = `${best.url}/pair#${encodePairingFragment(payload)}`;
146
+
147
+ return json(
148
+ {
149
+ pairingId: pairing.pairingId,
150
+ expiresAt: pairing.expiresAt,
151
+ link,
152
+ webLink,
153
+ candidates,
154
+ qr: qrMatrix(webLink),
155
+ },
156
+ { headers: NO_STORE_HEADERS },
157
+ );
158
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * `GET /api/connect/status` — everything the Connect page draws.
8
+ *
9
+ * Authenticated like every other API route: the payload names the machine, its
10
+ * addresses and its paired devices, which is reconnaissance a stranger should
11
+ * not get for free.
12
+ */
13
+
14
+ import { json, NO_STORE_HEADERS } from '@/server/lib/remix-compat';
15
+ import { connectStatus } from '@/server/lib/connect/status.server';
16
+
17
+ export async function loader() {
18
+ return json(await connectStatus(), { headers: NO_STORE_HEADERS });
19
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * `POST /api/connect/tunnels` — start or stop one provider.
8
+ *
9
+ * The response is the whole status payload rather than a boolean: the page has
10
+ * to redraw the address list and the tunnel card together, and a second read
11
+ * would let the two disagree for a frame.
12
+ *
13
+ * A refusal carries the provider's own sentence. "Tailscale refused: HTTPS is
14
+ * not enabled for this tailnet" is actionable; `{ ok: false }` is not.
15
+ */
16
+
17
+ import { json, NO_STORE_HEADERS, type ActionFunctionArgs } from '@/server/lib/remix-compat';
18
+ import { connectStatus, currentPort } from '@/server/lib/connect/status.server';
19
+ import { findTailscale, startServe, stopServe } from '@/server/lib/connect/tailscale.server';
20
+ import {
21
+ findCloudflared,
22
+ readCloudflaredConfig,
23
+ startCloudflared,
24
+ stopCloudflared,
25
+ } from '@/server/lib/connect/cloudflared.server';
26
+
27
+ interface TunnelRequest {
28
+ provider?: unknown;
29
+ action?: unknown;
30
+ }
31
+
32
+ export async function action({ request }: ActionFunctionArgs) {
33
+ if (request.method !== 'POST') {
34
+ return json({ error: 'Method not allowed' }, { status: 405, headers: NO_STORE_HEADERS });
35
+ }
36
+
37
+ const body = (await request.json().catch(() => null)) as TunnelRequest | null;
38
+ const provider = body?.provider;
39
+ const verb = body?.action;
40
+ if ((provider !== 'tailscale' && provider !== 'cloudflare') || (verb !== 'start' && verb !== 'stop')) {
41
+ return json(
42
+ { error: 'Expected { provider: "tailscale" | "cloudflare", action: "start" | "stop" }' },
43
+ { status: 400, headers: NO_STORE_HEADERS },
44
+ );
45
+ }
46
+
47
+ const port = currentPort();
48
+ let failure: string | null = null;
49
+
50
+ if (provider === 'tailscale') {
51
+ const presence = findTailscale();
52
+ if (!presence.binary) {
53
+ failure = presence.reason;
54
+ } else {
55
+ const outcome = verb === 'start' ? await startServe(presence.binary, port) : await stopServe(presence.binary);
56
+ if (!outcome.ok) failure = outcome.reason;
57
+ }
58
+ } else if (verb === 'stop') {
59
+ stopCloudflared(port);
60
+ } else {
61
+ const presence = findCloudflared();
62
+ const config = presence.configPath ? readCloudflaredConfig(presence.configPath) : null;
63
+ if (presence.reason || !presence.binary || !presence.configPath || !config?.hostname) {
64
+ failure = presence.reason ?? 'cloudflared is not configured.';
65
+ } else {
66
+ const outcome = await startCloudflared(presence.binary, presence.configPath, config.hostname, port);
67
+ if (!outcome.ok) failure = outcome.reason;
68
+ }
69
+ }
70
+
71
+ const status = await connectStatus();
72
+ return json(
73
+ failure ? { ok: false, error: failure, status } : { ok: true, status },
74
+ { status: failure ? 400 : 200, headers: NO_STORE_HEADERS },
75
+ );
76
+ }
@@ -8,6 +8,7 @@ import { isTrayEnabledByArgv } from '@/server/lib/lifecycle/argv-flags';
8
8
  import { isTlsEnabledByArgv } from '@/server/lib/lifecycle/tls';
9
9
  import { isMockMode } from '@/server/mock.server';
10
10
  import { pluginPlatformReady } from '@/server/lib/plugins/loader.server';
11
+ import { connectIdentity } from '@/server/lib/connect/identity.server';
11
12
 
12
13
  const STARTED_AT = Date.now();
13
14
  const STARTED_ISO = new Date(STARTED_AT).toISOString();
@@ -46,6 +47,10 @@ export async function loader() {
46
47
  // address, so a LAN-bound instance with no password — reachable by anyone
47
48
  // on the network — is visible from the CLI instead of only from a browser.
48
49
  authEnabled: isAuthEnabled(),
50
+ // Stable identity of this install, derived from a persisted key. A paired
51
+ // device pins it and refuses an address that answers with a different one,
52
+ // which is what stops a reassigned LAN address from receiving its token.
53
+ serverId: connectIdentity().serverId,
49
54
  // Reported so discovery does not have to guess the scheme: `status` and
50
55
  // `findLiveInstance` read it to build the URL they print and probe.
51
56
  tls: isTlsEnabledByArgv(),
@@ -31,6 +31,7 @@ import { harnessBindings } from '@/server/routes/harness';
31
31
  import { healthBindings } from '@/server/routes/health';
32
32
  import { wellKnownBindings } from '@/server/routes/well-known';
33
33
  import { notificationsBindings } from '@/server/routes/notifications';
34
+ import { connectBindings } from '@/server/routes/connect';
34
35
 
35
36
  const allBindings: HandlerBinding[] = [
36
37
  ...authBindings,
@@ -61,6 +62,7 @@ const allBindings: HandlerBinding[] = [
61
62
  ...pluginsBindings,
62
63
  ...healthBindings,
63
64
  ...notificationsBindings,
65
+ ...connectBindings,
64
66
  ...wellKnownBindings,
65
67
  ];
66
68
 
@@ -19,7 +19,7 @@ import { clearSessionFileCaches } from '@/server/lib/omp/session/files';
19
19
  import { getSessionChangeDiff, getSessionChanges } from '@/server/routes/sessions/changes';
20
20
 
21
21
  const SESSION_ID = '01a0cc50-fd62-7417-899c-e24ff8c8608c';
22
- const CWD = '/tmp/project';
22
+ let CWD = '';
23
23
  let agentDir = '';
24
24
  let journalDir = '';
25
25
 
@@ -34,6 +34,10 @@ function args(sessionId: string | undefined, query = ''): LoaderFunctionArgs {
34
34
  beforeAll(async () => {
35
35
  agentDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'omp-changes-route-'));
36
36
  process.env.PI_CODING_AGENT_DIR = agentDir;
37
+ CWD = path.join(agentDir, 'project');
38
+ await fsp.mkdir(CWD, { recursive: true });
39
+ // The list drops a creation whose file is gone, so the kept one must exist.
40
+ await fsp.writeFile(path.join(CWD, 'a.ts'), 'one\n');
37
41
  const cwdDir = path.join(agentDir, 'sessions', '-tmp-project');
38
42
  await fsp.mkdir(cwdDir, { recursive: true });
39
43
  const sessionFile = path.join(cwdDir, `2026-01-01T00-00-00-000Z_${SESSION_ID}.jsonl`);
@@ -47,7 +51,12 @@ beforeAll(async () => {
47
51
  await fsp.writeFile(path.join(journalDir, 'blobs', after), Bun.gzipSync(Buffer.from('one\n', 'utf8')));
48
52
  await fsp.writeFile(
49
53
  path.join(journalDir, 'changes.jsonl'),
50
- `${JSON.stringify({ type: 'change', at: 1000, agent: 'Main', tool: 'write', path: `${CWD}/a.ts`, before: null, after })}\n`,
54
+ [
55
+ JSON.stringify({ type: 'change', at: 1000, agent: 'Main', tool: 'write', path: `${CWD}/a.ts`, before: null, after }),
56
+ // Created then `rm`'d: the journal has no delete record, so the list must
57
+ // drop it by checking the path.
58
+ JSON.stringify({ type: 'change', at: 1001, agent: 'Main', tool: 'write', path: `${CWD}/gone.ts`, before: null, after }),
59
+ ].join('\n') + '\n',
51
60
  );
52
61
  clearSessionFileCaches();
53
62
  });
@@ -59,7 +68,7 @@ afterAll(async () => {
59
68
  });
60
69
 
61
70
  describe('getSessionChanges', () => {
62
- test('answers the records for a real session', async () => {
71
+ test('answers the records for a real session, minus a creation whose file is gone', async () => {
63
72
  const response = (await getSessionChanges(args(SESSION_ID))) as Response;
64
73
  expect(response.status).toBe(200);
65
74
  const body = (await response.json()) as { records: Array<{ displayPath: string }> };
@@ -9,12 +9,18 @@
9
9
  * GET /api/sessions/:sessionId/changes
10
10
  * Every `change` record, oldest first, with a display path. No blob
11
11
  * content: the client buckets records into runs and only asks for a diff
12
- * when a file is clicked.
12
+ * when a file is clicked. A creation whose file is gone is dropped — a
13
+ * `bash rm` never reaches the journal, so the run's list would otherwise
14
+ * count a file that no longer exists.
13
15
  *
14
16
  * GET /api/sessions/:sessionId/changes/diff?path=<abs>&from=<ms>&to=<ms>
15
17
  * The net change of one path inside one run window: the first record's
16
18
  * `before` and the last record's `after`, plus a unified patch.
17
19
  *
20
+ * GET /api/sessions/:sessionId/changes/stats?from=<ms>&to=<ms>
21
+ * The same net change as `+`/`−` line counts for every path in the window,
22
+ * so the run's file summary can print the totals without opening a diff.
23
+ *
18
24
  * A session with no journal (older omp, or no artifacts directory) answers an
19
25
  * empty list — a normal state, not an error. The diff read answers 404 when the
20
26
  * path has no record in the range, so a stale click reports the real problem.
@@ -23,14 +29,14 @@
23
29
  import { json } from '@/server/lib/remix-compat';
24
30
  import type { LoaderFunctionArgs } from '@/server/lib/remix-compat';
25
31
  import { isSinglePathSegment } from '@/server/lib/fs/path-segment';
26
- import { readSessionChangeDiff, readSessionChangeIndex } from '@/server/lib/omp/session/changes';
32
+ import { readSessionChangeDiff, readSessionChangeList, readSessionChangeStats } from '@/server/lib/omp/session/changes';
27
33
 
28
34
  /** GET /api/sessions/:sessionId/changes */
29
35
  export async function getSessionChanges({ params }: LoaderFunctionArgs) {
30
36
  const sessionId = params.sessionId;
31
37
  if (!sessionId) return json({ error: 'Missing session id' }, { status: 400 });
32
38
  if (!isSinglePathSegment(sessionId)) return json({ error: 'Session not found' }, { status: 404 });
33
- return json({ sessionId, records: await readSessionChangeIndex(sessionId) });
39
+ return json({ sessionId, records: await readSessionChangeList(sessionId) });
34
40
  }
35
41
 
36
42
  /** GET /api/sessions/:sessionId/changes/diff */
@@ -53,3 +59,21 @@ export async function getSessionChangeDiff({ params, request }: LoaderFunctionAr
53
59
  if (!diff) return json({ error: 'No change for that path in the range' }, { status: 404 });
54
60
  return json({ success: true, ...diff });
55
61
  }
62
+
63
+ /** GET /api/sessions/:sessionId/changes/stats */
64
+ export async function getSessionChangeStats({ params, request }: LoaderFunctionArgs) {
65
+ const sessionId = params.sessionId;
66
+ if (!sessionId) return json({ error: 'Missing session id' }, { status: 400 });
67
+ if (!isSinglePathSegment(sessionId)) return json({ error: 'Session not found' }, { status: 404 });
68
+
69
+ const url = new URL(request.url);
70
+ const fromRaw = url.searchParams.get('from');
71
+ const toRaw = url.searchParams.get('to');
72
+ const from = fromRaw === null ? Number.NaN : Number(fromRaw);
73
+ const to = toRaw === null ? Number.NaN : Number(toRaw);
74
+ if (!Number.isFinite(from) || !Number.isFinite(to) || to < from) {
75
+ return json({ error: 'from and to are required' }, { status: 400 });
76
+ }
77
+
78
+ return json({ sessionId, files: await readSessionChangeStats(sessionId, from, to) });
79
+ }
@@ -21,7 +21,7 @@ import { getSessionRelations, updateSessionParent } from '@/server/routes/sessio
21
21
  import { forkSessionRoute } from '@/server/routes/sessions/fork';
22
22
  import { getSessionAnswer } from '@/server/routes/sessions/answer';
23
23
  import { getSessionMcp, probeSessionMcp, setSessionMcp } from '@/server/routes/sessions/mcp';
24
- import { getSessionChangeDiff, getSessionChanges } from '@/server/routes/sessions/changes';
24
+ import { getSessionChangeDiff, getSessionChanges, getSessionChangeStats } from '@/server/routes/sessions/changes';
25
25
 
26
26
  export const sessionsBindings: HandlerBinding[] = [
27
27
  ...bindingsFor(sessionsList, '/api/sessions/list'),
@@ -48,6 +48,7 @@ export const sessionsBindings: HandlerBinding[] = [
48
48
  // parameter name must stay `sessionId`.
49
49
  { method: 'GET', path: '/api/sessions/:sessionId/changes', handler: getSessionChanges },
50
50
  { method: 'GET', path: '/api/sessions/:sessionId/changes/diff', handler: getSessionChangeDiff },
51
+ { method: 'GET', path: '/api/sessions/:sessionId/changes/stats', handler: getSessionChangeStats },
51
52
  // The MCP list this session has, and the per-session switch. A static suffix
52
53
  // under the same `:sessionId` position, so the parameter name must stay
53
54
  // `sessionId` (Elysia requires one name per position).
@@ -0,0 +1,144 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The pairing payload's parser, which is the input to a request that hands out a
8
+ * credential.
9
+ *
10
+ * The cases worth pinning are the refusals: an expired code, a payload with no
11
+ * candidate, a version this build does not understand, and a link whose scheme
12
+ * is right but whose body is not. A parser that accepted any of them would let a
13
+ * stale QR enrol a device.
14
+ */
15
+
16
+ import { describe, expect, test } from 'bun:test';
17
+ import {
18
+ encodePairingFragment,
19
+ encodePairingPayload,
20
+ normalizeOrigin,
21
+ parsePairingFragment,
22
+ parsePairingLink,
23
+ parsePairingPayload,
24
+ PAIRING_VERSION,
25
+ type PairingPayload,
26
+ } from '@/shared/lib/connect/payload';
27
+
28
+ // Relative to the real clock: `encodePairingPayload` validates expiry against
29
+ // `Date.now()`, so a fixed timestamp turns this suite into a time bomb — it
30
+ // passed until the hardcoded date fell behind the runner's clock.
31
+ const NOW = Date.now();
32
+
33
+ function payload(overrides: Partial<PairingPayload> = {}): PairingPayload {
34
+ return {
35
+ v: PAIRING_VERSION,
36
+ pairingId: 'pair-1',
37
+ secret: 'secret-value',
38
+ serverId: 'server-1',
39
+ label: 'rajeb-macbook',
40
+ expiresAt: new Date(NOW + 120_000).toISOString(),
41
+ candidates: [
42
+ { kind: 'tailscale', url: 'https://node.tailnet.ts.net' },
43
+ { kind: 'lan', url: 'http://192.168.18.76:3000' },
44
+ ],
45
+ ...overrides,
46
+ };
47
+ }
48
+
49
+ describe('encodePairingPayload / parsePairingPayload', () => {
50
+ test('round-trips every field', () => {
51
+ const parsed = parsePairingPayload(encodePairingPayload(payload()), NOW);
52
+ expect(parsed).toEqual(payload());
53
+ });
54
+
55
+ test('refuses an expired payload', () => {
56
+ // The encoder refuses to MINT an expired code, so expiry is measured where
57
+ // it is decided: the parser, given a clock past the payload's own deadline.
58
+ const link = encodePairingPayload(payload());
59
+ expect(parsePairingPayload(link, NOW + 10 * 60_000)).toBeNull();
60
+ });
61
+
62
+ test('refuses to mint a payload with no usable candidate', () => {
63
+ // A code with no route would scan successfully and then fail every probe,
64
+ // which reads as a broken camera rather than a missing tunnel.
65
+ expect(() => encodePairingPayload(payload({ candidates: [] }))).toThrow('Invalid pairing payload');
66
+ });
67
+
68
+ test('refuses a link with the wrong scheme', () => {
69
+ const link = encodePairingPayload(payload()).replace('kabmo://', 'https://');
70
+ expect(parsePairingPayload(link, NOW)).toBeNull();
71
+ });
72
+
73
+ test('refuses a body that is not JSON', () => {
74
+ expect(parsePairingPayload('kabmo://connect?v=1&p=bm90LWpzb24', NOW)).toBeNull();
75
+ });
76
+
77
+ test('refuses a version this build does not understand', () => {
78
+ const link = encodePairingPayload(payload()).replace('v=1', 'v=2');
79
+ expect(parsePairingPayload(link, NOW)).toBeNull();
80
+ });
81
+
82
+ test('drops a candidate whose URL is not an http origin', () => {
83
+ const link = encodePairingPayload(
84
+ payload({
85
+ candidates: [
86
+ { kind: 'lan', url: 'ftp://192.168.18.76' },
87
+ { kind: 'tailscale', url: 'https://node.tailnet.ts.net' },
88
+ ],
89
+ }),
90
+ );
91
+ expect(parsePairingPayload(link, NOW)?.candidates).toEqual([
92
+ { kind: 'tailscale', url: 'https://node.tailnet.ts.net' },
93
+ ]);
94
+ });
95
+ });
96
+
97
+ describe('normalizeOrigin', () => {
98
+ test('strips a path, a query and a trailing slash', () => {
99
+ expect(normalizeOrigin('https://node.ts.net/some/path?x=1')).toBe('https://node.ts.net');
100
+ });
101
+
102
+ test('keeps a non-default port', () => {
103
+ expect(normalizeOrigin('http://192.168.18.76:3000/')).toBe('http://192.168.18.76:3000');
104
+ });
105
+
106
+ test('refuses a non-http scheme', () => {
107
+ expect(normalizeOrigin('ws://node.ts.net')).toBeNull();
108
+ });
109
+ });
110
+
111
+ describe('parsePairingLink', () => {
112
+ test('reads the browser form the QR actually encodes', () => {
113
+ const fragment = encodePairingFragment(payload());
114
+ const parsed = parsePairingLink(`https://node.tailnet.ts.net/pair#${fragment}`, NOW);
115
+ expect(parsed?.pairingId).toBe('pair-1');
116
+ expect(parsed?.candidates).toHaveLength(2);
117
+ });
118
+
119
+ test('reads the deep link a native shell registers', () => {
120
+ const parsed = parsePairingLink(encodePairingPayload(payload()), NOW);
121
+ expect(parsed?.pairingId).toBe('pair-1');
122
+ });
123
+
124
+ test('refuses a link with no fragment', () => {
125
+ expect(parsePairingLink('https://node.tailnet.ts.net/pair', NOW)).toBeNull();
126
+ });
127
+
128
+ test('refuses a fragment that is not a payload', () => {
129
+ expect(parsePairingLink('https://node.tailnet.ts.net/pair#not-base64', NOW)).toBeNull();
130
+ });
131
+
132
+ test('refuses an expired code carried in a fragment', () => {
133
+ const fragment = encodePairingFragment(payload());
134
+ expect(parsePairingLink(`https://node.tailnet.ts.net/pair#${fragment}`, NOW + 10 * 60_000)).toBeNull();
135
+ });
136
+ });
137
+
138
+ describe('parsePairingFragment', () => {
139
+ test('accepts the fragment with or without its leading hash', () => {
140
+ const fragment = encodePairingFragment(payload());
141
+ expect(parsePairingFragment(fragment, NOW)?.pairingId).toBe('pair-1');
142
+ expect(parsePairingFragment(`#${fragment}`, NOW)?.pairingId).toBe('pair-1');
143
+ });
144
+ });