@senpi-ai/runtime 3.0.134 → 3.0.136

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 (264) hide show
  1. package/dist/actions/action-events.d.ts +21 -7
  2. package/dist/actions/action-events.d.ts.map +1 -1
  3. package/dist/actions/action-events.js +54 -26
  4. package/dist/actions/action-events.js.map +1 -1
  5. package/dist/actions/action-runtime-module.d.ts.map +1 -1
  6. package/dist/actions/action-runtime-module.js +38 -7
  7. package/dist/actions/action-runtime-module.js.map +1 -1
  8. package/dist/actions/close-position/close-position.action.d.ts.map +1 -1
  9. package/dist/actions/close-position/close-position.action.js +122 -15
  10. package/dist/actions/close-position/close-position.action.js.map +1 -1
  11. package/dist/actions/decision-engine.d.ts.map +1 -1
  12. package/dist/actions/decision-engine.js +15 -2
  13. package/dist/actions/decision-engine.js.map +1 -1
  14. package/dist/actions/event-derivation.d.ts +71 -2
  15. package/dist/actions/event-derivation.d.ts.map +1 -1
  16. package/dist/actions/event-derivation.js +251 -8
  17. package/dist/actions/event-derivation.js.map +1 -1
  18. package/dist/actions/open-position/open-position.action.d.ts +12 -2
  19. package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
  20. package/dist/actions/open-position/open-position.action.js +141 -41
  21. package/dist/actions/open-position/open-position.action.js.map +1 -1
  22. package/dist/actions/position-tracker/position-tracker.action.d.ts +2 -1
  23. package/dist/actions/position-tracker/position-tracker.action.d.ts.map +1 -1
  24. package/dist/actions/position-tracker/position-tracker.action.js +62 -17
  25. package/dist/actions/position-tracker/position-tracker.action.js.map +1 -1
  26. package/dist/actions/skipped-signal-results.d.ts +25 -0
  27. package/dist/actions/skipped-signal-results.d.ts.map +1 -0
  28. package/dist/actions/skipped-signal-results.js +71 -0
  29. package/dist/actions/skipped-signal-results.js.map +1 -0
  30. package/dist/actions/store/types.d.ts +9 -2
  31. package/dist/actions/store/types.d.ts.map +1 -1
  32. package/dist/actions/store/types.js.map +1 -1
  33. package/dist/actions/types.d.ts +13 -0
  34. package/dist/actions/types.d.ts.map +1 -1
  35. package/dist/actions/types.js +13 -0
  36. package/dist/actions/types.js.map +1 -1
  37. package/dist/cli/guide-commands.d.ts.map +1 -1
  38. package/dist/cli/guide-commands.js +3 -0
  39. package/dist/cli/guide-commands.js.map +1 -1
  40. package/dist/constants/dsl/index.d.ts +6 -0
  41. package/dist/constants/dsl/index.d.ts.map +1 -1
  42. package/dist/constants/dsl/index.js +6 -0
  43. package/dist/constants/dsl/index.js.map +1 -1
  44. package/dist/dsl/engine-client/event-mapping.d.ts.map +1 -1
  45. package/dist/dsl/engine-client/event-mapping.js +14 -0
  46. package/dist/dsl/engine-client/event-mapping.js.map +1 -1
  47. package/dist/dsl/events/build-closed-event.d.ts +16 -1
  48. package/dist/dsl/events/build-closed-event.d.ts.map +1 -1
  49. package/dist/dsl/events/build-closed-event.js +6 -0
  50. package/dist/dsl/events/build-closed-event.js.map +1 -1
  51. package/dist/dsl/events/handlers.d.ts +7 -0
  52. package/dist/dsl/events/handlers.d.ts.map +1 -1
  53. package/dist/dsl/events/handlers.js +37 -7
  54. package/dist/dsl/events/handlers.js.map +1 -1
  55. package/dist/dsl/monitor/create-monitor.d.ts +6 -2
  56. package/dist/dsl/monitor/create-monitor.d.ts.map +1 -1
  57. package/dist/dsl/monitor/create-monitor.js +82 -9
  58. package/dist/dsl/monitor/create-monitor.js.map +1 -1
  59. package/dist/dsl/monitor/dsl-failure-events.d.ts +45 -2
  60. package/dist/dsl/monitor/dsl-failure-events.d.ts.map +1 -1
  61. package/dist/dsl/monitor/dsl-failure-events.js +52 -3
  62. package/dist/dsl/monitor/dsl-failure-events.js.map +1 -1
  63. package/dist/dsl/monitor/process-one-position.d.ts +1 -0
  64. package/dist/dsl/monitor/process-one-position.d.ts.map +1 -1
  65. package/dist/dsl/monitor/process-one-position.js +159 -36
  66. package/dist/dsl/monitor/process-one-position.js.map +1 -1
  67. package/dist/dsl/plugin/index.d.ts +8 -2
  68. package/dist/dsl/plugin/index.d.ts.map +1 -1
  69. package/dist/dsl/plugin/index.js +8 -6
  70. package/dist/dsl/plugin/index.js.map +1 -1
  71. package/dist/health/types.d.ts +13 -0
  72. package/dist/health/types.d.ts.map +1 -1
  73. package/dist/health/types.js +12 -0
  74. package/dist/health/types.js.map +1 -1
  75. package/dist/index.d.ts +27 -4
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js +271 -41
  78. package/dist/index.js.map +1 -1
  79. package/dist/runtime/action-registry.d.ts.map +1 -1
  80. package/dist/runtime/action-registry.js +4 -3
  81. package/dist/runtime/action-registry.js.map +1 -1
  82. package/dist/runtime/domain-events.d.ts.map +1 -1
  83. package/dist/runtime/domain-events.js +7 -0
  84. package/dist/runtime/domain-events.js.map +1 -1
  85. package/dist/runtime/lifecycle-events.d.ts +15 -3
  86. package/dist/runtime/lifecycle-events.d.ts.map +1 -1
  87. package/dist/runtime/lifecycle-events.js +17 -3
  88. package/dist/runtime/lifecycle-events.js.map +1 -1
  89. package/dist/runtime/lifecycle-reaper.d.ts +4 -6
  90. package/dist/runtime/lifecycle-reaper.d.ts.map +1 -1
  91. package/dist/runtime/lifecycle-reaper.js +4 -6
  92. package/dist/runtime/lifecycle-reaper.js.map +1 -1
  93. package/dist/runtime/reconcile-run.d.ts +13 -3
  94. package/dist/runtime/reconcile-run.d.ts.map +1 -1
  95. package/dist/runtime/reconcile-run.js +4 -3
  96. package/dist/runtime/reconcile-run.js.map +1 -1
  97. package/dist/runtime/reconcile-state.d.ts +8 -0
  98. package/dist/runtime/reconcile-state.d.ts.map +1 -1
  99. package/dist/runtime/reconcile-state.js +4 -1
  100. package/dist/runtime/reconcile-state.js.map +1 -1
  101. package/dist/runtime/run.d.ts +1 -0
  102. package/dist/runtime/run.d.ts.map +1 -1
  103. package/dist/runtime/run.js.map +1 -1
  104. package/dist/runtime/runtime-schema.js +3 -3
  105. package/dist/runtime/runtime-schema.js.map +1 -1
  106. package/dist/runtime/runtime.d.ts +1 -0
  107. package/dist/runtime/runtime.d.ts.map +1 -1
  108. package/dist/runtime/runtime.js +28 -4
  109. package/dist/runtime/runtime.js.map +1 -1
  110. package/dist/runtime/supervisor/long-running-supervisor.d.ts +13 -0
  111. package/dist/runtime/supervisor/long-running-supervisor.d.ts.map +1 -1
  112. package/dist/runtime/supervisor/long-running-supervisor.js +1 -0
  113. package/dist/runtime/supervisor/long-running-supervisor.js.map +1 -1
  114. package/dist/runtime/validate-dsl-position-tracking.d.ts.map +1 -1
  115. package/dist/runtime/validate-dsl-position-tracking.js +2 -1
  116. package/dist/runtime/validate-dsl-position-tracking.js.map +1 -1
  117. package/dist/runtime-api/handlers/ingest-signals.d.ts.map +1 -1
  118. package/dist/runtime-api/handlers/ingest-signals.js +1 -0
  119. package/dist/runtime-api/handlers/ingest-signals.js.map +1 -1
  120. package/dist/runtime-api/handlers/types.d.ts +5 -0
  121. package/dist/runtime-api/handlers/types.d.ts.map +1 -1
  122. package/dist/runtime-api/intake/ingest-request.d.ts +17 -0
  123. package/dist/runtime-api/intake/ingest-request.d.ts.map +1 -0
  124. package/dist/runtime-api/intake/ingest-request.js +34 -0
  125. package/dist/runtime-api/intake/ingest-request.js.map +1 -0
  126. package/dist/runtime-api/intake/intake-events.d.ts +1 -1
  127. package/dist/runtime-api/intake/intake-events.d.ts.map +1 -1
  128. package/dist/runtime-api/intake/intake-events.js +9 -3
  129. package/dist/runtime-api/intake/intake-events.js.map +1 -1
  130. package/dist/runtime-api/intake/intake-mount.d.ts.map +1 -1
  131. package/dist/runtime-api/intake/intake-mount.js +4 -19
  132. package/dist/runtime-api/intake/intake-mount.js.map +1 -1
  133. package/dist/runtime-api/intake/process-error-post.d.ts +6 -1
  134. package/dist/runtime-api/intake/process-error-post.d.ts.map +1 -1
  135. package/dist/runtime-api/intake/process-error-post.js +5 -1
  136. package/dist/runtime-api/intake/process-error-post.js.map +1 -1
  137. package/dist/runtime-api/intake/process-signal-post.d.ts +7 -1
  138. package/dist/runtime-api/intake/process-signal-post.d.ts.map +1 -1
  139. package/dist/runtime-api/intake/process-signal-post.js +5 -0
  140. package/dist/runtime-api/intake/process-signal-post.js.map +1 -1
  141. package/dist/runtime-api/intake/scaffold-error-router.js.map +1 -1
  142. package/dist/runtime-api/intake/scaffold-tick-router.d.ts +39 -0
  143. package/dist/runtime-api/intake/scaffold-tick-router.d.ts.map +1 -0
  144. package/dist/runtime-api/intake/scaffold-tick-router.js +122 -0
  145. package/dist/runtime-api/intake/scaffold-tick-router.js.map +1 -0
  146. package/dist/runtime-api/intake/scanner-launcher.d.ts.map +1 -1
  147. package/dist/runtime-api/intake/scanner-launcher.js +15 -0
  148. package/dist/runtime-api/intake/scanner-launcher.js.map +1 -1
  149. package/dist/runtime-api/intake/types.d.ts +55 -0
  150. package/dist/runtime-api/intake/types.d.ts.map +1 -1
  151. package/dist/runtime-api/routes/signals.d.ts +2 -0
  152. package/dist/runtime-api/routes/signals.d.ts.map +1 -1
  153. package/dist/runtime-api/routes/signals.js +5 -1
  154. package/dist/runtime-api/routes/signals.js.map +1 -1
  155. package/dist/runtime-api/routes/signals.schema.d.ts +43 -0
  156. package/dist/runtime-api/routes/signals.schema.d.ts.map +1 -1
  157. package/dist/runtime-api/routes/signals.schema.js +43 -0
  158. package/dist/runtime-api/routes/signals.schema.js.map +1 -1
  159. package/dist/runtime-api/server.d.ts +7 -1
  160. package/dist/runtime-api/server.d.ts.map +1 -1
  161. package/dist/runtime-api/server.js +1 -0
  162. package/dist/runtime-api/server.js.map +1 -1
  163. package/dist/scanners/engine/engine.d.ts +22 -1
  164. package/dist/scanners/engine/engine.d.ts.map +1 -1
  165. package/dist/scanners/engine/engine.js +78 -11
  166. package/dist/scanners/engine/engine.js.map +1 -1
  167. package/dist/scanners/engine/lifecycle.d.ts +7 -1
  168. package/dist/scanners/engine/lifecycle.d.ts.map +1 -1
  169. package/dist/scanners/events.d.ts +4 -0
  170. package/dist/scanners/events.d.ts.map +1 -1
  171. package/dist/scanners/events.js +2 -0
  172. package/dist/scanners/events.js.map +1 -1
  173. package/dist/scanners/external/scaffold/delivery.py +194 -25
  174. package/dist/scanners/external/scaffold/scaffold.py +172 -31
  175. package/dist/scanners/external/scaffold/senpi_mcp.py +150 -8
  176. package/dist/scanners/external/scaffold/tick_facts.py +130 -0
  177. package/dist/scanners/external/scaffold/ulid.py +58 -0
  178. package/dist/scanners/external-scanner-receiver.d.ts +17 -0
  179. package/dist/scanners/external-scanner-receiver.d.ts.map +1 -1
  180. package/dist/scanners/external-scanner-receiver.js +8 -0
  181. package/dist/scanners/external-scanner-receiver.js.map +1 -1
  182. package/dist/scanners/runtime-module.d.ts +1 -0
  183. package/dist/scanners/runtime-module.d.ts.map +1 -1
  184. package/dist/scanners/runtime-module.js +66 -9
  185. package/dist/scanners/runtime-module.js.map +1 -1
  186. package/dist/telemetry/attributes.d.ts +20 -0
  187. package/dist/telemetry/attributes.d.ts.map +1 -1
  188. package/dist/telemetry/attributes.js +24 -0
  189. package/dist/telemetry/attributes.js.map +1 -1
  190. package/dist/telemetry/dsl-positions.d.ts +111 -0
  191. package/dist/telemetry/dsl-positions.d.ts.map +1 -0
  192. package/dist/telemetry/dsl-positions.js +118 -0
  193. package/dist/telemetry/dsl-positions.js.map +1 -0
  194. package/dist/telemetry/event-builders.d.ts +81 -6
  195. package/dist/telemetry/event-builders.d.ts.map +1 -1
  196. package/dist/telemetry/event-builders.js +141 -17
  197. package/dist/telemetry/event-builders.js.map +1 -1
  198. package/dist/telemetry/event-store.d.ts +6 -0
  199. package/dist/telemetry/event-store.d.ts.map +1 -1
  200. package/dist/telemetry/event-store.js +12 -8
  201. package/dist/telemetry/event-store.js.map +1 -1
  202. package/dist/telemetry/live-telemetry.d.ts +257 -0
  203. package/dist/telemetry/live-telemetry.d.ts.map +1 -0
  204. package/dist/telemetry/live-telemetry.js +959 -0
  205. package/dist/telemetry/live-telemetry.js.map +1 -0
  206. package/dist/telemetry/metrics.d.ts +14 -2
  207. package/dist/telemetry/metrics.d.ts.map +1 -1
  208. package/dist/telemetry/metrics.js +19 -4
  209. package/dist/telemetry/metrics.js.map +1 -1
  210. package/dist/telemetry/scanner-stats.d.ts +143 -0
  211. package/dist/telemetry/scanner-stats.d.ts.map +1 -0
  212. package/dist/telemetry/scanner-stats.js +426 -0
  213. package/dist/telemetry/scanner-stats.js.map +1 -0
  214. package/dist/telemetry/scanner-tick-feed.d.ts +87 -0
  215. package/dist/telemetry/scanner-tick-feed.d.ts.map +1 -0
  216. package/dist/telemetry/scanner-tick-feed.js +48 -0
  217. package/dist/telemetry/scanner-tick-feed.js.map +1 -0
  218. package/dist/telemetry/spans/redact-pii.d.ts.map +1 -1
  219. package/dist/telemetry/spans/redact-pii.js +18 -2
  220. package/dist/telemetry/spans/redact-pii.js.map +1 -1
  221. package/dist/telemetry/strategy-topology.d.ts +99 -0
  222. package/dist/telemetry/strategy-topology.d.ts.map +1 -0
  223. package/dist/telemetry/strategy-topology.js +93 -0
  224. package/dist/telemetry/strategy-topology.js.map +1 -0
  225. package/dist/telemetry/telemetry-publisher.d.ts +83 -0
  226. package/dist/telemetry/telemetry-publisher.d.ts.map +1 -0
  227. package/dist/telemetry/telemetry-publisher.js +256 -0
  228. package/dist/telemetry/telemetry-publisher.js.map +1 -0
  229. package/dist/telemetry/tick-frame.d.ts +212 -0
  230. package/dist/telemetry/tick-frame.d.ts.map +1 -0
  231. package/dist/telemetry/tick-frame.js +421 -0
  232. package/dist/telemetry/tick-frame.js.map +1 -0
  233. package/dist/telemetry/timeline-buffer.d.ts +95 -0
  234. package/dist/telemetry/timeline-buffer.d.ts.map +1 -0
  235. package/dist/telemetry/timeline-buffer.js +237 -0
  236. package/dist/telemetry/timeline-buffer.js.map +1 -0
  237. package/dist/telemetry/tracing.d.ts +9 -0
  238. package/dist/telemetry/tracing.d.ts.map +1 -1
  239. package/dist/telemetry/tracing.js +36 -0
  240. package/dist/telemetry/tracing.js.map +1 -1
  241. package/dist/types/dsl/index.d.ts +48 -0
  242. package/dist/types/dsl/index.d.ts.map +1 -1
  243. package/dist/types/scanner.d.ts +15 -0
  244. package/dist/types/scanner.d.ts.map +1 -1
  245. package/dist/utils/event-catalog.d.ts +202 -0
  246. package/dist/utils/event-catalog.d.ts.map +1 -1
  247. package/dist/utils/event-catalog.js +26 -0
  248. package/dist/utils/event-catalog.js.map +1 -1
  249. package/dist/utils/logger.d.ts +4 -1
  250. package/dist/utils/logger.d.ts.map +1 -1
  251. package/dist/utils/logger.js.map +1 -1
  252. package/dist/utils/telemetry-required-log.d.ts +60 -0
  253. package/dist/utils/telemetry-required-log.d.ts.map +1 -0
  254. package/dist/utils/telemetry-required-log.js +105 -0
  255. package/dist/utils/telemetry-required-log.js.map +1 -0
  256. package/dist/utils/ulid.d.ts +9 -0
  257. package/dist/utils/ulid.d.ts.map +1 -0
  258. package/dist/utils/ulid.js +43 -0
  259. package/dist/utils/ulid.js.map +1 -0
  260. package/dist/validate/recipe-checks.d.ts.map +1 -1
  261. package/dist/validate/recipe-checks.js +2 -2
  262. package/dist/validate/recipe-checks.js.map +1 -1
  263. package/openclaw.plugin.json +1 -1
  264. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -64,7 +64,11 @@ import { createIntakeContext } from "./runtime-api/intake/intake-context.js";
64
64
  import { wireRuntime, intakeUrlFor, selectScanners } from "./runtime-api/intake/intake-mount.js";
65
65
  import { ingestDispatchMutex, ingestDispatchKey } from "./runtime-api/intake/ingest-mutex.js";
66
66
  import { buildScaffoldErrorRouter } from "./runtime-api/intake/scaffold-error-router.js";
67
+ import { buildScaffoldTickRouter } from "./runtime-api/intake/scaffold-tick-router.js";
68
+ import { toIngestRequest } from "./runtime-api/intake/ingest-request.js";
67
69
  import { loadRuntimeConfig } from "./runtime/load-runtime-config.js";
70
+ import { createLiveTelemetry } from "./telemetry/live-telemetry.js";
71
+ import { resolveTickTelemetry } from "./telemetry/tick-frame.js";
68
72
  /** Initialize all core features (DSL, risk, health) on the given event bus. */
69
73
  export function initCore(bus) {
70
74
  initDsl(bus);
@@ -223,6 +227,16 @@ const senpiRuntimePlugin = {
223
227
  ? "env SENPI_LOG_LEVEL"
224
228
  : "default";
225
229
  pluginLogger.info(`[senpi-runtime] log level: ${startupLogLevel} (source: ${logLevelSourceLabel}). Set plugin config "logLevel" or env SENPI_LOG_LEVEL to debug|info|warn|error to override.`);
230
+ // Same shape as the log-level line above, and for the same reason: a box publishing less than
231
+ // an operator expects must say so at boot rather than be diagnosed from an empty screen. No env
232
+ // var is named because there is none — see `tickTelemetry` on SenpiRuntimePluginConfig.
233
+ const tickTelemetry = resolveTickTelemetry(config.tickTelemetry);
234
+ if (tickTelemetry.invalid !== undefined) {
235
+ pluginLogger.warn(`[senpi-runtime] Ignoring invalid plugin config ${tickTelemetry.invalid} (expected off|summary|verbose); keeping mcp=${tickTelemetry.settings.mcp} state=${tickTelemetry.settings.state}.`);
236
+ }
237
+ pluginLogger.info(tickTelemetry.settings.enabled
238
+ ? `[senpi-runtime] tick telemetry: mcp=${tickTelemetry.settings.mcp} state=${tickTelemetry.settings.state} (source: ${config.tickTelemetry === undefined ? "default" : "plugin config tickTelemetry"}). Set plugin config "tickTelemetry" to off|summary|verbose, or {mcp,state}, to override.`
239
+ : `[senpi-runtime] tick telemetry: off (source: plugin config tickTelemetry). No per-tick frame is published.`);
226
240
  const senpiCliStore = readSenpiCliStore();
227
241
  const baseStateDir = resolveSenpiBaseStateDir({
228
242
  store: senpiCliStore,
@@ -355,6 +369,7 @@ const senpiRuntimePlugin = {
355
369
  }
356
370
  let routeAcceptedSignalToRuntime;
357
371
  let routeScaffoldErrorToRuntime;
372
+ let routeScaffoldTickToTelemetry;
358
373
  const launchers = new Map();
359
374
  // Runtimes that are UP but whose external scanners never wired (mount/launch/install
360
375
  // failure), keyed runtimeId → failed phase. Populated at the four unwired sites,
@@ -382,10 +397,168 @@ const senpiRuntimePlugin = {
382
397
  * engines, one margin account: the exact state `[E_WALLET_HAS_RUNTIME]` exists to prevent.
383
398
  */
384
399
  const installsInFlight = new Map();
400
+ // ── Live telemetry ────────────────────────────────────────────────
401
+ // Every runtime this box knows about, running or not, keyed runtimeId. The topology payload has
402
+ // to name a stopped strategy too, so this is populated from the registry rather than from
403
+ // `runtimeHandles` (which holds only the live ones) and is the source of the two facts the
404
+ // registry entry does not carry: the strategy's display name and its declared scanners. Both come
405
+ // from the parsed YAML — `name` is the same `config.name` that `RuntimeHealthStatus.runtimeName`
406
+ // is built from, so a runtime whose config never parsed falls back to its id rather than to a
407
+ // guess, and its scanner list stays empty rather than inventing rows.
408
+ const telemetryStrategies = new Map();
409
+ const noteTelemetryRuntime = (runtimeId, address) => {
410
+ const existing = telemetryStrategies.get(runtimeId);
411
+ telemetryStrategies.set(runtimeId, {
412
+ address,
413
+ name: existing?.name ?? runtimeId,
414
+ scanners: existing?.scanners ?? [],
415
+ });
416
+ };
417
+ const noteTelemetryRuntimeConfig = (runtimeId, config) => {
418
+ telemetryStrategies.set(runtimeId, {
419
+ address: config.strategy?.wallet ?? telemetryStrategies.get(runtimeId)?.address ?? "",
420
+ name: config.name,
421
+ scanners: config.scanners ?? [],
422
+ });
423
+ };
385
424
  // Dedicated logger for the runtime-api subtree — required because the
386
425
  // PluginLogger surface (info/warn/error) lacks `debug`, while the
387
426
  // Logger contract used by `runtime-api/` includes it.
388
427
  const apiLogger = createLogger("[senpi-core][api]");
428
+ /**
429
+ * One gather per publish tick. Health and system state are read together because the two payloads
430
+ * need both: the topology reads health and `runtimeName`, the stats read the per-scanner rows,
431
+ * and `restartCount` / `degradedReason` live only on the health rows while every other scanner
432
+ * field lives only on the system-state rows — so they are joined here on `(runtimeId, scannerId)`.
433
+ */
434
+ const collectTelemetryFacts = async () => {
435
+ const [statuses, states] = await Promise.all([
436
+ collectRuntimeHealthStatuses(runtimeHandles, api.logger),
437
+ collectRuntimeSystemStates(runtimeHandles, api.logger, baseStateDir),
438
+ ]);
439
+ const healthByRuntime = new Map();
440
+ for (const status of statuses) {
441
+ if (status.runtimeId !== undefined)
442
+ healthByRuntime.set(status.runtimeId, status);
443
+ }
444
+ const scannerState = [];
445
+ // Registration facts per (runtimeId, scannerId), so the topology can report a scanner's live
446
+ // schedule rather than only what its YAML declared.
447
+ const registrations = new Map();
448
+ for (const state of states) {
449
+ const runtimeId = state.runtimeId;
450
+ const healthRows = runtimeId === undefined
451
+ ? []
452
+ : healthByRuntime.get(runtimeId)?.components.scanners.scanners ?? [];
453
+ for (const row of state.components.scanners.state.scanners) {
454
+ const supervision = healthRows.find((r) => r.scannerId === row.scannerId);
455
+ const snapshot = {
456
+ address: row.address,
457
+ scannerId: row.scannerId,
458
+ health: row.health,
459
+ degradedReason: supervision?.degradedReason ?? null,
460
+ enabled: row.enabled,
461
+ inFlightSince: row.inFlightSince,
462
+ lastRunStartedAt: row.lastRunStartedAt,
463
+ lastRunFinishedAt: row.lastRunFinishedAt,
464
+ lastRunStatus: row.lastRunStatus,
465
+ lastRunReason: row.lastRunReason,
466
+ nextRunAt: row.nextRunAt,
467
+ lastAliveAt: row.lastAliveAt,
468
+ // No supervision row means the restart count is unknown, not zero. A zero here would
469
+ // read as "this scanner has never restarted" on a scanner nobody is supervising.
470
+ restartCount: supervision?.restartCount ?? null,
471
+ };
472
+ scannerState.push(snapshot);
473
+ if (runtimeId !== undefined) {
474
+ registrations.set(`${runtimeId}::${row.scannerId}`, {
475
+ ...snapshot,
476
+ scheduleMode: row.scheduleMode,
477
+ configVersion: row.configVersion,
478
+ intervalSeconds: row.intervalSeconds,
479
+ });
480
+ }
481
+ }
482
+ }
483
+ const strategies = [];
484
+ for (const [runtimeId, entry] of telemetryStrategies) {
485
+ const health = healthByRuntime.get(runtimeId);
486
+ const scanners = entry.scanners.map((declared) => {
487
+ const live = registrations.get(`${runtimeId}::${declared.name}`);
488
+ return live === undefined
489
+ ? { entry: declared }
490
+ : {
491
+ entry: declared,
492
+ registration: {
493
+ enabled: live.enabled,
494
+ scheduleMode: live.scheduleMode,
495
+ // The engine's own cadence, which is what the scanner actually polls on — a
496
+ // recipe may omit it and take the scanner definition's default. An external
497
+ // scanner registers zero because it is POSTed to rather than polled, and only
498
+ // the recipe knows the cadence its scaffold was told to tick at.
499
+ intervalSeconds: live.intervalSeconds > 0 ? live.intervalSeconds : declared.interval_seconds ?? null,
500
+ configVersion: live.configVersion,
501
+ },
502
+ };
503
+ });
504
+ strategies.push({
505
+ runtimeId,
506
+ address: entry.address,
507
+ // `runtimeName` is built from the same `config.name`; the indexed value is used because it
508
+ // is available for a stopped runtime too, where there is no health status to read.
509
+ name: health?.runtimeName ?? entry.name,
510
+ scanners,
511
+ });
512
+ }
513
+ // The DSL states, read straight off each runtime's plugin. Synchronous and in-memory — this is
514
+ // the same store the `senpi.listDslPositions` RPC reads — so it costs the gather nothing, and a
515
+ // recipe with no DSL exit block has no plugin and contributes no rows. A runtime whose read
516
+ // throws is skipped rather than failing the whole gather, on the same rule health follows: a
517
+ // strategy mid-teardown must not take the stream down.
518
+ const dslPositions = [];
519
+ for (const [runtimeId, handle] of runtimeHandles) {
520
+ if (!handle.dsl)
521
+ continue;
522
+ try {
523
+ for (const state of handle.dsl.listActiveDslStates()) {
524
+ dslPositions.push({ runtimeId, state });
525
+ }
526
+ }
527
+ catch (err) {
528
+ api.logger.warn("[senpi-runtime] could not read DSL states for telemetry", { runtimeId, err });
529
+ }
530
+ }
531
+ return {
532
+ strategies,
533
+ runningRuntimeIds: runtimeHandles,
534
+ unwiredRuntimeIds: unwiredRuntimes,
535
+ readHealth: (runtimeId) => healthByRuntime.get(runtimeId),
536
+ scannerState,
537
+ dslPositions,
538
+ };
539
+ };
540
+ const liveTelemetry = createLiveTelemetry({
541
+ collectFacts: collectTelemetryFacts,
542
+ tickTelemetry: config.tickTelemetry,
543
+ });
544
+ /**
545
+ * Wrapped gateway methods capture the broadcast handle on the FIRST request to ANY of them —
546
+ * not only on subscribe. `ctx.context` is the only route to the websocket push layer and it
547
+ * exists only inside a handler, so capturing it in the subscribe method alone would mean a box
548
+ * whose client never subscribes can never publish anything, silently.
549
+ *
550
+ * The wrapper covers only what is registered through it. `senpi.deploy.start`,
551
+ * `senpi.deploy.status` and `senpi.update` are registered straight onto the plugin api by their
552
+ * own registrars and never arm the handle. That is not a gap in practice: one wrapped call arms
553
+ * it for the life of the process, and the websocket client admits `senpi.telemetry.subscribe`,
554
+ * which is wrapped.
555
+ */
556
+ const registerGatewayMethod = (name, handler, opts) => {
557
+ api.registerGatewayMethod(name, (ctx) => {
558
+ liveTelemetry.captureBroadcast(ctx, name);
559
+ return handler(ctx);
560
+ }, opts);
561
+ };
389
562
  // A gateway seam failed to wire/launch a runtime's external scanner stack: the runtime is up but
390
563
  // runs blind on internal scanners only. Two records, by design: a first-class `runtime.scanners_unwired`
391
564
  // event (the queryable/alertable fact, by phase) and the migrated exception-form `logger.error`
@@ -493,8 +666,7 @@ const senpiRuntimePlugin = {
493
666
  // ── lifecycle reaper ─────────────────────────────────────────────────────────────────────────
494
667
  // A runtime exists iff its strategy is open. Every close path ends at the backend and none of
495
668
  // them tells this box, so the reaper asks: once after boot, hourly, and whenever the backend
496
- // rejects an order with STRATEGY_NOT_ACTIVE. Enforcing by default since the 3.0.121 observe-only
497
- // validation; SENPI_REAPER_ENFORCE=false returns a box to observe-only (see
669
+ // rejects an order with STRATEGY_NOT_ACTIVE. Observe-only unless enforcement is on (see
498
670
  // runtime/lifecycle-reaper.ts for the safety rule). Constructed here so both `run()` call sites
499
671
  // (boot and install) can hand it their not-active rejections; it does no I/O until started.
500
672
  const reaperBootDelayOverride = resolveReaperBootDelayMs(process.env);
@@ -560,26 +732,14 @@ const senpiRuntimePlugin = {
560
732
  // /signals will not be mounted and no signals will be routed.
561
733
  if (sharedIntakeContext) {
562
734
  const ctx = sharedIntakeContext;
563
- routeAcceptedSignalToRuntime = (signal, _correlationId, scannerId) => {
735
+ routeAcceptedSignalToRuntime = (signal, correlationId, scannerId) => {
564
736
  const resolved = ctx.registry.resolve(scannerId);
565
737
  if (!resolved)
566
738
  return;
567
739
  const h = runtimeHandles.get(resolved.runtimeId);
568
740
  if (!h)
569
741
  return;
570
- const request = {
571
- scanner: resolved.scannerName,
572
- signal_id: signal.signal_id, // greppable handle across intake→ingest (obs only)
573
- asset: signal.asset,
574
- direction: signal.direction,
575
- ...(signal.signal_type !== undefined && { signal_type: signal.signal_type }),
576
- data: signal.data,
577
- // Per-signal sizing rides at the top level; the open-position action
578
- // reads request.marginPct / request.leverage directly. Without this a
579
- // supervised signal's sizing is lost ("no margin source resolved").
580
- ...(signal.marginPct !== undefined && { marginPct: signal.marginPct }),
581
- ...(signal.leverage !== undefined && { leverage: signal.leverage }),
582
- };
742
+ const request = toIngestRequest(signal, correlationId, resolved.scannerName);
583
743
  // Trace the sizing-relevant fields the narrowed request carries, so a
584
744
  // field dropped at this seam is visible instead of vanishing silently.
585
745
  apiLogger.debug(`[intake] ingest req signal_id=${signal.signal_id} scanner=${resolved.scannerName} asset=${signal.asset} direction=${signal.direction} marginPct=${signal.marginPct} leverage=${signal.leverage}`);
@@ -599,15 +759,18 @@ const senpiRuntimePlugin = {
599
759
  // The single server-level onError closure — the `/errors` counterpart of
600
760
  // routeAcceptedSignalToRuntime. It records a scaffold-reported tick failure into
601
761
  // the owning runtime's scanner telemetry so a scanner that fails every tick stops
602
- // rendering "healthy".
762
+ // rendering "healthy". Filter: only tick-level failure types count — a
763
+ // `candidate_rejected` body is a per-candidate reject on an otherwise-OK tick, not
764
+ // a failed run.
603
765
  //
604
- // This is the SHARED implementation (scaffold-error-router.ts), not a copy of
605
- // buildIntakeMount's onScaffoldError. It used to be a copy, and the copy had its
606
- // own hardcoded three-type filter: when `mcp_error` was added to the tick-failure
607
- // list it reached the tested seam and never reached this route, so the
608
- // wedged-scanner signal was green in CI and inert in production. There is now one
609
- // filter, and scaffold-error-router.test.ts drives THIS closure.
766
+ // This is the SHARED implementation (scaffold-error-router.ts), so this route and
767
+ // buildIntakeMount's onScaffoldError apply one filter, and scaffold-error-router.test.ts
768
+ // drives THIS closure.
610
769
  routeScaffoldErrorToRuntime = buildScaffoldErrorRouter(ctx, runtimeHandles);
770
+ // The per-tick level for a supervised external scanner. Both intake routes call it, so a
771
+ // quiet tick and a failed tick are equally visible; it needs no runtime handle because it
772
+ // publishes a level rather than recording a run.
773
+ routeScaffoldTickToTelemetry = buildScaffoldTickRouter(ctx);
611
774
  }
612
775
  // One bounded read: which registered wallets the platform says are dead, so a restart does
613
776
  // not re-scaffold runtimes on closed wallets (fail-open — see runtime/boot-skip.ts).
@@ -659,6 +822,9 @@ const senpiRuntimePlugin = {
659
822
  continue;
660
823
  const pathOrContent = entry.runtimeYamlPath ?? entry.runtimeYamlContent;
661
824
  const entryStateDir = buildRuntimeStateDir(baseStateDir, entry.id, entry.wallet ?? "");
825
+ // Indexed before the boot attempt: a runtime whose start throws is installed but stopped,
826
+ // and the telemetry topology has to be able to say so.
827
+ noteTelemetryRuntime(entry.id, entry.wallet ?? "");
662
828
  const handle = await run(pathOrContent, {
663
829
  fromPath: hasPath,
664
830
  stateDir: entryStateDir,
@@ -682,6 +848,7 @@ const senpiRuntimePlugin = {
682
848
  if (sharedIntakeContext) {
683
849
  try {
684
850
  const runtimeConfig = await loadRuntimeConfig(pathOrContent, { fromPath: hasPath });
851
+ noteTelemetryRuntimeConfig(entry.id, runtimeConfig);
685
852
  // Content-installed runtimes carry their recipe dir in the registry
686
853
  // entry (runtimeYamlDir) so relative scanner paths still resolve
687
854
  // after a restart; path-installed ones derive it from the path.
@@ -733,6 +900,7 @@ const senpiRuntimePlugin = {
733
900
  // event) so listRuntimes/health don't render a bare "running".
734
901
  try {
735
902
  const runtimeConfig = await loadRuntimeConfig(pathOrContent, { fromPath: hasPath });
903
+ noteTelemetryRuntimeConfig(entry.id, runtimeConfig);
736
904
  if (selectScanners(runtimeConfig).length > 0) {
737
905
  unwiredRuntimes.set(entry.id, "no_intake");
738
906
  handle.attachSupervisionSource(() => ({
@@ -791,6 +959,7 @@ const senpiRuntimePlugin = {
791
959
  intakeContext: sharedIntakeContext,
792
960
  onAccepted: routeAcceptedSignalToRuntime,
793
961
  onError: routeScaffoldErrorToRuntime,
962
+ onTick: routeScaffoldTickToTelemetry,
794
963
  });
795
964
  apiHandle.ready();
796
965
  }
@@ -834,6 +1003,12 @@ const senpiRuntimePlugin = {
834
1003
  }
835
1004
  }
836
1005
  }
1006
+ // Publish ticks start only once the runtimes are up, so the first frames describe a real
1007
+ // box. Gated by the same switch the skills coordinator uses: unit tests boot `register()`
1008
+ // and must not acquire background timers. The subscribe method still answers without them.
1009
+ if (process.env.SENPI_RUNTIME_API_DISABLED !== "true") {
1010
+ liveTelemetry.start();
1011
+ }
837
1012
  // Last, once everything above is up: the reaper's post-boot pass and hourly sweep. Its
838
1013
  // not-active escalation is also off until here, so no delete can land while the boot loop is
839
1014
  // still wiring runtimes and launchers. Nothing here may fail start() — a throw from inside the boot loop takes every runtime down, which
@@ -851,6 +1026,11 @@ const senpiRuntimePlugin = {
851
1026
  }
852
1027
  },
853
1028
  async stop() {
1029
+ // Live telemetry goes first: it owns a timer and an in-memory buffer, nothing downstream
1030
+ // depends on it, and stopping it here guarantees no publish tick reads a half-torn-down
1031
+ // runtime handle. Records emitted during the teardown below land in a buffer nobody drains,
1032
+ // which is the right trade for a process on its way out.
1033
+ liveTelemetry.stop();
854
1034
  // Stop the reaper first so no pass starts deleting while the runtimes are torn down below,
855
1035
  // and wait (bounded) for a pass already under way, so its delete cannot stop a handle the
856
1036
  // teardown below is stopping too.
@@ -1190,6 +1370,10 @@ const senpiRuntimePlugin = {
1190
1370
  onStrategyNotActive: (address) => reaper.checkWallet(address),
1191
1371
  });
1192
1372
  runtimeHandles.set(resolvedId, handle);
1373
+ if (parsedConfig)
1374
+ noteTelemetryRuntimeConfig(resolvedId, parsedConfig);
1375
+ else
1376
+ noteTelemetryRuntime(resolvedId, wallet);
1193
1377
  // Registry create fact — distinct from the runtime.started boot transition (which also fires
1194
1378
  // on a transient restart). Emitted inside emitEvent's guard so telemetry never fails the install.
1195
1379
  emitEvent(apiLogger, () => buildRuntimeCreatedEvent({ runtimeId: resolvedId, address: wallet, recipeName: runtimeName }));
@@ -1302,7 +1486,7 @@ const senpiRuntimePlugin = {
1302
1486
  }
1303
1487
  }
1304
1488
  /** Gateway respond accepts (ok, payload?, error?) with error as { code, message }; plugin SDK types may omit the third arg. */
1305
- api.registerGatewayMethod("senpi.installRuntime", async (ctx) => {
1489
+ registerGatewayMethod("senpi.installRuntime", async (ctx) => {
1306
1490
  const respond = ctx.respond;
1307
1491
  const result = await installRuntimeCore(ctx.params);
1308
1492
  if (result.ok)
@@ -1310,7 +1494,7 @@ const senpiRuntimePlugin = {
1310
1494
  else
1311
1495
  respond(false, undefined, result.error);
1312
1496
  }, { scope: "operator.write" });
1313
- api.registerGatewayMethod("senpi.listRuntimes", async (ctx) => {
1497
+ registerGatewayMethod("senpi.listRuntimes", async (ctx) => {
1314
1498
  const respond = ctx.respond;
1315
1499
  const { readRegistry } = await import("./runtime/strategy-registry.js");
1316
1500
  const registry = await readRegistry(baseStateDir);
@@ -1453,6 +1637,9 @@ const senpiRuntimePlugin = {
1453
1637
  // "running — NO ENTRY SCANNERS" forever. The map is otherwise only cleared on a
1454
1638
  // successful wire/install, which a scanner-less reinstall never reaches.
1455
1639
  unwiredRuntimes.delete(targetId);
1640
+ // Same reuse hazard: a deleted id left in the index would keep publishing a strategy that no
1641
+ // longer exists, and would hand a reinstall the old name and scanner list.
1642
+ telemetryStrategies.delete(targetId);
1456
1643
  bootSkippedRuntimes.delete(targetId);
1457
1644
  // Archive state directory before removing from registry
1458
1645
  if (deletedEntry) {
@@ -1483,7 +1670,7 @@ const senpiRuntimePlugin = {
1483
1670
  }));
1484
1671
  return { ok: true, payload: { id: targetId } };
1485
1672
  }
1486
- api.registerGatewayMethod("senpi.deleteRuntime", async (ctx) => {
1673
+ registerGatewayMethod("senpi.deleteRuntime", async (ctx) => {
1487
1674
  const respond = ctx.respond;
1488
1675
  const result = await deleteRuntimeCore(ctx.params);
1489
1676
  if (result.ok)
@@ -1590,6 +1777,17 @@ const senpiRuntimePlugin = {
1590
1777
  return checkProofCoversRecipe(packageDir, verifyProof(packageDir), appliedRecipe, (f) => readFileSync(f, "utf8"));
1591
1778
  },
1592
1779
  applyToRuntime: makeApplyToRuntime(runtimeHandles, async (runtimeId, next, recipe) => {
1780
+ // Re-index the topology facts FIRST, ahead of every early return and every failure path
1781
+ // below. `makeApplyToRuntime` only reaches this callback once the in-process swap has
1782
+ // succeeded, so `next` is already the recipe this box runs: its display name and its
1783
+ // declared scanner list are the ones the topology payload must name. Leaving the index on
1784
+ // the previous config would publish strategy rows the new scanner stats cannot join to.
1785
+ //
1786
+ // Ahead of the early return because an apply on a box with no intake still swapped the
1787
+ // recipe, and ahead of the launcher because a launcher that fails is a runtime running the
1788
+ // new recipe with no external scanners — the degraded state a dashboard most needs to show,
1789
+ // and one it can only render if the declared scanners are the new ones.
1790
+ noteTelemetryRuntimeConfig(runtimeId, next);
1593
1791
  // Restart this runtime's external scanner children against the new package.
1594
1792
  //
1595
1793
  // The rebuild swaps in-process components; these are separate OS processes, spawned once
@@ -1737,7 +1935,7 @@ const senpiRuntimePlugin = {
1737
1935
  * producers — slated for removal in Task 5 once the migration counter
1738
1936
  * decays to zero (see `runtime-phase-2-api-plan.md` Section 8).
1739
1937
  */
1740
- api.registerGatewayMethod("senpi.ingestExternalScannerData", async (ctx) => {
1938
+ registerGatewayMethod("senpi.ingestExternalScannerData", async (ctx) => {
1741
1939
  const respond = ctx.respond;
1742
1940
  // TODO(s11): wire actual telemetry counter for
1743
1941
  // runtime.deprecated_gateway_ingest_call (event name, properties:
@@ -1756,6 +1954,7 @@ const senpiRuntimePlugin = {
1756
1954
  ...(request.direction !== undefined && { direction: request.direction }),
1757
1955
  ...(request.score !== undefined && { score: request.score }),
1758
1956
  ...(request.signal_type !== undefined && { signal_type: request.signal_type }),
1957
+ ...(request.tick_id !== undefined && { tick_id: request.tick_id }),
1759
1958
  ...(request.data !== undefined && { data: request.data }),
1760
1959
  ...(request.signals !== undefined && { signals: request.signals }),
1761
1960
  };
@@ -1813,7 +2012,7 @@ const senpiRuntimePlugin = {
1813
2012
  });
1814
2013
  }
1815
2014
  }, { scope: "operator.write" });
1816
- api.registerGatewayMethod("senpi.listDslPositions", async (ctx) => {
2015
+ registerGatewayMethod("senpi.listDslPositions", async (ctx) => {
1817
2016
  const respond = ctx.respond;
1818
2017
  const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
1819
2018
  const address = typeof ctx.params?.address === "string" ? ctx.params.address : undefined;
@@ -1838,7 +2037,7 @@ const senpiRuntimePlugin = {
1838
2037
  }
1839
2038
  respond(true, { positions });
1840
2039
  }, { scope: "operator.read" });
1841
- api.registerGatewayMethod("senpi.getDslPositionState", async (ctx) => {
2040
+ registerGatewayMethod("senpi.getDslPositionState", async (ctx) => {
1842
2041
  const respond = ctx.respond;
1843
2042
  const asset = typeof ctx.params?.asset === "string" ? ctx.params.asset : undefined;
1844
2043
  if (!asset) {
@@ -1879,7 +2078,7 @@ const senpiRuntimePlugin = {
1879
2078
  }
1880
2079
  respond(true, { positions: matches });
1881
2080
  }, { scope: "operator.read" });
1882
- api.registerGatewayMethod("senpi.listDslArchives", async (ctx) => {
2081
+ registerGatewayMethod("senpi.listDslArchives", async (ctx) => {
1883
2082
  const respond = ctx.respond;
1884
2083
  const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
1885
2084
  const address = typeof ctx.params?.address === "string" ? ctx.params.address : undefined;
@@ -1905,7 +2104,7 @@ const senpiRuntimePlugin = {
1905
2104
  closes = closes.slice(0, limit);
1906
2105
  respond(true, { closes });
1907
2106
  }, { scope: "operator.read" });
1908
- api.registerGatewayMethod("senpi.getHealthStatus", async (ctx) => {
2107
+ registerGatewayMethod("senpi.getHealthStatus", async (ctx) => {
1909
2108
  const respond = ctx.respond;
1910
2109
  const updater = autoUpdateCoordinator.getSnapshot();
1911
2110
  const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
@@ -1933,7 +2132,7 @@ const senpiRuntimePlugin = {
1933
2132
  const statuses = await collectRuntimeHealthStatuses(runtimeHandles, api.logger);
1934
2133
  respond(true, { statuses, updater });
1935
2134
  }, { scope: "operator.read" });
1936
- api.registerGatewayMethod("senpi.getSystemState", async (ctx) => {
2135
+ registerGatewayMethod("senpi.getSystemState", async (ctx) => {
1937
2136
  const respond = ctx.respond;
1938
2137
  const updater = autoUpdateCoordinator.getSnapshot();
1939
2138
  const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
@@ -2000,6 +2199,36 @@ const senpiRuntimePlugin = {
2000
2199
  });
2001
2200
  }
2002
2201
  }, { scope: "operator.write" });
2202
+ /**
2203
+ * Live telemetry — the one method of the stream, called once per connect.
2204
+ *
2205
+ * It returns the current value of all three broadcast payloads plus the recent record window, so
2206
+ * a client joining a box that has been running for hours renders a full screen immediately
2207
+ * instead of waiting for the next thing to happen. `(afterEpoch, afterSeq)` resumes a client that
2208
+ * already holds part of this epoch's run — a cursor naming any other epoch is dropped, because a
2209
+ * seq from a previous run cannot address these records. `truncated` says when the records between
2210
+ * a cursor of this epoch and the oldest record still held are gone, which nothing in `recent`
2211
+ * alone can express.
2212
+ *
2213
+ * Read-only, like every other inspection method here. The scope that decides who RECEIVES the
2214
+ * broadcasts is a property of the client's own connection, not of this method.
2215
+ */
2216
+ registerGatewayMethod("senpi.telemetry.subscribe", async (ctx) => {
2217
+ const respond = ctx.respond;
2218
+ try {
2219
+ respond(true, await liveTelemetry.snapshot({
2220
+ afterEpoch: ctx.params?.afterEpoch,
2221
+ afterSeq: ctx.params?.afterSeq,
2222
+ }));
2223
+ }
2224
+ catch (err) {
2225
+ api.logger.warn("[senpi-runtime] telemetry subscribe error", { err });
2226
+ respond(false, undefined, {
2227
+ code: "INTERNAL_ERROR",
2228
+ message: `Failed to build the telemetry snapshot: ${formatGatewayError(err)}`,
2229
+ });
2230
+ }
2231
+ }, { scope: "operator.read" });
2003
2232
  /**
2004
2233
  * Action layer — read-only inspection.
2005
2234
  *
@@ -2019,7 +2248,7 @@ const senpiRuntimePlugin = {
2019
2248
  * persisted action-store machinery (`src/actions/store/`) usable
2020
2249
  * from the operator-facing CLI again.
2021
2250
  */
2022
- api.registerGatewayMethod("senpi.listActions", async (ctx) => {
2251
+ registerGatewayMethod("senpi.listActions", async (ctx) => {
2023
2252
  const respond = ctx.respond;
2024
2253
  const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
2025
2254
  const address = typeof ctx.params?.address === "string" ? ctx.params.address : undefined;
@@ -2049,7 +2278,7 @@ const senpiRuntimePlugin = {
2049
2278
  }
2050
2279
  respond(true, { actions: merged });
2051
2280
  }, { scope: "operator.read" });
2052
- api.registerGatewayMethod("senpi.getActionState", async (ctx) => {
2281
+ registerGatewayMethod("senpi.getActionState", async (ctx) => {
2053
2282
  const respond = ctx.respond;
2054
2283
  const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
2055
2284
  const actionName = typeof ctx.params?.actionName === "string" ? ctx.params.actionName : undefined;
@@ -2086,7 +2315,7 @@ const senpiRuntimePlugin = {
2086
2315
  });
2087
2316
  }
2088
2317
  }, { scope: "operator.read" });
2089
- api.registerGatewayMethod("senpi.getActionHistory", async (ctx) => {
2318
+ registerGatewayMethod("senpi.getActionHistory", async (ctx) => {
2090
2319
  const respond = ctx.respond;
2091
2320
  const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
2092
2321
  const actionName = typeof ctx.params?.actionName === "string" ? ctx.params.actionName : undefined;
@@ -2154,7 +2383,7 @@ const senpiRuntimePlugin = {
2154
2383
  // reachable on HTTP `/audit`. Passes through the caller-controlled subset
2155
2384
  // of the audit_query contract; resource scoping (wallet → strategyId) is
2156
2385
  // owned by handle.auditQuery, never the caller.
2157
- api.registerGatewayMethod("senpi.auditQuery", async (ctx) => {
2386
+ registerGatewayMethod("senpi.auditQuery", async (ctx) => {
2158
2387
  const respond = ctx.respond;
2159
2388
  const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
2160
2389
  if (!runtimeId) {
@@ -2202,7 +2431,7 @@ const senpiRuntimePlugin = {
2202
2431
  // its state root private, so re-derive it from baseStateDir + the handle's
2203
2432
  // wallet (same helper the writer's stateDir was built with); the writer
2204
2433
  // nests entries under `<root>/<address>/risk-guard/audit.jsonl`.
2205
- api.registerGatewayMethod("senpi.getRiskAudit", async (ctx) => {
2434
+ registerGatewayMethod("senpi.getRiskAudit", async (ctx) => {
2206
2435
  const respond = ctx.respond;
2207
2436
  const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
2208
2437
  if (!runtimeId) {
@@ -2245,7 +2474,7 @@ const senpiRuntimePlugin = {
2245
2474
  // Per-strategy local domain-event ring (on-disk JSONL) — the trade narrative, queryable locally.
2246
2475
  // Same state-root re-derivation as getRiskAudit: the Runtime keeps its root private, so rebuild it
2247
2476
  // from baseStateDir + the handle's wallet; the writer nests rows under `<root>/strategies/<address>/events/`.
2248
- api.registerGatewayMethod("senpi.getEvents", async (ctx) => {
2477
+ registerGatewayMethod("senpi.getEvents", async (ctx) => {
2249
2478
  const respond = ctx.respond;
2250
2479
  const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
2251
2480
  if (!runtimeId) {
@@ -2302,12 +2531,12 @@ const senpiRuntimePlugin = {
2302
2531
  }
2303
2532
  }, { scope: "operator.read" });
2304
2533
  // ─── Skills manager — read + mutate ──────────────────────────────────────
2305
- api.registerGatewayMethod("senpi.skills.status", async (ctx) => {
2534
+ registerGatewayMethod("senpi.skills.status", async (ctx) => {
2306
2535
  const respond = ctx.respond;
2307
2536
  const snapshot = skillsCoordinator.getSnapshot();
2308
2537
  respond(true, { snapshot });
2309
2538
  }, { scope: "operator.read" });
2310
- api.registerGatewayMethod("senpi.skills.update", async (ctx) => {
2539
+ registerGatewayMethod("senpi.skills.update", async (ctx) => {
2311
2540
  const respond = ctx.respond;
2312
2541
  const name = typeof ctx.params?.name === "string" ? ctx.params.name.trim() : undefined;
2313
2542
  if (!name) {
@@ -2332,7 +2561,7 @@ const senpiRuntimePlugin = {
2332
2561
  });
2333
2562
  }
2334
2563
  }, { scope: "operator.write" });
2335
- api.registerGatewayMethod("senpi.skills.updateAll", async (ctx) => {
2564
+ registerGatewayMethod("senpi.skills.updateAll", async (ctx) => {
2336
2565
  const respond = ctx.respond;
2337
2566
  try {
2338
2567
  const results = await skillsCoordinator.updateAll();
@@ -2398,6 +2627,7 @@ function parseGatewayExternalScannerIngestParams(params) {
2398
2627
  direction: params?.direction,
2399
2628
  score: params?.score,
2400
2629
  signal_type: params?.signal_type,
2630
+ tick_id: params?.tick_id,
2401
2631
  data: params?.data,
2402
2632
  signals: params?.signals,
2403
2633
  },