home-hosted 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +319 -628
- package/dist/chunks/archive-DP-XQR8X.js +352 -0
- package/dist/chunks/archive-DP-XQR8X.js.map +1 -0
- package/dist/chunks/atomic-C1PfJpE7.js +26 -0
- package/dist/chunks/atomic-C1PfJpE7.js.map +1 -0
- package/dist/chunks/backup-CZcVca2a.js +822 -0
- package/dist/chunks/backup-CZcVca2a.js.map +1 -0
- package/dist/chunks/backups-CFRaWe_m.js +4691 -0
- package/dist/chunks/backups-CFRaWe_m.js.map +1 -0
- package/dist/chunks/config-text-DifCHhnz.js +50 -0
- package/dist/chunks/config-text-DifCHhnz.js.map +1 -0
- package/dist/chunks/contracts-CMBD1TF9.js +2230 -0
- package/dist/chunks/contracts-CMBD1TF9.js.map +1 -0
- package/dist/chunks/daemon-log-BVj8cDEo.js +241 -0
- package/dist/chunks/daemon-log-BVj8cDEo.js.map +1 -0
- package/dist/chunks/daemon-qKVECISl.js +247 -0
- package/dist/chunks/daemon-qKVECISl.js.map +1 -0
- package/dist/chunks/docker-Cy9Lyvda.js +437 -0
- package/dist/chunks/docker-Cy9Lyvda.js.map +1 -0
- package/dist/chunks/down-pKbGCW9d.js +383 -0
- package/dist/chunks/down-pKbGCW9d.js.map +1 -0
- package/dist/chunks/init-BZ7hK9Vf.js +276 -0
- package/dist/chunks/init-BZ7hK9Vf.js.map +1 -0
- package/dist/chunks/last-stop-C-BXz_XI.js +53 -0
- package/dist/chunks/last-stop-C-BXz_XI.js.map +1 -0
- package/dist/chunks/layout-DwTtmund.js +24 -0
- package/dist/chunks/layout-DwTtmund.js.map +1 -0
- package/dist/chunks/lazy-Ce5zEAq1.js +66 -0
- package/dist/chunks/lazy-Ce5zEAq1.js.map +1 -0
- package/dist/chunks/log-buffer-Dy9HHDMD.js +414 -0
- package/dist/chunks/log-buffer-Dy9HHDMD.js.map +1 -0
- package/dist/chunks/logger-B5U4GD3j.js +13 -0
- package/dist/chunks/logger-B5U4GD3j.js.map +1 -0
- package/dist/chunks/logs---TI_bxM.js +267 -0
- package/dist/chunks/logs---TI_bxM.js.map +1 -0
- package/dist/chunks/migrate-Cfoq-Vgh.js +155 -0
- package/dist/chunks/migrate-Cfoq-Vgh.js.map +1 -0
- package/dist/chunks/nanny-B-Eu0sFW.js +132 -0
- package/dist/chunks/nanny-B-Eu0sFW.js.map +1 -0
- package/dist/chunks/nanny-BtWfy0QH.js +1167 -0
- package/dist/chunks/nanny-BtWfy0QH.js.map +1 -0
- package/dist/chunks/nanny-ChMtq1Zl.js +39 -0
- package/dist/chunks/nanny-ChMtq1Zl.js.map +1 -0
- package/dist/chunks/nanny-sweep-DErnlPY1.js +105 -0
- package/dist/chunks/nanny-sweep-DErnlPY1.js.map +1 -0
- package/dist/chunks/nearest-6KgQEDUe.js +41 -0
- package/dist/chunks/nearest-6KgQEDUe.js.map +1 -0
- package/dist/chunks/parse-DhmG26fI.js +383 -0
- package/dist/chunks/parse-DhmG26fI.js.map +1 -0
- package/dist/chunks/paths-CGlGDrOU.js +206 -0
- package/dist/chunks/paths-CGlGDrOU.js.map +1 -0
- package/dist/chunks/port-B8WBTRMk.js +333 -0
- package/dist/chunks/port-B8WBTRMk.js.map +1 -0
- package/dist/chunks/restart-Des4DrAN.js +92 -0
- package/dist/chunks/restart-Des4DrAN.js.map +1 -0
- package/dist/chunks/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/chunks/schema-B240VXcV.js +103 -0
- package/dist/chunks/schema-B240VXcV.js.map +1 -0
- package/dist/chunks/secrets-BieELnZh.js +562 -0
- package/dist/chunks/secrets-BieELnZh.js.map +1 -0
- package/dist/chunks/server-Bge2r2qQ.js +169 -0
- package/dist/chunks/server-Bge2r2qQ.js.map +1 -0
- package/dist/chunks/server-ids-DRuNLVCV.js +32 -0
- package/dist/chunks/server-ids-DRuNLVCV.js.map +1 -0
- package/dist/chunks/set-password-D5vZqqSX.js +43 -0
- package/dist/chunks/set-password-D5vZqqSX.js.map +1 -0
- package/dist/chunks/set-token-obPiEJYk.js +78 -0
- package/dist/chunks/set-token-obPiEJYk.js.map +1 -0
- package/dist/chunks/settings-xu-XTfWg.js +423 -0
- package/dist/chunks/settings-xu-XTfWg.js.map +1 -0
- package/dist/chunks/setup-temp-CAN4_bA-.js +150 -0
- package/dist/chunks/setup-temp-CAN4_bA-.js.map +1 -0
- package/dist/chunks/shape-DnTKzjQ2.js +24 -0
- package/dist/chunks/shape-DnTKzjQ2.js.map +1 -0
- package/dist/chunks/src-BtWMFmzZ.js +12338 -0
- package/dist/chunks/src-BtWMFmzZ.js.map +1 -0
- package/dist/chunks/status-DT1EsA-B.js +123 -0
- package/dist/chunks/status-DT1EsA-B.js.map +1 -0
- package/dist/chunks/ui-D562aqw5.js +325 -0
- package/dist/chunks/ui-D562aqw5.js.map +1 -0
- package/dist/chunks/ui-dir-CsU3uLNV.js +39 -0
- package/dist/chunks/ui-dir-CsU3uLNV.js.map +1 -0
- package/dist/chunks/ui-release-DKzVvlLd.js +312 -0
- package/dist/chunks/ui-release-DKzVvlLd.js.map +1 -0
- package/dist/chunks/ui-revert-EkBBwRTt.js +27 -0
- package/dist/chunks/ui-revert-EkBBwRTt.js.map +1 -0
- package/dist/chunks/ui-switch-BnZTdMDd.js +150 -0
- package/dist/chunks/ui-switch-BnZTdMDd.js.map +1 -0
- package/dist/chunks/ui-update-_xryLYxw.js +272 -0
- package/dist/chunks/ui-update-_xryLYxw.js.map +1 -0
- package/dist/chunks/up-Pdz-l6IH.js +210 -0
- package/dist/chunks/up-Pdz-l6IH.js.map +1 -0
- package/dist/chunks/usage-DFrCVXpT.js +111 -0
- package/dist/chunks/usage-DFrCVXpT.js.map +1 -0
- package/dist/chunks/workspaces-DYcfvKV_.js +229 -0
- package/dist/chunks/workspaces-DYcfvKV_.js.map +1 -0
- package/dist/chunks/wsl-temperature-BiCI4iK6.js +322 -0
- package/dist/chunks/wsl-temperature-BiCI4iK6.js.map +1 -0
- package/dist/cli.js +441 -25418
- package/dist/cli.js.map +1 -1
- package/dist/client.js +144 -0
- package/dist/client.js.map +1 -0
- package/dist/types/api/acme.d.ts +24 -0
- package/dist/types/api/auth/$.routes.d.ts +103 -0
- package/dist/types/api/backups.d.ts +184 -0
- package/dist/types/api/control.d.ts +470 -0
- package/dist/types/api/ddns.d.ts +432 -0
- package/dist/types/api/events.d.ts +22 -0
- package/dist/types/api/health.d.ts +28 -0
- package/dist/types/api/logs.d.ts +95 -0
- package/dist/types/api/metrics.d.ts +21 -0
- package/dist/types/api/notifications.d.ts +141 -0
- package/dist/types/api/proxy.d.ts +1128 -0
- package/dist/types/api/servers/$.routes.d.ts +1318 -0
- package/dist/types/api/settings.d.ts +642 -0
- package/dist/types/api/state.d.ts +498 -0
- package/dist/types/api/static.d.ts +11 -0
- package/dist/types/api/tls.d.ts +112 -0
- package/dist/types/api/workspaces/$.routes.d.ts +797 -0
- package/dist/types/api/wsl-temperature.d.ts +113 -0
- package/dist/types/app.d.ts +6095 -0
- package/dist/types/cli/args.d.ts +75 -0
- package/dist/types/cli/backup-offline.d.ts +23 -0
- package/dist/types/cli/backup.d.ts +86 -0
- package/dist/types/cli/down.d.ts +80 -0
- package/dist/types/cli/init.d.ts +60 -0
- package/dist/types/cli/io.d.ts +65 -0
- package/dist/types/cli/logs.d.ts +76 -0
- package/dist/types/cli/migrate.d.ts +33 -0
- package/dist/types/cli/nanny.d.ts +19 -0
- package/dist/types/cli/nearest.d.ts +10 -0
- package/dist/types/cli/restart.d.ts +41 -0
- package/dist/types/cli/server.d.ts +68 -0
- package/dist/types/cli/set-password.d.ts +14 -0
- package/dist/types/cli/set-token.d.ts +21 -0
- package/dist/types/cli/setup-temp.d.ts +65 -0
- package/dist/types/cli/status.d.ts +14 -0
- package/dist/types/cli/ui-revert.d.ts +3 -0
- package/dist/types/cli/ui-switch.d.ts +27 -0
- package/dist/types/cli/ui-update.d.ts +72 -0
- package/dist/types/cli/up.d.ts +96 -0
- package/dist/types/cli/usage.d.ts +23 -0
- package/dist/types/cli.d.ts +12 -0
- package/dist/types/client.d.ts +11891 -0
- package/dist/types/config/layout.d.ts +11 -0
- package/dist/types/config/migrations.d.ts +69 -0
- package/dist/types/config/parse.d.ts +54 -0
- package/dist/types/config/patch.d.ts +20 -0
- package/dist/types/config/schema.d.ts +318 -0
- package/dist/types/config/secret-parts.d.ts +48 -0
- package/dist/types/config/secrets.d.ts +208 -0
- package/dist/types/config/seed.d.ts +30 -0
- package/dist/types/config/server-ids.d.ts +14 -0
- package/dist/types/config/settings.d.ts +120 -0
- package/dist/types/config/store.d.ts +145 -0
- package/dist/types/config/workspaces.d.ts +99 -0
- package/dist/types/helpers/action-result.d.ts +46 -0
- package/dist/types/helpers/atomic.d.ts +9 -0
- package/dist/types/helpers/backoff.d.ts +7 -0
- package/dist/types/helpers/bind.d.ts +16 -0
- package/dist/types/helpers/config-text.d.ts +23 -0
- package/dist/types/helpers/cookies.d.ts +19 -0
- package/dist/types/helpers/copy-tree.d.ts +20 -0
- package/dist/types/helpers/daemon-log.d.ts +45 -0
- package/dist/types/helpers/daemon.d.ts +135 -0
- package/dist/types/helpers/deferred.d.ts +7 -0
- package/dist/types/helpers/env-file.d.ts +20 -0
- package/dist/types/helpers/error.d.ts +26 -0
- package/dist/types/helpers/event-stream.d.ts +21 -0
- package/dist/types/helpers/factory.d.ts +6 -0
- package/dist/types/helpers/last-stop.d.ts +20 -0
- package/dist/types/helpers/logger.d.ts +7 -0
- package/dist/types/helpers/open.d.ts +2 -0
- package/dist/types/helpers/openapi.d.ts +34 -0
- package/dist/types/helpers/paths.d.ts +112 -0
- package/dist/types/helpers/restore-lock.d.ts +32 -0
- package/dist/types/helpers/runtime.d.ts +18 -0
- package/dist/types/helpers/secret-compare.d.ts +13 -0
- package/dist/types/helpers/shell.d.ts +19 -0
- package/dist/types/helpers/sse.d.ts +23 -0
- package/dist/types/helpers/template.d.ts +8 -0
- package/dist/types/helpers/ui-dir.d.ts +11 -0
- package/dist/types/helpers/utf8-chunks.d.ts +15 -0
- package/dist/types/helpers/validate.d.ts +7 -0
- package/dist/types/helpers/validator.d.ts +12 -0
- package/dist/types/helpers/version.d.ts +10 -0
- package/dist/types/helpers/workspace.d.ts +25 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/middleware/auth.d.ts +53 -0
- package/dist/types/middleware/host.d.ts +29 -0
- package/dist/types/middleware/loopback.d.ts +18 -0
- package/dist/types/openapi-reference.d.ts +22 -0
- package/dist/types/openapi.d.ts +34 -0
- package/dist/types/providers/archive.d.ts +54 -0
- package/dist/types/providers/backup-hook.d.ts +34 -0
- package/dist/types/providers/ddns/cloudflare.d.ts +2 -0
- package/dist/types/providers/ddns/desec.d.ts +2 -0
- package/dist/types/providers/ddns/digitalocean.d.ts +2 -0
- package/dist/types/providers/ddns/duckdns.d.ts +2 -0
- package/dist/types/providers/ddns/dyndns2.d.ts +15 -0
- package/dist/types/providers/ddns/dynu.d.ts +2 -0
- package/dist/types/providers/ddns/freedns.d.ts +2 -0
- package/dist/types/providers/ddns/gandi.d.ts +2 -0
- package/dist/types/providers/ddns/godaddy.d.ts +2 -0
- package/dist/types/providers/ddns/henet.d.ts +3 -0
- package/dist/types/providers/ddns/index.d.ts +12 -0
- package/dist/types/providers/ddns/ip.d.ts +27 -0
- package/dist/types/providers/ddns/namecheap-api.d.ts +13 -0
- package/dist/types/providers/ddns/namecheap.d.ts +6 -0
- package/dist/types/providers/ddns/noip.d.ts +2 -0
- package/dist/types/providers/ddns/porkbun.d.ts +2 -0
- package/dist/types/providers/ddns/spaceship.d.ts +7 -0
- package/dist/types/providers/ddns/types.d.ts +98 -0
- package/dist/types/providers/ddns/zone.d.ts +11 -0
- package/dist/types/providers/docker.d.ts +117 -0
- package/dist/types/providers/entry-state.d.ts +15 -0
- package/dist/types/providers/health-check.d.ts +27 -0
- package/dist/types/providers/host.d.ts +147 -0
- package/dist/types/providers/identity.d.ts +54 -0
- package/dist/types/providers/log-tail.d.ts +56 -0
- package/dist/types/providers/nanny-sweep.d.ts +54 -0
- package/dist/types/providers/nanny.d.ts +104 -0
- package/dist/types/providers/port.d.ts +142 -0
- package/dist/types/providers/proc.d.ts +125 -0
- package/dist/types/providers/process.d.ts +78 -0
- package/dist/types/providers/proxy/caddy.d.ts +2 -0
- package/dist/types/providers/proxy/index.d.ts +7 -0
- package/dist/types/providers/proxy/types.d.ts +54 -0
- package/dist/types/providers/server-vars.d.ts +4 -0
- package/dist/types/providers/telegram.d.ts +74 -0
- package/dist/types/providers/ui-release.d.ts +113 -0
- package/dist/types/providers/webhook.d.ts +64 -0
- package/dist/types/providers/wsl-temperature.d.ts +65 -0
- package/dist/types/services/acme-challenge.d.ts +44 -0
- package/dist/types/services/auth.d.ts +177 -0
- package/dist/types/services/backups.d.ts +476 -0
- package/dist/types/services/config-watch.d.ts +40 -0
- package/dist/types/services/control-server.d.ts +58 -0
- package/dist/types/services/ddns.d.ts +72 -0
- package/dist/types/services/dependencies.d.ts +21 -0
- package/dist/types/services/events.d.ts +17 -0
- package/dist/types/services/exposure.d.ts +86 -0
- package/dist/types/services/history.d.ts +37 -0
- package/dist/types/services/host-monitor.d.ts +33 -0
- package/dist/types/services/init.d.ts +71 -0
- package/dist/types/services/log-buffer.d.ts +39 -0
- package/dist/types/services/log-files.d.ts +77 -0
- package/dist/types/services/log-relay.d.ts +35 -0
- package/dist/types/services/nanny.d.ts +14 -0
- package/dist/types/services/notifications.d.ts +124 -0
- package/dist/types/services/panel.d.ts +213 -0
- package/dist/types/services/proxy-certificates/certificates.d.ts +116 -0
- package/dist/types/services/proxy-config.d.ts +83 -0
- package/dist/types/services/proxy.d.ts +431 -0
- package/dist/types/services/state.d.ts +38 -0
- package/dist/types/services/supervisor/compose.d.ts +17 -0
- package/dist/types/services/supervisor/entry.d.ts +149 -0
- package/dist/types/services/supervisor/health.d.ts +56 -0
- package/dist/types/services/supervisor/output.d.ts +126 -0
- package/dist/types/services/supervisor/pending-load.d.ts +6 -0
- package/dist/types/services/supervisor/persistent.d.ts +58 -0
- package/dist/types/services/supervisor/port-preflight.d.ts +45 -0
- package/dist/types/services/supervisor/records.d.ts +118 -0
- package/dist/types/services/supervisor/spawn.d.ts +15 -0
- package/dist/types/services/supervisor/view.d.ts +4 -0
- package/dist/types/services/supervisor.d.ts +145 -0
- package/dist/types/services/tls.d.ts +48 -0
- package/dist/types/services/ui-update.d.ts +44 -0
- package/dist/types/services/ui.d.ts +50 -0
- package/dist/types/shared/action-outcome.d.ts +25 -0
- package/dist/types/shared/api-client.d.ts +351 -0
- package/dist/types/shared/backup-scope.d.ts +167 -0
- package/dist/types/shared/clone.d.ts +14 -0
- package/dist/types/shared/contracts.d.ts +4175 -0
- package/dist/types/shared/cpu-scale.d.ts +25 -0
- package/dist/types/shared/ddns-form.d.ts +75 -0
- package/dist/types/shared/endpoint.d.ts +8 -0
- package/dist/types/shared/error-message.d.ts +8 -0
- package/dist/types/shared/fields.d.ts +21 -0
- package/dist/types/shared/form-repair.d.ts +6 -0
- package/dist/types/shared/generated.d.ts +26 -0
- package/dist/types/shared/host-readings.d.ts +185 -0
- package/dist/types/shared/lazy.d.ts +4 -0
- package/dist/types/shared/live-frames.d.ts +22 -0
- package/dist/types/shared/live-series.d.ts +21 -0
- package/dist/types/shared/live-store.d.ts +72 -0
- package/dist/types/shared/patch-diff.d.ts +105 -0
- package/dist/types/shared/probe-latency.d.ts +25 -0
- package/dist/types/shared/proxy-form.d.ts +184 -0
- package/dist/types/shared/server-attention.d.ts +37 -0
- package/dist/types/shared/server-form.d.ts +121 -0
- package/dist/types/shared/server-key.d.ts +13 -0
- package/dist/types/shared/server-readings.d.ts +55 -0
- package/dist/types/shared/server-url.d.ts +43 -0
- package/dist/types/shared/shape.d.ts +17 -0
- package/dist/types/shared/stream-access.d.ts +20 -0
- package/dist/types/shared/ui-format.d.ts +89 -0
- package/docs/API.md +209 -0
- package/docs/BACKUPS.md +117 -0
- package/docs/CLI.md +95 -0
- package/docs/DDNS.md +11 -1
- package/docs/NOTIFICATIONS.md +7 -1
- package/docs/REVERSE_PROXY.md +9 -3
- package/docs/SECURITY.md +93 -0
- package/docs/SERVERS.md +141 -34
- package/docs/UI_CREATION.md +91 -291
- package/docs/demo/blank-host-restore.sh +4 -3
- package/package.json +22 -14
- package/uis/stock/dist/assets/CopyButton-BUBKRJyY.js +1 -0
- package/uis/stock/dist/assets/GlobalSettingsView-yYMcRWvt.js +1 -0
- package/uis/stock/dist/assets/LogViewer-DIliXy62.js +1 -0
- package/uis/stock/dist/assets/LogsView-B7Z-7RNg.js +1 -0
- package/uis/stock/dist/assets/Modal-DmKa5Qpp.js +39 -0
- package/uis/stock/dist/assets/ProxyView-DvZiNkwb.js +1 -0
- package/uis/stock/dist/assets/ServerDetailView-6idGT_EX.js +2 -0
- package/uis/stock/dist/assets/SettingsShell-CeGtleYI.js +1 -0
- package/uis/stock/dist/assets/SettingsView-BrhJIrmk.js +2 -0
- package/uis/stock/dist/assets/de-BRITeb0H.js +1 -0
- package/uis/stock/dist/assets/es-B2zIEssV.js +1 -0
- package/uis/stock/dist/assets/fr-s0ZOBEqh.js +1 -0
- package/uis/stock/dist/assets/index-C1MehbKy.css +2 -0
- package/uis/stock/dist/assets/index-CnBN54wF.js +15 -0
- package/uis/stock/dist/assets/ja-CU7MR85V.js +1 -0
- package/uis/stock/dist/assets/ko-tL5Me6d-.js +1 -0
- package/uis/stock/dist/assets/ru-92yrvkNJ.js +1 -0
- package/uis/stock/dist/assets/vi-CzvY16k2.js +1 -0
- package/uis/stock/dist/assets/zh-CN-DDwFW_uW.js +1 -0
- package/uis/stock/dist/index.html +3 -2
- package/uis/stock/dist/ui.json +3 -3
- package/docs/RESTORE_DEMO.md +0 -306
- package/uis/stock/dist/assets/de-0YLueNal.js +0 -1
- package/uis/stock/dist/assets/es-FCHhRmn2.js +0 -1
- package/uis/stock/dist/assets/fr-C69Z8o0z.js +0 -1
- package/uis/stock/dist/assets/index-Cok5msAO.css +0 -2
- package/uis/stock/dist/assets/index-KdyqrVv8.js +0 -53
- package/uis/stock/dist/assets/ja-Chz9YOqR.js +0 -1
- package/uis/stock/dist/assets/ko-CtXZ2x1l.js +0 -1
- package/uis/stock/dist/assets/ru-D_jE64xN.js +0 -1
- package/uis/stock/dist/assets/vi-sxSffss7.js +0 -1
- package/uis/stock/dist/assets/zh-CN-ChTpf29X.js +0 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { f as fail, h as invocation, m as green } from "../cli.js";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import { defineCommand } from "citty";
|
|
4
|
+
//#region src/cli/server.ts
|
|
5
|
+
/** The panel's answer when a port is already free — success for `start --free-port`, refused alone. */
|
|
6
|
+
var NOTHING_LISTENING = /^nothing is listening on port \d+ any more$/;
|
|
7
|
+
/**
|
|
8
|
+
* Asks the running panel to do one thing to one entry, and turns its answer into an exit code.
|
|
9
|
+
*
|
|
10
|
+
* Shared by every per-server command so the "the panel is not running", "it does not know this
|
|
11
|
+
* command" and "it refused, here is why" sentences exist once. Returns the body, so a caller can
|
|
12
|
+
* say more about what happened; a refusal never returns at all.
|
|
13
|
+
*/
|
|
14
|
+
async function callServerAction(action, id, workspace, options = {}) {
|
|
15
|
+
const { clearRuntime, readRuntime, requestControl, runtimeIsAlive, runtimeIsGone } = await import("./daemon-qKVECISl.js");
|
|
16
|
+
const runtime = readRuntime();
|
|
17
|
+
if (runtime === null || !await runtimeIsAlive(runtime)) {
|
|
18
|
+
if (runtime !== null && await runtimeIsGone(runtime)) clearRuntime();
|
|
19
|
+
fail(`home-hosted is not running — start it with \`${invocation()} up\``);
|
|
20
|
+
}
|
|
21
|
+
const query = workspace === void 0 || workspace.length === 0 ? "" : `?workspace=${encodeURIComponent(workspace)}`;
|
|
22
|
+
const answer = await requestControl(runtime, `/_hh/servers/${encodeURIComponent(id)}/${action}${query}`);
|
|
23
|
+
if (answer === null) fail(`the control panel is not answering on ${runtime.probeUrl}`);
|
|
24
|
+
const body = answer.body ?? {};
|
|
25
|
+
if (body.ok !== true) {
|
|
26
|
+
const reason = body.error ?? body.message;
|
|
27
|
+
if (options.tolerateFree === true && reason !== void 0 && NOTHING_LISTENING.test(reason)) return {
|
|
28
|
+
...body,
|
|
29
|
+
ok: true
|
|
30
|
+
};
|
|
31
|
+
if (reason !== void 0) fail(reason);
|
|
32
|
+
if (answer.status === 404) fail(`the panel on ${runtime.url} is home-hosted ${runtime.version}, which does not know this command — restart it on this release`);
|
|
33
|
+
fail(`the panel answered ${answer.status}`);
|
|
34
|
+
}
|
|
35
|
+
return body;
|
|
36
|
+
}
|
|
37
|
+
/** `workspace/id`, or `id` in the default workspace. */
|
|
38
|
+
function label(id, workspace) {
|
|
39
|
+
return workspace === void 0 ? id : `${workspace}/${id}`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* How long `start` watches the entry before it reports.
|
|
43
|
+
*
|
|
44
|
+
* `start` on the panel returns the instant the process is spawned — right for a click, wrong for a
|
|
45
|
+
* script: an entry whose command exits immediately printed "started" and exited 0, while it was
|
|
46
|
+
* already in its crash-restart loop, so `start x && curl x` raced every boot. One second covers a
|
|
47
|
+
* process that dies on startup without making a healthy start feel hung.
|
|
48
|
+
*/
|
|
49
|
+
var START_SETTLE_MS = 1e3;
|
|
50
|
+
async function runServerAction(action, id, workspace) {
|
|
51
|
+
await callServerAction(action, id, workspace);
|
|
52
|
+
if (action === "start" || action === "restart") await confirmStillRunning(id, workspace);
|
|
53
|
+
const verb = action === "start" ? "started" : action === "stop" ? "stopped" : "restarted";
|
|
54
|
+
process.stdout.write(`${green(verb)} ${label(id, workspace)}\n`);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Says so when a just-started entry is already gone.
|
|
58
|
+
*
|
|
59
|
+
* `start` answers on spawn, so a command that exits straight away is reported as started. Reading
|
|
60
|
+
* the entry back is the only honest answer, and it is a **refusal** rather than a success line: a
|
|
61
|
+
* deploy chain that continues against a dead process is the failure this exists to stop.
|
|
62
|
+
*/
|
|
63
|
+
async function confirmStillRunning(id, workspace) {
|
|
64
|
+
const { readRuntime, requestControl } = await import("./daemon-qKVECISl.js");
|
|
65
|
+
const runtime = readRuntime();
|
|
66
|
+
if (runtime === null) return;
|
|
67
|
+
await new Promise((resolve) => setTimeout(resolve, START_SETTLE_MS));
|
|
68
|
+
const query = workspace === void 0 || workspace.length === 0 ? "" : `?workspace=${encodeURIComponent(workspace)}`;
|
|
69
|
+
const answer = await requestControl(runtime, `/_hh/servers/${encodeURIComponent(id)}${query}`, 15e3, "GET");
|
|
70
|
+
if (answer === null || answer.status !== 200) return;
|
|
71
|
+
const view = answer.body ?? {};
|
|
72
|
+
if (view.status === "running" || view.status === "starting") return;
|
|
73
|
+
const why = view.lastError === null || view.lastError === void 0 || view.lastError.length === 0 ? `status is ${view.status ?? "unknown"}` : view.lastError;
|
|
74
|
+
fail(`server "${label(id, workspace)}" did not stay up — ${why}. It was spawned; check \`${invocation()} logs ${id}\``);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* `free-port` — ask whatever holds this entry's port to stop, then say what actually happened.
|
|
78
|
+
*
|
|
79
|
+
* The panel refuses what it supervises rather than signalling it, so a success is not simply
|
|
80
|
+
* "ok": the report distinguishes the pids that left, the ones that ignored SIGTERM and had to be
|
|
81
|
+
* killed, and any this panel owns that were deliberately left alone.
|
|
82
|
+
*/
|
|
83
|
+
async function runFreePort(id, workspace, options = {}) {
|
|
84
|
+
const body = await callServerAction("free-port", id, workspace, { tolerateFree: options.tolerateFree });
|
|
85
|
+
const port = body.port ?? null;
|
|
86
|
+
const where = label(id, workspace);
|
|
87
|
+
const terminated = body.terminated ?? [];
|
|
88
|
+
const forced = body.forced ?? [];
|
|
89
|
+
const skipped = body.skipped ?? [];
|
|
90
|
+
const parts = [];
|
|
91
|
+
if (terminated.length > 0) parts.push(`pid ${terminated.join(", ")} stopped`);
|
|
92
|
+
if (forced.length > 0) parts.push(`pid ${forced.join(", ")} had to be killed`);
|
|
93
|
+
if (skipped.length > 0) parts.push(`pid ${skipped.join(", ")} left alone (this panel supervises it)`);
|
|
94
|
+
const idle = terminated.length === 0 && forced.length === 0 && skipped.length === 0;
|
|
95
|
+
if (port === null || idle) {
|
|
96
|
+
process.stdout.write(`${green("port is free")} ${where}${port === null ? "" : ` on ${port}`}\n`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const detail = idle ? "nothing was listening" : parts.join("; ");
|
|
100
|
+
if (body.free === true) {
|
|
101
|
+
process.stdout.write(`${green("freed")} port ${port} for ${where} — ${detail}\n`);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
fail(`port ${port} is still in use for ${where} — ${detail}`);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* `start`, and `start --free-port`.
|
|
108
|
+
*
|
|
109
|
+
* `--free-port` frees the port first, then starts — the one sequence a person actually wants after
|
|
110
|
+
* reading "port 4010 is already in use". It is a flag on `start` rather than only a command because
|
|
111
|
+
* the two calls it saves are the common case; `free-port` on its own still exists for when the intent
|
|
112
|
+
* is only to unblock a port.
|
|
113
|
+
*/
|
|
114
|
+
function serverCommand(action) {
|
|
115
|
+
const withFreePort = action === "start";
|
|
116
|
+
return defineCommand({
|
|
117
|
+
meta: { name: action },
|
|
118
|
+
args: {
|
|
119
|
+
id: {
|
|
120
|
+
type: "positional",
|
|
121
|
+
required: false,
|
|
122
|
+
description: "the server id from the workspace's servers.config.json"
|
|
123
|
+
},
|
|
124
|
+
workspace: {
|
|
125
|
+
type: "string",
|
|
126
|
+
alias: "w",
|
|
127
|
+
description: "the workspace to act in (default: the panel's default workspace)"
|
|
128
|
+
},
|
|
129
|
+
...withFreePort ? { "free-port": {
|
|
130
|
+
type: "boolean",
|
|
131
|
+
description: "free the port first, then start (what the panel's Free port button does)"
|
|
132
|
+
} } : {}
|
|
133
|
+
},
|
|
134
|
+
run: async ({ args }) => {
|
|
135
|
+
const id = typeof args.id === "string" ? args.id.trim() : "";
|
|
136
|
+
if (id.length === 0) fail(`${action} needs a server id — see \`${invocation()} status\` or the workspace's servers.config.json`);
|
|
137
|
+
const workspace = typeof args.workspace === "string" ? args.workspace.trim() : void 0;
|
|
138
|
+
if (withFreePort && args["free-port"] === true) await runFreePort(id, workspace, { tolerateFree: true });
|
|
139
|
+
await runServerAction(action, id, workspace);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/** `free-port <id>` — the panel's Free port button, from a shell. */
|
|
144
|
+
var freePortCommand = defineCommand({
|
|
145
|
+
meta: { name: "free-port" },
|
|
146
|
+
args: {
|
|
147
|
+
id: {
|
|
148
|
+
type: "positional",
|
|
149
|
+
required: false,
|
|
150
|
+
description: "the server whose port should be freed"
|
|
151
|
+
},
|
|
152
|
+
workspace: {
|
|
153
|
+
type: "string",
|
|
154
|
+
alias: "w",
|
|
155
|
+
description: "the workspace to act in (default: the panel's default workspace)"
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
run: async ({ args }) => {
|
|
159
|
+
const id = typeof args.id === "string" ? args.id.trim() : "";
|
|
160
|
+
if (id.length === 0) fail(`free-port needs a server id — see \`${invocation()} status\` or the workspace's servers.config.json`);
|
|
161
|
+
await runFreePort(id, typeof args.workspace === "string" ? args.workspace.trim() : void 0);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
var startCommand = serverCommand("start");
|
|
165
|
+
var stopCommand = serverCommand("stop");
|
|
166
|
+
//#endregion
|
|
167
|
+
export { freePortCommand, runServerAction, startCommand, stopCommand };
|
|
168
|
+
|
|
169
|
+
//# sourceMappingURL=server-Bge2r2qQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-Bge2r2qQ.js","names":[],"sources":["../../src/cli/server.ts"],"sourcesContent":["import process from 'node:process'\nimport { defineCommand } from 'citty'\nimport { fail, green, invocation } from '#src/cli/io'\n\n/**\n * `start`/`stop`/`restart` for one supervised server.\n *\n * The supervisor lives inside the daemon, so a single server cannot be started or\n * stopped without it: these drive the running panel over its local control channel\n * (the same token `down` uses), which needs no session and no API token.\n *\n * `restart` shares the name with the panel's own restart, which is why the id is optional:\n * bare `restart` stays \"down, then up\", and `restart <id>` is one entry — the same thing the\n * UI's per-server Restart button does, which the shell could not.\n */\n\nexport type ServerAction = 'start' | 'stop' | 'restart'\n\n/** The panel's answer when a port is already free — success for `start --free-port`, refused alone. */\nconst NOTHING_LISTENING = /^nothing is listening on port \\d+ any more$/\n\ninterface ActionBody {\n ok?: boolean\n error?: string\n message?: string\n}\n\n/**\n * Asks the running panel to do one thing to one entry, and turns its answer into an exit code.\n *\n * Shared by every per-server command so the \"the panel is not running\", \"it does not know this\n * command\" and \"it refused, here is why\" sentences exist once. Returns the body, so a caller can\n * say more about what happened; a refusal never returns at all.\n */\nasync function callServerAction(action: string, id: string, workspace?: string, options: { tolerateFree?: boolean } = {}): Promise<ActionBody> {\n const { clearRuntime, readRuntime, requestControl, runtimeIsAlive, runtimeIsGone } = await import('#src/helpers/daemon')\n\n const runtime = readRuntime()\n if (runtime === null || !await runtimeIsAlive(runtime)) {\n // Only a record with nothing behind the pid is deleted — see `runtimeIsGone`.\n if (runtime !== null && await runtimeIsGone(runtime))\n clearRuntime()\n fail(`home-hosted is not running — start it with \\`${invocation()} up\\``)\n }\n\n const query = workspace === undefined || workspace.length === 0 ? '' : `?workspace=${encodeURIComponent(workspace)}`\n const answer = await requestControl(runtime, `/_hh/servers/${encodeURIComponent(id)}/${action}${query}`)\n if (answer === null)\n fail(`the control panel is not answering on ${runtime.probeUrl}`)\n\n const body = (answer.body ?? {}) as ActionBody\n if (body.ok !== true) {\n const reason = body.error ?? body.message\n // `start --free-port` wants the port free, so \"nothing is listening\" is the state it asked for;\n // for `free-port` on its own it is a refusal, because the person asked to free something.\n if (options.tolerateFree === true && reason !== undefined && NOTHING_LISTENING.test(reason))\n return { ...body, ok: true }\n if (reason !== undefined)\n fail(reason)\n // A panel from before this command answers a bare 404: say which release is running\n // rather than leaving a puzzled person staring at a status code.\n if (answer.status === 404)\n fail(`the panel on ${runtime.url} is home-hosted ${runtime.version}, which does not know this command — restart it on this release`)\n fail(`the panel answered ${answer.status}`)\n }\n return body\n}\n\n/** `workspace/id`, or `id` in the default workspace. */\nfunction label(id: string, workspace?: string): string {\n return workspace === undefined ? id : `${workspace}/${id}`\n}\n\n/**\n * How long `start` watches the entry before it reports.\n *\n * `start` on the panel returns the instant the process is spawned — right for a click, wrong for a\n * script: an entry whose command exits immediately printed \"started\" and exited 0, while it was\n * already in its crash-restart loop, so `start x && curl x` raced every boot. One second covers a\n * process that dies on startup without making a healthy start feel hung.\n */\nconst START_SETTLE_MS = 1000\n\n/** The view fields `start` reads back to decide whether the entry actually survived. */\ninterface StartedView {\n status?: string\n lastError?: string | null\n restarts?: number\n}\n\nexport async function runServerAction(action: ServerAction, id: string, workspace?: string): Promise<void> {\n await callServerAction(action, id, workspace)\n\n // Both spawn, so both are verified: `restart <id>` is the same process-start path as `start`, and\n // an entry that dies on boot reports `ok` from either one.\n if (action === 'start' || action === 'restart')\n await confirmStillRunning(id, workspace)\n\n // The past tense is the verb: `restart` says \"restarted\", not \"stopped\".\n const verb = action === 'start' ? 'started' : action === 'stop' ? 'stopped' : 'restarted'\n process.stdout.write(`${green(verb)} ${label(id, workspace)}\\n`)\n}\n\n/**\n * Says so when a just-started entry is already gone.\n *\n * `start` answers on spawn, so a command that exits straight away is reported as started. Reading\n * the entry back is the only honest answer, and it is a **refusal** rather than a success line: a\n * deploy chain that continues against a dead process is the failure this exists to stop.\n */\nasync function confirmStillRunning(id: string, workspace?: string): Promise<void> {\n const { readRuntime, requestControl } = await import('#src/helpers/daemon')\n const runtime = readRuntime()\n if (runtime === null)\n return\n\n await new Promise(resolve => setTimeout(resolve, START_SETTLE_MS))\n\n const query = workspace === undefined || workspace.length === 0 ? '' : `?workspace=${encodeURIComponent(workspace)}`\n const answer = await requestControl(runtime, `/_hh/servers/${encodeURIComponent(id)}${query}`, 15_000, 'GET')\n if (answer === null || answer.status !== 200)\n return\n\n const view = (answer.body ?? {}) as StartedView\n // `running` and `starting` are both alive; `backoff` means it exited and is waiting to retry,\n // which is the case that used to read as success.\n if (view.status === 'running' || view.status === 'starting')\n return\n\n const why = view.lastError === null || view.lastError === undefined || view.lastError.length === 0\n ? `status is ${view.status ?? 'unknown'}`\n : view.lastError\n fail(`server \"${label(id, workspace)}\" did not stay up — ${why}. It was spawned; check \\`${invocation()} logs ${id}\\``)\n}\n\n/**\n * `free-port` — ask whatever holds this entry's port to stop, then say what actually happened.\n *\n * The panel refuses what it supervises rather than signalling it, so a success is not simply\n * \"ok\": the report distinguishes the pids that left, the ones that ignored SIGTERM and had to be\n * killed, and any this panel owns that were deliberately left alone.\n */\nexport async function runFreePort(id: string, workspace?: string, options: { tolerateFree?: boolean } = {}): Promise<void> {\n const body = await callServerAction('free-port', id, workspace, { tolerateFree: options.tolerateFree }) as ActionBody & {\n port?: number | null\n terminated?: number[]\n forced?: number[]\n skipped?: number[]\n free?: boolean\n }\n\n const port = body.port ?? null\n const where = label(id, workspace)\n const terminated = body.terminated ?? []\n const forced = body.forced ?? []\n const skipped = body.skipped ?? []\n\n const parts: string[] = []\n if (terminated.length > 0)\n parts.push(`pid ${terminated.join(', ')} stopped`)\n if (forced.length > 0)\n parts.push(`pid ${forced.join(', ')} had to be killed`)\n if (skipped.length > 0)\n parts.push(`pid ${skipped.join(', ')} left alone (this panel supervises it)`)\n\n // `free: false` with nothing signalled is the panel saying \"there was nothing to free\" — either\n // the port was already idle (tolerated here, since `start --free-port` wanted exactly that) or a\n // socket survived and it refused. `free === false` also covers the tolerated answer, which is the\n // same body with `ok` flipped, so the two callers cannot drift.\n const idle = terminated.length === 0 && forced.length === 0 && skipped.length === 0\n if (port === null || idle) {\n process.stdout.write(`${green('port is free')} ${where}${port === null ? '' : ` on ${port}`}\\n`)\n return\n }\n\n const detail = idle ? 'nothing was listening' : parts.join('; ')\n if (body.free === true) {\n process.stdout.write(`${green('freed')} port ${port} for ${where} — ${detail}\\n`)\n return\n }\n // The port was taken and still is: a socket that survived SIGTERM. Exit 1, because a caller\n // scripting this needs to know the server still cannot start.\n fail(`port ${port} is still in use for ${where} — ${detail}`)\n}\n\n/**\n * `start`, and `start --free-port`.\n *\n * `--free-port` frees the port first, then starts — the one sequence a person actually wants after\n * reading \"port 4010 is already in use\". It is a flag on `start` rather than only a command because\n * the two calls it saves are the common case; `free-port` on its own still exists for when the intent\n * is only to unblock a port.\n */\nfunction serverCommand(action: ServerAction) {\n const withFreePort = action === 'start'\n return defineCommand({\n // No `description`: `cli.ts` owns the one copy (`SYNOPSIS` + `SUMMARIES`) and renders it through\n // `commandHelp`, which `main()` intercepts before citty sees `--help`. citty's own usage printer is\n // the only reader of a subcommand description here and it never runs (`runCommand`, not `runMain`),\n // so a copy in the module is unreachable text that drifts — `migrate`, `up` and `ui-update` had all\n // diverged by the time this was noticed.\n meta: {\n name: action,\n },\n args: {\n // `required: false` keeps citty's own refusal out of the way: the message below\n // names the id and where to find it.\n id: { type: 'positional', required: false, description: 'the server id from the workspace\\'s servers.config.json' },\n workspace: { type: 'string', alias: 'w', description: 'the workspace to act in (default: the panel\\'s default workspace)' },\n ...(withFreePort\n ? { 'free-port': { type: 'boolean', description: 'free the port first, then start (what the panel\\'s Free port button does)' } }\n : {}),\n },\n run: async ({ args }) => {\n const id = typeof args.id === 'string' ? args.id.trim() : ''\n if (id.length === 0)\n fail(`${action} needs a server id — see \\`${invocation()} status\\` or the workspace's servers.config.json`)\n const workspace = typeof args.workspace === 'string' ? args.workspace.trim() : undefined\n // Freeing first is not \"free port, ignore the outcome, then start\": a port that stays taken\n // makes the start fail with the same sentence, so stop here with the port's own reason.\n if (withFreePort && args['free-port'] === true)\n await runFreePort(id, workspace, { tolerateFree: true })\n await runServerAction(action, id, workspace)\n },\n })\n}\n\n/** `free-port <id>` — the panel's Free port button, from a shell. */\nexport const freePortCommand = defineCommand({\n meta: { name: 'free-port' },\n args: {\n id: { type: 'positional', required: false, description: 'the server whose port should be freed' },\n workspace: { type: 'string', alias: 'w', description: 'the workspace to act in (default: the panel\\'s default workspace)' },\n },\n run: async ({ args }) => {\n const id = typeof args.id === 'string' ? args.id.trim() : ''\n if (id.length === 0)\n fail(`free-port needs a server id — see \\`${invocation()} status\\` or the workspace's servers.config.json`)\n const workspace = typeof args.workspace === 'string' ? args.workspace.trim() : undefined\n await runFreePort(id, workspace)\n },\n})\n\nexport const startCommand = serverCommand('start')\nexport const stopCommand = serverCommand('stop')\n// `restart` is deliberately absent: bare `restart` means the *panel*, and `restart <id>` is handled by\n// `cli/restart.ts` through the same `runServerAction`. A `restartServerCommand` used to be exported\n// here — never wired into the command surface, so it read as an entry point nothing could reach.\n"],"mappings":";;;;;AAmBA,IAAM,oBAAoB;;;;;;;;AAe1B,eAAe,iBAAiB,QAAgB,IAAY,WAAoB,UAAsC,CAAC,GAAwB;CAC7I,MAAM,EAAE,cAAc,aAAa,gBAAgB,gBAAgB,kBAAkB,MAAM,OAAO;CAElG,MAAM,UAAU,YAAY;CAC5B,IAAI,YAAY,QAAQ,CAAC,MAAM,eAAe,OAAO,GAAG;EAEtD,IAAI,YAAY,QAAQ,MAAM,cAAc,OAAO,GACjD,aAAa;EACf,KAAK,gDAAgD,WAAW,EAAE,MAAM;CAC1E;CAEA,MAAM,QAAQ,cAAc,KAAA,KAAa,UAAU,WAAW,IAAI,KAAK,cAAc,mBAAmB,SAAS;CACjH,MAAM,SAAS,MAAM,eAAe,SAAS,gBAAgB,mBAAmB,EAAE,EAAE,GAAG,SAAS,OAAO;CACvG,IAAI,WAAW,MACb,KAAK,yCAAyC,QAAQ,UAAU;CAElE,MAAM,OAAQ,OAAO,QAAQ,CAAC;CAC9B,IAAI,KAAK,OAAO,MAAM;EACpB,MAAM,SAAS,KAAK,SAAS,KAAK;EAGlC,IAAI,QAAQ,iBAAiB,QAAQ,WAAW,KAAA,KAAa,kBAAkB,KAAK,MAAM,GACxF,OAAO;GAA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
+
import { t as isRecord } from "./shape-DnTKzjQ2.js";
|
|
3
|
+
//#region src/config/server-ids.ts
|
|
4
|
+
/**
|
|
5
|
+
* The server ids a workspace's `servers.config.json` declares — or `null` when the file cannot
|
|
6
|
+
* answer, which is a different fact from "it declares none".
|
|
7
|
+
*
|
|
8
|
+
* Read-only and tolerant on purpose. `WorkspaceStore.load()` *seeds* a missing file, so a
|
|
9
|
+
* diagnostic command that reached for it would write to the state root it was only reading; and a
|
|
10
|
+
* config this release cannot parse must not turn a log lookup into a refusal. Both of those
|
|
11
|
+
* collapse to `null`, and every caller then answers as it did before, because "I cannot tell"
|
|
12
|
+
* is not "there is no such entry".
|
|
13
|
+
*
|
|
14
|
+
* The entries are not validated against `serverSchema`: this answers which *files* may exist
|
|
15
|
+
* (`<id>.log`), and an entry with a bad field still writes a log under its own id.
|
|
16
|
+
*/
|
|
17
|
+
function readDeclaredServerIds(file) {
|
|
18
|
+
let parsed;
|
|
19
|
+
try {
|
|
20
|
+
parsed = JSON.parse(readStateFile(file));
|
|
21
|
+
} catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
if (!isRecord(parsed) || !Array.isArray(parsed.servers)) return null;
|
|
25
|
+
const ids = [];
|
|
26
|
+
for (const entry of parsed.servers) if (isRecord(entry) && typeof entry.id === "string" && entry.id.length > 0) ids.push(entry.id);
|
|
27
|
+
return ids;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { readDeclaredServerIds };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=server-ids-DRuNLVCV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-ids-DRuNLVCV.js","names":[],"sources":["../../src/config/server-ids.ts"],"sourcesContent":["import { readStateFile } from '#src/helpers/config-text'\nimport { isRecord } from '#src/shared/shape'\n\n/**\n * The server ids a workspace's `servers.config.json` declares — or `null` when the file cannot\n * answer, which is a different fact from \"it declares none\".\n *\n * Read-only and tolerant on purpose. `WorkspaceStore.load()` *seeds* a missing file, so a\n * diagnostic command that reached for it would write to the state root it was only reading; and a\n * config this release cannot parse must not turn a log lookup into a refusal. Both of those\n * collapse to `null`, and every caller then answers as it did before, because \"I cannot tell\"\n * is not \"there is no such entry\".\n *\n * The entries are not validated against `serverSchema`: this answers which *files* may exist\n * (`<id>.log`), and an entry with a bad field still writes a log under its own id.\n */\nexport function readDeclaredServerIds(file: string): string[] | null {\n let parsed: unknown\n try {\n parsed = JSON.parse(readStateFile(file))\n }\n catch {\n // Missing or not JSON: nothing to decide from.\n return null\n }\n if (!isRecord(parsed) || !Array.isArray(parsed.servers))\n return null\n\n const ids: string[] = []\n for (const entry of parsed.servers) {\n if (isRecord(entry) && typeof entry.id === 'string' && entry.id.length > 0)\n ids.push(entry.id)\n }\n return ids\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,sBAAsB,MAA+B;CACnE,IAAI;CACJ,IAAI;EACF,SAAS,KAAK,MAAM,cAAc,IAAI,CAAC;CACzC,QACM;EAEJ,OAAO;CACT;CACA,IAAI,CAAC,SAAS,MAAM,KAAK,CAAC,MAAM,QAAQ,OAAO,OAAO,GACpD,OAAO;CAET,MAAM,MAAgB,CAAC;CACvB,KAAK,MAAM,SAAS,OAAO,SACzB,IAAI,SAAS,KAAK,KAAK,OAAO,MAAM,OAAO,YAAY,MAAM,GAAG,SAAS,GACvE,IAAI,KAAK,MAAM,EAAE;CAErB,OAAO;AACT"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { d as dim, f as fail, h as invocation, m as green, v as promptHidden } from "../cli.js";
|
|
2
|
+
import { a as globalSecretsPath } from "./paths-CGlGDrOU.js";
|
|
3
|
+
import { n as SecretsStore } from "./secrets-BieELnZh.js";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { defineCommand } from "citty";
|
|
6
|
+
//#region src/cli/set-password.ts
|
|
7
|
+
/** `set-password` sets the panel password without the API. */
|
|
8
|
+
var setPasswordArgs = { clear: {
|
|
9
|
+
type: "boolean",
|
|
10
|
+
description: "remove the password: nobody can sign in until a new one is set"
|
|
11
|
+
} };
|
|
12
|
+
async function runSetPassword(clear) {
|
|
13
|
+
const store = new SecretsStore(globalSecretsPath, void 0, "global");
|
|
14
|
+
if (clear) {
|
|
15
|
+
store.clearPassword();
|
|
16
|
+
process.stdout.write(`cleared the control panel password in ${globalSecretsPath}\n`);
|
|
17
|
+
process.stdout.write(`${dim(`nobody can sign in until a new one is set (\`${invocation()} set-password\`); until then only this machine and an API token reach the panel`)}\n`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const interactive = process.stdin.isTTY === true;
|
|
21
|
+
let password = process.env.HHOSTED_PASSWORD;
|
|
22
|
+
if (password === void 0 && interactive) {
|
|
23
|
+
password = await promptHidden("New control panel password: ");
|
|
24
|
+
const again = await promptHidden("Repeat it: ");
|
|
25
|
+
if (password !== again) fail("the passwords do not match");
|
|
26
|
+
}
|
|
27
|
+
if (password === void 0 || password.length === 0) fail("no password given: run interactively, or set HHOSTED_PASSWORD for a non-interactive run");
|
|
28
|
+
store.setPassword(password);
|
|
29
|
+
process.stdout.write(`${green("password stored")} in ${globalSecretsPath} (mode 0600)\n`);
|
|
30
|
+
if (password.length < 8) process.stdout.write(`${dim(`${password.length} characters is short — easy to guess if the panel is reachable beyond loopback`)}\n`);
|
|
31
|
+
process.stdout.write(`${dim("a running panel picks it up immediately, and every existing browser session is signed out")}\n`);
|
|
32
|
+
}
|
|
33
|
+
var setPasswordCommand = defineCommand({
|
|
34
|
+
meta: { name: "set-password" },
|
|
35
|
+
args: setPasswordArgs,
|
|
36
|
+
run: async ({ args }) => {
|
|
37
|
+
await runSetPassword(args.clear === true);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
//#endregion
|
|
41
|
+
export { setPasswordCommand };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=set-password-D5vZqqSX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-password-D5vZqqSX.js","names":["secretsPath"],"sources":["../../src/cli/set-password.ts"],"sourcesContent":["import process from 'node:process'\nimport { defineCommand } from 'citty'\nimport { dim, fail, green, invocation, promptHidden } from '#src/cli/io'\nimport { SecretsStore } from '#src/config/secrets'\nimport { globalSecretsPath as secretsPath } from '#src/helpers/paths'\n\n/** `set-password` sets the panel password without the API. */\n\nexport const setPasswordArgs = {\n clear: { type: 'boolean', description: 'remove the password: nobody can sign in until a new one is set' },\n} as const\n\nexport async function runSetPassword(clear: boolean): Promise<void> {\n const store = new SecretsStore(secretsPath, undefined, 'global')\n\n if (clear) {\n store.clearPassword()\n // Authentication stays enabled: with no password nobody can sign in, and only this machine (or\n // an API token) reaches the API until a new one is set. It used to say auth was disabled.\n process.stdout.write(`cleared the control panel password in ${secretsPath}\\n`)\n process.stdout.write(`${dim(`nobody can sign in until a new one is set (\\`${invocation()} set-password\\`); until then only this machine and an API token reach the panel`)}\\n`)\n return\n }\n\n const interactive = process.stdin.isTTY === true\n let password = process.env.HHOSTED_PASSWORD\n\n if (password === undefined && interactive) {\n password = await promptHidden('New control panel password: ')\n const again = await promptHidden('Repeat it: ')\n if (password !== again)\n fail('the passwords do not match')\n }\n\n if (password === undefined || password.length === 0) {\n fail('no password given: run interactively, or set HHOSTED_PASSWORD for a non-interactive run')\n }\n\n store.setPassword(password)\n process.stdout.write(`${green('password stored')} in ${secretsPath} (mode 0600)\\n`)\n if (password.length < 8)\n process.stdout.write(`${dim(`${password.length} characters is short — easy to guess if the panel is reachable beyond loopback`)}\\n`)\n process.stdout.write(`${dim('a running panel picks it up immediately, and every existing browser session is signed out')}\\n`)\n}\n\nexport const setPasswordCommand = defineCommand({\n meta: { name: 'set-password' },\n args: setPasswordArgs,\n run: async ({ args }) => {\n await runSetPassword(args.clear === true)\n },\n})\n"],"mappings":";;;;;;;AAQA,IAAa,kBAAkB,EAC7B,OAAO;CAAE,MAAM;CAAW,aAAa;AAAiE,EAC1G;AAEA,eAAsB,eAAe,OAA+B;CAClE,MAAM,QAAQ,IAAI,aAAaA,mBAAa,KAAA,GAAW,QAAQ;CAE/D,IAAI,OAAO;EACT,MAAM,cAAc;EAGpB,QAAQ,OAAO,MAAM,yCAAyCA,kBAAY,GAAG;EAC7E,QAAQ,OAAO,MAAM,GAAG,IAAI,gDAAgD,WAAW,EAAE,gFAAgF,EAAE,GAAG;EAC9K;CACF;CAEA,MAAM,cAAc,QAAQ,MAAM,UAAU;CAC5C,IAAI,WAAW,QAAQ,IAAI;CAE3B,IAAI,aAAa,KAAA,KAAa,aAAa;EACzC,WAAW,MAAM,aAAa,8BAA8B;EAC5D,MAAM,QAAQ,MAAM,aAAa,aAAa;EAC9C,IAAI,aAAa,OACf,KAAK,4BAA4B;CACrC;CAEA,IAAI,aAAa,KAAA,KAAa,SAAS,WAAW,GAChD,KAAK,yFAAyF;CAGhG,MAAM,YAAY,QAAQ;CAC1B,QAAQ,OAAO,MAAM,GAAG,MAAM,iBAAiB,EAAE,MAAMA,kBAAY,eAAe;CAClF,IAAI,SAAS,SAAS,GACpB,QAAQ,OAAO,MAAM,GAAG,IAAI,GAAG,SAAS,OAAO,+EAA+E,EAAE,GAAG;CACrI,QAAQ,OAAO,MAAM,GAAG,IAAI,2FAA2F,EAAE,GAAG;AAC9H;AAEA,IAAa,qBAAqB,cAAc;CAC9C,MAAM,EAAE,MAAM,eAAe;CAC7B,MAAM;CACN,KAAK,OAAO,EAAE,WAAW;EACvB,MAAM,eAAe,KAAK,UAAU,IAAI;CAC1C;AACF,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { c as bold, d as dim, f as fail, h as invocation, m as green, v as promptHidden } from "../cli.js";
|
|
2
|
+
import { a as globalSecretsPath } from "./paths-CGlGDrOU.js";
|
|
3
|
+
import { n as SecretsStore, r as generateApiToken } from "./secrets-BieELnZh.js";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { defineCommand } from "citty";
|
|
6
|
+
//#region src/cli/set-token.ts
|
|
7
|
+
/** `set-token` sets the bearer credential scripts and agents use. */
|
|
8
|
+
var DEFAULT_PORT = 3999;
|
|
9
|
+
var setTokenArgs = {
|
|
10
|
+
generate: {
|
|
11
|
+
type: "boolean",
|
|
12
|
+
description: "create a strong token and print it once"
|
|
13
|
+
},
|
|
14
|
+
clear: {
|
|
15
|
+
type: "boolean",
|
|
16
|
+
description: "remove the token, so it stops working"
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
async function runSetToken(generate, clear) {
|
|
20
|
+
if (generate && clear) fail("use either --generate or --clear, not both");
|
|
21
|
+
const store = new SecretsStore(globalSecretsPath, void 0, "global");
|
|
22
|
+
if (clear) {
|
|
23
|
+
if (!store.apiTokenSet) {
|
|
24
|
+
process.stdout.write("no API token is set — nothing to clear\n");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
store.clearApiToken();
|
|
28
|
+
process.stdout.write(`${green("API token cleared")} in ${globalSecretsPath} — it stops working immediately\n`);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let token = process.env.HHOSTED_TOKEN ?? null;
|
|
32
|
+
if (generate) token = generateApiToken();
|
|
33
|
+
else if (token === null && process.stdin.isTTY === true) token = await promptHidden("API token: ");
|
|
34
|
+
if (token !== null) token = token.trim();
|
|
35
|
+
if (token === null || token.length === 0) fail(`no token given: run \`${invocation()} set-token --generate\`, set HHOSTED_TOKEN, or paste one interactively`);
|
|
36
|
+
store.setApiToken(token);
|
|
37
|
+
process.stdout.write(`${green(generate ? "token generated" : "token stored")} in ${globalSecretsPath} (mode 0600)\n`);
|
|
38
|
+
if (generate) {
|
|
39
|
+
process.stdout.write(` ${bold(token)}\n`);
|
|
40
|
+
process.stdout.write(`${dim(" shown once — only its SHA-256 is kept on disk, so copy it now")}\n`);
|
|
41
|
+
} else process.stdout.write(`${dim(` stored as ${token.slice(0, 8)}… — the file keeps only its hash`)}\n`);
|
|
42
|
+
const { readRuntime } = await import("./daemon-qKVECISl.js");
|
|
43
|
+
const runtime = readRuntime();
|
|
44
|
+
const base = (runtime?.url ?? `http://127.0.0.1:${DEFAULT_PORT}`).replace(/\/+$/, "");
|
|
45
|
+
if (runtime !== null) {
|
|
46
|
+
const verified = await verifyToken(base, token);
|
|
47
|
+
if (verified === true) process.stdout.write(`${dim(`verified: ${base}/api/auth/session accepted it`)}\n`);
|
|
48
|
+
else if (verified === false) process.stdout.write(`${dim(`the panel at ${base} did not accept it — is it running with this state directory?`)}\n`);
|
|
49
|
+
}
|
|
50
|
+
process.stdout.write(`Use it from a script or an agent:\n`);
|
|
51
|
+
process.stdout.write(` ${bold(`curl -H "Authorization: Bearer ${generate ? token : "<token>"}" ${base}/api/state`)}\n`);
|
|
52
|
+
process.stdout.write(`${dim("It needs no restart and outlives sessions, and it holds the same access as a signed-in browser — except clearing the panel password, which a token may not do.")}\n`);
|
|
53
|
+
process.stdout.write(`${dim("Changing the password does NOT revoke it: `set-password` drops sessions and leaves the token working. Rotate with this command if it may have leaked.")}\n`);
|
|
54
|
+
process.stdout.write(`${dim(`Remove it any time with: ${invocation()} set-token --clear`)}\n`);
|
|
55
|
+
if (store.usingDefaultPassword) process.stdout.write(`${dim("The panel password is still the default — change it before the panel is reachable beyond loopback.")}\n`);
|
|
56
|
+
}
|
|
57
|
+
/** Asks the live panel whether it accepts the token, without failing when it cannot. */
|
|
58
|
+
async function verifyToken(base, token) {
|
|
59
|
+
if (!base.startsWith("http://")) return null;
|
|
60
|
+
try {
|
|
61
|
+
const response = await fetch(`${base}/api/auth/session`, { headers: { authorization: `Bearer ${token}` } });
|
|
62
|
+
if (!response.ok) return false;
|
|
63
|
+
return (await response.json()).authenticated === true;
|
|
64
|
+
} catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
var setTokenCommand = defineCommand({
|
|
69
|
+
meta: { name: "set-token" },
|
|
70
|
+
args: setTokenArgs,
|
|
71
|
+
run: async ({ args }) => {
|
|
72
|
+
await runSetToken(args.generate === true, args.clear === true);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
//#endregion
|
|
76
|
+
export { setTokenCommand };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=set-token-obPiEJYk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-token-obPiEJYk.js","names":["secretsPath"],"sources":["../../src/cli/set-token.ts"],"sourcesContent":["import process from 'node:process'\nimport { defineCommand } from 'citty'\nimport { bold, dim, fail, green, invocation, promptHidden } from '#src/cli/io'\nimport { generateApiToken, SecretsStore } from '#src/config/secrets'\nimport { globalSecretsPath as secretsPath } from '#src/helpers/paths'\n\n/** `set-token` sets the bearer credential scripts and agents use. */\n\nconst DEFAULT_PORT = 3999\n\nexport const setTokenArgs = {\n generate: { type: 'boolean', description: 'create a strong token and print it once' },\n clear: { type: 'boolean', description: 'remove the token, so it stops working' },\n} as const\n\nexport async function runSetToken(generate: boolean, clear: boolean): Promise<void> {\n if (generate && clear)\n fail('use either --generate or --clear, not both')\n\n const store = new SecretsStore(secretsPath, undefined, 'global')\n\n if (clear) {\n if (!store.apiTokenSet) {\n process.stdout.write('no API token is set — nothing to clear\\n')\n return\n }\n store.clearApiToken()\n process.stdout.write(`${green('API token cleared')} in ${secretsPath} — it stops working immediately\\n`)\n return\n }\n\n let token: string | null = process.env.HHOSTED_TOKEN ?? null\n if (generate)\n token = generateApiToken()\n else if (token === null && process.stdin.isTTY === true)\n token = await promptHidden('API token: ')\n if (token !== null)\n token = token.trim()\n if (token === null || token.length === 0) {\n fail(`no token given: run \\`${invocation()} set-token --generate\\`, set HHOSTED_TOKEN, or paste one interactively`)\n }\n\n store.setApiToken(token)\n process.stdout.write(`${green(generate ? 'token generated' : 'token stored')} in ${secretsPath} (mode 0600)\\n`)\n if (generate) {\n process.stdout.write(` ${bold(token)}\\n`)\n process.stdout.write(`${dim(' shown once — only its SHA-256 is kept on disk, so copy it now')}\\n`)\n }\n else {\n process.stdout.write(`${dim(` stored as ${token.slice(0, 8)}… — the file keeps only its hash`)}\\n`)\n }\n\n const { readRuntime } = await import('#src/helpers/daemon')\n // Only the panel that owns *this* state directory is worth asking: guessing a\n // port would probe someone else's panel and call the mismatch a failure.\n const runtime = readRuntime()\n const base = (runtime?.url ?? `http://127.0.0.1:${DEFAULT_PORT}`).replace(/\\/+$/, '')\n\n if (runtime !== null) {\n const verified = await verifyToken(base, token)\n if (verified === true)\n process.stdout.write(`${dim(`verified: ${base}/api/auth/session accepted it`)}\\n`)\n else if (verified === false)\n process.stdout.write(`${dim(`the panel at ${base} did not accept it — is it running with this state directory?`)}\\n`)\n }\n\n process.stdout.write(`Use it from a script or an agent:\\n`)\n process.stdout.write(` ${bold(`curl -H \"Authorization: Bearer ${generate ? token : '<token>'}\" ${base}/api/state`)}\\n`)\n process.stdout.write(`${dim('It needs no restart and outlives sessions, and it holds the same access as a signed-in browser — except clearing the panel password, which a token may not do.')}\\n`)\n process.stdout.write(`${dim('Changing the password does NOT revoke it: `set-password` drops sessions and leaves the token working. Rotate with this command if it may have leaked.')}\\n`)\n process.stdout.write(`${dim(`Remove it any time with: ${invocation()} set-token --clear`)}\\n`)\n if (store.usingDefaultPassword)\n process.stdout.write(`${dim('The panel password is still the default — change it before the panel is reachable beyond loopback.')}\\n`)\n}\n\n/** Asks the live panel whether it accepts the token, without failing when it cannot. */\nasync function verifyToken(base: string, token: string): Promise<boolean | null> {\n // An https endpoint is usually TLS this project generated itself, which a plain\n // fetch refuses; the liveness probe in `helpers/daemon` is the one that knows how.\n if (!base.startsWith('http://'))\n return null\n try {\n const response = await fetch(`${base}/api/auth/session`, { headers: { authorization: `Bearer ${token}` } })\n if (!response.ok)\n return false\n const body = await response.json() as { authenticated?: boolean }\n return body.authenticated === true\n }\n catch {\n return null\n }\n}\n\nexport const setTokenCommand = defineCommand({\n meta: { name: 'set-token' },\n args: setTokenArgs,\n run: async ({ args }) => {\n await runSetToken(args.generate === true, args.clear === true)\n },\n})\n"],"mappings":";;;;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