@camstack/server 1.2.718 → 1.2.720

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 (970) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/addon-root-inventory.js +1 -1
  3. package/dist/agent/addon-scan.js +11 -7
  4. package/dist/agent/agent-addon-updates.js +1 -1
  5. package/dist/agent/agent-cap-dispatch-service.js +1 -1
  6. package/dist/agent/agent-heap-watch.js +1 -1
  7. package/dist/agent/agent-http.js +1 -1
  8. package/dist/agent/agent-hub-addon-update.js +1 -1
  9. package/dist/agent/agent-hub-registration.js +1 -1
  10. package/dist/agent/agent-infra-capabilities.js +2 -2
  11. package/dist/agent/agent-mesh-gate.js +1 -1
  12. package/dist/agent/agent-node-certificates.js +1 -1
  13. package/dist/agent/agent-pairing-routes.js +1 -1
  14. package/dist/agent/agent-pairing-store.js +1 -1
  15. package/dist/agent/agent-service.js +6 -2
  16. package/dist/agent/agent-update-service.js +3 -1
  17. package/dist/agent/hub-membership-client.js +1 -1
  18. package/dist/agent/infra-boot-guard.js +2 -2
  19. package/dist/agent/main.js +9 -9
  20. package/dist/api/addon-upload.js +1 -1
  21. package/dist/api/core/addon-settings.router.js +1 -1
  22. package/dist/api/core/agent-pairing.router.js +1 -1
  23. package/dist/api/core/auth-device-cert.procedures.js +1 -1
  24. package/dist/api/core/cap-providers.js +6 -6
  25. package/dist/api/core/certificates.router.js +1 -1
  26. package/dist/api/core/lifecycle-job-runner.js +1 -1
  27. package/dist/api/core/logging-settings.js +1 -1
  28. package/dist/api/core/logs.router.js +2 -2
  29. package/dist/api/core/notifications.router.js +1 -1
  30. package/dist/api/core/preferences.router.js +1 -1
  31. package/dist/api/core/repl.router.js +1 -1
  32. package/dist/api/cors/cors-policy.js +1 -1
  33. package/dist/api/mesh-membership-routes.js +1 -1
  34. package/dist/api/model-distributor.js +1 -1
  35. package/dist/api/trpc/cap-route-error-formatter.js +1 -1
  36. package/dist/api/trpc/cap-router-runtime.js +2 -2
  37. package/dist/api/trpc/core-cap-bridge.js +1 -1
  38. package/dist/api/trpc/device-collection-dispatch.js +1 -1
  39. package/dist/api/trpc/generated-cap-routers.js +1 -1
  40. package/dist/api/trpc/principal-authorization.js +1 -1
  41. package/dist/api/trpc/principal-visibility.js +1 -1
  42. package/dist/api/trpc/scope-access.js +1 -1
  43. package/dist/api/trpc/trpc.context.js +1 -1
  44. package/dist/api/trpc/trpc.middleware.js +1 -1
  45. package/dist/api/trpc/trpc.router.js +3 -3
  46. package/dist/auth/auth-network-policy.js +1 -1
  47. package/dist/auth/client-address.js +1 -1
  48. package/dist/auth/hub-sessions.js +1 -1
  49. package/dist/auth/session-lifetimes.js +1 -1
  50. package/dist/auth/sso-finish-deps.js +1 -1
  51. package/dist/boot/boot-config.js +53 -133
  52. package/dist/boot/platform-keychain-key.js +1 -1
  53. package/dist/boot/post-boot.service.js +1 -1
  54. package/dist/bootstrap-packages.js +3 -3
  55. package/dist/core/addon/addon-call-gateway.js +1 -1
  56. package/dist/core/addon/addon-package.service.js +140 -21
  57. package/dist/core/addon/addon-registry.service.js +36 -32
  58. package/dist/core/addon/addon-requirements.js +81 -0
  59. package/dist/core/addon/hub-addon-api.js +1 -1
  60. package/dist/core/addon/installed-addon-versions.js +82 -0
  61. package/dist/core/addon/package-dir-utils.js +11 -1
  62. package/dist/core/addon/settings-door-wiring.js +1 -1
  63. package/dist/core/addon-bridge/addon-bridge.service.js +3 -3
  64. package/dist/core/addon-pages/addon-pages.service.js +1 -1
  65. package/dist/core/agent/agent-desired-set.js +1 -1
  66. package/dist/core/agent/agent-pairing-http.js +1 -1
  67. package/dist/core/agent/agent-registry.service.js +41 -7
  68. package/dist/core/agent/cluster-node-history-store.js +1 -1
  69. package/dist/core/agent/delivery-requirements.js +36 -0
  70. package/dist/core/agent/forgotten-node-revoker.js +1 -1
  71. package/dist/core/agent/node-removal-hooks.js +6 -2
  72. package/dist/core/auth/auth.service.js +1 -1
  73. package/dist/core/config/config.schema.js +2 -2
  74. package/dist/core/config/config.service.js +1 -1
  75. package/dist/core/events/event-bus.service.js +1 -1
  76. package/dist/core/feature/feature.service.js +1 -1
  77. package/dist/core/lifecycle/lifecycle-state-machine.js +2 -2
  78. package/dist/core/logging/log-history.js +1 -1
  79. package/dist/core/logging/log-ring-buffer.js +2 -2
  80. package/dist/core/logging/logging.service.js +2 -2
  81. package/dist/core/logging/scoped-logger.js +2 -2
  82. package/dist/core/moleculer/cap-route-authority.js +2 -2
  83. package/dist/core/moleculer/hub-mesh-guard.js +1 -1
  84. package/dist/core/moleculer/moleculer.service.js +1 -1
  85. package/dist/core/network/network-quality.service.js +1 -1
  86. package/dist/core/notification/notification-wrapper.service.js +1 -1
  87. package/dist/core/notification/toast-wrapper.service.js +1 -1
  88. package/dist/core/repl/repl-engine.service.js +1 -1
  89. package/dist/core/server-update/server-update.service.js +3 -0
  90. package/dist/core/server-update/system-ensure-prebuilds.js +3 -3
  91. package/dist/core/server-update/system-exec-npm.js +2 -2
  92. package/dist/core/storage/fs-storage-backend.js +2 -2
  93. package/dist/core/storage/storage-location-manager.js +2 -2
  94. package/dist/core/storage/storage.service.js +1 -1
  95. package/dist/framework-nodepath.js +14 -1
  96. package/dist/launcher.js +23 -23
  97. package/dist/legacy-package-names.js +15 -0
  98. package/dist/main.js +2 -2
  99. package/dist/manual-boot.js +4 -3
  100. package/dist/package-inventory.js +6 -3
  101. package/dist/server-root/index.js +182 -30
  102. package/dist/single-copy-cleanup-runner.js +3 -3
  103. package/dist/single-copy-cleanup.js +19 -14
  104. package/package.json +53 -19
  105. package/scripts/closure-postinstall.mjs +1 -1
  106. package/system/assets/addon-pages-aggregator/icon.svg +5 -0
  107. package/system/assets/addon-widgets-aggregator/icon.svg +6 -0
  108. package/system/assets/alert-center/icon.svg +5 -0
  109. package/system/assets/autotrack/icon.svg +5 -0
  110. package/system/assets/backup-orchestrator/icon.svg +5 -0
  111. package/system/assets/calendars/icon.svg +5 -0
  112. package/system/assets/camera-grid/icon.svg +10 -0
  113. package/system/assets/composer/icon.svg +7 -0
  114. package/system/assets/console-logging/icon.svg +4 -0
  115. package/system/assets/core-blocks/icon.svg +6 -0
  116. package/system/assets/device-history/icon.svg +4 -0
  117. package/system/assets/device-manager/icon.svg +6 -0
  118. package/system/assets/filesystem-storage/icon.svg +6 -0
  119. package/system/assets/hub-forwarder/icon.svg +7 -0
  120. package/system/assets/keychain/icon.svg +6 -0
  121. package/system/assets/liveness-monitor/icon.svg +4 -0
  122. package/system/assets/local-auth/icon.svg +5 -0
  123. package/system/assets/local-network/icon.svg +7 -0
  124. package/system/assets/loki-logging/icon.svg +7 -0
  125. package/system/assets/metrics-native/icon.svg +3 -0
  126. package/system/assets/platform-probe/icon.svg +5 -0
  127. package/system/assets/record-entries/icon.svg +8 -0
  128. package/system/assets/remote-access-orchestrator/icon.svg +5 -0
  129. package/system/assets/snapshot/icon.svg +4 -0
  130. package/system/assets/sqlite-settings/icon.svg +5 -0
  131. package/system/assets/storage-orchestrator/icon.svg +8 -0
  132. package/system/assets/system-config/icon.svg +4 -0
  133. package/system/assets/winston-logging/icon.svg +6 -0
  134. package/system/dist/addon/addon-api-factory.d.ts +35 -0
  135. package/system/dist/addon-routes/addon-route-registry.d.ts +37 -0
  136. package/system/dist/addon-runner.js +11894 -0
  137. package/system/dist/addon-runner.mjs +11840 -0
  138. package/system/dist/addon-utils.d.ts +23 -0
  139. package/system/dist/addon-utils.js +27 -0
  140. package/system/dist/addon-utils.mjs +3 -0
  141. package/system/dist/agent-https-BMbnmX5u.mjs +1042 -0
  142. package/system/dist/agent-https-DslXCDRW.js +1289 -0
  143. package/system/dist/amd-accelerators-CEuPFBBK.js +36 -0
  144. package/system/dist/amd-accelerators-U_RsoEDd.mjs +35 -0
  145. package/system/dist/auth/auth-audit-log.d.ts +45 -0
  146. package/system/dist/auth/auth-manager.d.ts +155 -0
  147. package/system/dist/auth/cidr.d.ts +22 -0
  148. package/system/dist/auth/device-ca-store.d.ts +57 -0
  149. package/system/dist/auth/device-ca.d.ts +65 -0
  150. package/system/dist/auth/device-credential-manager.d.ts +158 -0
  151. package/system/dist/auth/external-identity-manager.d.ts +42 -0
  152. package/system/dist/auth/jwt-signing-key.d.ts +42 -0
  153. package/system/dist/auth/legacy-token-tables.d.ts +16 -0
  154. package/system/dist/auth/login-session-manager.d.ts +140 -0
  155. package/system/dist/auth/origin.d.ts +34 -0
  156. package/system/dist/auth/parse-record.d.ts +18 -0
  157. package/system/dist/auth/scope-matcher.d.ts +8 -0
  158. package/system/dist/auth/session-revocation-bus.d.ts +32 -0
  159. package/system/dist/auth/token-expiry.d.ts +62 -0
  160. package/system/dist/auth/totp-manager.d.ts +107 -0
  161. package/system/dist/auth/user-management-internal.d.ts +90 -0
  162. package/system/dist/auth/user-manager.d.ts +69 -0
  163. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.d.ts +57 -0
  164. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +271 -0
  165. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +263 -0
  166. package/system/dist/builtins/addon-pages-aggregator/dedupe-pages.d.ts +24 -0
  167. package/system/dist/builtins/addon-pages-aggregator/index.d.ts +1 -0
  168. package/system/dist/builtins/addon-pages-aggregator/index.js +8 -0
  169. package/system/dist/builtins/addon-pages-aggregator/index.mjs +2 -0
  170. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.d.ts +57 -0
  171. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +257 -0
  172. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +249 -0
  173. package/system/dist/builtins/addon-widgets-aggregator/index.d.ts +1 -0
  174. package/system/dist/builtins/addon-widgets-aggregator/index.js +8 -0
  175. package/system/dist/builtins/addon-widgets-aggregator/index.mjs +2 -0
  176. package/system/dist/builtins/alerts/alert-episode-policy.d.ts +39 -0
  177. package/system/dist/builtins/alerts/alert-store.d.ts +32 -0
  178. package/system/dist/builtins/alerts/alerts.addon.d.ts +148 -0
  179. package/system/dist/builtins/alerts/alerts.addon.js +1566 -0
  180. package/system/dist/builtins/alerts/alerts.addon.mjs +1559 -0
  181. package/system/dist/builtins/alerts/device-label.d.ts +8 -0
  182. package/system/dist/builtins/alerts/emit-alert-policy.d.ts +15 -0
  183. package/system/dist/builtins/alerts/index.d.ts +1 -0
  184. package/system/dist/builtins/alerts/index.js +4 -0
  185. package/system/dist/builtins/alerts/index.mjs +2 -0
  186. package/system/dist/builtins/alerts/migration-alerts.d.ts +13 -0
  187. package/system/dist/builtins/alerts/prune-policy.d.ts +44 -0
  188. package/system/dist/builtins/alerts/record-kinds.d.ts +15 -0
  189. package/system/dist/builtins/alerts/runner-alert.d.ts +58 -0
  190. package/system/dist/builtins/autotrack/autotrack-cameras.d.ts +125 -0
  191. package/system/dist/builtins/autotrack/autotrack-config.d.ts +89 -0
  192. package/system/dist/builtins/autotrack/autotrack-decision.d.ts +86 -0
  193. package/system/dist/builtins/autotrack/autotrack-loop.d.ts +95 -0
  194. package/system/dist/builtins/autotrack/autotrack.addon.d.ts +108 -0
  195. package/system/dist/builtins/autotrack/frame-error.d.ts +50 -0
  196. package/system/dist/builtins/autotrack/frame-measurements.d.ts +97 -0
  197. package/system/dist/builtins/autotrack/index.d.ts +2 -0
  198. package/system/dist/builtins/autotrack/index.js +1018 -0
  199. package/system/dist/builtins/autotrack/index.mjs +1012 -0
  200. package/system/dist/builtins/autotrack/ptz-mirror.d.ts +54 -0
  201. package/system/dist/builtins/autotrack/target-selection.d.ts +46 -0
  202. package/system/dist/builtins/backup-orchestrator/backup-databases.d.ts +51 -0
  203. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.d.ts +291 -0
  204. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +3213 -0
  205. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +3204 -0
  206. package/system/dist/builtins/backup-orchestrator/cron-helpers.d.ts +23 -0
  207. package/system/dist/builtins/backup-orchestrator/destination-policy.d.ts +91 -0
  208. package/system/dist/builtins/backup-orchestrator/download-helpers.d.ts +12 -0
  209. package/system/dist/builtins/backup-orchestrator/encryption-key-store.d.ts +49 -0
  210. package/system/dist/builtins/backup-orchestrator/index.d.ts +2 -0
  211. package/system/dist/builtins/backup-orchestrator/index.js +8 -0
  212. package/system/dist/builtins/backup-orchestrator/index.mjs +2 -0
  213. package/system/dist/builtins/backup-orchestrator/manifest-store.d.ts +134 -0
  214. package/system/dist/builtins/backup-orchestrator/record-kinds.d.ts +56 -0
  215. package/system/dist/builtins/backup-orchestrator/restore-archive.d.ts +24 -0
  216. package/system/dist/builtins/backup-orchestrator/run-queue.d.ts +106 -0
  217. package/system/dist/builtins/backup-orchestrator/schedule-store.d.ts +59 -0
  218. package/system/dist/builtins/backup-orchestrator/seed-marker-store.d.ts +26 -0
  219. package/system/dist/builtins/backup-orchestrator/staging-paths.d.ts +36 -0
  220. package/system/dist/builtins/backup-orchestrator/write-targets.d.ts +63 -0
  221. package/system/dist/builtins/calendars/calendar-color.d.ts +9 -0
  222. package/system/dist/builtins/calendars/calendar-prefs-store.d.ts +34 -0
  223. package/system/dist/builtins/calendars/calendars.addon.d.ts +19 -0
  224. package/system/dist/builtins/calendars/calendars.addon.js +227 -0
  225. package/system/dist/builtins/calendars/calendars.addon.mjs +220 -0
  226. package/system/dist/builtins/calendars/index.d.ts +1 -0
  227. package/system/dist/builtins/calendars/index.js +8 -0
  228. package/system/dist/builtins/calendars/index.mjs +2 -0
  229. package/system/dist/builtins/calendars/record-kinds.d.ts +18 -0
  230. package/system/dist/builtins/camera-grid/acquire-retry.d.ts +30 -0
  231. package/system/dist/builtins/camera-grid/addon.d.ts +205 -0
  232. package/system/dist/builtins/camera-grid/flv-join.d.ts +40 -0
  233. package/system/dist/builtins/camera-grid/grid-activity-mirror.d.ts +42 -0
  234. package/system/dist/builtins/camera-grid/grid-activity.d.ts +91 -0
  235. package/system/dist/builtins/camera-grid/grid-camera-declarations.d.ts +59 -0
  236. package/system/dist/builtins/camera-grid/grid-camera-device.d.ts +68 -0
  237. package/system/dist/builtins/camera-grid/grid-canvas-derivation.d.ts +54 -0
  238. package/system/dist/builtins/camera-grid/grid-canvas-seed.d.ts +112 -0
  239. package/system/dist/builtins/camera-grid/grid-canvas.d.ts +85 -0
  240. package/system/dist/builtins/camera-grid/grid-child.d.ts +32 -0
  241. package/system/dist/builtins/camera-grid/grid-compositor-child.d.ts +3 -0
  242. package/system/dist/builtins/camera-grid/grid-compositor-invocation.d.ts +47 -0
  243. package/system/dist/builtins/camera-grid/grid-compositor.d.ts +54 -0
  244. package/system/dist/builtins/camera-grid/grid-detection-mapping.d.ts +61 -0
  245. package/system/dist/builtins/camera-grid/grid-device-settings.d.ts +35 -0
  246. package/system/dist/builtins/camera-grid/grid-filter-graph.d.ts +53 -0
  247. package/system/dist/builtins/camera-grid/grid-frame-sample.d.ts +53 -0
  248. package/system/dist/builtins/camera-grid/grid-instances.d.ts +22 -0
  249. package/system/dist/builtins/camera-grid/grid-last-frame-store.d.ts +58 -0
  250. package/system/dist/builtins/camera-grid/grid-layout-native-provider.d.ts +34 -0
  251. package/system/dist/builtins/camera-grid/grid-plan.d.ts +34 -0
  252. package/system/dist/builtins/camera-grid/grid-profiles.d.ts +104 -0
  253. package/system/dist/builtins/camera-grid/grid-row-normalization.d.ts +10 -0
  254. package/system/dist/builtins/camera-grid/grid-sentry-sources.d.ts +64 -0
  255. package/system/dist/builtins/camera-grid/grid-snapshot.d.ts +62 -0
  256. package/system/dist/builtins/camera-grid/grid-stream-descriptor.d.ts +53 -0
  257. package/system/dist/builtins/camera-grid/grid-stream-invocation.d.ts +44 -0
  258. package/system/dist/builtins/camera-grid/grid-stream-relay.d.ts +35 -0
  259. package/system/dist/builtins/camera-grid/grid-stream-session.d.ts +143 -0
  260. package/system/dist/builtins/camera-grid/grid-tile-feed.d.ts +50 -0
  261. package/system/dist/builtins/camera-grid/grid-tile-plan.d.ts +66 -0
  262. package/system/dist/builtins/camera-grid/grid-wire-format.d.ts +30 -0
  263. package/system/dist/builtins/camera-grid/index.d.ts +45 -0
  264. package/system/dist/builtins/camera-grid/index.js +3994 -0
  265. package/system/dist/builtins/camera-grid/index.mjs +3961 -0
  266. package/system/dist/builtins/camera-grid/silence-analysis.d.ts +37 -0
  267. package/system/dist/builtins/cluster-agent/record-kinds.d.ts +49 -0
  268. package/system/dist/builtins/composer/actuator-dispatch.d.ts +13 -0
  269. package/system/dist/builtins/composer/actuator-groups.d.ts +68 -0
  270. package/system/dist/builtins/composer/actuator-invoke.d.ts +32 -0
  271. package/system/dist/builtins/composer/claim-gate.d.ts +59 -0
  272. package/system/dist/builtins/composer/composed-device-set.d.ts +52 -0
  273. package/system/dist/builtins/composer/composed-device.d.ts +57 -0
  274. package/system/dist/builtins/composer/composer-apply-waits.d.ts +28 -0
  275. package/system/dist/builtins/composer/composer-grafts.d.ts +73 -0
  276. package/system/dist/builtins/composer/composer-live-set.d.ts +30 -0
  277. package/system/dist/builtins/composer/composer-plan.d.ts +112 -0
  278. package/system/dist/builtins/composer/composer-runtime-factory.d.ts +30 -0
  279. package/system/dist/builtins/composer/composer-seeds.d.ts +28 -0
  280. package/system/dist/builtins/composer/composer-verdict.d.ts +33 -0
  281. package/system/dist/builtins/composer/composer.addon.d.ts +26 -0
  282. package/system/dist/builtins/composer/composer.addon.js +6229 -0
  283. package/system/dist/builtins/composer/composer.addon.mjs +6223 -0
  284. package/system/dist/builtins/composer/composer.d.ts +208 -0
  285. package/system/dist/builtins/composer/composition-declarations.d.ts +64 -0
  286. package/system/dist/builtins/composer/composition-evaluation.d.ts +53 -0
  287. package/system/dist/builtins/composer/composition-runtime.d.ts +203 -0
  288. package/system/dist/builtins/composer/composition-target.d.ts +60 -0
  289. package/system/dist/builtins/composer/confirmed-seed.d.ts +44 -0
  290. package/system/dist/builtins/composer/deadline-timer.d.ts +18 -0
  291. package/system/dist/builtins/composer/existing-target.d.ts +131 -0
  292. package/system/dist/builtins/composer/field-record.d.ts +64 -0
  293. package/system/dist/builtins/composer/forward-commands.d.ts +61 -0
  294. package/system/dist/builtins/composer/graft-host.d.ts +71 -0
  295. package/system/dist/builtins/composer/held-claims.d.ts +29 -0
  296. package/system/dist/builtins/composer/history-helpers.d.ts +67 -0
  297. package/system/dist/builtins/composer/index.d.ts +1 -0
  298. package/system/dist/builtins/composer/index.js +8 -0
  299. package/system/dist/builtins/composer/index.mjs +2 -0
  300. package/system/dist/builtins/composer/math-quantity.d.ts +20 -0
  301. package/system/dist/builtins/composer/own-field-reads.d.ts +30 -0
  302. package/system/dist/builtins/composer/owned-fields-target.d.ts +95 -0
  303. package/system/dist/builtins/composer/pulse-seed-resolve.d.ts +59 -0
  304. package/system/dist/builtins/composer/pulse-seed.d.ts +75 -0
  305. package/system/dist/builtins/composer/slice-assembler.d.ts +26 -0
  306. package/system/dist/builtins/composer/source-readings.d.ts +128 -0
  307. package/system/dist/builtins/composer/source-tracker.d.ts +135 -0
  308. package/system/dist/builtins/console-logging/console-destination.d.ts +19 -0
  309. package/system/dist/builtins/console-logging/console-logging.addon.d.ts +26 -0
  310. package/system/dist/builtins/console-logging/index.d.ts +3 -0
  311. package/system/dist/builtins/console-logging/index.js +108 -0
  312. package/system/dist/builtins/console-logging/index.mjs +99 -0
  313. package/system/dist/builtins/core-blocks/actions-service.d.ts +113 -0
  314. package/system/dist/builtins/core-blocks/actions-store.d.ts +32 -0
  315. package/system/dist/builtins/core-blocks/actions-wiring.d.ts +32 -0
  316. package/system/dist/builtins/core-blocks/block-package.d.ts +54 -0
  317. package/system/dist/builtins/core-blocks/block-settings-store.d.ts +93 -0
  318. package/system/dist/builtins/core-blocks/block-supervisor.d.ts +176 -0
  319. package/system/dist/builtins/core-blocks/block-type-defs.d.ts +29 -0
  320. package/system/dist/builtins/core-blocks/blocks-integration.d.ts +89 -0
  321. package/system/dist/builtins/core-blocks/compile-block.d.ts +52 -0
  322. package/system/dist/builtins/core-blocks/composition-api.d.ts +50 -0
  323. package/system/dist/builtins/core-blocks/composition-peers.d.ts +31 -0
  324. package/system/dist/builtins/core-blocks/composition-sources.d.ts +40 -0
  325. package/system/dist/builtins/core-blocks/core-block-store.d.ts +120 -0
  326. package/system/dist/builtins/core-blocks/core-blocks.addon.d.ts +108 -0
  327. package/system/dist/builtins/core-blocks/core-blocks.addon.js +6374 -0
  328. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +6355 -0
  329. package/system/dist/builtins/core-blocks/extract-settings-schema.d.ts +6 -0
  330. package/system/dist/builtins/core-blocks/index.d.ts +8 -0
  331. package/system/dist/builtins/core-blocks/index.js +21 -0
  332. package/system/dist/builtins/core-blocks/index.mjs +2 -0
  333. package/system/dist/builtins/core-blocks/lock-door-gate.d.ts +31 -0
  334. package/system/dist/builtins/core-blocks/lock-door-sensor.d.ts +35 -0
  335. package/system/dist/builtins/core-blocks/power-source-service.d.ts +70 -0
  336. package/system/dist/builtins/core-blocks/record-kinds.d.ts +83 -0
  337. package/system/dist/builtins/core-blocks/remote-call-redirect.d.ts +23 -0
  338. package/system/dist/builtins/core-blocks/remote-components-service.d.ts +10 -0
  339. package/system/dist/builtins/core-blocks/remote-service.d.ts +85 -0
  340. package/system/dist/builtins/core-blocks/remote-wiring.d.ts +49 -0
  341. package/system/dist/builtins/core-blocks/runs-api.d.ts +30 -0
  342. package/system/dist/builtins/core-blocks/runs-ledger.d.ts +64 -0
  343. package/system/dist/builtins/core-blocks/scheduler/scheduler-engine.d.ts +91 -0
  344. package/system/dist/builtins/core-blocks/scheduler/scheduler-holds.d.ts +54 -0
  345. package/system/dist/builtins/core-blocks/scheduler/scheduler-service.d.ts +76 -0
  346. package/system/dist/builtins/core-blocks/scheduler/scheduler-store.d.ts +23 -0
  347. package/system/dist/builtins/core-blocks/scheduler/scheduler-timeline.d.ts +53 -0
  348. package/system/dist/builtins/core-blocks/scheduler/scheduler-trace.d.ts +17 -0
  349. package/system/dist/builtins/core-blocks/scheduler/scheduler-types.d.ts +20 -0
  350. package/system/dist/builtins/core-blocks/scheduler/scheduler-wiring.d.ts +41 -0
  351. package/system/dist/builtins/core-blocks/templates-service.d.ts +24 -0
  352. package/system/dist/builtins/device-history/capture/capture-engine.d.ts +113 -0
  353. package/system/dist/builtins/device-history/capture/capture-filter.d.ts +37 -0
  354. package/system/dist/builtins/device-history/capture/device-directory.d.ts +47 -0
  355. package/system/dist/builtins/device-history/capture/field-path.d.ts +10 -0
  356. package/system/dist/builtins/device-history/capture/point-writer.d.ts +63 -0
  357. package/system/dist/builtins/device-history/device-history.addon.d.ts +53 -0
  358. package/system/dist/builtins/device-history/device-history.addon.js +2885 -0
  359. package/system/dist/builtins/device-history/device-history.addon.mjs +2878 -0
  360. package/system/dist/builtins/device-history/index.d.ts +3 -0
  361. package/system/dist/builtins/device-history/ingest/producer-ingest.d.ts +99 -0
  362. package/system/dist/builtins/device-history/query/history-query.d.ts +116 -0
  363. package/system/dist/builtins/device-history/query/point-shape.d.ts +31 -0
  364. package/system/dist/builtins/device-history/retention/departure-tracker.d.ts +33 -0
  365. package/system/dist/builtins/device-history/retention/orphans.d.ts +50 -0
  366. package/system/dist/builtins/device-history/retention/retention.d.ts +74 -0
  367. package/system/dist/builtins/device-history/rollup/rollup-engine.d.ts +74 -0
  368. package/system/dist/builtins/device-history/rollup/rollup-math.d.ts +50 -0
  369. package/system/dist/builtins/device-history/runtime/history-runtime.d.ts +118 -0
  370. package/system/dist/builtins/device-history/status/counters.d.ts +55 -0
  371. package/system/dist/builtins/device-history/store/history-door.d.ts +7 -0
  372. package/system/dist/builtins/device-history/store/history-schema.d.ts +28 -0
  373. package/system/dist/builtins/device-history/store/history-store.d.ts +109 -0
  374. package/system/dist/builtins/device-history/store/row-readers.d.ts +11 -0
  375. package/system/dist/builtins/device-history/store/series-registry.d.ts +64 -0
  376. package/system/dist/builtins/device-history/store/series-scale.d.ts +37 -0
  377. package/system/dist/builtins/device-history/time/bucket-time.d.ts +25 -0
  378. package/system/dist/builtins/device-manager/adoption-job-engine.d.ts +153 -0
  379. package/system/dist/builtins/device-manager/claimed-status-overlay.d.ts +45 -0
  380. package/system/dist/builtins/device-manager/contribution-cache.d.ts +85 -0
  381. package/system/dist/builtins/device-manager/day-night-config-schema.d.ts +30 -0
  382. package/system/dist/builtins/device-manager/device-aggregation-merge.d.ts +22 -0
  383. package/system/dist/builtins/device-manager/device-aggregation.d.ts +335 -0
  384. package/system/dist/builtins/device-manager/device-bindings-store.d.ts +278 -0
  385. package/system/dist/builtins/device-manager/device-config-contribution.d.ts +45 -0
  386. package/system/dist/builtins/device-manager/device-config-secrets.d.ts +40 -0
  387. package/system/dist/builtins/device-manager/device-event-propagator.d.ts +26 -0
  388. package/system/dist/builtins/device-manager/device-extension-linked-slot.d.ts +27 -0
  389. package/system/dist/builtins/device-manager/device-form-secrets.d.ts +25 -0
  390. package/system/dist/builtins/device-manager/device-linked-devices.d.ts +201 -0
  391. package/system/dist/builtins/device-manager/device-manager.addon.d.ts +234 -0
  392. package/system/dist/builtins/device-manager/device-manager.addon.js +11369 -0
  393. package/system/dist/builtins/device-manager/device-manager.addon.mjs +11358 -0
  394. package/system/dist/builtins/device-manager/device-meta-actions.d.ts +338 -0
  395. package/system/dist/builtins/device-manager/device-meta-store.d.ts +103 -0
  396. package/system/dist/builtins/device-manager/device-meta-types.d.ts +277 -0
  397. package/system/dist/builtins/device-manager/device-online-fallback.d.ts +35 -0
  398. package/system/dist/builtins/device-manager/device-projection.d.ts +71 -0
  399. package/system/dist/builtins/device-manager/device-provider-context.d.ts +126 -0
  400. package/system/dist/builtins/device-manager/device-queries.d.ts +67 -0
  401. package/system/dist/builtins/device-manager/device-removal-hooks.d.ts +92 -0
  402. package/system/dist/builtins/device-manager/device-row-store.d.ts +449 -0
  403. package/system/dist/builtins/device-manager/device-source-activation.d.ts +103 -0
  404. package/system/dist/builtins/device-manager/device-state-claim-views.d.ts +92 -0
  405. package/system/dist/builtins/device-manager/device-state-claims.d.ts +66 -0
  406. package/system/dist/builtins/device-manager/device-state-mirror.d.ts +267 -0
  407. package/system/dist/builtins/device-manager/device-sync-resolvers.d.ts +30 -0
  408. package/system/dist/builtins/device-manager/device-tombstone-store.d.ts +29 -0
  409. package/system/dist/builtins/device-manager/discovery-orchestrator.d.ts +45 -0
  410. package/system/dist/builtins/device-manager/field-claims-index.d.ts +96 -0
  411. package/system/dist/builtins/device-manager/field-ownership.d.ts +71 -0
  412. package/system/dist/builtins/device-manager/fleet-read-census.d.ts +104 -0
  413. package/system/dist/builtins/device-manager/image-settings-config-schema.d.ts +22 -0
  414. package/system/dist/builtins/device-manager/index.d.ts +2 -0
  415. package/system/dist/builtins/device-manager/index.js +8 -0
  416. package/system/dist/builtins/device-manager/index.mjs +2 -0
  417. package/system/dist/builtins/device-manager/linked-devices-manual-backfill.d.ts +27 -0
  418. package/system/dist/builtins/device-manager/location-alignment.d.ts +61 -0
  419. package/system/dist/builtins/device-manager/migrate-device.d.ts +192 -0
  420. package/system/dist/builtins/device-manager/migrate-guard.d.ts +78 -0
  421. package/system/dist/builtins/device-manager/migrate-hardware-state.d.ts +79 -0
  422. package/system/dist/builtins/device-manager/migrate-reload.d.ts +46 -0
  423. package/system/dist/builtins/device-manager/migration-refused.d.ts +23 -0
  424. package/system/dist/builtins/device-manager/mirror-row-writer.d.ts +222 -0
  425. package/system/dist/builtins/device-manager/record-kinds.d.ts +14 -0
  426. package/system/dist/builtins/device-manager/recording-onboard-config-schema.d.ts +65 -0
  427. package/system/dist/builtins/device-manager/removal-cleanup.d.ts +50 -0
  428. package/system/dist/builtins/device-manager/removal-fence.d.ts +58 -0
  429. package/system/dist/builtins/device-manager/running-flip.d.ts +11 -0
  430. package/system/dist/builtins/device-manager/runtime-state-persist-gate.d.ts +64 -0
  431. package/system/dist/builtins/device-manager/secret-config-paths.d.ts +24 -0
  432. package/system/dist/builtins/device-manager/stale-wrapper-activations.d.ts +59 -0
  433. package/system/dist/builtins/device-manager/write-lock.d.ts +17 -0
  434. package/system/dist/builtins/hub-forwarder/hub-forwarder-destination.d.ts +43 -0
  435. package/system/dist/builtins/hub-forwarder/hub-forwarder.addon.d.ts +16 -0
  436. package/system/dist/builtins/hub-forwarder/index.d.ts +3 -0
  437. package/system/dist/builtins/hub-forwarder/index.js +151 -0
  438. package/system/dist/builtins/hub-forwarder/index.mjs +142 -0
  439. package/system/dist/builtins/keychain/index.d.ts +1 -0
  440. package/system/dist/builtins/keychain/index.js +2059 -0
  441. package/system/dist/builtins/keychain/index.mjs +2052 -0
  442. package/system/dist/builtins/keychain/key-sources.d.ts +37 -0
  443. package/system/dist/builtins/keychain/keychain-crypto.d.ts +28 -0
  444. package/system/dist/builtins/keychain/keychain-reset-trigger.d.ts +25 -0
  445. package/system/dist/builtins/keychain/keychain-service.d.ts +180 -0
  446. package/system/dist/builtins/keychain/keychain-store.d.ts +125 -0
  447. package/system/dist/builtins/keychain/keychain-usage.d.ts +17 -0
  448. package/system/dist/builtins/keychain/keychain.addon.d.ts +36 -0
  449. package/system/dist/builtins/keychain/platform-key-source.d.ts +24 -0
  450. package/system/dist/builtins/keychain/record-kinds.d.ts +16 -0
  451. package/system/dist/builtins/keychain/system-held-secrets.d.ts +25 -0
  452. package/system/dist/builtins/liveness-monitor/index.d.ts +2 -0
  453. package/system/dist/builtins/liveness-monitor/index.js +6 -0
  454. package/system/dist/builtins/liveness-monitor/index.mjs +2 -0
  455. package/system/dist/builtins/liveness-monitor/liveness-checks.d.ts +85 -0
  456. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.d.ts +46 -0
  457. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +443 -0
  458. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +437 -0
  459. package/system/dist/builtins/liveness-monitor/liveness-reporter.d.ts +28 -0
  460. package/system/dist/builtins/liveness-monitor/storage-root-access.d.ts +53 -0
  461. package/system/dist/builtins/local-auth/admin-account-boot.d.ts +27 -0
  462. package/system/dist/builtins/local-auth/auth-config-reader.d.ts +39 -0
  463. package/system/dist/builtins/local-auth/auth-schema.d.ts +93 -0
  464. package/system/dist/builtins/local-auth/index.d.ts +1 -0
  465. package/system/dist/builtins/local-auth/index.js +4 -0
  466. package/system/dist/builtins/local-auth/index.mjs +2 -0
  467. package/system/dist/builtins/local-auth/jwt-signing-key-keeper.d.ts +30 -0
  468. package/system/dist/builtins/local-auth/local-auth.addon.d.ts +48 -0
  469. package/system/dist/builtins/local-auth/local-auth.addon.js +12418 -0
  470. package/system/dist/builtins/local-auth/local-auth.addon.mjs +12388 -0
  471. package/system/dist/builtins/local-auth/oauth-grants.d.ts +71 -0
  472. package/system/dist/builtins/local-auth/oauth-session-manager.d.ts +44 -0
  473. package/system/dist/builtins/local-auth/person-scopes.d.ts +7 -0
  474. package/system/dist/builtins/local-auth/preferences-record-kinds.d.ts +27 -0
  475. package/system/dist/builtins/local-auth/record-kinds.d.ts +137 -0
  476. package/system/dist/builtins/local-auth/user-preferences-store.d.ts +56 -0
  477. package/system/dist/builtins/local-network/address-book.d.ts +128 -0
  478. package/system/dist/builtins/local-network/agent-mdns.d.ts +56 -0
  479. package/system/dist/builtins/local-network/hub-mdns-ciao.d.ts +7 -0
  480. package/system/dist/builtins/local-network/hub-mdns.d.ts +58 -0
  481. package/system/dist/builtins/local-network/index.d.ts +1 -0
  482. package/system/dist/builtins/local-network/index.js +10 -0
  483. package/system/dist/builtins/local-network/index.mjs +2 -0
  484. package/system/dist/builtins/local-network/ipv6-lan.d.ts +21 -0
  485. package/system/dist/builtins/local-network/local-hostname.d.ts +15 -0
  486. package/system/dist/builtins/local-network/local-network.addon.d.ts +334 -0
  487. package/system/dist/builtins/local-network/local-network.addon.js +2487 -0
  488. package/system/dist/builtins/local-network/local-network.addon.mjs +2466 -0
  489. package/system/dist/builtins/local-network/scan/dns-wire.d.ts +17 -0
  490. package/system/dist/builtins/local-network/scan/scan-engine.d.ts +31 -0
  491. package/system/dist/builtins/local-network/scan/scan-io-node.d.ts +2 -0
  492. package/system/dist/builtins/local-network/scan/scan-io.d.ts +56 -0
  493. package/system/dist/builtins/local-network/scan/subnets.d.ts +57 -0
  494. package/system/dist/builtins/loki-logging/index.d.ts +4 -0
  495. package/system/dist/builtins/loki-logging/index.js +915 -0
  496. package/system/dist/builtins/loki-logging/index.mjs +901 -0
  497. package/system/dist/builtins/loki-logging/loki-destination.d.ts +142 -0
  498. package/system/dist/builtins/loki-logging/loki-logging.addon.d.ts +66 -0
  499. package/system/dist/builtins/loki-logging/loki-payload.d.ts +100 -0
  500. package/system/dist/builtins/loki-logging/loki-read.d.ts +51 -0
  501. package/system/dist/builtins/loki-logging/retire-enabled-flag.d.ts +48 -0
  502. package/system/dist/builtins/native-metrics/cgroup-memory.d.ts +240 -0
  503. package/system/dist/builtins/native-metrics/cgroup-pids.d.ts +159 -0
  504. package/system/dist/builtins/native-metrics/container-memory-ring.d.ts +18 -0
  505. package/system/dist/builtins/native-metrics/darwin-memory.d.ts +26 -0
  506. package/system/dist/builtins/native-metrics/gpu-probe.d.ts +18 -0
  507. package/system/dist/builtins/native-metrics/index.d.ts +2 -0
  508. package/system/dist/builtins/native-metrics/load-series-config.d.ts +83 -0
  509. package/system/dist/builtins/native-metrics/load-series-reader.d.ts +63 -0
  510. package/system/dist/builtins/native-metrics/load-series-types.d.ts +14 -0
  511. package/system/dist/builtins/native-metrics/native-metrics-provider.d.ts +49 -0
  512. package/system/dist/builtins/native-metrics/native-metrics.addon.d.ts +233 -0
  513. package/system/dist/builtins/native-metrics/native-metrics.addon.js +3116 -0
  514. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +3106 -0
  515. package/system/dist/builtins/native-metrics/node-load-ring.d.ts +212 -0
  516. package/system/dist/builtins/native-metrics/node-metrics-history-recorder.d.ts +155 -0
  517. package/system/dist/builtins/native-metrics/proc-process-table.d.ts +25 -0
  518. package/system/dist/builtins/native-metrics/process-classification.d.ts +110 -0
  519. package/system/dist/builtins/native-metrics/thread-cpu-sampler.d.ts +116 -0
  520. package/system/dist/builtins/platform-probe/accelerator-facts-probe.d.ts +24 -0
  521. package/system/dist/builtins/platform-probe/accelerator-reprobe.d.ts +23 -0
  522. package/system/dist/builtins/platform-probe/amd-accelerators.d.ts +15 -0
  523. package/system/dist/builtins/platform-probe/amd-npu.d.ts +35 -0
  524. package/system/dist/builtins/platform-probe/coral-accelerators.d.ts +87 -0
  525. package/system/dist/builtins/platform-probe/index.d.ts +57 -0
  526. package/system/dist/builtins/platform-probe/index.js +1151 -0
  527. package/system/dist/builtins/platform-probe/index.mjs +1140 -0
  528. package/system/dist/builtins/platform-probe/inference-config-resolver.d.ts +29 -0
  529. package/system/dist/builtins/platform-probe/intel-accelerators.d.ts +14 -0
  530. package/system/dist/builtins/platform-probe/intel-npu.d.ts +38 -0
  531. package/system/dist/builtins/platform-probe/platform-scorer.d.ts +66 -0
  532. package/system/dist/builtins/platform-probe/runtime-packages.d.ts +6 -0
  533. package/system/dist/builtins/platform-probe/windows-hardware.d.ts +77 -0
  534. package/system/dist/builtins/record-entries/entries-service.d.ts +42 -0
  535. package/system/dist/builtins/record-entries/index.d.ts +1 -0
  536. package/system/dist/builtins/record-entries/index.js +162 -0
  537. package/system/dist/builtins/record-entries/index.mjs +156 -0
  538. package/system/dist/builtins/record-entries/record-entries.addon.d.ts +13 -0
  539. package/system/dist/builtins/records-isolated.d.ts +10 -0
  540. package/system/dist/builtins/remote-access-orchestrator/enabled-providers-reconcile.d.ts +96 -0
  541. package/system/dist/builtins/remote-access-orchestrator/index.d.ts +1 -0
  542. package/system/dist/builtins/remote-access-orchestrator/index.js +8 -0
  543. package/system/dist/builtins/remote-access-orchestrator/index.mjs +2 -0
  544. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.d.ts +71 -0
  545. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +214 -0
  546. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +208 -0
  547. package/system/dist/builtins/shared/device-state-changed.d.ts +16 -0
  548. package/system/dist/builtins/shared/settle-sources.d.ts +22 -0
  549. package/system/dist/builtins/snapshot/index.d.ts +2 -0
  550. package/system/dist/builtins/snapshot/index.js +2720 -0
  551. package/system/dist/builtins/snapshot/index.mjs +2713 -0
  552. package/system/dist/builtins/snapshot/snapshot-cache.d.ts +108 -0
  553. package/system/dist/builtins/snapshot/snapshot-coalescing.d.ts +135 -0
  554. package/system/dist/builtins/snapshot/snapshot-courtesy.d.ts +68 -0
  555. package/system/dist/builtins/snapshot/snapshot-durable-store.d.ts +36 -0
  556. package/system/dist/builtins/snapshot/snapshot-fatigue.d.ts +41 -0
  557. package/system/dist/builtins/snapshot/snapshot-grab-pick.d.ts +20 -0
  558. package/system/dist/builtins/snapshot/snapshot-link-url.d.ts +66 -0
  559. package/system/dist/builtins/snapshot/snapshot-media-handler.d.ts +121 -0
  560. package/system/dist/builtins/snapshot/snapshot-resize.d.ts +75 -0
  561. package/system/dist/builtins/snapshot/snapshot.addon.d.ts +581 -0
  562. package/system/dist/builtins/sqlite-storage/analyze-stats.d.ts +83 -0
  563. package/system/dist/builtins/sqlite-storage/config-store.d.ts +8 -0
  564. package/system/dist/builtins/sqlite-storage/database-snapshot-provider.d.ts +18 -0
  565. package/system/dist/builtins/sqlite-storage/device-store.d.ts +23 -0
  566. package/system/dist/builtins/sqlite-storage/file-host-client.d.ts +75 -0
  567. package/system/dist/builtins/sqlite-storage/file-host-handlers.d.ts +27 -0
  568. package/system/dist/builtins/sqlite-storage/file-host-protocol.d.ts +167 -0
  569. package/system/dist/builtins/sqlite-storage/file-host-worker.d.ts +1 -0
  570. package/system/dist/builtins/sqlite-storage/filesystem-browse-provider.d.ts +25 -0
  571. package/system/dist/builtins/sqlite-storage/filesystem-storage-provider.d.ts +83 -0
  572. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.d.ts +33 -0
  573. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +419 -0
  574. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +411 -0
  575. package/system/dist/builtins/sqlite-storage/filter-compiler.d.ts +126 -0
  576. package/system/dist/builtins/sqlite-storage/index.d.ts +12 -0
  577. package/system/dist/builtins/sqlite-storage/index.js +82 -0
  578. package/system/dist/builtins/sqlite-storage/index.mjs +50 -0
  579. package/system/dist/builtins/sqlite-storage/integration-record-kinds.d.ts +31 -0
  580. package/system/dist/builtins/sqlite-storage/integration-registry.d.ts +34 -0
  581. package/system/dist/builtins/sqlite-storage/migrations/migration-actions.d.ts +12 -0
  582. package/system/dist/builtins/sqlite-storage/migrations/migration-edits.d.ts +35 -0
  583. package/system/dist/builtins/sqlite-storage/migrations/migration-engine.d.ts +125 -0
  584. package/system/dist/builtins/sqlite-storage/migrations/migration-hold.d.ts +23 -0
  585. package/system/dist/builtins/sqlite-storage/migrations/migration-pass.d.ts +48 -0
  586. package/system/dist/builtins/sqlite-storage/migrations/migration-restore-marker.d.ts +3 -0
  587. package/system/dist/builtins/sqlite-storage/migrations/migration-types.d.ts +151 -0
  588. package/system/dist/builtins/sqlite-storage/migrations/migrations-provider.d.ts +61 -0
  589. package/system/dist/builtins/sqlite-storage/owned-sqlite-file.d.ts +173 -0
  590. package/system/dist/builtins/sqlite-storage/path-guard.d.ts +11 -0
  591. package/system/dist/builtins/sqlite-storage/placement-errors.d.ts +60 -0
  592. package/system/dist/builtins/sqlite-storage/placement-router.d.ts +85 -0
  593. package/system/dist/builtins/sqlite-storage/prefix-range.d.ts +50 -0
  594. package/system/dist/builtins/sqlite-storage/query-bounds.d.ts +110 -0
  595. package/system/dist/builtins/sqlite-storage/query-profiler.d.ts +242 -0
  596. package/system/dist/builtins/sqlite-storage/records/records-catalog.d.ts +27 -0
  597. package/system/dist/builtins/sqlite-storage/records/records-engine-types.d.ts +48 -0
  598. package/system/dist/builtins/sqlite-storage/records/records-engine.d.ts +115 -0
  599. package/system/dist/builtins/sqlite-storage/records/records-explain.d.ts +18 -0
  600. package/system/dist/builtins/sqlite-storage/records/records-plan.d.ts +95 -0
  601. package/system/dist/builtins/sqlite-storage/records/records-probe.d.ts +33 -0
  602. package/system/dist/builtins/sqlite-storage/records/records-provider.d.ts +72 -0
  603. package/system/dist/builtins/sqlite-storage/records/records-rows.d.ts +46 -0
  604. package/system/dist/builtins/sqlite-storage/records/records-sql.d.ts +39 -0
  605. package/system/dist/builtins/sqlite-storage/retired-settings-keys.d.ts +276 -0
  606. package/system/dist/builtins/sqlite-storage/shm-lock-canary.d.ts +60 -0
  607. package/system/dist/builtins/sqlite-storage/sqlite-pragmas.d.ts +191 -0
  608. package/system/dist/builtins/sqlite-storage/sqlite-settings-backend.d.ts +583 -0
  609. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.d.ts +52 -0
  610. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +2960 -0
  611. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +2952 -0
  612. package/system/dist/builtins/sqlite-storage/sqlite-snapshot-protocol.d.ts +54 -0
  613. package/system/dist/builtins/sqlite-storage/sqlite-snapshot-worker.d.ts +33 -0
  614. package/system/dist/builtins/sqlite-storage/sqlite-snapshotter.d.ts +118 -0
  615. package/system/dist/builtins/sqlite-storage/stale-data/stale-data-audit.d.ts +81 -0
  616. package/system/dist/builtins/sqlite-storage/stale-data/stale-data-ports.d.ts +17 -0
  617. package/system/dist/builtins/sqlite-storage/statement-shape.d.ts +64 -0
  618. package/system/dist/builtins/sqlite-storage/storage-admin-provider.d.ts +33 -0
  619. package/system/dist/builtins/sqlite-storage/table-sizes.d.ts +95 -0
  620. package/system/dist/builtins/sqlite-storage/vector-index-shared.d.ts +81 -0
  621. package/system/dist/builtins/sqlite-storage/vector-index-vec.d.ts +143 -0
  622. package/system/dist/builtins/sqlite-storage/vector-provider.d.ts +30 -0
  623. package/system/dist/builtins/sqlite-storage/wal-checkpoint-policy.d.ts +196 -0
  624. package/system/dist/builtins/sqlite-storage/wal-checkpoint-worker.d.ts +1 -0
  625. package/system/dist/builtins/sqlite-storage/wal-checkpointer.d.ts +76 -0
  626. package/system/dist/builtins/sqlite-storage/wal-maintenance.d.ts +130 -0
  627. package/system/dist/builtins/storage-orchestrator/access-guards.d.ts +43 -0
  628. package/system/dist/builtins/storage-orchestrator/data-store-dispatch.d.ts +39 -0
  629. package/system/dist/builtins/storage-orchestrator/drain-ratchet.d.ts +104 -0
  630. package/system/dist/builtins/storage-orchestrator/drain-state-store.d.ts +26 -0
  631. package/system/dist/builtins/storage-orchestrator/hub-settings-forward.d.ts +128 -0
  632. package/system/dist/builtins/storage-orchestrator/index.d.ts +7 -0
  633. package/system/dist/builtins/storage-orchestrator/index.js +11 -0
  634. package/system/dist/builtins/storage-orchestrator/index.mjs +2 -0
  635. package/system/dist/builtins/storage-orchestrator/location-class-paths.d.ts +13 -0
  636. package/system/dist/builtins/storage-orchestrator/location-history-recorder.d.ts +76 -0
  637. package/system/dist/builtins/storage-orchestrator/location-occupancy-slice.d.ts +71 -0
  638. package/system/dist/builtins/storage-orchestrator/location-occupancy.d.ts +19 -0
  639. package/system/dist/builtins/storage-orchestrator/location-protection.d.ts +20 -0
  640. package/system/dist/builtins/storage-orchestrator/location-repoint-move.d.ts +57 -0
  641. package/system/dist/builtins/storage-orchestrator/location-repointer.d.ts +97 -0
  642. package/system/dist/builtins/storage-orchestrator/location-root-collision.d.ts +80 -0
  643. package/system/dist/builtins/storage-orchestrator/location-secrets.d.ts +114 -0
  644. package/system/dist/builtins/storage-orchestrator/location-store.d.ts +82 -0
  645. package/system/dist/builtins/storage-orchestrator/location-volume-capacity.d.ts +58 -0
  646. package/system/dist/builtins/storage-orchestrator/provider-discovery.d.ts +24 -0
  647. package/system/dist/builtins/storage-orchestrator/record-kinds.d.ts +43 -0
  648. package/system/dist/builtins/storage-orchestrator/storage-cleanup-coordinator.d.ts +68 -0
  649. package/system/dist/builtins/storage-orchestrator/storage-location-band-monitor.d.ts +77 -0
  650. package/system/dist/builtins/storage-orchestrator/storage-migration-coordinator.d.ts +241 -0
  651. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.d.ts +318 -0
  652. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +5280 -0
  653. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +5264 -0
  654. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.service.d.ts +475 -0
  655. package/system/dist/builtins/storage-orchestrator/storage-pressure-manager.d.ts +115 -0
  656. package/system/dist/builtins/system-backup/backup-encryption.d.ts +94 -0
  657. package/system/dist/builtins/system-backup/system-backup.service.d.ts +308 -0
  658. package/system/dist/builtins/system-config/index.d.ts +2 -0
  659. package/system/dist/builtins/system-config/index.js +10 -0
  660. package/system/dist/builtins/system-config/index.mjs +2 -0
  661. package/system/dist/builtins/system-config/mesh-actions.d.ts +3 -0
  662. package/system/dist/builtins/system-config/record-kinds.d.ts +32 -0
  663. package/system/dist/builtins/system-config/system-config.addon.d.ts +56 -0
  664. package/system/dist/builtins/system-config/system-config.addon.js +89334 -0
  665. package/system/dist/builtins/system-config/system-config.addon.mjs +89233 -0
  666. package/system/dist/builtins/winston-logging/index.d.ts +3 -0
  667. package/system/dist/builtins/winston-logging/index.js +324 -0
  668. package/system/dist/builtins/winston-logging/index.mjs +313 -0
  669. package/system/dist/builtins/winston-logging/log-file-cursor.d.ts +12 -0
  670. package/system/dist/builtins/winston-logging/log-file-index-store.d.ts +11 -0
  671. package/system/dist/builtins/winston-logging/log-file-index.d.ts +77 -0
  672. package/system/dist/builtins/winston-logging/log-file-read-client.d.ts +44 -0
  673. package/system/dist/builtins/winston-logging/log-file-read-protocol.d.ts +41 -0
  674. package/system/dist/builtins/winston-logging/log-file-read-worker.d.ts +1 -0
  675. package/system/dist/builtins/winston-logging/log-file-reader.d.ts +51 -0
  676. package/system/dist/builtins/winston-logging/winston-destination.d.ts +39 -0
  677. package/system/dist/builtins/winston-logging/winston-logging.addon.d.ts +20 -0
  678. package/system/dist/chunk-CNf5ZN-e.mjs +37 -0
  679. package/system/dist/chunk-Cek0wNdY.js +64 -0
  680. package/system/dist/composition-sources-C14epb_m.js +155 -0
  681. package/system/dist/composition-sources-EXNuxmGQ.mjs +132 -0
  682. package/system/dist/constants-DIGWBiNC.mjs +20 -0
  683. package/system/dist/constants-M7NtSiRo.js +66 -0
  684. package/system/dist/coral-accelerators-BSVsBVzt.js +250 -0
  685. package/system/dist/coral-accelerators-DBlgWB8k.mjs +231 -0
  686. package/system/dist/custom-action-registry-JuMHGKEc.js +1638 -0
  687. package/system/dist/custom-action-registry-oHl1xltx.mjs +1482 -0
  688. package/system/dist/device-ca-3vmBP1i0.js +474 -0
  689. package/system/dist/device-ca-DZlvNBWU.mjs +367 -0
  690. package/system/dist/dist-DcMqHB_N.mjs +108095 -0
  691. package/system/dist/dist-M9yHiIY7.js +110554 -0
  692. package/system/dist/download/hosted-model-revisions.d.ts +10 -0
  693. package/system/dist/download/model-download-service.d.ts +35 -0
  694. package/system/dist/download/model-downloader.d.ts +156 -0
  695. package/system/dist/events/event-bus.d.ts +10 -0
  696. package/system/dist/events/system-event-bus.d.ts +14 -0
  697. package/system/dist/feature/feature-manager.d.ts +11 -0
  698. package/system/dist/file-host-worker.js +160 -0
  699. package/system/dist/file-host-worker.mjs +160 -0
  700. package/system/dist/formatter-DkYZ4LXp.mjs +162 -0
  701. package/system/dist/formatter-xbxeV4GD.js +167 -0
  702. package/system/dist/framework-resolver-hook.mjs +49 -0
  703. package/system/dist/http/asset-compression.d.ts +55 -0
  704. package/system/dist/http/authenticated-file-server.d.ts +53 -0
  705. package/system/dist/http/data-plane-registry.d.ts +58 -0
  706. package/system/dist/http/file-data-plane.d.ts +18 -0
  707. package/system/dist/http/lan-http-bind.d.ts +41 -0
  708. package/system/dist/http/reverse-proxy.d.ts +42 -0
  709. package/system/dist/hub-mdns-ciao-CpCKuQnK.js +1163 -0
  710. package/system/dist/hub-mdns-ciao-Czz2ssit.mjs +942 -0
  711. package/system/dist/i18n/catalog-registry.d.ts +35 -0
  712. package/system/dist/i18n/index.d.ts +2 -0
  713. package/system/dist/index.d.ts +156 -0
  714. package/system/dist/index.js +28736 -0
  715. package/system/dist/index.mjs +28065 -0
  716. package/system/dist/intel-accelerators-BvBjZn4j.js +16 -0
  717. package/system/dist/intel-accelerators-idEumqk1.mjs +15 -0
  718. package/system/dist/intel-npu-C8HKvRQF.mjs +27 -0
  719. package/system/dist/intel-npu-DYF5hO5K.js +28 -0
  720. package/system/dist/kernel/addon-class-resolver.d.ts +4 -0
  721. package/system/dist/kernel/addon-engine-manager.d.ts +22 -0
  722. package/system/dist/kernel/addon-health-monitor.d.ts +163 -0
  723. package/system/dist/kernel/addon-installer.d.ts +651 -0
  724. package/system/dist/kernel/addon-loader.d.ts +144 -0
  725. package/system/dist/kernel/addon-manifest.d.ts +128 -0
  726. package/system/dist/kernel/addon-refused-error.d.ts +30 -0
  727. package/system/dist/kernel/addon-residue.d.ts +45 -0
  728. package/system/dist/kernel/addon-settings-store.d.ts +43 -0
  729. package/system/dist/kernel/addon-version-policy.d.ts +34 -0
  730. package/system/dist/kernel/anon-rss.d.ts +12 -0
  731. package/system/dist/kernel/array-buffer-census.d.ts +118 -0
  732. package/system/dist/kernel/bootstrap-config.d.ts +7 -0
  733. package/system/dist/kernel/cap-router-builder.d.ts +180 -0
  734. package/system/dist/kernel/capability-handle.d.ts +46 -0
  735. package/system/dist/kernel/capability-registry.d.ts +621 -0
  736. package/system/dist/kernel/config-manager.d.ts +174 -0
  737. package/system/dist/kernel/config-schema.d.ts +37 -0
  738. package/system/dist/kernel/custom-action-registry.d.ts +32 -0
  739. package/system/dist/kernel/deps/addon-deps-manager.d.ts +28 -0
  740. package/system/dist/kernel/deps/closure-dedupe.d.ts +105 -0
  741. package/system/dist/kernel/deps/ensure-addon-natives.d.ts +41 -0
  742. package/system/dist/kernel/deps/ensure-native-prebuilds.d.ts +40 -0
  743. package/system/dist/kernel/deps/manifest-native-deps.d.ts +42 -0
  744. package/system/dist/kernel/deps/manifest-python-deps.d.ts +20 -0
  745. package/system/dist/kernel/deps/manifest-system-deps.d.ts +18 -0
  746. package/system/dist/kernel/deps/npm-command.d.ts +60 -0
  747. package/system/dist/kernel/deps/system-package-allowlist.d.ts +12 -0
  748. package/system/dist/kernel/deps/system-package-broker.d.ts +31 -0
  749. package/system/dist/kernel/deps/system-package-client.d.ts +9 -0
  750. package/system/dist/kernel/device-call-redirect.d.ts +18 -0
  751. package/system/dist/kernel/device-registry.d.ts +29 -0
  752. package/system/dist/kernel/device-settings-store.d.ts +74 -0
  753. package/system/dist/kernel/event-loop-stall-monitor.d.ts +41 -0
  754. package/system/dist/kernel/event-plane-report.d.ts +225 -0
  755. package/system/dist/kernel/fs-utils.d.ts +88 -0
  756. package/system/dist/kernel/gc-census.d.ts +161 -0
  757. package/system/dist/kernel/heap-spaces.d.ts +112 -0
  758. package/system/dist/kernel/heap-watch.d.ts +816 -0
  759. package/system/dist/kernel/host-externals.d.ts +12 -0
  760. package/system/dist/kernel/hwaccel/hwaccel-resolver.d.ts +56 -0
  761. package/system/dist/kernel/hwaccel/vaapi-init-probe.d.ts +29 -0
  762. package/system/dist/kernel/index.d.ts +116 -0
  763. package/system/dist/kernel/inference/inference-resolver.d.ts +22 -0
  764. package/system/dist/kernel/inference/local-python-runtimes.d.ts +2 -0
  765. package/system/dist/kernel/infra-capabilities.d.ts +13 -0
  766. package/system/dist/kernel/isolated-builtin-phase.d.ts +57 -0
  767. package/system/dist/kernel/lifecycle/job-journal.d.ts +19 -0
  768. package/system/dist/kernel/lifecycle/lifecycle-job-engine.d.ts +106 -0
  769. package/system/dist/kernel/lifecycle/staging-area.d.ts +31 -0
  770. package/system/dist/kernel/moleculer/accessory-prune-gate.d.ts +55 -0
  771. package/system/dist/kernel/moleculer/addon-context-factory.d.ts +104 -0
  772. package/system/dist/kernel/moleculer/addon-data-plane-facility.d.ts +19 -0
  773. package/system/dist/kernel/moleculer/addon-deploy-source.d.ts +16 -0
  774. package/system/dist/kernel/moleculer/addon-peer-bytes-facility.d.ts +25 -0
  775. package/system/dist/kernel/moleculer/addon-runner.d.ts +1 -0
  776. package/system/dist/kernel/moleculer/addon-service-factory.d.ts +50 -0
  777. package/system/dist/kernel/moleculer/agent-event-scope.d.ts +49 -0
  778. package/system/dist/kernel/moleculer/agent-ui-unlock.d.ts +67 -0
  779. package/system/dist/kernel/moleculer/broker-factory.d.ts +95 -0
  780. package/system/dist/kernel/moleculer/broker-transport-swap.d.ts +60 -0
  781. package/system/dist/kernel/moleculer/cap-usage-registry.d.ts +126 -0
  782. package/system/dist/kernel/moleculer/capabilities-access.d.ts +21 -0
  783. package/system/dist/kernel/moleculer/child-addon-call-dispatch.d.ts +53 -0
  784. package/system/dist/kernel/moleculer/child-cap-descriptors.d.ts +34 -0
  785. package/system/dist/kernel/moleculer/child-cap-dispatch.d.ts +59 -0
  786. package/system/dist/kernel/moleculer/children-batch-loader.d.ts +98 -0
  787. package/system/dist/kernel/moleculer/core-cap-service.d.ts +65 -0
  788. package/system/dist/kernel/moleculer/crash-supervisor.d.ts +50 -0
  789. package/system/dist/kernel/moleculer/device-cap-proxy.d.ts +70 -0
  790. package/system/dist/kernel/moleculer/device-event-ring.d.ts +155 -0
  791. package/system/dist/kernel/moleculer/event-bus-core.d.ts +198 -0
  792. package/system/dist/kernel/moleculer/event-bus.d.ts +106 -0
  793. package/system/dist/kernel/moleculer/hub-log-forwarder.d.ts +36 -0
  794. package/system/dist/kernel/moleculer/hub-service.d.ts +39 -0
  795. package/system/dist/kernel/moleculer/init-watchdog.d.ts +60 -0
  796. package/system/dist/kernel/moleculer/mesh-access-middleware.d.ts +42 -0
  797. package/system/dist/kernel/moleculer/mesh-identity.d.ts +57 -0
  798. package/system/dist/kernel/moleculer/mesh-mtls/constants.d.ts +17 -0
  799. package/system/dist/kernel/moleculer/mesh-mtls/index.d.ts +12 -0
  800. package/system/dist/kernel/moleculer/mesh-mtls/mesh-ca-keeper.d.ts +60 -0
  801. package/system/dist/kernel/moleculer/mesh-mtls/mesh-ca.d.ts +49 -0
  802. package/system/dist/kernel/moleculer/mesh-mtls/mesh-certificate-registry.d.ts +105 -0
  803. package/system/dist/kernel/moleculer/mesh-mtls/mesh-crl.d.ts +16 -0
  804. package/system/dist/kernel/moleculer/mesh-mtls/mesh-membership.d.ts +64 -0
  805. package/system/dist/kernel/moleculer/mesh-mtls/mesh-peer-transport.d.ts +47 -0
  806. package/system/dist/kernel/moleculer/mesh-mtls/mesh-renewal.d.ts +135 -0
  807. package/system/dist/kernel/moleculer/mesh-mtls/mesh-tls-enabler.d.ts +9 -0
  808. package/system/dist/kernel/moleculer/mesh-mtls/mesh-tls-gate.d.ts +40 -0
  809. package/system/dist/kernel/moleculer/mesh-mtls/pairing/agent-pairing.d.ts +214 -0
  810. package/system/dist/kernel/moleculer/mesh-mtls/pairing/hub-pairing.d.ts +115 -0
  811. package/system/dist/kernel/moleculer/mesh-mtls/pairing/index.d.ts +3 -0
  812. package/system/dist/kernel/moleculer/mesh-mtls/pairing/pairing-protocol.d.ts +107 -0
  813. package/system/dist/kernel/moleculer/mesh-mtls/tls-tcp-transporter.d.ts +242 -0
  814. package/system/dist/kernel/moleculer/mesh-queue-report.d.ts +51 -0
  815. package/system/dist/kernel/moleculer/node-registry.d.ts +146 -0
  816. package/system/dist/kernel/moleculer/process-context.d.ts +4 -0
  817. package/system/dist/kernel/moleculer/process-service.d.ts +92 -0
  818. package/system/dist/kernel/moleculer/provider-registry.d.ts +28 -0
  819. package/system/dist/kernel/moleculer/readiness-context.d.ts +67 -0
  820. package/system/dist/kernel/moleculer/readiness-service.d.ts +37 -0
  821. package/system/dist/kernel/moleculer/records-api-transport.d.ts +9 -0
  822. package/system/dist/kernel/moleculer/register-framework-resolver.d.ts +8 -0
  823. package/system/dist/kernel/moleculer/register-node-client.d.ts +49 -0
  824. package/system/dist/kernel/moleculer/remote-logger.d.ts +43 -0
  825. package/system/dist/kernel/moleculer/resilient-cap-call.d.ts +28 -0
  826. package/system/dist/kernel/moleculer/runner-addon-settings.d.ts +29 -0
  827. package/system/dist/kernel/moleculer/runner-device-settings.d.ts +39 -0
  828. package/system/dist/kernel/moleculer/runner-heap-flags.d.ts +228 -0
  829. package/system/dist/kernel/moleculer/runner-native-allocator.d.ts +107 -0
  830. package/system/dist/kernel/moleculer/runner-process-group.d.ts +96 -0
  831. package/system/dist/kernel/moleculer/runner-refusal.d.ts +27 -0
  832. package/system/dist/kernel/moleculer/runtime-state-load.d.ts +29 -0
  833. package/system/dist/kernel/moleculer/settings-read-guard.d.ts +49 -0
  834. package/system/dist/kernel/moleculer/stream-probe-service.d.ts +28 -0
  835. package/system/dist/kernel/moleculer/trpc-links.d.ts +244 -0
  836. package/system/dist/kernel/moleculer/typed-array-serde.d.ts +14 -0
  837. package/system/dist/kernel/moleculer/worker-device-restore.d.ts +10 -0
  838. package/system/dist/kernel/outbound-queue-watch.d.ts +94 -0
  839. package/system/dist/kernel/prefix-walk.d.ts +39 -0
  840. package/system/dist/kernel/process-cpu-census.d.ts +74 -0
  841. package/system/dist/kernel/provider-kind-drift.d.ts +21 -0
  842. package/system/dist/kernel/restart-coordinator.d.ts +90 -0
  843. package/system/dist/kernel/sections-store.d.ts +20 -0
  844. package/system/dist/kernel/settings-door-view.d.ts +41 -0
  845. package/system/dist/kernel/settings-read-error.d.ts +35 -0
  846. package/system/dist/kernel/settings-view-types.d.ts +80 -0
  847. package/system/dist/kernel/socket-plane-report.d.ts +268 -0
  848. package/system/dist/kernel/status-overlay.d.ts +38 -0
  849. package/system/dist/kernel/storage-location-registry.d.ts +55 -0
  850. package/system/dist/kernel/store-settings-view.d.ts +14 -0
  851. package/system/dist/kernel/system-settings-mirror.d.ts +46 -0
  852. package/system/dist/kernel/system-settings-policy.d.ts +28 -0
  853. package/system/dist/kernel/transport/cap-action-census.d.ts +218 -0
  854. package/system/dist/kernel/transport/cap-action-name.d.ts +100 -0
  855. package/system/dist/kernel/transport/cap-child-index.d.ts +49 -0
  856. package/system/dist/kernel/transport/cap-route-resolver.d.ts +231 -0
  857. package/system/dist/kernel/transport/cap-route.d.ts +168 -0
  858. package/system/dist/kernel/transport/cap-routing-hints.d.ts +42 -0
  859. package/system/dist/kernel/transport/child-cap-protocol.d.ts +307 -0
  860. package/system/dist/kernel/transport/claimed-get-status.d.ts +39 -0
  861. package/system/dist/kernel/transport/create-local-transport.d.ts +7 -0
  862. package/system/dist/kernel/transport/device-call-redirect.d.ts +39 -0
  863. package/system/dist/kernel/transport/frame-codec.d.ts +122 -0
  864. package/system/dist/kernel/transport/hub-cap-forward.d.ts +96 -0
  865. package/system/dist/kernel/transport/index.d.ts +38 -0
  866. package/system/dist/kernel/transport/local-child-client.d.ts +199 -0
  867. package/system/dist/kernel/transport/local-child-registry.d.ts +654 -0
  868. package/system/dist/kernel/transport/local-endpoint-path.d.ts +6 -0
  869. package/system/dist/kernel/transport/local-transport.d.ts +122 -0
  870. package/system/dist/kernel/transport/parent-unowned-call.d.ts +283 -0
  871. package/system/dist/kernel/transport/peer-answered-error.d.ts +21 -0
  872. package/system/dist/kernel/transport/socket-channel.d.ts +116 -0
  873. package/system/dist/kernel/transport/socket-traffic.d.ts +118 -0
  874. package/system/dist/kernel/transport/uds-event-bridge.d.ts +85 -0
  875. package/system/dist/kernel/transport/uds-event-bus.d.ts +93 -0
  876. package/system/dist/kernel/transport/uds-local-transport.d.ts +18 -0
  877. package/system/dist/kernel/transport/uds-log-ingest.d.ts +43 -0
  878. package/system/dist/kernel/transport/uds-logger.d.ts +44 -0
  879. package/system/dist/kernel/utils/ring-buffer.d.ts +15 -0
  880. package/system/dist/kernel/workspace-detect.d.ts +9 -0
  881. package/system/dist/lib-5THG9eKz.mjs +15545 -0
  882. package/system/dist/lib-C3U1yluo.js +7110 -0
  883. package/system/dist/lib-CZ3g2WTS.js +15549 -0
  884. package/system/dist/lib-DFZblCIu.mjs +7106 -0
  885. package/system/dist/lifecycle/lifecycle-state-machine.d.ts +28 -0
  886. package/system/dist/log-file-read-protocol-B7M3X3bT.mjs +785 -0
  887. package/system/dist/log-file-read-protocol-D0WcLbIV.js +817 -0
  888. package/system/dist/log-file-read-worker.js +64 -0
  889. package/system/dist/log-file-read-worker.mjs +64 -0
  890. package/system/dist/log-read-filter-Bi066jwU.js +134 -0
  891. package/system/dist/log-read-filter-D7Ev3zm-.mjs +93 -0
  892. package/system/dist/logging/formatter.d.ts +57 -0
  893. package/system/dist/logging/log-manager.d.ts +145 -0
  894. package/system/dist/logging/log-read-filter.d.ts +43 -0
  895. package/system/dist/logging/log-redactor.d.ts +30 -0
  896. package/system/dist/logging/log-ring-buffer.d.ts +62 -0
  897. package/system/dist/logging/logging-gate.d.ts +76 -0
  898. package/system/dist/logging/logging-gate.singleton.d.ts +16 -0
  899. package/system/dist/logging/partitioned-log-buffer.d.ts +169 -0
  900. package/system/dist/logging/scoped-logger.d.ts +17 -0
  901. package/system/dist/migrations/hub/index.d.ts +11 -0
  902. package/system/dist/ms-CgH2OFlD.mjs +120 -0
  903. package/system/dist/ms-LB3giGoU.js +124 -0
  904. package/system/dist/network/network-quality.d.ts +11 -0
  905. package/system/dist/notification/notification-service.d.ts +43 -0
  906. package/system/dist/notification/toast-service.d.ts +22 -0
  907. package/system/dist/pipeline/engine-manager-resolver.d.ts +15 -0
  908. package/system/dist/pipeline/pipeline-runner.d.ts +8 -0
  909. package/system/dist/pipeline/pipeline-validator.d.ts +13 -0
  910. package/system/dist/platform-key-source-BWlq0jjn.mjs +23 -0
  911. package/system/dist/platform-key-source-Di7HrlGR.js +40 -0
  912. package/system/dist/prefix-range-D_KueXbQ.js +27 -0
  913. package/system/dist/prefix-range-Dl0znowN.mjs +22 -0
  914. package/system/dist/prefix-walk-DAOBSyH1.mjs +88 -0
  915. package/system/dist/prefix-walk-Dv6MLZlM.js +99 -0
  916. package/system/dist/process/proc-stat.d.ts +75 -0
  917. package/system/dist/process/resource-monitor.d.ts +28 -0
  918. package/system/dist/python/python-env-manager.d.ts +12 -0
  919. package/system/dist/read-all-rows-CVoO1ONM.js +29 -0
  920. package/system/dist/read-all-rows-TaPqdWNF.mjs +25 -0
  921. package/system/dist/records/read-all-rows.d.ts +6 -0
  922. package/system/dist/repl/interfaces.d.ts +31 -0
  923. package/system/dist/repl/repl-engine.d.ts +8 -0
  924. package/system/dist/resource-monitor-Di9daRwI.mjs +96 -0
  925. package/system/dist/resource-monitor-mio9dSCT.js +113 -0
  926. package/system/dist/restore-archive-Cy7jGqiD.js +4325 -0
  927. package/system/dist/restore-archive-DS4nvQ43.mjs +4213 -0
  928. package/system/dist/retention-Dqm_EiVq.mjs +893 -0
  929. package/system/dist/retention-Ufa2fci-.js +1024 -0
  930. package/system/dist/retired-settings-keys-C8nOOr5H.js +381 -0
  931. package/system/dist/retired-settings-keys-u6xQA6r7.mjs +364 -0
  932. package/system/dist/safe-buffer-B1OjL1I9.mjs +42 -0
  933. package/system/dist/safe-buffer-D3aoa-7X.js +46 -0
  934. package/system/dist/settle-sources-Bhsy57y-.js +38 -0
  935. package/system/dist/settle-sources-CDtNC8ub.mjs +33 -0
  936. package/system/dist/snapshot-courtesy-CyFs1M3I.mjs +167 -0
  937. package/system/dist/snapshot-courtesy-D_C5-nC0.js +192 -0
  938. package/system/dist/sqlite-snapshot-protocol-2QaTouWV.mjs +34 -0
  939. package/system/dist/sqlite-snapshot-protocol-B9OndqZv.js +51 -0
  940. package/system/dist/sqlite-snapshot-worker.js +185 -0
  941. package/system/dist/sqlite-snapshot-worker.mjs +179 -0
  942. package/system/dist/src-CnAqG6EF.js +714 -0
  943. package/system/dist/src-hG4grMU4.mjs +709 -0
  944. package/system/dist/storage/fs-storage-backend.d.ts +40 -0
  945. package/system/dist/storage/storage-location-manager.d.ts +23 -0
  946. package/system/dist/storage/storage-manager.d.ts +83 -0
  947. package/system/dist/tls/agent-https-names.d.ts +25 -0
  948. package/system/dist/tls/agent-https.d.ts +111 -0
  949. package/system/dist/tls/boot-tls.d.ts +35 -0
  950. package/system/dist/tls/cert-backdate.d.ts +10 -0
  951. package/system/dist/tls/cert-evaluation.d.ts +41 -0
  952. package/system/dist/tls/cert-identity.d.ts +60 -0
  953. package/system/dist/tls/cert-issue.d.ts +57 -0
  954. package/system/dist/tls/cert-manager.d.ts +124 -0
  955. package/system/dist/tls/cert-name-constraints.d.ts +53 -0
  956. package/system/dist/tls/cert-utc-time.d.ts +1 -0
  957. package/system/dist/tls/https-listener.d.ts +30 -0
  958. package/system/dist/tls/index.d.ts +12 -0
  959. package/system/dist/tls/tls-actions.d.ts +49 -0
  960. package/system/dist/tls/tls-status.d.ts +57 -0
  961. package/system/dist/tls/uploaded-cert.d.ts +46 -0
  962. package/system/dist/wal-checkpoint-policy-BahrTtyD.mjs +186 -0
  963. package/system/dist/wal-checkpoint-policy-d2z2qPqx.js +233 -0
  964. package/system/dist/wal-checkpoint-worker.js +144 -0
  965. package/system/dist/wal-checkpoint-worker.mjs +143 -0
  966. package/system/dist/wal-maintenance-BmugbgS7.js +0 -0
  967. package/system/dist/wal-maintenance-Bnb2QzYG.mjs +0 -0
  968. package/system/dist/x509.es-BRiJgOvu.mjs +11939 -0
  969. package/system/dist/x509.es-WtnRNyYS.js +12076 -0
  970. package/system/package.json +516 -0
@@ -0,0 +1,3106 @@
1
+ import { Dt as ROOT_BUCKET_KEY, Gt as UNATTRIBUTED_BUCKET_KEY, Ho as createEvent, Jr as metricsProviderCapability, Ms as EventCategory, Oi as resolveBucketMs, Qa as BaseAddon, Si as reducePoints, js as errMsg, ur as foldSnapshotByFunction } from "../../dist-DcMqHB_N.mjs";
2
+ import { access, readFile, readdir } from "node:fs/promises";
3
+ import { promisify } from "node:util";
4
+ import * as os$1 from "node:os";
5
+ import { platform } from "node:os";
6
+ import * as fs$1 from "node:fs";
7
+ import { constants, readFileSync } from "node:fs";
8
+ import { execFile } from "node:child_process";
9
+ //#region src/builtins/native-metrics/cgroup-memory.ts
10
+ /** `readFileSync`, with every failure flattened to `null`. */
11
+ var nodeCgroupFileReader = { read(path) {
12
+ try {
13
+ return readFileSync(path, "utf8");
14
+ } catch {
15
+ return null;
16
+ }
17
+ } };
18
+ /** Where the v2 unified hierarchy is mounted, and where v1 hangs its controllers. */
19
+ var CGROUP_MOUNT_ROOT = "/sys/fs/cgroup";
20
+ /**
21
+ * The i915 GEM accounting file.
22
+ *
23
+ * **debugfs, and it is not mounted in our containers.** Verified on the live
24
+ * hub on 2026-08-29: readable on the Unraid host (`6014 shrinkable [0 free]
25
+ * objects, 1194934272 bytes`), `ENOENT` inside the `CamStack` container where
26
+ * `native-metrics` actually runs. It is probed ONCE per process and latched —
27
+ * a bind mount cannot appear under a running container — so an absent file
28
+ * costs one failed `open` for the life of the runner and one log line, never a
29
+ * failure per tick.
30
+ *
31
+ * Making it populate is a one-line change on the container, not here:
32
+ * mounting `/sys/kernel/debug` read-only into `CamStack` fills this field on
33
+ * the next sample with no code change.
34
+ */
35
+ var I915_GEM_OBJECTS_PATH = "/sys/kernel/debug/dri/0/i915_gem_objects";
36
+ /**
37
+ * v1's "no limit" sentinel — `PAGE_COUNTER_MAX << PAGE_SHIFT`, which is what a
38
+ * 64-bit kernel writes into `memory.limit_in_bytes` when nothing is set. It is
39
+ * a limit in the same sense that `Infinity` is a number, so it reads as `null`.
40
+ */
41
+ var V1_UNLIMITED_SENTINEL = 0x7ffffffffffff000;
42
+ /**
43
+ * Parse `/proc/self/cgroup`.
44
+ *
45
+ * Two formats, and the file may contain both on a hybrid host:
46
+ *
47
+ * ```
48
+ * 0::/ ← v2 unified
49
+ * 5:memory:/docker/9f3c… ← v1, memory controller
50
+ * 4:cpu,cpuacct:/docker/9f3c… ← v1, other controllers
51
+ * ```
52
+ *
53
+ * v2 wins when present: on a hybrid host the unified hierarchy is the one
54
+ * carrying `memory.current`, and every camstack deployment is v2 (verified on
55
+ * the live hub, which reports the single line `0::/`).
56
+ *
57
+ * Returns `null` when the file names no memory hierarchy at all — which is
58
+ * also what a non-Linux host produces, because there is no file to read.
59
+ */
60
+ function parseCgroupSelf(text) {
61
+ let v1 = null;
62
+ for (const rawLine of text.split("\n")) {
63
+ const line = rawLine.trim();
64
+ if (line.length === 0) continue;
65
+ const first = line.indexOf(":");
66
+ if (first < 0) continue;
67
+ const second = line.indexOf(":", first + 1);
68
+ if (second < 0) continue;
69
+ const controllers = line.slice(first + 1, second);
70
+ const path = line.slice(second + 1);
71
+ if (path.length === 0) continue;
72
+ const normalized = path.startsWith("/") ? path : `/${path}`;
73
+ if (controllers.length === 0) return {
74
+ version: "v2",
75
+ path: normalized
76
+ };
77
+ if (v1 === null && controllers.split(",").includes("memory")) v1 = {
78
+ version: "v1",
79
+ path: normalized
80
+ };
81
+ }
82
+ return v1;
83
+ }
84
+ /**
85
+ * Parse a `memory.stat` file — v1 or v2, both are `key value` per line.
86
+ *
87
+ * Unknown keys are KEPT rather than refused: a v2 `memory.stat` carries ~50
88
+ * fields and we read five of them, and a kernel that adds a sixth must not
89
+ * turn into a parse failure. A malformed line is skipped, not thrown on.
90
+ */
91
+ function parseCgroupStat(text) {
92
+ const out = /* @__PURE__ */ new Map();
93
+ for (const rawLine of text.split("\n")) {
94
+ const line = rawLine.trim();
95
+ if (line.length === 0) continue;
96
+ const space = line.indexOf(" ");
97
+ if (space <= 0) continue;
98
+ const key = line.slice(0, space);
99
+ const value = Number(line.slice(space + 1).trim());
100
+ if (!Number.isFinite(value)) continue;
101
+ out.set(key, value);
102
+ }
103
+ return out;
104
+ }
105
+ /**
106
+ * Parse a single-scalar cgroup file (`memory.current`, `memory.max`, …).
107
+ *
108
+ * `max` — v2's word for "no limit" — and v1's `V1_UNLIMITED_SENTINEL` both
109
+ * become `null`, because a ceiling nothing can reach is not a ceiling and
110
+ * charting it as 8 exabytes would flatten every real series to zero.
111
+ */
112
+ function parseCgroupScalar(text) {
113
+ const trimmed = text.trim();
114
+ if (trimmed.length === 0) return null;
115
+ if (trimmed === "max") return null;
116
+ const value = Number(trimmed);
117
+ if (!Number.isFinite(value) || value < 0) return null;
118
+ if (value >= V1_UNLIMITED_SENTINEL) return null;
119
+ return value;
120
+ }
121
+ /**
122
+ * Parse the first line of `i915_gem_objects`.
123
+ *
124
+ * ```
125
+ * 6014 shrinkable [0 free] objects, 1194934272 bytes
126
+ * ```
127
+ *
128
+ * Only the byte total is taken. The format has changed across kernel releases
129
+ * more than once, so a line that does not match reads `null` — an unrecognised
130
+ * format is UNKNOWN, never zero.
131
+ */
132
+ function parseI915GemObjects(text) {
133
+ const match = text.match(/^\s*\d+\s+shrinkable\b[^,\n]*,\s*(\d+)\s+bytes/m);
134
+ if (match === null) return null;
135
+ const bytes = Number(match[1]);
136
+ return Number.isFinite(bytes) ? bytes : null;
137
+ }
138
+ /**
139
+ * Find the cgroup from INSIDE this process — never a hard-coded path.
140
+ *
141
+ * The path the hub happens to have (`/sys/fs/cgroup/docker/<id>/memory.stat`
142
+ * as seen from the Unraid host) is an artefact of where you are standing. From
143
+ * inside the container the same cgroup is at the mount ROOT, because Docker
144
+ * gives the container its own cgroup namespace and `/proc/self/cgroup` reports
145
+ * `0::/`. Hard-coding either one breaks the other.
146
+ *
147
+ * So the resolution is: ask `/proc/self/cgroup` which hierarchy and which
148
+ * path, then take the FIRST candidate directory that actually publishes the
149
+ * usage file.
150
+ *
151
+ * - **v2** — `<mount><path>` then `<mount>`. The second candidate is the
152
+ * namespaced case and the one that answers on our hub; the first is the
153
+ * un-namespaced case (a host process, or `--cgroupns=host`).
154
+ * - **v1** — `<mount>/memory<path>` then `<mount>/memory`, same reasoning.
155
+ * - **neither** — `null`. macOS has no `/proc/self/cgroup` at all, so a
156
+ * developer Mac lands here and reports nothing, which is the truth.
157
+ */
158
+ function resolveCgroupMemoryLayout(fs) {
159
+ const selfText = fs.read("/proc/self/cgroup");
160
+ if (selfText === null) return null;
161
+ const entry = parseCgroupSelf(selfText);
162
+ if (entry === null) return null;
163
+ const suffix = entry.path === "/" ? "" : entry.path;
164
+ const candidates = entry.version === "v2" ? [`${CGROUP_MOUNT_ROOT}${suffix}`, CGROUP_MOUNT_ROOT] : [`${CGROUP_MOUNT_ROOT}/memory${suffix}`, `${CGROUP_MOUNT_ROOT}/memory`];
165
+ const usageFile = entry.version === "v2" ? "memory.current" : "memory.usage_in_bytes";
166
+ const limitFile = entry.version === "v2" ? "memory.max" : "memory.limit_in_bytes";
167
+ for (const directory of candidates) {
168
+ if (fs.read(`${directory}/${usageFile}`) === null) continue;
169
+ return {
170
+ source: entry.version === "v2" ? "cgroup-v2" : "cgroup-v1",
171
+ directory,
172
+ currentPath: `${directory}/${usageFile}`,
173
+ limitPath: `${directory}/${limitFile}`,
174
+ statPath: `${directory}/memory.stat`
175
+ };
176
+ }
177
+ return null;
178
+ }
179
+ /** A stat lookup that answers `null` for a key this hierarchy does not publish. */
180
+ function statValue(stat, key) {
181
+ const value = stat.get(key);
182
+ return value === void 0 ? null : value;
183
+ }
184
+ /**
185
+ * v2 publishes `slab` directly; older v2 kernels publish only the two halves.
186
+ * Summing them is the same number, so the fallback is exact rather than an
187
+ * approximation — and when neither is present the answer is `null`.
188
+ */
189
+ function resolveSlab(stat) {
190
+ const direct = statValue(stat, "slab");
191
+ if (direct !== null) return direct;
192
+ const reclaimable = stat.get("slab_reclaimable");
193
+ const unreclaimable = stat.get("slab_unreclaimable");
194
+ if (reclaimable === void 0 || unreclaimable === void 0) return null;
195
+ return reclaimable + unreclaimable;
196
+ }
197
+ /**
198
+ * Turn one layout's three files into a snapshot.
199
+ *
200
+ * Pure over the text, so the whole mapping — including a v2 `memory.stat` full
201
+ * of fields we do not read — is testable against a real fixture.
202
+ *
203
+ * v1's `memory.stat` names the same quantities differently and publishes fewer
204
+ * of them: `rss` is the anonymous charge, `cache` is the page cache, and there
205
+ * is no slab accounting at all. Mapping them onto the same field names is what
206
+ * makes a v1 node and a v2 node comparable; reporting `slabBytes: null` on v1
207
+ * is what stops that comparison from lying.
208
+ */
209
+ function buildContainerMemorySnapshot(input) {
210
+ const currentBytes = parseCgroupScalar(input.currentText);
211
+ if (currentBytes === null) return null;
212
+ const stat = input.statText === null ? /* @__PURE__ */ new Map() : parseCgroupStat(input.statText);
213
+ const isV2 = input.source === "cgroup-v2";
214
+ return {
215
+ source: input.source,
216
+ currentBytes,
217
+ limitBytes: input.limitText === null ? null : parseCgroupScalar(input.limitText),
218
+ anonBytes: statValue(stat, isV2 ? "anon" : "rss"),
219
+ fileBytes: statValue(stat, isV2 ? "file" : "cache"),
220
+ shmemBytes: statValue(stat, "shmem"),
221
+ slabBytes: isV2 ? resolveSlab(stat) : null,
222
+ gpuShmemBytes: input.gpuShmemBytes
223
+ };
224
+ }
225
+ /**
226
+ * The sampler. Resolves once, latches, and logs TRANSITIONS only.
227
+ *
228
+ * Three states are worth a line and none of them is worth one per tick:
229
+ *
230
+ * 1. **Resolution** — once, at the first sample. Either the layout that
231
+ * answered, or "no cgroup on this node", which is a fact about the node and
232
+ * not an error.
233
+ * 2. **GPU probe** — once, at the first sample. Absent debugfs is the normal
234
+ * case inside a container and is stated as such, then never retried: a bind
235
+ * mount cannot appear under a running container.
236
+ * 3. **Read failing / recovering** — a cgroup that resolved and then stopped
237
+ * answering is a real change and says so, once in each direction. A tick
238
+ * that fails while already failing is silent, because the first line
239
+ * already said it.
240
+ *
241
+ * The silence is bounded by design: at the 10 s snapshot cadence a per-tick
242
+ * warning would be 8 640 lines a day on a node that simply is not Linux.
243
+ */
244
+ var ContainerMemoryProbe = class {
245
+ logger;
246
+ fs;
247
+ wantGpu;
248
+ resolved = false;
249
+ layout = null;
250
+ gpuProbed = false;
251
+ gpuReadable = false;
252
+ /** `null` until the first sample — so the FIRST outcome is a transition too. */
253
+ lastReadOk = null;
254
+ constructor(deps) {
255
+ this.logger = deps.logger;
256
+ this.fs = deps.fs ?? nodeCgroupFileReader;
257
+ this.wantGpu = deps.readGpu ?? true;
258
+ }
259
+ /** Did this node resolve a cgroup at all? Absent is a reportable fact. */
260
+ get available() {
261
+ return this.layout !== null;
262
+ }
263
+ /**
264
+ * One reading, or `null` when this node has no cgroup or the cgroup stopped
265
+ * answering. `null` is ABSENT — the caller contributes no point, and no
266
+ * point is what a chart must show, never a zero.
267
+ */
268
+ sample() {
269
+ const layout = this.resolveOnce();
270
+ if (layout === null) return null;
271
+ const currentText = this.fs.read(layout.currentPath);
272
+ if (currentText === null) {
273
+ this.noteRead(false, `unreadable: ${layout.currentPath}`);
274
+ return null;
275
+ }
276
+ const snapshot = buildContainerMemorySnapshot({
277
+ source: layout.source,
278
+ currentText,
279
+ limitText: this.fs.read(layout.limitPath),
280
+ statText: this.fs.read(layout.statPath),
281
+ gpuShmemBytes: this.readGpuShmem()
282
+ });
283
+ if (snapshot === null) {
284
+ this.noteRead(false, `unparseable: ${layout.currentPath}`);
285
+ return null;
286
+ }
287
+ this.noteRead(true, null);
288
+ return snapshot;
289
+ }
290
+ /** Resolve on first use and never again — a cgroup does not move under a pid. */
291
+ resolveOnce() {
292
+ if (this.resolved) return this.layout;
293
+ this.resolved = true;
294
+ try {
295
+ this.layout = resolveCgroupMemoryLayout(this.fs);
296
+ } catch (err) {
297
+ this.layout = null;
298
+ this.logger.warn("cgroup memory resolution failed — container memory will be ABSENT", { meta: { error: errMsg(err) } });
299
+ return null;
300
+ }
301
+ if (this.layout === null) {
302
+ this.logger.info("no cgroup on this node — container memory is ABSENT, not zero, for every sample", { meta: {
303
+ platform: process.platform,
304
+ probed: "/proc/self/cgroup"
305
+ } });
306
+ return null;
307
+ }
308
+ this.logger.info("container memory resolved from the cgroup", { meta: {
309
+ source: this.layout.source,
310
+ directory: this.layout.directory
311
+ } });
312
+ return this.layout;
313
+ }
314
+ /**
315
+ * The GPU number, probed once.
316
+ *
317
+ * It is host-wide and lives in debugfs, so it is absent far more often than
318
+ * it is present — inside every camstack container today. One `open` decides
319
+ * it for the life of the process; after that an unreadable file costs
320
+ * nothing at all, not even a syscall.
321
+ */
322
+ readGpuShmem() {
323
+ if (!this.wantGpu) return null;
324
+ if (!this.gpuProbed) {
325
+ this.gpuProbed = true;
326
+ const text = this.fs.read(I915_GEM_OBJECTS_PATH);
327
+ this.gpuReadable = text !== null && parseI915GemObjects(text) !== null;
328
+ this.logger.info(this.gpuReadable ? "i915 GEM accounting is readable — GPU-backed shmem will be reported" : "i915 GEM accounting is NOT readable — gpuShmemBytes stays UNKNOWN (this is normal: debugfs is not mounted in the container, and a node with no Intel GPU has no such file)", { meta: { path: I915_GEM_OBJECTS_PATH } });
329
+ if (!this.gpuReadable) return null;
330
+ return text === null ? null : parseI915GemObjects(text);
331
+ }
332
+ if (!this.gpuReadable) return null;
333
+ const text = this.fs.read(I915_GEM_OBJECTS_PATH);
334
+ return text === null ? null : parseI915GemObjects(text);
335
+ }
336
+ /** Log a read outcome only when it CHANGES. Never once per tick. */
337
+ noteRead(ok, reason) {
338
+ if (this.lastReadOk === ok) return;
339
+ const first = this.lastReadOk === null;
340
+ this.lastReadOk = ok;
341
+ if (!ok) {
342
+ this.logger.warn("cgroup memory stopped answering — container memory is ABSENT until it returns", { meta: { reason: reason ?? "unknown" } });
343
+ return;
344
+ }
345
+ if (!first) this.logger.info("cgroup memory is answering again");
346
+ }
347
+ };
348
+ //#endregion
349
+ //#region src/builtins/native-metrics/cgroup-pids.ts
350
+ /**
351
+ * `pids.max` is either a number or the word `max`.
352
+ *
353
+ * `max` means NO ceiling, and that is `null` — not `Infinity`, not a huge
354
+ * number. A ceiling nothing can reach is not a ceiling, and reporting one
355
+ * would make every utilisation fraction on an unlimited node read as 0 %.
356
+ */
357
+ function parsePidsMax(text) {
358
+ const trimmed = text.trim();
359
+ if (trimmed.length === 0 || trimmed === "max") return null;
360
+ const value = Number(trimmed);
361
+ if (!Number.isFinite(value) || value < 0) return null;
362
+ return value;
363
+ }
364
+ /**
365
+ * `pids.events` is `key value` per line; we read exactly one key:
366
+ *
367
+ * ```
368
+ * max 22
369
+ * ```
370
+ *
371
+ * `max` is the number of times a fork was refused because the limit was hit.
372
+ * A kernel that publishes only `pids.events.local`, or a file we cannot make
373
+ * sense of, answers `null` — unknown, never zero, because zero here means "no
374
+ * refusals have ever happened" and that is a claim.
375
+ */
376
+ function parsePidsEvents(text) {
377
+ for (const rawLine of text.split("\n")) {
378
+ const line = rawLine.trim();
379
+ if (line.length === 0) continue;
380
+ const space = line.indexOf(" ");
381
+ if (space <= 0) continue;
382
+ if (line.slice(0, space) !== "max") continue;
383
+ const value = Number(line.slice(space + 1).trim());
384
+ if (!Number.isFinite(value) || value < 0) return null;
385
+ return value;
386
+ }
387
+ return null;
388
+ }
389
+ /** Turn one layout's files into a snapshot. Pure over the text. */
390
+ function buildContainerPidsSnapshot(input) {
391
+ const current = Number(input.currentText.trim());
392
+ if (!Number.isFinite(current) || current < 0) return null;
393
+ const max = input.maxText === null ? null : parsePidsMax(input.maxText);
394
+ return {
395
+ source: input.source,
396
+ current,
397
+ max,
398
+ usedFraction: max === null || max === 0 ? null : current / max,
399
+ refusals: input.eventsText === null ? null : parsePidsEvents(input.eventsText)
400
+ };
401
+ }
402
+ /**
403
+ * Find the pids cgroup from INSIDE this process, never a hard-coded path —
404
+ * same reasoning as the memory layout: from inside the container the cgroup is
405
+ * at the mount ROOT (`0::/`), from the host it is `<mount>/docker/<id>`, and
406
+ * hard-coding either one breaks the other.
407
+ */
408
+ function resolveCgroupPidsLayout(fs) {
409
+ const selfText = fs.read("/proc/self/cgroup");
410
+ if (selfText === null) return null;
411
+ const entry = parseCgroupSelf(selfText);
412
+ if (entry === null) return null;
413
+ const suffix = entry.path === "/" ? "" : entry.path;
414
+ const candidates = entry.version === "v2" ? [`${CGROUP_MOUNT_ROOT}${suffix}`, CGROUP_MOUNT_ROOT] : [`${CGROUP_MOUNT_ROOT}/pids${suffix}`, `${CGROUP_MOUNT_ROOT}/pids`];
415
+ for (const directory of candidates) {
416
+ if (fs.read(`${directory}/pids.current`) === null) continue;
417
+ return {
418
+ source: entry.version === "v2" ? "cgroup-v2" : "cgroup-v1",
419
+ directory,
420
+ currentPath: `${directory}/pids.current`,
421
+ maxPath: `${directory}/pids.max`,
422
+ eventsPath: `${directory}/pids.events`
423
+ };
424
+ }
425
+ return null;
426
+ }
427
+ var DEFAULT_HEARTBEAT_MS = 6e4;
428
+ var DEFAULT_PRESSURE_FRACTION = .8;
429
+ /**
430
+ * The sampler.
431
+ *
432
+ * Its logging is deliberately different from the memory probe's, because the
433
+ * operator asked for a DAY of regular readings before deciding whether to
434
+ * raise the ceiling: there is a heartbeat, on its own cadence, whatever the
435
+ * sampling tick is. Three lines exist and no more:
436
+ *
437
+ * 1. **Resolution**, once — the hierarchy that answered, or "no cgroup here",
438
+ * which is a fact about the node and not an error.
439
+ * 2. **Heartbeat**, every `heartbeatMs` — current, ceiling, utilisation and
440
+ * the lifetime refusal count. INFO while there is room, WARN while we are
441
+ * above `pressureFraction`, and one INFO when it comes back down, so the
442
+ * log carries BOTH edges of a pressure episode rather than only its start.
443
+ * 3. **A refusal**, immediately — the `pids.events` counter rose, so the
444
+ * kernel said no that many times since the last sample and some subsystem
445
+ * silently did without a thread. This one never waits for the heartbeat.
446
+ */
447
+ var ContainerPidsProbe = class {
448
+ logger;
449
+ fs;
450
+ now;
451
+ heartbeatMs;
452
+ pressureFraction;
453
+ resolved = false;
454
+ layout = null;
455
+ lastHeartbeatAt = null;
456
+ lastRefusals = null;
457
+ underPressure = false;
458
+ constructor(deps) {
459
+ this.logger = deps.logger;
460
+ this.fs = deps.fs ?? nodeCgroupFileReader;
461
+ this.now = deps.now ?? Date.now;
462
+ this.heartbeatMs = deps.heartbeatMs ?? DEFAULT_HEARTBEAT_MS;
463
+ this.pressureFraction = deps.pressureFraction ?? DEFAULT_PRESSURE_FRACTION;
464
+ }
465
+ /** Did this node resolve a pids cgroup at all? Absent is a reportable fact. */
466
+ get available() {
467
+ return this.layout !== null;
468
+ }
469
+ /** One reading, or `null` where there is no cgroup or it stopped answering. */
470
+ sample() {
471
+ const layout = this.resolveOnce();
472
+ if (layout === null) return null;
473
+ const currentText = this.fs.read(layout.currentPath);
474
+ if (currentText === null) return null;
475
+ const snapshot = buildContainerPidsSnapshot({
476
+ source: layout.source,
477
+ currentText,
478
+ maxText: this.fs.read(layout.maxPath),
479
+ eventsText: this.fs.read(layout.eventsPath)
480
+ });
481
+ if (snapshot === null) return null;
482
+ this.report(snapshot);
483
+ return snapshot;
484
+ }
485
+ resolveOnce() {
486
+ if (this.resolved) return this.layout;
487
+ this.resolved = true;
488
+ try {
489
+ this.layout = resolveCgroupPidsLayout(this.fs);
490
+ } catch (err) {
491
+ this.layout = null;
492
+ this.logger.warn("cgroup pids resolution failed — the pid ceiling will be ABSENT", { meta: { error: errMsg(err) } });
493
+ return null;
494
+ }
495
+ if (this.layout === null) {
496
+ this.logger.info("no pids cgroup on this node — the pid ceiling is ABSENT, not unlimited, for every sample", { meta: {
497
+ platform: process.platform,
498
+ probed: "/proc/self/cgroup"
499
+ } });
500
+ return null;
501
+ }
502
+ this.logger.info("pid ceiling resolved from the cgroup", { meta: {
503
+ source: this.layout.source,
504
+ directory: this.layout.directory
505
+ } });
506
+ return this.layout;
507
+ }
508
+ report(snapshot) {
509
+ this.reportRefusals(snapshot);
510
+ const at = this.now();
511
+ const pressure = snapshot.usedFraction !== null && snapshot.usedFraction >= this.pressureFraction;
512
+ if (this.underPressure && !pressure) {
513
+ this.underPressure = false;
514
+ this.logger.info("pid pressure recovered — back under the guard fraction", { meta: this.meta(snapshot) });
515
+ this.lastHeartbeatAt = at;
516
+ return;
517
+ }
518
+ if (!(this.lastHeartbeatAt === null || at - this.lastHeartbeatAt >= this.heartbeatMs)) return;
519
+ this.lastHeartbeatAt = at;
520
+ this.underPressure = pressure;
521
+ if (pressure) {
522
+ this.logger.warn("pid ceiling is being approached — a refused clone() is silent work loss, and this container counts THREADS", { meta: this.meta(snapshot) });
523
+ return;
524
+ }
525
+ this.logger.info("pid ceiling", { meta: this.meta(snapshot) });
526
+ }
527
+ /**
528
+ * The counter only ever rises, so a rise is a refusal that happened in this
529
+ * window. Reported the moment it is seen — never held for the heartbeat,
530
+ * because this is the line that says work was lost.
531
+ */
532
+ reportRefusals(snapshot) {
533
+ const refusals = snapshot.refusals;
534
+ if (refusals === null) return;
535
+ const previous = this.lastRefusals;
536
+ this.lastRefusals = refusals;
537
+ if (previous === null || refusals <= previous) return;
538
+ this.logger.warn("the kernel REFUSED a fork at the pid ceiling — something asked for a thread and did not get one", { meta: {
539
+ ...this.meta(snapshot),
540
+ refusedSinceLastSample: refusals - previous
541
+ } });
542
+ }
543
+ meta(snapshot) {
544
+ return {
545
+ current: snapshot.current,
546
+ max: snapshot.max,
547
+ usedPct: snapshot.usedFraction === null ? null : Math.round(snapshot.usedFraction * 1e3) / 10,
548
+ refusalsLifetime: snapshot.refusals,
549
+ source: snapshot.source
550
+ };
551
+ }
552
+ };
553
+ /**
554
+ * One node's fixed-capacity circular buffer of samples.
555
+ *
556
+ * Mirrors {@link LogRingBuffer}: write at `head`, wrap, and once full every
557
+ * accepted sample evicts the oldest. `rows` is carried alongside so the fleet
558
+ * budget never has to walk the samples to know what a partition costs.
559
+ */
560
+ var LoadPartition = class {
561
+ capacity;
562
+ slots;
563
+ head = 0;
564
+ count = 0;
565
+ rows = 0;
566
+ /** Newest retained sample's timestamp — the monotonic gate for `push`. */
567
+ newestAtMs = null;
568
+ constructor(capacity) {
569
+ this.capacity = capacity;
570
+ this.slots = Array.from({ length: capacity });
571
+ }
572
+ /**
573
+ * Accept a sample.
574
+ *
575
+ * A sample at or before the newest one already held is REFUSED. The bus drops
576
+ * a node's own broadcast echo, but a cross-node redelivery or a replayed
577
+ * subscription must not be able to double a point — and idempotence here is
578
+ * what lets every reader above treat the series as a set.
579
+ *
580
+ * `accepted` is reported separately from `rowDelta` on purpose: a full ring
581
+ * that evicts a sample of the same size has a delta of zero and is not a
582
+ * refusal, and conflating the two would silently stop advancing the write
583
+ * ordinal on a steady-state cluster.
584
+ */
585
+ push(sample) {
586
+ if (this.newestAtMs !== null && sample.atMs <= this.newestAtMs) return {
587
+ accepted: false,
588
+ rowDelta: 0
589
+ };
590
+ const evicted = this.count === this.capacity ? this.slots[this.head]?.processes.length ?? 0 : 0;
591
+ this.slots[this.head] = sample;
592
+ this.head = (this.head + 1) % this.capacity;
593
+ if (this.count < this.capacity) this.count++;
594
+ this.newestAtMs = sample.atMs;
595
+ const rowDelta = sample.processes.length - evicted;
596
+ this.rows += rowDelta;
597
+ return {
598
+ accepted: true,
599
+ rowDelta
600
+ };
601
+ }
602
+ /** Drop the oldest sample. Returns the rows reclaimed (0 when empty). */
603
+ dropOldest() {
604
+ if (this.count === 0) return 0;
605
+ const index = (this.head - this.count + this.capacity) % this.capacity;
606
+ const victim = this.slots[index];
607
+ this.slots[index] = void 0;
608
+ this.count--;
609
+ const reclaimed = victim?.processes.length ?? 0;
610
+ this.rows -= reclaimed;
611
+ if (this.count === 0) this.newestAtMs = null;
612
+ return reclaimed;
613
+ }
614
+ /** Oldest-first, optionally only what is strictly newer than `sinceMs`. */
615
+ list(sinceMs) {
616
+ const out = [];
617
+ for (let i = 0; i < this.count; i++) {
618
+ const index = (this.head - this.count + i + this.capacity) % this.capacity;
619
+ const sample = this.slots[index];
620
+ if (sample === void 0) continue;
621
+ if (sinceMs !== void 0 && sample.atMs <= sinceMs) continue;
622
+ out.push(sample);
623
+ }
624
+ return out;
625
+ }
626
+ size() {
627
+ return this.count;
628
+ }
629
+ rowCount() {
630
+ return this.rows;
631
+ }
632
+ oldestAtMs() {
633
+ if (this.count === 0) return null;
634
+ const index = (this.head - this.count + this.capacity) % this.capacity;
635
+ return this.slots[index]?.atMs ?? null;
636
+ }
637
+ lastWriteAtMs() {
638
+ return this.newestAtMs;
639
+ }
640
+ };
641
+ /**
642
+ * The partitioned ring: one {@link LoadPartition} per node id.
643
+ *
644
+ * Three bounds, doing three different jobs — the same division as the log
645
+ * buffer, for the same reason:
646
+ *
647
+ * - **`samplesPerNode`** is HARD and per partition. It is what the operator
648
+ * asked for (an hour) and it can never be exceeded.
649
+ * - **`maxTotalProcessRows`** is the FLEET budget, and it is denominated in the
650
+ * thing memory is proportional to. When it bites, the oldest sample of the
651
+ * HEAVIEST partition is dropped — the node creating the pressure is the node
652
+ * that pays, and a quiet node keeps its full hour. The node just written to is
653
+ * NOT protected here: if it is the heaviest, it is the culprit.
654
+ * - **`maxNodes`** is the backstop against an unbounded key space, and it drops
655
+ * whole partitions least-recently-written first, never the one being written.
656
+ *
657
+ * Plus {@link DEFAULT_NODE_IDLE_EVICTION_MS}, which is what stops a node that
658
+ * simply stopped emitting from living in memory forever.
659
+ */
660
+ var NodeLoadRing = class {
661
+ partitions = /* @__PURE__ */ new Map();
662
+ /**
663
+ * Node id → write ordinal of its last accepted sample. A monotonic counter,
664
+ * not a clock: partition eviction must follow the order writes actually
665
+ * happened, and node clocks disagree.
666
+ */
667
+ lastWriteSeq = /* @__PURE__ */ new Map();
668
+ writeSeq = 0;
669
+ totalRows = 0;
670
+ samplesPerNode;
671
+ maxTotalProcessRows;
672
+ maxNodes;
673
+ idleEvictionMs;
674
+ now;
675
+ constructor(options = {}) {
676
+ this.samplesPerNode = options.samplesPerNode ?? 180;
677
+ this.maxTotalProcessRows = options.maxTotalProcessRows ?? 32e3;
678
+ this.maxNodes = options.maxNodes ?? 16;
679
+ this.idleEvictionMs = options.idleEvictionMs ?? 36e5;
680
+ this.now = options.now ?? Date.now;
681
+ }
682
+ /**
683
+ * Retain one snapshot. `processes` is stored by reference — the payload is
684
+ * already an immutable arrival off the bus, and copying it would double the
685
+ * measured cost for nothing.
686
+ *
687
+ * Returns whether the sample was ACCEPTED — that is, whether it was new
688
+ * rather than a replay of a timestamp this node has already delivered.
689
+ *
690
+ * The return value is not diagnostics. It is the idempotence gate the
691
+ * DURABLE tier rides on this return value (`node-metrics-history-recorder.ts`):
692
+ * only an accepted sample is sent to device-history. The gate is one monotonic
693
+ * comparison in memory.
694
+ */
695
+ record(nodeId, atMs, processes) {
696
+ if (nodeId.length === 0) return false;
697
+ this.sweepIdle();
698
+ let partition = this.partitions.get(nodeId);
699
+ if (partition === void 0) {
700
+ partition = new LoadPartition(this.samplesPerNode);
701
+ this.partitions.set(nodeId, partition);
702
+ }
703
+ const outcome = partition.push({
704
+ atMs,
705
+ processes
706
+ });
707
+ if (!outcome.accepted) {
708
+ if (partition.size() === 0) this.partitions.delete(nodeId);
709
+ return false;
710
+ }
711
+ this.totalRows += outcome.rowDelta;
712
+ this.lastWriteSeq.set(nodeId, ++this.writeSeq);
713
+ if (this.partitions.size > this.maxNodes) this.evictPartitions(this.partitions.size - this.maxNodes, nodeId);
714
+ this.enforceRowBudget();
715
+ return true;
716
+ }
717
+ /**
718
+ * Read one node's retained series, oldest-first.
719
+ *
720
+ * `sinceMs` is EXCLUSIVE: a caller passes the newest timestamp it already
721
+ * holds and gets back only what it is missing. That is the whole contract
722
+ * that lets the admin UI seed from here and then continue live without
723
+ * doubling a point it already drew.
724
+ *
725
+ * A node nobody has recorded answers with an empty series, not an error —
726
+ * unknown is the truth about a node that has not reported.
727
+ */
728
+ read(nodeId, sinceMs) {
729
+ this.sweepIdle();
730
+ const partition = this.partitions.get(nodeId);
731
+ if (partition === void 0) return {
732
+ nodeId,
733
+ samples: [],
734
+ retainedSamples: 0,
735
+ oldestAtMs: null,
736
+ capacity: this.samplesPerNode
737
+ };
738
+ return {
739
+ nodeId,
740
+ samples: partition.list(sinceMs),
741
+ retainedSamples: partition.size(),
742
+ oldestAtMs: partition.oldestAtMs(),
743
+ capacity: this.samplesPerNode
744
+ };
745
+ }
746
+ /** Node ids with a live partition. Observability for the fleet bound. */
747
+ nodeIds() {
748
+ return [...this.partitions.keys()];
749
+ }
750
+ /** Process rows retained across every partition — the number that IS memory. */
751
+ rowCount() {
752
+ return this.totalRows;
753
+ }
754
+ /** Samples retained across every partition. */
755
+ sampleCount() {
756
+ let total = 0;
757
+ for (const partition of this.partitions.values()) total += partition.size();
758
+ return total;
759
+ }
760
+ /**
761
+ * Drop partitions whose newest sample is older than the retention window.
762
+ *
763
+ * Lazy, on write and on read — never a timer. A timer would be a new
764
+ * periodic cost in a subsystem whose entire premise is that it adds none,
765
+ * and a ring that nobody writes to and nobody reads is not growing either.
766
+ */
767
+ sweepIdle() {
768
+ const cutoff = this.now() - this.idleEvictionMs;
769
+ for (const [nodeId, partition] of [...this.partitions.entries()]) {
770
+ const lastWrite = partition.lastWriteAtMs();
771
+ if (lastWrite !== null && lastWrite > cutoff) continue;
772
+ this.dropPartition(nodeId);
773
+ }
774
+ }
775
+ /**
776
+ * Bring the fleet back under the row budget by dropping the OLDEST sample of
777
+ * the HEAVIEST partition, repeatedly.
778
+ *
779
+ * Terminates: every iteration removes one sample from a non-empty partition,
780
+ * and the population of samples is finite and strictly decreasing.
781
+ */
782
+ enforceRowBudget() {
783
+ while (this.totalRows > this.maxTotalProcessRows) {
784
+ const victim = this.heaviestPartition();
785
+ if (victim === null) return;
786
+ const [nodeId, partition] = victim;
787
+ this.totalRows -= partition.dropOldest();
788
+ if (partition.size() === 0) this.dropPartition(nodeId);
789
+ }
790
+ }
791
+ heaviestPartition() {
792
+ let best = null;
793
+ for (const entry of this.partitions.entries()) {
794
+ if (entry[1].size() === 0) continue;
795
+ if (best === null || entry[1].rowCount() > best[1].rowCount()) best = entry;
796
+ }
797
+ return best;
798
+ }
799
+ /** Drop `count` whole partitions, least-recently-written first. */
800
+ evictPartitions(count, protectedNodeId) {
801
+ const order = [...this.partitions.keys()].filter((nodeId) => nodeId !== protectedNodeId).toSorted((a, b) => (this.lastWriteSeq.get(a) ?? 0) - (this.lastWriteSeq.get(b) ?? 0));
802
+ let remaining = count;
803
+ for (const nodeId of order) {
804
+ if (remaining <= 0) return;
805
+ this.dropPartition(nodeId);
806
+ remaining -= 1;
807
+ }
808
+ }
809
+ /** Remove a partition and everything that indexes it. */
810
+ dropPartition(nodeId) {
811
+ const partition = this.partitions.get(nodeId);
812
+ if (partition === void 0) return;
813
+ this.totalRows -= partition.rowCount();
814
+ this.partitions.delete(nodeId);
815
+ this.lastWriteSeq.delete(nodeId);
816
+ }
817
+ };
818
+ var CONTAINER_MEMORY_MAX_TOTAL_ROWS = 2880;
819
+ var ContainerMemoryRing = class {
820
+ ring;
821
+ constructor(options = {}) {
822
+ this.ring = new NodeLoadRing({
823
+ samplesPerNode: options.samplesPerNode ?? 180,
824
+ maxTotalProcessRows: CONTAINER_MEMORY_MAX_TOTAL_ROWS,
825
+ ...options.now !== void 0 ? { now: options.now } : {}
826
+ });
827
+ }
828
+ record(nodeId, atMs, snapshot) {
829
+ return this.ring.record(nodeId, atMs, [snapshot]);
830
+ }
831
+ read(nodeId, sinceMs) {
832
+ const series = this.ring.read(nodeId, sinceMs);
833
+ const out = [];
834
+ for (const sample of series.samples) {
835
+ const snapshot = sample.processes[0];
836
+ if (snapshot === void 0) continue;
837
+ out.push({
838
+ ...snapshot,
839
+ atMs: sample.atMs
840
+ });
841
+ }
842
+ return out;
843
+ }
844
+ };
845
+ function reduceContainerMemory(points, bucketMs, origin) {
846
+ if (bucketMs <= 0 || points.length === 0) return points;
847
+ const buckets = /* @__PURE__ */ new Map();
848
+ for (const point of points) {
849
+ const start = origin + Math.floor((point.atMs - origin) / bucketMs) * bucketMs;
850
+ const held = buckets.get(start);
851
+ if (held === void 0 || point.currentBytes > held.currentBytes) buckets.set(start, {
852
+ ...point,
853
+ atMs: start
854
+ });
855
+ }
856
+ return [...buckets.values()].toSorted((a, b) => a.atMs - b.atMs);
857
+ }
858
+ function mergeContainerMemory(cold, hot) {
859
+ const byAt = /* @__PURE__ */ new Map();
860
+ for (const point of cold) byAt.set(point.atMs, point);
861
+ for (const point of hot) byAt.set(point.atMs, point);
862
+ return [...byAt.values()].toSorted((a, b) => a.atMs - b.atMs);
863
+ }
864
+ var DEFAULT_MAX_ROWS = 5e5;
865
+ /** Why a value was refused — the message an operator is shown verbatim. */
866
+ var LoadSeriesConfigError = class extends Error {
867
+ constructor(message) {
868
+ super(message);
869
+ this.name = "LoadSeriesConfigError";
870
+ }
871
+ };
872
+ function requireInteger(value, field) {
873
+ const n = typeof value === "number" ? value : Number(value);
874
+ if (!Number.isFinite(n)) throw new LoadSeriesConfigError(`${field} must be a number, received ${String(value)}`);
875
+ return Math.round(n);
876
+ }
877
+ /**
878
+ * Resolve the configuration, REFUSING anything out of range.
879
+ *
880
+ * An ABSENT field takes its default — that is not a refusal, it is a document
881
+ * that has never been written. A PRESENT field outside its bounds throws.
882
+ */
883
+ function resolveLoadSeriesConfig(raw) {
884
+ let cadenceSec = 10;
885
+ if (raw.loadSeriesCadenceSec !== void 0 && raw.loadSeriesCadenceSec !== null) {
886
+ cadenceSec = requireInteger(raw.loadSeriesCadenceSec, "loadSeriesCadenceSec");
887
+ if (cadenceSec < 5 || cadenceSec > 60) throw new LoadSeriesConfigError(`load series cadence must be between 5 and 60 seconds — refused ${cadenceSec}`);
888
+ }
889
+ let retentionHours = 6;
890
+ if (raw.loadSeriesRetentionHours !== void 0 && raw.loadSeriesRetentionHours !== null) {
891
+ retentionHours = requireInteger(raw.loadSeriesRetentionHours, "loadSeriesRetentionHours");
892
+ if (retentionHours < 1 || retentionHours > 72) throw new LoadSeriesConfigError(`load series retention must be between 1 and 72 hours — refused ${retentionHours}`);
893
+ }
894
+ return {
895
+ cadenceSec,
896
+ retentionHours,
897
+ maxRows: DEFAULT_MAX_ROWS
898
+ };
899
+ }
900
+ /**
901
+ * Project the cost of a configuration from the numbers the cluster is actually
902
+ * reporting — nodes and processes OBSERVED, never a constant.
903
+ *
904
+ * This is what makes the knob honest: an operator raising retention to three
905
+ * days sees the row count and the megabytes BEFORE applying it, rather than
906
+ * discovering them afterwards. `MEASURED_BYTES_PER_ROW` is measured, not
907
+ * guessed — see `node-metrics-history-recorder.ts`.
908
+ */
909
+ function projectLoadSeriesCost(input) {
910
+ const samplesPerNodeWindow = input.config.retentionHours * 3600 / input.config.cadenceSec;
911
+ const intendedRows = Math.round(samplesPerNodeWindow * Math.max(input.observedProcessRows, 0));
912
+ const boundedRows = Math.min(intendedRows, input.config.maxRows);
913
+ return {
914
+ intendedRows,
915
+ boundedRows,
916
+ estimatedBytes: boundedRows * 87,
917
+ capBites: intendedRows > input.config.maxRows
918
+ };
919
+ }
920
+ /** Human-readable one-liner for the settings form. */
921
+ function describeLoadSeriesCost(projection) {
922
+ const mib = (projection.estimatedBytes / 1048576).toFixed(1);
923
+ const rows = projection.intendedRows.toLocaleString("en-US");
924
+ const capped = projection.boundedRows.toLocaleString("en-US");
925
+ if (!projection.capBites) return `This configuration retains ~${rows} rows ≈ ${mib} MiB on the hub database (NVMe cache), measured at 87 bytes per row.`;
926
+ return `This configuration WANTS ~${rows} rows, above the ${projection.boundedRows.toLocaleString("en-US")}-row hard cap. The table will hold ~${capped} rows ≈ ${mib} MiB and the OLDEST samples will be evicted, so the effective window is shorter than the retention you asked for.`;
927
+ }
928
+ //#endregion
929
+ //#region src/builtins/native-metrics/load-series-reader.ts
930
+ /**
931
+ * The ONE reader over both retention tiers.
932
+ *
933
+ * The hot window is the in-memory ring; the cold one is device-history raw
934
+ * points. A caller never learns which tier a point came
935
+ * from, and that is a hard requirement rather than a nicety: a second reader
936
+ * is how two charts start disagreeing about the same node, and it is how "the
937
+ * ring says X, the table says Y" becomes a question nobody can answer.
938
+ *
939
+ * Three things happen here, in this order, and each one is load-bearing:
940
+ *
941
+ * 1. **Merge and dedupe on `atMs`.** The two tiers OVERLAP by construction —
942
+ * the ring holds the last 180 snapshots and the table holds every snapshot
943
+ * the ring accepted, including those same 180. A snapshot present in both
944
+ * must contribute exactly once. Identity is `atMs`, because one node emits
945
+ * one snapshot per tick and a timestamp already held IS that snapshot. The
946
+ * HOT copy wins on a tie: it is the payload as it arrived, while the cold
947
+ * one has been through the storage encode.
948
+ * 2. **Fold per function.** The chart draws one series per addon, so the fold
949
+ * happens here rather than in the browser.
950
+ * 3. **Reduce, preserving the extremes.** See `load-series-fold.ts` for why
951
+ * the representative of a bucket is its MAX and never its mean.
952
+ *
953
+ * A GAP stays a gap through all three. Emission is fixed-cadence, so a missing
954
+ * interval means one thing — nobody reported — and nothing here fills it in.
955
+ */
956
+ /**
957
+ * Merge the two tiers into one deduped, oldest-first list of samples.
958
+ *
959
+ * Exported because the dedup is the property worth testing on its own: a
960
+ * doubled point is invisible in a total and obvious only as a chart that reads
961
+ * twice as loud as the machine.
962
+ */
963
+ function mergeSamples(cold, hot) {
964
+ const byAt = /* @__PURE__ */ new Map();
965
+ for (const sample of cold) byAt.set(sample.atMs, sample);
966
+ for (const sample of hot) byAt.set(sample.atMs, sample);
967
+ return [...byAt.values()].toSorted((a, b) => a.atMs - b.atMs);
968
+ }
969
+ /** `RetainedProcess` is already the fold's row shape — named, not re-derived. */
970
+ function toFoldRows(processes) {
971
+ return processes;
972
+ }
973
+ /**
974
+ * Merge, fold and reduce. The whole read path in one pure function, so every
975
+ * property that matters — dedup, peak survival, an empty bucket staying empty
976
+ * — is testable without a database or a ring.
977
+ */
978
+ function mergeLoadSeries(input) {
979
+ const samples = mergeSamples(input.cold, input.hot);
980
+ if (samples.length === 0) return {
981
+ series: [],
982
+ bucketMs: input.cadenceMs,
983
+ retainedSamples: 0,
984
+ oldestAtMs: null
985
+ };
986
+ const byKey = /* @__PURE__ */ new Map();
987
+ for (const sample of samples) for (const bucket of foldSnapshotByFunction(toFoldRows(sample.processes), sample.atMs)) {
988
+ const held = byKey.get(bucket.key);
989
+ if (held === void 0) byKey.set(bucket.key, {
990
+ kind: bucket.kind,
991
+ points: [bucket.point]
992
+ });
993
+ else held.points.push(bucket.point);
994
+ }
995
+ const oldestAtMs = samples[0]?.atMs ?? null;
996
+ const newestAtMs = samples.at(-1)?.atMs ?? oldestAtMs;
997
+ const spanMs = oldestAtMs === null || newestAtMs === null ? 0 : newestAtMs - oldestAtMs + input.cadenceMs;
998
+ const bucketMs = input.maxPoints === void 0 ? input.cadenceMs : resolveBucketMs(spanMs, input.cadenceMs, input.maxPoints);
999
+ const origin = oldestAtMs ?? 0;
1000
+ const series = [...byKey.entries()].map(([key, held]) => ({
1001
+ key,
1002
+ kind: held.kind,
1003
+ points: bucketMs > input.cadenceMs ? reducePoints(held.points, bucketMs, origin) : held.points
1004
+ }));
1005
+ const weight = (s) => {
1006
+ const last = s.points.at(-1);
1007
+ if (last === void 0) return -1;
1008
+ if (last.cpuMainPercent !== null && last.cpuGcPercent !== null) return last.cpuMainPercent + last.cpuGcPercent;
1009
+ return last.cpuLifetimePercent;
1010
+ };
1011
+ return {
1012
+ series: series.toSorted((a, b) => {
1013
+ const d = weight(b) - weight(a);
1014
+ return d !== 0 ? d : a.key.localeCompare(b.key);
1015
+ }),
1016
+ bucketMs,
1017
+ retainedSamples: samples.length,
1018
+ oldestAtMs
1019
+ };
1020
+ }
1021
+ //#endregion
1022
+ //#region src/builtins/native-metrics/node-metrics-history-recorder.ts
1023
+ /**
1024
+ * Node load history via device-history (D850, LTS P4) — hub only: the hub's
1025
+ * bus carries every node's snapshots, so the hub's writer is the cluster's.
1026
+ *
1027
+ * Per RUNNER, never per PID. A series was once scoped by process id, and a pid
1028
+ * changes on every runner restart: the hub held ~11.8k node series, most of
1029
+ * them one restart long, and no chart could follow a runner across a respawn.
1030
+ * The scope is now the fold's own function key (`load-series-fold.ts`): the
1031
+ * runner's addon id, or `__root__` / `__unattributed__`, so a runner keeps ONE
1032
+ * series for life and the cold tier folds exactly like the hot ring. The old
1033
+ * `process-*` keys are no longer written; their rows age out by retention.
1034
+ *
1035
+ * Node TOTALS ride the resources snapshot: CPU %, memory %, CPU temperature
1036
+ * and, when the node has one, GPU utilisation and temperature. A reading the
1037
+ * node did not take (`null`) is no point — never 0 (D393).
1038
+ *
1039
+ * The in-memory rings still serve the last hour for charts.
1040
+ */
1041
+ var ADDON_ID = "metrics-native";
1042
+ var MIB = 1048576;
1043
+ function keyOf(name) {
1044
+ return `addon:${ADDON_ID}/${name}`;
1045
+ }
1046
+ /** Per-runner series (scope = the fold key). */
1047
+ var RUNNER_CPU_MAIN_KEY = keyOf("runner-cpu-main-percent");
1048
+ var RUNNER_CPU_GC_KEY = keyOf("runner-cpu-gc-percent");
1049
+ var RUNNER_CPU_LIFETIME_KEY = keyOf("runner-cpu-lifetime-percent");
1050
+ var RUNNER_RSS_KEY = keyOf("runner-rss-mib");
1051
+ var RUNNER_PROCESSES_KEY = keyOf("runner-processes");
1052
+ /** Node totals (scope ''). */
1053
+ var NODE_CPU_KEY = keyOf("node-cpu-percent");
1054
+ var NODE_MEMORY_KEY = keyOf("node-memory-percent");
1055
+ var NODE_CPU_TEMPERATURE_KEY = keyOf("node-cpu-temperature");
1056
+ var NODE_GPU_KEY = keyOf("node-gpu-percent");
1057
+ var NODE_GPU_TEMPERATURE_KEY = keyOf("node-gpu-temperature");
1058
+ var NODE_CONTAINER_CURRENT_KEY = keyOf("container-current-mib");
1059
+ keyOf("process-cpu-percent");
1060
+ keyOf("process-rss-mib");
1061
+ /**
1062
+ * The per-runner series are downsampled to device-history's point cadence:
1063
+ * one point per series per this many ms, sustained. Process snapshots arrive
1064
+ * at the load-series cadence (5–60 s, `load-series-config.ts`), and at 5 s
1065
+ * writing each one has every other batch refused whole for `rate`.
1066
+ *
1067
+ * These two numbers MIRROR `RECORD_MIN_INTERVAL_MS` / `RECORD_RATE_SLACK_MS`
1068
+ * of the ingest door (`device-history/ingest/producer-ingest.ts`) — a builtin
1069
+ * does not import another — and `node-metrics-history-cadence.spec.ts` pins
1070
+ * them equal, so the door moving fails a spec instead of a day of history.
1071
+ */
1072
+ var RUNNER_SAMPLE_MIN_INTERVAL_MS = 1e4;
1073
+ var RUNNER_SAMPLE_RATE_SLACK_MS = 1e3;
1074
+ /** True when the door would take a point at `ts` after `slot`. */
1075
+ function sampleIsDue(slot, ts) {
1076
+ if (slot === void 0 || ts < slot.lastTs) return true;
1077
+ return ts >= slot.nextDue - RUNNER_SAMPLE_RATE_SLACK_MS;
1078
+ }
1079
+ /** The slot after a batch at `ts` was accepted — the door's own grid rule. */
1080
+ function nextSampleSlot(slot, ts) {
1081
+ if (slot === void 0) return {
1082
+ lastTs: ts,
1083
+ nextDue: ts + RUNNER_SAMPLE_MIN_INTERVAL_MS
1084
+ };
1085
+ if (ts < slot.lastTs) return slot;
1086
+ return {
1087
+ lastTs: ts,
1088
+ nextDue: Math.max(slot.nextDue, ts) + RUNNER_SAMPLE_MIN_INTERVAL_MS
1089
+ };
1090
+ }
1091
+ var DECLARATIONS = [
1092
+ {
1093
+ name: "runner-cpu-main-percent",
1094
+ displayName: "Runner CPU % (main thread)",
1095
+ unit: "%"
1096
+ },
1097
+ {
1098
+ name: "runner-cpu-gc-percent",
1099
+ displayName: "Runner CPU % (GC)",
1100
+ unit: "%"
1101
+ },
1102
+ {
1103
+ name: "runner-cpu-lifetime-percent",
1104
+ displayName: "Runner CPU % (lifetime average)",
1105
+ unit: "%"
1106
+ },
1107
+ {
1108
+ name: "runner-rss-mib",
1109
+ displayName: "Runner RSS (MiB)",
1110
+ unit: "MiB"
1111
+ },
1112
+ {
1113
+ name: "runner-processes",
1114
+ displayName: "Runner processes",
1115
+ unit: "count"
1116
+ },
1117
+ {
1118
+ name: "node-cpu-percent",
1119
+ displayName: "Node CPU %",
1120
+ unit: "%"
1121
+ },
1122
+ {
1123
+ name: "node-memory-percent",
1124
+ displayName: "Node memory %",
1125
+ unit: "%"
1126
+ },
1127
+ {
1128
+ name: "node-cpu-temperature",
1129
+ displayName: "Node CPU temperature",
1130
+ unit: "°C"
1131
+ },
1132
+ {
1133
+ name: "node-gpu-percent",
1134
+ displayName: "Node GPU %",
1135
+ unit: "%"
1136
+ },
1137
+ {
1138
+ name: "node-gpu-temperature",
1139
+ displayName: "Node GPU temperature",
1140
+ unit: "°C"
1141
+ },
1142
+ {
1143
+ name: "container-current-mib",
1144
+ displayName: "Container memory current (MiB)",
1145
+ unit: "MiB"
1146
+ }
1147
+ ];
1148
+ function nodeMetricsHistoryClient(api) {
1149
+ return {
1150
+ declareSeries: (input) => api.declareSeries.mutate(input),
1151
+ record: (input) => api.record.mutate({ points: [...input.points] }),
1152
+ queryNode: async (input) => {
1153
+ return { series: (await api.queryNode.query({ ...input })).series.map((s) => ({
1154
+ scope: s.scope,
1155
+ points: s.points.map((p) => ({
1156
+ t: p.t,
1157
+ samples: p.samples,
1158
+ value: p.last ?? p.mean
1159
+ }))
1160
+ })) };
1161
+ }
1162
+ };
1163
+ }
1164
+ function refusalCounts(result) {
1165
+ const counts = {};
1166
+ for (const r of result.refused) counts[r.reason] = (counts[r.reason] ?? 0) + r.count;
1167
+ return counts;
1168
+ }
1169
+ /** The fold's function key of a process: the same rule as `foldSnapshotByFunction`. */
1170
+ function runnerScopeOf(process) {
1171
+ if (process.addonId !== null) return process.addonId;
1172
+ return process.classification === "root" ? ROOT_BUCKET_KEY : UNATTRIBUTED_BUCKET_KEY;
1173
+ }
1174
+ function round1(value) {
1175
+ return Math.round(value * 10) / 10;
1176
+ }
1177
+ var NodeMetricsHistoryRecorder = class {
1178
+ deps;
1179
+ declared = false;
1180
+ lastTotalsAt = /* @__PURE__ */ new Map();
1181
+ /** Per node: the door's slot for the per-runner batch (see {@link sampleIsDue}). */
1182
+ sampleSlots = /* @__PURE__ */ new Map();
1183
+ /** A not-ready skip was logged and device-history has not been ready since. */
1184
+ waitLogged = false;
1185
+ constructor(deps) {
1186
+ this.deps = deps;
1187
+ }
1188
+ async declare() {
1189
+ if (this.declared) return;
1190
+ for (const d of DECLARATIONS) await this.deps.deviceHistory.declareSeries({
1191
+ name: d.name,
1192
+ subjectKind: "node",
1193
+ kind: "gauge",
1194
+ displayName: d.displayName,
1195
+ ingest: "points",
1196
+ unit: d.unit
1197
+ });
1198
+ this.declared = true;
1199
+ }
1200
+ /** One process snapshot: per-runner sums plus the container's memory. */
1201
+ async recordSample(nodeId, atMs, processes, containerMemory) {
1202
+ if (!sampleIsDue(this.sampleSlots.get(nodeId), atMs)) return;
1203
+ const subject = {
1204
+ kind: "node",
1205
+ nodeId
1206
+ };
1207
+ const point = (key, scope, value) => ({
1208
+ key,
1209
+ subject,
1210
+ scope,
1211
+ ts: atMs,
1212
+ value
1213
+ });
1214
+ const byRunner = /* @__PURE__ */ new Map();
1215
+ for (const p of processes) {
1216
+ const scope = runnerScopeOf(p);
1217
+ const t = byRunner.get(scope) ?? {
1218
+ main: 0,
1219
+ gc: 0,
1220
+ splitKnown: true,
1221
+ lifetime: 0,
1222
+ rss: 0,
1223
+ count: 0
1224
+ };
1225
+ const known = p.cpuMainPercent !== null && p.cpuGcPercent !== null;
1226
+ byRunner.set(scope, {
1227
+ main: t.main + (p.cpuMainPercent ?? 0),
1228
+ gc: t.gc + (p.cpuGcPercent ?? 0),
1229
+ splitKnown: t.splitKnown && known,
1230
+ lifetime: t.lifetime + p.cpuPercent,
1231
+ rss: t.rss + p.memoryRssBytes,
1232
+ count: t.count + 1
1233
+ });
1234
+ }
1235
+ const points = [];
1236
+ for (const [scope, t] of byRunner) {
1237
+ if (t.splitKnown) {
1238
+ points.push(point(RUNNER_CPU_MAIN_KEY, scope, round1(t.main)));
1239
+ points.push(point(RUNNER_CPU_GC_KEY, scope, round1(t.gc)));
1240
+ }
1241
+ points.push(point(RUNNER_CPU_LIFETIME_KEY, scope, round1(t.lifetime)));
1242
+ points.push(point(RUNNER_RSS_KEY, scope, Math.round(t.rss / MIB)));
1243
+ points.push(point(RUNNER_PROCESSES_KEY, scope, t.count));
1244
+ }
1245
+ if (containerMemory !== null) points.push(point(NODE_CONTAINER_CURRENT_KEY, "", Math.round(containerMemory.currentBytes / MIB)));
1246
+ if (await this.write(nodeId, atMs, points) > 0) this.sampleSlots.set(nodeId, nextSampleSlot(this.sampleSlots.get(nodeId), atMs));
1247
+ }
1248
+ /** One resources snapshot: the node's totals, at most every {@link NODE_TOTALS_MIN_INTERVAL_MS}. */
1249
+ async recordTotals(nodeId, atMs, snapshot) {
1250
+ const last = this.lastTotalsAt.get(nodeId);
1251
+ if (last !== void 0 && atMs >= last && atMs - last < 15e3) return;
1252
+ this.lastTotalsAt.set(nodeId, atMs);
1253
+ const subject = {
1254
+ kind: "node",
1255
+ nodeId
1256
+ };
1257
+ const points = [];
1258
+ const add = (key, value) => {
1259
+ if (value === null || !Number.isFinite(value)) return;
1260
+ points.push({
1261
+ key,
1262
+ subject,
1263
+ scope: "",
1264
+ ts: atMs,
1265
+ value: round1(value)
1266
+ });
1267
+ };
1268
+ add(NODE_CPU_KEY, snapshot.cpu.total);
1269
+ add(NODE_MEMORY_KEY, snapshot.memory.percent);
1270
+ add(NODE_CPU_TEMPERATURE_KEY, snapshot.cpuTemperature);
1271
+ add(NODE_GPU_KEY, snapshot.gpu?.utilization ?? null);
1272
+ add(NODE_GPU_TEMPERATURE_KEY, snapshot.gpu?.temperature ?? null);
1273
+ await this.write(nodeId, atMs, points);
1274
+ }
1275
+ async write(nodeId, atMs, points) {
1276
+ if (points.length === 0) return 0;
1277
+ if (!await this.ensureDeclared()) return 0;
1278
+ try {
1279
+ const result = await this.deps.deviceHistory.record({ points });
1280
+ if (result.refused.length > 0) {
1281
+ if (result.refused.some((r) => r.reason === "undeclared")) this.declared = false;
1282
+ this.deps.logger.warn("node metrics history points refused", { meta: {
1283
+ nodeId,
1284
+ accepted: result.accepted,
1285
+ refused: refusalCounts(result)
1286
+ } });
1287
+ }
1288
+ return result.accepted;
1289
+ } catch (err) {
1290
+ this.deps.logger.warn("node metrics history sample not stored", { meta: {
1291
+ nodeId,
1292
+ atMs,
1293
+ error: err instanceof Error ? err.message : String(err)
1294
+ } });
1295
+ return 0;
1296
+ }
1297
+ }
1298
+ async readContainerPoints(nodeId, sinceMs, maxPoints) {
1299
+ if (!await this.ensureDeclared()) return [];
1300
+ const result = await this.deps.deviceHistory.queryNode({
1301
+ forNodeId: nodeId,
1302
+ key: NODE_CONTAINER_CURRENT_KEY,
1303
+ from: sinceMs + 1,
1304
+ to: Date.now(),
1305
+ resolution: "raw",
1306
+ maxPoints
1307
+ });
1308
+ const out = [];
1309
+ for (const s of result.series) for (const p of s.points) {
1310
+ if (p.value === null || !Number.isFinite(p.value)) continue;
1311
+ out.push({
1312
+ atMs: p.t,
1313
+ source: "cgroup-v2",
1314
+ currentBytes: p.value * MIB,
1315
+ limitBytes: null,
1316
+ anonBytes: null,
1317
+ fileBytes: null,
1318
+ shmemBytes: null,
1319
+ slabBytes: null,
1320
+ gpuShmemBytes: null
1321
+ });
1322
+ }
1323
+ return out.toSorted((a, b) => a.atMs - b.atMs);
1324
+ }
1325
+ /**
1326
+ * The cold tier as process samples the fold reads like the hot ring's. A
1327
+ * runner's sums come back as `processes` equal rows (sums preserved, count
1328
+ * right); its CPU split is `null` where it was not recorded.
1329
+ */
1330
+ async readProcessSamples(nodeId, sinceMs, maxPoints) {
1331
+ if (!await this.ensureDeclared()) return [];
1332
+ const to = Date.now();
1333
+ const read = (key) => this.deps.deviceHistory.queryNode({
1334
+ forNodeId: nodeId,
1335
+ key,
1336
+ from: sinceMs + 1,
1337
+ to,
1338
+ resolution: "raw",
1339
+ maxPoints
1340
+ });
1341
+ const [main, gc, lifetime, rss, count] = await Promise.all([
1342
+ read(RUNNER_CPU_MAIN_KEY),
1343
+ read(RUNNER_CPU_GC_KEY),
1344
+ read(RUNNER_CPU_LIFETIME_KEY),
1345
+ read(RUNNER_RSS_KEY),
1346
+ read(RUNNER_PROCESSES_KEY)
1347
+ ]);
1348
+ return assembleRunnerSamples({
1349
+ main,
1350
+ gc,
1351
+ lifetime,
1352
+ rss,
1353
+ count
1354
+ });
1355
+ }
1356
+ async ensureDeclared() {
1357
+ if (this.deps.historyReady !== void 0 && !this.deps.historyReady()) {
1358
+ if (!this.waitLogged) {
1359
+ this.waitLogged = true;
1360
+ this.deps.logger.info("node metrics history waits for device-history — samples until it is ready are not stored");
1361
+ }
1362
+ return false;
1363
+ }
1364
+ this.waitLogged = false;
1365
+ try {
1366
+ await this.declare();
1367
+ return true;
1368
+ } catch (err) {
1369
+ this.deps.logger.warn("node metrics history declare failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
1370
+ return false;
1371
+ }
1372
+ }
1373
+ };
1374
+ /** `atMs -> scope -> value` of one key's answer, finite values only. */
1375
+ function indexAnswer(answer) {
1376
+ const out = /* @__PURE__ */ new Map();
1377
+ for (const s of answer.series) for (const p of s.points) {
1378
+ if (p.value === null || !Number.isFinite(p.value)) continue;
1379
+ const at = out.get(p.t) ?? /* @__PURE__ */ new Map();
1380
+ at.set(s.scope, p.value);
1381
+ out.set(p.t, at);
1382
+ }
1383
+ return out;
1384
+ }
1385
+ /**
1386
+ * Per-runner cold points back into process rows. A sample exists where the
1387
+ * runner's lifetime CPU and RSS were both recorded (always written together).
1388
+ */
1389
+ function assembleRunnerSamples(answers) {
1390
+ const main = indexAnswer(answers.main);
1391
+ const gc = indexAnswer(answers.gc);
1392
+ const rss = indexAnswer(answers.rss);
1393
+ const count = indexAnswer(answers.count);
1394
+ const samples = [];
1395
+ for (const [atMs, lifetimeByScope] of indexAnswer(answers.lifetime)) {
1396
+ const processes = [];
1397
+ for (const [scope, lifetime] of lifetimeByScope) {
1398
+ const rssMib = rss.get(atMs)?.get(scope);
1399
+ if (rssMib === void 0) continue;
1400
+ const n = Math.max(1, Math.round(count.get(atMs)?.get(scope) ?? 1));
1401
+ const m = main.get(atMs)?.get(scope);
1402
+ const g = gc.get(atMs)?.get(scope);
1403
+ const split = m !== void 0 && g !== void 0;
1404
+ const isRoot = scope === ROOT_BUCKET_KEY;
1405
+ const isUnattributed = scope === UNATTRIBUTED_BUCKET_KEY;
1406
+ for (let i = 0; i < n; i += 1) processes.push({
1407
+ pid: 0,
1408
+ addonId: isRoot || isUnattributed ? null : scope,
1409
+ classification: isRoot ? "root" : isUnattributed ? "system" : "managed",
1410
+ cpuPercent: lifetime / n,
1411
+ memoryRssBytes: rssMib * MIB / n,
1412
+ cpuMainPercent: split ? m / n : null,
1413
+ cpuGcPercent: split ? g / n : null
1414
+ });
1415
+ }
1416
+ if (processes.length > 0) samples.push({
1417
+ atMs,
1418
+ processes
1419
+ });
1420
+ }
1421
+ return samples.toSorted((a, b) => a.atMs - b.atMs);
1422
+ }
1423
+ //#endregion
1424
+ //#region src/builtins/native-metrics/darwin-memory.ts
1425
+ var PAGE_SIZE_RE = /page size of (\d+) bytes/;
1426
+ function readCounter(output, label) {
1427
+ const match = output.match(new RegExp(`^${label}:\\s+(\\d+)\\.?\\s*$`, "m"));
1428
+ return match ? parseInt(match[1], 10) : null;
1429
+ }
1430
+ /** Parses `vm_stat` output. Returns null when a required counter is missing. */
1431
+ function parseVmStat(output) {
1432
+ const pageSize = parseInt(output.match(PAGE_SIZE_RE)?.[1] ?? "", 10);
1433
+ if (!Number.isFinite(pageSize) || pageSize <= 0) return null;
1434
+ const free = readCounter(output, "Pages free");
1435
+ const inactive = readCounter(output, "Pages inactive");
1436
+ const speculative = readCounter(output, "Pages speculative");
1437
+ const wired = readCounter(output, "Pages wired down");
1438
+ const purgeable = readCounter(output, "Pages purgeable");
1439
+ const anonymous = readCounter(output, "Anonymous pages");
1440
+ const fileBacked = readCounter(output, "File-backed pages");
1441
+ const compressor = readCounter(output, "Pages occupied by compressor");
1442
+ if (free === null || inactive === null || speculative === null || wired === null || purgeable === null || anonymous === null || fileBacked === null || compressor === null) return null;
1443
+ return {
1444
+ pageSize,
1445
+ free,
1446
+ inactive,
1447
+ speculative,
1448
+ wired,
1449
+ purgeable,
1450
+ anonymous,
1451
+ fileBacked,
1452
+ compressor
1453
+ };
1454
+ }
1455
+ /** used = app + wired + compressed; available = total - used. */
1456
+ function computeDarwinMemory(pages, totalBytes) {
1457
+ if (totalBytes <= 0) return null;
1458
+ const app = Math.max(0, pages.anonymous - pages.purgeable);
1459
+ const usedBytes = Math.min(totalBytes, (app + pages.wired + pages.compressor) * pages.pageSize);
1460
+ return {
1461
+ usedBytes,
1462
+ availableBytes: totalBytes - usedBytes,
1463
+ percent: Math.round(usedBytes / totalBytes * 1e3) / 10
1464
+ };
1465
+ }
1466
+ //#endregion
1467
+ //#region src/builtins/native-metrics/gpu-probe.ts
1468
+ /**
1469
+ * The Linux GPU probe, forking only when there is something to fork.
1470
+ *
1471
+ * `nvidia-smi` was spawned on every sample — twelve times a minute from
1472
+ * hub-main — on a host with an Intel i915 and no NVIDIA driver. Each spawn
1473
+ * was a synchronous `fork()` of the largest process on the host (D441: p50
1474
+ * 91 ms at 5.8 GB RSS), and each one failed at `exec` and yielded `null`.
1475
+ * Twelve forks a minute bought nothing (D452).
1476
+ *
1477
+ * Whether the binary exists is a question `access(2)` answers on the libuv
1478
+ * pool without a fork. It is asked on EVERY call rather than latched: a handful
1479
+ * of `stat`s every five seconds costs nothing, and a latch is a second fact
1480
+ * about the host that can go stale — the same shape as the caches D224
1481
+ * forbids.
1482
+ */
1483
+ var nodeAccessCheck = (path) => access(path, constants.X_OK);
1484
+ /**
1485
+ * The first `PATH` entry under which `binary` is executable, or `null`.
1486
+ * An empty or missing `PATH` asks nothing.
1487
+ */
1488
+ async function findOnPath(binary, pathEnv, check = nodeAccessCheck) {
1489
+ const dirs = (pathEnv ?? "").split(":").filter((dir) => dir.length > 0);
1490
+ for (const dir of dirs) {
1491
+ const candidate = `${dir}/${binary}`;
1492
+ try {
1493
+ await check(candidate);
1494
+ return candidate;
1495
+ } catch {}
1496
+ }
1497
+ return null;
1498
+ }
1499
+ var NVIDIA_SMI_ARGS = ["--query-gpu=utilization.gpu,name,memory.used,memory.total,temperature.gpu", "--format=csv,noheader,nounits"];
1500
+ /**
1501
+ * `nvidia-smi`'s one-line CSV as a `MetricsGpuInfo`, or `null` when the
1502
+ * binary is absent, fails, or prints something else. Never throws.
1503
+ */
1504
+ async function readNvidiaGpu(deps) {
1505
+ const binary = await deps.findOnPath("nvidia-smi");
1506
+ if (binary === null) return null;
1507
+ let stdout;
1508
+ try {
1509
+ stdout = await deps.exec(binary, NVIDIA_SMI_ARGS);
1510
+ } catch {
1511
+ return null;
1512
+ }
1513
+ const parts = stdout.trim().split(",").map((s) => s.trim());
1514
+ if (parts.length < 5) return null;
1515
+ return {
1516
+ utilization: parseInt(parts[0], 10) || 0,
1517
+ model: parts[1] ?? "Unknown GPU",
1518
+ memoryUsedBytes: (parseInt(parts[2], 10) || 0) * 1024 * 1024,
1519
+ memoryTotalBytes: (parseInt(parts[3], 10) || 0) * 1024 * 1024,
1520
+ temperature: parseInt(parts[4], 10) || null
1521
+ };
1522
+ }
1523
+ //#endregion
1524
+ //#region src/builtins/native-metrics/native-metrics-provider.ts
1525
+ var IS_DARWIN = os$1.platform() === "darwin";
1526
+ var IS_LINUX = os$1.platform() === "linux";
1527
+ var NativeMetricsProvider = class {
1528
+ id = "native";
1529
+ cachedSnapshot = null;
1530
+ samplingTimer = null;
1531
+ macMemTimer = null;
1532
+ prevCpu;
1533
+ diagnostics = null;
1534
+ consecutiveSampleErrors = 0;
1535
+ constructor() {
1536
+ this.prevCpu = aggregateCpuTimes();
1537
+ }
1538
+ /**
1539
+ * Optional diagnostics sink for sampling errors. The first failure and
1540
+ * every Nth failure thereafter are reported so a permanently-broken
1541
+ * collector doesn't spam logs but is still observable.
1542
+ */
1543
+ setDiagnostics(diag) {
1544
+ this.diagnostics = diag;
1545
+ }
1546
+ startSampling(intervalMs) {
1547
+ if (IS_DARWIN) {
1548
+ sampleMacMemory(this);
1549
+ this.macMemTimer = setInterval(() => void sampleMacMemory(this), 5e3);
1550
+ if (this.macMemTimer.unref) this.macMemTimer.unref();
1551
+ }
1552
+ this.collectSnapshot().then((s) => {
1553
+ this.cachedSnapshot = s;
1554
+ this.consecutiveSampleErrors = 0;
1555
+ }).catch((err) => this.reportSampleError(err));
1556
+ this.samplingTimer = setInterval(() => {
1557
+ this.collectSnapshot().then((s) => {
1558
+ this.cachedSnapshot = s;
1559
+ this.consecutiveSampleErrors = 0;
1560
+ }).catch((err) => this.reportSampleError(err));
1561
+ }, intervalMs);
1562
+ if (this.samplingTimer.unref) this.samplingTimer.unref();
1563
+ }
1564
+ reportSampleError(err) {
1565
+ this.consecutiveSampleErrors++;
1566
+ if (!this.diagnostics) return;
1567
+ if (!(this.consecutiveSampleErrors === 1 || this.consecutiveSampleErrors % 60 === 0)) return;
1568
+ this.diagnostics.warn("metrics-provider sample failed", {
1569
+ consecutiveErrors: this.consecutiveSampleErrors,
1570
+ error: err instanceof Error ? err.message : String(err)
1571
+ });
1572
+ }
1573
+ stopSampling() {
1574
+ if (this.samplingTimer) {
1575
+ clearInterval(this.samplingTimer);
1576
+ this.samplingTimer = null;
1577
+ }
1578
+ if (this.macMemTimer) {
1579
+ clearInterval(this.macMemTimer);
1580
+ this.macMemTimer = null;
1581
+ }
1582
+ }
1583
+ async collectSnapshot() {
1584
+ const cpu = this.sampleCpu();
1585
+ const memory = this.getMemoryInfo();
1586
+ const processInfo = getProcessResources();
1587
+ const [gpu, network, disk, cpuTemp] = await Promise.all([
1588
+ getGpuInfoInternal().catch(() => null),
1589
+ takeNetworkIoSnapshot(),
1590
+ takeDiskIoSnapshot(),
1591
+ getCpuTemperatureInternal().catch(() => null)
1592
+ ]);
1593
+ const snapshot = {
1594
+ cpu,
1595
+ memory,
1596
+ gpu,
1597
+ network,
1598
+ disk,
1599
+ pressure: {
1600
+ cpu: getPressure("cpu"),
1601
+ memory: getPressure("memory"),
1602
+ io: getPressure("io")
1603
+ },
1604
+ process: processInfo,
1605
+ cpuTemperature: cpuTemp,
1606
+ timestampMs: Date.now()
1607
+ };
1608
+ this.cachedSnapshot = snapshot;
1609
+ return snapshot;
1610
+ }
1611
+ async getCached() {
1612
+ return this.cachedSnapshot;
1613
+ }
1614
+ async getCurrent() {
1615
+ const s = this.cachedSnapshot ?? await this.collectSnapshot();
1616
+ const mb = (bytes) => Math.round(bytes / 1024 / 1024);
1617
+ return {
1618
+ cpuPercent: s.cpu.total,
1619
+ memoryPercent: s.memory.percent,
1620
+ memoryUsedMB: s.memory.usedBytes === null ? null : mb(s.memory.usedBytes),
1621
+ memoryTotalMB: mb(s.memory.totalBytes),
1622
+ temperature: s.cpuTemperature ?? void 0,
1623
+ gpuPercent: s.gpu?.utilization,
1624
+ gpuMemoryPercent: s.gpu && s.gpu.memoryTotalBytes > 0 ? Math.round(s.gpu.memoryUsedBytes / s.gpu.memoryTotalBytes * 1e3) / 10 : void 0
1625
+ };
1626
+ }
1627
+ async getDiskSpace(input) {
1628
+ return getDiskSpaceInternal(input.dirPath);
1629
+ }
1630
+ async getGpuInfo() {
1631
+ return getGpuInfoInternal();
1632
+ }
1633
+ async getCpuTemperature() {
1634
+ return getCpuTemperatureInternal();
1635
+ }
1636
+ async getProcessStats(input) {
1637
+ const { getPidStats } = await import("../../resource-monitor-Di9daRwI.mjs").then((n) => n.r);
1638
+ const raw = await getPidStats(input.pids);
1639
+ const result = [];
1640
+ for (const [pid, s] of raw) result.push({
1641
+ pid,
1642
+ cpu: s.cpu,
1643
+ memory: s.memory,
1644
+ privateBytes: s.privateBytes,
1645
+ sharedBytes: s.sharedBytes
1646
+ });
1647
+ return result;
1648
+ }
1649
+ sampleCpu() {
1650
+ const curr = aggregateCpuTimes();
1651
+ const prev = this.prevCpu;
1652
+ this.prevCpu = curr;
1653
+ const dUser = curr.user - prev.user;
1654
+ const dNice = curr.nice - prev.nice;
1655
+ const dSys = curr.sys - prev.sys;
1656
+ const dIrq = curr.irq - prev.irq;
1657
+ const dIdle = curr.idle - prev.idle;
1658
+ const dTotal = dUser + dNice + dSys + dIrq + dIdle;
1659
+ const pct = (v) => dTotal === 0 ? 0 : Math.round(v / dTotal * 1e3) / 10;
1660
+ return {
1661
+ total: pct(dUser + dNice + dSys + dIrq),
1662
+ user: pct(dUser),
1663
+ system: pct(dSys),
1664
+ irq: pct(dIrq),
1665
+ nice: pct(dNice),
1666
+ loadAvg: os$1.loadavg(),
1667
+ cores: os$1.cpus().length
1668
+ };
1669
+ }
1670
+ /** Cached macOS memory (set by sampleMacMemory timer). */
1671
+ _cachedMacMem = null;
1672
+ _macMemInFlight = false;
1673
+ getMemoryInfo() {
1674
+ const total = os$1.totalmem();
1675
+ const unknown = {
1676
+ percent: null,
1677
+ totalBytes: total,
1678
+ usedBytes: null,
1679
+ availableBytes: null,
1680
+ swapUsedBytes: 0,
1681
+ swapTotalBytes: 0
1682
+ };
1683
+ if (total === 0) return unknown;
1684
+ if (IS_DARWIN) return this._cachedMacMem ?? unknown;
1685
+ let available = null;
1686
+ let swapUsedBytes = 0;
1687
+ let swapTotalBytes = 0;
1688
+ if (IS_LINUX) try {
1689
+ const meminfo = fs$1.readFileSync("/proc/meminfo", "utf-8");
1690
+ const availKb = meminfo.match(/MemAvailable:\s+(\d+)/)?.[1];
1691
+ if (availKb !== void 0) available = parseInt(availKb, 10) * 1024;
1692
+ const swapTotal = parseInt(meminfo.match(/SwapTotal:\s+(\d+)/)?.[1] ?? "0", 10) * 1024;
1693
+ const swapFree = parseInt(meminfo.match(/SwapFree:\s+(\d+)/)?.[1] ?? "0", 10) * 1024;
1694
+ swapTotalBytes = swapTotal;
1695
+ swapUsedBytes = swapTotal - swapFree;
1696
+ } catch {}
1697
+ else available = os$1.freemem();
1698
+ if (available === null) return unknown;
1699
+ const used = total - available;
1700
+ return {
1701
+ percent: Math.round(used / total * 1e3) / 10,
1702
+ totalBytes: total,
1703
+ usedBytes: used,
1704
+ availableBytes: available,
1705
+ swapUsedBytes,
1706
+ swapTotalBytes
1707
+ };
1708
+ }
1709
+ };
1710
+ function aggregateCpuTimes() {
1711
+ const cpus = os$1.cpus();
1712
+ let user = 0, nice = 0, sys = 0, irq = 0, idle = 0;
1713
+ for (const cpu of cpus) {
1714
+ user += cpu.times.user;
1715
+ nice += cpu.times.nice;
1716
+ sys += cpu.times.sys;
1717
+ irq += cpu.times.irq;
1718
+ idle += cpu.times.idle;
1719
+ }
1720
+ return {
1721
+ user,
1722
+ nice,
1723
+ sys,
1724
+ irq,
1725
+ idle
1726
+ };
1727
+ }
1728
+ var VM_STAT = "/usr/bin/vm_stat";
1729
+ var SYSCTL = "/usr/sbin/sysctl";
1730
+ function execFileText(file, args) {
1731
+ return new Promise((resolve, reject) => {
1732
+ execFile(file, [...args], {
1733
+ timeout: 2e3,
1734
+ encoding: "utf-8"
1735
+ }, (err, stdout) => err ? reject(err) : resolve(stdout));
1736
+ });
1737
+ }
1738
+ async function readMacSwap() {
1739
+ try {
1740
+ const swapOut = await execFileText(SYSCTL, ["-n", "vm.swapusage"]);
1741
+ const totalMatch = swapOut.match(/total\s*=\s*([\d.]+)M/);
1742
+ const usedMatch = swapOut.match(/used\s*=\s*([\d.]+)M/);
1743
+ return {
1744
+ total: totalMatch ? parseFloat(totalMatch[1]) * 1024 * 1024 : 0,
1745
+ used: usedMatch ? parseFloat(usedMatch[1]) * 1024 * 1024 : 0
1746
+ };
1747
+ } catch {
1748
+ return {
1749
+ used: 0,
1750
+ total: 0
1751
+ };
1752
+ }
1753
+ }
1754
+ /** One spawn per tick (never overlapping); a failed read clears the cache. */
1755
+ async function sampleMacMemory(provider) {
1756
+ if (provider._macMemInFlight) return;
1757
+ provider._macMemInFlight = true;
1758
+ try {
1759
+ const pages = parseVmStat(await execFileText(VM_STAT, []));
1760
+ const mem = pages ? computeDarwinMemory(pages, os$1.totalmem()) : null;
1761
+ if (!mem) {
1762
+ provider._cachedMacMem = null;
1763
+ return;
1764
+ }
1765
+ const swap = await readMacSwap();
1766
+ provider._cachedMacMem = {
1767
+ percent: mem.percent,
1768
+ totalBytes: os$1.totalmem(),
1769
+ usedBytes: mem.usedBytes,
1770
+ availableBytes: mem.availableBytes,
1771
+ swapUsedBytes: swap.used,
1772
+ swapTotalBytes: swap.total
1773
+ };
1774
+ } catch {
1775
+ provider._cachedMacMem = null;
1776
+ } finally {
1777
+ provider._macMemInFlight = false;
1778
+ }
1779
+ }
1780
+ function getDiskSpaceInternal(dirPath) {
1781
+ return new Promise((resolve, reject) => {
1782
+ fs$1.statfs(dirPath, (err, stats) => {
1783
+ if (err) return reject(err);
1784
+ const totalBytes = stats.blocks * stats.bsize;
1785
+ const availableBytes = stats.bavail * stats.bsize;
1786
+ const usedBytes = totalBytes - stats.bfree * stats.bsize;
1787
+ resolve({
1788
+ path: dirPath,
1789
+ totalBytes,
1790
+ usedBytes,
1791
+ availableBytes,
1792
+ percent: totalBytes > 0 ? Math.round(usedBytes / totalBytes * 1e3) / 10 : 0
1793
+ });
1794
+ });
1795
+ });
1796
+ }
1797
+ async function takeDiskIoSnapshot() {
1798
+ const now = Date.now();
1799
+ if (IS_LINUX) try {
1800
+ const data = fs$1.readFileSync("/proc/diskstats", "utf-8");
1801
+ let readOps = 0, readBytes = 0, writeOps = 0, writeBytes = 0;
1802
+ for (const line of data.split("\n")) {
1803
+ const parts = line.trim().split(/\s+/);
1804
+ if (parts.length < 14) continue;
1805
+ const devName = parts[2];
1806
+ if (/\d+$/.test(devName) && !/^nvme\d+n\d+$/.test(devName)) continue;
1807
+ readOps += parseInt(parts[3], 10) || 0;
1808
+ readBytes += (parseInt(parts[5], 10) || 0) * 512;
1809
+ writeOps += parseInt(parts[7], 10) || 0;
1810
+ writeBytes += (parseInt(parts[9], 10) || 0) * 512;
1811
+ }
1812
+ return {
1813
+ readBytes,
1814
+ writeBytes,
1815
+ readOps,
1816
+ writeOps,
1817
+ timestampMs: now
1818
+ };
1819
+ } catch {}
1820
+ return {
1821
+ readBytes: 0,
1822
+ writeBytes: 0,
1823
+ readOps: 0,
1824
+ writeOps: 0,
1825
+ timestampMs: now
1826
+ };
1827
+ }
1828
+ async function takeNetworkIoSnapshot() {
1829
+ const now = Date.now();
1830
+ if (IS_LINUX) try {
1831
+ const data = fs$1.readFileSync("/proc/net/dev", "utf-8");
1832
+ let rxBytes = 0, txBytes = 0, rxPackets = 0, txPackets = 0, rxErrors = 0, txErrors = 0;
1833
+ for (const line of data.split("\n")) {
1834
+ const match = line.match(/^\s*(\w+):\s+(.+)$/);
1835
+ if (!match) continue;
1836
+ if (match[1] === "lo") continue;
1837
+ const cols = match[2].trim().split(/\s+/);
1838
+ rxBytes += parseInt(cols[0], 10) || 0;
1839
+ rxPackets += parseInt(cols[1], 10) || 0;
1840
+ rxErrors += parseInt(cols[2], 10) || 0;
1841
+ txBytes += parseInt(cols[8], 10) || 0;
1842
+ txPackets += parseInt(cols[9], 10) || 0;
1843
+ txErrors += parseInt(cols[10], 10) || 0;
1844
+ }
1845
+ return {
1846
+ rxBytes,
1847
+ txBytes,
1848
+ rxPackets,
1849
+ txPackets,
1850
+ rxErrors,
1851
+ txErrors,
1852
+ timestampMs: now
1853
+ };
1854
+ } catch {}
1855
+ if (IS_DARWIN) try {
1856
+ const stdout = await execAsync("netstat", ["-ib"]);
1857
+ let rxBytes = 0, txBytes = 0, rxPackets = 0, txPackets = 0, rxErrors = 0, txErrors = 0;
1858
+ for (const line of stdout.split("\n")) {
1859
+ const parts = line.trim().split(/\s+/);
1860
+ if (parts.length < 11) continue;
1861
+ if (parts[0] === "lo0" || parts[0] === "Name") continue;
1862
+ if (!parts[2]?.startsWith("Link#")) continue;
1863
+ rxPackets += parseInt(parts[4], 10) || 0;
1864
+ rxErrors += parseInt(parts[5], 10) || 0;
1865
+ rxBytes += parseInt(parts[6], 10) || 0;
1866
+ txPackets += parseInt(parts[7], 10) || 0;
1867
+ txErrors += parseInt(parts[8], 10) || 0;
1868
+ txBytes += parseInt(parts[9], 10) || 0;
1869
+ }
1870
+ return {
1871
+ rxBytes,
1872
+ txBytes,
1873
+ rxPackets,
1874
+ txPackets,
1875
+ rxErrors,
1876
+ txErrors,
1877
+ timestampMs: now
1878
+ };
1879
+ } catch {}
1880
+ return {
1881
+ rxBytes: 0,
1882
+ txBytes: 0,
1883
+ rxPackets: 0,
1884
+ txPackets: 0,
1885
+ rxErrors: 0,
1886
+ txErrors: 0,
1887
+ timestampMs: now
1888
+ };
1889
+ }
1890
+ async function getCpuTemperatureInternal() {
1891
+ if (IS_LINUX) for (const p of ["/sys/class/thermal/thermal_zone0/temp", "/sys/class/hwmon/hwmon0/temp1_input"]) try {
1892
+ const raw = fs$1.readFileSync(p, "utf-8").trim();
1893
+ const millideg = parseInt(raw, 10);
1894
+ if (!isNaN(millideg)) return Math.round(millideg / 100) / 10;
1895
+ } catch {
1896
+ continue;
1897
+ }
1898
+ if (IS_DARWIN) try {
1899
+ const match = (await execAsync("sudo", [
1900
+ "-n",
1901
+ "powermetrics",
1902
+ "--samplers",
1903
+ "smc",
1904
+ "-i",
1905
+ "1",
1906
+ "-n",
1907
+ "1"
1908
+ ], 3e3)).match(/CPU die temperature:\s+([\d.]+)\s*C/);
1909
+ if (match) return Math.round(parseFloat(match[1]) * 10) / 10;
1910
+ } catch {}
1911
+ return null;
1912
+ }
1913
+ async function getGpuInfoInternal() {
1914
+ if (IS_DARWIN) try {
1915
+ const utilMatch = (await execAsync("ioreg", [
1916
+ "-r",
1917
+ "-d",
1918
+ "1",
1919
+ "-c",
1920
+ "IOAccelerator"
1921
+ ])).match(/"GPU Core Utilization"\s*=\s*(\d+)/);
1922
+ const util = utilMatch ? parseInt(utilMatch[1], 10) : 0;
1923
+ const utilPct = util > 1e3 ? Math.round(util / 1e7) : util;
1924
+ return {
1925
+ utilization: Math.min(100, utilPct),
1926
+ model: "Apple Silicon GPU",
1927
+ memoryUsedBytes: 0,
1928
+ memoryTotalBytes: 0,
1929
+ temperature: null
1930
+ };
1931
+ } catch {}
1932
+ if (IS_LINUX) return readNvidiaGpu({
1933
+ findOnPath: (binary) => findOnPath(binary, process.env["PATH"]),
1934
+ exec: (command, args) => execAsync(command, [...args])
1935
+ });
1936
+ return null;
1937
+ }
1938
+ function getProcessResources() {
1939
+ let openFds = 0;
1940
+ let threadCount = 0;
1941
+ if (IS_LINUX) {
1942
+ try {
1943
+ openFds = fs$1.readdirSync(`/proc/${process.pid}/fd`).length;
1944
+ } catch {}
1945
+ try {
1946
+ const match = fs$1.readFileSync(`/proc/${process.pid}/status`, "utf-8").match(/Threads:\s+(\d+)/);
1947
+ if (match) threadCount = parseInt(match[1], 10);
1948
+ } catch {}
1949
+ }
1950
+ const nodeProcess = process;
1951
+ return {
1952
+ openFds,
1953
+ threadCount,
1954
+ activeHandles: (nodeProcess._getActiveHandles?.() ?? []).length,
1955
+ activeRequests: (nodeProcess._getActiveRequests?.() ?? []).length
1956
+ };
1957
+ }
1958
+ function getPressure(resource) {
1959
+ if (!IS_LINUX) return null;
1960
+ try {
1961
+ const data = fs$1.readFileSync(`/proc/pressure/${resource}`, "utf-8");
1962
+ const parseLine = (prefix) => {
1963
+ const match = data.match(new RegExp(`${prefix} avg10=(\\d+\\.\\d+) avg60=(\\d+\\.\\d+) avg300=(\\d+\\.\\d+)`));
1964
+ if (!match) return null;
1965
+ return {
1966
+ avg10: parseFloat(match[1]),
1967
+ avg60: parseFloat(match[2]),
1968
+ avg300: parseFloat(match[3])
1969
+ };
1970
+ };
1971
+ const some = parseLine("some");
1972
+ if (!some) return null;
1973
+ return {
1974
+ some,
1975
+ full: parseLine("full")
1976
+ };
1977
+ } catch {
1978
+ return null;
1979
+ }
1980
+ }
1981
+ function execAsync(cmd, args, timeoutMs = 5e3) {
1982
+ return new Promise((resolve, reject) => {
1983
+ execFile(cmd, args, { timeout: timeoutMs }, (err, stdout) => {
1984
+ if (err) return reject(err);
1985
+ resolve(stdout);
1986
+ });
1987
+ });
1988
+ }
1989
+ /**
1990
+ * Parse one `/proc/<pid>/stat` line. `null` for a line that does not parse —
1991
+ * a process that exited between the readdir and the read leaves a truncated
1992
+ * or empty file, and that is normal, not an error.
1993
+ */
1994
+ function parseProcStat(line) {
1995
+ const close = line.lastIndexOf(")");
1996
+ const open = line.indexOf("(");
1997
+ if (close < 0 || open < 0 || close < open) return null;
1998
+ const pid = Number(line.slice(0, open).trim());
1999
+ const comm = line.slice(open + 1, close);
2000
+ const rest = line.slice(close + 1).trim().split(/\s+/);
2001
+ const state = rest[0];
2002
+ const ppid = Number(rest[1]);
2003
+ const pgid = Number(rest[2]);
2004
+ const utime = Number(rest[11]);
2005
+ const stime = Number(rest[12]);
2006
+ const startTicks = Number(rest[19]);
2007
+ const rssPages = Number(rest[21]);
2008
+ if (state === void 0 || state === "") return null;
2009
+ if (![
2010
+ pid,
2011
+ ppid,
2012
+ pgid,
2013
+ utime,
2014
+ stime,
2015
+ startTicks,
2016
+ rssPages
2017
+ ].every(Number.isFinite)) return null;
2018
+ return {
2019
+ pid,
2020
+ comm,
2021
+ state,
2022
+ ppid,
2023
+ pgid,
2024
+ ticks: utime + stime,
2025
+ startTicks,
2026
+ rssPages
2027
+ };
2028
+ }
2029
+ function statusKb(status, key) {
2030
+ const match = status.match(new RegExp(`^${key}:\\s+(\\d+)`, "m"));
2031
+ return match ? parseInt(match[1], 10) * 1024 : void 0;
2032
+ }
2033
+ /** Read `VmRSS` / `RssAnon` / `RssFile` (kB in the file) out of `/proc/<pid>/status`. */
2034
+ function parseProcStatusRss(status) {
2035
+ return {
2036
+ rssBytes: statusKb(status, "VmRSS"),
2037
+ privateBytes: statusKb(status, "RssAnon"),
2038
+ sharedBytes: statusKb(status, "RssFile")
2039
+ };
2040
+ }
2041
+ /** Seconds the process has been alive — `ps etime`, whole seconds. */
2042
+ function elapsedSecSince(input) {
2043
+ return Math.max(0, Math.floor(input.uptimeSec - input.startTicks / 100));
2044
+ }
2045
+ /**
2046
+ * `ps pcpu`: CPU time over elapsed time, as a percentage with one decimal.
2047
+ *
2048
+ * This is deliberately the LIFETIME average `ps` prints, not an instantaneous
2049
+ * rate: the columns fed from it have always shown that quantity, and the
2050
+ * instantaneous split is a different number with a different owner
2051
+ * (`cpuMainPercent` / `cpuGcPercent` from `thread-cpu-sampler.ts`). A process
2052
+ * with no elapsed window yet reports 0, never a division by zero.
2053
+ */
2054
+ function lifetimeCpuPercent(input) {
2055
+ const elapsedSec = input.uptimeSec - input.startTicks / 100;
2056
+ if (!(elapsedSec > 0)) return 0;
2057
+ const cpuSec = input.ticks / 100;
2058
+ return Math.round(cpuSec / elapsedSec * 1e3) / 10;
2059
+ }
2060
+ var PID_RE = /^\d+$/;
2061
+ var nodeProcReader = {
2062
+ listPids: async () => (await readdir("/proc")).filter((entry) => PID_RE.test(entry)).map((entry) => Number(entry)),
2063
+ readStat: (pid) => readFile(`/proc/${pid}/stat`, "latin1"),
2064
+ readStatus: (pid) => readFile(`/proc/${pid}/status`, "latin1"),
2065
+ readCmdline: (pid) => readFile(`/proc/${pid}/cmdline`, "latin1"),
2066
+ readUptimeSec: async () => {
2067
+ const [first] = (await readFile("/proc/uptime", "latin1")).trim().split(/\s+/);
2068
+ const seconds = Number(first);
2069
+ if (!Number.isFinite(seconds)) throw new Error(`/proc/uptime unreadable: ${String(first)}`);
2070
+ return seconds;
2071
+ }
2072
+ };
2073
+ /** `ps command=`: argv joined by spaces, or `[comm]` when there is no argv. */
2074
+ function commandFromCmdline(cmdline, comm) {
2075
+ const joined = cmdline.split("\0").filter((part) => part.length > 0).join(" ");
2076
+ return joined.length > 0 ? joined : `[${comm}]`;
2077
+ }
2078
+ //#endregion
2079
+ //#region src/builtins/native-metrics/proc-process-table.ts
2080
+ /**
2081
+ * The node's process table — every row `ps -eo pid,ppid,pgid,pcpu,rss,etime,
2082
+ * command` printed — read from `/proc` on Linux, with no fork.
2083
+ *
2084
+ * Why the fork mattered, and the numbers, are in `process/proc-stat.ts`. What
2085
+ * this file adds is the WHOLE-TABLE read: one `readdir` of `/proc`, then per
2086
+ * pid `stat`, `status` and `cmdline`, all through `fs/promises` so the reads
2087
+ * land on the libuv pool and the main thread pays only the parse. Measured in
2088
+ * the hub container (70 processes, D452): 2–4 ms wall for the walk, against
2089
+ * 3–4 ms for `ps` itself — the fork that USED to precede it was the cost.
2090
+ *
2091
+ * A pid that vanishes between the listing and its reads is omitted whole.
2092
+ * Never a partial row: a row with a command and no memory would render as a
2093
+ * process using nothing, which is a different claim from "gone".
2094
+ */
2095
+ var execFileAsync = promisify(execFile);
2096
+ async function readProcRow(pid, uptimeSec, reader) {
2097
+ let stat;
2098
+ let cmdline;
2099
+ let status;
2100
+ try {
2101
+ [stat, cmdline, status] = await Promise.all([
2102
+ reader.readStat(pid),
2103
+ reader.readCmdline(pid),
2104
+ reader.readStatus(pid)
2105
+ ]);
2106
+ } catch {
2107
+ return null;
2108
+ }
2109
+ const parsed = parseProcStat(stat);
2110
+ if (parsed === null) return null;
2111
+ const rss = parseProcStatusRss(status);
2112
+ return {
2113
+ pid: parsed.pid,
2114
+ ppid: parsed.ppid,
2115
+ pgid: parsed.pgid,
2116
+ cpuPercent: lifetimeCpuPercent({
2117
+ ticks: parsed.ticks,
2118
+ startTicks: parsed.startTicks,
2119
+ uptimeSec
2120
+ }),
2121
+ memoryRssBytes: rss.rssBytes ?? 0,
2122
+ uptimeSec: elapsedSecSince({
2123
+ startTicks: parsed.startTicks,
2124
+ uptimeSec
2125
+ }),
2126
+ command: commandFromCmdline(cmdline, parsed.comm)
2127
+ };
2128
+ }
2129
+ /** Every process in `/proc`, as the rows `ps -eo …` would have printed. */
2130
+ async function readProcProcessTable(reader = nodeProcReader) {
2131
+ const [pids, uptimeSec] = await Promise.all([reader.listPids(), reader.readUptimeSec()]);
2132
+ return (await Promise.all(pids.map((pid) => readProcRow(pid, uptimeSec, reader)))).filter((row) => row !== null);
2133
+ }
2134
+ /**
2135
+ * Parse `ps etime` → seconds. `MM:SS`, `HH:MM:SS`, `DD-HH:MM:SS`.
2136
+ * Only the `ps` path needs this; `/proc` gives the number directly.
2137
+ */
2138
+ function parseEtime(etime) {
2139
+ const dashParts = etime.split("-");
2140
+ let days = 0;
2141
+ let hms = etime;
2142
+ if (dashParts.length === 2) {
2143
+ days = parseInt(dashParts[0], 10) || 0;
2144
+ hms = dashParts[1];
2145
+ }
2146
+ const parts = hms.split(":").map((p) => parseInt(p, 10) || 0);
2147
+ let hours = 0;
2148
+ let minutes = 0;
2149
+ let seconds = 0;
2150
+ if (parts.length === 3) [hours, minutes, seconds] = parts;
2151
+ else if (parts.length === 2) [minutes, seconds] = parts;
2152
+ else if (parts.length === 1) [seconds] = parts;
2153
+ return days * 86400 + hours * 3600 + minutes * 60 + seconds;
2154
+ }
2155
+ var PS_ROW_RE = /^(\d+)\s+(\d+)\s+(\d+)\s+([\d.]+)\s+(\d+)\s+(\S+)\s+(.+)$/;
2156
+ /** Parse the output of `ps -eo pid=,ppid=,pgid=,pcpu=,rss=,etime=,command=`. */
2157
+ function parsePsTable(stdout) {
2158
+ const rows = [];
2159
+ for (const line of stdout.split("\n")) {
2160
+ const match = line.trim().match(PS_ROW_RE);
2161
+ if (!match) continue;
2162
+ const [, pidS, ppidS, pgidS, cpuS, rssS, etimeS, command] = match;
2163
+ rows.push({
2164
+ pid: parseInt(pidS, 10),
2165
+ ppid: parseInt(ppidS, 10),
2166
+ pgid: parseInt(pgidS, 10),
2167
+ cpuPercent: Math.round(parseFloat(cpuS) * 10) / 10,
2168
+ memoryRssBytes: parseInt(rssS, 10) * 1024,
2169
+ uptimeSec: parseEtime(etimeS),
2170
+ command
2171
+ });
2172
+ }
2173
+ return rows;
2174
+ }
2175
+ /** The fork. Only reached on a platform without `/proc`. */
2176
+ async function spawnPsTable() {
2177
+ const { stdout } = await execFileAsync("ps", ["-eo", "pid=,ppid=,pgid=,pcpu=,rss=,etime=,command="], {
2178
+ timeout: 5e3,
2179
+ maxBuffer: 8 * 1024 * 1024
2180
+ });
2181
+ return parsePsTable(stdout);
2182
+ }
2183
+ var defaultDeps = {
2184
+ platform: platform(),
2185
+ reader: nodeProcReader,
2186
+ spawnPs: spawnPsTable
2187
+ };
2188
+ /**
2189
+ * The process table, from `/proc` where it exists and from `ps` elsewhere.
2190
+ * Throws only when the chosen source cannot answer at all; the caller logs it
2191
+ * as a skipped interval.
2192
+ */
2193
+ function readProcessTable(deps = defaultDeps) {
2194
+ return deps.platform === "linux" ? readProcProcessTable(deps.reader) : deps.spawnPs();
2195
+ }
2196
+ //#endregion
2197
+ //#region src/builtins/native-metrics/process-classification.ts
2198
+ /**
2199
+ * Regex matching camstack-related command lines. We surface anything with
2200
+ * an obvious camstack fingerprint so operators can spot stray inference
2201
+ * pools, leaked tsx watchers, and zombie node workers in the Cluster →
2202
+ * Agent → Processes tab.
2203
+ *
2204
+ * Patterns mirror `scripts/hunt-zombies.sh` — keep them in sync when
2205
+ * adding a new long-lived subprocess.
2206
+ */
2207
+ var CAMSTACK_CMD_RE = /(camstack|tsx\s+watch\s.*launcher\.ts|packages\/agent\/dist\/cli\.js|inference_pool\.py|bench-(inference-pool|nodeav)|node .*\/packages\/)/;
2208
+ /**
2209
+ * Classify one pid.
2210
+ *
2211
+ * Identity-driven, not ancestry-driven: a process is `root` because it IS
2212
+ * this node, `managed` because the kernel named it, and `system` otherwise.
2213
+ * There is no third source of truth to consult and no walk to get wrong.
2214
+ */
2215
+ function classifyProcess(pid, selfPid, managed) {
2216
+ if (pid === selfPid) return "root";
2217
+ if (managed.has(pid)) return "managed";
2218
+ return "system";
2219
+ }
2220
+ /** Turn a `ps` snapshot into the node's process table. */
2221
+ function buildNodeProcesses(input) {
2222
+ const out = [];
2223
+ for (const p of input.psRows) {
2224
+ if (!CAMSTACK_CMD_RE.test(p.command)) continue;
2225
+ const managed = input.managed.get(p.pid);
2226
+ const split = input.cpuSplits.get(p.pid);
2227
+ const classification = classifyProcess(p.pid, input.selfPid, input.managed);
2228
+ out.push({
2229
+ pid: p.pid,
2230
+ ppid: p.ppid,
2231
+ pgid: p.pgid,
2232
+ classification,
2233
+ addonId: managed?.addonId ?? null,
2234
+ nodeId: managed?.nodeId ?? (p.pid === input.selfPid ? input.selfNodeId : null),
2235
+ command: p.command,
2236
+ cpuPercent: p.cpuPercent,
2237
+ memoryRssBytes: p.memoryRssBytes,
2238
+ cpuMainPercent: split?.mainPercent ?? null,
2239
+ cpuGcPercent: split?.gcPercent ?? null,
2240
+ threadCount: split?.threadCount ?? null,
2241
+ uptimeSec: p.uptimeSec
2242
+ });
2243
+ }
2244
+ return out;
2245
+ }
2246
+ //#endregion
2247
+ //#region src/builtins/native-metrics/thread-cpu-sampler.ts
2248
+ /**
2249
+ * Per-process CPU split: the process's OWN threads vs V8's helper-thread pool.
2250
+ *
2251
+ * ## Why this exists
2252
+ *
2253
+ * `ps pcpu` — the number every CPU column in this app renders today — is the
2254
+ * process's CPU averaged over its **entire lifetime**. On a runner that has
2255
+ * been up for three days it barely moves, which makes it useless as a series:
2256
+ * a chart drawn from it is a flat line that cannot show a spike.
2257
+ *
2258
+ * Worse, a single total hides the finding that rewrote the 2026-08-27
2259
+ * diagnosis. Separating the V8 helper threads from the rest showed that ~2
2260
+ * whole cores of the container **were not computing** — hub-main was at 73%
2261
+ * and `stream-broker` at 61% of their CPU in that pool
2262
+ * (`docs/architecture/load-ledger.md`). A CPU chart that does not split the
2263
+ * two renders "busy" where the truth is "allocating too much".
2264
+ *
2265
+ * This module produces both at once, from the source the ledger prescribes:
2266
+ * a delta over `/proc/<pid>/task/<tid>/stat`, classified by thread name.
2267
+ *
2268
+ * ## What `gcPercent` actually contains — read this before quoting it
2269
+ *
2270
+ * It is the CPU of the threads V8 names `V8Worker`: its platform worker pool.
2271
+ * Concurrent marking and sweeping run there, and so does background
2272
+ * compilation. So `gcPercent` is **"the V8 helper pool"**, of which GC is the
2273
+ * dominant but not the only tenant. It is exactly the quantity the load ledger
2274
+ * measured — the 73% / 61% figures are this number — and it is reported under
2275
+ * that name for continuity, not because every jiffy in it is a collection.
2276
+ * The UI labels it `GC / V8 helpers` for the same reason.
2277
+ *
2278
+ * ## Cost
2279
+ *
2280
+ * One `readdir` plus one small `read` per thread, for the camstack-shaped pids
2281
+ * ONLY — on a busy node that is ~10 processes × ~10-40 threads. It rides the
2282
+ * existing 20 s process-snapshot tick and never adds a timer of its own, so it
2283
+ * is strictly cheaper than the full-process-table `ps -eo` scan that tick
2284
+ * already pays. There is no high-frequency sampler here; that is the defect
2285
+ * the load ledger documents.
2286
+ *
2287
+ * ## Linux only
2288
+ *
2289
+ * `/proc/<pid>/task` does not exist on macOS or Windows. Every read returns
2290
+ * `null` there, and `null` must reach the UI as "unknown" — never as zero.
2291
+ */
2292
+ /**
2293
+ * Kernel jiffies per second (`USER_HZ`). `sysconf(_SC_CLK_TCK)` is not exposed
2294
+ * to Node, and this has been 100 on every Linux/x86-64 and arm64 kernel
2295
+ * configuration we ship to. It scales both numerator and denominator of the
2296
+ * ratio identically, so a wrong value would scale all CPU numbers by a
2297
+ * constant — visible immediately, not a silent skew.
2298
+ */
2299
+ var CLOCK_TICKS_PER_SEC = 100;
2300
+ /**
2301
+ * Thread names V8 gives its platform worker pool. `comm` is capped at 15
2302
+ * characters by the kernel, which is why this matches a PREFIX.
2303
+ */
2304
+ var V8_HELPER_THREAD_RE = /^V8Worker/;
2305
+ function parseThreadStat(line) {
2306
+ const close = line.lastIndexOf(")");
2307
+ const open = line.indexOf("(");
2308
+ if (close < 0 || open < 0 || close < open) return null;
2309
+ const comm = line.slice(open + 1, close);
2310
+ const rest = line.slice(close + 1).trim().split(/\s+/);
2311
+ const utime = Number(rest[11]);
2312
+ const stime = Number(rest[12]);
2313
+ const startTicks = Number(rest[19]);
2314
+ if (!Number.isFinite(utime) || !Number.isFinite(stime)) return null;
2315
+ if (!Number.isFinite(startTicks)) return null;
2316
+ return {
2317
+ comm,
2318
+ ticks: utime + stime,
2319
+ startTicks
2320
+ };
2321
+ }
2322
+ var nodeProcFsReader = {
2323
+ listTaskIds: (pid) => readdir(`/proc/${pid}/task`),
2324
+ readTaskStat: (pid, tid) => readFile(`/proc/${pid}/task/${tid}/stat`, "utf8")
2325
+ };
2326
+ /**
2327
+ * Read one instant's tick counts for `pid`, or `null` when the process has no
2328
+ * readable `/proc/<pid>/task` — it exited, we lack permission, or this is not
2329
+ * Linux. `null` is "unknown"; it must never be turned into a zero downstream.
2330
+ */
2331
+ async function readThreadTicks(pid, reader = nodeProcFsReader) {
2332
+ let tids;
2333
+ try {
2334
+ tids = await reader.listTaskIds(pid);
2335
+ } catch {
2336
+ return null;
2337
+ }
2338
+ let mainTicks = 0;
2339
+ let gcTicks = 0;
2340
+ let threadCount = 0;
2341
+ let startTicks = null;
2342
+ const mainThreadTid = String(pid);
2343
+ for (const tid of tids) {
2344
+ let line;
2345
+ try {
2346
+ line = await reader.readTaskStat(pid, tid);
2347
+ } catch {
2348
+ continue;
2349
+ }
2350
+ const parsed = parseThreadStat(line);
2351
+ if (parsed === null) continue;
2352
+ threadCount += 1;
2353
+ if (tid === mainThreadTid) startTicks = parsed.startTicks;
2354
+ if (V8_HELPER_THREAD_RE.test(parsed.comm)) gcTicks += parsed.ticks;
2355
+ else mainTicks += parsed.ticks;
2356
+ }
2357
+ if (threadCount === 0) return null;
2358
+ return {
2359
+ mainTicks,
2360
+ gcTicks,
2361
+ threadCount,
2362
+ atMs: Date.now(),
2363
+ startTicks
2364
+ };
2365
+ }
2366
+ /**
2367
+ * The CPU split between two samples of the SAME process.
2368
+ *
2369
+ * Returns `null` — never a zero — when the window cannot produce a rate:
2370
+ * - the two samples are not separated in time (no window to divide by);
2371
+ * - the pid's `starttime` changed, or is unknown on either side. A changed
2372
+ * starttime means the pid was RECYCLED: this is a different process that
2373
+ * happens to wear the same number. See below for why the tick check alone
2374
+ * does not catch it;
2375
+ * - either tick count went BACKWARDS, which is the same fault seen from the
2376
+ * other side. A negative delta divided by a window would render as a
2377
+ * plausible small number for the wrong process, and a plausible wrong
2378
+ * number is the failure this whole surface exists to avoid.
2379
+ *
2380
+ * ## Why `starttime` and not just the backwards-tick check
2381
+ *
2382
+ * The backwards check only fires when the NEW process has burned FEWER ticks
2383
+ * than the dead one had. A recycled pid landing on a busier process — an
2384
+ * ffmpeg that has been transcoding for a minute inheriting the pid of an
2385
+ * ffmpeg that idled — produces a large POSITIVE delta, which divides cleanly
2386
+ * and renders as a spike. That is not a hypothetical rounding concern now that
2387
+ * the process snapshot attributes each pid to a camera: it would charge one
2388
+ * camera for another camera's whole lifetime of CPU, in a chart built
2389
+ * specifically to answer "why is 102 worse than 101". `starttime` is the pid's
2390
+ * incarnation number and it catches both directions.
2391
+ */
2392
+ function cpuSplitBetween(prev, next) {
2393
+ const windowMs = next.atMs - prev.atMs;
2394
+ if (windowMs <= 0) return null;
2395
+ if (prev.startTicks === null || next.startTicks === null) return null;
2396
+ if (prev.startTicks !== next.startTicks) return null;
2397
+ const mainDelta = next.mainTicks - prev.mainTicks;
2398
+ const gcDelta = next.gcTicks - prev.gcTicks;
2399
+ if (mainDelta < 0 || gcDelta < 0) return null;
2400
+ const windowTicks = windowMs / 1e3 * CLOCK_TICKS_PER_SEC;
2401
+ const pct = (delta) => Math.round(delta / windowTicks * 1e3) / 10;
2402
+ return {
2403
+ mainPercent: pct(mainDelta),
2404
+ gcPercent: pct(gcDelta),
2405
+ threadCount: next.threadCount
2406
+ };
2407
+ }
2408
+ /**
2409
+ * Keeps the previous tick sample per pid so the next process-snapshot tick can
2410
+ * turn it into a rate.
2411
+ *
2412
+ * Bounded by construction: {@link sample} replaces the whole map with only the
2413
+ * pids it was just asked about, so a pid that stops appearing in the scan is
2414
+ * dropped on the following tick rather than accumulating forever.
2415
+ */
2416
+ var ThreadCpuTracker = class {
2417
+ reader;
2418
+ previous = /* @__PURE__ */ new Map();
2419
+ constructor(reader = nodeProcFsReader) {
2420
+ this.reader = reader;
2421
+ }
2422
+ /**
2423
+ * Sample `pids` and return the split for each one that HAS a usable previous
2424
+ * sample. A pid absent from the result has no answer yet — the caller must
2425
+ * report `null`, not `0`.
2426
+ */
2427
+ async sample(pids) {
2428
+ const out = /* @__PURE__ */ new Map();
2429
+ const nextPrevious = /* @__PURE__ */ new Map();
2430
+ for (const pid of pids) {
2431
+ const next = await readThreadTicks(pid, this.reader);
2432
+ if (next === null) continue;
2433
+ nextPrevious.set(pid, next);
2434
+ const prev = this.previous.get(pid);
2435
+ if (prev === void 0) continue;
2436
+ const split = cpuSplitBetween(prev, next);
2437
+ if (split !== null) out.set(pid, split);
2438
+ }
2439
+ this.previous = nextPrevious;
2440
+ return out;
2441
+ }
2442
+ };
2443
+ //#endregion
2444
+ //#region src/builtins/native-metrics/native-metrics.addon.ts
2445
+ /** The hub's node id — `isHub` below is the same test; device-history lives there. */
2446
+ var HUB_NODE_ID = "hub";
2447
+ /**
2448
+ * Cadence for the per-node metric snapshot bus events. ~5 s matches
2449
+ * the existing UI polling cadence (ProcessesTab, ProcessResources)
2450
+ * and stays within the sampling interval so consumers always see a
2451
+ * fresh-from-OS payload.
2452
+ */
2453
+ var METRICS_SNAPSHOT_INTERVAL_MS = 5e3;
2454
+ /**
2455
+ * Force a RESOURCES-snapshot emit at least every 60s even when the
2456
+ * coarsened payload looks unchanged. Without this an idle node
2457
+ * (steady CPU within ±5%, no process churn) goes silent on the
2458
+ * bus and the UI's "node alive" chip can stale out.
2459
+ *
2460
+ * The PROCESS-tree snapshot has no such heartbeat and no dedup: it is
2461
+ * fixed-cadence — see `startProcessSnapshotTimer`.
2462
+ */
2463
+ var METRICS_SNAPSHOT_HEARTBEAT_MS = 6e4;
2464
+ /**
2465
+ * Coarsen CPU/mem percentages to integer buckets before deduping.
2466
+ * Without this every 5s tick differs by ±0.3% and the equality check
2467
+ * always fails, so the snapshot fans out unconditionally.
2468
+ */
2469
+ function coarsenResourcesSnapshot(snapshot) {
2470
+ if (!snapshot || typeof snapshot !== "object") return JSON.stringify(snapshot);
2471
+ const round = (v) => {
2472
+ if (typeof v === "number") {
2473
+ if (v >= 0 && v <= 100) return Math.round(v / 5) * 5;
2474
+ return Math.round(v / 1e5) * 1e5;
2475
+ }
2476
+ if (Array.isArray(v)) return v.map(round);
2477
+ if (v && typeof v === "object") {
2478
+ const out = {};
2479
+ for (const [k, val] of Object.entries(v)) out[k] = round(val);
2480
+ return out;
2481
+ }
2482
+ return v;
2483
+ };
2484
+ return JSON.stringify(round(snapshot));
2485
+ }
2486
+ function narrowWorkerState(state) {
2487
+ switch (state) {
2488
+ case "starting":
2489
+ case "running":
2490
+ case "stopping":
2491
+ case "stopped":
2492
+ case "crashed": return state;
2493
+ default: return "running";
2494
+ }
2495
+ }
2496
+ /**
2497
+ * Native metrics — CPU, memory, disk usage sampling.
2498
+ * Settings appear under Cluster → NodeDetail → Settings.
2499
+ */
2500
+ var NativeMetricsAddon = class NativeMetricsAddon extends BaseAddon {
2501
+ provider = null;
2502
+ startedAtMs = Date.now();
2503
+ snapshotTimer = null;
2504
+ processSnapshotTimer = null;
2505
+ /**
2506
+ * Snapshot-equality cache for the resources + processes emit.
2507
+ * Stores the coarsened JSON and timestamp; a tick where the
2508
+ * coarsened payload matches the cache (and the heartbeat hasn't
2509
+ * elapsed) is skipped.
2510
+ */
2511
+ lastResourcesEmit = null;
2512
+ /**
2513
+ * Holds the previous `/proc/<pid>/task/*` tick counts so each process scan
2514
+ * can turn them into an instantaneous CPU rate split between the process's
2515
+ * own threads and V8's helper pool. Self-bounding — see `ThreadCpuTracker`.
2516
+ */
2517
+ threadCpu = new ThreadCpuTracker();
2518
+ /**
2519
+ * Retention for the snapshots this addon emits. Fed by SUBSCRIBING to
2520
+ * `metrics.node-processes-snapshot`, never by a second sampler — on the hub
2521
+ * that bus carries every node, so the hub's ring is the cluster's. Bounds and
2522
+ * measured cost live in `node-load-ring.ts`.
2523
+ */
2524
+ loadRing = new NodeLoadRing();
2525
+ /**
2526
+ * The COLD tier, and it exists only on the HUB.
2527
+ *
2528
+ * The table is hub-resident and the hub already hears every node's snapshot
2529
+ * on its bus, so the hub's writer is the cluster's. An agent writing through
2530
+ * the `settings-store` singleton would ship its rows over Moleculer, once
2531
+ * per sample, to reach that very same table.
2532
+ */
2533
+ metricsHistory = null;
2534
+ /**
2535
+ * The container's OWN memory, sampled on the process-snapshot tick.
2536
+ *
2537
+ * It rides that tick rather than a timer of its own so a memory reading and
2538
+ * the process rows it must be compared against carry the SAME timestamp —
2539
+ * the whole question is a subtraction, and two clocks make it an estimate.
2540
+ * Constructed in `onInitialize`, where the logger exists; it resolves the
2541
+ * cgroup once and latches.
2542
+ */
2543
+ memoryProbe = null;
2544
+ pidsProbe = null;
2545
+ /** Hot tier for the container reading. Bounds in `container-memory-ring.ts`. */
2546
+ memoryRing = new ContainerMemoryRing();
2547
+ /** The resolved knobs. Re-resolved on every settings write. */
2548
+ loadConfig = {
2549
+ cadenceSec: 10,
2550
+ retentionHours: 6,
2551
+ maxRows: DEFAULT_MAX_ROWS
2552
+ };
2553
+ /**
2554
+ * Process rows seen in each node's most recent snapshot — the OBSERVED
2555
+ * numbers the settings form projects its cost from. A constant here would be
2556
+ * a projection that stops being true the first time the fleet changes.
2557
+ */
2558
+ observedRowsByNode = /* @__PURE__ */ new Map();
2559
+ constructor() {
2560
+ super({
2561
+ samplingIntervalMs: 5e3,
2562
+ loadSeriesCadenceSec: 10,
2563
+ loadSeriesRetentionHours: 6
2564
+ });
2565
+ }
2566
+ /** Is this the hub? The same test every other addon uses (`addon-ai`). */
2567
+ get isHub() {
2568
+ return (this.ctx.kernel.cluster?.broker?.nodeID ?? HUB_NODE_ID) === HUB_NODE_ID;
2569
+ }
2570
+ /** Process rows observed across the whole fleet, for the cost projection. */
2571
+ observedFleetRows() {
2572
+ let total = 0;
2573
+ for (const rows of this.observedRowsByNode.values()) total += rows;
2574
+ return total;
2575
+ }
2576
+ /**
2577
+ * Project a `NodeProcess` onto the series' own row.
2578
+ *
2579
+ * `command`, `ppid`, `pgid`, `nodeId`, `threadCount` and `uptimeSec` are
2580
+ * dropped here, at the single point both tiers pass through, so the hot ring
2581
+ * and the cold table carry the SAME shape and the merged read cannot tell
2582
+ * them apart. `command` in particular is the fattest field in a snapshot and
2583
+ * the same identical string on every runner — the runner id travels in the
2584
+ * environment, not in argv — and nothing that draws this series reads it.
2585
+ */
2586
+ static toRetained(process) {
2587
+ return {
2588
+ pid: process.pid,
2589
+ addonId: process.addonId,
2590
+ classification: process.classification,
2591
+ cpuPercent: process.cpuPercent,
2592
+ memoryRssBytes: process.memoryRssBytes,
2593
+ cpuMainPercent: process.cpuMainPercent,
2594
+ cpuGcPercent: process.cpuGcPercent
2595
+ };
2596
+ }
2597
+ async onInitialize() {
2598
+ const provider = new NativeMetricsProvider();
2599
+ provider.setDiagnostics({ warn: (message, meta) => this.ctx.logger.warn(message, { meta: meta ?? {} }) });
2600
+ provider.startSampling(this.config.samplingIntervalMs);
2601
+ this.provider = provider;
2602
+ this.startedAtMs = Date.now();
2603
+ this.ctx.logger.info("Native metrics provider started", { meta: { intervalMs: this.config.samplingIntervalMs } });
2604
+ const composed = {
2605
+ collectSnapshot: () => provider.collectSnapshot(),
2606
+ getCached: () => provider.getCached(),
2607
+ getCurrent: () => provider.getCurrent(),
2608
+ getDiskSpace: (params) => provider.getDiskSpace(params),
2609
+ getGpuInfo: () => provider.getGpuInfo(),
2610
+ getCpuTemperature: () => provider.getCpuTemperature(),
2611
+ getProcessStats: (params) => provider.getProcessStats(params),
2612
+ listAddonInstances: () => this.listAddonInstances(),
2613
+ getAddonStats: (params) => this.getAddonStats(params.addonId),
2614
+ listNodeProcesses: () => this.listNodeProcesses(),
2615
+ getLoadSeries: (params) => this.readLoadSeries(params)
2616
+ };
2617
+ this.applyLoadSeriesConfig();
2618
+ if (this.isHub) {
2619
+ const historyScope = {
2620
+ type: "node",
2621
+ nodeId: HUB_NODE_ID
2622
+ };
2623
+ const historyHandle = this.ctx.useCapability("device-history", historyScope);
2624
+ const recorder = new NodeMetricsHistoryRecorder({
2625
+ deviceHistory: nodeMetricsHistoryClient(this.ctx.api.deviceHistory),
2626
+ logger: this.ctx.logger.child("NodeMetricsHistory"),
2627
+ historyReady: () => historyHandle.isReady
2628
+ });
2629
+ this.metricsHistory = recorder;
2630
+ const declareNow = () => {
2631
+ recorder.declare().catch((err) => {
2632
+ this.ctx.logger.warn("node metrics history declare failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
2633
+ });
2634
+ };
2635
+ this.ctx.addDisposer(this.ctx.onCapabilityStateChange("device-history", historyScope, (state) => {
2636
+ if (state === "ready") declareNow();
2637
+ }));
2638
+ if (historyHandle.isReady) declareNow();
2639
+ }
2640
+ this.memoryProbe = new ContainerMemoryProbe({ logger: this.ctx.logger.child("ContainerMemory") });
2641
+ this.pidsProbe = new ContainerPidsProbe({ logger: this.ctx.logger.child("ContainerPids") });
2642
+ if (this.snapshotTimer) clearInterval(this.snapshotTimer);
2643
+ this.snapshotTimer = setInterval(() => this.runTick("resources snapshot", () => this.emitResourcesSnapshot()), METRICS_SNAPSHOT_INTERVAL_MS);
2644
+ this.startProcessSnapshotTimer();
2645
+ if (this.metricsHistory !== null) {
2646
+ const history = this.metricsHistory;
2647
+ this.ctx.addDisposer(this.ctx.eventBus.subscribe({ category: EventCategory.MetricsNodeResourcesSnapshot }, (event) => {
2648
+ history.recordTotals(event.data.nodeId, event.data.timestamp, event.data.snapshot);
2649
+ }));
2650
+ }
2651
+ this.ctx.addDisposer(this.ctx.eventBus.subscribe({ category: EventCategory.MetricsNodeProcessesSnapshot }, (event) => this.retainSnapshot(event.data.nodeId, event.data.timestamp, event.data.processes, event.data.containerMemory)));
2652
+ return [{
2653
+ capability: metricsProviderCapability,
2654
+ provider: composed
2655
+ }];
2656
+ }
2657
+ /**
2658
+ * Retain one arriving snapshot in BOTH tiers.
2659
+ *
2660
+ * The ring is written FIRST and it is the gate: `record` refuses a timestamp
2661
+ * this node has already delivered, and only an accepted sample reaches the
2662
+ * table. That is what makes the append idempotent without a unique index
2663
+ * over two million rows — the composite key it replaces was measured at ~40
2664
+ * bytes per row (measured on the old SQLite tier; see D850).
2665
+ *
2666
+ * The durable append is fire-and-forget: a storage stall must cost a gap in
2667
+ * the cold window, never a blocked event-bus handler. Every failure logs.
2668
+ */
2669
+ retainSnapshot(nodeId, atMs, processes, containerMemory) {
2670
+ const retained = processes.map((p) => NativeMetricsAddon.toRetained(p));
2671
+ if (!this.loadRing.record(nodeId, atMs, retained)) return;
2672
+ this.observedRowsByNode.set(nodeId, retained.length);
2673
+ if (containerMemory !== null) this.memoryRing.record(nodeId, atMs, containerMemory);
2674
+ const history = this.metricsHistory;
2675
+ if (history === null) return;
2676
+ history.recordSample(nodeId, atMs, retained, containerMemory);
2677
+ }
2678
+ /**
2679
+ * The ONE reader, over both tiers.
2680
+ *
2681
+ * Cold first, hot second, merged and deduped on `atMs` — see
2682
+ * `load-series-reader.ts`. The cold read is bounded in ROWS, because rows
2683
+ * are what a query costs, and the fold + reduction happen HERE rather than
2684
+ * in the browser: six hours at the 10 s cadence is 2 160 snapshots, and
2685
+ * shipping them to a page that will discard most of them is precisely the
2686
+ * cost this subsystem exists to avoid.
2687
+ */
2688
+ async readLoadSeries(params) {
2689
+ const cadenceMs = this.loadConfig.cadenceSec * 1e3;
2690
+ const sinceMs = params.sinceMs ?? 0;
2691
+ const hotSamples = this.loadRing.read(params.forNodeId, params.sinceMs).samples.map((sample) => ({
2692
+ atMs: sample.atMs,
2693
+ processes: sample.processes
2694
+ }));
2695
+ const history = this.metricsHistory;
2696
+ const merged = mergeLoadSeries({
2697
+ cold: history === null ? [] : await history.readProcessSamples(params.forNodeId, sinceMs, this.loadConfig.maxRows),
2698
+ hot: hotSamples,
2699
+ cadenceMs,
2700
+ ...params.maxPoints !== void 0 ? { maxPoints: params.maxPoints } : {}
2701
+ });
2702
+ return {
2703
+ nodeId: params.forNodeId,
2704
+ series: merged.series,
2705
+ containerMemory: await this.readContainerMemory({
2706
+ forNodeId: params.forNodeId,
2707
+ sinceMs,
2708
+ ...params.sinceMs !== void 0 ? { exclusiveSinceMs: params.sinceMs } : {},
2709
+ bucketMs: merged.bucketMs,
2710
+ cadenceMs,
2711
+ origin: merged.oldestAtMs
2712
+ }),
2713
+ bucketMs: merged.bucketMs,
2714
+ retainedSamples: merged.retainedSamples,
2715
+ oldestAtMs: merged.oldestAtMs,
2716
+ cadenceMs,
2717
+ durable: history !== null
2718
+ };
2719
+ }
2720
+ /**
2721
+ * The container's memory over the same window, on the same x-axis.
2722
+ *
2723
+ * Both tiers, merged and deduped on `atMs` like the process series, then
2724
+ * reduced against the SAME `bucketMs` and the SAME origin — otherwise the
2725
+ * two series in one answer would sit on two different axes and the
2726
+ * subtraction they exist for would be an eyeball.
2727
+ *
2728
+ * An EMPTY answer means the node has no cgroup, or nothing has been retained
2729
+ * for it yet. It never means zero.
2730
+ */
2731
+ async readContainerMemory(params) {
2732
+ const hot = this.memoryRing.read(params.forNodeId, params.exclusiveSinceMs);
2733
+ const history = this.metricsHistory;
2734
+ const merged = mergeContainerMemory(history === null ? [] : await history.readContainerPoints(params.forNodeId, params.sinceMs, 5e3), hot);
2735
+ if (params.bucketMs <= params.cadenceMs) return merged;
2736
+ return reduceContainerMemory(merged, params.bucketMs, params.origin ?? 0);
2737
+ }
2738
+ /**
2739
+ * Re-resolve the knobs and restate the fixed cadence.
2740
+ *
2741
+ * A REFUSED value (out of 5-60 s, or out of 1-72 h) leaves the previous
2742
+ * configuration in force and says so. Refused, never clamped: storing 10
2743
+ * when the operator typed 2 and reading 10 back is a knob and a readback
2744
+ * agreeing on a value nobody chose.
2745
+ */
2746
+ applyLoadSeriesConfig() {
2747
+ try {
2748
+ const next = resolveLoadSeriesConfig({
2749
+ loadSeriesCadenceSec: this.config.loadSeriesCadenceSec,
2750
+ loadSeriesRetentionHours: this.config.loadSeriesRetentionHours
2751
+ });
2752
+ const changed = next.cadenceSec !== this.loadConfig.cadenceSec || next.retentionHours !== this.loadConfig.retentionHours;
2753
+ this.loadConfig = next;
2754
+ if (changed) {
2755
+ const projection = projectLoadSeriesCost({
2756
+ config: next,
2757
+ observedProcessRows: this.observedFleetRows()
2758
+ });
2759
+ this.ctx.logger.info("load series configuration applied", { meta: {
2760
+ nodeId: this.ctx.kernel.localNodeId ?? this.ctx.id,
2761
+ cadenceSec: next.cadenceSec,
2762
+ retentionHours: next.retentionHours,
2763
+ maxRows: next.maxRows,
2764
+ projectedRows: projection.intendedRows,
2765
+ projectedMib: Math.round(projection.estimatedBytes / 1048576 * 10) / 10,
2766
+ capBites: projection.capBites
2767
+ } });
2768
+ }
2769
+ } catch (err) {
2770
+ this.ctx.logger.warn("load series configuration REFUSED — keeping the previous values", { meta: {
2771
+ nodeId: this.ctx.kernel.localNodeId ?? this.ctx.id,
2772
+ cadenceSec: this.loadConfig.cadenceSec,
2773
+ retentionHours: this.loadConfig.retentionHours,
2774
+ error: err instanceof Error ? err.message : String(err)
2775
+ } });
2776
+ }
2777
+ }
2778
+ /**
2779
+ * (Re)arm the process-tree timer at the configured interval.
2780
+ *
2781
+ * The process-tree snapshot is FIXED-CADENCE, and its cadence is the
2782
+ * operator's `loadSeriesCadenceSec` (5-60 s, 10 by default).
2783
+ *
2784
+ * It used to emit only ON A CHANGE, with a 60 s fallback heartbeat, and the
2785
+ * dedup is gone rather than tuned. A conditional emit makes a hole in the
2786
+ * series mean two different things — "nothing changed" and "nobody reported"
2787
+ * — and telling those apart is the entire reason an operator opens this chart
2788
+ * after a spike. Now a gap means exactly one thing.
2789
+ *
2790
+ * It is not free: the emit rate is deterministic, so the durable table's row
2791
+ * count is too (nodes x processes / cadence, no discount for a quiet fleet).
2792
+ * The measured cost of that is in `docs/architecture/load-ledger.md`, and it
2793
+ * is why the retention default is six hours rather than three days.
2794
+ */
2795
+ startProcessSnapshotTimer() {
2796
+ if (this.processSnapshotTimer) clearInterval(this.processSnapshotTimer);
2797
+ this.processSnapshotTimer = null;
2798
+ if (!this.ctxIfReady) return;
2799
+ this.processSnapshotTimer = setInterval(() => this.runTick("process snapshot", () => this.emitProcessesSnapshot()), this.loadConfig.cadenceSec * 1e3);
2800
+ }
2801
+ /**
2802
+ * Run one periodic tick so that it can NEVER become an unhandled rejection.
2803
+ *
2804
+ * `clearInterval` in `onShutdown` stops FUTURE ticks; it cannot recall one
2805
+ * already in flight. A process tick awaits a `/proc` read and a
2806
+ * `$process.list` broker call, and a graceful stop shuts this addon down
2807
+ * (nulling `ctx`) while the agent goes on to stop its other addons and the
2808
+ * broker — so the tick resumed with no context, its catch block reached for
2809
+ * `this.ctx.logger`, threw again, and the rejection of the timer callback
2810
+ * killed `docker stop CamStack-Agent` with exit code 1 (agent-a,
2811
+ * 2026-10-07 04:22Z). The ticks themselves now capture their context once
2812
+ * and stand down when it is gone; this wrapper is the backstop.
2813
+ *
2814
+ * A tick before `initialize()` or after `shutdown()` is a no-op.
2815
+ */
2816
+ runTick(name, tick) {
2817
+ if (!this.ctxIfReady) return;
2818
+ tick().catch((err) => {
2819
+ this.ctxIfReady?.logger.warn("native-metrics tick failed — this interval will be missing", { meta: {
2820
+ tick: name,
2821
+ error: err instanceof Error ? err.message : String(err)
2822
+ } });
2823
+ });
2824
+ }
2825
+ async onShutdown() {
2826
+ if (this.snapshotTimer) {
2827
+ clearInterval(this.snapshotTimer);
2828
+ this.snapshotTimer = null;
2829
+ }
2830
+ if (this.processSnapshotTimer) {
2831
+ clearInterval(this.processSnapshotTimer);
2832
+ this.processSnapshotTimer = null;
2833
+ }
2834
+ this.provider?.stopSampling();
2835
+ this.provider = null;
2836
+ }
2837
+ /**
2838
+ * Resolve this node's short id (strips any `nodeId/addonId` suffix).
2839
+ * Returns null when the provider or event bus isn't available yet.
2840
+ */
2841
+ resolveSnapshotNodeId(ctx) {
2842
+ if (!this.provider || !ctx.eventBus) return null;
2843
+ const rawNodeId = ctx.kernel.localNodeId ?? ctx.id;
2844
+ return rawNodeId.includes("/") ? rawNodeId.split("/")[0] : rawNodeId;
2845
+ }
2846
+ /**
2847
+ * Emit one `metrics.node-resources-snapshot` for this node. Cheap —
2848
+ * reads the cached sample (the provider's background sampler already
2849
+ * runs at samplingIntervalMs). Fires on METRICS_SNAPSHOT_INTERVAL_MS.
2850
+ */
2851
+ async emitResourcesSnapshot() {
2852
+ const ctx = this.ctxIfReady;
2853
+ if (!ctx) return;
2854
+ const provider = this.provider;
2855
+ const eventBus = ctx.eventBus;
2856
+ const nodeId = this.resolveSnapshotNodeId(ctx);
2857
+ if (!provider || !eventBus || !nodeId) return;
2858
+ const timestamp = Date.now();
2859
+ try {
2860
+ const snapshot = await provider.getCached() ?? await provider.collectSnapshot();
2861
+ if (this.ctxIfReady !== ctx) return;
2862
+ const coarse = coarsenResourcesSnapshot(snapshot);
2863
+ const prev = this.lastResourcesEmit;
2864
+ const heartbeatDue = !prev || timestamp - prev.emittedAt >= METRICS_SNAPSHOT_HEARTBEAT_MS;
2865
+ if (!prev || prev.coarse !== coarse || heartbeatDue) {
2866
+ this.lastResourcesEmit = {
2867
+ coarse,
2868
+ emittedAt: timestamp
2869
+ };
2870
+ eventBus.emit(createEvent(EventCategory.MetricsNodeResourcesSnapshot, {
2871
+ type: "node",
2872
+ id: nodeId,
2873
+ nodeId
2874
+ }, {
2875
+ nodeId,
2876
+ snapshot,
2877
+ timestamp
2878
+ }));
2879
+ }
2880
+ } catch {}
2881
+ }
2882
+ /**
2883
+ * Emit one `metrics.node-processes-snapshot` for this node.
2884
+ *
2885
+ * Heavy — a full process-table read (`/proc` on Linux, `ps -eo` elsewhere;
2886
+ * `proc-process-table.ts`) plus a `$process.list` broker call — and
2887
+ * UNCONDITIONAL. The change-detection that used to guard it is gone: with a
2888
+ * fixed cadence a missing interval means exactly one thing, and that is the
2889
+ * property an operator investigating a spike is actually looking for.
2890
+ *
2891
+ * A failed scan emits nothing, which is the same signal: nobody reported.
2892
+ */
2893
+ async emitProcessesSnapshot() {
2894
+ const ctx = this.ctxIfReady;
2895
+ if (!ctx) return;
2896
+ const eventBus = ctx.eventBus;
2897
+ const nodeId = this.resolveSnapshotNodeId(ctx);
2898
+ if (!this.provider || !eventBus || !nodeId) return;
2899
+ const timestamp = Date.now();
2900
+ try {
2901
+ const processes = await this.listNodeProcesses();
2902
+ if (this.ctxIfReady !== ctx) {
2903
+ ctx.logger.debug("process snapshot dropped — addon shut down mid-tick", { meta: { nodeId } });
2904
+ return;
2905
+ }
2906
+ const containerMemory = this.memoryProbe?.sample() ?? null;
2907
+ this.pidsProbe?.sample();
2908
+ eventBus.emit(createEvent(EventCategory.MetricsNodeProcessesSnapshot, {
2909
+ type: "node",
2910
+ id: nodeId,
2911
+ nodeId
2912
+ }, {
2913
+ nodeId,
2914
+ processes,
2915
+ timestamp,
2916
+ containerMemory
2917
+ }));
2918
+ } catch (err) {
2919
+ ctx.logger.warn("process snapshot skipped — this interval will be missing", { meta: {
2920
+ nodeId,
2921
+ error: err instanceof Error ? err.message : String(err)
2922
+ } });
2923
+ }
2924
+ }
2925
+ async onConfigChanged() {
2926
+ if (!this.ctxIfReady) return;
2927
+ this.provider?.stopSampling();
2928
+ this.provider?.startSampling(this.config.samplingIntervalMs);
2929
+ this.applyLoadSeriesConfig();
2930
+ this.startProcessSnapshotTimer();
2931
+ }
2932
+ async listWorkerInstances() {
2933
+ const broker = this.ctxIfReady?.kernel.cluster?.broker;
2934
+ if (!broker) return [];
2935
+ try {
2936
+ return await broker.call("$process.list");
2937
+ } catch {
2938
+ return [];
2939
+ }
2940
+ }
2941
+ async listAddonInstances() {
2942
+ const hubNodeId = (this.ctx.kernel.cluster?.broker)?.nodeID ?? "hub";
2943
+ const uptimeSec = Math.max(0, Math.floor((Date.now() - this.startedAtMs) / 1e3));
2944
+ const instances = [{
2945
+ addonId: "$hub",
2946
+ nodeId: hubNodeId,
2947
+ role: "hub",
2948
+ pid: process.pid,
2949
+ state: "running",
2950
+ uptimeSec
2951
+ }];
2952
+ const workers = await this.listWorkerInstances();
2953
+ for (const w of workers) instances.push({
2954
+ addonId: w.addonId,
2955
+ nodeId: w.nodeId,
2956
+ role: "worker",
2957
+ pid: w.pid,
2958
+ state: narrowWorkerState(w.state),
2959
+ uptimeSec: w.uptimeSeconds
2960
+ });
2961
+ return instances;
2962
+ }
2963
+ async getAddonStats(addonId) {
2964
+ const provider = this.provider;
2965
+ if (!provider) return null;
2966
+ if (addonId === "$hub") return (await provider.getProcessStats({ pids: [process.pid] }))[0] ?? null;
2967
+ const target = (await this.listWorkerInstances()).find((w) => w.addonId === addonId);
2968
+ if (!target) return null;
2969
+ return (await provider.getProcessStats({ pids: [target.pid] }))[0] ?? null;
2970
+ }
2971
+ /**
2972
+ * Walk the OS process table and classify each camstack-shaped process.
2973
+ *
2974
+ * Classification is IDENTITY-driven: `root` is this pid, `managed` is a pid
2975
+ * the kernel's `$process.list` names, and every other camstack-shaped
2976
+ * process is `system`. The rules — and why there is no longer an ancestry
2977
+ * walk behind them — live in `process-classification.ts`.
2978
+ */
2979
+ async listNodeProcesses() {
2980
+ const selfNodeId = this.ctx.kernel.cluster?.broker?.nodeID ?? "hub";
2981
+ const ps = await this.runPs();
2982
+ if (ps.length === 0) return [];
2983
+ const managed = /* @__PURE__ */ new Map();
2984
+ const workers = await this.listWorkerInstances();
2985
+ for (const w of workers) managed.set(w.pid, {
2986
+ addonId: w.addonId,
2987
+ nodeId: w.nodeId
2988
+ });
2989
+ const camstackPids = ps.filter((p) => CAMSTACK_CMD_RE.test(p.command)).map((p) => p.pid);
2990
+ const cpuSplits = await this.threadCpu.sample(camstackPids);
2991
+ return buildNodeProcesses({
2992
+ psRows: ps,
2993
+ selfPid: process.pid,
2994
+ selfNodeId,
2995
+ managed,
2996
+ cpuSplits
2997
+ });
2998
+ }
2999
+ /**
3000
+ * Every pid + command + resource stats on this node.
3001
+ *
3002
+ * From `/proc` on Linux — no fork. This used to be a `ps -eo` child on every
3003
+ * tick, i.e. a synchronous `fork()` of hub-main at p50 91 ms (D441, D452).
3004
+ * `ps` remains the source only on a platform without `/proc`.
3005
+ */
3006
+ async runPs() {
3007
+ try {
3008
+ return await readProcessTable();
3009
+ } catch (err) {
3010
+ this.ctxIfReady?.logger.warn("process table read failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
3011
+ return [];
3012
+ }
3013
+ }
3014
+ /**
3015
+ * The knobs live HERE, on the document this addon already owns.
3016
+ *
3017
+ * Fields on an existing document, never a method per knob —
3018
+ * `system.getLoggingSettings` / `setLoggingSettings` set that precedent.
3019
+ * They are deliberately NOT in the logging document: that one is about
3020
+ * levels and diagnostic windows, and two documents both claiming a knob is
3021
+ * how this repo has already shipped a switch nobody read.
3022
+ *
3023
+ * Cluster-wide, not per-node: every node must emit on the same cadence or
3024
+ * the fleet's series cannot be laid over each other, and the table is single
3025
+ * and hub-resident, so a per-node retention would be a promise nothing could
3026
+ * keep.
3027
+ *
3028
+ * The cost line is computed from OBSERVED numbers — the nodes and process
3029
+ * counts the cluster is actually reporting — so an operator raising the
3030
+ * retention sees what it costs BEFORE applying it, not afterwards.
3031
+ */
3032
+ globalSettingsSchema() {
3033
+ const projection = projectLoadSeriesCost({
3034
+ config: this.loadConfig,
3035
+ observedProcessRows: this.observedFleetRows()
3036
+ });
3037
+ return this.schema({ sections: [{
3038
+ id: "native-metrics-settings",
3039
+ title: "System Metrics",
3040
+ titleKey: "server:globalSettings.s_native-metrics-settings.title",
3041
+ fields: [this.field({
3042
+ type: "number",
3043
+ key: "samplingIntervalMs",
3044
+ label: "Sampling Interval",
3045
+ labelKey: "server:globalSettings.s_native-metrics-settings.samplingIntervalMs.label",
3046
+ description: "How often to collect system metrics",
3047
+ descriptionKey: "server:globalSettings.s_native-metrics-settings.samplingIntervalMs.description",
3048
+ min: 1e3,
3049
+ max: 6e4,
3050
+ step: 1e3,
3051
+ default: 5e3,
3052
+ unit: "ms"
3053
+ })]
3054
+ }, {
3055
+ id: "native-metrics-load-series",
3056
+ title: "Load history",
3057
+ titleKey: "server:globalSettings.s_native-metrics-load-series.title",
3058
+ fields: [
3059
+ this.field({
3060
+ type: "number",
3061
+ key: "loadSeriesCadenceSec",
3062
+ label: "Sampling cadence",
3063
+ labelKey: "server:globalSettings.s_native-metrics-load-series.loadSeriesCadenceSec.label",
3064
+ description: "How often every node reports its process tree. FIXED — a sample is emitted on every interval whether or not anything changed, so a gap in the chart means one thing only: nobody reported. Outside 5-60 s the value is refused.",
3065
+ descriptionKey: "server:globalSettings.s_native-metrics-load-series.loadSeriesCadenceSec.description",
3066
+ min: 5,
3067
+ max: 60,
3068
+ step: 1,
3069
+ default: 10,
3070
+ unit: "s"
3071
+ }),
3072
+ this.field({
3073
+ type: "number",
3074
+ key: "loadSeriesRetentionHours",
3075
+ label: "Retention",
3076
+ labelKey: "server:globalSettings.s_native-metrics-load-series.loadSeriesRetentionHours.label",
3077
+ description: "How long the load history is kept on disk (the hub database, on the NVMe cache — never the recordings disk). This is the INTENTION; the row cap below is the guarantee.",
3078
+ descriptionKey: "server:globalSettings.s_native-metrics-load-series.loadSeriesRetentionHours.description",
3079
+ min: 1,
3080
+ max: 72,
3081
+ step: 1,
3082
+ default: 6,
3083
+ unit: "h"
3084
+ }),
3085
+ {
3086
+ type: "info",
3087
+ key: "load-series-cost",
3088
+ label: "What this configuration costs",
3089
+ labelKey: "server:globalSettings.s_native-metrics-load-series.load-series-cost.label",
3090
+ content: describeLoadSeriesCost(projection),
3091
+ variant: projection.capBites ? "warning" : "info"
3092
+ },
3093
+ {
3094
+ type: "info",
3095
+ key: "load-series-cap",
3096
+ label: "Hard row cap",
3097
+ labelKey: "server:globalSettings.s_native-metrics-load-series.load-series-cap.label",
3098
+ content: `The table never exceeds ${this.loadConfig.maxRows.toLocaleString("en-US")} rows. When it would, the OLDEST samples are evicted and a warning is logged — so raising the retention can never turn into an incident, only into a shorter effective window.`,
3099
+ variant: "info"
3100
+ }
3101
+ ]
3102
+ }] });
3103
+ }
3104
+ };
3105
+ //#endregion
3106
+ export { NativeMetricsProvider as a, NativeMetricsAddon as default, parseProcStatusRss as i, nodeProcReader as n, parseProcStat as r, lifetimeCpuPercent as t };