@camstack/system 1.2.157 → 1.2.160

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 (77) hide show
  1. package/dist/addon-runner.js +17 -16
  2. package/dist/addon-runner.mjs +2 -1
  3. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  4. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  5. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  6. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  7. package/dist/builtins/alerts/alerts.addon.js +1 -1
  8. package/dist/builtins/alerts/alerts.addon.mjs +1 -1
  9. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.d.ts +10 -7
  10. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +50 -12
  11. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +50 -12
  12. package/dist/builtins/backup-orchestrator/write-targets.d.ts +63 -0
  13. package/dist/builtins/console-logging/index.js +1 -1
  14. package/dist/builtins/console-logging/index.mjs +1 -1
  15. package/dist/builtins/core-blocks/core-blocks.addon.js +1 -1
  16. package/dist/builtins/core-blocks/core-blocks.addon.mjs +1 -1
  17. package/dist/builtins/device-manager/device-bindings-store.d.ts +56 -10
  18. package/dist/builtins/device-manager/device-manager.addon.d.ts +11 -0
  19. package/dist/builtins/device-manager/device-manager.addon.js +216 -81
  20. package/dist/builtins/device-manager/device-manager.addon.mjs +216 -81
  21. package/dist/builtins/device-manager/device-meta-actions.d.ts +9 -3
  22. package/dist/builtins/device-manager/device-meta-store.d.ts +32 -5
  23. package/dist/builtins/device-manager/device-queries.d.ts +7 -3
  24. package/dist/builtins/device-manager/write-lock.d.ts +17 -0
  25. package/dist/builtins/doorbell/virtual-doorbell.addon.js +1 -1
  26. package/dist/builtins/doorbell/virtual-doorbell.addon.mjs +1 -1
  27. package/dist/builtins/hub-forwarder/index.js +1 -1
  28. package/dist/builtins/hub-forwarder/index.mjs +1 -1
  29. package/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  30. package/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  31. package/dist/builtins/local-auth/local-auth.addon.js +1 -1
  32. package/dist/builtins/local-auth/local-auth.addon.mjs +1 -1
  33. package/dist/builtins/local-network/local-network.addon.js +1 -1
  34. package/dist/builtins/local-network/local-network.addon.mjs +1 -1
  35. package/dist/builtins/loki-logging/index.js +1 -1
  36. package/dist/builtins/loki-logging/index.mjs +1 -1
  37. package/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  38. package/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  39. package/dist/builtins/platform-probe/index.js +1 -1
  40. package/dist/builtins/platform-probe/index.mjs +1 -1
  41. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  42. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  43. package/dist/builtins/snapshot/index.js +1 -1
  44. package/dist/builtins/snapshot/index.mjs +1 -1
  45. package/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  46. package/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  47. package/dist/builtins/sqlite-storage/filter-compiler.d.ts +41 -2
  48. package/dist/builtins/sqlite-storage/sqlite-settings-backend.d.ts +15 -7
  49. package/dist/builtins/sqlite-storage/sqlite-settings.addon.js +0 -0
  50. package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +0 -0
  51. package/dist/builtins/sqlite-storage/vector-index-shared.d.ts +30 -5
  52. package/dist/builtins/sqlite-storage/vector-index-vec.d.ts +28 -6
  53. package/dist/builtins/storage-orchestrator/access-guards.d.ts +32 -0
  54. package/dist/builtins/storage-orchestrator/location-secrets.d.ts +33 -0
  55. package/dist/builtins/storage-orchestrator/storage-migration-coordinator.d.ts +74 -3
  56. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.d.ts +26 -0
  57. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +552 -15
  58. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +552 -15
  59. package/dist/builtins/storage-orchestrator/storage-orchestrator.service.d.ts +56 -1
  60. package/dist/builtins/system-config/system-config.addon.js +1 -1
  61. package/dist/builtins/system-config/system-config.addon.mjs +1 -1
  62. package/dist/builtins/winston-logging/index.js +1 -1
  63. package/dist/builtins/winston-logging/index.mjs +1 -1
  64. package/dist/{dist-CDgIzo82.js → dist-CcvXUhHK.js} +537 -17
  65. package/dist/{dist-LvKus-mT.mjs → dist-DKs---Vx.mjs} +520 -18
  66. package/dist/index.js +141 -139
  67. package/dist/index.mjs +3 -3
  68. package/dist/kernel/deps/manifest-system-deps.d.ts +15 -0
  69. package/dist/kernel/index.d.ts +4 -2
  70. package/dist/kernel/moleculer/cap-usage-registry.d.ts +132 -7
  71. package/dist/kernel/storage-location-registry.d.ts +16 -1
  72. package/dist/kernel/transport/local-child-registry.d.ts +57 -0
  73. package/dist/{manifest-python-deps-CD14Pv0-.mjs → manifest-system-deps-DnoPpLGp.mjs} +466 -83
  74. package/dist/{manifest-python-deps-DVODn-qc.js → manifest-system-deps-oJMkWSX-.js} +477 -82
  75. package/dist/{retired-settings-keys-CV4QVdXj.mjs → retired-settings-keys-C3eONTvV.mjs} +1 -1
  76. package/dist/{retired-settings-keys-BfAzWvPC.js → retired-settings-keys-DXZ2xe7C.js} +1 -1
  77. package/package.json +2 -1
@@ -1,4 +1,4 @@
1
- import "./dist-LvKus-mT.mjs";
1
+ import "./dist-DKs---Vx.mjs";
2
2
  import * as crypto$1 from "node:crypto";
3
3
  import { randomBytes, randomUUID } from "node:crypto";
4
4
  import { ensureBinary, ensureFfmpeg, ensurePython, installPythonPackages, installPythonRequirements } from "@camstack/types/node";
@@ -1603,7 +1603,7 @@ function createAddonDataPlaneFacility(args) {
1603
1603
  * Failures THROW with an actionable message — a caller must never proceed as
1604
1604
  * if dependencies were installed when they were not.
1605
1605
  */
1606
- var execFileAsync$1 = promisify(execFile);
1606
+ var execFileAsync$2 = promisify(execFile);
1607
1607
  var DEFAULT_REGISTRY = "https://registry.npmjs.org";
1608
1608
  /** Where the bootstrap lands inside `cacheDir` (npm tgz carries a `package/` prefix). */
1609
1609
  function bootstrappedCliPath(cacheDir) {
@@ -1611,7 +1611,7 @@ function bootstrappedCliPath(cacheDir) {
1611
1611
  }
1612
1612
  async function defaultProbeSystemNpm() {
1613
1613
  try {
1614
- await execFileAsync$1("npm", ["--version"], { timeout: 15e3 });
1614
+ await execFileAsync$2("npm", ["--version"], { timeout: 15e3 });
1615
1615
  return true;
1616
1616
  } catch {
1617
1617
  return false;
@@ -1629,7 +1629,7 @@ async function defaultDownloadTarball(url, destTgz) {
1629
1629
  await fs.promises.writeFile(destTgz, bytes);
1630
1630
  }
1631
1631
  async function defaultExtractTarball(tgzPath, destDir) {
1632
- await execFileAsync$1("tar", [
1632
+ await execFileAsync$2("tar", [
1633
1633
  "-xzf",
1634
1634
  tgzPath,
1635
1635
  "-C",
@@ -1668,7 +1668,7 @@ async function runNpm(args, options) {
1668
1668
  registry: options.registry,
1669
1669
  logger: options.logger
1670
1670
  });
1671
- return execFileAsync$1(invocation.command, [...invocation.argsPrefix, ...args], {
1671
+ return execFileAsync$2(invocation.command, [...invocation.argsPrefix, ...args], {
1672
1672
  ...options.cwd !== void 0 ? { cwd: options.cwd } : {},
1673
1673
  timeout: options.timeout ?? 3e5
1674
1674
  });
@@ -1748,7 +1748,7 @@ function resolveAddonClass(mod) {
1748
1748
  }
1749
1749
  //#endregion
1750
1750
  //#region src/kernel/deps/manifest-native-deps.ts
1751
- var execFileAsync = promisify(execFile);
1751
+ var execFileAsync$1 = promisify(execFile);
1752
1752
  /**
1753
1753
  * Fallback bootstrap-cache location when the caller doesn't thread one
1754
1754
  * through (the forked addon-runner's spawn-time install). tmpdir survives the
@@ -2057,7 +2057,7 @@ async function rebuildNativeDeps(addonDir, packageNames, logger, npmCacheDir, re
2057
2057
  return;
2058
2058
  }
2059
2059
  logger.warn("@electron/rebuild not available — falling back to npx", { meta: { addonDir } });
2060
- await execFileAsync("npx", [
2060
+ await execFileAsync$1("npx", [
2061
2061
  "--yes",
2062
2062
  "electron-rebuild",
2063
2063
  "-m",
@@ -5546,6 +5546,246 @@ function createLocalTransport() {
5546
5546
  };
5547
5547
  }
5548
5548
  //#endregion
5549
+ //#region src/kernel/moleculer/cap-usage-registry.ts
5550
+ /**
5551
+ * In-memory observation of tRPC cap calls between addons — the store behind
5552
+ * `nodes.getCapUsageGraph`.
5553
+ *
5554
+ * Storage: `Map<callerAddonId, Map<providerAddonId, Map<capName, RollingWindow>>>`.
5555
+ * `RollingWindow` is a fixed-size ring of 1-second buckets — default 300
5556
+ * buckets = 5 minutes retention. Queries narrower than the retention window
5557
+ * filter buckets at read time.
5558
+ *
5559
+ * ── The ring ages, and that is not free decoration ─────────────────────────
5560
+ * Buckets are indexed `second % retention`, so a bucket written at second S is
5561
+ * hit again at S + retention·k forever. Until 2026-08-30 nothing ever zeroed
5562
+ * them: the `lastCallAtMs` guard hid it while a triple was fully idle, but ONE
5563
+ * fresh call re-armed the entire stale ring. A triple that made 1000 calls and
5564
+ * then one call five minutes later reported **1001 calls/min instead of 1**.
5565
+ * An over-counted edge is worse than the empty graph this instrument shipped
5566
+ * with — silence invites doubt, a confident wrong number sends the next
5567
+ * investigation at the wrong addon.
5568
+ *
5569
+ * The fix is clear-forward: on each record, zero the buckets the ring has
5570
+ * ADVANCED over since the previous write, and never read past the last written
5571
+ * second. Amortised O(1) — a busy triple clears 0–1 buckets per call, and an
5572
+ * idle one clears at most `retention` once, when it wakes.
5573
+ *
5574
+ * ── Cardinality is bounded, because this map lives on hub-main ─────────────
5575
+ * The previous docblock claimed "~22 MB worst case … under 200 KB at ~10 active
5576
+ * triples". Both numbers were written for a smaller machine and the second was
5577
+ * an assumption, not a bound: the key space is caller × provider × cap, and on
5578
+ * the live hub that is 64 addons × 64 runners × ~150 caps. Nothing capped it.
5579
+ *
5580
+ * Today a ring is one `Uint32Array(retention)` — 1.2 KB of ArrayBuffer at the
5581
+ * default — plus the three Map entries that reach it. MEASURED (`heapUsed` +
5582
+ * `arrayBuffers`, node 24, `--expose-gc`): **1.7 KB per triple**, so ≈1.0 MB at
5583
+ * the realistic hub figure (64 callers × a handful of caps each, ≈600 triples)
5584
+ * and **6.3 MB at the {@link DEFAULT_MAX_TRIPLES} ceiling**. `recordCall` costs
5585
+ * ≈46 ns (1e6 calls in 46 ms) — at the 39 717 calls/min that started this
5586
+ * investigation, ≈30 µs of hub-main per second.
5587
+ *
5588
+ * Reclamation is what keeps it at the low end: a triple whose ring has entirely
5589
+ * aged out is dead data and is dropped on the next admission sweep. The hard
5590
+ * cap only exists so that a pathological key space (a caller id derived from
5591
+ * something unbounded) cannot take hub-main's heap with it — and when it bites,
5592
+ * {@link CapUsageRegistry.getStats} says how often, because an instrument that
5593
+ * truncates silently is the defect this whole file exists to fix (D237).
5594
+ */
5595
+ /** Ring length in seconds when the caller does not pick one. */
5596
+ var DEFAULT_RETENTION_SECONDS = 300;
5597
+ /**
5598
+ * Ceiling on live `(caller, provider, cap)` triples. ≈1.5 KB each → ≈6 MB.
5599
+ * Roughly 6× the realistic hub figure, so it is a backstop against an
5600
+ * unbounded key space, not a working limit.
5601
+ */
5602
+ var DEFAULT_MAX_TRIPLES = 4e3;
5603
+ /**
5604
+ * Provider placeholder for a call the PARENT routed rather than short-
5605
+ * circuiting to a sibling runner: hub-in-process (`settings-store`,
5606
+ * `device-manager`, the `$core-caps` bridge), or a remote node. At the layer
5607
+ * that records — the parent's `cap-call-out` handler — the sibling id IS the
5608
+ * provider and everything else has not been resolved yet.
5609
+ *
5610
+ * It is a NAMED unknown, not a dropped observation, for the reason D237 was
5611
+ * written: the caller is always known, and "who is hammering `settings-store`"
5612
+ * is the question this graph exists to answer. Sibling to
5613
+ * `UNRESOLVED_PROVIDER_ADDON_ID` in `trpc-links.ts`, which names the same kind
5614
+ * of unknown one layer up.
5615
+ */
5616
+ var PARENT_ROUTED_PROVIDER_ADDON_ID = "(unresolved: parent-routed)";
5617
+ var CapUsageRegistry = class {
5618
+ retentionSeconds;
5619
+ maxTriples;
5620
+ map = /* @__PURE__ */ new Map();
5621
+ triples = 0;
5622
+ droppedTriples = 0;
5623
+ constructor(opts) {
5624
+ this.retentionSeconds = Math.max(1, opts?.retentionSeconds ?? DEFAULT_RETENTION_SECONDS);
5625
+ this.maxTriples = Math.max(1, opts?.maxTriples ?? DEFAULT_MAX_TRIPLES);
5626
+ }
5627
+ /**
5628
+ * Record one observed cap call.
5629
+ *
5630
+ * On the hot path: this runs once per cross-process cap call on hub-main's
5631
+ * event loop, which is the cluster's only queue (D181). Three Map lookups, an
5632
+ * integer increment, and — only when the wall clock has moved on — a bounded
5633
+ * clear. No allocation once a triple exists, and it NEVER throws into the
5634
+ * call it observes.
5635
+ */
5636
+ recordCall(rec) {
5637
+ try {
5638
+ if (rec.callerAddonId === "" || rec.providerAddonId === "" || rec.capName === "") return;
5639
+ if (!Number.isFinite(rec.atMs) || rec.atMs < 0) return;
5640
+ const window = this.windowFor(rec);
5641
+ if (window === null) return;
5642
+ const sec = Math.floor(rec.atMs / 1e3);
5643
+ if (window.lastCallAtMs !== 0) {
5644
+ const lastSec = Math.floor(window.lastCallAtMs / 1e3);
5645
+ const advanced = Math.min(sec - lastSec, this.retentionSeconds);
5646
+ for (let k = 1; k <= advanced; k++) window.buckets[(lastSec + k) % this.retentionSeconds] = 0;
5647
+ }
5648
+ const idx = sec % this.retentionSeconds;
5649
+ window.buckets[idx] = (window.buckets[idx] ?? 0) + 1;
5650
+ if (rec.atMs > window.lastCallAtMs) window.lastCallAtMs = rec.atMs;
5651
+ } catch {}
5652
+ }
5653
+ getGraph(opts) {
5654
+ const windowSeconds = Math.max(1, Math.min(opts.windowSeconds, this.retentionSeconds));
5655
+ const minMs = opts.nowMs - windowSeconds * 1e3;
5656
+ const nowSec = Math.floor(opts.nowMs / 1e3);
5657
+ const out = [];
5658
+ for (const [caller, byProvider] of this.map) for (const [provider, byCap] of byProvider) for (const [capName, window] of byCap) {
5659
+ if (window.lastCallAtMs < minMs) continue;
5660
+ const count = this.sumWindow(window, nowSec, windowSeconds);
5661
+ if (count === 0) continue;
5662
+ const callsPerMin = count / windowSeconds * 60;
5663
+ out.push({
5664
+ callerAddonId: caller,
5665
+ providerAddonId: provider,
5666
+ capName,
5667
+ callsPerMin,
5668
+ lastCallAtMs: window.lastCallAtMs
5669
+ });
5670
+ }
5671
+ return out;
5672
+ }
5673
+ /** See {@link CapUsageStats}. Cheap — three counters, no scan. */
5674
+ getStats() {
5675
+ return {
5676
+ triples: this.triples,
5677
+ maxTriples: this.maxTriples,
5678
+ droppedTriples: this.droppedTriples
5679
+ };
5680
+ }
5681
+ /** Test / diagnostic helper — drops all recorded calls. */
5682
+ clear() {
5683
+ this.map.clear();
5684
+ this.triples = 0;
5685
+ this.droppedTriples = 0;
5686
+ }
5687
+ /**
5688
+ * Sum the buckets covering `(nowSec - windowSeconds, nowSec]`.
5689
+ *
5690
+ * The scan starts at `lastSec`, never at `nowSec`. `recordCall` clears the
5691
+ * buckets the ring has advanced OVER, which by definition stops at the last
5692
+ * write: the buckets for the seconds since then still hold whatever the
5693
+ * previous pass left in them, and reading `nowSec` down would count it. A
5694
+ * triple that went quiet for a couple of minutes and then made one call would
5695
+ * report the burst it made five minutes earlier.
5696
+ *
5697
+ * No lower bound is needed beyond the window itself: every bucket at or below
5698
+ * `lastSec - retention` was cleared by the advance that reached `lastSec`, so
5699
+ * it reads zero anyway. The loop is bounded by `windowSeconds ≤ retention`.
5700
+ */
5701
+ sumWindow(window, nowSec, windowSeconds) {
5702
+ const lastSec = Math.floor(window.lastCallAtMs / 1e3);
5703
+ const from = Math.min(nowSec, lastSec);
5704
+ const floorSec = nowSec - windowSeconds;
5705
+ let count = 0;
5706
+ for (let s = from; s > floorSec; s--) count += window.buckets[s % this.retentionSeconds] ?? 0;
5707
+ return count;
5708
+ }
5709
+ /**
5710
+ * The ring for this triple, creating it if the ceiling allows. `null` means
5711
+ * the observation is dropped — counted, never silent (see
5712
+ * {@link CapUsageStats.droppedTriples}).
5713
+ */
5714
+ windowFor(rec) {
5715
+ let byProvider = this.map.get(rec.callerAddonId);
5716
+ if (!byProvider) {
5717
+ byProvider = /* @__PURE__ */ new Map();
5718
+ this.map.set(rec.callerAddonId, byProvider);
5719
+ }
5720
+ let byCap = byProvider.get(rec.providerAddonId);
5721
+ if (!byCap) {
5722
+ byCap = /* @__PURE__ */ new Map();
5723
+ byProvider.set(rec.providerAddonId, byCap);
5724
+ }
5725
+ const existing = byCap.get(rec.capName);
5726
+ if (existing) return existing;
5727
+ if (this.triples >= this.maxTriples) {
5728
+ this.reclaimExpired(rec.atMs);
5729
+ if (this.triples >= this.maxTriples) {
5730
+ this.droppedTriples++;
5731
+ return null;
5732
+ }
5733
+ byProvider = this.map.get(rec.callerAddonId);
5734
+ if (!byProvider) {
5735
+ byProvider = /* @__PURE__ */ new Map();
5736
+ this.map.set(rec.callerAddonId, byProvider);
5737
+ }
5738
+ byCap = byProvider.get(rec.providerAddonId);
5739
+ if (!byCap) {
5740
+ byCap = /* @__PURE__ */ new Map();
5741
+ byProvider.set(rec.providerAddonId, byCap);
5742
+ }
5743
+ }
5744
+ const created = {
5745
+ buckets: new Uint32Array(this.retentionSeconds),
5746
+ lastCallAtMs: 0
5747
+ };
5748
+ byCap.set(rec.capName, created);
5749
+ this.triples++;
5750
+ return created;
5751
+ }
5752
+ /**
5753
+ * Drop every triple whose whole ring has aged out — its last call is older
5754
+ * than the retention window, so it can contribute to no query. O(triples),
5755
+ * and only reachable when the ceiling is full, so it is amortised away by the
5756
+ * admissions it enables.
5757
+ */
5758
+ reclaimExpired(nowMs) {
5759
+ const cutoff = nowMs - this.retentionSeconds * 1e3;
5760
+ for (const [caller, byProvider] of this.map) {
5761
+ for (const [provider, byCap] of byProvider) {
5762
+ for (const [capName, window] of byCap) {
5763
+ if (window.lastCallAtMs >= cutoff) continue;
5764
+ byCap.delete(capName);
5765
+ this.triples--;
5766
+ }
5767
+ if (byCap.size === 0) byProvider.delete(provider);
5768
+ }
5769
+ if (byProvider.size === 0) this.map.delete(caller);
5770
+ }
5771
+ }
5772
+ };
5773
+ var singleton = null;
5774
+ /**
5775
+ * The registry for THIS process. Deliberately per-process: the reader
5776
+ * (`nodes.getCapUsageGraph` → `cap-providers.ts`) runs on hub-main, so only
5777
+ * writes made on hub-main are ever visible. See the blind-spot list on
5778
+ * `LocalChildRegistryOptions.capUsageObserver` for what that excludes.
5779
+ */
5780
+ function getCapUsageRegistry() {
5781
+ if (!singleton) singleton = new CapUsageRegistry();
5782
+ return singleton;
5783
+ }
5784
+ /** Test helper — clears the singleton (kept module-private elsewhere). */
5785
+ function __resetCapUsageRegistryForTests() {
5786
+ singleton = null;
5787
+ }
5788
+ //#endregion
5549
5789
  //#region src/kernel/moleculer/event-bus-core.ts
5550
5790
  /**
5551
5791
  * @param retainRecent - `true` ONLY for the hub main broker bus (it serves
@@ -6237,6 +6477,8 @@ var LocalChildRegistry = class {
6237
6477
  isAddonPinnedCall;
6238
6478
  /** See {@link LocalChildRegistryOptions.capTimeoutMs}. */
6239
6479
  capTimeoutMs;
6480
+ /** See {@link LocalChildRegistryOptions.capUsageObserver}. */
6481
+ capUsageObserver;
6240
6482
  /** Tracks capNames already logged as UDS-routed; one INFO line per capName per process. */
6241
6483
  egressRoutedCaps = /* @__PURE__ */ new Set();
6242
6484
  /** Active event fan-out mode, read once from `CAMSTACK_UDS_EVENT_FANOUT`. */
@@ -6268,6 +6510,7 @@ var LocalChildRegistry = class {
6268
6510
  this.isAggregatedCollectionMethod = opts.isAggregatedCollectionMethod;
6269
6511
  this.isAddonPinnedCall = opts.isAddonPinnedCall;
6270
6512
  this.capTimeoutMs = opts.capTimeoutMs;
6513
+ this.capUsageObserver = opts.capUsageObserver;
6271
6514
  } else {
6272
6515
  this.server = serverOrOptions;
6273
6516
  this.onUnownedCall = onUnownedCallArg;
@@ -6434,6 +6677,29 @@ var LocalChildRegistry = class {
6434
6677
  }
6435
6678
  return candidates[0];
6436
6679
  }
6680
+ /**
6681
+ * Publish one cap-usage observation, if a sink is wired.
6682
+ *
6683
+ * Cost discipline — this is on the hot path (D181: hub-main's event loop is
6684
+ * the cluster's only queue): no sink means one undefined check; with a sink
6685
+ * it is one object literal and one `Date.now()`, and the sink itself is O(1).
6686
+ * Wrapped so a broken observer can never fail the call it observes — the
6687
+ * registry swallows too, and BOTH matter: this catch also covers a sink that
6688
+ * is not the registry.
6689
+ */
6690
+ recordCapUsage(callerChildId, providerChildId, capName, methodName) {
6691
+ const sink = this.capUsageObserver;
6692
+ if (sink === void 0 || callerChildId === null) return;
6693
+ try {
6694
+ sink({
6695
+ callerAddonId: callerChildId,
6696
+ providerAddonId: providerChildId ?? "(unresolved: parent-routed)",
6697
+ capName,
6698
+ methodName,
6699
+ atMs: Date.now()
6700
+ });
6701
+ } catch {}
6702
+ }
6437
6703
  /** First child whose cap manifest contains a descriptor matching `predicate`. */
6438
6704
  findChildId(predicate) {
6439
6705
  for (const entry of this.children.values()) if (entry.caps.some(predicate)) return entry.childId;
@@ -6703,7 +6969,9 @@ var LocalChildRegistry = class {
6703
6969
  const pinTargetsThisNode = pinnedNodeId !== void 0 && this.ownNodeId !== void 0 && pinnedNodeId === this.ownNodeId;
6704
6970
  const aggregated = pinnedNodeId === void 0 && this.isAggregatedCollectionMethod?.(out.capName, out.method) === true;
6705
6971
  const addonPinned = pinnedNodeId === void 0 && this.isAddonPinnedCall?.(out.capName, out.method, out.args) === true;
6706
- if ((!(out.native === true) && !aggregated && !addonPinned && (pinnedNodeId === void 0 || pinTargetsThisNode) ? this.resolveChildId(out.capName, out.deviceId) : null) !== null) {
6972
+ const target = !(out.native === true) && !aggregated && !addonPinned && (pinnedNodeId === void 0 || pinTargetsThisNode) ? this.resolveChildId(out.capName, out.deviceId) : null;
6973
+ this.recordCapUsage(childId, target, out.capName, out.method);
6974
+ if (target !== null) {
6707
6975
  if (!this.egressRoutedCaps.has(out.capName)) {
6708
6976
  this.egressRoutedCaps.add(out.capName);
6709
6977
  this.logger?.info("routed child egress over UDS", { capName: out.capName });
@@ -7855,80 +8123,6 @@ function buildLinkChain(target, localResolver, hookup) {
7855
8123
  return links;
7856
8124
  }
7857
8125
  //#endregion
7858
- //#region src/kernel/moleculer/cap-usage-registry.ts
7859
- var CapUsageRegistry = class {
7860
- retentionSeconds;
7861
- map = /* @__PURE__ */ new Map();
7862
- constructor(opts) {
7863
- this.retentionSeconds = Math.max(1, opts?.retentionSeconds ?? 300);
7864
- }
7865
- recordCall(rec) {
7866
- try {
7867
- if (rec.callerAddonId === "" || rec.providerAddonId === "" || rec.capName === "") return;
7868
- if (!Number.isFinite(rec.atMs) || rec.atMs < 0) return;
7869
- let byProvider = this.map.get(rec.callerAddonId);
7870
- if (!byProvider) {
7871
- byProvider = /* @__PURE__ */ new Map();
7872
- this.map.set(rec.callerAddonId, byProvider);
7873
- }
7874
- let byCap = byProvider.get(rec.providerAddonId);
7875
- if (!byCap) {
7876
- byCap = /* @__PURE__ */ new Map();
7877
- byProvider.set(rec.providerAddonId, byCap);
7878
- }
7879
- let window = byCap.get(rec.capName);
7880
- if (!window) {
7881
- window = {
7882
- buckets: Array.from({ length: this.retentionSeconds }, () => 0),
7883
- lastCallAtMs: 0
7884
- };
7885
- byCap.set(rec.capName, window);
7886
- }
7887
- const bucketIdx = Math.floor(rec.atMs / 1e3) % this.retentionSeconds;
7888
- window.buckets[bucketIdx] = (window.buckets[bucketIdx] ?? 0) + 1;
7889
- if (rec.atMs > window.lastCallAtMs) window.lastCallAtMs = rec.atMs;
7890
- } catch {}
7891
- }
7892
- getGraph(opts) {
7893
- const windowSeconds = Math.max(1, Math.min(opts.windowSeconds, this.retentionSeconds));
7894
- const minMs = opts.nowMs - windowSeconds * 1e3;
7895
- const out = [];
7896
- for (const [caller, byProvider] of this.map) for (const [provider, byCap] of byProvider) for (const [capName, window] of byCap) {
7897
- if (window.lastCallAtMs < minMs) continue;
7898
- const nowBucket = Math.floor(opts.nowMs / 1e3);
7899
- let count = 0;
7900
- for (let i = 0; i < windowSeconds; i++) {
7901
- const b = (nowBucket - i + this.retentionSeconds * 1e6) % this.retentionSeconds;
7902
- count += window.buckets[b] ?? 0;
7903
- }
7904
- if (count === 0) continue;
7905
- const callsPerMin = count / windowSeconds * 60;
7906
- out.push({
7907
- callerAddonId: caller,
7908
- providerAddonId: provider,
7909
- capName,
7910
- callsPerMin,
7911
- lastCallAtMs: window.lastCallAtMs
7912
- });
7913
- }
7914
- return out;
7915
- }
7916
- /** Test / diagnostic helper — drops all recorded calls. */
7917
- clear() {
7918
- this.map.clear();
7919
- }
7920
- };
7921
- var singleton = null;
7922
- /** Hub-side singleton. The first caller seeds it; subsequent calls return the same. */
7923
- function getCapUsageRegistry() {
7924
- if (!singleton) singleton = new CapUsageRegistry();
7925
- return singleton;
7926
- }
7927
- /** Test helper — clears the singleton (kept module-private elsewhere). */
7928
- function __resetCapUsageRegistryForTests() {
7929
- singleton = null;
7930
- }
7931
- //#endregion
7932
8126
  //#region src/kernel/hwaccel/hwaccel-resolver.ts
7933
8127
  /**
7934
8128
  * Platform-probe for hardware video decode acceleration.
@@ -9500,4 +9694,193 @@ async function installManifestPythonDeps(declaration, addonDir, deps, logger) {
9500
9694
  await deps.installPythonRequirements(reqAbs);
9501
9695
  }
9502
9696
  //#endregion
9503
- export { buildNativeCapProxy as $, RUNNER_HEAP_SNAPSHOT_ENV as $t, createParentUnownedCallHandler as A, HUB_MAIN_HEAP_WATCH_LABEL as At, AGENT_CAP_FWD_SERVICE as B, createLoopDelayMeter as Bt, brokerTransportLink as C, runNpm as Ct, HUB_CAP_FWD_ACTION as D, HEAP_RECLAIM_TRIGGER_MB as Dt, localProviderLink as E, HEAP_RECLAIM_STEADY_STATE_INTERVAL_MS as Et, createUdsLoggerWithControl as F, RUNNER_HEAP_WATCH_INTERVAL_MS as Ft, readMoleculerFanoutMode as G, parseRssBudgetMb as Gt, CapRouteError as H, describeRss as Ht, LocalChildClient as I, RUNNER_RSS_BUDGET_ENV as It, UdsLocalTransportServer as J, startHeapWatch as Jt, createLocalTransport as K, reclaimIntervalMs as Kt, LocalChildRegistry as L, ZERO_LOOP_DELAY as Lt, createUdsEventBus as M, HUB_RSS_BUDGET_ENV as Mt, udsChildLogToWorkerEntry as N, RSS_BUDGET_REANNOUNCE_MIN_MS as Nt, HUB_CAP_FWD_SERVICE as O, HEAP_WATCH_INTERVAL_MS as Ot, createUdsLogger as P, RSS_BUDGET_RELEASE_RATIO as Pt, encodeFrame as Q, HEAP_SPACE_REPORT_MIN_MB as Qt, UDS_NO_ROUTE_PREFIX as R, buildHeapSample as Rt, brokerCallForCap as S, formatEventPlane as Sn, resolveNpmInvocation as St, ipcParentLink as T, HEAP_RECLAIM_MIN_INTERVAL_MS as Tt, classifyCapRoute as U, hubMainRssBudget as Ut, CapRouteResolver as V, createV8Reclaimer as Vt, callWithServiceDiscovery as W, nextRssBudgetState as Wt, localEndpointPath as X, strandedMb as Xt, SocketChannel as Y, startRunnerHeapWatch as Yt, FrameDecoder as Z, DECISIVE_HEAP_SPACES as Zt, createKernelHwAccel as _, socketDirectionMessages as _n, CapabilityHandle as _t, getWorkerDeviceRegistry as a, selectReportedSpaces as an, setWorkerNativeCapsChangeListener as at, __resetCapUsageRegistryForTests as b, createEventPlaneReader as bn, installManifestNativeDeps as bt, setHubConnected as c, createSocketPlaneMeter as cn, NATIVE_PROVIDER_SERVICE_INFIX as ct, getBrokerEventBus as d, formatSocketPlane as dn, capBareAction as dt, emitHeapDiagnosticReport as en, buildUdsNativeCapProxy as et, getMoleculerEventStats as f, EMPTY_SOCKET_DIRECTION as fn, capServiceName as ft, AddonDepsManager as g, socketDirectionBytes as gn, DeviceRegistry as gt, subscribePassthrough as h, sampleSocketDirection as hn, serializeTypedArrays as ht, createUdsAddonContext as i, readHeapSpaces as in, mountNativeCapService as it, createUdsEventBridge as j, HUB_MAIN_RSS_BUDGET_MB as jt, createHubCapForwardService as k, HEAP_WATCH_WARN_RATIO as kt, EVENT_TOPIC_PREFIX as l, createSocketPlaneReader as ln, capActionName as lt, setNodeEventInterest as m, recordSocketFrame as mn, deserializeTypedArrays as mt, adaptBrokerToCluster as n, heapSnapshotAuthorised as nn, getWorkerNativeCapProvider as nt, getOrInitReadinessRegistry as o, EMPTY_SOCKET_PLANE_BASELINE as on, createAddonService as ot, registerEventBusService as p, createSocketDirectionCounters as pn, parseCapAction as pt, UdsLocalTransportClient as q, shouldReclaim as qt, createAddonContext as r, heapSpaceField as rn, getWorkerNativeCapSnapshot as rt, getOrInitReadinessRegistryForClient as s, SOCKET_PLANE_TOP_N as sn, validateProviderRegistrations as st, installManifestPythonDeps as t, formatHeapSpaces as tn, createBrokerDeviceManagerApi as tt, clusterEventTopic as u, diffSocketPlane as un, capActionSuffix as ut, resolveHwAccel as v, EVENT_PLANE_TOP_N as vn, CapabilityUnavailableError as vt, buildLinkChain as w, createAddonDataPlaneFacility as wt, getCapUsageRegistry as x, diffEventPlane as xn, resolveAddonClass as xt, CapUsageRegistry as y, createEventPlaneMeter as yn, copyBundledNativeModules as yt, AGENT_CAP_FWD_ACTION as z, createDeferredHeapWatchSink as zt };
9697
+ //#region src/kernel/deps/manifest-system-deps.ts
9698
+ /**
9699
+ * Auto-install the host binaries declared in an addon's manifest
9700
+ * (`camstack.addons[].systemDependencies`) before `onInitialize()` runs.
9701
+ *
9702
+ * ── Why this is framework and not addon-local ──────────────────────────────
9703
+ * The Python precedent (`camstack.addons[].python.requirements` →
9704
+ * `installManifestPythonDeps`, called from the same place in
9705
+ * `addon-runner.ts`) already answers "this addon needs something installed,
9706
+ * satisfy it before its caps register". A binary is the same question with a
9707
+ * different package manager, so it gets the same mechanism rather than a
9708
+ * second one per addon — CLAUDE.md forbids a parallel answer where one exists,
9709
+ * and the next addon that needs `rclone` or `mediainfo` inherits this for
9710
+ * free instead of copying a startup routine.
9711
+ *
9712
+ * ── The four things this has to get right ──────────────────────────────────
9713
+ * 1. **Cheap on the common path.** The binary is probed first; the package
9714
+ * manager is only invoked when it is genuinely absent. Runners respawn
9715
+ * routinely (deploys, updates, crash recovery) and a network round-trip on
9716
+ * every boot is a cost the Python mechanism does not impose either.
9717
+ * 2. **Runs every boot, not once.** The install lands INSIDE the container
9718
+ * and is lost on every image update. That is expected. "Already
9719
+ * installed" is a success, not an error.
9720
+ * 3. **Honest, not fatal.** A failure warns and returns. The addon still
9721
+ * loads; the capability that wraps the binary is responsible for refusing
9722
+ * loudly on its own surface. Aborting the runner here would take the
9723
+ * addon's SIBLINGS down with it (they share `execution.group`).
9724
+ * 4. **Platform reality is stated, not assumed.** An unsupported host logs
9725
+ * which manager it looked for and continues. Silence would read as
9726
+ * "installed".
9727
+ *
9728
+ * Every branch that declines to install SAYS SO. A dependency step that
9729
+ * produced no line at all is indistinguishable from one that never ran, and
9730
+ * the failure it precedes ("smbclient: ENOENT") arrives minutes later in a
9731
+ * different addon's logs.
9732
+ */
9733
+ var execFileAsync = promisify(execFile);
9734
+ /** How long a single package-manager invocation may take. */
9735
+ var INSTALL_TIMEOUT_MS = 300 * 1e3;
9736
+ /** How long the `command -v <binary>` presence probe may take. */
9737
+ var PROBE_TIMEOUT_MS = 1e4;
9738
+ /**
9739
+ * Satisfy every `systemDependencies` entry the declaration carries.
9740
+ * Resolves regardless of outcome — see the docblock.
9741
+ */
9742
+ async function installManifestSystemDeps(declaration, logger, options = {}) {
9743
+ const deps = declaration.systemDependencies;
9744
+ if (!deps || deps.length === 0) return;
9745
+ const hasBinary = options.hasBinary ?? defaultHasBinary;
9746
+ const detectManager = options.detectManager ?? defaultDetectManager;
9747
+ const run = options.run ?? defaultRun;
9748
+ const platform = options.platform ?? process.platform;
9749
+ for (const dep of deps) try {
9750
+ await satisfyOne(dep, declaration.id, {
9751
+ hasBinary,
9752
+ detectManager,
9753
+ run,
9754
+ platform
9755
+ }, logger);
9756
+ } catch (err) {
9757
+ logger.warn("system dependency step failed", { meta: {
9758
+ addonId: declaration.id,
9759
+ binary: dep.binary,
9760
+ error: err instanceof Error ? err.message : String(err)
9761
+ } });
9762
+ }
9763
+ }
9764
+ async function satisfyOne(dep, addonId, rt, logger) {
9765
+ if (await rt.hasBinary(dep.binary)) {
9766
+ logger.debug("system dependency already present", { meta: {
9767
+ addonId,
9768
+ binary: dep.binary
9769
+ } });
9770
+ return;
9771
+ }
9772
+ const manager = await rt.detectManager();
9773
+ if (manager === null) {
9774
+ logger.warn("system dependency missing and no supported package manager on this host", { meta: {
9775
+ addonId,
9776
+ binary: dep.binary,
9777
+ platform: rt.platform,
9778
+ ...dep.reason !== void 0 ? { reason: dep.reason } : {}
9779
+ } });
9780
+ return;
9781
+ }
9782
+ const packageName = dep.packages[manager];
9783
+ if (packageName === void 0 || packageName.length === 0) {
9784
+ logger.warn("system dependency missing and the addon declares no package for this manager", { meta: {
9785
+ addonId,
9786
+ binary: dep.binary,
9787
+ manager,
9788
+ ...dep.reason !== void 0 ? { reason: dep.reason } : {}
9789
+ } });
9790
+ return;
9791
+ }
9792
+ const plan = planFor(manager, packageName);
9793
+ logger.info("installing system dependency", { meta: {
9794
+ addonId,
9795
+ binary: dep.binary,
9796
+ manager,
9797
+ package: packageName
9798
+ } });
9799
+ try {
9800
+ for (const [command, args] of plan.steps) await rt.run(command, args);
9801
+ } catch (err) {
9802
+ logger.warn("system dependency install failed — the addon loads, its capability must refuse", { meta: {
9803
+ addonId,
9804
+ binary: dep.binary,
9805
+ manager,
9806
+ package: packageName,
9807
+ error: err instanceof Error ? err.message : String(err),
9808
+ ...dep.reason !== void 0 ? { reason: dep.reason } : {}
9809
+ } });
9810
+ return;
9811
+ }
9812
+ if (!await rt.hasBinary(dep.binary)) {
9813
+ logger.warn("system dependency installed but the binary still does not resolve", { meta: {
9814
+ addonId,
9815
+ binary: dep.binary,
9816
+ manager,
9817
+ package: packageName
9818
+ } });
9819
+ return;
9820
+ }
9821
+ logger.info("system dependency installed", { meta: {
9822
+ addonId,
9823
+ binary: dep.binary,
9824
+ manager,
9825
+ package: packageName
9826
+ } });
9827
+ }
9828
+ function planFor(manager, packageName) {
9829
+ switch (manager) {
9830
+ case "apt": return {
9831
+ manager,
9832
+ steps: [["apt-get", ["update"]], ["apt-get", [
9833
+ "install",
9834
+ "-y",
9835
+ "--no-install-recommends",
9836
+ packageName
9837
+ ]]]
9838
+ };
9839
+ case "apk": return {
9840
+ manager,
9841
+ steps: [["apk", [
9842
+ "add",
9843
+ "--no-cache",
9844
+ packageName
9845
+ ]]]
9846
+ };
9847
+ case "dnf": return {
9848
+ manager,
9849
+ steps: [["dnf", [
9850
+ "install",
9851
+ "-y",
9852
+ packageName
9853
+ ]]]
9854
+ };
9855
+ case "brew": return {
9856
+ manager,
9857
+ steps: [["brew", ["install", packageName]]]
9858
+ };
9859
+ }
9860
+ }
9861
+ async function defaultHasBinary(binary) {
9862
+ try {
9863
+ await execFileAsync("command", ["-v", binary], {
9864
+ timeout: PROBE_TIMEOUT_MS,
9865
+ shell: process.platform === "win32" ? false : "/bin/sh"
9866
+ });
9867
+ return true;
9868
+ } catch {
9869
+ return false;
9870
+ }
9871
+ }
9872
+ async function defaultDetectManager() {
9873
+ const candidates = os.platform() === "darwin" ? ["brew"] : [
9874
+ "apt",
9875
+ "apk",
9876
+ "dnf",
9877
+ "brew"
9878
+ ];
9879
+ for (const candidate of candidates) if (await defaultHasBinary(candidate === "apt" ? "apt-get" : candidate)) return candidate;
9880
+ return null;
9881
+ }
9882
+ async function defaultRun(command, args) {
9883
+ await execFileAsync(command, [...args], { timeout: INSTALL_TIMEOUT_MS });
9884
+ }
9885
+ //#endregion
9886
+ export { FrameDecoder as $, DECISIVE_HEAP_SPACES as $t, createUdsEventBus as A, HEAP_WATCH_INTERVAL_MS as At, CapRouteError as B, buildHeapSample as Bt, ipcParentLink as C, diffEventPlane as Cn, resolveAddonClass as Ct, createHubCapForwardService as D, HEAP_RECLAIM_MIN_INTERVAL_MS as Dt, HUB_CAP_FWD_SERVICE as E, createAddonDataPlaneFacility as Et, LocalChildRegistry as F, RSS_BUDGET_REANNOUNCE_MIN_MS as Ft, PARENT_ROUTED_PROVIDER_ADDON_ID as G, hubMainRssBudget as Gt, callWithServiceDiscovery as H, createLoopDelayMeter as Ht, UDS_NO_ROUTE_PREFIX as I, RSS_BUDGET_RELEASE_RATIO as It, createLocalTransport as J, reclaimIntervalMs as Jt, __resetCapUsageRegistryForTests as K, nextRssBudgetState as Kt, AGENT_CAP_FWD_ACTION as L, RUNNER_HEAP_WATCH_INTERVAL_MS as Lt, createUdsLogger as M, HUB_MAIN_HEAP_WATCH_LABEL as Mt, createUdsLoggerWithControl as N, HUB_MAIN_RSS_BUDGET_MB as Nt, createParentUnownedCallHandler as O, HEAP_RECLAIM_STEADY_STATE_INTERVAL_MS as Ot, LocalChildClient as P, HUB_RSS_BUDGET_ENV as Pt, localEndpointPath as Q, strandedMb as Qt, AGENT_CAP_FWD_SERVICE as R, RUNNER_RSS_BUDGET_ENV as Rt, buildLinkChain as S, createEventPlaneReader as Sn, installManifestNativeDeps as St, HUB_CAP_FWD_ACTION as T, runNpm as Tt, readMoleculerFanoutMode as U, createV8Reclaimer as Ut, classifyCapRoute as V, createDeferredHeapWatchSink as Vt, CapUsageRegistry as W, describeRss as Wt, UdsLocalTransportServer as X, startHeapWatch as Xt, UdsLocalTransportClient as Y, shouldReclaim as Yt, SocketChannel as Z, startRunnerHeapWatch as Zt, AddonDepsManager as _, sampleSocketDirection as _n, serializeTypedArrays as _t, createUdsAddonContext as a, heapSpaceField as an, getWorkerNativeCapSnapshot as at, brokerCallForCap as b, EVENT_PLANE_TOP_N as bn, CapabilityUnavailableError as bt, getOrInitReadinessRegistryForClient as c, EMPTY_SOCKET_PLANE_BASELINE as cn, createAddonService as ct, clusterEventTopic as d, createSocketPlaneReader as dn, capActionName as dt, HEAP_SPACE_REPORT_MIN_MB as en, encodeFrame as et, getBrokerEventBus as f, diffSocketPlane as fn, capActionSuffix as ft, subscribePassthrough as g, recordSocketFrame as gn, deserializeTypedArrays as gt, setNodeEventInterest as h, createSocketDirectionCounters as hn, parseCapAction as ht, createAddonContext as i, heapSnapshotAuthorised as in, getWorkerNativeCapProvider as it, udsChildLogToWorkerEntry as j, HEAP_WATCH_WARN_RATIO as jt, createUdsEventBridge as k, HEAP_RECLAIM_TRIGGER_MB as kt, setHubConnected as l, SOCKET_PLANE_TOP_N as ln, validateProviderRegistrations as lt, registerEventBusService as m, EMPTY_SOCKET_DIRECTION as mn, capServiceName as mt, installManifestPythonDeps as n, emitHeapDiagnosticReport as nn, buildUdsNativeCapProxy as nt, getWorkerDeviceRegistry as o, readHeapSpaces as on, mountNativeCapService as ot, getMoleculerEventStats as p, formatSocketPlane as pn, capBareAction as pt, getCapUsageRegistry as q, parseRssBudgetMb as qt, adaptBrokerToCluster as r, formatHeapSpaces as rn, createBrokerDeviceManagerApi as rt, getOrInitReadinessRegistry as s, selectReportedSpaces as sn, setWorkerNativeCapsChangeListener as st, installManifestSystemDeps as t, RUNNER_HEAP_SNAPSHOT_ENV as tn, buildNativeCapProxy as tt, EVENT_TOPIC_PREFIX as u, createSocketPlaneMeter as un, NATIVE_PROVIDER_SERVICE_INFIX as ut, createKernelHwAccel as v, socketDirectionBytes as vn, DeviceRegistry as vt, localProviderLink as w, formatEventPlane as wn, resolveNpmInvocation as wt, brokerTransportLink as x, createEventPlaneMeter as xn, copyBundledNativeModules as xt, resolveHwAccel as y, socketDirectionMessages as yn, CapabilityHandle as yt, CapRouteResolver as z, ZERO_LOOP_DELAY as zt };