@camstack/agent 1.1.19 → 1.1.21

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/dist/cli.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import { createRequire as __cr } from 'node:module'; const require = globalThis.require ?? __cr(import.meta.url);
3
3
  import {
4
4
  startAgent
5
- } from "./chunk-ZGI2MAIL.mjs";
5
+ } from "./chunk-4X5XKWDM.mjs";
6
6
 
7
7
  // src/cli.ts
8
8
  import { existsSync } from "fs";
@@ -86,6 +86,9 @@ Environment variables (override CLI args):
86
86
  CAMSTACK_DATA_DIR Data directory path
87
87
  CAMSTACK_LOG_LEVEL Log level
88
88
  CAMSTACK_CLUSTER_SECRET Cluster secret
89
+ CAMSTACK_HUB_URL Derived automatically from the hub address; set
90
+ only to override the cross-node stream/recording
91
+ pull host
89
92
 
90
93
  Examples:
91
94
  camstack-agent --hub 192.168.1.100
package/dist/cli.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * CamStack Agent CLI — starts a remote agent node that connects to a hub.\n *\n * Usage:\n * camstack-agent --hub 192.168.1.100\n * camstack-agent --hub 192.168.1.100 --name gpu-box --data ./agent-data\n * CAMSTACK_HUB_ADDRESS=192.168.1.100 camstack-agent\n */\nimport { existsSync } from 'node:fs'\nimport { Module as nodeModule } from 'node:module'\nimport * as os from 'node:os'\nimport * as path from 'node:path'\nimport { startAgent } from './agent-bootstrap.js'\n\n// `Module._initPaths()` re-derives the CJS search paths from a NODE_PATH set\n// after process start. It's a stable Node internal backing NODE_PATH support\n// but is absent from @types/node — declare it via merging (no cast).\ndeclare module 'node:module' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Module {\n function _initPaths(): void\n }\n}\n\ninterface CliArgs {\n hub?: string\n name?: string\n data?: string\n logLevel?: string\n secret?: string\n statusPort?: string\n help?: boolean\n}\n\nfunction parseArgs(argv: readonly string[]): CliArgs {\n const args: CliArgs = {}\n for (let i = 2; i < argv.length; i++) {\n const arg = argv[i]!\n const next = argv[i + 1]\n switch (arg) {\n case '--hub':\n case '-h':\n if (arg === '-h' && !next?.match(/^[\\d.]+/)) {\n args.help = true\n break\n }\n args.hub = next\n i++\n break\n case '--name':\n case '-n':\n args.name = next\n i++\n break\n case '--data':\n case '-d':\n args.data = next\n i++\n break\n case '--log-level':\n case '-l':\n args.logLevel = next\n i++\n break\n case '--secret':\n case '-s':\n args.secret = next\n i++\n break\n case '--status-port':\n case '-p':\n args.statusPort = next\n i++\n break\n case '--help':\n args.help = true\n break\n default:\n if (!arg.startsWith('-') && !args.hub) {\n args.hub = arg\n break\n }\n console.error(`Unknown argument: ${arg}`)\n args.help = true\n }\n }\n return args\n}\n\nfunction printHelp(): void {\n console.log(\n `\ncamstack-agent — CamStack remote agent node\n\nUsage:\n camstack-agent --hub <hub-address> [options]\n camstack-agent <hub-address> [options]\n\nOptions:\n --hub, -h <address> Hub address (IP or hostname, e.g. 192.168.1.100)\n --name, -n <name> Node name (default: hostname)\n --data, -d <path> Data directory (default: ./camstack-data)\n --log-level, -l <level> Log level: trace|debug|info|warn|error (default: info)\n --secret, -s <secret> Cluster secret (nodes must share the same secret)\n --help Show this help\n\nEnvironment variables (override CLI args):\n CAMSTACK_NODE_ID Node identifier\n CAMSTACK_HUB_ADDRESS Hub address\n CAMSTACK_DATA_DIR Data directory path\n CAMSTACK_LOG_LEVEL Log level\n CAMSTACK_CLUSTER_SECRET Cluster secret\n\nExamples:\n camstack-agent --hub 192.168.1.100\n camstack-agent --hub 192.168.1.100 --name gpu-box --log-level debug\n CAMSTACK_HUB_ADDRESS=192.168.1.100 camstack-agent\n`.trim(),\n )\n}\n\nconst args = parseArgs(process.argv)\n\nif (args.help) {\n printHelp()\n process.exit(0)\n}\n\n// CLI args → env vars (env vars set externally take precedence via agent-config.ts)\nif (args.hub && !process.env['CAMSTACK_HUB_ADDRESS']) {\n process.env['CAMSTACK_HUB_ADDRESS'] = args.hub\n}\nif (args.name && !process.env['CAMSTACK_NODE_ID']) {\n process.env['CAMSTACK_NODE_ID'] = args.name\n}\nif (args.data && !process.env['CAMSTACK_DATA_DIR']) {\n process.env['CAMSTACK_DATA_DIR'] = args.data\n}\nif (args.logLevel && !process.env['CAMSTACK_LOG_LEVEL']) {\n process.env['CAMSTACK_LOG_LEVEL'] = args.logLevel\n}\nif (args.secret && !process.env['CAMSTACK_CLUSTER_SECRET']) {\n process.env['CAMSTACK_CLUSTER_SECRET'] = args.secret\n}\nif (args.statusPort && !process.env['CAMSTACK_STATUS_PORT']) {\n process.env['CAMSTACK_STATUS_PORT'] = args.statusPort\n}\n\n// Packaged-app framework resolution. In a self-contained build (e.g. the\n// Electron `.app`, where this CLI lives at `<root>/agent/dist/cli.js` and the\n// host-provided package closure at `<root>/node_modules`), addons installed\n// under the data dir cannot walk up to the framework's node_modules. Mirror the\n// Docker image's setup: point the addon-runner's resolver hook at the framework\n// (CAMSTACK_FRAMEWORK_DIR, for ESM imports) AND seed NODE_PATH (for CJS\n// `require`) so host externals (@camstack/shm-ring, sharp, node-av, …) resolve.\n// No-op in dev (workspace symlinks resolve the framework) and when an operator\n// or the Docker image has already set CAMSTACK_FRAMEWORK_DIR.\nif (!process.env['CAMSTACK_FRAMEWORK_DIR']) {\n const scriptPath = process.argv[1]\n if (scriptPath) {\n const frameworkDir = path.resolve(path.dirname(scriptPath), '..', '..')\n const frameworkModules = path.join(frameworkDir, 'node_modules')\n // Sentinel: a host-provided native package present in the framework's\n // node_modules confirms the self-contained layout (absent in dev).\n if (existsSync(path.join(frameworkModules, '@camstack', 'shm-ring'))) {\n process.env['CAMSTACK_FRAMEWORK_DIR'] = frameworkDir\n const existingNodePath = process.env['NODE_PATH']\n process.env['NODE_PATH'] = existingNodePath\n ? `${frameworkModules}${path.delimiter}${existingNodePath}`\n : frameworkModules\n // Node reads NODE_PATH once at startup into the CJS module search paths;\n // setting it now (post-start) only reaches CHILD processes that inherit\n // it at spawn (the forked addon-runners). The agent's OWN main process —\n // where bootCoreAddons imports the in-process infra builtins (storage /\n // settings / metrics from @camstack/system) — must re-derive its search\n // paths or those addons' host-dep requires (@camstack/types, …) fail with\n // \"Cannot find module\" and the agent boots with NO infrastructure.\n nodeModule._initPaths()\n console.log(\n `[Agent] Self-contained framework detected — CAMSTACK_FRAMEWORK_DIR=${frameworkDir}`,\n )\n // Also point the bootstrap installer at the bundled addons so a fresh\n // (empty) data dir gets seeded with the agent's required packages\n // (@camstack/system — platform-probe/storage/settings/metrics builtins —\n // plus the bundled addons). Without this, bootCoreAddons finds no addon\n // packages and the agent runs with NO infrastructure (no platform-probe →\n // detection engine can't auto-pick the node's accelerator, no storage,\n // etc.). Mirrors the Docker image's CAMSTACK_BUNDLED_ADDONS_DIR.\n if (!process.env['CAMSTACK_BUNDLED_ADDONS_DIR']) {\n const bundledAddons = path.join(frameworkDir, 'addons')\n if (existsSync(bundledAddons)) {\n process.env['CAMSTACK_BUNDLED_ADDONS_DIR'] = bundledAddons\n }\n }\n }\n }\n}\n\n// Default node name to hostname if not set\nif (!process.env['CAMSTACK_NODE_ID']) {\n process.env['CAMSTACK_NODE_ID'] = os.hostname()\n}\n\n// Hub address is optional — agent starts in discovery mode without it.\n// The agent UI on :4444 lets the user configure the hub connection.\nif (!process.env['CAMSTACK_HUB_ADDRESS']) {\n console.log('[Agent] No hub address specified — starting in discovery mode')\n console.log('[Agent] Configure hub connection at http://localhost:4444')\n}\n\nstartAgent().catch((err: unknown) => {\n console.error('[Agent] Fatal error:', err)\n process.exit(1)\n})\n"],"mappings":";;;;;;;AASA,SAAS,kBAAkB;AAC3B,SAAS,UAAU,kBAAkB;AACrC,YAAY,QAAQ;AACpB,YAAY,UAAU;AAuBtB,SAAS,UAAU,MAAkC;AACnD,QAAMA,QAAgB,CAAC;AACvB,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,MAAM,KAAK,CAAC;AAClB,U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AAGA,IAAI,CAAC,QAAQ,IAAI,kBAAkB,GAAG;AACpC,UAAQ,IAAI,kBAAkB,IAAO,YAAS;AAChD;AAIA,IAAI,CAAC,QAAQ,IAAI,sBAAsB,GAAG;AACxC,UAAQ,IAAI,oEAA+D;AAC3E,UAAQ,IAAI,2DAA2D;AACzE;AAEA,WAAW,EAAE,MAAM,CAAC,QAAiB;AACnC,UAAQ,MAAM,wBAAwB,GAAG;AACzC,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["args"]}
1
+ {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * CamStack Agent CLI — starts a remote agent node that connects to a hub.\n *\n * Usage:\n * camstack-agent --hub 192.168.1.100\n * camstack-agent --hub 192.168.1.100 --name gpu-box --data ./agent-data\n * CAMSTACK_HUB_ADDRESS=192.168.1.100 camstack-agent\n */\nimport { existsSync } from 'node:fs'\nimport { Module as nodeModule } from 'node:module'\nimport * as os from 'node:os'\nimport * as path from 'node:path'\nimport { startAgent } from './agent-bootstrap.js'\n\n// `Module._initPaths()` re-derives the CJS search paths from a NODE_PATH set\n// after process start. It's a stable Node internal backing NODE_PATH support\n// but is absent from @types/node — declare it via merging (no cast).\ndeclare module 'node:module' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Module {\n function _initPaths(): void\n }\n}\n\ninterface CliArgs {\n hub?: string\n name?: string\n data?: string\n logLevel?: string\n secret?: string\n statusPort?: string\n help?: boolean\n}\n\nfunction parseArgs(argv: readonly string[]): CliArgs {\n const args: CliArgs = {}\n for (let i = 2; i < argv.length; i++) {\n const arg = argv[i]!\n const next = argv[i + 1]\n switch (arg) {\n case '--hub':\n case '-h':\n if (arg === '-h' && !next?.match(/^[\\d.]+/)) {\n args.help = true\n break\n }\n args.hub = next\n i++\n break\n case '--name':\n case '-n':\n args.name = next\n i++\n break\n case '--data':\n case '-d':\n args.data = next\n i++\n break\n case '--log-level':\n case '-l':\n args.logLevel = next\n i++\n break\n case '--secret':\n case '-s':\n args.secret = next\n i++\n break\n case '--status-port':\n case '-p':\n args.statusPort = next\n i++\n break\n case '--help':\n args.help = true\n break\n default:\n if (!arg.startsWith('-') && !args.hub) {\n args.hub = arg\n break\n }\n console.error(`Unknown argument: ${arg}`)\n args.help = true\n }\n }\n return args\n}\n\nfunction printHelp(): void {\n console.log(\n `\ncamstack-agent — CamStack remote agent node\n\nUsage:\n camstack-agent --hub <hub-address> [options]\n camstack-agent <hub-address> [options]\n\nOptions:\n --hub, -h <address> Hub address (IP or hostname, e.g. 192.168.1.100)\n --name, -n <name> Node name (default: hostname)\n --data, -d <path> Data directory (default: ./camstack-data)\n --log-level, -l <level> Log level: trace|debug|info|warn|error (default: info)\n --secret, -s <secret> Cluster secret (nodes must share the same secret)\n --help Show this help\n\nEnvironment variables (override CLI args):\n CAMSTACK_NODE_ID Node identifier\n CAMSTACK_HUB_ADDRESS Hub address\n CAMSTACK_DATA_DIR Data directory path\n CAMSTACK_LOG_LEVEL Log level\n CAMSTACK_CLUSTER_SECRET Cluster secret\n CAMSTACK_HUB_URL Derived automatically from the hub address; set\n only to override the cross-node stream/recording\n pull host\n\nExamples:\n camstack-agent --hub 192.168.1.100\n camstack-agent --hub 192.168.1.100 --name gpu-box --log-level debug\n CAMSTACK_HUB_ADDRESS=192.168.1.100 camstack-agent\n`.trim(),\n )\n}\n\nconst args = parseArgs(process.argv)\n\nif (args.help) {\n printHelp()\n process.exit(0)\n}\n\n// CLI args → env vars (env vars set externally take precedence via agent-config.ts)\nif (args.hub && !process.env['CAMSTACK_HUB_ADDRESS']) {\n process.env['CAMSTACK_HUB_ADDRESS'] = args.hub\n}\nif (args.name && !process.env['CAMSTACK_NODE_ID']) {\n process.env['CAMSTACK_NODE_ID'] = args.name\n}\nif (args.data && !process.env['CAMSTACK_DATA_DIR']) {\n process.env['CAMSTACK_DATA_DIR'] = args.data\n}\nif (args.logLevel && !process.env['CAMSTACK_LOG_LEVEL']) {\n process.env['CAMSTACK_LOG_LEVEL'] = args.logLevel\n}\nif (args.secret && !process.env['CAMSTACK_CLUSTER_SECRET']) {\n process.env['CAMSTACK_CLUSTER_SECRET'] = args.secret\n}\nif (args.statusPort && !process.env['CAMSTACK_STATUS_PORT']) {\n process.env['CAMSTACK_STATUS_PORT'] = args.statusPort\n}\n\n// Packaged-app framework resolution. In a self-contained build (e.g. the\n// Electron `.app`, where this CLI lives at `<root>/agent/dist/cli.js` and the\n// host-provided package closure at `<root>/node_modules`), addons installed\n// under the data dir cannot walk up to the framework's node_modules. Mirror the\n// Docker image's setup: point the addon-runner's resolver hook at the framework\n// (CAMSTACK_FRAMEWORK_DIR, for ESM imports) AND seed NODE_PATH (for CJS\n// `require`) so host externals (@camstack/shm-ring, sharp, node-av, …) resolve.\n// No-op in dev (workspace symlinks resolve the framework) and when an operator\n// or the Docker image has already set CAMSTACK_FRAMEWORK_DIR.\nif (!process.env['CAMSTACK_FRAMEWORK_DIR']) {\n const scriptPath = process.argv[1]\n if (scriptPath) {\n const frameworkDir = path.resolve(path.dirname(scriptPath), '..', '..')\n const frameworkModules = path.join(frameworkDir, 'node_modules')\n // Sentinel: a host-provided native package present in the framework's\n // node_modules confirms the self-contained layout (absent in dev).\n if (existsSync(path.join(frameworkModules, '@camstack', 'shm-ring'))) {\n process.env['CAMSTACK_FRAMEWORK_DIR'] = frameworkDir\n const existingNodePath = process.env['NODE_PATH']\n process.env['NODE_PATH'] = existingNodePath\n ? `${frameworkModules}${path.delimiter}${existingNodePath}`\n : frameworkModules\n // Node reads NODE_PATH once at startup into the CJS module search paths;\n // setting it now (post-start) only reaches CHILD processes that inherit\n // it at spawn (the forked addon-runners). The agent's OWN main process —\n // where bootCoreAddons imports the in-process infra builtins (storage /\n // settings / metrics from @camstack/system) — must re-derive its search\n // paths or those addons' host-dep requires (@camstack/types, …) fail with\n // \"Cannot find module\" and the agent boots with NO infrastructure.\n nodeModule._initPaths()\n console.log(\n `[Agent] Self-contained framework detected — CAMSTACK_FRAMEWORK_DIR=${frameworkDir}`,\n )\n // Also point the bootstrap installer at the bundled addons so a fresh\n // (empty) data dir gets seeded with the agent's required packages\n // (@camstack/system — platform-probe/storage/settings/metrics builtins —\n // plus the bundled addons). Without this, bootCoreAddons finds no addon\n // packages and the agent runs with NO infrastructure (no platform-probe →\n // detection engine can't auto-pick the node's accelerator, no storage,\n // etc.). Mirrors the Docker image's CAMSTACK_BUNDLED_ADDONS_DIR.\n if (!process.env['CAMSTACK_BUNDLED_ADDONS_DIR']) {\n const bundledAddons = path.join(frameworkDir, 'addons')\n if (existsSync(bundledAddons)) {\n process.env['CAMSTACK_BUNDLED_ADDONS_DIR'] = bundledAddons\n }\n }\n }\n }\n}\n\n// Default node name to hostname if not set\nif (!process.env['CAMSTACK_NODE_ID']) {\n process.env['CAMSTACK_NODE_ID'] = os.hostname()\n}\n\n// Hub address is optional — agent starts in discovery mode without it.\n// The agent UI on :4444 lets the user configure the hub connection.\nif (!process.env['CAMSTACK_HUB_ADDRESS']) {\n console.log('[Agent] No hub address specified — starting in discovery mode')\n console.log('[Agent] Configure hub connection at http://localhost:4444')\n}\n\nstartAgent().catch((err: unknown) => {\n console.error('[Agent] Fatal error:', err)\n process.exit(1)\n})\n"],"mappings":";;;;;;;AASA,SAAS,kBAAkB;AAC3B,SAAS,UAAU,kBAAkB;AACrC,YAAY,QAAQ;AACpB,YAAY,UAAU;AAuBtB,SAAS,UAAU,MAAkC;AACnD,QAAMA,QAAgB,CAAC;AACvB,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,MAAM,KAAK,CAAC;AAClB,UAAM,OAAO,KAAK,IAAI,CAAC;AACvB,YAAQ,KAAK;AAAA,MACX,KAAK;AAAA,MACL,KAAK;AACH,YAAI,QAAQ,QAAQ,CAAC,MAAM,MAAM,SAAS,GAAG;AAC3C,UAAAA,MAAK,OAAO;AACZ;AAAA,QACF;AACA,QAAAA,MAAK,MAAM;AACX;AACA;AAAA,MACF,KAAK;AAAA,MACL,KAAK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,QAAiB;AACnC,UAAQ,MAAM,wBAAwB,GAAG;AACzC,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["args"]}
package/dist/index.js CHANGED
@@ -579,9 +579,12 @@ function createAgentService(deps) {
579
579
  }
580
580
  const pkgName = entry?.packageName;
581
581
  if (pkgName && pkgName !== addonId) {
582
- const pkgDir = path3.join(deps.addonsDir, pkgName);
583
- if (fs3.existsSync(pkgDir)) {
584
- fs3.rmSync(pkgDir, { recursive: true, force: true });
582
+ const pkgShared = [...deps.loadedAddons.values()].some((e) => e.packageName === pkgName);
583
+ if (!pkgShared) {
584
+ const pkgDir = path3.join(deps.addonsDir, pkgName);
585
+ if (fs3.existsSync(pkgDir)) {
586
+ fs3.rmSync(pkgDir, { recursive: true, force: true });
587
+ }
585
588
  }
586
589
  }
587
590
  broker.logger.info(`$agent.undeploy: ${addonId} disposed (instance + service + folder)`);
@@ -643,6 +646,67 @@ var path6 = __toESM(require("path"));
643
646
  var fs4 = __toESM(require("fs"));
644
647
  var path4 = __toESM(require("path"));
645
648
  var import_fastify = __toESM(require("fastify"));
649
+
650
+ // src/derive-hub-url.ts
651
+ var HUB_API_PORT = 4443;
652
+ function deriveHubUrlFromHubAddress(hubAddress) {
653
+ const trimmed = hubAddress.trim();
654
+ if (trimmed.length === 0) return void 0;
655
+ const afterAt = trimmed.includes("@") ? trimmed.split("@")[1] ?? "" : trimmed;
656
+ const authority = afterAt.split("/")[0] ?? "";
657
+ const host = extractHostFromAuthority(authority);
658
+ if (host === void 0) return void 0;
659
+ return `https://${host}:${HUB_API_PORT}`;
660
+ }
661
+ function deriveHubUrlForExport(hubUrlWasExplicit, hubAddress) {
662
+ if (hubUrlWasExplicit) return void 0;
663
+ if (hubAddress === void 0) return void 0;
664
+ return deriveHubUrlFromHubAddress(hubAddress);
665
+ }
666
+ function extractHostFromAuthority(authority) {
667
+ const value = authority.trim();
668
+ if (value.length === 0) return void 0;
669
+ if (value.startsWith("[")) {
670
+ const end = value.indexOf("]");
671
+ if (end > 0) return value.slice(0, end + 1);
672
+ return void 0;
673
+ }
674
+ const host = value.split(":")[0] ?? "";
675
+ return host.length > 0 ? host : void 0;
676
+ }
677
+ var HUB_NODE_ID = "hub";
678
+ var IPV4_MAPPED_PREFIX = "::ffff:";
679
+ var IPV4_DOTTED_QUAD = /^\d{1,3}(?:\.\d{1,3}){3}$/;
680
+ function pickIpv4(ipList) {
681
+ if (!ipList) return null;
682
+ for (const ip of ipList) {
683
+ if (ip.includes(":")) continue;
684
+ if (ip.startsWith("127.")) continue;
685
+ return ip;
686
+ }
687
+ return null;
688
+ }
689
+ function normalizeObservedHost(raw) {
690
+ if (raw === void 0 || raw === null) return void 0;
691
+ const trimmed = raw.trim();
692
+ if (trimmed.length === 0) return void 0;
693
+ if (trimmed.startsWith("[")) return trimmed;
694
+ if (trimmed.toLowerCase().startsWith(IPV4_MAPPED_PREFIX)) {
695
+ const mapped = trimmed.slice(IPV4_MAPPED_PREFIX.length);
696
+ if (IPV4_DOTTED_QUAD.test(mapped)) return mapped;
697
+ }
698
+ if (trimmed.includes(":")) return `[${trimmed}]`;
699
+ return trimmed;
700
+ }
701
+ function deriveHubUrlFromRegistry(nodes) {
702
+ const hub = nodes.find((node) => node.id === HUB_NODE_ID);
703
+ if (hub === void 0) return void 0;
704
+ const host = normalizeObservedHost(hub.udpAddress) ?? pickIpv4(hub.ipList) ?? hub.hostname;
705
+ if (host === void 0 || host.length === 0) return void 0;
706
+ return `https://${host}:${HUB_API_PORT}`;
707
+ }
708
+
709
+ // src/agent-http.ts
646
710
  function compareVersions(a, b) {
647
711
  if (a === null && b === null) return 0;
648
712
  if (a === null) return -1;
@@ -704,15 +768,6 @@ function getRegistryNodes(broker) {
704
768
  return [];
705
769
  }
706
770
  }
707
- function pickIpv4(ipList) {
708
- if (!ipList) return null;
709
- for (const ip of ipList) {
710
- if (ip.includes(":")) continue;
711
- if (ip.startsWith("127.")) continue;
712
- return ip;
713
- }
714
- return null;
715
- }
716
771
  function resolveHubEndpoint(nodes) {
717
772
  const hub = nodes.find((n) => n.id === "hub");
718
773
  if (!hub) return null;
@@ -1051,6 +1106,14 @@ var import_system4 = require("@camstack/system");
1051
1106
  var agentLogManager = new import_system4.LogManager(5e3);
1052
1107
  async function startAgent(configPath) {
1053
1108
  const config = loadAgentConfig(configPath);
1109
+ const hubUrlWasExplicit = process.env["CAMSTACK_HUB_URL"] !== void 0;
1110
+ const derivedHubUrl = deriveHubUrlForExport(hubUrlWasExplicit, config.hubAddress);
1111
+ if (derivedHubUrl !== void 0) {
1112
+ process.env["CAMSTACK_HUB_URL"] = derivedHubUrl;
1113
+ console.log(
1114
+ `[Agent] Derived CAMSTACK_HUB_URL=${derivedHubUrl} from hub address "${config.hubAddress}"`
1115
+ );
1116
+ }
1054
1117
  if (config.hubAddress) {
1055
1118
  console.log(
1056
1119
  `[Agent] Starting node "${config.nodeId}" (name="${config.name}") connecting to ${config.hubAddress}`
@@ -1097,6 +1160,13 @@ async function startAgent(configPath) {
1097
1160
  console.log(
1098
1161
  `[Agent] New config: hub=${fresh.hubAddress ?? "discovery"}, secret=${fresh.secret ? "yes" : "none"}`
1099
1162
  );
1163
+ const freshHubUrl = deriveHubUrlForExport(hubUrlWasExplicit, fresh.hubAddress);
1164
+ if (freshHubUrl !== void 0 && process.env["CAMSTACK_HUB_URL"] !== freshHubUrl) {
1165
+ process.env["CAMSTACK_HUB_URL"] = freshHubUrl;
1166
+ console.log(
1167
+ `[Agent] Derived CAMSTACK_HUB_URL=${freshHubUrl} from hub address "${fresh.hubAddress}"`
1168
+ );
1169
+ }
1100
1170
  broker = (0, import_system3.createBroker)({
1101
1171
  nodeID: config.nodeId,
1102
1172
  mode: "agent",
@@ -1361,6 +1431,25 @@ async function startAgent(configPath) {
1361
1431
  (0, import_system3.registerEventBusService)(broker);
1362
1432
  broker.createService((0, import_system3.createHwAccelService)((0, import_system3.createKernelHwAccel)()));
1363
1433
  await broker.start();
1434
+ let hubUrlFromRegistry;
1435
+ const reconcileHubUrlFromRegistry = () => {
1436
+ if (hubUrlWasExplicit) return;
1437
+ const current = process.env["CAMSTACK_HUB_URL"];
1438
+ if (current !== void 0 && current !== hubUrlFromRegistry) return;
1439
+ const fromRegistry = deriveHubUrlFromRegistry(
1440
+ getRegistryNodes(broker)
1441
+ );
1442
+ if (fromRegistry === void 0 || fromRegistry === current) return;
1443
+ process.env["CAMSTACK_HUB_URL"] = fromRegistry;
1444
+ hubUrlFromRegistry = fromRegistry;
1445
+ console.log(`[Agent] Derived CAMSTACK_HUB_URL=${fromRegistry} from live hub connection`);
1446
+ };
1447
+ reconcileHubUrlFromRegistry();
1448
+ broker.localBus.on("$node.connected", (data) => {
1449
+ const node = data.node;
1450
+ if (node?.id !== "hub") return;
1451
+ reconcileHubUrlFromRegistry();
1452
+ });
1364
1453
  let udsEventBridgeDispose = null;
1365
1454
  if (agentUdsRegistry !== void 0) {
1366
1455
  const agentBrokerEventBus = (0, import_system3.getBrokerEventBus)(broker);