home-hosted 0.13.0 → 0.20.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 (485) hide show
  1. package/README.md +117 -322
  2. package/bin/home-hosted.mjs +41 -0
  3. package/dist/chunks/account-DiLrSyww.js +359 -0
  4. package/dist/chunks/account-DiLrSyww.js.map +1 -0
  5. package/dist/chunks/add-DEIYVkNK.js +183 -0
  6. package/dist/chunks/add-DEIYVkNK.js.map +1 -0
  7. package/dist/chunks/{archive-DP-XQR8X.js → archive-DFi3qK1c.js} +25 -73
  8. package/dist/chunks/archive-DFi3qK1c.js.map +1 -0
  9. package/dist/chunks/{atomic-C1PfJpE7.js → atomic-SZUwDtGD.js} +3 -6
  10. package/dist/chunks/atomic-SZUwDtGD.js.map +1 -0
  11. package/dist/chunks/{backup-CZcVca2a.js → backup-DnyxIzw0.js} +110 -190
  12. package/dist/chunks/backup-DnyxIzw0.js.map +1 -0
  13. package/dist/chunks/backups-BrrN6cwW.js +2203 -0
  14. package/dist/chunks/backups-BrrN6cwW.js.map +1 -0
  15. package/dist/chunks/bind-DIxrnUst.js +43 -0
  16. package/dist/chunks/bind-DIxrnUst.js.map +1 -0
  17. package/dist/chunks/config-text-DxMOQQnk.js +34 -0
  18. package/dist/chunks/config-text-DxMOQQnk.js.map +1 -0
  19. package/dist/chunks/{contracts-CMBD1TF9.js → contracts-CxZ7u1L3.js} +1239 -1454
  20. package/dist/chunks/contracts-CxZ7u1L3.js.map +1 -0
  21. package/dist/chunks/daemon-BAAYUYQC.js +211 -0
  22. package/dist/chunks/daemon-BAAYUYQC.js.map +1 -0
  23. package/dist/chunks/daemon-log-Ccu-69vB.js +179 -0
  24. package/dist/chunks/daemon-log-Ccu-69vB.js.map +1 -0
  25. package/dist/chunks/deploy-CggSOEkq.js +144 -0
  26. package/dist/chunks/deploy-CggSOEkq.js.map +1 -0
  27. package/dist/chunks/{docker-Cy9Lyvda.js → docker--Un0uLfF.js} +32 -68
  28. package/dist/chunks/docker--Un0uLfF.js.map +1 -0
  29. package/dist/chunks/{down-pKbGCW9d.js → down-CpIN7LEQ.js} +34 -94
  30. package/dist/chunks/down-CpIN7LEQ.js.map +1 -0
  31. package/dist/chunks/exposure-CDJNvOCK.js +229 -0
  32. package/dist/chunks/exposure-CDJNvOCK.js.map +1 -0
  33. package/dist/chunks/import-Bd4VZH0f.js +205 -0
  34. package/dist/chunks/import-Bd4VZH0f.js.map +1 -0
  35. package/dist/chunks/import-plan--fDS_l5r.js +147 -0
  36. package/dist/chunks/import-plan--fDS_l5r.js.map +1 -0
  37. package/dist/chunks/import-write-BTfbeV26.js +42 -0
  38. package/dist/chunks/import-write-BTfbeV26.js.map +1 -0
  39. package/dist/chunks/{init-BZ7hK9Vf.js → init-Bv3oH65x.js} +14 -50
  40. package/dist/chunks/init-Bv3oH65x.js.map +1 -0
  41. package/dist/chunks/job-CYOdN6Ub.js +341 -0
  42. package/dist/chunks/job-CYOdN6Ub.js.map +1 -0
  43. package/dist/chunks/jobs-BX4ahcfh.js +489 -0
  44. package/dist/chunks/jobs-BX4ahcfh.js.map +1 -0
  45. package/dist/chunks/last-stop-DD3lHwo_.js +42 -0
  46. package/dist/chunks/last-stop-DD3lHwo_.js.map +1 -0
  47. package/dist/chunks/layout-D0ysDNav.js +18 -0
  48. package/dist/chunks/layout-D0ysDNav.js.map +1 -0
  49. package/dist/chunks/lazy-kfcBNeqj.js +48 -0
  50. package/dist/chunks/lazy-kfcBNeqj.js.map +1 -0
  51. package/dist/chunks/log-buffer-B7jmn7ts.js +110 -0
  52. package/dist/chunks/log-buffer-B7jmn7ts.js.map +1 -0
  53. package/dist/chunks/log-files-CZL2UhuE.js +488 -0
  54. package/dist/chunks/log-files-CZL2UhuE.js.map +1 -0
  55. package/dist/chunks/{logger-B5U4GD3j.js → logger-BnrKTBHQ.js} +2 -6
  56. package/dist/chunks/logger-BnrKTBHQ.js.map +1 -0
  57. package/dist/chunks/{logs---TI_bxM.js → logs-DxKI6OW2.js} +23 -73
  58. package/dist/chunks/logs-DxKI6OW2.js.map +1 -0
  59. package/dist/chunks/ls-BseUHy_m.js +128 -0
  60. package/dist/chunks/ls-BseUHy_m.js.map +1 -0
  61. package/dist/chunks/migrate-D4w_dXDm.js +268 -0
  62. package/dist/chunks/migrate-D4w_dXDm.js.map +1 -0
  63. package/dist/chunks/{nanny-B-Eu0sFW.js → nanny-BWh7nuvv.js} +21 -14
  64. package/dist/chunks/nanny-BWh7nuvv.js.map +1 -0
  65. package/dist/chunks/{nanny-ChMtq1Zl.js → nanny-BjF2-1pv.js} +3 -3
  66. package/dist/chunks/{nanny-ChMtq1Zl.js.map → nanny-BjF2-1pv.js.map} +1 -1
  67. package/dist/chunks/nanny-DGTXVq5d.js +806 -0
  68. package/dist/chunks/nanny-DGTXVq5d.js.map +1 -0
  69. package/dist/chunks/{nanny-sweep-DErnlPY1.js → nanny-sweep-hjmZ_p7S.js} +14 -24
  70. package/dist/chunks/nanny-sweep-hjmZ_p7S.js.map +1 -0
  71. package/dist/chunks/{nearest-6KgQEDUe.js → nearest-DOx4jySJ.js} +2 -10
  72. package/dist/chunks/nearest-DOx4jySJ.js.map +1 -0
  73. package/dist/chunks/{parse-DhmG26fI.js → parse-DVMPLUDe.js} +47 -72
  74. package/dist/chunks/parse-DVMPLUDe.js.map +1 -0
  75. package/dist/chunks/password-policy-Clq6PGE-.js +9 -0
  76. package/dist/chunks/password-policy-Clq6PGE-.js.map +1 -0
  77. package/dist/chunks/{paths-CGlGDrOU.js → paths-C34-TJLh.js} +32 -56
  78. package/dist/chunks/paths-C34-TJLh.js.map +1 -0
  79. package/dist/chunks/{port-B8WBTRMk.js → port-CnsrxKNR.js} +27 -71
  80. package/dist/chunks/port-CnsrxKNR.js.map +1 -0
  81. package/dist/chunks/process-CboOFPU_.js +192 -0
  82. package/dist/chunks/process-CboOFPU_.js.map +1 -0
  83. package/dist/chunks/{restart-Des4DrAN.js → restart-C0J8dZ2L.js} +11 -29
  84. package/dist/chunks/restart-C0J8dZ2L.js.map +1 -0
  85. package/dist/chunks/run-deploy-DoNDvwT4.js +91 -0
  86. package/dist/chunks/run-deploy-DoNDvwT4.js.map +1 -0
  87. package/dist/chunks/{schema-B240VXcV.js → schema-CZ6f-PHD.js} +7 -20
  88. package/dist/chunks/schema-CZ6f-PHD.js.map +1 -0
  89. package/dist/chunks/secret-MY397r90.js +219 -0
  90. package/dist/chunks/secret-MY397r90.js.map +1 -0
  91. package/dist/chunks/secrets-CG5N4lwY.js +1061 -0
  92. package/dist/chunks/secrets-CG5N4lwY.js.map +1 -0
  93. package/dist/chunks/server-Dm_dXfTW.js +255 -0
  94. package/dist/chunks/server-Dm_dXfTW.js.map +1 -0
  95. package/dist/chunks/server-attention-UQwYXqKe.js +10 -0
  96. package/dist/chunks/server-attention-UQwYXqKe.js.map +1 -0
  97. package/dist/chunks/server-create-D7nvhgBd.js +96 -0
  98. package/dist/chunks/server-create-D7nvhgBd.js.map +1 -0
  99. package/dist/chunks/server-ids-BEQD2rFz.js +23 -0
  100. package/dist/chunks/server-ids-BEQD2rFz.js.map +1 -0
  101. package/dist/chunks/server-vars-DMYmHutL.js +27 -0
  102. package/dist/chunks/server-vars-DMYmHutL.js.map +1 -0
  103. package/dist/chunks/service-C8l-ewNA.js +585 -0
  104. package/dist/chunks/service-C8l-ewNA.js.map +1 -0
  105. package/dist/chunks/{settings-xu-XTfWg.js → settings-CtYDs5PX.js} +62 -78
  106. package/dist/chunks/settings-CtYDs5PX.js.map +1 -0
  107. package/dist/chunks/{setup-temp-CAN4_bA-.js → setup-temp-TAtDmMMU.js} +43 -37
  108. package/dist/chunks/setup-temp-TAtDmMMU.js.map +1 -0
  109. package/dist/chunks/shape-CDGeYl_J.js +9 -0
  110. package/dist/chunks/shape-CDGeYl_J.js.map +1 -0
  111. package/dist/chunks/{src-BtWMFmzZ.js → src-BnzkVy_M.js} +12548 -10576
  112. package/dist/chunks/src-BnzkVy_M.js.map +1 -0
  113. package/dist/chunks/{status-DT1EsA-B.js → status-efbbfYZQ.js} +53 -26
  114. package/dist/chunks/status-efbbfYZQ.js.map +1 -0
  115. package/dist/chunks/store-Bs_Lljjm.js +2082 -0
  116. package/dist/chunks/store-Bs_Lljjm.js.map +1 -0
  117. package/dist/chunks/template-xan58bJh.js +28 -0
  118. package/dist/chunks/template-xan58bJh.js.map +1 -0
  119. package/dist/chunks/token-DDeWfZA4.js +142 -0
  120. package/dist/chunks/token-DDeWfZA4.js.map +1 -0
  121. package/dist/chunks/{ui-D562aqw5.js → ui-BcIAtyxE.js} +68 -79
  122. package/dist/chunks/ui-BcIAtyxE.js.map +1 -0
  123. package/dist/chunks/{ui-dir-CsU3uLNV.js → ui-dir-ClCzVRc3.js} +3 -7
  124. package/dist/chunks/ui-dir-ClCzVRc3.js.map +1 -0
  125. package/dist/chunks/ui-format-CDvvqOoi.js +53 -0
  126. package/dist/chunks/ui-format-CDvvqOoi.js.map +1 -0
  127. package/dist/chunks/{ui-release-DKzVvlLd.js → ui-release-XbJ85pYI.js} +36 -38
  128. package/dist/chunks/ui-release-XbJ85pYI.js.map +1 -0
  129. package/dist/chunks/{ui-revert-EkBBwRTt.js → ui-revert-Dgawq7ze.js} +4 -4
  130. package/dist/chunks/ui-revert-Dgawq7ze.js.map +1 -0
  131. package/dist/chunks/{ui-switch-BnZTdMDd.js → ui-switch-CfQMbZ0g.js} +31 -38
  132. package/dist/chunks/ui-switch-CfQMbZ0g.js.map +1 -0
  133. package/dist/chunks/{ui-update-_xryLYxw.js → ui-update-B3PPivUm.js} +30 -48
  134. package/dist/chunks/ui-update-B3PPivUm.js.map +1 -0
  135. package/dist/chunks/ui-update-CAiH2tFb.js +109 -0
  136. package/dist/chunks/ui-update-CAiH2tFb.js.map +1 -0
  137. package/dist/chunks/{up-Pdz-l6IH.js → up-BQSnYxYd.js} +47 -53
  138. package/dist/chunks/up-BQSnYxYd.js.map +1 -0
  139. package/dist/chunks/{usage-DFrCVXpT.js → usage-KG8TeOio.js} +7 -20
  140. package/dist/chunks/usage-KG8TeOio.js.map +1 -0
  141. package/dist/chunks/{workspaces-DYcfvKV_.js → workspaces-D9akpzU8.js} +80 -68
  142. package/dist/chunks/workspaces-D9akpzU8.js.map +1 -0
  143. package/dist/chunks/{wsl-temperature-BiCI4iK6.js → wsl-temperature-D-_d4Yk1.js} +47 -42
  144. package/dist/chunks/wsl-temperature-D-_d4Yk1.js.map +1 -0
  145. package/dist/cli.js +306 -238
  146. package/dist/cli.js.map +1 -1
  147. package/dist/client.js +76 -29
  148. package/dist/client.js.map +1 -1
  149. package/dist/types/api/acme.d.ts +3 -7
  150. package/dist/types/api/auth/$.routes.d.ts +107 -16
  151. package/dist/types/api/backups.d.ts +5 -5
  152. package/dist/types/api/control.d.ts +747 -38
  153. package/dist/types/api/ddns.d.ts +13 -18
  154. package/dist/types/api/events.d.ts +9 -3
  155. package/dist/types/api/health.d.ts +2 -4
  156. package/dist/types/api/jobs.d.ts +438 -0
  157. package/dist/types/api/logs.d.ts +20 -0
  158. package/dist/types/api/metrics.d.ts +2 -5
  159. package/dist/types/api/notifications.d.ts +3 -6
  160. package/dist/types/api/proxy.d.ts +63 -23
  161. package/dist/types/api/server-ops.d.ts +17 -0
  162. package/dist/types/api/servers/$.routes.d.ts +418 -186
  163. package/dist/types/api/session-required.d.ts +16 -0
  164. package/dist/types/api/settings.d.ts +7 -7
  165. package/dist/types/api/state.d.ts +100 -10
  166. package/dist/types/api/static.d.ts +2 -2
  167. package/dist/types/api/tls.d.ts +2 -5
  168. package/dist/types/api/workspaces/$.routes.d.ts +186 -12
  169. package/dist/types/api/wsl-temperature.d.ts +4 -10
  170. package/dist/types/app.d.ts +4511 -2778
  171. package/dist/types/cli/account.d.ts +23 -0
  172. package/dist/types/cli/add.d.ts +96 -0
  173. package/dist/types/cli/args.d.ts +24 -35
  174. package/dist/types/cli/backup-offline.d.ts +2 -8
  175. package/dist/types/cli/backup.d.ts +12 -21
  176. package/dist/types/cli/down.d.ts +15 -41
  177. package/dist/types/cli/import-plan.d.ts +55 -0
  178. package/dist/types/cli/import-write.d.ts +5 -0
  179. package/dist/types/cli/import.d.ts +86 -0
  180. package/dist/types/cli/io.d.ts +26 -35
  181. package/dist/types/cli/job.d.ts +99 -0
  182. package/dist/types/cli/logs.d.ts +1 -10
  183. package/dist/types/cli/ls.d.ts +57 -0
  184. package/dist/types/cli/migrate.d.ts +31 -8
  185. package/dist/types/cli/nearest.d.ts +1 -9
  186. package/dist/types/cli/run-deploy.d.ts +36 -0
  187. package/dist/types/cli/secret.d.ts +90 -0
  188. package/dist/types/cli/server.d.ts +6 -15
  189. package/dist/types/cli/service.d.ts +135 -0
  190. package/dist/types/cli/setup-temp.d.ts +17 -13
  191. package/dist/types/cli/status.d.ts +7 -1
  192. package/dist/types/cli/token.d.ts +6 -0
  193. package/dist/types/cli/ui-switch.d.ts +3 -14
  194. package/dist/types/cli/ui-update.d.ts +3 -16
  195. package/dist/types/cli/up.d.ts +9 -22
  196. package/dist/types/cli/usage.d.ts +2 -6
  197. package/dist/types/cli.d.ts +1 -10
  198. package/dist/types/client.d.ts +4099 -1142
  199. package/dist/types/config/accounts.d.ts +16 -0
  200. package/dist/types/config/jobs.d.ts +68 -0
  201. package/dist/types/config/layout.d.ts +2 -8
  202. package/dist/types/config/migrations.d.ts +9 -41
  203. package/dist/types/config/parse.d.ts +8 -13
  204. package/dist/types/config/patch.d.ts +1 -6
  205. package/dist/types/config/schema.d.ts +16 -18
  206. package/dist/types/config/secret-parts.d.ts +6 -27
  207. package/dist/types/config/secrets.d.ts +167 -88
  208. package/dist/types/config/seed.d.ts +1 -6
  209. package/dist/types/config/server-ids.d.ts +2 -11
  210. package/dist/types/config/settings.d.ts +13 -49
  211. package/dist/types/config/store.d.ts +17 -54
  212. package/dist/types/config/workspaces.d.ts +24 -56
  213. package/dist/types/helpers/action-result.d.ts +18 -32
  214. package/dist/types/helpers/atomic.d.ts +1 -4
  215. package/dist/types/helpers/backoff.d.ts +0 -1
  216. package/dist/types/helpers/bind.d.ts +3 -11
  217. package/dist/types/helpers/config-text.d.ts +4 -19
  218. package/dist/types/helpers/cookies.d.ts +2 -7
  219. package/dist/types/helpers/copy-tree.d.ts +4 -12
  220. package/dist/types/helpers/daemon-log.d.ts +8 -33
  221. package/dist/types/helpers/daemon.d.ts +20 -70
  222. package/dist/types/helpers/deferred.d.ts +2 -4
  223. package/dist/types/helpers/env-file.d.ts +2 -7
  224. package/dist/types/helpers/error.d.ts +3 -14
  225. package/dist/types/helpers/event-stream.d.ts +18 -10
  226. package/dist/types/helpers/factory.d.ts +2 -3
  227. package/dist/types/helpers/last-stop.d.ts +5 -12
  228. package/dist/types/helpers/logger.d.ts +1 -5
  229. package/dist/types/helpers/open.d.ts +0 -1
  230. package/dist/types/helpers/openapi.d.ts +19 -5
  231. package/dist/types/helpers/paths.d.ts +18 -53
  232. package/dist/types/helpers/restore-lock.d.ts +2 -17
  233. package/dist/types/helpers/runtime.d.ts +3 -13
  234. package/dist/types/helpers/secret-compare.d.ts +2 -10
  235. package/dist/types/helpers/server-create.d.ts +15 -0
  236. package/dist/types/helpers/shell.d.ts +2 -16
  237. package/dist/types/helpers/sse.d.ts +8 -6
  238. package/dist/types/helpers/ui-dir.d.ts +1 -5
  239. package/dist/types/helpers/utf8-chunks.d.ts +2 -8
  240. package/dist/types/helpers/validate.d.ts +2 -4
  241. package/dist/types/helpers/validator.d.ts +8 -4
  242. package/dist/types/helpers/version.d.ts +1 -6
  243. package/dist/types/helpers/workspace.d.ts +24 -16
  244. package/dist/types/index.d.ts +2 -3
  245. package/dist/types/middleware/auth.d.ts +8 -27
  246. package/dist/types/middleware/body-limit.d.ts +10 -0
  247. package/dist/types/middleware/host.d.ts +4 -23
  248. package/dist/types/middleware/loopback.d.ts +1 -8
  249. package/dist/types/middleware/token-scope.d.ts +34 -0
  250. package/dist/types/node-compat.d.ts +43 -0
  251. package/dist/types/openapi-reference.d.ts +4 -19
  252. package/dist/types/openapi.d.ts +5 -8
  253. package/dist/types/providers/archive.d.ts +8 -25
  254. package/dist/types/providers/backup-hook.d.ts +4 -19
  255. package/dist/types/providers/ddns/dyndns2.d.ts +0 -3
  256. package/dist/types/providers/ddns/index.d.ts +2 -3
  257. package/dist/types/providers/ddns/ip.d.ts +2 -12
  258. package/dist/types/providers/ddns/namecheap-api.d.ts +3 -2
  259. package/dist/types/providers/ddns/types.d.ts +6 -32
  260. package/dist/types/providers/ddns/zone.d.ts +1 -4
  261. package/dist/types/providers/docker.d.ts +18 -45
  262. package/dist/types/providers/entry-state.d.ts +4 -9
  263. package/dist/types/providers/health-check.d.ts +1 -5
  264. package/dist/types/providers/host.d.ts +33 -108
  265. package/dist/types/providers/identity.d.ts +9 -34
  266. package/dist/types/providers/log-tail.d.ts +14 -24
  267. package/dist/types/providers/nanny-sweep.d.ts +8 -25
  268. package/dist/types/providers/nanny.d.ts +16 -58
  269. package/dist/types/providers/port.d.ts +28 -83
  270. package/dist/types/providers/proc.d.ts +22 -80
  271. package/dist/types/providers/process.d.ts +12 -36
  272. package/dist/types/providers/proxy/admin.d.ts +11 -0
  273. package/dist/types/providers/proxy/types.d.ts +4 -16
  274. package/dist/types/providers/telegram.d.ts +1 -17
  275. package/dist/types/providers/ui-release.d.ts +15 -25
  276. package/dist/types/providers/webhook.d.ts +8 -29
  277. package/dist/types/providers/wsl-temperature.d.ts +13 -22
  278. package/dist/types/services/acme-challenge.d.ts +2 -16
  279. package/dist/types/services/auth.d.ts +65 -80
  280. package/dist/types/services/backups/archive-safety.d.ts +30 -0
  281. package/dist/types/services/backups/paths.d.ts +31 -0
  282. package/dist/types/services/backups.d.ts +61 -271
  283. package/dist/types/services/config-watch.d.ts +3 -15
  284. package/dist/types/services/control-server.d.ts +6 -10
  285. package/dist/types/services/ddns.d.ts +12 -13
  286. package/dist/types/services/dependencies.d.ts +3 -14
  287. package/dist/types/services/deploy.d.ts +34 -0
  288. package/dist/types/services/events.d.ts +15 -9
  289. package/dist/types/services/exposure.d.ts +13 -63
  290. package/dist/types/services/history.d.ts +5 -14
  291. package/dist/types/services/host-monitor.d.ts +6 -11
  292. package/dist/types/services/init.d.ts +5 -35
  293. package/dist/types/services/job-ledger.d.ts +27 -0
  294. package/dist/types/services/jobs.d.ts +113 -0
  295. package/dist/types/services/log-buffer.d.ts +7 -8
  296. package/dist/types/services/log-files.d.ts +12 -42
  297. package/dist/types/services/log-relay.d.ts +3 -13
  298. package/dist/types/services/nanny.d.ts +3 -10
  299. package/dist/types/services/notifications.d.ts +31 -61
  300. package/dist/types/services/panel.d.ts +32 -78
  301. package/dist/types/services/proxy-certificates/certificates.d.ts +31 -69
  302. package/dist/types/services/proxy-config.d.ts +15 -36
  303. package/dist/types/services/proxy-dns01.d.ts +14 -0
  304. package/dist/types/services/proxy.d.ts +73 -254
  305. package/dist/types/services/scheduler.d.ts +46 -0
  306. package/dist/types/services/state.d.ts +17 -8
  307. package/dist/types/services/supervisor/compose.d.ts +2 -6
  308. package/dist/types/services/supervisor/entry.d.ts +29 -32
  309. package/dist/types/services/supervisor/health.d.ts +8 -31
  310. package/dist/types/services/supervisor/job-run.d.ts +36 -0
  311. package/dist/types/services/supervisor/output.d.ts +13 -77
  312. package/dist/types/services/supervisor/persistent.d.ts +5 -11
  313. package/dist/types/services/supervisor/port-preflight.d.ts +4 -10
  314. package/dist/types/services/supervisor/records.d.ts +27 -60
  315. package/dist/types/services/supervisor/restart-required.d.ts +13 -0
  316. package/dist/types/services/supervisor/spawn.d.ts +3 -5
  317. package/dist/types/services/supervisor/view.d.ts +3 -1
  318. package/dist/types/services/supervisor.d.ts +31 -43
  319. package/dist/types/services/tls.d.ts +6 -17
  320. package/dist/types/services/ui-update.d.ts +19 -17
  321. package/dist/types/services/ui.d.ts +10 -19
  322. package/dist/types/shared/action-outcome.d.ts +2 -7
  323. package/dist/types/shared/api-client.d.ts +133 -177
  324. package/dist/types/shared/api-scopes.d.ts +17 -0
  325. package/dist/types/shared/backup-scope.d.ts +16 -90
  326. package/dist/types/shared/clone.d.ts +2 -11
  327. package/dist/types/shared/contracts/accounts.d.ts +99 -0
  328. package/dist/types/shared/contracts/backups.d.ts +219 -0
  329. package/dist/types/shared/contracts/ddns.d.ts +208 -0
  330. package/dist/types/shared/contracts/frames.d.ts +1395 -0
  331. package/dist/types/shared/contracts/index.d.ts +3 -0
  332. package/dist/types/shared/contracts/logs.d.ts +107 -0
  333. package/dist/types/shared/contracts/proxy.d.ts +303 -0
  334. package/dist/types/shared/contracts.d.ts +852 -1982
  335. package/dist/types/shared/cpu-scale.d.ts +3 -19
  336. package/dist/types/shared/crash-cause.d.ts +8 -0
  337. package/dist/types/shared/cron.d.ts +70 -0
  338. package/dist/types/shared/ddns-form.d.ts +9 -43
  339. package/dist/types/shared/endpoint.d.ts +1 -7
  340. package/dist/types/shared/error-codes.d.ts +438 -0
  341. package/dist/types/shared/error-message.d.ts +1 -7
  342. package/dist/types/shared/fields.d.ts +7 -17
  343. package/dist/types/shared/form-repair.d.ts +1 -5
  344. package/dist/types/shared/generated.d.ts +3 -19
  345. package/dist/types/shared/host-readings.d.ts +25 -128
  346. package/dist/types/shared/lazy.d.ts +1 -1
  347. package/dist/types/shared/live-frames.d.ts +2 -8
  348. package/dist/types/shared/live-series.d.ts +2 -8
  349. package/dist/types/shared/live-store.d.ts +4 -8
  350. package/dist/types/shared/log-download.d.ts +6 -0
  351. package/dist/types/shared/meta.d.ts +6 -0
  352. package/dist/types/shared/password-policy.d.ts +10 -0
  353. package/dist/types/shared/patch-diff.d.ts +13 -72
  354. package/dist/types/shared/port-reading.d.ts +18 -0
  355. package/dist/types/shared/probe-latency.d.ts +3 -21
  356. package/dist/types/shared/proxy-form.d.ts +33 -74
  357. package/dist/types/shared/proxy-validate.d.ts +11 -0
  358. package/dist/types/shared/query-params.d.ts +8 -0
  359. package/dist/types/shared/server-attention.d.ts +2 -27
  360. package/dist/types/shared/server-form.d.ts +15 -54
  361. package/dist/types/shared/server-key.d.ts +1 -12
  362. package/dist/types/shared/server-readings.d.ts +7 -32
  363. package/dist/types/shared/server-url.d.ts +9 -31
  364. package/dist/types/shared/shape.d.ts +1 -16
  365. package/dist/types/shared/stream-access.d.ts +2 -8
  366. package/dist/types/shared/ui-format.d.ts +25 -65
  367. package/docs/API.md +315 -107
  368. package/docs/BACKUPS.md +61 -56
  369. package/docs/CLI.md +255 -49
  370. package/docs/DDNS.md +35 -49
  371. package/docs/JOBS.md +129 -0
  372. package/docs/NOTIFICATIONS.md +58 -90
  373. package/docs/REVERSE_PROXY.md +116 -188
  374. package/docs/SECURITY.md +126 -44
  375. package/docs/SERVERS.md +282 -409
  376. package/docs/UI_CREATION.md +90 -47
  377. package/docs/demo/blank-host-restore.sh +31 -7
  378. package/package.json +15 -6
  379. package/scripts/prepare.mjs +47 -0
  380. package/uis/stock/dist/assets/CopyButton-8mliL0xi.js +1 -0
  381. package/uis/stock/dist/assets/GlobalSettingsView-BINXY77E.js +1 -0
  382. package/uis/stock/dist/assets/LogViewer-kiSnTwdY.js +1 -0
  383. package/uis/stock/dist/assets/LogsView-DDXf_ONs.js +1 -0
  384. package/uis/stock/dist/assets/Modal-lrUuViF2.js +39 -0
  385. package/uis/stock/dist/assets/ProxyView-uXMaJdSQ.js +1 -0
  386. package/uis/stock/dist/assets/ServerDetailView-CW0Vb_c0.js +4 -0
  387. package/uis/stock/dist/assets/SettingsShell-B135xWjJ.js +1 -0
  388. package/uis/stock/dist/assets/SettingsView-BLtWxVkl.js +2 -0
  389. package/uis/stock/dist/assets/de-BIoTrHBQ.js +1 -0
  390. package/uis/stock/dist/assets/es-x4-ih8lH.js +1 -0
  391. package/uis/stock/dist/assets/fr-DatqBBkO.js +1 -0
  392. package/uis/stock/dist/assets/index-CnojaKcA.css +2 -0
  393. package/uis/stock/dist/assets/index-D-CiZReu.js +16 -0
  394. package/uis/stock/dist/assets/ja-CW1703Gw.js +1 -0
  395. package/uis/stock/dist/assets/ko-wFbT4XtK.js +1 -0
  396. package/uis/stock/dist/assets/ru-C1p5C4VN.js +1 -0
  397. package/uis/stock/dist/assets/useUnsavedGuard-BcsXsfCC.js +9 -0
  398. package/uis/stock/dist/assets/vi-CDqr0uie.js +1 -0
  399. package/uis/stock/dist/assets/zh-CN-BJ7iit-X.js +1 -0
  400. package/uis/stock/dist/index.html +4 -3
  401. package/uis/stock/dist/ui.json +3 -3
  402. package/dist/chunks/archive-DP-XQR8X.js.map +0 -1
  403. package/dist/chunks/atomic-C1PfJpE7.js.map +0 -1
  404. package/dist/chunks/backup-CZcVca2a.js.map +0 -1
  405. package/dist/chunks/backups-CFRaWe_m.js +0 -4691
  406. package/dist/chunks/backups-CFRaWe_m.js.map +0 -1
  407. package/dist/chunks/config-text-DifCHhnz.js +0 -50
  408. package/dist/chunks/config-text-DifCHhnz.js.map +0 -1
  409. package/dist/chunks/contracts-CMBD1TF9.js.map +0 -1
  410. package/dist/chunks/daemon-log-BVj8cDEo.js +0 -241
  411. package/dist/chunks/daemon-log-BVj8cDEo.js.map +0 -1
  412. package/dist/chunks/daemon-qKVECISl.js +0 -247
  413. package/dist/chunks/daemon-qKVECISl.js.map +0 -1
  414. package/dist/chunks/docker-Cy9Lyvda.js.map +0 -1
  415. package/dist/chunks/down-pKbGCW9d.js.map +0 -1
  416. package/dist/chunks/init-BZ7hK9Vf.js.map +0 -1
  417. package/dist/chunks/last-stop-C-BXz_XI.js +0 -53
  418. package/dist/chunks/last-stop-C-BXz_XI.js.map +0 -1
  419. package/dist/chunks/layout-DwTtmund.js +0 -24
  420. package/dist/chunks/layout-DwTtmund.js.map +0 -1
  421. package/dist/chunks/lazy-Ce5zEAq1.js +0 -66
  422. package/dist/chunks/lazy-Ce5zEAq1.js.map +0 -1
  423. package/dist/chunks/log-buffer-Dy9HHDMD.js +0 -414
  424. package/dist/chunks/log-buffer-Dy9HHDMD.js.map +0 -1
  425. package/dist/chunks/logger-B5U4GD3j.js.map +0 -1
  426. package/dist/chunks/logs---TI_bxM.js.map +0 -1
  427. package/dist/chunks/migrate-Cfoq-Vgh.js +0 -155
  428. package/dist/chunks/migrate-Cfoq-Vgh.js.map +0 -1
  429. package/dist/chunks/nanny-B-Eu0sFW.js.map +0 -1
  430. package/dist/chunks/nanny-BtWfy0QH.js +0 -1167
  431. package/dist/chunks/nanny-BtWfy0QH.js.map +0 -1
  432. package/dist/chunks/nanny-sweep-DErnlPY1.js.map +0 -1
  433. package/dist/chunks/nearest-6KgQEDUe.js.map +0 -1
  434. package/dist/chunks/parse-DhmG26fI.js.map +0 -1
  435. package/dist/chunks/paths-CGlGDrOU.js.map +0 -1
  436. package/dist/chunks/port-B8WBTRMk.js.map +0 -1
  437. package/dist/chunks/restart-Des4DrAN.js.map +0 -1
  438. package/dist/chunks/schema-B240VXcV.js.map +0 -1
  439. package/dist/chunks/secrets-BieELnZh.js +0 -562
  440. package/dist/chunks/secrets-BieELnZh.js.map +0 -1
  441. package/dist/chunks/server-Bge2r2qQ.js +0 -169
  442. package/dist/chunks/server-Bge2r2qQ.js.map +0 -1
  443. package/dist/chunks/server-ids-DRuNLVCV.js +0 -32
  444. package/dist/chunks/server-ids-DRuNLVCV.js.map +0 -1
  445. package/dist/chunks/set-password-D5vZqqSX.js +0 -43
  446. package/dist/chunks/set-password-D5vZqqSX.js.map +0 -1
  447. package/dist/chunks/set-token-obPiEJYk.js +0 -78
  448. package/dist/chunks/set-token-obPiEJYk.js.map +0 -1
  449. package/dist/chunks/settings-xu-XTfWg.js.map +0 -1
  450. package/dist/chunks/setup-temp-CAN4_bA-.js.map +0 -1
  451. package/dist/chunks/shape-DnTKzjQ2.js +0 -24
  452. package/dist/chunks/shape-DnTKzjQ2.js.map +0 -1
  453. package/dist/chunks/src-BtWMFmzZ.js.map +0 -1
  454. package/dist/chunks/status-DT1EsA-B.js.map +0 -1
  455. package/dist/chunks/ui-D562aqw5.js.map +0 -1
  456. package/dist/chunks/ui-dir-CsU3uLNV.js.map +0 -1
  457. package/dist/chunks/ui-release-DKzVvlLd.js.map +0 -1
  458. package/dist/chunks/ui-revert-EkBBwRTt.js.map +0 -1
  459. package/dist/chunks/ui-switch-BnZTdMDd.js.map +0 -1
  460. package/dist/chunks/ui-update-_xryLYxw.js.map +0 -1
  461. package/dist/chunks/up-Pdz-l6IH.js.map +0 -1
  462. package/dist/chunks/usage-DFrCVXpT.js.map +0 -1
  463. package/dist/chunks/workspaces-DYcfvKV_.js.map +0 -1
  464. package/dist/chunks/wsl-temperature-BiCI4iK6.js.map +0 -1
  465. package/dist/types/cli/set-password.d.ts +0 -14
  466. package/dist/types/cli/set-token.d.ts +0 -21
  467. package/uis/stock/dist/assets/CopyButton-BUBKRJyY.js +0 -1
  468. package/uis/stock/dist/assets/GlobalSettingsView-yYMcRWvt.js +0 -1
  469. package/uis/stock/dist/assets/LogViewer-DIliXy62.js +0 -1
  470. package/uis/stock/dist/assets/LogsView-B7Z-7RNg.js +0 -1
  471. package/uis/stock/dist/assets/Modal-DmKa5Qpp.js +0 -39
  472. package/uis/stock/dist/assets/ProxyView-DvZiNkwb.js +0 -1
  473. package/uis/stock/dist/assets/ServerDetailView-6idGT_EX.js +0 -2
  474. package/uis/stock/dist/assets/SettingsShell-CeGtleYI.js +0 -1
  475. package/uis/stock/dist/assets/SettingsView-BrhJIrmk.js +0 -2
  476. package/uis/stock/dist/assets/de-BRITeb0H.js +0 -1
  477. package/uis/stock/dist/assets/es-B2zIEssV.js +0 -1
  478. package/uis/stock/dist/assets/fr-s0ZOBEqh.js +0 -1
  479. package/uis/stock/dist/assets/index-C1MehbKy.css +0 -2
  480. package/uis/stock/dist/assets/index-CnBN54wF.js +0 -15
  481. package/uis/stock/dist/assets/ja-CU7MR85V.js +0 -1
  482. package/uis/stock/dist/assets/ko-tL5Me6d-.js +0 -1
  483. package/uis/stock/dist/assets/ru-92yrvkNJ.js +0 -1
  484. package/uis/stock/dist/assets/vi-CzvY16k2.js +0 -1
  485. package/uis/stock/dist/assets/zh-CN-DDwFW_uW.js +0 -1
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","names":[],"sources":["../src/shared/error-message.ts","../src/cli/args.ts","../src/helpers/shell.ts","../src/cli/io.ts","../src/helpers/runtime.ts","../src/helpers/version.ts","../src/cli.ts"],"sourcesContent":["/**\n * One rendering for a thrown value, so a caught error reads the same everywhere.\n *\n * `catch` binds `unknown`, and the same ternary was written out in ~60 places across the\n * panel and both UIs. Two idioms in one codebase is how they drift, and the UIs are\n * separate bundles: a fix applied to one copy silently misses the others.\n */\nexport function errorMessage(caught: unknown): string {\n return caught instanceof Error ? caught.message : String(caught)\n}\n","import type { ArgsDef } from 'citty'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { nearestWord } from './nearest'\n\n/**\n * The argument work that happens *before* citty: `--home`/`--project` have to\n * change the environment before any `#src` module resolves a path, and the\n * curated surface (`help`, `version`, `unknown command`) has to stay byte-for-\n * byte what it always was. Both live here so they can be tested without a\n * terminal, a daemon or a spawned process; this module imports node builtins\n * only and never reads the state directories itself.\n */\n\nexport interface DirFlags {\n project?: string\n home?: string\n}\n\nexport interface DirFlagResult extends DirFlags {\n rest: string[]\n error?: string\n}\n\n/** `--home`/`--project` are handled for every command, so they are peeled off first. */\nexport function extractDirFlags(argv: string[]): DirFlagResult {\n const rest: string[] = []\n let project: string | undefined\n let home: string | undefined\n\n for (let index = 0; index < argv.length; index++) {\n const arg = argv[index]!\n const equals = arg.indexOf('=')\n const name = equals === -1 ? arg : arg.slice(0, equals)\n if (name !== '--project' && name !== '--home') {\n rest.push(arg)\n continue\n }\n const value = equals === -1 ? argv[++index] : arg.slice(equals + 1)\n if (value === undefined || value.length === 0)\n return { rest, project, home, error: `${name} needs a directory` }\n if (name === '--project')\n project = value\n else\n home = value\n }\n\n return { rest, project, home }\n}\n\n/** Set before any state module is imported, so it decides where state lives. */\nexport function applyDirFlags(flags: DirFlags): void {\n if (flags.project !== undefined)\n process.env.HHOSTED_PROJECT = path.resolve(flags.project)\n if (flags.home !== undefined)\n process.env.HHOSTED_HOME = path.resolve(flags.home)\n}\n\nexport type Invocation\n = | { kind: 'help', command?: string }\n | { kind: 'version' }\n | { kind: 'command', argv: string[] }\n | { kind: 'unknown', command: string }\n\nconst HELP_TOKENS = new Set(['help', '--help', '-h'])\nconst VERSION_TOKENS = new Set(['version', '--version', '-v'])\n// After a command, only the flag forms count: a bare `help` may be the value of an\n// option (`init --name help`), and answering that with the usage text would skip\n// the command instead of running it.\nconst HELP_FLAGS = new Set(['--help', '-h'])\n/** Commands whose first bare word is a server id, so `<command> help` names a server, not help. */\nconst ID_FIRST = new Set(['start', 'stop', 'free-port', 'restart', 'logs'])\nconst VERSION_FLAGS = new Set(['--version', '-v'])\n\n/**\n * What the stripped argv means, before citty sees it.\n *\n * `help`/`version` are commands here, not flags, and a help or version flag on a\n * command is answered the same way instead of being parsed as one of that\n * command's options. A help flag after a command keeps that command's name, so\n * the curated text can stay scoped to it; the bare `help` (or a top-level flag)\n * is the whole reference. A first token that starts with `-` is the one-shot\n * form (`home-hosted -p 4000`), so `up` is prepended. Anything else has to name\n * a command, which keeps the old `unknown command:` text exact.\n */\nexport function resolveInvocation(argv: string[], commands: readonly string[]): Invocation {\n if (argv.length === 0)\n return { kind: 'command', argv: ['up'] }\n\n const first = argv[0]!\n // `help <command>` is `<command> --help`; `help` alone, or before anything else, is the reference.\n if (HELP_TOKENS.has(first))\n return argv[1] !== undefined && commands.includes(argv[1]) ? { kind: 'help', command: argv[1] } : { kind: 'help' }\n if (VERSION_TOKENS.has(first))\n return { kind: 'version' }\n\n if (first.startsWith('-'))\n return { kind: 'command', argv: ['up', ...argv] }\n\n if (!commands.includes(first))\n return { kind: 'unknown', command: first }\n\n // `<command> help`, when `help` is the only word after it and the command takes no id there:\n // `start help` may name a server called `help`, and `init --name help` is an option value.\n if (argv.length === 2 && argv[1] === 'help' && !ID_FIRST.has(first))\n return { kind: 'help', command: first }\n\n for (const arg of argv.slice(1)) {\n if (HELP_FLAGS.has(arg))\n return { kind: 'help', command: first }\n if (VERSION_FLAGS.has(arg))\n return { kind: 'version' }\n }\n\n return { kind: 'command', argv }\n}\n\nconst CAMEL = /[A-Z]/g\n\n/** citty takes camelCase definitions; the flag a person types is kebab-case. */\nfunction kebab(name: string): string {\n return name.replace(CAMEL, match => `-${match.toLowerCase()}`)\n}\n\nfunction aliasesOf(def: ArgsDef[string]): string[] {\n if (def === undefined || !('alias' in def) || def.alias === undefined)\n return []\n return Array.isArray(def.alias) ? def.alias : [def.alias]\n}\n\n/**\n * Every spelling that reaches one declared option: the key, its kebab form, each alias, and the\n * `no-` negation citty gives a boolean. `findArg` accepts on this set and the suggestion offers from\n * it, so a suggestion can never name a spelling the parser would then refuse.\n */\nfunction namesOf(key: string, def: NonNullable<ArgsDef[string]>): string[] {\n return [key, kebab(key), ...aliasesOf(def)]\n}\n\n/** The spellings of every option this command declares, for a suggestion. */\nfunction declaredOptionNames(argsDef: ArgsDef): string[] {\n const names: string[] = []\n for (const [key, def] of Object.entries(argsDef)) {\n if (def === undefined || def.type === 'positional')\n continue\n names.push(...namesOf(key, def))\n if (def.type === 'boolean')\n names.push(...namesOf(key, def).map(name => `no-${name}`))\n }\n return names\n}\n\nfunction findArg(argsDef: ArgsDef, name: string): ArgsDef[string] | undefined {\n for (const [key, def] of Object.entries(argsDef)) {\n if (def === undefined)\n continue\n // A positional is never reachable as `--<key>`: `start --id web` is a mistake,\n // not a second way to spell `start web`.\n if (def.type === 'positional')\n continue\n if (namesOf(key, def).includes(name))\n return def\n // `--no-<flag>` is citty's negation of a declared boolean, never an option.\n if (def.type === 'boolean' && (name === `no-${key}` || name === `no-${kebab(key)}`))\n return def\n }\n return undefined\n}\n\n/**\n * citty parses permissively (`strict: false`), so a mistyped flag would quietly do\n * nothing — `--autostart` where `--no-autostart` was meant would start the panel\n * with the wrong policy. This keeps the refusal the command line always had, from\n * citty's own definitions rather than a second list.\n *\n * `undefined` means the command parses its own argv — `ui-switch` calls `node:util`'s\n * `parseArgs` with its own options, which is strict already — so it is left alone. An\n * **empty** definition is different: it declares that this command takes nothing, so\n * every flag and every bare word is refused here. Reading `{}` as \"parses its own argv\"\n * is what let `ui-revert`, which has no parser at all, accept and discard anything:\n * `ui-revert --dry-run` deleted the installed UI and exited 0.\n *\n * Returns the message to print, or null.\n */\nexport function rejectUnknownFlags(argv: string[], argsDef: ArgsDef | undefined): string | null {\n if (argsDef === undefined)\n return null\n\n // Declared positionals are the only bare arguments a command accepts, and they\n // are filled in the order they were declared (`start <id>`).\n let positionals = Object.values(argsDef).filter(def => def?.type === 'positional').length\n\n for (let index = 0; index < argv.length; index++) {\n const token = argv[index]!\n if (token === '--')\n return null\n if (!token.startsWith('-') || token.length === 1) {\n if (positionals === 0)\n return `Unexpected argument '${token}'`\n positionals -= 1\n continue\n }\n\n const body = token.startsWith('--') ? token.slice(2) : token.slice(1)\n const equals = body.indexOf('=')\n const name = equals === -1 ? body : body.slice(0, equals)\n const def = name.length === 0 ? undefined : findArg(argsDef, name)\n if (def === undefined) {\n // The valid names are right here in `argsDef`, so a near miss can name the option it meant —\n // `--autostart` for `--no-autostart` is the case that matters. A far-off name gets nothing.\n const suggested = nearestWord(name, declaredOptionNames(argsDef))\n const hint = suggested === null ? '' : ` — did you mean \\`--${suggested}\\`?`\n return `Unknown option '${token}'${hint}`\n }\n // A string option consumes the next token, unless it was given inline.\n if (def.type === 'string' && equals === -1 && argv[index + 1] === undefined)\n return `Option '${token}' needs a value`\n if (def.type === 'string' && equals === -1)\n index += 1\n }\n\n return null\n}\n\nexport interface UpFlags {\n port?: number\n host?: string\n autostart: boolean\n open: boolean\n foreground: boolean\n printConfig: boolean\n}\n\n/**\n * The daemon gets the same instructions, but never `--foreground` (that is what\n * makes it the daemon) and never `--print-config` (that one is answered in the\n * calling process).\n */\nexport function buildDaemonArgv(flags: UpFlags): string[] {\n const args: string[] = ['up', '--foreground']\n if (flags.port !== undefined)\n args.push('--port', String(flags.port))\n if (flags.host !== undefined)\n args.push('--host', flags.host)\n if (!flags.autostart)\n args.push('--no-autostart')\n if (flags.open)\n args.push('--open')\n return args\n}\n","import process from 'node:process'\n\n/**\n * A value quoted for the shell it will be pasted into.\n *\n * One rule for every string this package prints for a person to copy: a directory, an id, a\n * workspace. `init` printed `cd my servers && npm run up` for the default `./my-servers`-style\n * directory a person picks, which the shell answers `cd: too many arguments` — a failure in the one\n * line the scaffold exists to hand over.\n *\n * POSIX gets single quotes, with an embedded quote closed and reopened (`'\\''`), the one form that is\n * safe inside a single-quoted string. Windows' `cmd.exe` has no single-quote quoting at all, so it\n * gets double quotes: that is what it understands, and a path whose name contains a `\"` is not\n * representable there either way.\n *\n * It cannot use the platform to *decide the shell*, only to pick the dialect: a POSIX path is\n * quoted for `sh` even when the process is running on Windows (the panel's CLI under Git Bash), and\n * a Windows path for `cmd.exe`. `process.platform` is the only signal available, so the rule is\n * documented rather than guessed at each call site.\n */\nexport function shellQuote(value: string): string {\n return process.platform === 'win32'\n ? `\"${value}\"`\n : `'${value.replace(/'/g, `'\\\\''`)}'`\n}\n","import process from 'node:process'\nimport readline from 'node:readline'\nimport { shellQuote } from '#src/helpers/shell'\n\n/**\n * The bits every command shares: the colours, the failure shape, and the one\n * place readline is set up. Imported by `src/cli.ts` and by the command modules\n * it loads lazily, so it may not read the state directories. Its only imports are\n * node builtins and `helpers/shell.ts`, which reads neither the filesystem nor\n * `helpers/paths.ts` — the two ways a `#src` import here would pull the state\n * graph in before citty is even asked anything.\n */\n\nexport const isTty = (): boolean => process.stdout.isTTY === true\n\nexport const paint = (code: string, text: string): string => (isTty() ? `\\x1B[${code}m${text}\\x1B[0m` : text)\nexport const dim = (text: string): string => paint('2', text)\nexport const bold = (text: string): string => paint('1', text)\nexport const cyan = (text: string): string => paint('36', text)\nexport const green = (text: string): string => paint('32', text)\n/** A section title in the help output. */\nexport const heading = (text: string): string => paint('1;4', text)\n\n/** The seam `ui-switch` takes, so the command stays testable without a terminal. */\nexport const style = { bold, dim, green }\n\n/**\n * How this process was invoked, so a hint names a command the person can actually run.\n *\n * `npx home-hosted` leaves no `home-hosted` on `PATH`, so a hard-coded \"run `home-hosted down`\"\n * fails with `command not found`. A package-manager cache path means npx/dlx; `cli.ts` means a\n * source checkout. A string to print, not a parser. `HHOSTED_INVOCATION` overrides it.\n *\n * **The state directory travels with it.** A command that was told `--home` (or inherited\n * `HHOSTED_HOME`) prints hints about *that* home, and a hint without the flag reaches the default\n * one instead: measured, `pnpm run cli backup list` — the documented way to try anything in this\n * repo — printed \"`pnpm exec tsx src/cli.ts backup create --all` takes one\", and running that\n * verbatim created `~/.home-hosted` beside the `.dev-state/` it was asked about. The same shape hits\n * every project `init` scaffolds, because its scripts all pass `--home ./state`. So the flag is part\n * of the invocation whenever a state directory was chosen, quoted for the shell that will run it.\n *\n * `HHOSTED_INVOCATION` overrides the *program*, never the state: a wrapper that sets it still wants\n * its hints pointed at the home it is driving.\n */\nexport function invocation(): string {\n const program = invocationProgram()\n const home = process.env.HHOSTED_HOME?.trim()\n return home === undefined || home.length === 0 ? program : `${program} --home ${shellQuote(home)}`\n}\n\n/** The program alone — what a hint would say if every home were the default one. */\nfunction invocationProgram(): string {\n const override = process.env.HHOSTED_INVOCATION?.trim()\n if (override !== undefined && override.length > 0)\n return override\n\n const entry = process.argv[1] ?? ''\n // A package-manager cache (`~/.npm/_npx/…`, `~/.local/share/pnpm/dlx/…`) means the package is\n // not installed, so the bare name would not resolve in the user's shell.\n if (/[\\\\/](?:_npx|dlx)[\\\\/]/.test(entry))\n return 'npx home-hosted'\n // A source checkout (`tsx src/cli.ts`, the repo's own scripts) has no installed bin either.\n if (/[\\\\/]cli\\.ts$/.test(entry))\n return 'pnpm exec tsx src/cli.ts'\n\n return 'home-hosted'\n}\n\n/**\n * A reader that hangs up is a finished conversation, not a crash.\n *\n * Node's stdout is a socket. When the reader closes it, the next write raises `EPIPE` as an **error\n * event**, and an unhandled one kills the process with an engine stack trace and exit 1: measured on\n * the built CLI, `dist/cli.js status | head -1` printed `Error: write EPIPE … at runStatus` and exited\n * 1, so `set -o pipefail` turned a working panel into a failed deploy step. `logs --lines all | head`\n * and `logs --follow | head` did the same.\n *\n * GNU tools die of SIGPIPE (141), which `pipefail` reports as a failure too; Node's own CLI and\n * Python's exit 0. This follows the latter, because the command *succeeded* and only the reader\n * stopped listening — nothing was refused, and no work was lost.\n *\n * **The code for \"the reader is gone\" is not the same on every platform.** `EPIPE` is what Linux\n * reports; libuv elsewhere can surface the same condition as `ERR_STREAM_DESTROYED`, and a write to an\n * already-destroyed stream arrives with no `code` at all and the message `closed`. Matching only\n * `EPIPE` left the macOS gate failing with exit 1 and an **empty stderr** — nothing was printed and\n * nothing was explained, because the error was a stream state, not a failed write. So the test is\n * \"does this error say the reader went away\"; a full disk or an EIO still ends the process.\n *\n * `ENOTCONN` is the one the macOS runner actually produced: a stdout **socket** whose peer has closed\n * reports \"socket is not connected\", not a broken pipe (measured in the cross-platform workflow —\n * `write ENOTCONN` at the write site, with the reader long gone). It means the same thing here and\n * nowhere else in this codebase: nothing in the CLI opens a socket of its own, so a write reaching\n * this handler with `ENOTCONN` is always the stdout pipe's reader having hung up.\n *\n * Installed once at the entry so every command shares it. A per-command copy is the shape that leaves\n * the next command broken, and every release adds more write sites.\n */\nconst READER_GONE = /^(?:EPIPE|ENOTCONN|ERR_STREAM_DESTROYED|ERR_STREAM_WRITE_AFTER_END|ECONNRESET)$/\n\nexport function isClosedReaderError(error: unknown): boolean {\n const code = (error as NodeJS.ErrnoException | null)?.code\n if (typeof code === 'string' && READER_GONE.test(code))\n return true\n // A write to a destroyed stream carries no code, only the message.\n const message = (error as Error | null)?.message ?? ''\n return /^(?:closed|write after end|premature close)$/i.test(message)\n}\n\nexport function treatClosedReaderAsDone(): void {\n process.stdout.on('error', (error: NodeJS.ErrnoException) => {\n if (isClosedReaderError(error))\n process.exit(0)\n // Anything else is a real write failure, which used to end the process by default; keep that.\n throw error\n })\n}\n\n/** One shape for every failure: a red `error <message>` on stderr and exit 1. */\nexport function fail(message: string): never {\n process.stderr.write(`${paint('31', 'error')} ${message}\\n`)\n process.exit(1)\n}\n\n/**\n * The same red `error <message>` line on stderr, for a refusal that still has something to do\n * afterwards — `logs --json` has already written its document, and `down` has a persistent sweep to\n * report. `fail()` cannot serve those because it exits.\n *\n * **Every refusal goes to stderr**, whether or not the command has more to say: a `--json` caller\n * parses stdout, so a refusal written there makes stdout not-a-document — a script sees prose where\n * it expected JSON. `logs` printed its unreadable-file refusal on stdout while the exit code said 1,\n * and `down` printed \"could not stop pid N\" there too. Both go through here now.\n */\nexport function refusal(message: string): void {\n process.stderr.write(`${paint('31', 'error')} ${message}\\n`)\n}\n\nexport function delay(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms))\n}\n\n/** A plain y/N question, for decisions that are not secrets. */\nexport function prompt(question: string): Promise<string> {\n return new Promise((resolve) => {\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout })\n rl.question(question, (answer) => {\n rl.close()\n resolve(answer)\n })\n })\n}\n\n/** Reads a line with echo suppressed, so the password never lands in scrollback. */\nexport function promptHidden(question: string): Promise<string> {\n return new Promise((resolve) => {\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true })\n const onData = (): void => {\n readline.clearLine(process.stdout, 0)\n readline.cursorTo(process.stdout, 0)\n process.stdout.write(question)\n }\n\n process.stdin.on('data', onData)\n rl.question(question, (answer) => {\n process.stdin.off('data', onData)\n rl.close()\n process.stdout.write('\\n')\n resolve(answer)\n })\n })\n}\n\n/** Asks a yes/no question with a default, so an empty answer is a real answer. */\nexport async function confirm(question: string, fallback: boolean): Promise<boolean> {\n const answer = (await prompt(`${question} ${fallback ? '[Y/n]' : '[y/N]'} `)).trim().toLowerCase()\n if (answer.length === 0)\n return fallback\n return answer === 'y' || answer === 'yes'\n}\n\n/** The first-run password while it is still the one in use, read from this machine's secrets file. */\nexport async function firstRunPassword(): Promise<string | null> {\n const { SecretsStore } = await import('#src/config/secrets')\n const { globalSecretsPath } = await import('#src/helpers/paths')\n try {\n return new SecretsStore(globalSecretsPath, undefined, 'global').initialPassword\n }\n catch {\n return null\n }\n}\n","import process from 'node:process'\n\n/**\n * How to run this CLI again in the same runtime. Under tsx that means passing the\n * resolved loader too, because a spawned child's working directory is the project's,\n * not the package's. Shared by `up` (which re-spawns itself detached) and by the\n * panel (which spawns a persistent entry's nanny).\n *\n * Nothing here reads a state directory, which is why the CLI can import it before\n * `--home`/`--project` have been applied.\n */\nexport function runtimeArgs(): string[] {\n let resolved: string | null = null\n const resolveTsx = (): string => resolved ??= import.meta.resolve('tsx')\n\n return process.execArgv.map((arg) => {\n if (arg === 'tsx')\n return resolveTsx()\n if (arg.startsWith('--import=') && arg.slice('--import='.length) === 'tsx')\n return `--import=${resolveTsx()}`\n return arg\n })\n}\n\n/**\n * The hidden command a persistent entry runs under. It is spawned by the panel and\n * never typed by a person, so it stays out of the curated CLI surface (help, the\n * unknown-command message, flag refusal) — but the argv has to be one definition,\n * because process identity reads it back: see `providers/identity.ts`.\n */\nexport const NANNY_COMMAND = '__nanny'\n\nexport function nannyArgv(entry: string, id: string, specPath: string, statePath: string): string[] {\n return [...runtimeArgs(), entry, NANNY_COMMAND, '--id', id, '--spec', specPath, '--state', statePath]\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nlet cachedRoot: { dir: string, version: string } | null = null\n\n/**\n * The package's own directory and release, found by walking up to the manifest named `home-hosted`.\n *\n * The caller may be `src/**` under tsx, `dist/cli.js`, or a code-split chunk under `dist/chunks/`,\n * so no fixed relative path is right for all of them; a nested manifest is not trusted.\n *\n * `src/cli.ts` reaches this through a **relative** import, not `#src/*`: the bootstrap may only pull\n * in modules that load node builtins statically.\n */\nfunction findPackage(): { dir: string, version: string } {\n if (cachedRoot !== null)\n return cachedRoot\n const start = path.dirname(fileURLToPath(import.meta.url))\n let dir = start\n for (let depth = 0; depth < 5; depth++) {\n try {\n const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')) as { name?: string, version?: string }\n if (manifest.name === 'home-hosted' && typeof manifest.version === 'string') {\n cachedRoot = { dir, version: manifest.version }\n return cachedRoot\n }\n }\n catch {\n // no manifest here; keep walking up\n }\n const parent = path.dirname(dir)\n if (parent === dir)\n break\n dir = parent\n }\n cachedRoot = { dir: path.dirname(start), version: '0.0.0' }\n return cachedRoot\n}\n\n/** The running release, read from the package manifest. */\nexport function appVersion(): string {\n return findPackage().version\n}\n\n/** Where the package is installed: the base for files it ships (`uis/stock/dist`). */\nexport function packageRoot(): string {\n return findPackage().dir\n}\n\n/**\n * The one line to add when this CLI and the panel it is talking to are not the same\n * release — which is what a linked checkout, a global install and a project pin\n * produce. `null` when they agree.\n */\nexport function versionMismatchNote(panelVersion: string): string | null {\n const cli = appVersion()\n return cli === panelVersion ? null : `note: this CLI is ${cli}, the panel is ${panelVersion}`\n}\n","import type { SubCommandsDef } from 'citty'\nimport process from 'node:process'\nimport { fileURLToPath } from 'node:url'\nimport { defineCommand, runCommand } from 'citty'\nimport { errorMessage } from '#src/shared/error-message'\nimport { applyDirFlags, extractDirFlags, rejectUnknownFlags, resolveInvocation } from './cli/args'\nimport { cyan, dim, fail, heading, treatClosedReaderAsDone } from './cli/io'\nimport { nearestWord } from './cli/nearest'\nimport { NANNY_COMMAND } from './helpers/runtime'\nimport { appVersion } from './helpers/version'\n\n/**\n * The command line, and nothing else. Two things happen before citty is asked\n * anything: `--home`/`--project` are peeled off and applied (because\n * `#src/helpers/paths.ts` resolves at import time), and the curated surface —\n * `help`, `version`, `unknown command`, and the `-p 4000` shorthand for `up` —\n * is decided. The command modules are then resolved lazily by citty, so their\n * own `#src` imports are safe: by the time one is imported, the directories are\n * already in the environment.\n *\n * The only static imports here are node builtins, citty, and the path-free local\n * modules the pre-pass needs (`helpers/runtime.ts` only names the hidden nanny\n * command); every command (and so every state-reading module) is a dynamic import\n * behind `subCommands`.\n */\n\nconst CLI_ENTRY = fileURLToPath(import.meta.url)\n\n/**\n * The curated prose, kept here because citty cannot generate it. One named\n * piece per command, so the full reference and a single command's help are\n * composed from the same lines and can never drift apart. Every section lays\n * its left column out at the same width, so the two views read alike.\n */\n\nconst HEADER = 'home-hosted — a control panel for the processes on your home server'\n\n/** The one line the full reference lists for a command. */\nconst SYNOPSIS: Record<string, string> = {\n 'up': 'home-hosted up [options]',\n 'down': 'home-hosted down [--with-persistent]',\n 'restart': 'home-hosted restart [<id>] [options]',\n 'status': 'home-hosted status [--json]',\n 'logs': 'home-hosted logs [<id>] [--lines <n>] [--follow] [--json] [--workspace <id>]',\n 'usage': 'home-hosted usage [--json]',\n 'backup': 'home-hosted backup [list|create|restore] [options]',\n 'start': 'home-hosted start <id> [--workspace <id>] [--free-port]',\n 'stop': 'home-hosted stop <id> [--workspace <id>]',\n 'free-port': 'home-hosted free-port <id> [--workspace <id>]',\n 'set-password': 'home-hosted set-password [--clear]',\n 'set-token': 'home-hosted set-token [--generate|--clear]',\n 'setup-temp': 'home-hosted setup-temp [--wsl] [--download|--no-download] [--clear]',\n 'migrate': 'home-hosted migrate [--dry-run] [--yes]',\n 'init': 'home-hosted init [options]',\n 'ui-switch': 'home-hosted ui-switch [options]',\n 'ui-update': 'home-hosted ui-update [options]',\n 'ui-revert': 'home-hosted ui-revert',\n}\n\nconst SUMMARIES: Record<string, string> = {\n 'up': 'start it in the background (detached)',\n 'down': 'stop it, and everything it supervises',\n 'restart': 'down then up — or one server, given an id',\n 'status': 'is it running, where, and how to reach it',\n 'logs': 'show the panel\\'s console, or one server\\'s own log with an id',\n 'usage': 'live CPU and memory per server, loudest first',\n 'backup': 'list, create or restore a backup archive',\n 'start': 'start one server, leaving the panel up',\n 'stop': 'stop one server, leaving the panel up',\n 'free-port': 'free the port a server needs, so it can start',\n 'set-password': 'set the panel password without the API',\n 'set-token': 'set the API token that scripts and agents use',\n 'setup-temp': 'teach the panel how to read this machine\\'s CPU temperature',\n 'migrate': 'bring the config up to this release\\'s schema',\n 'init': 'scaffold a project that keeps its state in the repo',\n 'ui-switch': 'install a UI from a release asset, a zip file or a URL',\n 'ui-update': 'bring the installed UI up to date, or pick a release',\n 'ui-revert': 'go back to the stock control panel UI',\n}\n\n/** One option line, as the left column and the description that follows it. */\ntype OptionLine = [left: string, right: string]\n\n/** A heading and the option lines under it. */\ninterface OptionSection {\n heading: string\n lines: OptionLine[]\n}\n\n/** Every section lays its left column out at this width, so the two views align. */\nconst OPTION_WIDTH = 21\n\nconst UP_SECTION: OptionSection = {\n heading: 'Options for up',\n lines: [\n // Both are saved to settings.json, so the next plain `up` binds the same way.\n ['-p, --port <port>', 'control panel port (default: 3999); saved to settings.json'],\n ['--host <bind>', 'local | lan | an ipv4 address (default: local); saved to settings.json'],\n ['--open', 'open the panel in a browser once it is up'],\n ['--no-autostart', 'do not start the entries marked autostart'],\n ['--foreground', 'run in this process instead of detaching (systemd/docker)'],\n ['--print-config', 'print the effective config and exit — starts nothing, sets no password'],\n ],\n}\n\nconst STATUS_SECTION: OptionSection = {\n heading: 'Options for status',\n lines: [\n ['--json', 'print machine-readable JSON'],\n ],\n}\n\nconst LOGS_SECTION: OptionSection = {\n heading: 'Options for logs',\n lines: [\n ['<id>', 'one server\\'s own log instead of the panel console (optional)'],\n ['--lines <n>', 'how many lines to show: 1 or more (default 50), or `all`'],\n ['--follow', 'keep printing as the panel writes (like tail -f)'],\n ['--json', 'print machine-readable JSON (one object per line with --follow)'],\n ['-w, --workspace <id>', 'the workspace the server is in (default: the panel\\'s default)'],\n ],\n}\n\nconst USAGE_SECTION: OptionSection = {\n heading: 'Options for usage',\n lines: [\n ['--json', 'print machine-readable JSON'],\n ],\n}\n\nconst BACKUP_SECTION: OptionSection = {\n heading: 'Arguments for backup',\n lines: [\n ['list | create | restore', 'what to do (default: list)'],\n ['<name>', 'the archive, for restore — `backup list` shows them'],\n ['--from <path>', 'restore from an archive file anywhere on this machine, instead of a name'],\n ['--include <ids>', 'comma-separated item ids to act on (required for create/restore)'],\n ['--all', 'act on everything; one of --include or --all is required'],\n ['--exclude <ids>', 'leave these out; --all --exclude global:secrets keeps the password and token out of the archive'],\n ['--password <text>', 'encrypt a new archive, or unlock one on restore'],\n ['--confirm', 'apply without asking (create and restore plan first)'],\n ['--json', 'print the plan or the result as JSON'],\n ],\n}\n\nconst SERVER_SECTION: OptionSection = {\n heading: 'Arguments for stop/free-port',\n lines: [\n ['<id>', 'the server id from servers.config.json'],\n ['-w, --workspace <id>', 'the workspace to act in (default: the default workspace)'],\n ],\n}\n\n// Only `start` takes the flag: freeing a port before stopping a server means nothing.\nconst START_SECTION: OptionSection = {\n heading: 'Arguments for start',\n lines: [\n ['<id>', 'the server id from servers.config.json'],\n ['-w, --workspace <id>', 'the workspace to act in (default: the default workspace)'],\n ['--free-port', 'free the port first, then start — the panel\\'s Free port button'],\n ],\n}\n\n// `restart <id>` acts on one entry; bare `restart` acts on the panel, so the id is optional\n// and reads under `up`'s heading alongside its flags.\n// `down` had no options at all until `--with-persistent`, so its section is new rather than\n// an addition to someone else's: the flag exists on both commands and must read the same.\nconst PERSISTENT_LINE: OptionLine = ['--with-persistent', 'stop the persistent entries too (default: leave them running)']\n\nconst DOWN_SECTION: OptionSection = {\n heading: 'Options for down',\n lines: [PERSISTENT_LINE],\n}\n\nconst RESTART_SECTION: OptionSection = {\n heading: 'Options for restart (and every option of up)',\n lines: [\n // Its own section, not `UP_SECTION`: `restart` takes an id and `up` does not, and\n // advertising one there would document a flag `up` rejects.\n ['<id>', 'restart just this server, leaving the panel up (optional)'],\n ['-w, --workspace <id>', 'the workspace to act in, with an id'],\n PERSISTENT_LINE,\n ],\n}\n\nconst SET_PASSWORD_SECTION: OptionSection = {\n heading: 'Options for set-password',\n lines: [\n ['--clear', 'remove the password: nobody can sign in until a new one is set'],\n ],\n}\n\nconst SET_TOKEN_SECTION: OptionSection = {\n heading: 'Options for set-token',\n lines: [\n ['--generate', 'create a strong token and print it once'],\n ['--clear', 'remove the token, so it stops working'],\n ],\n}\n\nconst SETUP_TEMP_SECTION: OptionSection = {\n heading: 'Options for setup-temp',\n lines: [\n ['--wsl', 'read the temperature through the Windows host (WSL2)'],\n ['--download', 'with --wsl: fetch LibreHardwareMonitor without asking (for a script)'],\n ['--no-download', 'with --wsl: never fetch it; report what is missing'],\n ['--clear', 'stop using the command and delete the helper'],\n ],\n}\n\nconst MIGRATE_SECTION: OptionSection = {\n heading: 'Options for migrate',\n lines: [\n ['--dry-run', 'print what would change, write nothing'],\n ['-y, --yes', 'apply without asking (or set HHOSTED_MIGRATE=allow)'],\n ],\n}\n\nconst INIT_SECTION: OptionSection = {\n heading: 'Options for init',\n lines: [\n ['--dir <dir>', 'where to scaffold (default: ./my-servers)'],\n ['--name <name>', 'package name (default: the directory name)'],\n ['--pm <manager>', 'pnpm | npm | yarn | bun (default: the first one installed)'],\n ['--no-install', 'write the files, install nothing'],\n ['-y, --yes', 'take every default, ask nothing'],\n ],\n}\n\nconst UI_SWITCH_SECTION: OptionSection = {\n heading: 'Options for ui-switch',\n lines: [\n ['--repo <owner/name>', 'release repo (default: NamesMT/home-hosted)'],\n ['--tag <tag>', 'release tag (default: this release\\'s tag, or latest for another repo)'],\n ['--asset <name>', 'asset to install (exact or unambiguous match)'],\n ['--file <path|url>', 'install a zip from a local path or an http(s) URL'],\n ['--list', 'list the usable assets and install nothing'],\n ['--token <token>', 'GitHub token (or GITHUB_TOKEN / GH_TOKEN)'],\n ['-y, --yes', 'take the only asset instead of asking'],\n ],\n}\n\nconst UI_UPDATE_SECTION: OptionSection = {\n heading: 'Options for ui-update',\n lines: [\n ['--check', 'report whether an update is available and install nothing'],\n ['--tag <tag>', 'install that release instead of asking'],\n ['--asset <name>', 'asset to install (defaults to the one in use)'],\n ['--old', 'list older releases instead of newer ones'],\n ['--repo <owner/name>', 'for a UI that does not declare its own repo'],\n ['--token <token>', 'GitHub token (or GITHUB_TOKEN / GH_TOKEN)'],\n ['-y, --yes', 'take the only release instead of asking'],\n ],\n}\n\nconst EVERYWHERE_SECTION: OptionSection = {\n heading: 'Everywhere',\n lines: [\n ['--home <dir>', 'state directory (default: $HHOSTED_HOME or ~/.home-hosted)'],\n ['--project <dir>', 'base for relative entry paths (default: the current directory)'],\n ['-h, --help', 'this text'],\n ['-v, --version', 'the version'],\n ],\n}\n\nconst ALIAS_SECTION: OptionSection = {\n heading: 'Alias',\n lines: [\n ['hh', 'the same CLI, on a machine where home-hosted is installed'],\n ],\n}\n\nconst ENVIRONMENT_SECTION: OptionSection = {\n heading: 'Environment',\n lines: [\n ['HHOSTED_HOME', 'where config, secrets, logs, TLS and backups live'],\n ['HHOSTED_PROJECT', 'base for relative entry paths'],\n ['HHOSTED_PASSWORD', 'the password for a non-interactive set-password'],\n ['HHOSTED_TOKEN', 'the token for a non-interactive set-token'],\n ['HHOSTED_MIGRATE', '`allow` lets migrate apply without asking, for an unattended run'],\n ['HHOSTED_DDNS_SECRET', 'the key DDNS credentials are sealed with'],\n ['GITHUB_TOKEN', 'a GitHub token for ui-switch and ui-update (GH_TOKEN also works)'],\n ],\n}\n\n/**\n * The command name a typo most likely meant, or null when nothing is close. The candidates are\n * `SYNOPSIS`, the same source the reference renders, so a suggestion cannot name a command the CLI\n * does not have.\n */\nexport function suggestCommand(input: string): string | null {\n return nearestWord(input, Object.keys(SYNOPSIS))\n}\n\n/** The command list of the full reference, aligned as it always was. */\nfunction renderCommandList(): string {\n const width = Math.max(...Object.values(SYNOPSIS).map(synopsis => synopsis.length))\n return Object.keys(SYNOPSIS)\n .map((name) => {\n const synopsis = SYNOPSIS[name]!\n return ` ${cyan(synopsis)}${' '.repeat(width + 1 - synopsis.length)} ${SUMMARIES[name]}`\n })\n .join('\\n')\n}\n\nfunction renderSection(section: OptionSection): string {\n const lines = section.lines\n .map(([left, right]) => ` ${cyan(left)}${' '.repeat(Math.max(0, OPTION_WIDTH - left.length))} ${right}`)\n .join('\\n')\n return `${heading(section.heading)}\\n${lines}`\n}\n\n/** The trailer every command shares: the global flags, the alias and the environment. */\nconst SHARED_TRAILER = [\n renderSection(EVERYWHERE_SECTION),\n '',\n renderSection(ALIAS_SECTION),\n '',\n renderSection(ENVIRONMENT_SECTION),\n '',\n].join('\\n')\n\n/** Each command's own options; a command missing here takes none. */\nconst SECTIONS: Record<string, OptionSection> = {\n 'up': UP_SECTION,\n 'down': DOWN_SECTION,\n 'status': STATUS_SECTION,\n 'logs': LOGS_SECTION,\n 'usage': USAGE_SECTION,\n 'backup': BACKUP_SECTION,\n 'restart': RESTART_SECTION,\n 'start': START_SECTION,\n 'stop': SERVER_SECTION,\n 'free-port': SERVER_SECTION,\n 'set-password': SET_PASSWORD_SECTION,\n 'set-token': SET_TOKEN_SECTION,\n 'setup-temp': SETUP_TEMP_SECTION,\n 'migrate': MIGRATE_SECTION,\n 'init': INIT_SECTION,\n 'ui-switch': UI_SWITCH_SECTION,\n 'ui-update': UI_UPDATE_SECTION,\n}\n\n/**\n * The full reference: every command, then every command's options in the same order, then the\n * trailer. Built from `SECTIONS`, the same map `<command> --help` reads, so a command cannot be\n * listed without its options (logs, usage, backup, setup-temp and ui-update once were).\n */\nconst USAGE = [\n dim(HEADER),\n '',\n heading('Usage'),\n renderCommandList(),\n '',\n ...[...new Set(Object.keys(SYNOPSIS).map(name => SECTIONS[name]).filter(section => section !== undefined))]\n .flatMap(section => [renderSection(section), '']),\n SHARED_TRAILER,\n].join('\\n')\n\n/**\n * `home-hosted <command> --help`: the usage line, that command's own options,\n * and the shared trailer. A command with no options says so instead of printing\n * an empty heading.\n */\nexport function commandHelp(command: string): string {\n const synopsis = SYNOPSIS[command]\n if (synopsis === undefined)\n return USAGE\n\n const section = SECTIONS[command]\n // `restart` is `up` behind the scenes, so it lists up's options after its own.\n const options = section === undefined\n ? dim('no options')\n : [renderSection(section), ...(command === 'restart' ? ['', renderSection(UP_SECTION)] : [])].join('\\n')\n\n return [\n dim(HEADER),\n '',\n cyan(synopsis),\n '',\n options,\n '',\n SHARED_TRAILER,\n ].join('\\n')\n}\n\nfunction version(): void {\n process.stdout.write(`${appVersion()}\\n`)\n}\n\n/**\n * citty owns dispatch and argument parsing. Each entry is a lazy import, so a\n * command's `#src` modules are only evaluated once `applyDirFlags()` has run.\n */\nconst COMMANDS = {\n 'up': () => import('#src/cli/up').then(module => module.upCommand(CLI_ENTRY)),\n 'down': () => import('#src/cli/down').then(module => module.downCommand),\n 'restart': () => import('#src/cli/restart').then(module => module.restartCommand(CLI_ENTRY)),\n 'status': () => import('#src/cli/status').then(module => module.statusCommand),\n 'logs': () => import('#src/cli/logs').then(module => module.logsCommand),\n 'usage': () => import('#src/cli/usage').then(module => module.usageCommand),\n 'start': () => import('#src/cli/server').then(module => module.startCommand),\n 'stop': () => import('#src/cli/server').then(module => module.stopCommand),\n 'free-port': () => import('#src/cli/server').then(module => module.freePortCommand),\n 'set-password': () => import('#src/cli/set-password').then(module => module.setPasswordCommand),\n 'set-token': () => import('#src/cli/set-token').then(module => module.setTokenCommand),\n 'setup-temp': () => import('#src/cli/setup-temp').then(module => module.setupTempCommand),\n 'migrate': () => import('#src/cli/migrate').then(module => module.migrateCommand),\n 'init': () => import('#src/cli/init').then(module => module.initCommand),\n 'ui-switch': () => import('#src/cli/ui-switch').then(module => module.uiSwitchCommand),\n 'ui-update': () => import('#src/cli/ui-update').then(module => module.uiUpdateCommand),\n 'ui-revert': () => import('#src/cli/ui-revert').then(module => module.uiRevertCommand),\n 'backup': () => import('#src/cli/backup').then(module => module.backupCommand),\n} satisfies SubCommandsDef\n\nconst rootCommand = defineCommand({\n meta: {\n name: 'home-hosted',\n version: appVersion(),\n description: 'a control panel for the processes on your home server',\n },\n subCommands: COMMANDS,\n})\n\nconst commandNames = Object.keys(COMMANDS)\n\nasync function main(): Promise<void> {\n // Before the first byte is written: a reader that hangs up (`| head -1`, `grep -q`) closes the pipe,\n // and an unhandled EPIPE would print an engine stack trace and exit 1. One install, every command.\n treatClosedReaderAsDone()\n\n const dirFlags = extractDirFlags(process.argv.slice(2))\n if (dirFlags.error !== undefined)\n fail(dirFlags.error)\n applyDirFlags(dirFlags)\n\n // The persistent-entry nanny is spawned by the panel, never typed by a person, so\n // it is dispatched before the curated surface and stays out of it: no synopsis, no\n // unknown-command interplay, and citty owns its own `--help`.\n if (dirFlags.rest[0] === NANNY_COMMAND) {\n const { nannyCommand } = await import('#src/cli/nanny')\n try {\n await runCommand(nannyCommand, { rawArgs: dirFlags.rest })\n }\n catch (error) {\n fail(errorMessage(error))\n }\n return\n }\n\n const invocation = resolveInvocation(dirFlags.rest, commandNames)\n\n if (invocation.kind === 'help') {\n process.stdout.write(invocation.command === undefined ? USAGE : commandHelp(invocation.command))\n return\n }\n if (invocation.kind === 'version') {\n version()\n return\n }\n if (invocation.kind === 'unknown') {\n const suggestion = suggestCommand(invocation.command)\n process.stderr.write(`unknown command: ${invocation.command}\\n`)\n if (suggestion !== null)\n process.stderr.write(`${dim(`did you mean \\`${suggestion}\\`?`)}\\n`)\n process.stderr.write(`\\n${USAGE}`)\n process.exit(1)\n }\n\n // A state directory this release cannot use is refused before any command\n // resolves a path into it. It throws one sentence naming the fix, which is the\n // same shape as every other CLI failure below.\n const { ensureLayout } = await import('#src/config/layout')\n ensureLayout()\n\n // citty parses permissively, so the refusal of a mistyped flag is asked of\n // citty's own definitions first; a command that declares none (ui-switch) keeps\n // its own parseArgs, which is strict already.\n const sub = COMMANDS[invocation.argv[0]! as keyof typeof COMMANDS]\n const command = typeof sub === 'function' ? await sub() : sub\n const problem = rejectUnknownFlags(invocation.argv.slice(1), command?.args)\n if (problem !== null)\n fail(problem)\n\n // `runCommand`, not `runMain`: citty's `runMain` prints its own usage and\n // `console.error`s the message before `process.exit(1)`, so a wrapper can never\n // turn a failure back into `fail()`'s red `error <message>`. Letting the error\n // out keeps every failure on the one shape this CLI has always had.\n try {\n await runCommand(rootCommand, { rawArgs: invocation.argv })\n }\n catch (error) {\n fail(errorMessage(error))\n }\n}\n\nvoid main().catch((error: unknown) => {\n fail(errorMessage(error))\n})\n"],"mappings":";;;;;;;;;;;;;;;;AAOA,SAAgB,aAAa,QAAyB;CACpD,OAAO,kBAAkB,QAAQ,OAAO,UAAU,OAAO,MAAM;AACjE;;;;ACgB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AQ,GAAG;EAC/D,IAAI,eAAe,MACjB,QAAQ,OAAO,MAAM,GAAG,IAAI,kBAAkB,WAAW,IAAI,EAAE,GAAG;EACpE,QAAQ,OAAO,MAAM,KAAK,OAAO;EACjC,QAAQ,KAAK,CAAC;CAChB;CAKA,MAAM,EAAE,iBAAiB,MAAM,OAAO;CACtC,aAAa;CAKb,MAAM,MAAM,SAAS,WAAW,KAAK;CACrC,MAAM,UAAU,OAAO,QAAQ,aAAa,MAAM,IAAI,IAAI;CAC1D,MAAM,UAAU,mBAAmB,WAAW,KAAK,MAAM,CAAC,GAAG,SAAS,IAAI;CAC1E,IAAI,YAAY,MACd,KAAK,OAAO;CAMd,IAAI;EACF,MAAM,WAAW,aAAa,EAAE,SAAS,WAAW,KAAK,CAAC;CAC5D,SACO,OAAO;EACZ,KAAK,aAAa,KAAK,CAAC;CAC1B;AACF;AAEK,KAAK,CAAC,CAAC,OAAO,UAAmB;CACpC,KAAK,aAAa,KAAK,CAAC;AAC1B,CAAC"}
1
+ {"version":3,"file":"cli.js","names":["SCOPES"],"sources":["../src/shared/api-scopes.ts","../src/shared/error-message.ts","../src/cli/args.ts","../src/helpers/shell.ts","../src/cli/io.ts","../src/helpers/runtime.ts","../src/helpers/version.ts","../src/cli.ts"],"sourcesContent":["/**\n * The API scope names, apart from `#src/config/secrets.ts` (which re-exports them) so `src/cli.ts` can\n * read them without importing a state module before `--home` applies.\n */\n\n/**\n * What a credential may do.\n *\n * - `read` — every `GET`;\n * - `lifecycle` — start, stop, restart, free-port, clear-logs;\n * - `config` — server, workspace and settings writes, and backups;\n * - `proxy` — the reverse proxy: the engine, its routes and its certificates;\n * - `admin` — everything, including tokens, the password, UI install and restoring secrets.\n */\nexport const API_TOKEN_SCOPES = ['read', 'lifecycle', 'config', 'proxy', 'admin'] as const\nexport type ApiTokenScope = typeof API_TOKEN_SCOPES[number]\n\n/** Scopes with no per-workspace meaning: granting either grants the whole panel whatever `workspaces` says. */\nexport const PANEL_WIDE_SCOPES = ['proxy', 'admin'] as const satisfies readonly ApiTokenScope[]\n","/** One rendering for a thrown value, so a caught error reads the same everywhere. */\nexport function errorMessage(caught: unknown): string {\n return caught instanceof Error ? caught.message : String(caught)\n}\n","import type { ArgsDef } from 'citty'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { nearestWord } from './nearest'\n\n/**\n * The argument work before citty: `--home`/`--project` must change the environment before any `#src`\n * module resolves a path, and the curated surface (`help`, `version`, `unknown command`) is decided.\n * Node builtins only.\n */\n\nexport interface DirFlags {\n project?: string\n home?: string\n}\n\nexport interface DirFlagResult extends DirFlags {\n rest: string[]\n error?: string\n}\n\nexport function extractDirFlags(argv: string[]): DirFlagResult {\n const rest: string[] = []\n let project: string | undefined\n let home: string | undefined\n\n for (let index = 0; index < argv.length; index++) {\n const arg = argv[index]!\n const equals = arg.indexOf('=')\n const name = equals === -1 ? arg : arg.slice(0, equals)\n if (name !== '--project' && name !== '--home') {\n rest.push(arg)\n continue\n }\n const value = equals === -1 ? argv[++index] : arg.slice(equals + 1)\n if (value === undefined || value.length === 0)\n return { rest, project, home, error: `${name} needs a directory` }\n if (name === '--project')\n project = value\n else\n home = value\n }\n\n return { rest, project, home }\n}\n\nexport function applyDirFlags(flags: DirFlags): void {\n if (flags.project !== undefined)\n process.env.HHOSTED_PROJECT = path.resolve(flags.project)\n if (flags.home !== undefined)\n process.env.HHOSTED_HOME = path.resolve(flags.home)\n}\n\nexport type Invocation\n = | { kind: 'help', command?: string }\n | { kind: 'version' }\n | { kind: 'command', argv: string[] }\n | { kind: 'unknown', command: string }\n\nconst HELP_TOKENS = new Set(['help', '--help', '-h'])\nconst VERSION_TOKENS = new Set(['version', '--version', '-v'])\n// After a command only the flag forms count: a bare `help` may be an option value (`init --name help`).\nconst HELP_FLAGS = new Set(['--help', '-h'])\nconst ID_FIRST = new Set(['start', 'stop', 'free-port', 'restart', 'logs'])\nconst VERSION_FLAGS = new Set(['--version', '-v'])\n\n/**\n * What the stripped argv means, before citty sees it. `help`/`version` are commands; a help flag after\n * a command keeps it scoped; a first token starting with `-` is the `up` shorthand (`-p 4000`).\n */\nexport function resolveInvocation(argv: string[], commands: readonly string[]): Invocation {\n if (argv.length === 0)\n return { kind: 'command', argv: ['up'] }\n\n const first = argv[0]!\n if (HELP_TOKENS.has(first))\n return argv[1] !== undefined && commands.includes(argv[1]) ? { kind: 'help', command: argv[1] } : { kind: 'help' }\n if (VERSION_TOKENS.has(first))\n return { kind: 'version' }\n\n if (first.startsWith('-'))\n return { kind: 'command', argv: ['up', ...argv] }\n\n if (!commands.includes(first))\n return { kind: 'unknown', command: first }\n\n // `start help` may name a server called `help`.\n if (argv.length === 2 && argv[1] === 'help' && !ID_FIRST.has(first))\n return { kind: 'help', command: first }\n\n for (const arg of argv.slice(1)) {\n if (HELP_FLAGS.has(arg))\n return { kind: 'help', command: first }\n if (VERSION_FLAGS.has(arg))\n return { kind: 'version' }\n }\n\n return { kind: 'command', argv }\n}\n\nconst CAMEL = /[A-Z]/g\n\nfunction kebab(name: string): string {\n return name.replace(CAMEL, match => `-${match.toLowerCase()}`)\n}\n\nfunction aliasesOf(def: ArgsDef[string]): string[] {\n if (def === undefined || !('alias' in def) || def.alias === undefined)\n return []\n return Array.isArray(def.alias) ? def.alias : [def.alias]\n}\n\n/** Every spelling that reaches one option (key, kebab form, aliases, `no-`), so a suggestion is always accepted. */\nfunction namesOf(key: string, def: NonNullable<ArgsDef[string]>): string[] {\n return [key, kebab(key), ...aliasesOf(def)]\n}\n\nfunction declaredOptionNames(argsDef: ArgsDef): string[] {\n const names: string[] = []\n for (const [key, def] of Object.entries(argsDef)) {\n if (def === undefined || def.type === 'positional')\n continue\n names.push(...namesOf(key, def))\n if (def.type === 'boolean')\n names.push(...namesOf(key, def).map(name => `no-${name}`))\n }\n return names\n}\n\nfunction findArg(argsDef: ArgsDef, name: string): ArgsDef[string] | undefined {\n for (const [key, def] of Object.entries(argsDef)) {\n if (def === undefined)\n continue\n // A positional is never reachable as `--<key>`.\n if (def.type === 'positional')\n continue\n if (namesOf(key, def).includes(name))\n return def\n if (def.type === 'boolean' && (name === `no-${key}` || name === `no-${kebab(key)}`))\n return def\n }\n return undefined\n}\n\n/**\n * citty parses permissively, so a mistyped flag would quietly do nothing. Returns the message to\n * print, or null. `undefined` means the command parses its own argv (`ui-switch`); an empty `{}`\n * means it takes nothing, so everything is refused. A group's flags come from `flagTarget`.\n */\nexport function rejectUnknownFlags(argv: string[], argsDef: ArgsDef | undefined): string | null {\n if (argsDef === undefined)\n return null\n\n let positionals = Object.values(argsDef).filter(def => def?.type === 'positional').length\n\n for (let index = 0; index < argv.length; index++) {\n const token = argv[index]!\n if (token === '--')\n return null\n if (!token.startsWith('-') || token.length === 1) {\n if (positionals === 0)\n return `Unexpected argument '${token}'`\n positionals -= 1\n continue\n }\n\n const body = token.startsWith('--') ? token.slice(2) : token.slice(1)\n const equals = body.indexOf('=')\n const name = equals === -1 ? body : body.slice(0, equals)\n const def = name.length === 0 ? undefined : findArg(argsDef, name)\n if (def === undefined) {\n const suggested = nearestWord(name, declaredOptionNames(argsDef))\n const hint = suggested === null ? '' : ` — did you mean \\`--${suggested}\\`?`\n return `Unknown option '${token}'${hint}`\n }\n if (def.type === 'string' && equals === -1 && argv[index + 1] === undefined)\n return `Option '${token}' needs a value`\n if (def.type === 'string' && equals === -1)\n index += 1\n }\n\n return null\n}\n\ntype SubCommandsShape = Record<string, CommandShape | (() => CommandShape | Promise<CommandShape>)>\n\nexport interface CommandShape {\n args?: ArgsDef | (() => ArgsDef | Promise<ArgsDef>) | Promise<ArgsDef>\n subCommands?: SubCommandsShape | (() => SubCommandsShape | Promise<SubCommandsShape>) | Promise<SubCommandsShape>\n}\n\nasync function resolveLazy<T>(value: T | (() => T | Promise<T>) | Promise<T> | undefined): Promise<T | undefined> {\n if (value === undefined)\n return undefined\n const resolved = typeof value === 'function' ? await (value as () => T | Promise<T>)() : await value\n return resolved as T\n}\n\n/**\n * The definition whose `args` govern this argv: the subcommand's, for a group (`job ls --json`),\n * else the command's own. `CommandShape` rather than `CommandDef` because citty's generic args make\n * two commands' definitions mutually unassignable.\n */\nexport async function flagTarget(argv: string[], command: CommandShape | undefined): Promise<{ args: ArgsDef | undefined, argsFor: string[] }> {\n if (command === undefined)\n return { args: undefined, argsFor: argv }\n const subCommands = await resolveLazy(command.subCommands)\n if (subCommands === undefined)\n return { args: await resolveLazy(command.args), argsFor: argv }\n\n // The subcommand is the first bare word; a leading `--` ends the search (`add web -- node server.js`).\n const dashDash = argv.indexOf('--')\n const searchable = dashDash === -1 ? argv : argv.slice(0, dashDash)\n const index = searchable.findIndex(token => !token.startsWith('-'))\n if (index === -1)\n return { args: await resolveLazy(command.args), argsFor: argv }\n const sub = await resolveLazy(subCommands[searchable[index]!])\n if (sub === undefined)\n return { args: await resolveLazy(command.args), argsFor: argv }\n // The subcommand word is consumed by the group, so it is not validated as an argument.\n return { args: await resolveLazy(sub.args), argsFor: [...argv.slice(0, index), ...argv.slice(index + 1)] }\n}\n\nexport interface UpFlags {\n port?: number\n host?: string\n autostart: boolean\n open: boolean\n foreground: boolean\n printConfig: boolean\n}\n/** The daemon's argv: never `--foreground` (that makes it the daemon) or `--print-config`. */\nexport function buildDaemonArgv(flags: UpFlags): string[] {\n const args: string[] = ['up', '--foreground']\n if (flags.port !== undefined)\n args.push('--port', String(flags.port))\n if (flags.host !== undefined)\n args.push('--host', flags.host)\n if (!flags.autostart)\n args.push('--no-autostart')\n if (flags.open)\n args.push('--open')\n return args\n}\n","import process from 'node:process'\n\n/**\n * A value quoted for the shell a person will paste it into. POSIX gets single quotes (`'\\''` for an\n * embedded one); `cmd.exe` has no single-quote quoting, so Windows gets double quotes.\n */\nexport function shellQuote(value: string): string {\n return process.platform === 'win32'\n ? `\"${value}\"`\n : `'${value.replace(/'/g, `'\\\\''`)}'`\n}\n","import process from 'node:process'\nimport readline from 'node:readline'\nimport { shellQuote } from '#src/helpers/shell'\n\n/**\n * The bits every command shares: colours, the failure shape, readline. Imported before citty runs, so\n * it may not read the state directories or `helpers/paths.ts`.\n */\n\nexport const isTty = (): boolean => process.stdout.isTTY === true\n\nexport const paint = (code: string, text: string): string => (isTty() ? `\\x1B[${code}m${text}\\x1B[0m` : text)\nexport const dim = (text: string): string => paint('2', text)\nexport const bold = (text: string): string => paint('1', text)\nexport const cyan = (text: string): string => paint('36', text)\nexport const green = (text: string): string => paint('32', text)\nexport const heading = (text: string): string => paint('1;4', text)\n\n/** The seam `ui-switch` takes, so the command stays testable without a terminal. */\nexport const style = { bold, dim, green }\n\n/**\n * How this process was invoked, so a hint names a command the person can run (`npx` leaves no\n * `home-hosted` on PATH). Carries `--home` whenever one was chosen, so a pasted hint reaches the same\n * state. `HHOSTED_INVOCATION` overrides the program, never the state.\n */\nexport function invocation(): string {\n const program = invocationProgram()\n const home = process.env.HHOSTED_HOME?.trim()\n return home === undefined || home.length === 0 ? program : `${program} --home ${shellQuote(home)}`\n}\n\nfunction invocationProgram(): string {\n const override = process.env.HHOSTED_INVOCATION?.trim()\n if (override !== undefined && override.length > 0)\n return override\n\n const entry = process.argv[1] ?? ''\n // A package-manager cache means the package is not installed.\n if (/[\\\\/](?:_npx|dlx)[\\\\/]/.test(entry))\n return 'npx home-hosted'\n if (/[\\\\/]cli\\.ts$/.test(entry))\n return 'pnpm exec tsx src/cli.ts'\n\n return 'home-hosted'\n}\n\n/**\n * A reader that hangs up (`status | head -1`) is a finished conversation: exit 0 rather than an\n * EPIPE stack trace. The code differs per platform (`EPIPE`, `ENOTCONN` on macOS,\n * `ERR_STREAM_DESTROYED`), so the test is whether the error says the reader went away. Other write\n * failures still end the process.\n */\nconst READER_GONE = /^(?:EPIPE|ENOTCONN|ERR_STREAM_DESTROYED|ERR_STREAM_WRITE_AFTER_END|ECONNRESET)$/\n\nexport function isClosedReaderError(error: unknown): boolean {\n const code = (error as NodeJS.ErrnoException | null)?.code\n if (typeof code === 'string' && READER_GONE.test(code))\n return true\n const message = (error as Error | null)?.message ?? ''\n return /^(?:closed|write after end|premature close)$/i.test(message)\n}\n\nexport function treatClosedReaderAsDone(): void {\n process.stdout.on('error', (error: NodeJS.ErrnoException) => {\n if (isClosedReaderError(error))\n process.exit(0)\n throw error\n })\n}\n\nexport function fail(message: string): never {\n process.stderr.write(`${paint('31', 'error')} ${message}\\n`)\n process.exit(1)\n}\n\n/**\n * The same red `error <message>` on stderr, for a refusal that still has work to do after it. Every\n * refusal goes to stderr: a `--json` caller parses stdout.\n */\nexport function refusal(message: string): void {\n process.stderr.write(`${paint('31', 'error')} ${message}\\n`)\n}\n\n/**\n * A `--json` answer: one pretty-printed document on stdout. Every command prints through this, so a\n * script sees one shape everywhere.\n */\nexport function printJson(document: unknown): void {\n process.stdout.write(`${JSON.stringify(document, null, 2)}\\n`)\n}\n\nexport function delay(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms))\n}\n\nexport function prompt(question: string): Promise<string> {\n return new Promise((resolve) => {\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout })\n rl.question(question, (answer) => {\n rl.close()\n resolve(answer)\n })\n })\n}\n\n/** Reads a line with echo suppressed, so the password never lands in scrollback. */\nexport function promptHidden(question: string): Promise<string> {\n return new Promise((resolve) => {\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true })\n const onData = (): void => {\n readline.clearLine(process.stdout, 0)\n readline.cursorTo(process.stdout, 0)\n process.stdout.write(question)\n }\n\n process.stdin.on('data', onData)\n rl.question(question, (answer) => {\n process.stdin.off('data', onData)\n rl.close()\n process.stdout.write('\\n')\n resolve(answer)\n })\n })\n}\n\nexport async function confirm(question: string, fallback: boolean): Promise<boolean> {\n const answer = (await prompt(`${question} ${fallback ? '[Y/n]' : '[y/N]'} `)).trim().toLowerCase()\n if (answer.length === 0)\n return fallback\n return answer === 'y' || answer === 'yes'\n}\n\n/**\n * `recorded` while the first-run password is in use and its text is in the secrets file; `unrecorded`\n * when it is in use but the text is gone (a restore may carry only the hash); `null` otherwise.\n */\nexport type FirstRunPassword = { kind: 'recorded', account: string, password: string } | { kind: 'unrecorded', account: string }\n\nexport async function firstRunPasswordState(file?: string): Promise<FirstRunPassword | null> {\n const { SecretsStore } = await import('#src/config/secrets')\n const path = file ?? (await import('#src/helpers/paths')).globalSecretsPath\n try {\n const store = new SecretsStore(path, undefined, 'global')\n const account = store.listAccounts().find(entry => entry.isDefault)?.id\n if (account === undefined)\n return null\n const password = store.initialPassword\n return password === null ? { kind: 'unrecorded', account } : { kind: 'recorded', account, password }\n }\n catch {\n return null\n }\n}\n\nexport function unrecordedFirstRunHint(): string {\n return `the first-run secret is in use but no longer recorded — run \\`${invocation()} account reset\\``\n}\n\nexport async function firstRunPassword(): Promise<string | null> {\n const state = await firstRunPasswordState()\n return state?.kind === 'recorded' ? state.password : null\n}\n","import process from 'node:process'\n\n/**\n * How to run this CLI again in the same runtime (under tsx, with the resolved loader). Reads no\n * state directory, so the CLI can import it before `--home`/`--project` are applied.\n */\nexport function runtimeArgs(): string[] {\n let resolved: string | null = null\n const resolveTsx = (): string => resolved ??= import.meta.resolve('tsx')\n\n return process.execArgv.map((arg) => {\n if (arg === 'tsx')\n return resolveTsx()\n if (arg.startsWith('--import=') && arg.slice('--import='.length) === 'tsx')\n return `--import=${resolveTsx()}`\n return arg\n })\n}\n\n/** The hidden command a persistent entry runs under; one definition, because `providers/identity.ts` reads the argv back. */\nexport const NANNY_COMMAND = '__nanny'\n\nexport function nannyArgv(entry: string, id: string, specPath: string, statePath: string): string[] {\n return [...runtimeArgs(), entry, NANNY_COMMAND, '--id', id, '--spec', specPath, '--state', statePath]\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nlet cachedRoot: { dir: string, version: string } | null = null\n\n/**\n * The package's own directory and release, found by walking up to the manifest named `home-hosted`\n * (callers may be `src/**`, `dist/cli.js` or a chunk). `src/cli.ts` imports this relatively: the\n * bootstrap may only load modules with static node builtins.\n */\nfunction findPackage(): { dir: string, version: string } {\n if (cachedRoot !== null)\n return cachedRoot\n const start = path.dirname(fileURLToPath(import.meta.url))\n let dir = start\n for (let depth = 0; depth < 5; depth++) {\n try {\n const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')) as { name?: string, version?: string }\n if (manifest.name === 'home-hosted' && typeof manifest.version === 'string') {\n cachedRoot = { dir, version: manifest.version }\n return cachedRoot\n }\n }\n catch {\n }\n const parent = path.dirname(dir)\n if (parent === dir)\n break\n dir = parent\n }\n cachedRoot = { dir: path.dirname(start), version: '0.0.0' }\n return cachedRoot\n}\n\nexport function appVersion(): string {\n return findPackage().version\n}\n\n/** Where the package is installed: the base for files it ships (`uis/stock/dist`). */\nexport function packageRoot(): string {\n return findPackage().dir\n}\n\n/** The line to add when this CLI and the panel are different releases; `null` when they agree. */\nexport function versionMismatchNote(panelVersion: string): string | null {\n const cli = appVersion()\n return cli === panelVersion ? null : `note: this CLI is ${cli}, the panel is ${panelVersion}`\n}\n","import type { SubCommandsDef } from 'citty'\nimport type { CommandShape } from './cli/args'\nimport process from 'node:process'\nimport { fileURLToPath } from 'node:url'\nimport { defineCommand, runCommand } from 'citty'\nimport { API_TOKEN_SCOPES as SCOPES } from '#src/shared/api-scopes'\nimport { errorMessage } from '#src/shared/error-message'\nimport { applyDirFlags, extractDirFlags, flagTarget, rejectUnknownFlags, resolveInvocation } from './cli/args'\nimport { cyan, dim, fail, heading, treatClosedReaderAsDone } from './cli/io'\nimport { nearestWord } from './cli/nearest'\nimport { NANNY_COMMAND } from './helpers/runtime'\nimport { appVersion } from './helpers/version'\n\n/**\n * The command line. Before citty sees anything, `--home`/`--project` are applied (because\n * `#src/helpers/paths.ts` resolves at import time) and the curated surface is decided. Only node\n * builtins, citty and path-free modules are imported statically; every command is a lazy import.\n */\n\nconst CLI_ENTRY = fileURLToPath(import.meta.url)\n\n/** The curated prose: one piece per command, so the full reference and `<command> --help` share lines. */\n\nconst HEADER = 'home-hosted — a control panel for the processes on your home server'\n\nconst SYNOPSIS: Record<string, string> = {\n 'up': 'home-hosted up [options]',\n 'down': 'home-hosted down [--with-persistent]',\n 'restart': 'home-hosted restart [<id>] [options]',\n 'status': 'home-hosted status [--json]',\n 'logs': 'home-hosted logs [<id>] [--lines <n>] [--follow] [--json] [--workspace <id>]',\n 'usage': 'home-hosted usage [--json]',\n 'backup': 'home-hosted backup [list|create|restore] [options]',\n 'start': 'home-hosted start <id> [--workspace <id>] [--free-port]',\n 'stop': 'home-hosted stop <id> [--workspace <id>]',\n 'free-port': 'home-hosted free-port <id> [--workspace <id>]',\n 'account': 'home-hosted account create|ls|edit|secret|revoke|reset|disable-auth|enable-auth [<id>] [options]',\n 'setup-temp': 'home-hosted setup-temp [--wsl] [--download|--no-download] [--clear]',\n 'migrate': 'home-hosted migrate [--dry-run] [--yes]',\n 'init': 'home-hosted init [options]',\n 'ui-switch': 'home-hosted ui-switch [options]',\n 'ui-update': 'home-hosted ui-update [options]',\n 'ui-revert': 'home-hosted ui-revert',\n 'service': 'home-hosted service [install|uninstall|status] [--user|--system|--startup] [--print]',\n 'add': 'home-hosted add <id> [--port <n>] [--cwd <dir>] [--workspace <id>] [--persistent] [--autostart] [--secret-env <names>] -- <command> [args…]',\n 'ls': 'home-hosted ls [--workspace <id>] [--json]',\n 'secret': 'home-hosted secret set|unset|ls <id> [NAME] [--stdin] [--workspace <id>] [--json]',\n 'import': 'home-hosted import pm2|compose <file> [--confirm] [--dry-run] [--allow-js] [--env <name>] [--id <id>] [--workspace <id>] [--json]',\n 'token': 'home-hosted token create|ls|revoke [--name <name>] [--scope <scopes>] [--workspace <ids>] [--json]',\n 'deploy': 'home-hosted deploy <id> [--workspace <id>] [--json]',\n 'job': 'home-hosted job ls|run|stop|enable|disable|runs|log [<id>] [--detach] [--run <runId>] [--follow] [--workspace <id>] [--json]',\n}\n\nconst SUMMARIES: Record<string, string> = {\n 'up': 'start it in the background (detached)',\n 'down': 'stop it, and everything it supervises',\n 'restart': 'down then up — or one server, given an id',\n 'status': 'is it running, where, and how to reach it',\n 'logs': 'show the panel\\'s console, or one server\\'s own log with an id',\n 'usage': 'live CPU and memory per server, loudest first',\n 'backup': 'list, create or restore a backup archive',\n 'start': 'start one server, leaving the panel up',\n 'stop': 'stop one server, leaving the panel up',\n 'free-port': 'free the port a server needs, so it can start',\n 'setup-temp': 'teach the panel how to read this machine\\'s CPU temperature',\n 'migrate': 'bring the config up to this release\\'s schema',\n 'init': 'scaffold a project that keeps its state in the repo',\n 'ui-switch': 'install a UI from a release asset, a zip file or a URL',\n 'ui-update': 'bring the installed UI up to date, or pick a release',\n 'ui-revert': 'go back to the stock control panel UI',\n 'service': 'start the panel at boot with systemd, launchd or Task Scheduler',\n 'add': 'declare a server, through the panel or straight into servers.config.json',\n 'ls': 'list the servers a workspace declares, live when the panel is up',\n 'secret': 'a server\\'s secret environment — the names are listed, the values never printed',\n 'import': 'bring a pm2 ecosystem or a compose stack in as server entries',\n 'token': 'named, scoped API tokens — create, list or revoke',\n 'deploy': 'run an entry\\'s deploy steps and report the outcome',\n 'job': 'a workspace\\'s jobs: `ls` what is scheduled, `run` or `stop` one now, read its `runs` and `log`',\n 'account': 'the panel\\'s accounts: create, list, edit, set a secret, revoke, recover',\n}\n\ntype OptionLine = [left: string, right: string]\n\ninterface OptionSection {\n heading: string\n lines: OptionLine[]\n}\n\nconst OPTION_WIDTH = 21\n\nconst UP_SECTION: OptionSection = {\n heading: 'Options for up',\n lines: [\n ['-p, --port <port>', 'control panel port (default: 3999); saved to settings.json'],\n ['--host <bind>', 'local | lan | an ipv4 address (default: local); saved to settings.json'],\n ['--open', 'open the panel in a browser once it is up'],\n ['--no-autostart', 'do not start the entries marked autostart'],\n ['--foreground', 'run in this process instead of detaching (systemd/docker)'],\n ['--print-config', 'print the effective config and exit — starts nothing, sets no secret'],\n ],\n}\n\nconst STATUS_SECTION: OptionSection = {\n heading: 'Options for status',\n lines: [\n ['--json', 'print machine-readable JSON'],\n ],\n}\n\nconst LOGS_SECTION: OptionSection = {\n heading: 'Options for logs',\n lines: [\n ['<id>', 'one server\\'s own log instead of the panel console (optional)'],\n ['--lines <n>', 'how many lines to show: 1 or more (default 50), or `all`'],\n ['--follow', 'keep printing as the panel writes (like tail -f)'],\n ['--json', 'print machine-readable JSON (one object per line with --follow)'],\n ['-w, --workspace <id>', 'the workspace the server is in (default: the panel\\'s default)'],\n ],\n}\n\nconst USAGE_SECTION: OptionSection = {\n heading: 'Options for usage',\n lines: [\n ['--json', 'print machine-readable JSON'],\n ],\n}\n\nconst BACKUP_SECTION: OptionSection = {\n heading: 'Arguments for backup',\n lines: [\n ['list | create | restore', 'what to do (default: list)'],\n ['<name>', 'the archive, for restore — `backup list` shows them'],\n ['--from <path>', 'restore from an archive file anywhere on this machine, instead of a name'],\n ['--include <ids>', 'comma-separated item ids to act on (required for create/restore)'],\n ['--all', 'act on everything; one of --include or --all is required'],\n ['--exclude <ids>', 'leave these out; --all --exclude global:secrets keeps the accounts and API tokens out of the archive'],\n ['--encrypt', 'create: encrypt it with a password asked for without echo'],\n ['--password <text>', 'deprecated — shows in shell history; use HHOSTED_BACKUP_PASSWORD or --encrypt'],\n ['--confirm', 'apply without asking (create and restore plan first)'],\n ['--json', 'print the plan or the result as JSON'],\n ],\n}\n\nconst SERVER_SECTION: OptionSection = {\n heading: 'Arguments for stop/free-port',\n lines: [\n ['<id>', 'the server id from servers.config.json'],\n ['-w, --workspace <id>', 'the workspace to act in (default: the default workspace)'],\n ],\n}\n\nconst START_SECTION: OptionSection = {\n heading: 'Arguments for start',\n lines: [\n ['<id>', 'the server id from servers.config.json'],\n ['-w, --workspace <id>', 'the workspace to act in (default: the default workspace)'],\n ['--free-port', 'free the port first, then start — the panel\\'s Free port button'],\n ],\n}\n\nconst PERSISTENT_LINE: OptionLine = ['--with-persistent', 'stop the persistent entries too (default: leave them running)']\n\nconst DOWN_SECTION: OptionSection = {\n heading: 'Options for down',\n lines: [PERSISTENT_LINE],\n}\n\nconst RESTART_SECTION: OptionSection = {\n heading: 'Options for restart (and every option of up)',\n lines: [\n // Its own section: `restart` takes an id and `up` does not.\n ['<id>', 'restart just this server, leaving the panel up (optional)'],\n ['-w, --workspace <id>', 'the workspace to act in, with an id'],\n PERSISTENT_LINE,\n ],\n}\n\nconst ACCOUNT_SECTION: OptionSection = {\n heading: 'Commands for account',\n lines: [\n ['create <id>', 'a new account; the secret is generated and shown once (HHOSTED_SECRET sets your own)'],\n ['--scope <scopes>', `comma-separated, any of ${SCOPES.join(', ')} (default: all)`],\n ['-w, --workspace <ids>', 'limit it to those workspaces (default: every workspace)'],\n ['ls', 'the ids, labels, scopes and whether each is enabled — never a secret'],\n ['--label <text>', 'create/edit: a human label (default: the id)'],\n ['edit <id>', 'change --scope, -w (\\'\\' clears the limit), --label, or --enable/--disable'],\n ['secret <id>', 'set that account\\'s secret (prompts, or HHOSTED_SECRET for a script)'],\n ['revoke <id>', 'delete it; its sessions end immediately'],\n ['reset [id]', 'the recovery path: a fresh secret (or HHOSTED_SECRET) for an admin account, enabled'],\n ['disable-auth', 'switch the guard off; the accounts are kept'],\n ['enable-auth', 'switch it back on'],\n ['--json', 'create, ls, edit, revoke, reset: print one document on stdout'],\n ],\n}\n\nconst SETUP_TEMP_SECTION: OptionSection = {\n heading: 'Options for setup-temp',\n lines: [\n ['--wsl', 'read the temperature through the Windows host (WSL2)'],\n ['--download', 'with --wsl: fetch LibreHardwareMonitor without asking (for a script)'],\n ['--no-download', 'with --wsl: never fetch it; report what is missing'],\n ['--clear', 'stop using the command and delete the helper'],\n ],\n}\n\nconst MIGRATE_SECTION: OptionSection = {\n heading: 'Options for migrate',\n lines: [\n ['--dry-run', 'print what would change, write nothing'],\n ['-y, --yes', 'apply without asking (or set HHOSTED_MIGRATE=allow)'],\n ],\n}\n\nconst INIT_SECTION: OptionSection = {\n heading: 'Options for init',\n lines: [\n ['--dir <dir>', 'where to scaffold (default: ./my-servers)'],\n ['--name <name>', 'package name (default: the directory name)'],\n ['--pm <manager>', 'pnpm | npm | yarn | bun (default: the first one installed)'],\n ['--no-install', 'write the files, install nothing'],\n ['-y, --yes', 'take every default, ask nothing'],\n ],\n}\n\nconst UI_SWITCH_SECTION: OptionSection = {\n heading: 'Options for ui-switch',\n lines: [\n ['--repo <owner/name>', 'release repo (default: NamesMT/home-hosted)'],\n ['--tag <tag>', 'release tag (default: this release\\'s tag, or latest for another repo)'],\n ['--asset <name>', 'asset to install (exact or unambiguous match)'],\n ['--file <path|url>', 'install a zip from a local path or an http(s) URL'],\n ['--insecure', 'allow a plain http:// URL for --file'],\n ['--list', 'list the usable assets and install nothing'],\n ['--token <token>', 'GitHub token (or GITHUB_TOKEN / GH_TOKEN)'],\n ['-y, --yes', 'take the only asset instead of asking'],\n ],\n}\n\nconst UI_UPDATE_SECTION: OptionSection = {\n heading: 'Options for ui-update',\n lines: [\n ['--check', 'report whether an update is available and install nothing'],\n ['--tag <tag>', 'install that release instead of asking'],\n ['--asset <name>', 'asset to install (defaults to the one in use)'],\n ['--old', 'list older releases instead of newer ones'],\n ['--repo <owner/name>', 'for a UI that does not declare its own repo'],\n ['--token <token>', 'GitHub token (or GITHUB_TOKEN / GH_TOKEN)'],\n ['-y, --yes', 'take the only release instead of asking'],\n ],\n}\n\nconst SERVICE_SECTION: OptionSection = {\n heading: 'Options for service',\n lines: [\n ['install | uninstall | status', 'what to do (default: status)'],\n ['--user', 'a service for this account (default); on Linux, see loginctl enable-linger'],\n ['--system', 'a machine-wide service started at boot (needs sudo / an administrator)'],\n ['--startup', 'Windows: a Startup-folder entry at logon — needs no administrator, no restart policy'],\n ['--print', 'with install: print the unit to stdout and install nothing'],\n ],\n}\n\nconst ADD_SECTION: OptionSection = {\n heading: 'Arguments for add',\n lines: [\n ['<id>', 'the new server id: lowercase letters, digits, - and _'],\n ['-- <command> [args…]', 'the command it runs, after a bare --'],\n ['--port <n>', 'the port it listens on'],\n ['--cwd <dir>', 'its working directory (relative: to --project)'],\n ['-w, --workspace <id>', 'the workspace to add it to (default: the default workspace)'],\n ['--persistent', 'keep it running when the panel stops'],\n ['--autostart', 'start it whenever the panel starts (an add does not start it)'],\n ['--secret-env <names>', 'declare secret variable names (repeatable or comma-separated); then `secret set`'],\n ],\n}\n\nconst LS_SECTION: OptionSection = {\n heading: 'Options for ls',\n lines: [\n ['-w, --workspace <id>', 'the workspace to list (default: the default workspace)'],\n ['--json', 'print machine-readable JSON'],\n ],\n}\n\nconst SECRET_SECTION: OptionSection = {\n heading: 'Commands for secret',\n lines: [\n ['set <id> NAME', 'store a value: prompts without echo, or read one line from --stdin'],\n ['unset <id> NAME', 'forget the value (the name stays declared in the entry)'],\n ['ls <id>', 'the declared names, and which of them have a value'],\n ['<id>', 'a server or a job — both declare `secretEnv`'],\n ],\n}\n\nconst IMPORT_SECTION: OptionSection = {\n heading: 'Options for import',\n lines: [\n ['pm2 <file>', 'a pm2 ecosystem (.json, or .js with --allow-js): each app becomes one entry'],\n ['compose <file>', 'one entry for the stack, running `docker compose -f <file> up`'],\n ['--confirm', 'write the plan; without it nothing is written and a non-interactive run exits 1'],\n ['--dry-run', 'print the plan and write nothing, even with --confirm'],\n ['--allow-js', 'evaluate a .js ecosystem file — it is code, and it runs in this process'],\n ['--env <name>', 'pm2 only: read that env block (pm2 injects `env_<name>`; this reads the one you name)'],\n ['-w, --workspace <id>', 'the workspace to write into (default: the default workspace)'],\n ['--id <id>', 'compose only: the server id (default: the file\\'s directory name)'],\n ['--json', 'print the plan and the outcome as one document'],\n ],\n}\n\nconst TOKEN_SECTION: OptionSection = {\n heading: 'Commands for token',\n lines: [\n ['create --name <name> --scope <scopes>', `a new token; scopes are comma-separated (${SCOPES.join(', ')}) and cumulative`],\n ['create … -w, --workspace <ids>', 'limit it to those workspaces (default: every workspace)'],\n ['ls', 'the ids, names, scopes and when each was last used — never a value'],\n ['revoke <id>', 'stop a token working, immediately'],\n ['--json', 'print one document on stdout'],\n ],\n}\n\nconst DEPLOY_SECTION: OptionSection = {\n heading: 'Options for deploy',\n lines: [\n ['<id>', 'the server whose `deploy` steps to run'],\n ['-w, --workspace <id>', 'the workspace that owns it (default: the default workspace)'],\n ['--json', 'print one document on stdout'],\n ],\n}\n\nconst JOB_SECTION: OptionSection = {\n heading: 'Options for job',\n lines: [\n ['ls', 'what is scheduled: expression, next run, how the last run ended'],\n ['run <id>', 'run it now and wait for the outcome (anything but success exits 1)'],\n ['--detach', 'with run: start it and return at once'],\n ['stop <id>', 'end the run in flight'],\n ['enable|disable <id>', 'switch its schedule on or off'],\n ['runs <id>', 'its recent runs, newest first'],\n ['log <id>', 'what its runs wrote, newest last'],\n ['--run <runId>', 'with log: only that run\\'s lines'],\n ['-f, --follow', 'with log: keep printing new lines'],\n ['-w, --workspace <id>', 'the workspace that owns it (default: the panel\\'s default workspace)'],\n ['--json', 'print one document on stdout'],\n ],\n}\n\nconst EVERYWHERE_SECTION: OptionSection = {\n heading: 'Everywhere',\n lines: [\n ['--home <dir>', 'state directory (default: $HHOSTED_HOME or ~/.home-hosted)'],\n ['--project <dir>', 'base for relative entry paths (default: the current directory)'],\n ['-h, --help', 'this text'],\n ['-v, --version', 'the version'],\n ],\n}\n\nconst ALIAS_SECTION: OptionSection = {\n heading: 'Alias',\n lines: [\n ['hh', 'the same CLI, on a machine where home-hosted is installed'],\n ],\n}\n\nconst ENVIRONMENT_SECTION: OptionSection = {\n heading: 'Environment',\n lines: [\n ['HHOSTED_HOME', 'where config, secrets, logs, TLS and backups live'],\n ['HHOSTED_PROJECT', 'base for relative entry paths'],\n ['HHOSTED_SECRET', 'the secret for a non-interactive account create/secret/reset'],\n ['HHOSTED_BACKUP_PASSWORD', 'the archive password for backup create/restore, without a prompt'],\n ['HHOSTED_MIGRATE', '`allow` lets migrate apply without asking, for an unattended run'],\n ['HHOSTED_DDNS_SECRET', 'the key DDNS credentials are sealed with'],\n ['GITHUB_TOKEN', 'a GitHub token for ui-switch and ui-update (GH_TOKEN also works)'],\n ],\n}\n\n/** The command a typo most likely meant, from `SYNOPSIS`, or null. */\nexport function suggestCommand(input: string): string | null {\n return nearestWord(input, Object.keys(SYNOPSIS))\n}\n\nfunction renderCommandList(): string {\n const width = Math.max(...Object.values(SYNOPSIS).map(synopsis => synopsis.length))\n return Object.keys(SYNOPSIS)\n .map((name) => {\n const synopsis = SYNOPSIS[name]!\n return ` ${cyan(synopsis)}${' '.repeat(width + 1 - synopsis.length)} ${SUMMARIES[name]}`\n })\n .join('\\n')\n}\n\nfunction renderSection(section: OptionSection): string {\n const lines = section.lines\n .map(([left, right]) => ` ${cyan(left)}${' '.repeat(Math.max(0, OPTION_WIDTH - left.length))} ${right}`)\n .join('\\n')\n return `${heading(section.heading)}\\n${lines}`\n}\n\nconst SHARED_TRAILER = [\n renderSection(EVERYWHERE_SECTION),\n '',\n renderSection(ALIAS_SECTION),\n '',\n renderSection(ENVIRONMENT_SECTION),\n '',\n].join('\\n')\n\nconst SECTIONS: Record<string, OptionSection> = {\n 'up': UP_SECTION,\n 'down': DOWN_SECTION,\n 'status': STATUS_SECTION,\n 'logs': LOGS_SECTION,\n 'usage': USAGE_SECTION,\n 'backup': BACKUP_SECTION,\n 'restart': RESTART_SECTION,\n 'start': START_SECTION,\n 'stop': SERVER_SECTION,\n 'free-port': SERVER_SECTION,\n 'account': ACCOUNT_SECTION,\n 'setup-temp': SETUP_TEMP_SECTION,\n 'migrate': MIGRATE_SECTION,\n 'init': INIT_SECTION,\n 'ui-switch': UI_SWITCH_SECTION,\n 'ui-update': UI_UPDATE_SECTION,\n 'service': SERVICE_SECTION,\n 'add': ADD_SECTION,\n 'ls': LS_SECTION,\n 'secret': SECRET_SECTION,\n 'import': IMPORT_SECTION,\n 'token': TOKEN_SECTION,\n 'deploy': DEPLOY_SECTION,\n 'job': JOB_SECTION,\n}\n\n/** The full reference, built from `SECTIONS` so a command cannot be listed without its options. */\nconst USAGE = [\n dim(HEADER),\n '',\n heading('Usage'),\n renderCommandList(),\n '',\n ...[...new Set(Object.keys(SYNOPSIS).map(name => SECTIONS[name]).filter(section => section !== undefined))]\n .flatMap(section => [renderSection(section), '']),\n SHARED_TRAILER,\n].join('\\n')\n\nexport function commandHelp(command: string): string {\n const synopsis = SYNOPSIS[command]\n if (synopsis === undefined)\n return USAGE\n\n const section = SECTIONS[command]\n const options = section === undefined\n ? dim('no options')\n : [renderSection(section), ...(command === 'restart' ? ['', renderSection(UP_SECTION)] : [])].join('\\n')\n\n return [\n dim(HEADER),\n '',\n cyan(synopsis),\n '',\n options,\n '',\n dim('`home-hosted --help` lists every command, the options every command takes, and the environment'),\n '',\n ].join('\\n')\n}\n\nfunction version(): void {\n process.stdout.write(`${appVersion()}\\n`)\n}\n\n/** Lazy imports, so a command's `#src` modules load only after `applyDirFlags()`. */\nconst COMMANDS = {\n 'up': () => import('#src/cli/up').then(module => module.upCommand(CLI_ENTRY)),\n 'down': () => import('#src/cli/down').then(module => module.downCommand),\n 'restart': () => import('#src/cli/restart').then(module => module.restartCommand(CLI_ENTRY)),\n 'status': () => import('#src/cli/status').then(module => module.statusCommand),\n 'logs': () => import('#src/cli/logs').then(module => module.logsCommand),\n 'usage': () => import('#src/cli/usage').then(module => module.usageCommand),\n 'start': () => import('#src/cli/server').then(module => module.startCommand),\n 'stop': () => import('#src/cli/server').then(module => module.stopCommand),\n 'free-port': () => import('#src/cli/server').then(module => module.freePortCommand),\n 'account': () => import('#src/cli/account').then(module => module.accountCommand),\n 'setup-temp': () => import('#src/cli/setup-temp').then(module => module.setupTempCommand),\n 'migrate': () => import('#src/cli/migrate').then(module => module.migrateCommand),\n 'init': () => import('#src/cli/init').then(module => module.initCommand),\n 'ui-switch': () => import('#src/cli/ui-switch').then(module => module.uiSwitchCommand),\n 'ui-update': () => import('#src/cli/ui-update').then(module => module.uiUpdateCommand),\n 'ui-revert': () => import('#src/cli/ui-revert').then(module => module.uiRevertCommand),\n 'backup': () => import('#src/cli/backup').then(module => module.backupCommand),\n 'service': () => import('#src/cli/service').then(module => module.serviceCommand(CLI_ENTRY)),\n 'add': () => import('#src/cli/add').then(module => module.addCommand),\n 'ls': () => import('#src/cli/ls').then(module => module.lsCommand),\n 'secret': () => import('#src/cli/secret').then(module => module.secretCommand),\n 'import': () => import('#src/cli/import').then(module => module.importCommand),\n 'token': () => import('#src/cli/token').then(module => module.tokenCommand),\n 'deploy': () => import('#src/cli/run-deploy').then(module => module.deployCommand),\n 'job': () => import('#src/cli/job').then(module => module.jobCommand),\n} satisfies SubCommandsDef\n\nconst rootCommand = defineCommand({\n meta: {\n name: 'home-hosted',\n version: appVersion(),\n description: 'a control panel for the processes on your home server',\n },\n subCommands: COMMANDS,\n})\n\nconst commandNames = Object.keys(COMMANDS)\n\n/** `engines` is advisory (`npx` ignores it), so the floor is checked first, with no `#src` import. */\nfunction assertNodeFloor(): void {\n const required = 24\n const found = Number(process.versions.node.split('.')[0])\n if (Number.isFinite(found) && found >= required)\n return\n // Not \"home-hosted <word>\": the command-hint guards in tests would read that as a command.\n process.stderr.write(\n `This CLI needs Node ${required} or newer, and this is Node ${process.versions.node}.\\n`\n + ` install a newer one (https://nodejs.org), then run the command again.\\n`,\n )\n process.exit(1)\n}\n\nasync function main(): Promise<void> {\n assertNodeFloor()\n\n // An unhandled EPIPE (`| head -1`) would print a stack trace and exit 1.\n treatClosedReaderAsDone()\n\n const dirFlags = extractDirFlags(process.argv.slice(2))\n if (dirFlags.error !== undefined)\n fail(dirFlags.error)\n applyDirFlags(dirFlags)\n\n // The nanny is spawned by the panel, never typed, so it bypasses the curated surface.\n if (dirFlags.rest[0] === NANNY_COMMAND) {\n const { nannyCommand } = await import('#src/cli/nanny')\n try {\n await runCommand(nannyCommand, { rawArgs: dirFlags.rest })\n }\n catch (error) {\n fail(errorMessage(error))\n }\n return\n }\n\n const invocation = resolveInvocation(dirFlags.rest, commandNames)\n\n if (invocation.kind === 'help') {\n process.stdout.write(invocation.command === undefined ? USAGE : commandHelp(invocation.command))\n return\n }\n if (invocation.kind === 'version') {\n version()\n return\n }\n if (invocation.kind === 'unknown') {\n const suggestion = suggestCommand(invocation.command)\n process.stderr.write(`unknown command: ${invocation.command}\\n`)\n if (suggestion !== null)\n process.stderr.write(`did you mean \\`${suggestion}\\`?\\n`)\n process.stderr.write(`${dim('`home-hosted --help` lists commands')}\\n`)\n process.exit(1)\n }\n\n const { ensureLayout } = await import('#src/config/layout')\n ensureLayout()\n\n // citty parses permissively, so a mistyped flag is checked against `flagTarget` (a group declares its\n // flags on its subcommands).\n const sub = COMMANDS[invocation.argv[0]! as keyof typeof COMMANDS]\n const command = typeof sub === 'function' ? await sub() : sub\n const target = await flagTarget(invocation.argv.slice(1), command as CommandShape | undefined)\n const problem = rejectUnknownFlags(target.argsFor, target.args)\n if (problem !== null)\n fail(problem)\n\n // `runCommand`, not `runMain`: `runMain` prints its own usage and error, bypassing `fail()`.\n try {\n await runCommand(rootCommand, { rawArgs: invocation.argv })\n }\n catch (error) {\n // citty's own wording for a group's unknown subcommand (`account bogus`), coloured whatever the stream.\n if ((error as { code?: string } | null)?.code === 'E_UNKNOWN_COMMAND') {\n // eslint-disable-next-line no-control-regex\n const word = errorMessage(error).replace(/\\u001B\\[[0-9;]*m/g, '').replace(/^Unknown command /, '')\n fail(`unknown ${invocation.argv[0]} command: ${word} — \\`home-hosted ${invocation.argv[0]} --help\\` lists them`)\n }\n fail(errorMessage(error))\n }\n}\n\nvoid main().catch((error: unknown) => {\n fail(errorMessage(error))\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAcA,IAAa,mBAAmB;CAAC;CAAQ;CAAa;CAAU;CAAS;AAAO;;AAIhF,IAAa,oBAAoB,CAAC,SAAS,OAAO;;;;ACjBlD,SAAgB,aAAa,QAAyB;CACpD,OAAO,kBAAkB,QAAQ,OAAO,UAAU,OAAO,MAAM;AACjE;;;ACkBA,SAAgB,gBAAgB,MAA+B;CAC7D,MAAM,OAAiB,CAAC;CACxB,IAAI;CACJ,IAAI;CAEJ,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS;EAChD,MAAM,MAAM,KAAK;EACjB,MAAM,SAAS,IAAI,QAAQ,GAA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olves to this machine: `localhost`, `127.0.0.0/8`, `::1`. */
3
+ /**
4
+ * True for `localhost`, `127.0.0.0/8`, `::1` and the IPv4-mapped IPv6 loopback spellings `URL`
5
+ * normalises to (`[::ffff:7f00:1]`). Unlike `exposure.ts`'s `isLoopbackAddress`, `0.0.0.0`/`::` are not local.
6
+ */
4
7
  function isLoopbackHost(host) {
5
8
  const name = host.trim().toLowerCase();
6
9
  if (name === "localhost" || name === "::1" || name === "[::1]") return true;
7
10
  if (name.endsWith(".localhost")) return true;
8
- return /^127(?:\.\d{1,3}){3}$/.test(name);
11
+ const bare = name.startsWith("[") && name.endsWith("]") ? name.slice(1, -1) : name;
12
+ if (/^::ffff:127(?:\.\d{1,3}){3}$/.test(bare)) return true;
13
+ if (/^::ffff:(?:0:)?7f[0-9a-f]{2}:[0-9a-f]{1,4}$/.test(bare)) return true;
14
+ if (/^(?:0{1,4}:){5}ffff:7f[0-9a-f]{2}:[0-9a-f]{1,4}$/.test(bare)) return true;
15
+ return /^127(?:\.\d{1,3}){3}$/.test(bare);
9
16
  }
10
17
  //#endregion
11
18
  //#region src/client.ts
@@ -22,6 +29,17 @@ var HomeHostedError = class extends Error {
22
29
  this.detail = detail;
23
30
  }
24
31
  };
32
+ /** 250 ms doubling, capped at 30 s. */
33
+ function defaultRetryDelay(attempt) {
34
+ const ms = Math.min(250 * 2 ** Math.max(0, attempt - 1), 3e4);
35
+ return new Promise((resolve) => {
36
+ setTimeout(resolve, ms).unref?.();
37
+ });
38
+ }
39
+ /** A refusal no retry can fix: any `4xx` but a timeout (`408`) or a throttle (`429`). */
40
+ function isFinalRefusal(error) {
41
+ return error instanceof HomeHostedError && error.status >= 400 && error.status < 500 && error.status !== 408 && error.status !== 429;
42
+ }
25
43
  /** A token is sent only over https, or to this machine, unless the caller opted out. */
26
44
  function assertTokenTransport(baseUrl, options) {
27
45
  if (options.token === void 0 || options.allowInsecureToken === true) return;
@@ -38,6 +56,7 @@ function createClient(options) {
38
56
  const baseUrl = options.baseUrl.replace(/\/+$/, "");
39
57
  assertTokenTransport(baseUrl, options);
40
58
  const fetcher = options.fetch ?? globalThis.fetch.bind(globalThis);
59
+ const retryDelay = options.retryDelayMs ?? defaultRetryDelay;
41
60
  const headers = () => ({
42
61
  ...options.token === void 0 ? {} : { authorization: `Bearer ${options.token}` },
43
62
  ...options.headers
@@ -55,22 +74,46 @@ function createClient(options) {
55
74
  }
56
75
  /** The live feed: the first frame is always `hello` with the full state. */
57
76
  async function* events(query = {}) {
58
- const params = new URLSearchParams();
59
- if (query.workspace !== void 0) params.set("workspace", query.workspace);
60
- if (query.serverId !== void 0) params.set("serverId", query.serverId);
61
- if (query.logs === false) params.set("logs", "0");
62
- const suffix = params.size > 0 ? `?${params}` : "";
63
- const response = await fetcher(`${baseUrl}/api/events${suffix}`, {
64
- headers: {
65
- ...headers(),
66
- accept: "text/event-stream"
67
- },
68
- signal: query.signal
69
- });
70
- if (!response.ok || response.body === null) throw await toError(response);
71
- for await (const frame of readEventStream(response.body)) {
72
- if (frame.event === "ping" || frame.data === "") continue;
73
- yield JSON.parse(frame.data);
77
+ const base = (since) => {
78
+ const params = new URLSearchParams();
79
+ if (query.workspace !== void 0) params.set("workspace", query.workspace);
80
+ if (query.serverId !== void 0) params.set("serverId", query.serverId);
81
+ if (query.logs === false) params.set("logs", "0");
82
+ if (since !== void 0) params.set("since", String(since));
83
+ return params.size > 0 ? `?${params}` : "";
84
+ };
85
+ let resumeFrom = query.since;
86
+ let attempt = 0;
87
+ for (;;) {
88
+ let failed = null;
89
+ try {
90
+ const response = await fetcher(`${baseUrl}/api/events${base(resumeFrom)}`, {
91
+ headers: {
92
+ ...headers(),
93
+ accept: "text/event-stream"
94
+ },
95
+ signal: query.signal
96
+ });
97
+ if (!response.ok || response.body === null) throw await toError(response);
98
+ for await (const frame of readEventStream(response.body)) {
99
+ const id = frame.id !== void 0 && /^\d+$/.test(frame.id) ? Number(frame.id) : void 0;
100
+ if (id !== void 0) resumeFrom = id;
101
+ if (frame.event === "ping" || frame.data === "") continue;
102
+ yield {
103
+ ...JSON.parse(frame.data),
104
+ ...id === void 0 ? {} : { id }
105
+ };
106
+ }
107
+ } catch (error) {
108
+ if (!query.reconnect || query.signal?.aborted === true || isFinalRefusal(error)) throw error;
109
+ failed = error;
110
+ }
111
+ if (!query.reconnect || query.signal?.aborted === true) return;
112
+ attempt += 1;
113
+ await retryDelay(attempt);
114
+ const signal = query.signal;
115
+ if (signal !== void 0 && signal.aborted) return;
116
+ if (failed === null) attempt = 1;
74
117
  }
75
118
  }
76
119
  return {
@@ -90,26 +133,27 @@ async function toError(response) {
90
133
  return new HomeHostedError(typeof record.message === "string" ? record.message : typeof record.error === "string" ? record.error : `request failed with ${response.status}`, response.status, typeof record.code === "string" ? record.code : "HTTP_ERROR", record.detail);
91
134
  }
92
135
  /**
93
- * Cancels the body when the consumer stops reading early.
94
- *
95
- * `releaseLock()` alone does not: it drops our handle on the stream while the connection stays open,
96
- * so a `for await (const frame of hh.events())` that `break`s after one frame left the request running
97
- * — the panel kept a subscriber slot, and a Node script could not exit because the socket kept the
98
- * event loop alive. Measured against a real listener: `1 of 1` connections still open after leaving
99
- * the loop, and a plain-process run stayed awake until `process.exit()`.
100
- *
101
- * `cancel()` is a no-op once the stream has ended on its own, so this is safe on the normal path too.
136
+ * Cancels the body when the consumer stops reading early: `releaseLock()` alone leaves the
137
+ * connection open and keeps a Node process alive.
102
138
  */
103
139
  async function cancelBody(reader) {
104
140
  try {
105
141
  await reader.cancel();
106
142
  } catch {}
107
143
  }
108
- /** Parses a `text/event-stream` body into `{ event, data }` frames (the subset the panel sends). */
144
+ /**
145
+ * Parses a `text/event-stream` body into `{ event, data }` frames (the subset the panel sends).
146
+ *
147
+ * `id` is the frame's `id:` line — the panel-wide sequence — and it is on every frame the panel
148
+ * sends. A consumer that keeps the last one can hand it back as `events({ since })` to resume. It is
149
+ * **absent**, not `null`, on a frame that carried no `id:` line, so a body without one yields the
150
+ * same objects it always did.
151
+ */
109
152
  async function* readEventStream(body) {
110
153
  const decoder = new TextDecoder();
111
154
  let buffer = "";
112
155
  let event = "message";
156
+ let id = null;
113
157
  let data = [];
114
158
  const reader = body.getReader();
115
159
  try {
@@ -124,11 +168,14 @@ async function* readEventStream(body) {
124
168
  if (line === "") {
125
169
  if (data.length > 0) yield {
126
170
  event,
127
- data: data.join("\n")
171
+ data: data.join("\n"),
172
+ ...id === null ? {} : { id }
128
173
  };
129
174
  event = "message";
175
+ id = null;
130
176
  data = [];
131
177
  } else if (line.startsWith("event:")) event = line.slice(6).trim();
178
+ else if (line.startsWith("id:")) id = line.slice(3).replace(/^ /, "");
132
179
  else if (line.startsWith("data:")) data.push(line.slice(5).replace(/^ /, ""));
133
180
  newline = buffer.indexOf("\n");
134
181
  }
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":[],"sources":["../src/shared/server-url.ts","../src/client.ts"],"sourcesContent":["/**\n * The address a *browser* should open for a server entry.\n *\n * The panel builds `ServerView.url` from its own view of the network: for a `lan` bind that is this\n * machine's LAN address (`displayHost` → `lanAddress`). Someone who reached the panel over a public\n * hostname or a tunnel — `http://box.example:4999` — has no route to `192.168.1.20:4991`, so every\n * \"open server\" link was dead for exactly the users the bind was opened for. Only the browser knows\n * the name that reached the panel, so the swap happens here, in the one module both UIs read.\n *\n * The entry's own address is kept unless the swap is *provably* right:\n *\n * - a `lan` bind (`0.0.0.0`) listens on every interface, so whatever name reached the panel also\n * reaches the entry, on the entry's own port;\n * - any other bind is reachable at that address and nowhere else. A specific IP must be kept, and\n * rewriting a loopback entry would turn \"not reachable from here\" into a link to the panel;\n * - and if the page itself is loopback the viewer is on this machine, where the LAN address is\n * already the right answer.\n *\n * The scheme and the entry's port are never touched: a server port is plain HTTP whatever the panel\n * is served over, and the port belongs to the entry.\n */\n\n/** The fields this reads off a `ServerView`; narrowed so a test needs no whole view. */\nexport interface ServerLinkSource {\n /** The panel-computed address, or `null` when the entry has no port. */\n url: string | null\n /** The address the entry actually binds: `127.0.0.1` for `local`, `0.0.0.0` for `lan`, else the IP. */\n bindHost: string\n}\n\n/** True for a name a browser resolves to this machine: `localhost`, `127.0.0.0/8`, `::1`. */\nexport function isLoopbackHost(host: string): boolean {\n const name = host.trim().toLowerCase()\n if (name === 'localhost' || name === '::1' || name === '[::1]')\n return true\n if (name.endsWith('.localhost'))\n return true\n return /^127(?:\\.\\d{1,3}){3}$/.test(name)\n}\n\n/**\n * `url`, with this machine's own address replaced by the hostname the page was reached at — but only\n * when the entry listens on every interface and the viewer is not already on this machine. Anything\n * it must not rewrite comes back unchanged, and so does a `url` it cannot parse: a reachable address\n * is better than a link pointing at nothing.\n */\nexport function browserServerUrl(server: ServerLinkSource, pageHost: string): string | null {\n const { url, bindHost } = server\n // An empty host means no location to read (a non-DOM render), which is \"cannot tell\", not \"local\".\n const host = pageHost.trim()\n if (url === null || bindHost.trim() !== '0.0.0.0' || host === '' || isLoopbackHost(host))\n return url\n\n try {\n const parsed = new URL(url)\n // `location.hostname` brackets an IPv6 literal already; a bare one needs brackets to parse.\n const authority = host.includes(':') && !host.startsWith('[') ? `[${host}]` : host\n const port = parsed.port.length > 0 ? `:${parsed.port}` : ''\n const path = parsed.pathname === '/' ? '' : parsed.pathname\n return `${parsed.protocol}//${authority}${port}${path}${parsed.search}${parsed.hash}`\n }\n catch {\n return url\n }\n}\n\n/**\n * The hostname this page was reached at, or `''` where there is no location (a test, or a render that\n * never reaches a browser). Read through a narrowed `globalThis` so this module keeps the server\n * package's non-DOM type surface — it is compiled by both `tsconfig`s.\n */\nexport function pageHostname(): string {\n const location = (globalThis as { location?: { hostname?: string } }).location\n return location?.hostname ?? ''\n}\n","/**\n * `home-hosted/client` — a typed client for building your own tools on the panel's API.\n *\n * ```ts\n * import { createClient } from 'home-hosted/client'\n *\n * const hh = createClient({ baseUrl: 'http://127.0.0.1:3999', token: process.env.HH_TOKEN })\n * const { servers } = await hh.json(hh.api.servers.$get({ query: {} }))\n * for await (const frame of hh.events({ logs: false }))\n * console.log(frame.type)\n * ```\n *\n * `api` is Hono's RPC client rooted at `/api`, typed from the panel's own route table, so every path,\n * body and response is checked against the server that answers it; `rpc` is the same client at the\n * root, for `/healthz` and `/openapi`. Types only travel from the server: nothing of it is imported\n * at runtime.\n */\nimport type { AppType } from '#src/app'\nimport type { SseMessage } from '#src/shared/contracts'\nimport { hc } from 'hono/client'\nimport { isLoopbackHost } from '#src/shared/server-url'\n\nexport type { AppType } from '#src/app'\nexport type {\n ActionResultBody,\n AppState,\n ControlView,\n ServerConfig,\n ServerView,\n SseMessage,\n WorkspaceView,\n} from '#src/shared/contracts'\n\nexport interface ClientOptions {\n /** Where the panel listens, e.g. `http://127.0.0.1:3999`. */\n baseUrl: string\n /** An API token (`home-hosted set-token --generate`); omit it for a cookie session in a browser. */\n token?: string\n /** A `fetch` to use instead of the global one (tests, proxies, custom TLS). */\n fetch?: typeof fetch\n /** Extra headers on every request. */\n headers?: Record<string, string>\n /**\n * Send `token` over plain `http` to a host that is not this machine. Off by default: the token is\n * full admin, and anyone on the path could read it. Set it only for a network you trust end to end.\n */\n allowInsecureToken?: boolean\n}\n\n/** A failed request, carrying the panel's error envelope. */\nexport class HomeHostedError extends Error {\n override name = 'HomeHostedError'\n\n constructor(\n message: string,\n /** The HTTP status. */\n readonly status: number,\n /** The stable machine-readable code (`UNKNOWN_SERVER`, `AUTH_REQUIRED`, …). */\n readonly code: string,\n readonly detail?: unknown,\n ) {\n super(message)\n }\n}\n\nexport interface EventsQuery {\n /** Only this workspace's server and log frames. */\n workspace?: string\n /** Only this server's frames (pair it with `workspace`; ids are unique per workspace). */\n serverId?: string\n /** `false` drops log frames. */\n logs?: boolean\n /** Stops the stream. */\n signal?: AbortSignal\n}\n\n/** A token is sent only over https, or to this machine, unless the caller opted out. */\nfunction assertTokenTransport(baseUrl: string, options: ClientOptions): void {\n if (options.token === undefined || options.allowInsecureToken === true)\n return\n let url: URL\n try {\n url = new URL(baseUrl)\n }\n catch {\n throw new TypeError(`home-hosted/client: baseUrl \"${baseUrl}\" is not an absolute URL`)\n }\n if (url.protocol === 'https:' || isLoopbackHost(url.hostname))\n return\n throw new TypeError(`home-hosted/client: refusing to send the API token over plain http to ${url.host} — use https, a loopback address, or pass allowInsecureToken: true`)\n}\n\nexport function createClient(options: ClientOptions) {\n const baseUrl = options.baseUrl.replace(/\\/+$/, '')\n assertTokenTransport(baseUrl, options)\n const fetcher = options.fetch ?? globalThis.fetch.bind(globalThis)\n const headers = (): Record<string, string> => ({\n ...(options.token === undefined ? {} : { authorization: `Bearer ${options.token}` }),\n ...options.headers,\n })\n\n const rpc = hc<AppType>(baseUrl, { fetch: fetcher, headers })\n // Every route a client means lives under `/api`; rooting the client there keeps calls to\n // `hh.api.servers` rather than `hh.api.api.servers`.\n const api = rpc.api\n\n /** Awaits a call, returning its JSON body or throwing a `HomeHostedError`. */\n async function json<T>(call: Promise<{ ok: boolean, status: number, json: () => Promise<T> }>): Promise<T> {\n const response = await call\n if (!response.ok)\n throw await toError(response as unknown as Response)\n return await response.json()\n }\n\n /** The live feed: the first frame is always `hello` with the full state. */\n async function* events(query: EventsQuery = {}): AsyncGenerator<SseMessage> {\n const params = new URLSearchParams()\n if (query.workspace !== undefined)\n params.set('workspace', query.workspace)\n if (query.serverId !== undefined)\n params.set('serverId', query.serverId)\n if (query.logs === false)\n params.set('logs', '0')\n const suffix = params.size > 0 ? `?${params}` : ''\n const response = await fetcher(`${baseUrl}/api/events${suffix}`, {\n headers: { ...headers(), accept: 'text/event-stream' },\n signal: query.signal,\n })\n if (!response.ok || response.body === null)\n throw await toError(response)\n\n for await (const frame of readEventStream(response.body)) {\n if (frame.event === 'ping' || frame.data === '')\n continue\n yield JSON.parse(frame.data) as SseMessage\n }\n }\n\n return { api, rpc, json, events, baseUrl }\n}\n\nexport type HomeHostedClient = ReturnType<typeof createClient>\n\nasync function toError(response: Response): Promise<HomeHostedError> {\n let body: unknown = null\n try {\n body = await response.json()\n }\n catch {\n // not JSON: the status is all there is\n }\n const record = (typeof body === 'object' && body !== null ? body : {}) as Record<string, unknown>\n const message = typeof record.message === 'string'\n ? record.message\n : typeof record.error === 'string' ? record.error : `request failed with ${response.status}`\n return new HomeHostedError(message, response.status, typeof record.code === 'string' ? record.code : 'HTTP_ERROR', record.detail)\n}\n\n/**\n * Cancels the body when the consumer stops reading early.\n *\n * `releaseLock()` alone does not: it drops our handle on the stream while the connection stays open,\n * so a `for await (const frame of hh.events())` that `break`s after one frame left the request running\n * — the panel kept a subscriber slot, and a Node script could not exit because the socket kept the\n * event loop alive. Measured against a real listener: `1 of 1` connections still open after leaving\n * the loop, and a plain-process run stayed awake until `process.exit()`.\n *\n * `cancel()` is a no-op once the stream has ended on its own, so this is safe on the normal path too.\n */\nasync function cancelBody(reader: ReadableStreamDefaultReader<Uint8Array>): Promise<void> {\n try {\n await reader.cancel()\n }\n catch {\n // Already errored or gone: the connection is closed either way, which is the point.\n }\n}\n\n/** Parses a `text/event-stream` body into `{ event, data }` frames (the subset the panel sends). */\nexport async function* readEventStream(body: ReadableStream<Uint8Array>): AsyncGenerator<{ event: string, data: string }> {\n const decoder = new TextDecoder()\n let buffer = ''\n let event = 'message'\n let data: string[] = []\n const reader = body.getReader()\n try {\n for (;;) {\n const { value, done } = await reader.read()\n if (done)\n return\n buffer += decoder.decode(value, { stream: true })\n let newline = buffer.indexOf('\\n')\n while (newline !== -1) {\n const line = buffer.slice(0, newline).replace(/\\r$/, '')\n buffer = buffer.slice(newline + 1)\n if (line === '') {\n if (data.length > 0)\n yield { event, data: data.join('\\n') }\n event = 'message'\n data = []\n }\n else if (line.startsWith('event:')) {\n event = line.slice(6).trim()\n }\n else if (line.startsWith('data:')) {\n data.push(line.slice(5).replace(/^ /, ''))\n }\n newline = buffer.indexOf('\\n')\n }\n }\n }\n finally {\n await cancelBody(reader)\n reader.releaseLock()\n }\n}\n"],"mappings":";;;AA+BA,SAAgB,eAAe,MAAuB;CACpD,MAAM,OAAO,KAAK,KAAK,CAAC,CAAC,YAAY;CACrC,IAAI,SA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AAM,SAAS,KAAK,UAAU;CAC9B,IAAI;EACF,SAAS;GACP,MAAM,EAAE,OAAO,SAAS,MAAM,OAAO,KAAK;GAC1C,IAAI,MACF;GACF,UAAU,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;GAChD,IAAI,UAAU,OAAO,QAAQ,IAAI;GACjC,OAAO,YAAY,IAAI;IACrB,MAAM,OAAO,OAAO,MAAM,GAAG,OAAO,CAAC,CAAC,QAAQ,OAAO,EAAE;IACvD,SAAS,OAAO,MAAM,UAAU,CAAC;IACjC,IAAI,SAAS,IAAI;KACf,IAAI,KAAK,SAAS,GAChB,MAAM;MAAE;MAAO,MAAM,KAAK,KAAK,IAAI;KAAE;KACvC,QAAQ;KACR,OAAO,CAAC;IACV,OACK,IAAI,KAAK,WAAW,QAAQ,GAC/B,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK;SAExB,IAAI,KAAK,WAAW,OAAO,GAC9B,KAAK,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,MAAM,EAAE,CAAC;IAE3C,UAAU,OAAO,QAAQ,IAAI;GAC/B;EACF;CACF,UACQ;EACN,MAAM,WAAW,MAAM;EACvB,OAAO,YAAY;CACrB;AACF"}
1
+ {"version":3,"file":"client.js","names":[],"sources":["../src/shared/server-url.ts","../src/client.ts"],"sourcesContent":["/**\n * The address a *browser* should open for a server entry. `ServerView.url` names this machine's LAN\n * address, which a viewer on a public hostname cannot reach; only a `0.0.0.0` bind is rewritten to\n * the name the page was reached at (it listens on every interface). Scheme and port are never touched.\n */\n\n/** The fields this reads off a `ServerView`; narrowed so a test needs no whole view. */\nexport interface ServerLinkSource {\n /** `null` when the entry has no port. */\n url: string | null\n /** The address the entry actually binds: `127.0.0.1` for `local`, `0.0.0.0` for `lan`, else the IP. */\n bindHost: string\n}\n\n/**\n * True for `localhost`, `127.0.0.0/8`, `::1` and the IPv4-mapped IPv6 loopback spellings `URL`\n * normalises to (`[::ffff:7f00:1]`). Unlike `exposure.ts`'s `isLoopbackAddress`, `0.0.0.0`/`::` are not local.\n */\nexport function isLoopbackHost(host: string): boolean {\n const name = host.trim().toLowerCase()\n if (name === 'localhost' || name === '::1' || name === '[::1]')\n return true\n if (name.endsWith('.localhost'))\n return true\n // Node's `URL` gives the bracketless form to `client.ts`'s caller but brackets inside `hostname`.\n const bare = name.startsWith('[') && name.endsWith(']') ? name.slice(1, -1) : name\n // Dotted, hextet and fully expanded IPv4-mapped forms.\n if (/^::ffff:127(?:\\.\\d{1,3}){3}$/.test(bare))\n return true\n if (/^::ffff:(?:0:)?7f[0-9a-f]{2}:[0-9a-f]{1,4}$/.test(bare))\n return true\n if (/^(?:0{1,4}:){5}ffff:7f[0-9a-f]{2}:[0-9a-f]{1,4}$/.test(bare))\n return true\n return /^127(?:\\.\\d{1,3}){3}$/.test(bare)\n}\n\n/** `url` with the host swapped for `pageHost` when provably right; anything else comes back unchanged. */\nexport function browserServerUrl(server: ServerLinkSource, pageHost: string): string | null {\n const { url, bindHost } = server\n // An empty host means no location to read (a non-DOM render), which is \"cannot tell\", not \"local\".\n const host = pageHost.trim()\n if (url === null || bindHost.trim() !== '0.0.0.0' || host === '' || isLoopbackHost(host))\n return url\n\n try {\n const parsed = new URL(url)\n // `location.hostname` brackets an IPv6 literal already; a bare one needs brackets to parse.\n const authority = host.includes(':') && !host.startsWith('[') ? `[${host}]` : host\n const port = parsed.port.length > 0 ? `:${parsed.port}` : ''\n const path = parsed.pathname === '/' ? '' : parsed.pathname\n return `${parsed.protocol}//${authority}${port}${path}${parsed.search}${parsed.hash}`\n }\n catch {\n return url\n }\n}\n\n/** The page's hostname, or `''` with no location. Narrowed `globalThis` keeps the non-DOM type surface. */\nexport function pageHostname(): string {\n const location = (globalThis as { location?: { hostname?: string } }).location\n return location?.hostname ?? ''\n}\n","/**\n * `home-hosted/client` — a typed client for building your own tools on the panel's API.\n *\n * ```ts\n * import { createClient } from 'home-hosted/client'\n *\n * const hh = createClient({ baseUrl: 'http://127.0.0.1:3999', token: process.env.HH_TOKEN })\n * const { servers } = await hh.json(hh.api.servers.$get({ query: {} }))\n * for await (const frame of hh.events({ logs: false }))\n * console.log(frame.type)\n * ```\n *\n * `api` is Hono's RPC client rooted at `/api`, typed from the panel's own route table, so every path,\n * body and response is checked against the server that answers it; `rpc` is the same client at the\n * root, for `/healthz` and `/openapi`. Types only travel from the server: nothing of it is imported\n * at runtime.\n */\nimport type { AppType } from '#src/app'\nimport type { SseMessage } from '#src/shared/contracts'\nimport { hc } from 'hono/client'\nimport { isLoopbackHost } from '#src/shared/server-url'\n\nexport type { AppType } from '#src/app'\nexport type {\n ActionResultBody,\n AppState,\n ControlView,\n ServerConfig,\n ServerView,\n SseMessage,\n WorkspaceView,\n} from '#src/shared/contracts'\n\nexport interface ClientOptions {\n /** Where the panel listens, e.g. `http://127.0.0.1:3999`. */\n baseUrl: string\n /** `<id>:<secret>` from `home-hosted account create`; omit it for a cookie session in a browser. */\n token?: string\n /** A `fetch` to use instead of the global one (tests, proxies, custom TLS). */\n fetch?: typeof fetch\n /** The wait before the `n`-th reconnect attempt, replacing the built-in backoff. */\n retryDelayMs?: (attempt: number) => Promise<void>\n /** Extra headers on every request. */\n headers?: Record<string, string>\n /**\n * Send `token` over plain `http` to a host that is not this machine. Off by default: the token is\n * full admin, and anyone on the path could read it. Set it only for a network you trust end to end.\n */\n allowInsecureToken?: boolean\n}\n\n/** A failed request, carrying the panel's error envelope. */\nexport class HomeHostedError extends Error {\n override name = 'HomeHostedError'\n\n constructor(\n message: string,\n /** The HTTP status. */\n readonly status: number,\n /** The stable machine-readable code (`UNKNOWN_SERVER`, `AUTH_REQUIRED`, …). */\n readonly code: string,\n readonly detail?: unknown,\n ) {\n super(message)\n }\n}\n\nexport interface EventsQuery {\n /** Only this workspace's server and log frames. */\n workspace?: string\n /** Only this server's frames (pair it with `workspace`; ids are unique per workspace). */\n serverId?: string\n /** `false` drops log frames. */\n logs?: boolean\n /**\n * Resume after this sequence — the `id:` of the last frame already consumed.\n *\n * The stream answers with one current snapshot first, then the buffered `log` frames published\n * after it, so a reconnecting reader neither misses lines nor re-applies a stale snapshot. The\n * `id` of each frame is on the `id:` line; `readEventStream` exposes it as `lastId`.\n */\n since?: number\n /** Stops the stream. */\n signal?: AbortSignal\n /**\n * Keep the feed alive across a dropped connection, resuming from the last delivered `id` with\n * exponential backoff. Off by default, so a one-shot reader ends when it stops reading. A `4xx`\n * (a refused credential, an unknown workspace, a bad query) is thrown, never retried — except `408`/`429`.\n */\n reconnect?: boolean\n}\n\n/** 250 ms doubling, capped at 30 s. */\nfunction defaultRetryDelay(attempt: number): Promise<void> {\n const ms = Math.min(250 * 2 ** Math.max(0, attempt - 1), 30_000)\n return new Promise<void>((resolve) => {\n const timer = setTimeout(resolve, ms)\n // A pending reconnect must not be the reason a one-shot script cannot exit.\n timer.unref?.()\n })\n}\n\n/** A refusal no retry can fix: any `4xx` but a timeout (`408`) or a throttle (`429`). */\nfunction isFinalRefusal(error: unknown): boolean {\n return error instanceof HomeHostedError\n && error.status >= 400 && error.status < 500\n && error.status !== 408 && error.status !== 429\n}\n\n/** A token is sent only over https, or to this machine, unless the caller opted out. */\nfunction assertTokenTransport(baseUrl: string, options: ClientOptions): void {\n if (options.token === undefined || options.allowInsecureToken === true)\n return\n let url: URL\n try {\n url = new URL(baseUrl)\n }\n catch {\n throw new TypeError(`home-hosted/client: baseUrl \"${baseUrl}\" is not an absolute URL`)\n }\n if (url.protocol === 'https:' || isLoopbackHost(url.hostname))\n return\n throw new TypeError(`home-hosted/client: refusing to send the API token over plain http to ${url.host} — use https, a loopback address, or pass allowInsecureToken: true`)\n}\n\nexport function createClient(options: ClientOptions) {\n const baseUrl = options.baseUrl.replace(/\\/+$/, '')\n assertTokenTransport(baseUrl, options)\n const fetcher = options.fetch ?? globalThis.fetch.bind(globalThis)\n const retryDelay = options.retryDelayMs ?? defaultRetryDelay\n const headers = (): Record<string, string> => ({\n ...(options.token === undefined ? {} : { authorization: `Bearer ${options.token}` }),\n ...options.headers,\n })\n\n const rpc = hc<AppType>(baseUrl, { fetch: fetcher, headers })\n // Rooted at `/api`, so calls read `hh.api.servers`.\n const api = rpc.api\n\n /** Awaits a call, returning its JSON body or throwing a `HomeHostedError`. */\n async function json<T>(call: Promise<{ ok: boolean, status: number, json: () => Promise<T> }>): Promise<T> {\n const response = await call\n if (!response.ok)\n throw await toError(response as unknown as Response)\n return await response.json()\n }\n\n /** The live feed: the first frame is always `hello` with the full state. */\n async function* events(query: EventsQuery = {}): AsyncGenerator<ClientStreamFrame> {\n const base = (since: number | undefined): string => {\n const params = new URLSearchParams()\n if (query.workspace !== undefined)\n params.set('workspace', query.workspace)\n if (query.serverId !== undefined)\n params.set('serverId', query.serverId)\n if (query.logs === false)\n params.set('logs', '0')\n if (since !== undefined)\n params.set('since', String(since))\n return params.size > 0 ? `?${params}` : ''\n }\n\n // The last `id:` the consumer actually received, never a skipped `ping`.\n let resumeFrom = query.since\n let attempt = 0\n for (;;) {\n let failed: unknown = null\n try {\n const response = await fetcher(`${baseUrl}/api/events${base(resumeFrom)}`, {\n headers: { ...headers(), accept: 'text/event-stream' },\n signal: query.signal,\n })\n if (!response.ok || response.body === null)\n throw await toError(response)\n\n for await (const frame of readEventStream(response.body)) {\n const id = frame.id !== undefined && /^\\d+$/.test(frame.id) ? Number(frame.id) : undefined\n if (id !== undefined)\n resumeFrom = id\n if (frame.event === 'ping' || frame.data === '')\n continue\n // The `id` travels beside the payload, which is the wire frame.\n yield { ...(JSON.parse(frame.data) as SseMessage), ...(id === undefined ? {} : { id }) }\n }\n }\n catch (error) {\n if (!query.reconnect || query.signal?.aborted === true || isFinalRefusal(error))\n throw error\n failed = error\n }\n if (!query.reconnect || query.signal?.aborted === true)\n return\n attempt += 1\n await retryDelay(attempt)\n // Re-check the abort after the wait, so a caller that gave up during the backoff gets no retry.\n const signal = query.signal\n if (signal !== undefined && signal.aborted)\n return\n // A connection that delivered frames was healthy; a later drop starts the backoff over.\n if (failed === null)\n attempt = 1\n }\n }\n\n return { api, rpc, json, events, baseUrl }\n}\n\nexport type HomeHostedClient = ReturnType<typeof createClient>\n\n/**\n * One frame as `events()` delivers it: the wire message, plus the sequence number the stream assigned\n * it (`id`), which is what a later `events({ since })` resumes from. `id` is absent on a frame the\n * panel sent without one (an older panel, which has no resumable stream at all).\n */\nexport type ClientStreamFrame = SseMessage & { id?: number }\n\nasync function toError(response: Response): Promise<HomeHostedError> {\n let body: unknown = null\n try {\n body = await response.json()\n }\n catch {\n // not JSON: the status is all there is\n }\n const record = (typeof body === 'object' && body !== null ? body : {}) as Record<string, unknown>\n const message = typeof record.message === 'string'\n ? record.message\n : typeof record.error === 'string' ? record.error : `request failed with ${response.status}`\n return new HomeHostedError(message, response.status, typeof record.code === 'string' ? record.code : 'HTTP_ERROR', record.detail)\n}\n\n/**\n * Cancels the body when the consumer stops reading early: `releaseLock()` alone leaves the\n * connection open and keeps a Node process alive.\n */\nasync function cancelBody(reader: ReadableStreamDefaultReader<Uint8Array>): Promise<void> {\n try {\n await reader.cancel()\n }\n catch {\n // Already errored or gone: the connection is closed either way, which is the point.\n }\n}\n\n/**\n * Parses a `text/event-stream` body into `{ event, data }` frames (the subset the panel sends).\n *\n * `id` is the frame's `id:` line — the panel-wide sequence — and it is on every frame the panel\n * sends. A consumer that keeps the last one can hand it back as `events({ since })` to resume. It is\n * **absent**, not `null`, on a frame that carried no `id:` line, so a body without one yields the\n * same objects it always did.\n */\nexport async function* readEventStream(body: ReadableStream<Uint8Array>): AsyncGenerator<{ event: string, data: string, id?: string }> {\n const decoder = new TextDecoder()\n let buffer = ''\n let event = 'message'\n let id: string | null = null\n let data: string[] = []\n const reader = body.getReader()\n try {\n for (;;) {\n const { value, done } = await reader.read()\n if (done)\n return\n buffer += decoder.decode(value, { stream: true })\n let newline = buffer.indexOf('\\n')\n while (newline !== -1) {\n const line = buffer.slice(0, newline).replace(/\\r$/, '')\n buffer = buffer.slice(newline + 1)\n if (line === '') {\n if (data.length > 0)\n yield { event, data: data.join('\\n'), ...(id === null ? {} : { id }) }\n event = 'message'\n id = null\n data = []\n }\n else if (line.startsWith('event:')) {\n event = line.slice(6).trim()\n }\n else if (line.startsWith('id:')) {\n // The SSE grammar strips one leading space after the colon.\n id = line.slice(3).replace(/^ /, '')\n }\n else if (line.startsWith('data:')) {\n data.push(line.slice(5).replace(/^ /, ''))\n }\n newline = buffer.indexOf('\\n')\n }\n }\n }\n finally {\n await cancelBody(reader)\n reader.releaseLock()\n }\n}\n"],"mappings":";;;;;;AAkBA,SAAgB,eAAe,MAAuB;CACpD,MAAM,OAAO,KAAK,KAAK,CAAC,CAAC,YAAY;CACrC,IAAI,SAAS,eAAe,SAAS,SAAS,SAAS,SACrD,OAAO;CACT,IAAI,KAAK,SAAS,YAAY,GAC5B,OAAO;CAET,MAAM,OAAO,KAAK,WAAW,GAAG,KAAK,KAAK,SAAS,GAAG,IAAI,KAAK,MAAM,GAAG,EAAE,IAAI;CAE9E,IAAI,+BAA+B,KAAK,IAAI,GAC1C,OAAO;CACT,IAAI,8CAA8C,KAAK,IAAI,GACzD,OAAO;CACT,IAAI,mDAAmD,KAAK,IAAI,GAC9D,OAAO;CACT,OAAO,wBAAwB,KAAK,IAAI;AAC1C;;;;ACkBA,IAAa,kBAAb,cAAqC,MAAM;CAM9B;CAEA;CACA;CARX,OAAgB;CAEhB,YACE,SAEA,QAEA,MACA,QACA;EACA,MAAM,OAAO;EALJ,KAAA,SAAA;EAEA,KAAA,OAAA;EACA,KAAA,SAAA;CAGX;AACF;;AA4BA,SAAS,kBAAkB,SAAgC;CACzD,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,KAAK,IAAI,GAAG,UAAU,CAAC,GAAG,GAAM;CAC/D,OAAO,IAAI,SAAe,YAAY;EAGpC,WAFyB,SAAS,EAElC,CAAA,CAAM,QAAQ;CAChB,CAAC;AACH;;AAGA,SAAS,eAAe,OAAyB;CAC/C,OAAO,iBAAiB,mBACnB,MAAM,UAAU,OAAO,MAAM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AAO,GAC9B,KAAK,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,MAAM,EAAE,CAAC;IAE3C,UAAU,OAAO,QAAQ,IAAI;GAC/B;EACF;CACF,UACQ;EACN,MAAM,WAAW,MAAM;EACvB,OAAO,YAAY;CACrB;AACF"}
@@ -1,12 +1,8 @@
1
1
  import type { AppDeps } from '../app.js';
2
2
  /**
3
- * The ACMEProxy endpoint the reverse-proxy engine calls for a DNS-01 challenge.
4
- *
5
- * Deliberately outside `/api` — the engine is not a session — and outside `/_hh`,
6
- * which carries the panel's own local token. Two things guard it: only a loopback
7
- * peer is answered, and the engine must present the Basic credentials the panel
8
- * generated for it. The engine never holds DNS credentials; this endpoint writes
9
- * the record through the workspace account a route names.
3
+ * The ACMEProxy endpoint the reverse-proxy engine calls for a DNS-01 challenge. Outside `/api` and
4
+ * `/_hh`; answered only to a loopback peer presenting the Basic credentials the panel generated.
5
+ * The engine never holds DNS credentials.
10
6
  */
11
7
  export declare function createAcmeChallengeRoute(deps: AppDeps): import("hono/hono-base").HonoBase<import("hono").Env, {
12
8
  "/:action": {