@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.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +785 -624
- package/dist/client/static/js/{CsvGrid-fncjbg6j.js → CsvGrid-vze4m5ag.js} +1 -1
- package/dist/client/static/js/{DocxView-c9v2vr3r.js → DocxView-jbf21gmh.js} +5 -5
- package/dist/client/static/js/{DrawioView-vxjksm12.js → DrawioView-b52qybx5.js} +2 -2
- package/dist/client/static/js/{ImageView-a3g5k226.js → ImageView-mdgzj8px.js} +1 -1
- package/dist/client/static/js/{LayoutWrapper-hnjfwsjh.js → LayoutWrapper-3c49dvtt.js} +2 -2
- package/dist/client/static/js/Modal-sqp864vd.js +38 -0
- package/dist/client/static/js/{PdfView-ksaes53y.js → PdfView-g06rxqb1.js} +1 -1
- package/dist/client/static/js/{SessionsView-30vcr95v.js → SessionsView-521adxyr.js} +1 -1
- package/dist/client/static/js/{SheetView-vc484scg.js → SheetView-h8xmsz7q.js} +22 -22
- package/dist/client/static/js/{SvgPreview-tph89jet.js → SvgPreview-1j4jvcvz.js} +1 -1
- package/dist/client/static/js/{abnfDiagram-O67JEVCF-xbar278c.js → abnfDiagram-O67JEVCF-pasxh4b6.js} +1 -1
- package/dist/client/static/js/architecture-7GRP2DOG-fc9kmq1w.js +1 -0
- package/dist/client/static/js/{architectureDiagram-NJMV4G6O-s171n2z6.js → architectureDiagram-NJMV4G6O-ms14g0bm.js} +4 -4
- package/dist/client/static/js/{blockDiagram-BEXU5L5S-gzx6rv9n.js → blockDiagram-BEXU5L5S-ycn78fcq.js} +4 -4
- package/dist/client/static/js/{c4Diagram-YGBWAQC7-7f00skch.js → c4Diagram-YGBWAQC7-vn2gpjfm.js} +5 -5
- package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-j79v95nc.js → classDiagram-v2-NBCMYWYE-fyrm1pr5.js} +4 -4
- package/dist/client/static/js/{cose-bilkent-JH36ORCC-5fkn7ee5.js → cose-bilkent-JH36ORCC-ea5nwvgq.js} +1 -1
- package/dist/client/static/js/cynefin-OW5HDTMX-a4t8992q.js +1 -0
- package/dist/client/static/js/{cynefinDiagram-VND7K2PF-cfs1yvrd.js → cynefinDiagram-VND7K2PF-j6bsjpre.js} +1 -1
- package/dist/client/static/js/{dagre-6A5THRUB-44bgc48p.js → dagre-6A5THRUB-4smdkwv8.js} +2 -2
- package/dist/client/static/js/{diagram-22UHCM2B-a4g4x83k.js → diagram-22UHCM2B-9sm4kqwc.js} +11 -11
- package/dist/client/static/js/{diagram-3UASUU5V-gm4rg5na.js → diagram-3UASUU5V-2h3qxaed.js} +1 -1
- package/dist/client/static/js/{diagram-ATOU4E4O-a95y41vk.js → diagram-ATOU4E4O-1981bc94.js} +3 -3
- package/dist/client/static/js/{diagram-CDSNMT55-t3j93mmc.js → diagram-CDSNMT55-3vgsxavc.js} +4 -4
- package/dist/client/static/js/{diagram-MLGK6HIB-c2wdez02.js → diagram-MLGK6HIB-c9gf2r3f.js} +2 -2
- package/dist/client/static/js/{diagram-MPIPVDR6-gya9jhs5.js → diagram-MPIPVDR6-gjqeq92d.js} +2 -2
- package/dist/client/static/js/{dockerfile-a7q6174s.js → dockerfile-8v935dkn.js} +1 -1
- package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-jjhkza6t.js → ebnfDiagram-ZINNZB2B-4vbsgh99.js} +1 -1
- package/dist/client/static/js/{elixir-rpa1g4gy.js → elixir-vcbg60wv.js} +1 -1
- package/dist/client/static/js/{elk-276RUBZZ-f7re45mw.js → elk-276RUBZZ-nca3t891.js} +1 -1
- package/dist/client/static/js/{erDiagram-OPXOYQCR-tpm9g5te.js → erDiagram-OPXOYQCR-5kfkev03.js} +2 -2
- package/dist/client/static/js/eventmodeling-NTZA5JFV-18bdrkv5.js +1 -0
- package/dist/client/static/js/flowDiagram-KWPJA3E3-fg0yqx0h.js +1 -0
- package/dist/client/static/js/{ganttDiagram-FUAMR5RP-fz43n12d.js → ganttDiagram-FUAMR5RP-mxc73wmq.js} +3 -3
- package/dist/client/static/js/gitGraph-4MIJSDKK-8fa6y40p.js +1 -0
- package/dist/client/static/js/{gitGraphDiagram-X574FWY7-f61hgbn6.js → gitGraphDiagram-X574FWY7-7en3ag0e.js} +12 -12
- package/dist/client/static/js/html-dbrwss36.js +1 -0
- package/dist/client/static/js/{index-m73za75e.js → index-0vm41je9.js} +3 -3
- package/dist/client/static/js/{index-eyzeya95.js → index-1b0t1428.js} +5 -5
- package/dist/client/static/js/{index-2x5f66t6.js → index-1ksg88qf.js} +1 -1
- package/dist/client/static/js/{index-sffjtm5w.js → index-231241f4.js} +9 -9
- package/dist/client/static/js/index-2mx9ej4k.css +1 -0
- package/dist/client/static/js/{index-8239j2v1.js → index-4g46wbdw.js} +1 -1
- package/dist/client/static/js/{index-1xqs14fr.js → index-4qwzxj81.js} +1 -1
- package/dist/client/static/js/{index-gcs49f3p.js → index-52rqxgya.js} +1 -1
- package/dist/client/static/js/{index-at6bhjyf.js → index-6sf2vsp2.js} +1 -1
- package/dist/client/static/js/{index-q2w6s8n7.js → index-7a64yjrm.js} +4 -4
- package/dist/client/static/js/{index-rg8jpbsw.js → index-8acv5b77.js} +2 -2
- package/dist/client/static/js/{index-js7t1vb1.js → index-a0fmsv1d.js} +5 -5
- package/dist/client/static/js/{index-w0fwb80e.js → index-ag2rmtas.js} +1 -1
- package/dist/client/static/js/{index-djmg1d7h.js → index-b29afsjh.js} +1 -1
- package/dist/client/static/js/{index-e4p4cd3r.js → index-c3ek61zv.js} +1 -1
- package/dist/client/static/js/{index-0e40xskg.js → index-cd65zqba.js} +1 -1
- package/dist/client/static/js/{index-zt75xpq0.js → index-cgzrpvzj.js} +204 -204
- package/dist/client/static/js/{index-0n5wwe60.js → index-ev3yt353.js} +2 -2
- package/dist/client/static/js/{index-9y3gjdj7.js → index-eyfcm0cy.js} +1 -1
- package/dist/client/static/js/{index-qsm2z36d.js → index-f7jhhqtk.js} +1 -1
- package/dist/client/static/js/{index-vw5k8csz.js → index-fta1y9pc.js} +50 -50
- package/dist/client/static/js/{index-ajs3jj6j.js → index-fvmfge3p.js} +1 -1
- package/dist/client/static/js/{index-pxv2nw9w.js → index-g2dyfze9.js} +1 -1
- package/dist/client/static/js/{index-bkye8mz4.js → index-h5bn97p6.js} +1 -1
- package/dist/client/static/js/{index-trm9x02n.js → index-j51d5a5m.js} +6 -6
- package/dist/client/static/js/{index-pbe4yed4.js → index-jsyekbx9.js} +2 -2
- package/dist/client/static/js/{index-gs6f0qwa.js → index-nccwxv0s.js} +2 -2
- package/dist/client/static/js/{index-d495kfm0.js → index-p0nz38bm.js} +1 -1
- package/dist/client/static/js/{index-sdtye3jy.js → index-pm6xxwz1.js} +2 -2
- package/dist/client/static/js/{index-3rcjx70v.js → index-ptcrwswj.js} +1 -1
- package/dist/client/static/js/{index-14vndmcr.js → index-ptcwae2n.js} +1 -1
- package/dist/client/static/js/{index-5tgq7aqx.js → index-r014brzs.js} +2 -2
- package/dist/client/static/js/{index-xj9649ac.js → index-ray2czf6.js} +7 -7
- package/dist/client/static/js/{index-apvkd37e.js → index-rs80cwsv.js} +3 -3
- package/dist/client/static/js/{index-vw4brsdx.js → index-rzxcj7cg.js} +1 -1
- package/dist/client/static/js/{index-a293pdg7.js → index-s7gkkkyz.js} +2 -2
- package/dist/client/static/js/{index-1a0zkj8h.js → index-sd66wv26.js} +2 -2
- package/dist/client/static/js/{index-ypx3qmhq.js → index-vhqe0y82.js} +1 -1
- package/dist/client/static/js/{index-9fjt5anh.js → index-vy6termr.js} +1 -1
- package/dist/client/static/js/{index-0tf0arsp.js → index-xx6mqpxm.js} +3 -3
- package/dist/client/static/js/{index-03h3bkcf.js → index-ybm2x4vh.js} +1 -1
- package/dist/client/static/js/info-A6RAGUB7-3hk844f7.js +1 -0
- package/dist/client/static/js/{infoDiagram-VRGFBTTK-1qj804sn.js → infoDiagram-VRGFBTTK-sef80132.js} +2 -2
- package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-4j4qsnzw.js → ishikawaDiagram-OU5B5YK6-yhvepp1q.js} +6 -6
- package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-j0brnfft.js → journeyDiagram-ZHPQQLJL-5w77y95w.js} +5 -5
- package/dist/client/static/js/{julia-4ghmfy3e.js → julia-d4j6wgvf.js} +1 -1
- package/dist/client/static/js/{kanban-definition-PNTS6WVX-qqc22br0.js → kanban-definition-PNTS6WVX-02znqtna.js} +6 -6
- package/dist/client/static/js/{mermaid.core-vv3wbe65.js → mermaid.core-a6e6vck4.js} +5 -5
- package/dist/client/static/js/{mindmap-definition-NLK3R4M7-y5b2z8zp.js → mindmap-definition-NLK3R4M7-y4n74q9x.js} +8 -8
- package/dist/client/static/js/one-dark-pro-vwhfpzr8.js +1 -0
- package/dist/client/static/js/one-light-y5t9x6zh.js +1 -0
- package/dist/client/static/js/packet-AYTQ26CC-4nj2yy10.js +1 -0
- package/dist/client/static/js/{pegDiagram-GJSIUBJH-0be07mqs.js → pegDiagram-GJSIUBJH-pr7ehgzb.js} +1 -1
- package/dist/client/static/js/{perl-sd00t4b4.js → perl-srptw5vm.js} +1 -1
- package/dist/client/static/js/{php-2zfyqa61.js → php-n89g3fk7.js} +1 -1
- package/dist/client/static/js/pie-WAS4IAKB-k7rde3f9.js +1 -0
- package/dist/client/static/js/{pieDiagram-5QR66LMP-544w86jk.js → pieDiagram-5QR66LMP-39wpsk08.js} +2 -2
- package/dist/client/static/js/{quadrantDiagram-O4NWA36T-p09e7z5s.js → quadrantDiagram-O4NWA36T-esm913km.js} +5 -5
- package/dist/client/static/js/radar-RG4KPBEZ-513dpw4f.js +1 -0
- package/dist/client/static/js/railroad-74A4TZTK-9bqnst9c.js +1 -0
- package/dist/client/static/js/railroad-abnf-HS5TGJTU-7367d5bv.js +1 -0
- package/dist/client/static/js/railroad-ebnf-LZEXJU2U-b806b1mj.js +1 -0
- package/dist/client/static/js/railroad-peg-WCYAUIDC-5a67rwf8.js +1 -0
- package/dist/client/static/js/{railroadDiagram-XR7U4H2S-de830ed2.js → railroadDiagram-XR7U4H2S-wy2mgya6.js} +1 -1
- package/dist/client/static/js/{requirementDiagram-PLB6GJNP-b47d74p1.js → requirementDiagram-PLB6GJNP-6z9xdgbq.js} +2 -2
- package/dist/client/static/js/{ruby-v9qaqhby.js → ruby-r81ytgcm.js} +1 -1
- package/dist/client/static/js/{rust-fkt0qyrs.js → rust-frn3szvc.js} +1 -1
- package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-6ezc2fpj.js → sankeyDiagram-IPEJSGJF-rtmxk3ys.js} +4 -4
- package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-by5zqj6w.js → sequenceDiagram-PO4LG4MO-awzcrafg.js} +18 -18
- package/dist/client/static/js/{sizeCapture-INFHLROL-q85r06j6.js → sizeCapture-INFHLROL-03gy196j.js} +1 -1
- package/dist/client/static/js/sql-0e9mnrda.js +1 -0
- package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-ep5pyexs.js → stateDiagram-v2-GCMORJYK-an8v3q5n.js} +3 -3
- package/dist/client/static/js/{swimlanes-2SLR337P-95fcqkh8.js → swimlanes-2SLR337P-n9yb4wcs.js} +1 -1
- package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-xs2en5dv.js → swimlanesDiagram-TC7HE7FX-nx5nfnf0.js} +1 -1
- package/dist/client/static/js/{timeline-definition-EJHVYXUP-461e615g.js → timeline-definition-EJHVYXUP-jceb575g.js} +4 -4
- package/dist/client/static/js/treeView-Q6P3EWNA-kcy40evb.js +1 -0
- package/dist/client/static/js/treemap-WGGIJYW6-fsrvqxf4.js +1 -0
- package/dist/client/static/js/{usecaseDiagram-POWQR4AR-ftqfnvhg.js → usecaseDiagram-POWQR4AR-888h3100.js} +13 -13
- package/dist/client/static/js/{vennDiagram-UO4OBE2U-7t96h6ez.js → vennDiagram-UO4OBE2U-wbfz0rzv.js} +7 -7
- package/dist/client/static/js/{vue-j8vb9d7r.js → vue-c0rtg1wf.js} +1 -1
- package/dist/client/static/js/wardley-WFR3VGLG-36dmxww4.js +1 -0
- package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-0de8w8c6.js → wardleyDiagram-VNRHLVJA-rn8c5qf9.js} +4 -4
- package/dist/client/static/js/{xychartDiagram-PMCCYNJV-dez9phkf.js → xychartDiagram-PMCCYNJV-8sn1apt6.js} +5 -5
- package/package.json +4 -1
- package/src/client/components/auth/login-screen/index.tsx +1 -0
- package/src/client/components/common/MarkdownRenderer.tsx +9 -12
- package/src/client/components/settings/Modal.tsx +14 -84
- package/src/client/components/settings/Sidebar.tsx +3 -1
- package/src/client/components/settings/categories/ConnectSettings.tsx +105 -0
- package/src/client/components/settings/categories/connect-settings/DeviceTable.tsx +145 -0
- package/src/client/components/settings/categories/connect-settings/PairDialog.tsx +160 -0
- package/src/client/components/settings/categories/connect-settings/QrCode.tsx +73 -0
- package/src/client/components/settings/categories/connect-settings/ServerCard.tsx +94 -0
- package/src/client/components/settings/categories/connect-settings/TunnelRow.tsx +127 -0
- package/src/client/components/settings/category-content.tsx +116 -0
- package/src/client/components/workspace/chat-timeline/ChangedFilesSummary.test.tsx +120 -0
- package/src/client/components/workspace/chat-timeline/ChangedFilesSummary.tsx +56 -20
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +1 -0
- package/src/client/hooks/chat/timeline/change-stats.ts +57 -0
- package/src/client/hooks/connect/use-connect-status.ts +116 -0
- package/src/client/hooks/connect/use-pairing.ts +100 -0
- package/src/client/hooks/ui/clipboard.ts +26 -0
- package/src/client/tailwind.css +5 -0
- package/src/server/index.ts +2 -0
- package/src/server/lib/assets/font-css.server.test.ts +19 -0
- package/src/server/lib/auth/client-address.test.ts +58 -0
- package/src/server/lib/auth/client-address.ts +37 -3
- package/src/server/lib/auth/guard.ts +31 -4
- package/src/server/lib/auth/rate-limit.test.ts +25 -8
- package/src/server/lib/auth/rate-limit.ts +8 -5
- package/src/server/lib/connect/cloudflared.lifecycle.test.ts +88 -0
- package/src/server/lib/connect/cloudflared.server.test.ts +65 -0
- package/src/server/lib/connect/cloudflared.server.ts +206 -0
- package/src/server/lib/connect/devices.server.ts +192 -0
- package/src/server/lib/connect/identity.server.ts +81 -0
- package/src/server/lib/connect/pairing.server.test.ts +56 -0
- package/src/server/lib/connect/pairing.server.ts +113 -0
- package/src/server/lib/connect/qr.roundtrip.test.ts +106 -0
- package/src/server/lib/connect/qr.server.ts +36 -0
- package/src/server/lib/connect/run.server.ts +101 -0
- package/src/server/lib/connect/status.server.ts +177 -0
- package/src/server/lib/connect/tailscale.server.test.ts +117 -0
- package/src/server/lib/connect/tailscale.server.ts +172 -0
- package/src/server/lib/db/schema.ts +4 -0
- package/src/server/lib/omp/session/changes.test.ts +64 -1
- package/src/server/lib/omp/session/changes.ts +94 -1
- package/src/server/routes/connect/devices.ts +56 -0
- package/src/server/routes/connect/index.ts +15 -0
- package/src/server/routes/connect/pair-page.ts +177 -0
- package/src/server/routes/connect/pair.ts +158 -0
- package/src/server/routes/connect/status.ts +19 -0
- package/src/server/routes/connect/tunnels.ts +76 -0
- package/src/server/routes/health/probe.ts +5 -0
- package/src/server/routes/index.ts +2 -0
- package/src/server/routes/sessions/changes.test.ts +12 -3
- package/src/server/routes/sessions/changes.ts +27 -3
- package/src/server/routes/sessions/index.ts +2 -1
- package/src/shared/lib/connect/payload.test.ts +144 -0
- package/src/shared/lib/connect/payload.ts +229 -0
- package/src/shared/lib/connect/tier.test.ts +73 -0
- package/src/shared/lib/connect/tier.ts +105 -0
- package/src/shared/lib/connect/types.ts +99 -0
- package/src/shared/lib/markdown/fira-code-fonts.css +65 -6
- package/src/shared/lib/markdown/marked.ts +7 -4
- package/src/shared/lib/markdown/mermaid-actions.test.ts +78 -0
- package/src/shared/lib/markdown/mermaid-actions.ts +45 -0
- package/src/shared/lib/markdown/mermaid.ts +41 -7
- package/src/shared/lib/settings/sections.ts +6 -1
- package/src/shared/types/session-changes.ts +6 -0
- package/src/shared/types/settings/state.ts +2 -0
- package/dist/client/static/js/Modal-qtftcp2t.js +0 -38
- package/dist/client/static/js/architecture-7GRP2DOG-tavtgb8a.js +0 -1
- package/dist/client/static/js/cynefin-OW5HDTMX-cdh3n2z2.js +0 -1
- package/dist/client/static/js/eventmodeling-NTZA5JFV-as97tpyp.js +0 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-ggm06d12.js +0 -1
- package/dist/client/static/js/gitGraph-4MIJSDKK-eqz7p9ng.js +0 -1
- package/dist/client/static/js/html-pv88ny12.js +0 -1
- package/dist/client/static/js/index-e94a1en0.css +0 -1
- package/dist/client/static/js/info-A6RAGUB7-4pkzh1qx.js +0 -1
- package/dist/client/static/js/one-dark-pro-hm3f56n1.js +0 -1
- package/dist/client/static/js/one-light-xrz49rct.js +0 -1
- package/dist/client/static/js/packet-AYTQ26CC-yg71sp88.js +0 -1
- package/dist/client/static/js/pie-WAS4IAKB-89wd6np0.js +0 -1
- package/dist/client/static/js/radar-RG4KPBEZ-avn0b8r9.js +0 -1
- package/dist/client/static/js/railroad-74A4TZTK-de27xv5w.js +0 -1
- package/dist/client/static/js/railroad-abnf-HS5TGJTU-rg4zzj7x.js +0 -1
- package/dist/client/static/js/railroad-ebnf-LZEXJU2U-d84fhj8v.js +0 -1
- package/dist/client/static/js/railroad-peg-WCYAUIDC-dvf8xrmc.js +0 -1
- package/dist/client/static/js/sql-g8wcshpc.js +0 -1
- package/dist/client/static/js/treeView-Q6P3EWNA-mham0bh6.js +0 -1
- package/dist/client/static/js/treemap-WGGIJYW6-mxrxax86.js +0 -1
- package/dist/client/static/js/wardley-WFR3VGLG-8vrvh9p3.js +0 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Tailscale Serve, driven through the CLI the user already has.
|
|
8
|
+
*
|
|
9
|
+
* Serve is the preferred route for a reason that is not speed: it terminates TLS
|
|
10
|
+
* on THIS machine with a certificate the platform already trusts, so every shell
|
|
11
|
+
* accepts it without pinning, and the origin becomes a secure context — which is
|
|
12
|
+
* what brings back `getUserMedia` (dictation), `navigator.clipboard.readText`,
|
|
13
|
+
* `serviceWorker` and `crypto.subtle`. On the same network it is still a direct
|
|
14
|
+
* WireGuard peer connection, so it costs a fraction of a millisecond over the
|
|
15
|
+
* LAN address it replaces.
|
|
16
|
+
*
|
|
17
|
+
* Two facts about the CLI shape everything here:
|
|
18
|
+
*
|
|
19
|
+
* - `tailscale serve` proxies only to `http://127.0.0.1`, so Kabmo does NOT need
|
|
20
|
+
* `--lan` for this route. The listener stays on loopback.
|
|
21
|
+
* - The macOS App Store and Standalone variants ship the CLI inside the app
|
|
22
|
+
* bundle rather than on PATH, so a `Bun.which` miss is not "not installed".
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import os from 'os';
|
|
26
|
+
import { run, which } from '@/server/lib/connect/run.server';
|
|
27
|
+
|
|
28
|
+
/** Where the macOS app variants keep the CLI when it is not on PATH. */
|
|
29
|
+
const MACOS_APP_CLI = '/Applications/Tailscale.app/Contents/MacOS/Tailscale';
|
|
30
|
+
|
|
31
|
+
/** The HTTPS port Serve listens on. 443 is the default and the one we use. */
|
|
32
|
+
export const TAILSCALE_HTTPS_PORT = 443;
|
|
33
|
+
|
|
34
|
+
export interface TailscalePresence {
|
|
35
|
+
/** Absolute path to the CLI, or null when it cannot be found. */
|
|
36
|
+
binary: string | null;
|
|
37
|
+
/** Why it is absent, in one sentence, when it is. */
|
|
38
|
+
reason: string | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface TailscaleNode {
|
|
42
|
+
/** `https://<node>.<tailnet>.ts.net`, or null when the node has no name yet. */
|
|
43
|
+
url: string | null;
|
|
44
|
+
/** The node's own tailnet addresses, IPv4 first. */
|
|
45
|
+
addresses: string[];
|
|
46
|
+
/** `Running`, `Stopped`, `NeedsLogin`, … as the daemon reports it. */
|
|
47
|
+
backendState: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Locate the CLI, including the macOS app bundle. */
|
|
51
|
+
export function findTailscale(): TailscalePresence {
|
|
52
|
+
const onPath = which('tailscale');
|
|
53
|
+
if (onPath) return { binary: onPath, reason: null };
|
|
54
|
+
if (process.platform === 'darwin') {
|
|
55
|
+
try {
|
|
56
|
+
if (Bun.file(MACOS_APP_CLI).size > 0) return { binary: MACOS_APP_CLI, reason: null };
|
|
57
|
+
} catch {
|
|
58
|
+
// Not installed as an app either.
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
binary: null,
|
|
63
|
+
reason: 'The tailscale command was not found. Install Tailscale, or add its CLI to PATH.',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface StatusJson {
|
|
68
|
+
BackendState?: unknown;
|
|
69
|
+
Self?: {
|
|
70
|
+
DNSName?: unknown;
|
|
71
|
+
TailscaleIPs?: unknown;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The node's own identity, or null when the daemon cannot answer.
|
|
77
|
+
*
|
|
78
|
+
* `status --json` blocks against a stopped daemon, which is why the spawn has a
|
|
79
|
+
* timeout: a settings page must render "not running" rather than hang.
|
|
80
|
+
*/
|
|
81
|
+
export async function tailscaleNode(binary: string): Promise<TailscaleNode | null> {
|
|
82
|
+
const result = await run([binary, 'status', '--json'], { timeoutMs: 4_000 });
|
|
83
|
+
if (!result.ok) return null;
|
|
84
|
+
let parsed: StatusJson;
|
|
85
|
+
try {
|
|
86
|
+
parsed = JSON.parse(result.stdout) as StatusJson;
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const dnsName = typeof parsed.Self?.DNSName === 'string' ? parsed.Self.DNSName.replace(/\.$/, '') : '';
|
|
92
|
+
const addresses = Array.isArray(parsed.Self?.TailscaleIPs)
|
|
93
|
+
? parsed.Self.TailscaleIPs.filter((value): value is string => typeof value === 'string')
|
|
94
|
+
: [];
|
|
95
|
+
return {
|
|
96
|
+
url: dnsName ? `https://${dnsName}` : null,
|
|
97
|
+
addresses,
|
|
98
|
+
backendState: typeof parsed.BackendState === 'string' ? parsed.BackendState : 'Unknown',
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Whether Serve is currently sharing the HTTPS port. */
|
|
103
|
+
export async function serveIsUp(binary: string): Promise<boolean> {
|
|
104
|
+
const result = await run([binary, 'serve', 'status', '--json'], { timeoutMs: 4_000 });
|
|
105
|
+
if (!result.ok) return false;
|
|
106
|
+
try {
|
|
107
|
+
const parsed = JSON.parse(result.stdout) as Record<string, unknown>;
|
|
108
|
+
// The shape is `{ TCP: { "443": { HTTPS: true } }, Web: {...} }`; a non-empty
|
|
109
|
+
// object at either key means something is being served.
|
|
110
|
+
const tcp = parsed.TCP;
|
|
111
|
+
const web = parsed.Web;
|
|
112
|
+
const hasTcp = typeof tcp === 'object' && tcp !== null && Object.keys(tcp).length > 0;
|
|
113
|
+
const hasWeb = typeof web === 'object' && web !== null && Object.keys(web).length > 0;
|
|
114
|
+
return hasTcp || hasWeb;
|
|
115
|
+
} catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Share `port` on the tailnet.
|
|
122
|
+
*
|
|
123
|
+
* `--bg` is what makes it survive a reboot and a `tailscale down`/`up`; without
|
|
124
|
+
* it the share dies with the process that started it, which for a server that
|
|
125
|
+
* restarts on update would mean the phone loses its route silently.
|
|
126
|
+
*/
|
|
127
|
+
export async function startServe(binary: string, port: number): Promise<{ ok: boolean; reason: string | null }> {
|
|
128
|
+
const result = await run(
|
|
129
|
+
[binary, 'serve', '--bg', '--yes', `--https=${TAILSCALE_HTTPS_PORT}`, `http://127.0.0.1:${port}`],
|
|
130
|
+
{ timeoutMs: 15_000 },
|
|
131
|
+
);
|
|
132
|
+
if (result.ok) return { ok: true, reason: null };
|
|
133
|
+
if (result.error?.startsWith('timed out')) {
|
|
134
|
+
return {
|
|
135
|
+
ok: false,
|
|
136
|
+
reason:
|
|
137
|
+
'Tailscale did not answer within 15 seconds. HTTPS may be disabled for this tailnet — enable it in the Tailscale admin console, then try again.',
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const detail = (result.stderr || result.stdout || result.error || '').trim();
|
|
141
|
+
return {
|
|
142
|
+
ok: false,
|
|
143
|
+
reason: detail
|
|
144
|
+
? `Tailscale refused: ${detail.split('\n')[0]}`
|
|
145
|
+
: 'Tailscale refused to share this port. HTTPS may be disabled for the tailnet.',
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Stop sharing the HTTPS port.
|
|
151
|
+
*
|
|
152
|
+
* `off` for the port we turned on, never `reset`: reset would also remove every
|
|
153
|
+
* other share the user configured by hand, which is not ours to remove.
|
|
154
|
+
*/
|
|
155
|
+
export async function stopServe(binary: string): Promise<{ ok: boolean; reason: string | null }> {
|
|
156
|
+
const result = await run(
|
|
157
|
+
[binary, 'serve', '--yes', `--https=${TAILSCALE_HTTPS_PORT}`, 'off'],
|
|
158
|
+
{ timeoutMs: 10_000 },
|
|
159
|
+
);
|
|
160
|
+
if (result.ok) return { ok: true, reason: null };
|
|
161
|
+
const detail = (result.stderr || result.stdout || result.error || '').trim();
|
|
162
|
+
return { ok: false, reason: detail ? detail.split('\n')[0] : 'Tailscale did not stop the share.' };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** The machine's display name, used as the server label in a pairing payload. */
|
|
166
|
+
export function machineLabel(): string {
|
|
167
|
+
try {
|
|
168
|
+
return os.hostname().replace(/\.local$/, '') || 'Kabmo';
|
|
169
|
+
} catch {
|
|
170
|
+
return 'Kabmo';
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -27,6 +27,7 @@ import { ensureSessionRelationsSchema } from '@/server/lib/sessions/schema.serve
|
|
|
27
27
|
import { ensurePromptHistorySchema } from '@/server/lib/chat/schema.server';
|
|
28
28
|
import { ensureSessionMcpSchema } from '@/server/lib/mcp/schema.server';
|
|
29
29
|
import { ensureNotificationSchema } from '@/server/lib/notifications/schema.server';
|
|
30
|
+
import { ensureConnectSchema } from '@/server/lib/connect/devices.server';
|
|
30
31
|
import { migrateWorkspaceFolderColumns } from '@/shared/lib/workspace/schema-migrations';
|
|
31
32
|
import { migrateSessionStreamStateColumns } from '@/shared/lib/omp/session/schema-migrations';
|
|
32
33
|
|
|
@@ -157,6 +158,9 @@ export async function initSchema(db: DbClient): Promise<void> {
|
|
|
157
158
|
// The system-notification outbox: written by the run settles, read by a page
|
|
158
159
|
// over the realtime socket and by the Android watcher over SSE.
|
|
159
160
|
await ensureNotificationSchema(db);
|
|
161
|
+
// Paired devices and their token hashes: the Connect page's list, and the
|
|
162
|
+
// credential the auth gate verifies on every request from a phone.
|
|
163
|
+
await ensureConnectSchema(db);
|
|
160
164
|
await db.exec(`
|
|
161
165
|
CREATE TABLE IF NOT EXISTS files (
|
|
162
166
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -18,7 +18,7 @@ import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
|
|
18
18
|
import * as fsp from 'node:fs/promises';
|
|
19
19
|
import * as os from 'node:os';
|
|
20
20
|
import * as path from 'node:path';
|
|
21
|
-
import { readSessionChangeDiff, readSessionChangeIndex } from '@/server/lib/omp/session/changes';
|
|
21
|
+
import { readSessionChangeDiff, readSessionChangeIndex, readSessionChangeList, readSessionChangeStats } from '@/server/lib/omp/session/changes';
|
|
22
22
|
import { clearSessionFileCaches } from '@/server/lib/omp/session/files';
|
|
23
23
|
|
|
24
24
|
const SESSION_ID = '01a0cc50-fd62-7417-899c-e24ff8c8608c';
|
|
@@ -136,3 +136,66 @@ describe('readSessionChangeDiff', () => {
|
|
|
136
136
|
expect(await readSessionChangeDiff(SESSION_ID, `${CWD}/src/net.ts`, 9000, 9001)).toBeNull();
|
|
137
137
|
});
|
|
138
138
|
});
|
|
139
|
+
|
|
140
|
+
describe('readSessionChangeList', () => {
|
|
141
|
+
test('drops a creation whose file is gone — a bash rm never reaches the journal', async () => {
|
|
142
|
+
const created = await blob('l1', 'gone\n');
|
|
143
|
+
const file = path.join(agentDir, 'gone.ts');
|
|
144
|
+
await append({ type: 'change', at: 6000, agent: 'Main', tool: 'write', path: file, before: null, after: created });
|
|
145
|
+
|
|
146
|
+
expect(await readSessionChangeIndex(SESSION_ID)).toContainEqual(
|
|
147
|
+
expect.objectContaining({ path: file }),
|
|
148
|
+
);
|
|
149
|
+
expect((await readSessionChangeList(SESSION_ID)).some((record) => record.path === file)).toBe(false);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('keeps a creation whose file still exists', async () => {
|
|
153
|
+
const created = await blob('l2', 'here\n');
|
|
154
|
+
const file = path.join(agentDir, 'here.ts');
|
|
155
|
+
await fsp.writeFile(file, 'here\n');
|
|
156
|
+
await append({ type: 'change', at: 6001, agent: 'Main', tool: 'write', path: file, before: null, after: created });
|
|
157
|
+
|
|
158
|
+
expect((await readSessionChangeList(SESSION_ID)).some((record) => record.path === file)).toBe(true);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('keeps a modified path even when the file is gone', async () => {
|
|
162
|
+
const before = await blob('l3', 'a\n');
|
|
163
|
+
const after = await blob('l4', 'b\n');
|
|
164
|
+
const file = path.join(agentDir, 'modified-gone.ts');
|
|
165
|
+
await append({ type: 'change', at: 6002, agent: 'Main', tool: 'edit', path: file, before, after });
|
|
166
|
+
|
|
167
|
+
expect((await readSessionChangeList(SESSION_ID)).some((record) => record.path === file)).toBe(true);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe('readSessionChangeStats', () => {
|
|
172
|
+
test('counts the net change of the run, not each write', async () => {
|
|
173
|
+
const before = await blob('s1', 'alpha\nbeta\n');
|
|
174
|
+
const middle = await blob('s2', 'alpha\nBETA\n');
|
|
175
|
+
const after = await blob('s3', 'alpha\nBETA\ngamma\n');
|
|
176
|
+
const file = `${CWD}/src/stats.ts`;
|
|
177
|
+
await append({ type: 'change', at: 5000, agent: 'Main', tool: 'edit', path: file, before, after: middle });
|
|
178
|
+
await append({ type: 'change', at: 5001, agent: 'Main', tool: 'edit', path: file, before: middle, after });
|
|
179
|
+
|
|
180
|
+
expect(await readSessionChangeStats(SESSION_ID, 5000, 5001)).toEqual({
|
|
181
|
+
[file]: { added: 2, removed: 1 },
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test('a created file counts its lines as additions', async () => {
|
|
186
|
+
const created = await blob('s4', 'one\ntwo\n');
|
|
187
|
+
const file = `${CWD}/src/created-stats.ts`;
|
|
188
|
+
await append({ type: 'change', at: 5100, agent: 'Main', tool: 'write', path: file, before: null, after: created });
|
|
189
|
+
|
|
190
|
+
expect(await readSessionChangeStats(SESSION_ID, 5100, 5100)).toEqual({
|
|
191
|
+
[file]: { added: 2, removed: 0 },
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('a path whose blob was not stored is absent, not zero', async () => {
|
|
196
|
+
const file = `${CWD}/src/unstored.ts`;
|
|
197
|
+
await append({ type: 'change', at: 5200, agent: 'Main', tool: 'write', path: file, before: undefined, after: undefined });
|
|
198
|
+
|
|
199
|
+
expect(await readSessionChangeStats(SESSION_ID, 5200, 5200)).toEqual({});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
@@ -18,8 +18,13 @@
|
|
|
18
18
|
*
|
|
19
19
|
* - {@link readSessionChangeIndex} — every record, with a display path, for
|
|
20
20
|
* the chat's per-run file list. No blob content, so it stays small.
|
|
21
|
+
* - {@link readSessionChangeList} — that index minus creations whose file is
|
|
22
|
+
* gone (a `bash rm` is never journaled). The route serves this one.
|
|
21
23
|
* - {@link readSessionChangeDiff} — the net change of one path inside one
|
|
22
24
|
* run window: the first record's `before` and the last record's `after`.
|
|
25
|
+
* - {@link readSessionChangeStats} — that same net change as `+`/`−` line
|
|
26
|
+
* counts for every path in one window, which the run's file summary shows
|
|
27
|
+
* without opening a diff.
|
|
23
28
|
*
|
|
24
29
|
* The journal is append-only and can grow to megabytes, so the parse is cached
|
|
25
30
|
* by size+mtime (the same rule `plans.ts` follows). A session with no journal
|
|
@@ -33,7 +38,12 @@ import { readRawHeaderLine } from '@/server/lib/omp/session/files';
|
|
|
33
38
|
import { findSessionFileById } from '@/server/lib/omp/session/locator';
|
|
34
39
|
import { siblingDirForSession } from '@/server/lib/omp/subagent/history/paths';
|
|
35
40
|
import { unifiedDiff } from '@/shared/lib/fs/unified-diff';
|
|
36
|
-
import
|
|
41
|
+
import { patchSides } from '@/shared/lib/fs/patch-sides';
|
|
42
|
+
import type {
|
|
43
|
+
SessionChangeCounts,
|
|
44
|
+
SessionChangeDiff,
|
|
45
|
+
SessionChangeRecord,
|
|
46
|
+
} from '@/shared/types/session-changes';
|
|
37
47
|
|
|
38
48
|
const JOURNAL_FILE = 'changes.jsonl';
|
|
39
49
|
const BLOB_DIR = 'blobs';
|
|
@@ -169,6 +179,49 @@ export async function readSessionChangeIndex(sessionId: string): Promise<Session
|
|
|
169
179
|
}));
|
|
170
180
|
}
|
|
171
181
|
|
|
182
|
+
/** True when the path is still on disk; a stat error other than ENOENT counts
|
|
183
|
+
* as present, so a permission problem never hides a real change. */
|
|
184
|
+
async function pathExists(absolute: string): Promise<boolean> {
|
|
185
|
+
try {
|
|
186
|
+
await stat(absolute);
|
|
187
|
+
return true;
|
|
188
|
+
} catch (error) {
|
|
189
|
+
return (error as NodeJS.ErrnoException).code !== 'ENOENT';
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The index the chat's per-run list reads: {@link readSessionChangeIndex} minus
|
|
195
|
+
* creations whose file is gone.
|
|
196
|
+
*
|
|
197
|
+
* omp journals edit-tool writes only. A delete through `bash` (`rm`, `git
|
|
198
|
+
* clean`, a script) never reaches `changes.jsonl`, so a file the run created
|
|
199
|
+
* and then removed still reads as `added` — measured on a real session: the
|
|
200
|
+
* run wrote `MarkdownRenderer.test.tsx`, `rm`'d it six seconds later, and the
|
|
201
|
+
* list counted 8 files while the commit had 7. A creation whose path is absent
|
|
202
|
+
* now is that case, and its net change is zero.
|
|
203
|
+
*
|
|
204
|
+
* A MODIFIED path is kept even when absent: the run did change it, and the
|
|
205
|
+
* journal diff still holds both sides.
|
|
206
|
+
*/
|
|
207
|
+
export async function readSessionChangeList(sessionId: string): Promise<SessionChangeRecord[]> {
|
|
208
|
+
const records = await readSessionChangeIndex(sessionId);
|
|
209
|
+
if (records.length === 0) return records;
|
|
210
|
+
|
|
211
|
+
const firstByPath = new Map<string, SessionChangeRecord>();
|
|
212
|
+
for (const record of records) {
|
|
213
|
+
if (!firstByPath.has(record.path)) firstByPath.set(record.path, record);
|
|
214
|
+
}
|
|
215
|
+
const gone = new Set<string>();
|
|
216
|
+
await Promise.all(
|
|
217
|
+
[...firstByPath].map(async ([absolutePath, first]) => {
|
|
218
|
+
if (first.before !== null) return;
|
|
219
|
+
if (!(await pathExists(absolutePath))) gone.add(absolutePath);
|
|
220
|
+
}),
|
|
221
|
+
);
|
|
222
|
+
return gone.size === 0 ? records : records.filter((record) => !gone.has(record.path));
|
|
223
|
+
}
|
|
224
|
+
|
|
172
225
|
/**
|
|
173
226
|
* The net change of `absolutePath` inside `[from, to]`: the first record's
|
|
174
227
|
* `before` and the last record's `after`. `null` when the path has no record in
|
|
@@ -218,3 +271,43 @@ export async function readSessionChangeDiff(
|
|
|
218
271
|
unavailable: false,
|
|
219
272
|
};
|
|
220
273
|
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Net `+`/`−` line counts for every path changed inside `[from, to]`.
|
|
277
|
+
*
|
|
278
|
+
* The net rule is {@link readSessionChangeDiff}'s — first record's `before` to
|
|
279
|
+
* last record's `after` — so the summary's numbers describe the diff the file
|
|
280
|
+
* opens, not the churn of each intermediate write. A path whose blob was not
|
|
281
|
+
* stored is absent rather than counted as zero: a count would be a guess.
|
|
282
|
+
*/
|
|
283
|
+
export async function readSessionChangeStats(
|
|
284
|
+
sessionId: string,
|
|
285
|
+
from: number,
|
|
286
|
+
to: number,
|
|
287
|
+
): Promise<Record<string, SessionChangeCounts>> {
|
|
288
|
+
const journal = await readJournal(sessionId);
|
|
289
|
+
if (!journal) return {};
|
|
290
|
+
|
|
291
|
+
const spans = new Map<string, { first: RawChangeRecord; last: RawChangeRecord }>();
|
|
292
|
+
for (const record of journal.records) {
|
|
293
|
+
if (record.at < from || record.at > to) continue;
|
|
294
|
+
const span = spans.get(record.path);
|
|
295
|
+
if (span) span.last = record;
|
|
296
|
+
else spans.set(record.path, { first: record, last: record });
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const stats: Record<string, SessionChangeCounts> = {};
|
|
300
|
+
await Promise.all(
|
|
301
|
+
[...spans].map(async ([absolutePath, { first, last }]) => {
|
|
302
|
+
const [before, after] = await Promise.all([
|
|
303
|
+
resolveBlob(journal.dir, first.before),
|
|
304
|
+
resolveBlob(journal.dir, last.after),
|
|
305
|
+
]);
|
|
306
|
+
if (before === undefined || after === undefined) return;
|
|
307
|
+
const sides = patchSides(unifiedDiff(absolutePath, before ?? '', after ?? ''));
|
|
308
|
+
if (sides.additions === 0 && sides.deletions === 0) return;
|
|
309
|
+
stats[absolutePath] = { added: sides.additions, removed: sides.deletions };
|
|
310
|
+
}),
|
|
311
|
+
);
|
|
312
|
+
return stats;
|
|
313
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `GET /api/connect/devices` — the paired list.
|
|
8
|
+
* `DELETE /api/connect/devices?id=…` — revoke one.
|
|
9
|
+
* `POST /api/connect/devices` — a device reports the route it is using.
|
|
10
|
+
*
|
|
11
|
+
* The report is a POST rather than a side effect of every request: the auth gate
|
|
12
|
+
* runs on every call and is synchronous, so writing a row there would put a
|
|
13
|
+
* database write in front of every frame. A device reports once when it
|
|
14
|
+
* connects, which is exactly the fact the page displays.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { json, NO_STORE_HEADERS, type ActionFunctionArgs } from '@/server/lib/remix-compat';
|
|
18
|
+
import { listPairedDevices, revokeDevice, touchDevice } from '@/server/lib/connect/devices.server';
|
|
19
|
+
import { bearerToken } from '@/server/lib/sessions/agent-token.server';
|
|
20
|
+
import { verifyDeviceToken } from '@/server/lib/connect/devices.server';
|
|
21
|
+
import type { ConnectRouteKind } from '@/shared/lib/connect/types';
|
|
22
|
+
|
|
23
|
+
const ROUTE_KINDS: readonly ConnectRouteKind[] = ['cloudflare', 'lan', 'tailscale'];
|
|
24
|
+
|
|
25
|
+
export async function loader() {
|
|
26
|
+
return json({ devices: await listPairedDevices() }, { headers: NO_STORE_HEADERS });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function action({ request }: ActionFunctionArgs) {
|
|
30
|
+
const url = new URL(request.url);
|
|
31
|
+
|
|
32
|
+
if (request.method === 'DELETE') {
|
|
33
|
+
const id = url.searchParams.get('id') ?? '';
|
|
34
|
+
if (!id) return json({ error: 'Expected ?id=' }, { status: 400, headers: NO_STORE_HEADERS });
|
|
35
|
+
const revoked = await revokeDevice(id);
|
|
36
|
+
if (!revoked) return json({ error: 'No such device' }, { status: 404, headers: NO_STORE_HEADERS });
|
|
37
|
+
return json({ ok: true, devices: await listPairedDevices() }, { headers: NO_STORE_HEADERS });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (request.method === 'POST') {
|
|
41
|
+
const deviceId = verifyDeviceToken(bearerToken(request));
|
|
42
|
+
if (!deviceId) {
|
|
43
|
+
return json({ error: 'A device token is required' }, { status: 401, headers: NO_STORE_HEADERS });
|
|
44
|
+
}
|
|
45
|
+
const body = (await request.json().catch(() => null)) as { route?: unknown; rttMs?: unknown } | null;
|
|
46
|
+
const route = ROUTE_KINDS.find((kind) => kind === body?.route);
|
|
47
|
+
const rttMs = typeof body?.rttMs === 'number' && Number.isFinite(body.rttMs) ? Math.round(body.rttMs) : null;
|
|
48
|
+
if (!route || rttMs === null) {
|
|
49
|
+
return json({ error: 'Expected { route, rttMs }' }, { status: 400, headers: NO_STORE_HEADERS });
|
|
50
|
+
}
|
|
51
|
+
await touchDevice(deviceId, { route, rttMs });
|
|
52
|
+
return json({ ok: true }, { headers: NO_STORE_HEADERS });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return json({ error: 'Method not allowed' }, { status: 405, headers: NO_STORE_HEADERS });
|
|
56
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { bindingsFor, type HandlerBinding } from '@/server/lib/route-adapter';
|
|
2
|
+
import * as connectStatus from '@/server/routes/connect/status';
|
|
3
|
+
import * as connectTunnels from '@/server/routes/connect/tunnels';
|
|
4
|
+
import * as connectDevices from '@/server/routes/connect/devices';
|
|
5
|
+
import * as connectPair from '@/server/routes/connect/pair';
|
|
6
|
+
import * as connectPairPage from '@/server/routes/connect/pair-page';
|
|
7
|
+
|
|
8
|
+
export const connectBindings: HandlerBinding[] = [
|
|
9
|
+
...bindingsFor(connectStatus, '/api/connect/status'),
|
|
10
|
+
...bindingsFor(connectTunnels, '/api/connect/tunnels'),
|
|
11
|
+
...bindingsFor(connectDevices, '/api/connect/devices'),
|
|
12
|
+
...bindingsFor(connectPair, '/api/connect/pair'),
|
|
13
|
+
...bindingsFor(connectPair, '/api/connect/pair/claim'),
|
|
14
|
+
...bindingsFor(connectPairPage, '/pair'),
|
|
15
|
+
];
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `GET /pair` — the page a phone's camera opens.
|
|
8
|
+
*
|
|
9
|
+
* This is what makes a pairing code usable WITHOUT a native scanner: the QR
|
|
10
|
+
* encodes an `https://<address>/pair#<payload>` URL, the phone's own camera app
|
|
11
|
+
* opens it in the browser, and this page redeems the code and lands the browser
|
|
12
|
+
* on the console with a device cookie already set.
|
|
13
|
+
*
|
|
14
|
+
* The payload lives in the FRAGMENT, never the query string. A fragment is not
|
|
15
|
+
* sent to the server, so the one-time secret never reaches an access log, a
|
|
16
|
+
* proxy, or the `Referer` of anything this page loads. The page reads it with
|
|
17
|
+
* `location.hash` and posts it once.
|
|
18
|
+
*
|
|
19
|
+
* No external assets and no framework: this page has to render on a phone that
|
|
20
|
+
* has never reached this server before, over a link that may be slow, and a
|
|
21
|
+
* bundle that fails to load would leave the user staring at a blank screen with
|
|
22
|
+
* a code that is already burning its two minutes.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { NO_STORE_HEADERS } from '@/server/lib/remix-compat';
|
|
26
|
+
|
|
27
|
+
const PAGE = `<!doctype html>
|
|
28
|
+
<html lang="en">
|
|
29
|
+
<head>
|
|
30
|
+
<meta charset="utf-8">
|
|
31
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
32
|
+
<meta name="robots" content="noindex">
|
|
33
|
+
<title>Pair with Kabmo</title>
|
|
34
|
+
<style>
|
|
35
|
+
:root { color-scheme: light dark; }
|
|
36
|
+
body { margin: 0; min-height: 100vh; display: grid; place-items: center;
|
|
37
|
+
font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
38
|
+
background: #f7f5f0; color: #141310; }
|
|
39
|
+
main { width: min(28rem, calc(100vw - 3rem)); padding: 1.5rem;
|
|
40
|
+
border: 1px solid rgba(20,19,16,.12); border-radius: 14px; background: #fff; }
|
|
41
|
+
h1 { margin: 0 0 .5rem; font-size: 1.05rem; }
|
|
42
|
+
p { margin: 0; color: rgba(20,19,16,.65); font-size: .85rem; }
|
|
43
|
+
a { display: inline-block; margin-top: 1rem; padding: .5rem .9rem; border-radius: 8px;
|
|
44
|
+
background: #141310; color: #f7f5f0; text-decoration: none; font-weight: 600; font-size: .85rem; }
|
|
45
|
+
@media (prefers-color-scheme: dark) {
|
|
46
|
+
body { background: #141310; color: #f7f5f0; }
|
|
47
|
+
main { background: #1d1b17; border-color: rgba(247,245,240,.14); }
|
|
48
|
+
p { color: rgba(247,245,240,.65); }
|
|
49
|
+
a { background: #f7f5f0; color: #141310; }
|
|
50
|
+
}
|
|
51
|
+
</style>
|
|
52
|
+
</head>
|
|
53
|
+
<body>
|
|
54
|
+
<main>
|
|
55
|
+
<h1>Pair with Kabmo</h1>
|
|
56
|
+
<p id="status">Pairing…</p>
|
|
57
|
+
<a id="continue" href="/" hidden>Open the console</a>
|
|
58
|
+
</main>
|
|
59
|
+
<script>
|
|
60
|
+
(function () {
|
|
61
|
+
var status = document.getElementById('status');
|
|
62
|
+
var link = document.getElementById('continue');
|
|
63
|
+
|
|
64
|
+
function fail(message) {
|
|
65
|
+
status.textContent = message;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function decode(value) {
|
|
69
|
+
var padded = value.replace(/-/g, '+').replace(/_/g, '/');
|
|
70
|
+
while (padded.length % 4) padded += '=';
|
|
71
|
+
var binary = atob(padded);
|
|
72
|
+
var bytes = new Uint8Array(binary.length);
|
|
73
|
+
for (var i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);
|
|
74
|
+
return new TextDecoder().decode(bytes);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function deviceName() {
|
|
78
|
+
var ua = navigator.userAgent || '';
|
|
79
|
+
if (/iPhone/.test(ua)) return 'iPhone';
|
|
80
|
+
if (/iPad/.test(ua)) return 'iPad';
|
|
81
|
+
if (/Android/.test(ua)) return 'Android device';
|
|
82
|
+
if (/Macintosh/.test(ua)) return 'Mac';
|
|
83
|
+
if (/Windows/.test(ua)) return 'Windows PC';
|
|
84
|
+
return 'Browser';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function platform() {
|
|
88
|
+
var ua = navigator.userAgent || '';
|
|
89
|
+
if (/iPhone|iPad|iPod/.test(ua)) return 'ios';
|
|
90
|
+
if (/Android/.test(ua)) return 'android';
|
|
91
|
+
if (/Macintosh/.test(ua)) return 'macos';
|
|
92
|
+
if (/Windows/.test(ua)) return 'windows';
|
|
93
|
+
if (/Linux/.test(ua)) return 'linux';
|
|
94
|
+
return 'web';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
var raw = location.hash.slice(1);
|
|
98
|
+
if (!raw) { fail('This link is missing its pairing code. Create a new one in Settings → Connect.'); return; }
|
|
99
|
+
|
|
100
|
+
var payload;
|
|
101
|
+
try {
|
|
102
|
+
payload = JSON.parse(decode(raw));
|
|
103
|
+
} catch (error) {
|
|
104
|
+
fail('This link is not a Kabmo pairing code.');
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (!payload || !payload.pairingId || !payload.secret) {
|
|
108
|
+
fail('This link is not a Kabmo pairing code.');
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Which candidate this page was opened from, and how fast it answers.
|
|
113
|
+
//
|
|
114
|
+
// The page is served BY the origin it is pairing with, so location.origin
|
|
115
|
+
// matches exactly one candidate — this is a fact, not a guess. The round trip
|
|
116
|
+
// is measured here because the server cannot measure a phone's latency, and
|
|
117
|
+
// the device row's ROUTE/RTT columns are otherwise always empty.
|
|
118
|
+
var route = null;
|
|
119
|
+
var candidates = payload.candidates || [];
|
|
120
|
+
for (var i = 0; i < candidates.length; i += 1) {
|
|
121
|
+
if (candidates[i] && candidates[i].url === location.origin) { route = candidates[i].kind; break; }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function measure() {
|
|
125
|
+
if (!window.performance || !performance.now) return Promise.resolve(null);
|
|
126
|
+
var started = performance.now();
|
|
127
|
+
return fetch('/api/health', { cache: 'no-store' })
|
|
128
|
+
.then(function (response) { return response.ok ? Math.round(performance.now() - started) : null; })
|
|
129
|
+
.catch(function () { return null; });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
measure().then(function (rttMs) {
|
|
133
|
+
var body = {
|
|
134
|
+
pairingId: payload.pairingId,
|
|
135
|
+
secret: payload.secret,
|
|
136
|
+
name: deviceName(),
|
|
137
|
+
platform: platform()
|
|
138
|
+
};
|
|
139
|
+
if (route) body.route = route;
|
|
140
|
+
if (rttMs !== null) body.rttMs = rttMs;
|
|
141
|
+
|
|
142
|
+
return fetch('/api/connect/pair/claim', {
|
|
143
|
+
method: 'POST',
|
|
144
|
+
headers: { 'content-type': 'application/json' },
|
|
145
|
+
body: JSON.stringify(body)
|
|
146
|
+
});
|
|
147
|
+
}).then(function (response) {
|
|
148
|
+
return response.json().catch(function () { return null; }).then(function (body) {
|
|
149
|
+
if (!response.ok) {
|
|
150
|
+
fail((body && body.error) || 'This pairing code could not be redeemed.');
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
status.textContent = 'Paired. Opening the console…';
|
|
154
|
+
link.hidden = false;
|
|
155
|
+
location.replace('/');
|
|
156
|
+
});
|
|
157
|
+
}).catch(function () {
|
|
158
|
+
fail('Could not reach the server. Check that this device is on the same network or tailnet.');
|
|
159
|
+
});
|
|
160
|
+
})();
|
|
161
|
+
</script>
|
|
162
|
+
</body>
|
|
163
|
+
</html>`;
|
|
164
|
+
|
|
165
|
+
export async function loader() {
|
|
166
|
+
return new Response(PAGE, {
|
|
167
|
+
status: 200,
|
|
168
|
+
headers: {
|
|
169
|
+
'content-type': 'text/html; charset=utf-8',
|
|
170
|
+
...NO_STORE_HEADERS,
|
|
171
|
+
// The page reads a fragment and posts it once; nothing it loads may leak
|
|
172
|
+
// the URL onward.
|
|
173
|
+
'referrer-policy': 'no-referrer',
|
|
174
|
+
'x-content-type-options': 'nosniff',
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
}
|