home-hosted 0.10.1 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -320,7 +320,7 @@ can be told what to be: *"Help me build a UI for home-hosted: nostalgic game the
320
320
  | 🔗 **Ordered startup** | `dependsOn` waits for a dependency to be *healthy* — not merely spawned. `stop-all`/`down` stop dependents before their dependencies; stopping one server names the dependents it leaves running. [SERVERS.md](./docs/SERVERS.md#field-reference) |
321
321
  | 📜 **Logs** | Live per-server stream, buffer plus rotated files on disk, search, filter to one stream, download, one click to clear. `Keep rotated files` in **Workspace Settings** bounds the directory, and the search reads every rotation it keeps — lowering it deletes the extras. |
322
322
  | 📈 **Resources** | CPU and RSS per process tree — the summed containers for a compose entry — with an optional memory ceiling that restarts the entry. Stopping a compose entry stops its containers even when the wrapper is gone, and says so if one survives. [SERVERS.md](./docs/SERVERS.md#docker-and-compose) |
323
- | 🌡️ **Host vitals** | CPU usage, memory, swap, disk and CPU temperature, plus the load average as a per-cpu count, with thresholds that notify once and again on recovery. Where the OS exposes no sensor — a WSL2 guest above all — the tile says `n/a`; [set a temperature command](./docs/SERVERS.md#cpu-temperature-where-the-os-exposes-none) to supply the reading (the guide includes a WSL2 setup). |
323
+ | 🌡️ **Host vitals** | CPU usage, memory, swap, disk and CPU temperature, plus the load average as a per-cpu count, with thresholds that notify once and again on recovery. Where the OS exposes no sensor — a WSL2 guest above all — the tile says `n/a`; [`setup-temp --wsl`](./docs/SERVERS.md#cpu-temperature-where-the-os-exposes-none) bridges to the Windows host. |
324
324
  | 🤖 **Token API** | Scripts and agents drive it with `Authorization: Bearer` — no browser, no session. [↑](#-agents-scripts-and-tools) |
325
325
  | 🔔 **Notifications** | Telegram and webhooks (ntfy, Discord, Slack, anything) on crash, unhealthy, recovery, host thresholds and DNS changes. Toggles and throttle set once; each destination inherits or overrides. [Setup](./docs/NOTIFICATIONS.md). |
326
326
  | 🌐 **Dynamic DNS** | Keep hostnames pointed at your public IP — Cloudflare, Namecheap, Spaceship, Porkbun, GoDaddy, Gandi and more. [DDNS.md](./docs/DDNS.md) |
package/dist/cli.js CHANGED
@@ -13,7 +13,7 @@ import { LogLevels, createConsola } from "consola";
13
13
  import { isDevelopment } from "std-env";
14
14
  import { DetailedError } from "@namesmt/utils";
15
15
  import { type } from "arktype";
16
- import crypto, { X509Certificate, createPrivateKey, createPublicKey, randomBytes } from "node:crypto";
16
+ import crypto, { X509Certificate, createHash, createPrivateKey, createPublicKey, randomBytes } from "node:crypto";
17
17
  import { Readable, Writable } from "node:stream";
18
18
  import { bodyLimit } from "hono/body-limit";
19
19
  import { streamSSE } from "hono/streaming";
@@ -12984,14 +12984,52 @@ var init_$_routes = __esmMin((() => {
12984
12984
  //#endregion
12985
12985
  //#region src/providers/wsl-temperature.ts
12986
12986
  var wsl_temperature_exports = /* @__PURE__ */ __exportAll({
12987
+ LHM_RELEASE: () => LHM_RELEASE,
12988
+ LHM_SUBDIR: () => LHM_SUBDIR,
12989
+ installLibreHardwareMonitor: () => installLibreHardwareMonitor,
12987
12990
  isWsl: () => isWsl,
12991
+ lhmDirectory: () => lhmDirectory,
12992
+ lhmDirectoryWindows: () => lhmDirectoryWindows,
12993
+ lhmInstalled: () => lhmInstalled,
12988
12994
  probeWslTemperature: () => probeWslTemperature,
12989
12995
  tempCommandFor: () => tempCommandFor,
12996
+ tempCommandForWindows: () => tempCommandForWindows,
12997
+ toGuestPath: () => toGuestPath,
12990
12998
  windowsScriptPath: () => windowsScriptPath,
12991
12999
  writeWslTemperatureScript: () => writeWslTemperatureScript,
12992
13000
  wslScriptPath: () => wslScriptPath,
13001
+ wslScriptPathWindows: () => wslScriptPathWindows,
12993
13002
  wslTemperatureStatus: () => wslTemperatureStatus
12994
13003
  });
13004
+ /** The install directory in Windows terms, read from the environment (the system drive may not be `C:`). */
13005
+ function lhmDirectoryWindows() {
13006
+ try {
13007
+ const base = execFileSync("powershell.exe", [
13008
+ "-NoProfile",
13009
+ "-NonInteractive",
13010
+ "-Command",
13011
+ "$env:ProgramData"
13012
+ ], {
13013
+ timeout: 1e4,
13014
+ windowsHide: true,
13015
+ encoding: "utf8"
13016
+ }).trim();
13017
+ return base.length === 0 ? null : path.win32.join(base, LHM_SUBDIR);
13018
+ } catch {
13019
+ return null;
13020
+ }
13021
+ }
13022
+ /** A Windows path as a path this process can read: `C:\x` -> `/mnt/c/x`. */
13023
+ function toGuestPath(windowsPath) {
13024
+ const match = /^([a-z]):\\(.*)$/i.exec(windowsPath);
13025
+ if (match === null) return null;
13026
+ return path.posix.join("/mnt", match[1].toLowerCase(), ...match[2].split("\\"));
13027
+ }
13028
+ /** The install directory as a guest path, or null when the Windows side cannot be reached. */
13029
+ function lhmDirectory() {
13030
+ const windows = lhmDirectoryWindows();
13031
+ return windows === null ? null : toGuestPath(windows);
13032
+ }
12995
13033
  /**
12996
13034
  * Whether this process is a WSL2 guest.
12997
13035
  *
@@ -13006,40 +13044,38 @@ function isWsl() {
13006
13044
  return false;
13007
13045
  }
13008
13046
  }
13009
- /**
13010
- * Where the helper script goes: **on the Windows side**, under `%LOCALAPPDATA%`-style storage.
13011
- *
13012
- * This is the part that is easy to get wrong. `powershell.exe` reads a *Windows* path, so a script
13013
- * written into the guest's Linux home (`/tmp`, `~/.home-hosted`) is invisible to it — the command
13014
- * appears to work only while some stale copy exists, then fails with a path error that names nothing
13015
- * useful. `/mnt/c` is the 9p mount of `C:`, so writing there gives both sides the same file.
13016
- */
13047
+ /** A `/mnt/c/...` path as the `C:\...` path `powershell.exe` needs. Untranslatable paths pass through. */
13017
13048
  function windowsScriptPath(scriptPath) {
13018
13049
  const match = /^\/mnt\/([a-z])\/(.*)$/i.exec(scriptPath);
13019
13050
  if (match === null) return scriptPath;
13020
13051
  return `${match[1].toUpperCase()}:\\${match[2].replaceAll("/", "\\")}`;
13021
13052
  }
13022
- /**
13023
- * The Linux path the helper is written to: `C:\Tools\home-hosted\cpu-temp.ps1` on Windows.
13024
- *
13025
- * `user` is the Windows-side account, taken from the mount when it can be read. Falls back to the
13026
- * user's home on the Windows drive, which is where a person can find and delete the file.
13027
- */
13053
+ /** The helper script, written beside the library so every account resolves the same file. */
13028
13054
  function wslScriptPath() {
13029
13055
  if (!isWsl()) return null;
13030
- return path.join("/mnt/c/Tools/home-hosted", SCRIPT_NAME);
13056
+ const base = lhmDirectoryWindows();
13057
+ const guest = base === null ? null : toGuestPath(path.win32.dirname(base));
13058
+ if (guest === null) return null;
13059
+ return path.join(guest, SCRIPT_NAME);
13060
+ }
13061
+ /** Where the helper is, in Windows terms — what the command line has to say. */
13062
+ function wslScriptPathWindows() {
13063
+ const base = lhmDirectoryWindows();
13064
+ return base === null ? null : path.win32.join(path.win32.dirname(base), SCRIPT_NAME);
13031
13065
  }
13032
13066
  /** The `powershell.exe` invocation that runs `scriptPath` and prints the temperature. */
13033
13067
  function tempCommandFor(scriptPath) {
13034
13068
  return `powershell.exe -NoProfile -ExecutionPolicy Bypass -File "${windowsScriptPath(scriptPath)}"`;
13035
13069
  }
13070
+ /** The command for a path already expressed in Windows terms. */
13071
+ function tempCommandForWindows(windowsPath) {
13072
+ return `powershell.exe -NoProfile -ExecutionPolicy Bypass -File "${windowsPath}"`;
13073
+ }
13036
13074
  /** The script's body. Kept tiny: it runs on every host sample. */
13037
- function scriptBody(lhmDir) {
13038
- return `# CPU temperature for home-hosted, read through LibreHardwareMonitor.
13039
- # Written by \`home-hosted host tempsetup\`; safe to delete, and the panel stops using it when the
13040
- # Temperature command field is cleared.
13041
- $dir = '${lhmDir}'
13042
- if (-not (Test-Path "$dir\\LibreHardwareMonitorLib.dll")) {
13075
+ function scriptBody() {
13076
+ return `# CPU temperature for home-hosted. Written by \`home-hosted setup-temp --wsl\`; safe to delete.
13077
+ $dir = Join-Path $env:ProgramData 'home-hosted\\LibreHardwareMonitor'
13078
+ if (-not (Test-Path (Join-Path $dir 'LibreHardwareMonitorLib.dll'))) {
13043
13079
  [Console]::Error.WriteLine("LibreHardwareMonitor not found in $dir")
13044
13080
  exit 1
13045
13081
  }
@@ -13066,12 +13102,7 @@ if ($null -eq $out) { exit 2 }
13066
13102
  $out
13067
13103
  `;
13068
13104
  }
13069
- /**
13070
- * Whether the setup is in place: the script exists, and the panel has been pointed at it.
13071
- *
13072
- * `configured` is what the panel *will do*; `ready` is whether it can work — the two are separate so
13073
- * the UI can say "set up, but the library is missing" rather than only "not set up".
13074
- */
13105
+ /** `configured` (pointed at a command) and `libraryPresent` are separate, so the UI can say "set up, but the library is missing". */
13075
13106
  function wslTemperatureStatus(scriptPath, tempCommand) {
13076
13107
  const wsl = isWsl();
13077
13108
  const scriptWritten = scriptPath !== null && fs.existsSync(scriptPath);
@@ -13095,15 +13126,94 @@ function wslTemperatureStatus(scriptPath, tempCommand) {
13095
13126
  /** Write the helper script. Idempotent: re-running overwrites it with the current version. */
13096
13127
  function writeWslTemperatureScript(scriptPath) {
13097
13128
  fs.mkdirSync(path.dirname(scriptPath), { recursive: true });
13098
- fs.writeFileSync(scriptPath, scriptBody(LHM_DIR), { mode: 384 });
13129
+ fs.writeFileSync(scriptPath, scriptBody(), { mode: 384 });
13099
13130
  }
13100
- /**
13101
- * Run the helper once, to tell the person whether the setup works before they save a broken command.
13102
- *
13103
- * The answer is the reading, or a reason. A missing library and a library that returned nothing are
13104
- * different problems and get different sentences — the first says where to put the download, the
13105
- * second that the harness ran but found no sensor (a locked-down driver, a VM in a VM).
13106
- */
13131
+ /** Whether the DLL the helper loads is installed where the helper expects it. */
13132
+ function lhmInstalled() {
13133
+ const dir = lhmDirectory();
13134
+ if (dir === null) return false;
13135
+ try {
13136
+ return fs.existsSync(path.join(dir, "LibreHardwareMonitorLib.dll"));
13137
+ } catch {
13138
+ return false;
13139
+ }
13140
+ }
13141
+ /** Download, verify and unpack LibreHardwareMonitor. A failed attempt leaves nothing installed. */
13142
+ async function installLibreHardwareMonitor(options = {}) {
13143
+ const report = options.onProgress ?? (() => {});
13144
+ const targetWindows = lhmDirectoryWindows();
13145
+ const target = lhmDirectory();
13146
+ if (targetWindows === null || target === null) return {
13147
+ dir: null,
13148
+ error: "the Windows ProgramData directory could not be read, so there is nowhere to install to"
13149
+ };
13150
+ let staging = null;
13151
+ try {
13152
+ report(`downloading ${LHM_RELEASE.asset} (${LHM_RELEASE.version})…`);
13153
+ const response = await fetch(LHM_RELEASE.url, {
13154
+ redirect: "follow",
13155
+ signal: AbortSignal.timeout(12e4)
13156
+ });
13157
+ if (!response.ok) return {
13158
+ dir: null,
13159
+ error: `the download answered ${response.status} for ${LHM_RELEASE.url}`
13160
+ };
13161
+ const bytes = Buffer$1.from(await response.arrayBuffer());
13162
+ const digest = createHash("sha256").update(bytes).digest("hex");
13163
+ if (digest !== LHM_RELEASE.sha256) return {
13164
+ dir: null,
13165
+ error: `the download did not match its published sha256 (got ${digest.slice(0, 16)}…, expected ${LHM_RELEASE.sha256.slice(0, 16)}…) — nothing was installed`
13166
+ };
13167
+ const stagingRoot = path.join(path.dirname(target), ".staging");
13168
+ await fs.promises.mkdir(stagingRoot, { recursive: true });
13169
+ staging = await fs.promises.mkdtemp(path.join(stagingRoot, "run-"));
13170
+ const archive = path.join(staging, LHM_RELEASE.asset);
13171
+ await fs.promises.writeFile(archive, bytes);
13172
+ report(`unpacking into ${targetWindows}…`);
13173
+ await fs.promises.rm(target, {
13174
+ recursive: true,
13175
+ force: true
13176
+ });
13177
+ await fs.promises.mkdir(target, { recursive: true });
13178
+ await execFileAsync$2("powershell.exe", [
13179
+ "-NoProfile",
13180
+ "-NonInteractive",
13181
+ "-Command",
13182
+ `Expand-Archive -LiteralPath '${windowsScriptPath(archive)}' -DestinationPath '${targetWindows}' -Force`
13183
+ ], {
13184
+ timeout: 12e4,
13185
+ windowsHide: true
13186
+ });
13187
+ if (!lhmInstalled()) {
13188
+ await fs.promises.rm(target, {
13189
+ recursive: true,
13190
+ force: true
13191
+ }).catch(() => {});
13192
+ return {
13193
+ dir: null,
13194
+ error: `the archive unpacked but LibreHardwareMonitorLib.dll is not in ${targetWindows}`
13195
+ };
13196
+ }
13197
+ return {
13198
+ dir: targetWindows,
13199
+ error: null
13200
+ };
13201
+ } catch (error) {
13202
+ return {
13203
+ dir: null,
13204
+ error: error instanceof Error ? error.message : String(error)
13205
+ };
13206
+ } finally {
13207
+ if (staging !== null) {
13208
+ await fs.promises.rm(staging, {
13209
+ recursive: true,
13210
+ force: true
13211
+ }).catch(() => {});
13212
+ await fs.promises.rmdir(path.dirname(staging)).catch(() => {});
13213
+ }
13214
+ }
13215
+ }
13216
+ /** Run the helper once, so a setup that cannot work is reported rather than saved. */
13107
13217
  async function probeWslTemperature(tempCommand, timeoutMs) {
13108
13218
  try {
13109
13219
  const { stdout, stderr } = await execFileAsync$2(tempCommand, {
@@ -13135,12 +13245,19 @@ async function probeWslTemperature(tempCommand, timeoutMs) {
13135
13245
  };
13136
13246
  }
13137
13247
  }
13138
- var execFileAsync$2, SCRIPT_NAME, LHM_DIR;
13248
+ var execFileAsync$2, SCRIPT_NAME, LHM_SUBDIR, LHM_RELEASE;
13139
13249
  var init_wsl_temperature$1 = __esmMin((() => {
13140
13250
  init_logger();
13141
13251
  execFileAsync$2 = promisify(execFile);
13142
13252
  SCRIPT_NAME = "cpu-temp.ps1";
13143
- LHM_DIR = "C:\\Tools\\LibreHardwareMonitor";
13253
+ LHM_SUBDIR = "home-hosted\\LibreHardwareMonitor";
13254
+ LHM_RELEASE = {
13255
+ version: "0.9.6",
13256
+ asset: "LibreHardwareMonitor.zip",
13257
+ /** From the release's asset `digest` field, `sha256:…`. */
13258
+ sha256: "086d9f1b5a99e643edc2cfaaac16051685b551e4c5ac0b32a57c58c0e529c001",
13259
+ url: "https://github.com/LibreHardwareMonitor/LibreHardwareMonitor/releases/download/v0.9.6/LibreHardwareMonitor.zip"
13260
+ };
13144
13261
  }));
13145
13262
  //#endregion
13146
13263
  //#region src/api/wsl-temperature.ts
@@ -23139,13 +23256,13 @@ async function runSetupTemp(flags) {
23139
23256
  if (!isWsl()) fail("--wsl is for a WSL2 guest, and this is not one. Run `setup-temp` with no flag to see the options");
23140
23257
  const scriptPath = wslScriptPath();
23141
23258
  if (scriptPath === null) fail("the Windows drive is not mounted, so the helper cannot be written where powershell.exe can read it");
23259
+ if (!lhmInstalled()) await offerLibreHardwareMonitor(flags);
23142
23260
  writeWslTemperatureScript(scriptPath);
23143
23261
  const command = tempCommandFor(scriptPath);
23144
23262
  process.stdout.write(` helper ${dim(`${scriptPath} (${windowsScriptPath(scriptPath)} on Windows)`)}\n`);
23145
23263
  const probe = await probeWslTemperature(command, 5e3);
23146
23264
  if (probe.celsius === null) {
23147
23265
  process.stdout.write(`${fail("not set up")} — the helper did not answer: ${probe.error ?? "unknown reason"}\n`);
23148
- process.stdout.write(`${dim("install LibreHardwareMonitor in C:\\Tools\\LibreHardwareMonitor on Windows, then re-run this command")}\n`);
23149
23266
  process.stdout.write(`${dim(`the script is at ${scriptPath}; the config was left unchanged`)}\n`);
23150
23267
  return;
23151
23268
  }
@@ -23158,6 +23275,30 @@ async function runSetupTemp(flags) {
23158
23275
  process.stdout.write(` reading ${green(`${probe.celsius}°C`)}\n`);
23159
23276
  }
23160
23277
  }
23278
+ /**
23279
+ * Offer the ~6 MB download. A prompt, never a silent fetch: installing software nobody asked for is
23280
+ * not a setup command's job, and a non-interactive stdin answers no.
23281
+ */
23282
+ async function offerLibreHardwareMonitor(flags) {
23283
+ const where = lhmDirectoryWindows() ?? "C:\\ProgramData\\home-hosted\\LibreHardwareMonitor";
23284
+ if (flags.download !== true) {
23285
+ if (flags.download === false) {
23286
+ process.stdout.write(`${dim(`LibreHardwareMonitor is not installed; install it into ${where}, or pass --download`)}\n`);
23287
+ return;
23288
+ }
23289
+ const answer = await prompt(`LibreHardwareMonitor is required to read the sensor. Download it now (~6 MB)? [y/N] `);
23290
+ if (!/^y(?:es)?$/i.test(answer.trim())) {
23291
+ process.stdout.write(`${dim(`left it alone — install it into ${where} and re-run this command`)}\n`);
23292
+ return;
23293
+ }
23294
+ }
23295
+ const result = await installLibreHardwareMonitor({ onProgress: (message) => process.stdout.write(` ${dim(message)}\n`) });
23296
+ if (result.error !== null) {
23297
+ process.stdout.write(`${fail("the download did not install")} — ${result.error}\n`);
23298
+ return;
23299
+ }
23300
+ process.stdout.write(` library ${green("installed")} in ${result.dir}\n`);
23301
+ }
23161
23302
  var setupTempArgs, setupTempCommand;
23162
23303
  var init_setup_temp = __esmMin((() => {
23163
23304
  init_io();
@@ -23174,6 +23315,10 @@ var init_setup_temp = __esmMin((() => {
23174
23315
  type: "boolean",
23175
23316
  description: "stop using a configured command and delete its helper",
23176
23317
  default: false
23318
+ },
23319
+ download: {
23320
+ type: "boolean",
23321
+ description: "download LibreHardwareMonitor without asking; --no-download never does (for a script)"
23177
23322
  }
23178
23323
  };
23179
23324
  setupTempCommand = defineCommand({
@@ -23182,7 +23327,8 @@ var init_setup_temp = __esmMin((() => {
23182
23327
  async run({ args }) {
23183
23328
  await runSetupTemp({
23184
23329
  wsl: args.wsl === true,
23185
- clear: args.clear === true
23330
+ clear: args.clear === true,
23331
+ download: args.download
23186
23332
  });
23187
23333
  }
23188
23334
  });
@@ -25002,6 +25148,7 @@ var SYNOPSIS = {
25002
25148
  "free-port": "home-hosted free-port <id> [--workspace <id>]",
25003
25149
  "set-password": "home-hosted set-password",
25004
25150
  "set-token": "home-hosted set-token",
25151
+ "setup-temp": "home-hosted setup-temp [--wsl] [--download|--no-download] [--clear]",
25005
25152
  "migrate": "home-hosted migrate",
25006
25153
  "init": "home-hosted init",
25007
25154
  "ui-switch": "home-hosted ui-switch",
@@ -25100,6 +25247,15 @@ var SET_TOKEN_SECTION = {
25100
25247
  heading: "Options for set-token",
25101
25248
  lines: [["--generate", "create a strong token and print it once"], ["--clear", "remove the token, so it stops working"]]
25102
25249
  };
25250
+ var SETUP_TEMP_SECTION = {
25251
+ heading: "Options for setup-temp",
25252
+ lines: [
25253
+ ["--wsl", "read the temperature through the Windows host (WSL2)"],
25254
+ ["--download", "fetch LibreHardwareMonitor without asking (for a script)"],
25255
+ ["--no-download", "never fetch it; report what is missing"],
25256
+ ["--clear", "stop using the command and delete the helper"]
25257
+ ]
25258
+ };
25103
25259
  var MIGRATE_SECTION = {
25104
25260
  heading: "Options for migrate",
25105
25261
  lines: [["--dry-run", "print what would change, write nothing"], ["-y, --yes", "apply without asking (or set HHOSTED_MIGRATE=allow)"]]
@@ -25229,6 +25385,7 @@ var SECTIONS = {
25229
25385
  "free-port": SERVER_SECTION,
25230
25386
  "set-password": SET_PASSWORD_SECTION,
25231
25387
  "set-token": SET_TOKEN_SECTION,
25388
+ "setup-temp": SETUP_TEMP_SECTION,
25232
25389
  "migrate": MIGRATE_SECTION,
25233
25390
  "init": INIT_SECTION,
25234
25391
  "ui-switch": UI_SWITCH_SECTION,