@riddix/hamh 2.1.0-alpha.555 → 2.1.0-alpha.556

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.
@@ -147448,6 +147448,7 @@ import { hideBin } from "yargs/helpers";
147448
147448
  init_esm6();
147449
147449
 
147450
147450
  // src/commands/start/start-handler.ts
147451
+ init_esm();
147451
147452
  import * as ws from "ws";
147452
147453
 
147453
147454
  // src/api/web-api.ts
@@ -148445,14 +148446,17 @@ function deviceImageApi(storageLocation, haRegistry) {
148445
148446
  }
148446
148447
 
148447
148448
  // src/api/diagnostic-api.ts
148448
- import os from "node:os";
148449
+ import os2 from "node:os";
148449
148450
  import express6 from "express";
148450
148451
 
148451
148452
  // src/api/logs-api.ts
148453
+ import os from "node:os";
148452
148454
  import express5 from "express";
148455
+ var totalMemMB = Math.round(os.totalmem() / 1024 / 1024);
148456
+ var defaultMaxSize = totalMemMB < 2048 ? 200 : 1e3;
148453
148457
  var logBuffer = {
148454
148458
  entries: [],
148455
- maxSize: 1e3
148459
+ maxSize: defaultMaxSize
148456
148460
  };
148457
148461
  function addLogEntry(entry) {
148458
148462
  logBuffer.entries.push(entry);
@@ -148629,13 +148633,13 @@ function diagnosticApi(bridgeService, haClient, haRegistry, version, startTime)
148629
148633
  version,
148630
148634
  uptime: Math.floor((Date.now() - startTime) / 1e3),
148631
148635
  system: {
148632
- platform: os.platform(),
148633
- arch: os.arch(),
148636
+ platform: os2.platform(),
148637
+ arch: os2.arch(),
148634
148638
  nodeVersion: process.version,
148635
148639
  environment: detectEnvironment(),
148636
148640
  memory: {
148637
- totalMB: Math.round(os.totalmem() / 1024 / 1024),
148638
- freeMB: Math.round(os.freemem() / 1024 / 1024),
148641
+ totalMB: Math.round(os2.totalmem() / 1024 / 1024),
148642
+ freeMB: Math.round(os2.freemem() / 1024 / 1024),
148639
148643
  heapUsedMB: Math.round(memUsage.heapUsed / 1024 / 1024),
148640
148644
  heapTotalMB: Math.round(memUsage.heapTotal / 1024 / 1024),
148641
148645
  rssMB: Math.round(memUsage.rss / 1024 / 1024)
@@ -150033,7 +150037,7 @@ function metricsApi(bridgeService, haClient, haRegistry, startTime) {
150033
150037
  }
150034
150038
 
150035
150039
  // src/api/network-diagnostic-api.ts
150036
- import * as os2 from "node:os";
150040
+ import * as os3 from "node:os";
150037
150041
  import express13 from "express";
150038
150042
  function networkDiagnosticApi(mdnsInterface, mdnsIpv4) {
150039
150043
  const router = express13.Router();
@@ -150044,7 +150048,7 @@ function networkDiagnosticApi(mdnsInterface, mdnsIpv4) {
150044
150048
  return router;
150045
150049
  }
150046
150050
  function getNetworkInterfaces() {
150047
- const raw = os2.networkInterfaces();
150051
+ const raw = os3.networkInterfaces();
150048
150052
  const result = [];
150049
150053
  for (const [name, addrs] of Object.entries(raw)) {
150050
150054
  if (!addrs) continue;
@@ -150910,7 +150914,7 @@ function settingsApi(settingsStorage, envAuth) {
150910
150914
  // src/api/system-api.ts
150911
150915
  init_esm();
150912
150916
  import { exec } from "node:child_process";
150913
- import os3 from "node:os";
150917
+ import os4 from "node:os";
150914
150918
  import { promisify } from "node:util";
150915
150919
  import v8 from "node:v8";
150916
150920
  import express15 from "express";
@@ -150966,22 +150970,22 @@ function systemApi(version) {
150966
150970
  });
150967
150971
  router.get("/info", async (_req, res) => {
150968
150972
  try {
150969
- const totalMem = os3.totalmem();
150970
- const freeMem = os3.freemem();
150973
+ const totalMem = os4.totalmem();
150974
+ const freeMem = os4.freemem();
150971
150975
  const usedMem = totalMem - freeMem;
150972
150976
  const storageInfo = await getStorageInfo();
150973
- const cpus = os3.cpus();
150977
+ const cpus = os4.cpus();
150974
150978
  const memUsage = process.memoryUsage();
150975
150979
  const systemInfo = {
150976
150980
  version,
150977
150981
  nodeVersion: process.version,
150978
- hostname: os3.hostname(),
150979
- platform: os3.platform(),
150980
- arch: os3.arch(),
150981
- uptime: os3.uptime(),
150982
+ hostname: os4.hostname(),
150983
+ platform: os4.platform(),
150984
+ arch: os4.arch(),
150985
+ uptime: os4.uptime(),
150982
150986
  cpuCount: cpus.length,
150983
150987
  cpuModel: cpus[0]?.model || "Unknown",
150984
- loadAvg: os3.loadavg(),
150988
+ loadAvg: os4.loadavg(),
150985
150989
  environment: detectEnvironment2(),
150986
150990
  memory: {
150987
150991
  total: totalMem,
@@ -151017,7 +151021,7 @@ function systemApi(version) {
151017
151021
  }
151018
151022
  function getNetworkInterfaces2() {
151019
151023
  const interfaces = [];
151020
- const networkInterfaces3 = os3.networkInterfaces();
151024
+ const networkInterfaces3 = os4.networkInterfaces();
151021
151025
  for (const [name, ifaceList] of Object.entries(networkInterfaces3)) {
151022
151026
  if (!ifaceList) continue;
151023
151027
  for (const iface of ifaceList) {
@@ -151046,7 +151050,7 @@ function getNetworkInterfaces2() {
151046
151050
  async function getStorageInfo() {
151047
151051
  try {
151048
151052
  const pathToCheck = getDataPath();
151049
- if (os3.platform() === "win32") {
151053
+ if (os4.platform() === "win32") {
151050
151054
  return await getWindowsStorageInfo(pathToCheck);
151051
151055
  } else {
151052
151056
  return await getUnixStorageInfo(pathToCheck);
@@ -151636,7 +151640,7 @@ function mdns(env, options) {
151636
151640
  // src/core/app/storage.ts
151637
151641
  init_esm7();
151638
151642
  import fs8 from "node:fs";
151639
- import os4 from "node:os";
151643
+ import os5 from "node:os";
151640
151644
  import path8 from "node:path";
151641
151645
 
151642
151646
  // src/core/app/storage/custom-storage.ts
@@ -151743,7 +151747,7 @@ function storage(environment, options) {
151743
151747
  storageService.factory = (ns) => new CustomStorage(logger205, path8.resolve(location2, ns));
151744
151748
  }
151745
151749
  function resolveStorageLocation(storageLocation) {
151746
- const homedir = os4.homedir();
151750
+ const homedir = os5.homedir();
151747
151751
  return storageLocation ? path8.resolve(storageLocation.replace(/^~\//, `${homedir}/`)) : path8.join(homedir, ".home-assistant-matter-hub");
151748
151752
  }
151749
151753
 
@@ -151763,7 +151767,7 @@ function configureDefaultEnvironment(options) {
151763
151767
  // src/core/app/options.ts
151764
151768
  init_esm7();
151765
151769
  import { createRequire } from "node:module";
151766
- import os5 from "node:os";
151770
+ import os6 from "node:os";
151767
151771
  import path9 from "node:path";
151768
151772
  function resolveAppVersion() {
151769
151773
  try {
@@ -151829,7 +151833,7 @@ var Options = class {
151829
151833
  }
151830
151834
  resolveStorageLocation() {
151831
151835
  const storageLocation = notEmpty(this.startOptions.storageLocation);
151832
- const homedir = os5.homedir();
151836
+ const homedir = os6.homedir();
151833
151837
  return storageLocation ? path9.resolve(storageLocation.replace(/^~\//, `${homedir}/`)) : path9.join(homedir, ".home-assistant-matter-hub");
151834
151838
  }
151835
151839
  get bridgeService() {
@@ -152411,8 +152415,10 @@ import { getStates } from "home-assistant-js-websocket";
152411
152415
  import { fromPairs, keyBy, keys, uniq, values } from "lodash-es";
152412
152416
 
152413
152417
  // src/utils/log-memory.ts
152418
+ import os7 from "node:os";
152414
152419
  import v82 from "node:v8";
152415
152420
  var HEAP_PRESSURE_THRESHOLD = 0.85;
152421
+ var LOW_MEMORY_THRESHOLD_MB = 512;
152416
152422
  function logMemoryUsage(log, context) {
152417
152423
  const mem = process.memoryUsage();
152418
152424
  const heapUsedMB = Math.round(mem.heapUsed / 1024 / 1024);
@@ -152426,6 +152432,21 @@ function isHeapUnderPressure() {
152426
152432
  const stats = v82.getHeapStatistics();
152427
152433
  return stats.used_heap_size / stats.heap_size_limit > HEAP_PRESSURE_THRESHOLD;
152428
152434
  }
152435
+ function logStartupMemoryGuard(log) {
152436
+ const totalMB = Math.round(os7.totalmem() / 1024 / 1024);
152437
+ const freeMB = Math.round(os7.freemem() / 1024 / 1024);
152438
+ const heapLimitMB = Math.round(
152439
+ v82.getHeapStatistics().heap_size_limit / 1024 / 1024
152440
+ );
152441
+ log.info(
152442
+ `System memory: ${freeMB} MB free / ${totalMB} MB total, heap limit: ${heapLimitMB} MB`
152443
+ );
152444
+ if (freeMB < LOW_MEMORY_THRESHOLD_MB) {
152445
+ log.warn(
152446
+ `Low memory detected (${freeMB} MB free). HAMH typically needs 400-600 MB. Consider reducing the number of entities per bridge, stopping memory-heavy add-ons, or increasing available RAM. See the FAQ section 'The app keeps crashing or restarting' for details.`
152447
+ );
152448
+ }
152449
+ }
152429
152450
 
152430
152451
  // src/services/home-assistant/home-assistant-registry.ts
152431
152452
  init_retry();
@@ -181698,6 +181719,7 @@ async function startHandler(startOptions, webUiDist) {
181698
181719
  patchLevelControlTlv();
181699
181720
  const options = new Options({ ...startOptions, webUiDist });
181700
181721
  const rootEnv = configureDefaultEnvironment(options);
181722
+ logStartupMemoryGuard(Logger.get("Startup"));
181701
181723
  const appEnvironment = await AppEnvironment.create(rootEnv, options);
181702
181724
  registerFinalErrorHandlers();
181703
181725
  const bridgeService$ = appEnvironment.load(BridgeService);