amalgm 0.1.140 → 0.1.141

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 (2) hide show
  1. package/lib/supervisor.js +36 -5
  2. package/package.json +1 -1
package/lib/supervisor.js CHANGED
@@ -384,6 +384,33 @@ function runtimeStateFilesUnder(dir) {
384
384
  return files;
385
385
  }
386
386
 
387
+ function directoryExists(dir) {
388
+ try {
389
+ return fs.statSync(dir).isDirectory();
390
+ } catch {
391
+ return false;
392
+ }
393
+ }
394
+
395
+ function runtimeStateSearchRoots() {
396
+ const roots = [];
397
+ const usersRoot = path.join(AMALGM_HOME, 'users');
398
+ let userEntries;
399
+ try {
400
+ userEntries = fs.readdirSync(usersRoot, { withFileTypes: true });
401
+ } catch {
402
+ userEntries = [];
403
+ }
404
+
405
+ for (const entry of userEntries) {
406
+ if (!entry.isDirectory()) continue;
407
+ roots.push(path.join(usersRoot, entry.name, 'runtimes'));
408
+ }
409
+
410
+ roots.push(path.join(AMALGM_HOME, 'runtimes'));
411
+ return Array.from(new Set(roots.map((root) => path.resolve(root)))).filter(directoryExists);
412
+ }
413
+
387
414
  function stateProcessRunning(state) {
388
415
  const pids = [
389
416
  state?.supervisor_pid,
@@ -396,10 +423,7 @@ function stateProcessRunning(state) {
396
423
 
397
424
  function liveDeclaredRuntimePorts() {
398
425
  const used = new Set();
399
- const stateFiles = [
400
- ...runtimeStateFilesUnder(path.join(AMALGM_HOME, 'users')),
401
- ...runtimeStateFilesUnder(path.join(AMALGM_HOME, 'runtimes')),
402
- ];
426
+ const stateFiles = runtimeStateSearchRoots().flatMap((dir) => runtimeStateFilesUnder(dir));
403
427
  for (const stateFile of new Set(stateFiles)) {
404
428
  if (path.resolve(stateFile) === path.resolve(RUNTIME_STATE_FILE)) continue;
405
429
  const state = readJson(stateFile, null);
@@ -1306,4 +1330,11 @@ async function startSupervisor(options = {}) {
1306
1330
  });
1307
1331
  }
1308
1332
 
1309
- module.exports = { startSupervisor };
1333
+ module.exports = {
1334
+ startSupervisor,
1335
+ _test: {
1336
+ liveDeclaredRuntimePorts,
1337
+ runtimeStateFilesUnder,
1338
+ runtimeStateSearchRoots,
1339
+ },
1340
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amalgm",
3
- "version": "0.1.140",
3
+ "version": "0.1.141",
4
4
  "description": "Amalgm local computer runtime: login, MCP, chat, events, previews, and tunnels.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,