@pi-chamber/web 1.0.4 → 1.0.5-rc.2

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 (205) hide show
  1. package/README.md +1 -1
  2. package/bin/cli.js +21 -2
  3. package/bin/cli.test.js +164 -4
  4. package/bin/lib/DOCUMENTATION.md +3 -3
  5. package/bin/lib/cli-args.js +96 -13
  6. package/bin/lib/commands-connect-url-tailscale.test.js +136 -0
  7. package/bin/lib/commands-connect-url.js +146 -39
  8. package/bin/lib/commands-connect-url.test.js +126 -0
  9. package/bin/lib/commands-serve.js +45 -2
  10. package/bin/lib/commands-status.js +28 -5
  11. package/bin/lib/commands-status.test.js +107 -0
  12. package/bin/lib/commands-tunnel.js +36 -10
  13. package/dist/assets/{DiagramView-BpG1c3Hi.js → DiagramView-BWG8peHt.js} +1 -1
  14. package/dist/assets/DiffView-C_uRNQMT.js +18 -0
  15. package/dist/assets/{FileSaveConflictDialog-DP7k9a-i.js → FileSaveConflictDialog-DlH8IWDL.js} +2 -2
  16. package/dist/assets/FilesView-RnF9JBPu.js +6 -0
  17. package/dist/assets/{GitHubDetailScaffold-UxLAMAOl.js → GitHubDetailScaffold-BTRvUnwh.js} +2 -2
  18. package/dist/assets/{GitHubLinkPicker-Bh9RO1yK.js → GitHubLinkPicker-CGi8p2zF.js} +1 -1
  19. package/dist/assets/{GitHubListPrimitives-DQyhT5wG.js → GitHubListPrimitives-XckcmdeA.js} +1 -1
  20. package/dist/assets/{GitView-XBBheKRM.js → GitView-DyPJ8Oay.js} +4 -4
  21. package/dist/assets/{IssuesSurface-BA1kpvAJ.js → IssuesSurface-rQ78ziEu.js} +3 -3
  22. package/dist/assets/{JsonTreeView-BAaEPL4O.js → JsonTreeView-Cy5NKUzx.js} +1 -1
  23. package/dist/assets/{MarkdownRendererImpl-DzgDmUsL.js → MarkdownRendererImpl-C5AlnAbG.js} +1 -1
  24. package/dist/assets/{PatchDiff-BMEUsgXH.js → PatchDiff-D6048My1.js} +1 -1
  25. package/dist/assets/PierreDiffViewer-_000TWrM.js +135 -0
  26. package/dist/assets/PullRequestsSurface-eACi4Yxm.js +2 -0
  27. package/dist/assets/SessionSwitcherContent-CFMjBIfH.js +1 -0
  28. package/dist/assets/SessionSwitcherDropdown-CINW_ydZ.js +2 -0
  29. package/dist/assets/SessionUnreadDot-YZJi4IFP.js +1 -0
  30. package/dist/assets/SettingsView-DBiQXIji.js +6 -0
  31. package/dist/assets/{SettingsWindow-j0e99YI0.js → SettingsWindow-Wvd56oG1.js} +1 -1
  32. package/dist/assets/StickyHorizontalScrollbar-BMITjK4e.js +8 -0
  33. package/dist/assets/{ToolOutputDialog-VlS12Xyq.js → ToolOutputDialog-DeDXQNWw.js} +4 -4
  34. package/dist/assets/{ToolPartDiffPreview-DdSneZws.js → ToolPartDiffPreview-DuN8fldE.js} +1 -1
  35. package/dist/assets/{VirtualizedFileDiff-BqiXjvP6.js → VirtualizedFileDiff-BYVjUxk9.js} +4 -4
  36. package/dist/assets/{Virtualizer-Cp_cJWbI.js → Virtualizer-DP6HbEeC.js} +1 -1
  37. package/dist/assets/{collapsible-C7oyikVm.js → collapsible-BOcd0lzY.js} +1 -1
  38. package/dist/assets/{computeVirtualFileMetrics-BJjC-tXV.js → computeVirtualFileMetrics-E4gJTgVF.js} +1 -1
  39. package/dist/assets/{contextFileOpenGuard-BBzqKGei.js → contextFileOpenGuard-CcGZtZsz.js} +1 -1
  40. package/dist/assets/{gitStatusPredicates-Dq-E5DaH.js → gitStatusPredicates-C2H7tf7t.js} +1 -1
  41. package/dist/assets/{githubLink-Cryd7GkG.js → githubLink-DTEEkgAl.js} +5 -5
  42. package/dist/assets/{index-BbhXFTId.js → index-BKc_DF05.js} +1 -1
  43. package/dist/assets/index-DWSrsQWl.js +11 -0
  44. package/dist/assets/index-DsQIBAWK.css +1 -0
  45. package/dist/assets/main-BNoO2jRw.js +136 -0
  46. package/dist/assets/main-DnCR4Jva.js +2 -0
  47. package/dist/assets/{markdownCore-B9AuEyYi.js → markdownCore-CP1hsIRw.js} +2 -2
  48. package/dist/assets/{miniChat-CgOaJfD8.js → miniChat-BBI_B4OS.js} +2 -2
  49. package/dist/assets/mobile-dRWyYBgl.js +2 -0
  50. package/dist/assets/{nativeFileSave-BzhtrDoD.js → nativeFileSave-CFuugNKV.js} +1 -1
  51. package/dist/assets/pi-session-focus-preference-Cw78V7mw.js +9 -0
  52. package/dist/assets/{renderDiffWithHighlighter-CVLsdtQ5.js → renderDiffWithHighlighter-kdzNWs8-.js} +1 -1
  53. package/dist/assets/renderElectronMiniChatApp-uVOQvccp.js +2 -0
  54. package/dist/assets/{renderFileWithHighlighter-DJ9mk2bZ.js → renderFileWithHighlighter-BdeYSXwS.js} +1 -1
  55. package/dist/assets/renderMobileApp-Cdg1IAhJ.js +11 -0
  56. package/dist/assets/runtimeEndpointReset-thviM404.js +62 -0
  57. package/dist/assets/{runtimeSurface-DBiUWYK2.js → runtimeSurface-Der4qUnI.js} +1 -1
  58. package/dist/assets/useAppFontEffects-Bd0btzjJ.js +212 -0
  59. package/dist/assets/{useFilesViewSearch-D2Au5Xgt.js → useFilesViewSearch-Yvk43YOy.js} +3 -3
  60. package/dist/assets/useGitHubRemoteSearch-BUjSEnXC.js +1 -0
  61. package/dist/assets/{useSwitcherItems-Dej8BzXI.js → useSwitcherItems-D2opwbRZ.js} +1 -1
  62. package/dist/assets/{vendor-aparajita-capacitor-secure-storage-BYohCVY0.js → vendor-aparajita-capacitor-secure-storage-BDrMx_CE.js} +1 -1
  63. package/dist/assets/{vendor-base-ui-BscvGUFt.js → vendor-base-ui-CKRUCG-f.js} +1 -1
  64. package/dist/assets/{vendor-boot-Dgb9NVFe.js → vendor-boot-EC6IyLt1.js} +13 -13
  65. package/dist/assets/{vendor-capacitor-app-BjdQVib9.js → vendor-capacitor-app-BaupizkW.js} +1 -1
  66. package/dist/assets/{vendor-capacitor-keyboard-eTtI5go3.js → vendor-capacitor-keyboard-9BVxykO7.js} +1 -1
  67. package/dist/assets/{vendor-capacitor-status-bar-9rNIGxlO.js → vendor-capacitor-status-bar-BsrUwiaA.js} +1 -1
  68. package/dist/assets/{vendor-codemirror-autocomplete-DxS3jwvE.js → vendor-codemirror-autocomplete-CGpAsPWp.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-angular-DdjXl9e2.js → vendor-codemirror-lang-angular-CDJoHJSY.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-cpp--aMr7NVt.js → vendor-codemirror-lang-cpp-BmHofQls.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-css-CZ_qxZY9.js → vendor-codemirror-lang-css-RM2HqXZ0.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-go-Ca-y2Alu.js → vendor-codemirror-lang-go-Crwca_X7.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-html-COZ0L5wT.js → vendor-codemirror-lang-html-CHSHUpwq.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-java-D3Rf3QNJ.js → vendor-codemirror-lang-java-lhQXgWu0.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-javascript-DwJ-IvCs.js → vendor-codemirror-lang-javascript-Dw4kFO4e.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-jinja-D_5lod6k.js → vendor-codemirror-lang-jinja-_pAC3UTN.js} +1 -1
  77. package/dist/assets/{vendor-codemirror-lang-json-BG8C7OpC.js → vendor-codemirror-lang-json-B-b1vAv-.js} +1 -1
  78. package/dist/assets/{vendor-codemirror-lang-less-CVEkoaTw.js → vendor-codemirror-lang-less-xIgOi1ze.js} +1 -1
  79. package/dist/assets/{vendor-codemirror-lang-liquid-U9vj0m8w.js → vendor-codemirror-lang-liquid-CP49m5dB.js} +1 -1
  80. package/dist/assets/{vendor-codemirror-lang-markdown-DqlYH9gY.js → vendor-codemirror-lang-markdown-BTht2ATe.js} +1 -1
  81. package/dist/assets/{vendor-codemirror-lang-php-BFEiEVA1.js → vendor-codemirror-lang-php-BguZDhaO.js} +1 -1
  82. package/dist/assets/{vendor-codemirror-lang-python-Cz1dQXQd.js → vendor-codemirror-lang-python-CH6_em9L.js} +1 -1
  83. package/dist/assets/{vendor-codemirror-lang-rust-C_CoD9mj.js → vendor-codemirror-lang-rust-EG_DtGyi.js} +1 -1
  84. package/dist/assets/{vendor-codemirror-lang-sass-BuR0aKh5.js → vendor-codemirror-lang-sass-BknY5Qpo.js} +1 -1
  85. package/dist/assets/{vendor-codemirror-lang-sql-DggNUjdM.js → vendor-codemirror-lang-sql-B0f-qCZo.js} +1 -1
  86. package/dist/assets/{vendor-codemirror-lang-vue-DFZHi2J3.js → vendor-codemirror-lang-vue-CyGn9snv.js} +1 -1
  87. package/dist/assets/{vendor-codemirror-lang-wast-zuTN3SHT.js → vendor-codemirror-lang-wast-CsFfSyyB.js} +1 -1
  88. package/dist/assets/{vendor-codemirror-lang-xml-CrcvhI-k.js → vendor-codemirror-lang-xml-Cdan_Jp1.js} +1 -1
  89. package/dist/assets/{vendor-codemirror-lang-yaml-DcVWsakb.js → vendor-codemirror-lang-yaml-COI5hck8.js} +1 -1
  90. package/dist/assets/{vendor-codemirror-language-data-CCLITgCF.js → vendor-codemirror-language-data-CqU7kHmg.js} +2 -2
  91. package/dist/assets/{vendor-codemirror-search-H7NOEdbX.js → vendor-codemirror-search-DUfSCF9S.js} +1 -1
  92. package/dist/assets/{vendor-lezer-cpp-C8aD2KAr.js → vendor-lezer-cpp-DMZOJzBa.js} +1 -1
  93. package/dist/assets/{vendor-lezer-css-2lbTJF-Y.js → vendor-lezer-css-DUkkbMp7.js} +1 -1
  94. package/dist/assets/{vendor-lezer-go-Bw6LFTrZ.js → vendor-lezer-go-CHIhCNY6.js} +1 -1
  95. package/dist/assets/{vendor-lezer-html-D7ym2z7S.js → vendor-lezer-html-B3h0MOrG.js} +1 -1
  96. package/dist/assets/{vendor-lezer-java-CZhK7w21.js → vendor-lezer-java-tMazV_6X.js} +1 -1
  97. package/dist/assets/{vendor-lezer-javascript-rpKeTHZp.js → vendor-lezer-javascript-ctwLWf4v.js} +1 -1
  98. package/dist/assets/{vendor-lezer-json-C7jwsd2G.js → vendor-lezer-json-BP_UAzLL.js} +1 -1
  99. package/dist/assets/{vendor-lezer-lr-DR-ylqNN.js → vendor-lezer-lr-B8TQctNw.js} +1 -1
  100. package/dist/assets/{vendor-lezer-markdown-Bir0m5nB.js → vendor-lezer-markdown-aGLZf_3h.js} +1 -1
  101. package/dist/assets/{vendor-lezer-php-y0hIEfo1.js → vendor-lezer-php-D5zCNzlt.js} +1 -1
  102. package/dist/assets/{vendor-lezer-python-D64A9lNV.js → vendor-lezer-python-EJ4Im4y2.js} +1 -1
  103. package/dist/assets/{vendor-lezer-rust-E3ZA9T2L.js → vendor-lezer-rust-DO5c7OtA.js} +1 -1
  104. package/dist/assets/{vendor-lezer-sass-C5UFI9SP.js → vendor-lezer-sass-CMi6zfXI.js} +1 -1
  105. package/dist/assets/{vendor-lezer-xml-DOy7FzCR.js → vendor-lezer-xml-0MHMeZDp.js} +1 -1
  106. package/dist/assets/{vendor-lezer-yaml-kEjaSCvZ.js → vendor-lezer-yaml-BE2EFjpA.js} +1 -1
  107. package/dist/assets/{vendor-replit-codemirror-vim-BLfh0LPy.js → vendor-replit-codemirror-vim-AnOuN8yJ.js} +1 -1
  108. package/dist/assets/{web-components-C7CmoFxi.js → web-components-BeROQeen.js} +3 -3
  109. package/dist/index.html +4 -4
  110. package/dist/mini-chat.html +3 -3
  111. package/dist/mobile.html +3 -3
  112. package/dist/sw.js +1 -1
  113. package/package.json +1 -2
  114. package/server/index.js +72 -30
  115. package/server/lib/client-auth/DOCUMENTATION.md +15 -1
  116. package/server/lib/client-auth/pairing.js +2 -12
  117. package/server/lib/client-auth/remote-clients.js +2 -12
  118. package/server/lib/cloudflare-tunnel.js +0 -132
  119. package/server/lib/fs/DOCUMENTATION.md +8 -0
  120. package/server/lib/fs/atomic-write.js +111 -0
  121. package/server/lib/fs/atomic-write.test.js +133 -0
  122. package/server/lib/notifications/DOCUMENTATION.md +43 -32
  123. package/server/lib/notifications/pi-notification-watcher.js +8 -7
  124. package/server/lib/notifications/pi-notification-watcher.test.js +88 -2
  125. package/server/lib/pi/routes-extension-events.test.js +231 -0
  126. package/server/lib/pi/routes.js +137 -4
  127. package/server/lib/pi/routes.test.js +248 -2
  128. package/server/lib/pi/session-daemon/DOCUMENTATION.md +17 -4
  129. package/server/lib/pi/session-daemon/daemon-process.js +2 -0
  130. package/server/lib/pi/session-daemon/engines/index.js +6 -0
  131. package/server/lib/pi/session-daemon/extension-bridge-draft.test.js +1 -1
  132. package/server/lib/pi/session-daemon/extension-bridge.js +24 -0
  133. package/server/lib/pi/session-daemon/extension-message-render.js +74 -0
  134. package/server/lib/pi/session-daemon/extension-message-render.test.js +164 -0
  135. package/server/lib/pi/session-daemon/extension-tool-render.js +13 -6
  136. package/server/lib/pi/session-daemon/pending-input.js +188 -0
  137. package/server/lib/pi/session-daemon/pending-input.test.js +202 -0
  138. package/server/lib/pi/session-daemon/session-daemon-engines.test.js +828 -0
  139. package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +296 -6
  140. package/server/lib/pi/session-daemon/session-daemon-turn.e2e.test.js +9 -0
  141. package/server/lib/pi/session-daemon/session-daemon.js +219 -19
  142. package/server/lib/pi/session-daemon/session-daemon.test.js +30 -2
  143. package/server/lib/pi/session-daemon/session-engine-router.js +390 -0
  144. package/server/lib/pi/session-daemon/session-engine-router.test.js +515 -0
  145. package/server/lib/pi/session-daemon/session-engines.js +467 -0
  146. package/server/lib/pi/session-daemon/session-engines.test.js +383 -0
  147. package/server/lib/pi/snippets-store.js +8 -17
  148. package/server/lib/pi/ui-settings-store.js +6 -10
  149. package/server/lib/pi/ui-settings-store.test.js +37 -1
  150. package/server/lib/relay/DOCUMENTATION.md +6 -4
  151. package/server/lib/relay/identity-store.js +116 -0
  152. package/server/lib/relay/identity-store.test.js +169 -0
  153. package/server/lib/relay/identity.js +6 -4
  154. package/server/lib/relay/server-id.js +63 -0
  155. package/server/lib/relay/server-id.test.js +132 -0
  156. package/server/lib/relay/signing-key.js +14 -11
  157. package/server/lib/security/bind-host.js +6 -2
  158. package/server/lib/security/bind-host.test.js +17 -0
  159. package/server/lib/server/core-routes.js +27 -1
  160. package/server/lib/server/lan-addresses.js +18 -6
  161. package/server/lib/server/lan-addresses.test.js +28 -0
  162. package/server/lib/server/tunnel-auth.js +47 -7
  163. package/server/lib/server/tunnel-auth.rate-limit.test.js +164 -0
  164. package/server/lib/server/tunnel-service.DOCUMENTATION.md +3 -4
  165. package/server/lib/server/tunnel-service.js +23 -20
  166. package/server/lib/server/tunnel-service.test.js +19 -2
  167. package/server/lib/stt/config-store.js +5 -15
  168. package/server/lib/tailscale/DOCUMENTATION.md +285 -0
  169. package/server/lib/tailscale/nc-probe.js +220 -0
  170. package/server/lib/tailscale/routes.js +45 -0
  171. package/server/lib/tailscale/service.js +1012 -0
  172. package/server/lib/tailscale/tailscale.js +302 -0
  173. package/server/lib/tailscale/tailscale.test.js +2080 -0
  174. package/server/lib/tunnels/DOCUMENTATION.md +3 -4
  175. package/server/lib/tunnels/providers/cloudflare.js +1 -22
  176. package/server/lib/tunnels/types.js +0 -2
  177. package/server/lib/ui-auth/DOCUMENTATION.md +31 -0
  178. package/server/lib/ui-auth/ui-auth.js +80 -6
  179. package/server/lib/ui-auth/ui-auth.test.js +136 -0
  180. package/server/lib/ui-auth/ui-passkeys.js +2 -13
  181. package/server/lib/update-job-store.js +4 -6
  182. package/dist/assets/DiffView-BxwoRCYx.js +0 -18
  183. package/dist/assets/FilesView-D_2QcdUt.js +0 -6
  184. package/dist/assets/PierreDiffViewer-BW8MO-O6.js +0 -134
  185. package/dist/assets/PullRequestsSurface-B3ictm4I.js +0 -2
  186. package/dist/assets/SessionSwitcherContent-rLoyVqgs.js +0 -1
  187. package/dist/assets/SessionSwitcherDropdown-CfySKnUu.js +0 -2
  188. package/dist/assets/SessionUnreadDot-CmEF9sxM.js +0 -1
  189. package/dist/assets/SettingsView-BiwlwnTK.js +0 -6
  190. package/dist/assets/index-BnZVqcki.js +0 -11
  191. package/dist/assets/index-BnieExes.css +0 -1
  192. package/dist/assets/main-9O5IAtT_.js +0 -136
  193. package/dist/assets/main-DWGwALIw.js +0 -2
  194. package/dist/assets/mobile-BbJcYVym.js +0 -2
  195. package/dist/assets/pi-session-focus-preference-Bmk1iOvn.js +0 -10
  196. package/dist/assets/renderElectronMiniChatApp-R5o9NwFC.js +0 -2
  197. package/dist/assets/renderMobileApp-CQ9tWYIj.js +0 -11
  198. package/dist/assets/runtimeEndpointReset-CtK4C_5h.js +0 -62
  199. package/dist/assets/useAppFontEffects-DviRbaCJ.js +0 -212
  200. package/dist/assets/useGitHubRemoteSearch-D-K7aolk.js +0 -1
  201. package/dist/assets/vendor-capacitor-push-notifications-CBKq2Arn.js +0 -1
  202. package/server/lib/notifications/delivery-runtime.js +0 -314
  203. package/server/lib/notifications/delivery-runtime.test.js +0 -85
  204. package/server/lib/notifications/routes.js +0 -74
  205. package/server/lib/relay/service.js +0 -9
@@ -0,0 +1,285 @@
1
+ # Tailscale Module Documentation
2
+
3
+ ## Purpose
4
+
5
+ Tailscale remote access for PiChamber: `tailscale serve` publishes the local
6
+ server at `https://<machine>.<tailnet>.ts.net[:port]`, reachable only by
7
+ devices in the user's tailnet (private). `tailscale funnel` is identical but
8
+ reachable from the public internet (public). Funnel only allows the HTTPS
9
+ ports 443, 8443 and 10000. The URL is the machine's MagicDNS name and does
10
+ not change when the mapping is removed and re-added.
11
+
12
+ Off by default. Enabled only via the settings API (`PUT
13
+ /api/pichamber/tailscale/config`) or CLI flags (`pichamber pair --tailscale`,
14
+ `pichamber serve --tailscale`). Never auto-enabled when Tailscale is
15
+ detected.
16
+
17
+ Ephemeral Cloudflare quick tunnels were removed; this module is unaffected.
18
+
19
+ ## Entrypoints and structure
20
+
21
+ - `tailscale.js`: pure helpers — config validation/normalization, the auth
22
+ gate, executable resolution, `status --json` parsing (trailing-dot DNSName,
23
+ `BackendState`, `CertDomains`), `serve status --json` conflict detection,
24
+ approval-URL extraction, permission-denied detection. No I/O.
25
+ - `service.js`: `createTailscaleService` — persisted config, lifecycle
26
+ (apply on start, remove on stop, reconcile on change), crash-safe mapping
27
+ record, probe-before-advertise (direct fetch plus the `tailscale nc`
28
+ tailnet-path fallback), approval wait, and the status model. All
29
+ process execution goes through the injected `runner` (argument arrays, no
30
+ shell, bounded timeouts), and the tailnet-path probe goes through the
31
+ injected `tailnetHealthFetch` (built from the resolved executable by
32
+ default); tests inject fakes for both.
33
+ - `nc-probe.js`: `createTailscaleNcHealthFetch` — the tailnet-path fallback
34
+ for the self-probe. Spawns `tailscale nc <host> <port>`, runs a real TLS
35
+ handshake over the child's stdio, and performs the same credential-free
36
+ `GET /health` check Node-side (chunked encoding included) with
37
+ certificate verification ON. Never throws: every failure resolves to
38
+ `{ ok: false, ... }`.
39
+ - `routes.js`: `registerTailscaleRoutes` — thin authenticated HTTP API
40
+ following the `/api/pichamber/tunnel/*` conventions.
41
+ - `tailscale.test.js`: unit tests with an injected fake runner.
42
+
43
+ ## Lifecycle ("while PiChamber runs")
44
+
45
+ 1. `startWebUiServer` loads the persisted config, then reconciles the mapping
46
+ **after** HTTP listen to `http://127.0.0.1:<boundPort>` — always loopback,
47
+ even when the server also binds LAN. Reconcile runs in the background so
48
+ an approval wait never blocks server-ready (status shows
49
+ starting/needs-approval meanwhile); rejections are caught and logged.
50
+ Apply failure logs a warning and never stops startup; the status model
51
+ carries the error and `POST /api/pichamber/tailscale/retry` (or any
52
+ config change) reconciles again.
53
+ 2. Runtime config changes and retry respond after at most a short grace
54
+ (`CONFIG_RESPONSE_GRACE_MS`, 3s) with the current (possibly
55
+ transitional) status while reconcile continues in the background:
56
+ abort the in-flight apply (generation bump kills it), remove the old
57
+ mapping, apply the new one (bounded timeouts). A superseded apply that
58
+ still created a mapping is verified and removed, so no mapping is left
59
+ unowned. The enabled path reports `starting` synchronously before its
60
+ first await (approval output flips it to `needs-approval`), so the
61
+ early response is already transitional. Background failures are caught
62
+ and logged, never unhandled. Clients (the Remote Access UI hook,
63
+ `pichamber pair --tailscale`) poll `GET /status` until a terminal
64
+ state. Reconciles are serialized: each reconcile starts only after the
65
+ previous one settles, in call order. A reconcile superseded while queued
66
+ is skipped, and a superseded in-flight reconcile never removes a mapping
67
+ after the newer one starts — the generation is re-checked after the
68
+ serve-status query inside verified removal, and again before every
69
+ host-info/state write. A throwing reconcile never wedges the chain: the
70
+ next queued reconcile still runs while the caller still sees the
71
+ rejection.
72
+ 3. Graceful shutdown (`controller.stop`, covering CLI serve stop, SIGINT,
73
+ SIGTERM, and the Electron in-process server stop path) removes the mapping
74
+ PiChamber created (`serve/funnel --https=<p> off`, as appropriate) — but
75
+ only after verifying ownership against live serve status. On a status
76
+ query failure nothing is removed and the record is kept, so the next
77
+ start's stale cleanup retries with verification. Electron awaits this
78
+ stop with a bounded quit timeout (8s) before exiting, so shutdown uses
79
+ tighter bounds than reconcile — 3s status query + 4s removal — to finish
80
+ inside it; keep both sides in sync. A failed removal also
81
+ keeps the record and logs a warning (the next start's stale cleanup
82
+ retries with verification), and never blocks shutdown.
83
+
84
+ ## Crash safety and conflict rules
85
+
86
+ - The mapping PiChamber created is recorded in `tailscale-mapping.json`
87
+ (`{ httpsPort, mode, localPort }`) in the PiChamber data dir. On the next
88
+ start, a stale record for a different port/mode is removed (when it is
89
+ ours) before the new mapping is applied; a disabled config removes a stale
90
+ own mapping and reports `off`; a `blocked` (auth-gate) config removes a
91
+ stale own mapping first and then reports `blocked` (tailscaled persists
92
+ serve config, so the mapping would otherwise stay reachable without
93
+ auth). A failed status query keeps the record and reports `error` with
94
+ code `status_query_failed` (retry available) instead of acting blind. A
95
+ failed removal of a verified own mapping also keeps the record and
96
+ reports `error` with code `remove_failed` (the mapping may still be
97
+ live), so a later reconcile or retry can remove it first — reconcile
98
+ never applies a new mapping over one it failed to remove.
99
+ - NEVER remove or overwrite a mapping PiChamber did not create. Before
100
+ applying, `tailscale serve status --json` (`funnel status --json` for
101
+ public) is inspected — `Web` entries keyed by `<host>:<port>` with handler
102
+ targets. A mapping is OURS only when every handler target points at our
103
+ own `http://127.0.0.1:<boundPort>`. A mapping on the configured port is
104
+ also OURS when the mapping record (same port+mode) names the local port
105
+ the live targets point at — a crash-restart on a new bound port leaves the
106
+ old record behind while the port/mode are unchanged. Such a mapping is
107
+ repointed to the new bound port instead of reporting conflict. Anything
108
+ else on the target port reports state `conflict` with code `conflict` and a message suggesting the
109
+ other ports (8443/10000). Disabled and blocked reconciles still query host
110
+ prerequisites (`tailscale status --json` only — no serve/funnel commands)
111
+ after the mapping-removal check, so `installed`/`running`/`loggedIn` stay
112
+ accurate while `state` is `off`/`blocked`; the retry route re-checks them
113
+ the same way.
114
+
115
+ ## Security gate (core-enforced)
116
+
117
+ Tailscale proxies requests to loopback, which bypasses the
118
+ "refuse a network-exposed bind without a UI password" rule. Enabling
119
+ Tailscale (either mode) therefore requires UI auth (a UI password):
120
+
121
+ - Enforced in `setConfig` (rejects with code `auth_required`), in
122
+ `persistTailscaleConfigForStartup` (same gate, so the CLI cannot persist
123
+ an enabled config without satisfying it either), in server startup
124
+ reconcile (config enabled but gate unsatisfied → existing own mapping
125
+ removed with ownership verification, then state `blocked`, code
126
+ `auth_required`, mapping not applied), and in `pichamber serve
127
+ --tailscale` (fast deterministic CLI failure).
128
+ - `private` mode honors the same `PICHAMBER_ALLOW_UNAUTHENTICATED_LAN`
129
+ escape hatch as a LAN bind (`true`/`1`, case-insensitive). `public` mode
130
+ has NO escape hatch.
131
+
132
+ With no UI password, the Tailscale status/config routes are reachable
133
+ unauthenticated on loopback/LAN — the same as every other route in that
134
+ mode (no per-route auth exists without a password); enabling/disabling is
135
+ fail-safe because the auth gate above rejects enabling.
136
+
137
+ Funnel traffic is classified as `local` request scope by tunnel-auth
138
+ `classifyRequestScope` (it arrives from the loopback socket with a
139
+ forwarded Host). `local` scope is transport classification only and must
140
+ never relax authentication.
141
+
142
+ ## Trust-proxy / rate-limit / cookie / passkey findings
143
+
144
+ The server runs with `app.set('trust proxy', true)` (intentional: reverse
145
+ proxies and tunnels terminate TLS and set `X-Forwarded-*`).
146
+
147
+ - **Rate limiting (`getClientIp`)**: login limiters (UI password/passkey in
148
+ `ui-auth.js`, `/connect` in `tunnel-auth.js`) use a DUAL bucket. The
149
+ per-client bucket is still keyed by `X-Forwarded-For` first (UX behind
150
+ legit proxies: each tailnet device keeps its own budget), but EVERY
151
+ attempt is ALSO counted against a socket-address bucket keyed by
152
+ `req.socket.remoteAddress` (never `req.ip`, which Express rewrites from
153
+ XFF under `trust proxy`). The socket bucket allows 5x the per-client
154
+ limit in the same window — headroom for one forwarder multiplexing many
155
+ clients — and an attempt is refused if EITHER bucket is exhausted.
156
+ A successful login clears only the requester's per-client bucket, never
157
+ the shared socket bucket (which decays via window/lockout expiry only);
158
+ otherwise any legitimate login would wipe an attacker's accumulated
159
+ guesses and defeat the socket bound. Accepted trade-off: because
160
+ Serve/Funnel share the loopback socket, an attacker exhausting the
161
+ socket bucket over Funnel locks out every Tailscale/loopback login for
162
+ the lockout window (15 min) — bounded guessing is preferred over
163
+ unlimited guessing; the per-client bucket keeps separate tailnet
164
+ devices' normal budgets.
165
+ Threat direction: Tailscale Serve/Funnel forwards from 127.0.0.1 and
166
+ passes attacker-supplied XFF through, so XFF alone is attacker-controlled
167
+ and must never be the only key. Rotating XFF from one socket now hits the
168
+ socket lockout (50 login / 100 connect attempts per 5 minutes), and
169
+ distinct sockets stay independent.
170
+ - **Pairing redeem limiter**: keyed by the socket address (deliberately NOT
171
+ `req.ip`), so all Tailscale traffic shares the `127.0.0.1` bucket: 10
172
+ attempts per 5 minutes per `pairingId`. Pairing-ID scoping keeps this a
173
+ per-link budget, so one attacker's guesses never consume another link's
174
+ budget. Kept as-is; documented here.
175
+ - **Secure cookies (`isSecureRequest`)**: trusts `X-Forwarded-Proto`. Tailscale
176
+ terminates TLS and forwards `https`, so session cookies stay `Secure` over
177
+ the ts.net URL. If the header were absent, cookies would be issued without
178
+ the Secure flag but still over the encrypted tailnet transport — no
179
+ downgrade to plaintext.
180
+ - **Passkeys (`getCurrentRpId`)**: the relying-party ID derives from the
181
+ request host, so passkeys registered over the ts.net hostname are scoped to
182
+ that hostname and do not collide with LAN-host passkeys. No change needed.
183
+ - **Origin checks**: tunneled requests carry the ts.net origin via
184
+ `Host`/`X-Forwarded-Host`; no ts.net-specific origin bypass was added.
185
+
186
+ Nothing above required a code change: the gates already treat Tailscale as an
187
+ untrusted network transport, and the `auth_required` gate closes the
188
+ loopback-proxies-bypass-auth hole.
189
+
190
+ ## Status model (shared with the UI wrapper in `packages/ui/src/lib/tailscale.ts`)
191
+
192
+ `{ installed, running /* BackendState Running */, loggedIn, magicDnsName,
193
+ httpsCertsAvailable /* from CertDomains when present, else null */,
194
+ config: { enabled, mode, httpsPort }, state, url, approvalUrl, errorCode,
195
+ errorMessage, authGate: { privateAllowed, publicAllowed } }`
196
+
197
+ `authGate` is computed with `checkTailscaleAuthGate` for each mode: private
198
+ may stay allowed via `PICHAMBER_ALLOW_UNAUTHENTICATED_LAN`, public never is.
199
+ The UI disables each mode individually from these flags before the user
200
+ clicks, instead of waiting for the 403 from `setConfig`.
201
+
202
+ `installed`/`running`/`loggedIn`/`magicDnsName`/`httpsCertsAvailable` are
203
+ refreshed from `status --json` on every reconcile — including disabled
204
+ (`off`) and blocked reconciles, which never set prerequisite error codes
205
+ (`not_installed`/`not_running`/`not_logged_in`) for this — so the UI renders
206
+ Not installed / Not signed in accurately instead of a blanket Off, and
207
+ `POST /api/pichamber/tailscale/retry` re-checks them.
208
+
209
+ States: `off` | `unavailable` (not installed/running/logged in) | `blocked`
210
+ (auth gate) | `starting` (applied, URL not yet verified) |
211
+ `needs-approval` (+ `approvalUrl`) | `active` (+ `url`) | `conflict` |
212
+ `error`. `url` is set ONLY after a credential-free probe of `<url>/health`
213
+ reports this server's `serverId` — the stable relay signing-key identity
214
+ (`deriveServerId` of the `relaySigningKey` public JWK in the host-local
215
+ `<dataDir>/relay-identity.json`, the same id reported on `/health`,
216
+ `/api/version`, and relay pairing candidates, so clients verify a learned
217
+ address BEFORE sending a bearer token). `settings.json` is portable (copied
218
+ between hosts) and must never hold host identity. The probe compares against
219
+ the injected `getServerId` (a null/throwing id fails the probe, so the URL
220
+ stays `starting` and is never advertised). First-use
221
+ Funnel DNS can take minutes: `starting` keeps re-probing with backoff for
222
+ up to ~10 minutes.
223
+
224
+ When the direct fetch THROWS without an HTTP response (DNS/connect/abort —
225
+ typical on hosts running tailscaled with `--tun=userspace-networking` or
226
+ whose resolver does not use MagicDNS, so the host cannot reach its own ts.net
227
+ name), the same check is retried over the tailnet path via `tailscale nc`
228
+ (`nc-probe.js`, same timeout, credential-free, TLS verification ON). The
229
+ fallback must pass the identical gate: 2xx, JSON body, `serverId` match. An
230
+ HTTP response from the direct path — non-OK or mismatched serverId — never
231
+ triggers the fallback: something answered, so the tailnet path must not
232
+ override it. For public (funnel) mode the fallback still verifies over the
233
+ tailnet path, not the public internet path — it proves the mapping fronts
234
+ this server, not that the public URL is reachable.
235
+
236
+ Error codes: `auth_required` | `not_installed` | `not_running` |
237
+ `not_logged_in` | `permission_denied` (`sudo tailscale set --operator=$USER`)
238
+ | `needs_approval` | `conflict` | `apply_failed` | `remove_failed`
239
+ (the own mapping may still be live; the record is kept for retry) |
240
+ `status_query_failed`
241
+ (retry available; nothing was changed) | `probe_failed` | `invalid_config` |
242
+ `timeout` | `unknown`.
243
+
244
+ ## Approval flow
245
+
246
+ When HTTPS certs or Funnel are not enabled for the tailnet, serve/funnel
247
+ prints `https://login.tailscale.com/f/serve?node=...` (or `/f/funnel?...`)
248
+ and may block. The service streams stdout/stderr, extracts the first approval
249
+ URL, reports `needs-approval` while it keeps waiting (bounded 5 minutes,
250
+ cancellable on config change/shutdown), then proceeds. A timeout or exit with
251
+ the URL still pending stays `needs-approval` so the operator can approve and
252
+ hit retry.
253
+
254
+ ## Platform notes
255
+
256
+ - Executable: the well-known install location when it exists — macOS
257
+ `/Applications/Tailscale.app/Contents/MacOS/Tailscale`, Windows
258
+ `%ProgramFiles%\Tailscale\tailscale.exe` — otherwise `tailscale` /
259
+ `tailscale.exe` on PATH. The install location wins because GUI installs
260
+ often add no CLI to PATH and Electron launched from Finder has a minimal
261
+ PATH.
262
+ - Linux non-root without operator rights fails with access/permission style
263
+ errors → code `permission_denied` with the operator fix hint.
264
+ - Tailscale is not installed in CI/dev here; runtime validation against real
265
+ Tailscale is out of scope. The service is fully covered by fake-runner unit
266
+ tests instead.
267
+
268
+ ## Pairing integration
269
+
270
+ When `active`, the service exposes `{ type: 'tailscale', url, mode,
271
+ priority: 20 }` via `getPairingCandidate()`. Server routes append it to
272
+ Pairing v2 payloads and `GET /api/client-auth/connection/candidates` after
273
+ LAN candidates (priority 10) and before the relay candidate (priority 30).
274
+ `tailscale` is a distinct candidate type: old parsers drop unknown types
275
+ (verified in `connectionPayload.ts` and Electron `main.mjs`), so old clients
276
+ ignore it and use the rest; new desktop/mobile clients redeem over its `url`
277
+ like any direct URL. There is no per-transport "connected via" label surface
278
+ today, so no label change was needed.
279
+
280
+ ## Verification
281
+
282
+ ```sh
283
+ bun run test -- server/lib/tailscale/tailscale.test.js
284
+ node --check packages/web/server/lib/tailscale/service.js
285
+ ```
@@ -0,0 +1,220 @@
1
+ /**
2
+ * Tailnet-path health probe for the Tailscale self-check.
3
+ *
4
+ * Some hosts cannot reach their own MagicDNS name over the normal network
5
+ * path — containers/LXC running tailscaled with `--tun=userspace-networking`
6
+ * have no `tailscale0` interface, and host resolvers may not use MagicDNS —
7
+ * so a direct `fetch()` of `<url>/health` throws (DNS/connect error) even
8
+ * though the `tailscale serve`/`funnel` mapping works fine for tailnet
9
+ * peers. The state would sit at `starting` for the full retry budget and
10
+ * then report `probe_failed` for a mapping that was fine all along.
11
+ *
12
+ * This module tunnels the same credential-free `GET /health` check through
13
+ * the tailscale CLI instead: it spawns `tailscale nc <host> <port>` and runs
14
+ * a real TLS handshake over the child's stdio (wrapped as a Duplex via
15
+ * `stream.Duplex.from`) and sends the request with `node:http` over that
16
+ * TLS socket, so Node parses HTTP (including chunked encoding)
17
+ * and verifies the serve certificate exactly like a normal HTTPS request.
18
+ * Certificate verification stays ON — the serve cert is a valid Let's
19
+ * Encrypt cert for the ts.net name — and no Authorization header or cookie
20
+ * is ever sent.
21
+ *
22
+ * Factory: `createTailscaleNcHealthFetch({ executable, spawnFn })` returns
23
+ * `fetchHealth({ host, port, timeoutMs, signal })`, which never throws: every
24
+ * failure (spawn error, timeout, abort, TLS/HTTP error, oversized or
25
+ * non-JSON body) resolves to `{ ok: false, status: null, body: null,
26
+ * error }`. Success resolves to `{ ok: true, status, body }` where `status`
27
+ * is the HTTP status code and `body` is the parsed JSON (or null when the
28
+ * body is not JSON — callers must still check the status and the server
29
+ * identity themselves). Completion, timeout, abort, and error paths always
30
+ * kill the child and destroy the sockets. Response bodies are capped at
31
+ * 64 KiB (the remainder is drained and dropped).
32
+ */
33
+
34
+ import { spawn } from 'node:child_process';
35
+ import { request as httpRequest } from 'node:http';
36
+ import tls from 'node:tls';
37
+ import { Duplex } from 'node:stream';
38
+
39
+ import { TAILSCALE_PROBE_TIMEOUT_MS } from './tailscale.js';
40
+
41
+ // `/health` is a few hundred bytes; cap well above that so a rogue handler
42
+ // piping unbounded output through the serve mapping cannot grow memory.
43
+ const NC_PROBE_MAX_BODY_BYTES = 64 * 1024;
44
+
45
+ export const createTailscaleNcHealthFetch = ({ executable, spawnFn = spawn } = {}) => {
46
+ if (typeof executable !== 'string' || executable.length === 0) {
47
+ throw new Error('createTailscaleNcHealthFetch requires an executable path or command');
48
+ }
49
+ if (typeof spawnFn !== 'function') {
50
+ throw new Error('createTailscaleNcHealthFetch requires a spawn function');
51
+ }
52
+
53
+ const fail = (error) => ({ ok: false, status: null, body: null, error });
54
+
55
+ return async ({ host, port, timeoutMs = TAILSCALE_PROBE_TIMEOUT_MS, signal } = {}) => {
56
+ if (typeof host !== 'string' || host.length === 0 || !Number.isInteger(port) || port <= 0 || port > 65535) {
57
+ return fail('invalid-target');
58
+ }
59
+ if (signal?.aborted) return fail('aborted');
60
+ const effectiveTimeoutMs = Number.isFinite(timeoutMs) && timeoutMs > 0 ? timeoutMs : TAILSCALE_PROBE_TIMEOUT_MS;
61
+
62
+ let child = null;
63
+ try {
64
+ child = spawnFn(executable, ['nc', host, String(port)], {
65
+ windowsHide: true,
66
+ stdio: ['pipe', 'pipe', 'ignore'],
67
+ shell: false,
68
+ });
69
+ } catch {
70
+ return fail('spawn');
71
+ }
72
+ if (!child || !child.stdout || !child.stdin) {
73
+ try {
74
+ child?.kill?.('SIGKILL');
75
+ } catch {
76
+ }
77
+ return fail('spawn');
78
+ }
79
+
80
+ let tunnel = null;
81
+ try {
82
+ tunnel = Duplex.from({ readable: child.stdout, writable: child.stdin });
83
+ } catch {
84
+ try {
85
+ child.kill('SIGKILL');
86
+ } catch {
87
+ }
88
+ return fail('spawn');
89
+ }
90
+ // Stray stream errors after teardown are expected (e.g. destroying the
91
+ // tunnel aborts the in-flight handshake): every outcome is reported via
92
+ // `done`, never via unhandled stream errors.
93
+ tunnel.on('error', () => {});
94
+
95
+ try {
96
+ return await new Promise((resolve) => {
97
+ let settled = false;
98
+ let timer = null;
99
+ let tlsSocket = null;
100
+ let req = null;
101
+ const done = (value) => {
102
+ if (settled) return;
103
+ settled = true;
104
+ cleanup();
105
+ resolve(value);
106
+ };
107
+ const onAbort = () => done(fail('aborted'));
108
+ const cleanup = () => {
109
+ if (timer) {
110
+ clearTimeout(timer);
111
+ timer = null;
112
+ }
113
+ try {
114
+ signal?.removeEventListener?.('abort', onAbort);
115
+ } catch {
116
+ }
117
+ try {
118
+ req?.destroy?.();
119
+ } catch {
120
+ }
121
+ try {
122
+ tlsSocket?.destroy?.();
123
+ } catch {
124
+ }
125
+ try {
126
+ tunnel?.destroy?.();
127
+ } catch {
128
+ }
129
+ try {
130
+ child.kill?.('SIGKILL');
131
+ } catch {
132
+ }
133
+ };
134
+
135
+ timer = setTimeout(() => done(fail('timeout')), effectiveTimeoutMs);
136
+ if (timer?.unref) timer.unref();
137
+ try {
138
+ signal?.addEventListener?.('abort', onAbort, { once: true });
139
+ } catch {
140
+ }
141
+ try {
142
+ child.on?.('error', () => done(fail('spawn')));
143
+ } catch {
144
+ }
145
+
146
+ let secureSocket = null;
147
+ try {
148
+ secureSocket = tls.connect({ socket: tunnel, servername: host });
149
+ } catch {
150
+ done(fail('tls'));
151
+ return;
152
+ }
153
+ tlsSocket = secureSocket;
154
+ tlsSocket.on('error', () => done(fail('tls')));
155
+
156
+ let clientReq = null;
157
+ try {
158
+ clientReq = httpRequest(
159
+ {
160
+ host,
161
+ port,
162
+ path: '/health',
163
+ method: 'GET',
164
+ // Credential-free by construction: no Authorization header, no
165
+ // cookie. The Host header comes from `host` as usual.
166
+ headers: { Accept: 'application/json' },
167
+ // HTTP/1.1 over the already-verified TLS socket. No `agent`:
168
+ // any Agent (including `agent: false`) ignores
169
+ // `createConnection` and would resolve `host` via DNS again.
170
+ createConnection: () => tlsSocket,
171
+ },
172
+ (res) => {
173
+ const chunks = [];
174
+ let bytes = 0;
175
+ res.on('data', (chunk) => {
176
+ if (bytes + chunk.length <= NC_PROBE_MAX_BODY_BYTES) {
177
+ chunks.push(chunk);
178
+ bytes += chunk.length;
179
+ }
180
+ // Beyond the cap the rest is drained and dropped.
181
+ });
182
+ res.on('end', () => {
183
+ let body = null;
184
+ try {
185
+ body = JSON.parse(Buffer.concat(chunks).toString('utf8'));
186
+ } catch {
187
+ body = null;
188
+ }
189
+ done({ ok: true, status: res.statusCode ?? null, body });
190
+ });
191
+ res.on('error', () => done(fail('http')));
192
+ },
193
+ );
194
+ } catch {
195
+ done(fail('request'));
196
+ return;
197
+ }
198
+ req = clientReq;
199
+ req.on('error', () => done(fail('request')));
200
+ try {
201
+ req.end();
202
+ } catch {
203
+ done(fail('request'));
204
+ }
205
+ });
206
+ } catch {
207
+ // Belt and braces: the contract is never-throw, so a synchronous
208
+ // surprise above still resolves to a failure result.
209
+ try {
210
+ child?.kill?.('SIGKILL');
211
+ } catch {
212
+ }
213
+ try {
214
+ tunnel?.destroy?.();
215
+ } catch {
216
+ }
217
+ return fail('internal');
218
+ }
219
+ };
220
+ };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Authenticated Tailscale HTTP API (thin entrypoint — domain logic lives in
3
+ * `service.js`). Route conventions follow `/api/pichamber/tunnel/*`.
4
+ *
5
+ * - GET /api/pichamber/tailscale/status → status model (shared with the UI)
6
+ * - PUT /api/pichamber/tailscale/config → `{ enabled?, mode?, httpsPort? }`
7
+ * - POST /api/pichamber/tailscale/retry → re-run reconciliation
8
+ */
9
+
10
+ export const registerTailscaleRoutes = (app, { express, tailscaleService, uiAuthController }) => {
11
+ if (!tailscaleService) return;
12
+ const requireAuth = (req, res, next) => uiAuthController.requireAuth(req, res, next);
13
+
14
+ app.get('/api/pichamber/tailscale/status', requireAuth, async (_req, res) => {
15
+ try {
16
+ res.json(tailscaleService.getStatus());
17
+ } catch (error) {
18
+ res.status(500).json({ error: error?.message || 'Failed to get Tailscale status' });
19
+ }
20
+ });
21
+
22
+ app.put('/api/pichamber/tailscale/config', express.json({ limit: '16kb' }), requireAuth, async (req, res) => {
23
+ try {
24
+ const body = req.body && typeof req.body === 'object' ? req.body : {};
25
+ const patch = {};
26
+ if (Object.hasOwn(body, 'enabled')) patch.enabled = body.enabled;
27
+ if (Object.hasOwn(body, 'mode')) patch.mode = body.mode;
28
+ if (Object.hasOwn(body, 'httpsPort')) patch.httpsPort = body.httpsPort;
29
+ const result = await tailscaleService.setConfig(patch);
30
+ res.json(result);
31
+ } catch (error) {
32
+ const code = error?.code || 'unknown';
33
+ const statusCode = code === 'invalid_config' ? 422 : code === 'auth_required' ? 403 : 500;
34
+ res.status(statusCode).json({ error: error?.message || 'Failed to update Tailscale config', code });
35
+ }
36
+ });
37
+
38
+ app.post('/api/pichamber/tailscale/retry', requireAuth, async (_req, res) => {
39
+ try {
40
+ res.json(await tailscaleService.retry());
41
+ } catch (error) {
42
+ res.status(500).json({ error: error?.message || 'Tailscale retry failed' });
43
+ }
44
+ });
45
+ };