@camstack/server 1.2.194 → 1.2.196

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.
@@ -524,6 +524,14 @@ async function startAgent(configPath) {
524
524
  // cap). A pin to ANOTHER node still bypasses the sibling → onUnownedCall.
525
525
  ownNodeId: agentNodeId,
526
526
  onUnownedCall,
527
+ // NO `capUsageObserver` here, deliberately. `getCapUsageRegistry()` is a
528
+ // per-process singleton and the reader (`nodes.getCapUsageGraph`) runs on
529
+ // hub-main; recording in the agent would produce a map nobody ever reads,
530
+ // which is exactly the shape that made this graph return `[]` for
531
+ // months. An agent's addon traffic is a KNOWN blind spot of the graph —
532
+ // see `LocalChildRegistryOptions.capUsageObserver`. Closing it needs the
533
+ // caller identity to survive `$hub-cap-fwd`'s envelope, which today it
534
+ // does not.
527
535
  });
528
536
  await agentUdsRegistry.start();
529
537
  // E1: apply child manifest + cleanup from the UDS lifecycle (agent-local children).
@@ -623,8 +623,34 @@ function buildNodesProvider(agentRegistry, moleculer, addonRegistry, getNodeRoot
623
623
  }
624
624
  return result;
625
625
  },
626
+ /**
627
+ * Observed caller → provider → cap edges over the last `windowSeconds`.
628
+ *
629
+ * **Read the blind spots before drawing a conclusion.** This reads
630
+ * hub-main's `CapUsageRegistry`, written by the hub's `LocalChildRegistry`
631
+ * on every `cap-call-out` a hub-local forked addon sends. It therefore does
632
+ * NOT contain: hub-main → hub-main in-process calls (one shared `ctx.api`
633
+ * client, no per-caller identity), a runner's own co-located calls, or any
634
+ * traffic originating on an agent. An edge missing here means "not seen on
635
+ * this plane", never "did not happen" — the full list is on
636
+ * `LocalChildRegistryOptions.capUsageObserver`.
637
+ */
626
638
  getCapUsageGraph: async (input) => {
627
639
  const reg = (0, system_1.getCapUsageRegistry)();
640
+ const stats = reg.getStats();
641
+ if (stats.droppedTriples > 0) {
642
+ // The registry is bounded (it lives on hub-main — D181). If it ever
643
+ // truncates, the operator asking this question is told, because a
644
+ // silently incomplete diagnostic is the defect this surface exists to
645
+ // fix (D237).
646
+ logger?.warn('cap-usage graph is truncated — the triple ceiling was reached', {
647
+ meta: {
648
+ triples: stats.triples,
649
+ maxTriples: stats.maxTriples,
650
+ droppedTriples: stats.droppedTriples,
651
+ },
652
+ });
653
+ }
628
654
  return reg.getGraph({ windowSeconds: input.windowSeconds, nowMs: Date.now() });
629
655
  },
630
656
  setProcessLogLevel: async (input) => {
@@ -6292,6 +6292,15 @@ function createCapRouter_pipelineAnalytics(getProvider, createRemoteProxy) {
6292
6292
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
6293
6293
  return p.listTrackMedia(methodInput);
6294
6294
  }),
6295
+ listEventMedia: trpc_middleware_js_1.protectedProcedure
6296
+ .input(types_85.pipelineAnalyticsCapability.methods.listEventMedia.input.loose())
6297
+ .output(types_85.pipelineAnalyticsCapability.methods.listEventMedia.output)
6298
+ .query(async ({ input, ctx }) => {
6299
+ const { nodeId, ...methodInput } = input;
6300
+ const p = resolveProvider('pipeline-analytics', nodeId, () => getProvider(ctx), createRemoteProxy);
6301
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
6302
+ return p.listEventMedia(methodInput);
6303
+ }),
6295
6304
  searchObjectEvents: trpc_middleware_js_1.protectedProcedure
6296
6305
  .input(types_85.pipelineAnalyticsCapability.methods.searchObjectEvents.input.loose())
6297
6306
  .output(types_85.pipelineAnalyticsCapability.methods.searchObjectEvents.output)
@@ -940,8 +940,12 @@ class AddonPackageService {
940
940
  this.requireInstaller();
941
941
  const addonInstaller = this.installer;
942
942
  const previousVersion = this.getInstalledPackageVersion(name);
943
- // getInstalledPackageVersion returns '' when not installed
944
- const isFirstInstall = !previousVersion;
943
+ // `null` = no readable installed copy, which is exactly a first
944
+ // install. This used to test the truthiness of a lookup that answered
945
+ // `'0.0.0'` when it found nothing — always truthy — so a genuine first
946
+ // install took the update path and `applyUpdate` threw "not currently
947
+ // tracked in manifest".
948
+ const isFirstInstall = previousVersion === null;
945
949
  // First-time installs go through the original installFromNpm path;
946
950
  // applyUpdate explicitly refuses when the package isn't tracked yet.
947
951
  // Subsequent updates take the safe path: backup current install,
@@ -979,13 +983,16 @@ class AddonPackageService {
979
983
  const targetDir = path.join(addonsDir, dirName);
980
984
  const packageSpec = version ? `${name}@${version}` : name;
981
985
  await installPackageFromNpm(packageSpec, targetDir);
982
- updatedVersion = this.getInstalledPackageVersion(name);
986
+ // Core packages install FLAT (`<addonsDir>/<dirName>`), which the
987
+ // installer's lookup covers alongside the scoped form.
988
+ const installedVersion = this.getInstalledPackageVersion(name);
989
+ updatedVersion = installedVersion ?? '';
983
990
  // Invalidate cache after update
984
991
  this.cachedUpdates = null;
985
992
  this.logger.info('Core package updated -- restart required', {
986
- meta: { name, updatedVersion },
993
+ meta: { name, updatedVersion: installedVersion },
987
994
  });
988
- this.sendUpdateNotification(name, updatedVersion);
995
+ this.sendUpdateNotification(name, installedVersion);
989
996
  return { success: true, version: updatedVersion, requiresRestart: true };
990
997
  }
991
998
  catch (error) {
@@ -1749,38 +1756,40 @@ class AddonPackageService {
1749
1756
  // Private: general helpers
1750
1757
  // =========================================================================
1751
1758
  /**
1752
- * Read the currently installed version of a package.
1753
- * Checks data/addons/ first, then falls back to Node module resolution.
1754
- * Returns '0.0.0' if not found.
1759
+ * The version of `packageName` INSTALLED RIGHT NOW, or `null` when the hub
1760
+ * has no readable copy.
1761
+ *
1762
+ * Delegates to the installer, which is the one place that knows the on-disk
1763
+ * layout (`<addonsDir>/@camstack/<pkg>/`, with the pre-scope flat form as a
1764
+ * fallback). This method used to restate that path and got it wrong —
1765
+ * `packageName.replace(/^@camstack\//, '')` looked ONLY in the flat form, so
1766
+ * every scoped install missed. It then fell back to
1767
+ * `require.resolve('<pkg>/package.json')`, which cannot succeed either: an
1768
+ * addon is installed under the data directory, not in the hub's own
1769
+ * node_modules. Both misses landed on the literal `'0.0.0'`, and that string
1770
+ * was published on the `addon.updated` event as the version the operator had
1771
+ * been running ("@camstack/addon-terminal 0.0.0 → latest", 2026-08-30).
1772
+ *
1773
+ * `null`, not `'0.0.0'`: a version nobody installed is indistinguishable
1774
+ * from one that was, and the caller must be forced to decide what to say
1775
+ * about "unknown" rather than inherit a number that looks like an answer.
1755
1776
  */
1756
1777
  getInstalledPackageVersion(packageName) {
1757
1778
  try {
1758
- const addonsDir = this.resolveAddonsDir();
1759
- const dirName = packageName.replace(/^@camstack\//, '');
1760
- const pkgJsonPath = path.join(addonsDir, dirName, 'package.json');
1761
- if (fs.existsSync(pkgJsonPath)) {
1762
- const pkgJson = readJsonObject(pkgJsonPath);
1763
- const v = asString(pkgJson?.['version']);
1764
- if (v)
1765
- return v;
1766
- }
1779
+ const installed = this.installer?.getInstalledPackage(packageName) ?? null;
1780
+ const version = installed === null ? '' : asString(installed.version);
1781
+ if (version)
1782
+ return version;
1767
1783
  }
1768
1784
  catch (err) {
1769
- this.logger.debug('Version lookup via fs failed, trying require.resolve', {
1785
+ this.logger.debug('Installed-version lookup failed', {
1770
1786
  meta: { packageName, error: (0, types_1.errMsg)(err) },
1771
1787
  });
1772
1788
  }
1773
- try {
1774
- const pkgJsonPath = require.resolve(`${packageName}/package.json`);
1775
- const pkgJson = readJsonObject(pkgJsonPath);
1776
- return asString(pkgJson?.['version'], '0.0.0');
1777
- }
1778
- catch (err) {
1779
- this.logger.debug('Could not resolve version, returning 0.0.0', {
1780
- meta: { packageName, error: (0, types_1.errMsg)(err) },
1781
- });
1782
- return '0.0.0';
1783
- }
1789
+ this.logger.debug('No readable installed copy — previous version is unknown', {
1790
+ meta: { packageName },
1791
+ });
1792
+ return null;
1784
1793
  }
1785
1794
  /** Only allow @camstack/* scoped packages */
1786
1795
  isAllowedPackage(name) {
@@ -1838,12 +1847,19 @@ class AddonPackageService {
1838
1847
  throw new Error('AddonInstaller is not available -- @camstack/system may not be installed');
1839
1848
  }
1840
1849
  }
1841
- /** Send notification and toast for a successful package update */
1850
+ /**
1851
+ * Send notification and toast for a successful package update.
1852
+ *
1853
+ * `version === null` means the hub could not read back what it just
1854
+ * installed. The sentence then says the package was updated and stops —
1855
+ * never "updated to v0.0.0", which reads as a real version.
1856
+ */
1842
1857
  sendUpdateNotification(name, version) {
1858
+ const sentence = version === null ? `${name} updated` : `${name} updated to v${version}`;
1843
1859
  this.notificationService
1844
1860
  .notify({
1845
1861
  title: 'Package Updated',
1846
- body: `${name} updated to v${version}`,
1862
+ body: sentence,
1847
1863
  format: 'text',
1848
1864
  priority: 3,
1849
1865
  category: 'system',
@@ -1855,7 +1871,7 @@ class AddonPackageService {
1855
1871
  });
1856
1872
  this.toastService.broadcast({
1857
1873
  title: 'Package Updated',
1858
- message: `${name} updated to v${version}`,
1874
+ message: sentence,
1859
1875
  severity: 'info',
1860
1876
  duration: 5000,
1861
1877
  });
@@ -36,6 +36,7 @@ var __importStar = (this && this.__importStar) || (function () {
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.AddonRegistryService = void 0;
38
38
  exports.shouldEvictMissingOnDisk = shouldEvictMissingOnDisk;
39
+ exports.addonUpdatePayload = addonUpdatePayload;
39
40
  exports.shouldEmitProviderRegisteredReady = shouldEmitProviderRegisteredReady;
40
41
  const node_crypto_1 = require("node:crypto");
41
42
  const fs = __importStar(require("node:fs"));
@@ -69,6 +70,28 @@ const runner_spawn_fanout_js_1 = require("./runner-spawn-fanout.js");
69
70
  function shouldEvictMissingOnDisk(entry, id, onDiskIds) {
70
71
  return (entry.source === 'installed' && entry.packageName !== '@camstack/system' && !onDiskIds.has(id));
71
72
  }
73
+ /**
74
+ * The versions an `addon.updated` event states.
75
+ *
76
+ * `fromVersion === null` means the hub could not read what was installed
77
+ * before — a first install, or a tree with no readable `package.json` — and
78
+ * the key is then ABSENT, not present-and-empty. It used to arrive as the
79
+ * literal `'0.0.0'`, which the notification centre printed verbatim: the
80
+ * operator read "@camstack/addon-terminal 0.0.0 → latest" on his phone and
81
+ * had no way to tell that neither number was real (2026-08-30). An absent key
82
+ * the renderer leaves out is the honest form of "unknown"; a version-shaped
83
+ * placeholder is a claim.
84
+ *
85
+ * `toVersion` is never optional — it is what separates a package update from a
86
+ * settings save, which emits the same category carrying no versions at all
87
+ * (`parseAddonUpdateComplete`).
88
+ */
89
+ function addonUpdatePayload(fromVersion, toVersion) {
90
+ return {
91
+ ...(fromVersion !== null ? { fromVersion } : {}),
92
+ toVersion,
93
+ };
94
+ }
72
95
  /**
73
96
  * Type predicate: true when an `ISettingsBackend` also satisfies the
74
97
  * sync `ISettingsStore` contract (system/addon/device key-value ops)
@@ -1511,14 +1534,17 @@ class AddonRegistryService {
1511
1534
  this.healthMonitor.forget(packageName);
1512
1535
  this.addonLoader.clearLoadFailures(packageName);
1513
1536
  }
1514
- /** Emit addon.updated lifecycle event for all addons belonging to a package */
1537
+ /**
1538
+ * Emit `addon.updated` for every addon belonging to a package.
1539
+ *
1540
+ * The payload shape is {@link addonUpdatePayload} — an unknown predecessor
1541
+ * is an ABSENT key, never a placeholder.
1542
+ */
1515
1543
  emitUpdateEvent(packageName, fromVersion, toVersion) {
1544
+ const payload = addonUpdatePayload(fromVersion, toVersion);
1516
1545
  for (const [id, entry] of this.addonEntries) {
1517
1546
  if (entry.packageName === packageName) {
1518
- this.emitAddonLifecycleEvent('addon.updated', id, {
1519
- fromVersion,
1520
- toVersion,
1521
- });
1547
+ this.emitAddonLifecycleEvent('addon.updated', id, payload);
1522
1548
  }
1523
1549
  }
1524
1550
  }
@@ -396,6 +396,14 @@ class MoleculerService {
396
396
  // across a socket too — and one that hangs is cut off on both.
397
397
  capTimeoutMs: (capName, method) => this.capabilityService.getRegistry()?.getDefinition(capName)?.methods?.[method]
398
398
  ?.timeoutMs,
399
+ // Feed the cap-usage graph from the one place that sees a forked
400
+ // addon's outbound `ctx.api` traffic AND runs in the process that reads
401
+ // it back (`nodes.getCapUsageGraph` → `cap-providers.ts`). The
402
+ // runner-side observer in `addon-context-factory.ts` writes to the
403
+ // RUNNER's own module singleton, which hub-main never sees — which is
404
+ // why the graph answered `[]` on a hub running 64 addons. Blind spots
405
+ // that remain are listed on `LocalChildRegistryOptions.capUsageObserver`.
406
+ capUsageObserver: (obs) => (0, system_1.getCapUsageRegistry)().recordCall(obs),
399
407
  logger: {
400
408
  info: (msg, meta) => logger.info(msg, meta !== null && meta !== undefined
401
409
  ? { meta: meta }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/server",
3
- "version": "1.2.194",
3
+ "version": "1.2.196",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist",