@senpi-ai/runtime 3.0.133 → 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.
- package/README.md +8 -0
- package/dist/actions/action-events.d.ts +21 -7
- package/dist/actions/action-events.d.ts.map +1 -1
- package/dist/actions/action-events.js +54 -26
- package/dist/actions/action-events.js.map +1 -1
- package/dist/actions/action-runtime-module.d.ts.map +1 -1
- package/dist/actions/action-runtime-module.js +38 -7
- package/dist/actions/action-runtime-module.js.map +1 -1
- package/dist/actions/close-position/close-position.action.d.ts.map +1 -1
- package/dist/actions/close-position/close-position.action.js +122 -15
- package/dist/actions/close-position/close-position.action.js.map +1 -1
- package/dist/actions/decision-engine.d.ts.map +1 -1
- package/dist/actions/decision-engine.js +15 -2
- package/dist/actions/decision-engine.js.map +1 -1
- package/dist/actions/event-derivation.d.ts +71 -2
- package/dist/actions/event-derivation.d.ts.map +1 -1
- package/dist/actions/event-derivation.js +251 -8
- package/dist/actions/event-derivation.js.map +1 -1
- package/dist/actions/open-position/open-position.action.d.ts +12 -2
- package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
- package/dist/actions/open-position/open-position.action.js +141 -41
- package/dist/actions/open-position/open-position.action.js.map +1 -1
- package/dist/actions/position-tracker/position-tracker.action.d.ts +2 -1
- package/dist/actions/position-tracker/position-tracker.action.d.ts.map +1 -1
- package/dist/actions/position-tracker/position-tracker.action.js +62 -17
- package/dist/actions/position-tracker/position-tracker.action.js.map +1 -1
- package/dist/actions/skipped-signal-results.d.ts +25 -0
- package/dist/actions/skipped-signal-results.d.ts.map +1 -0
- package/dist/actions/skipped-signal-results.js +71 -0
- package/dist/actions/skipped-signal-results.js.map +1 -0
- package/dist/actions/store/types.d.ts +9 -2
- package/dist/actions/store/types.d.ts.map +1 -1
- package/dist/actions/store/types.js.map +1 -1
- package/dist/actions/types.d.ts +13 -0
- package/dist/actions/types.d.ts.map +1 -1
- package/dist/actions/types.js +13 -0
- package/dist/actions/types.js.map +1 -1
- package/dist/cli/guide-commands.d.ts.map +1 -1
- package/dist/cli/guide-commands.js +16 -0
- package/dist/cli/guide-commands.js.map +1 -1
- package/dist/cli/senpi-commands.d.ts.map +1 -1
- package/dist/cli/senpi-commands.js +88 -0
- package/dist/cli/senpi-commands.js.map +1 -1
- package/dist/constants/dsl/index.d.ts +6 -0
- package/dist/constants/dsl/index.d.ts.map +1 -1
- package/dist/constants/dsl/index.js +6 -0
- package/dist/constants/dsl/index.js.map +1 -1
- package/dist/dsl/engine-client/event-mapping.d.ts.map +1 -1
- package/dist/dsl/engine-client/event-mapping.js +14 -0
- package/dist/dsl/engine-client/event-mapping.js.map +1 -1
- package/dist/dsl/events/build-closed-event.d.ts +16 -1
- package/dist/dsl/events/build-closed-event.d.ts.map +1 -1
- package/dist/dsl/events/build-closed-event.js +6 -0
- package/dist/dsl/events/build-closed-event.js.map +1 -1
- package/dist/dsl/events/handlers.d.ts +7 -0
- package/dist/dsl/events/handlers.d.ts.map +1 -1
- package/dist/dsl/events/handlers.js +37 -7
- package/dist/dsl/events/handlers.js.map +1 -1
- package/dist/dsl/monitor/create-monitor.d.ts +6 -2
- package/dist/dsl/monitor/create-monitor.d.ts.map +1 -1
- package/dist/dsl/monitor/create-monitor.js +82 -9
- package/dist/dsl/monitor/create-monitor.js.map +1 -1
- package/dist/dsl/monitor/dsl-failure-events.d.ts +45 -2
- package/dist/dsl/monitor/dsl-failure-events.d.ts.map +1 -1
- package/dist/dsl/monitor/dsl-failure-events.js +52 -3
- package/dist/dsl/monitor/dsl-failure-events.js.map +1 -1
- package/dist/dsl/monitor/process-one-position.d.ts +1 -0
- package/dist/dsl/monitor/process-one-position.d.ts.map +1 -1
- package/dist/dsl/monitor/process-one-position.js +159 -36
- package/dist/dsl/monitor/process-one-position.js.map +1 -1
- package/dist/dsl/plugin/index.d.ts +8 -2
- package/dist/dsl/plugin/index.d.ts.map +1 -1
- package/dist/dsl/plugin/index.js +8 -6
- package/dist/dsl/plugin/index.js.map +1 -1
- package/dist/health/types.d.ts +13 -0
- package/dist/health/types.d.ts.map +1 -1
- package/dist/health/types.js +12 -0
- package/dist/health/types.js.map +1 -1
- package/dist/index.d.ts +27 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +310 -41
- package/dist/index.js.map +1 -1
- package/dist/runtime/action-registry.d.ts.map +1 -1
- package/dist/runtime/action-registry.js +4 -3
- package/dist/runtime/action-registry.js.map +1 -1
- package/dist/runtime/auto-update/coordinator.d.ts +24 -1
- package/dist/runtime/auto-update/coordinator.d.ts.map +1 -1
- package/dist/runtime/auto-update/coordinator.js +123 -13
- package/dist/runtime/auto-update/coordinator.js.map +1 -1
- package/dist/runtime/auto-update/resolve-package-name.d.ts +15 -0
- package/dist/runtime/auto-update/resolve-package-name.d.ts.map +1 -1
- package/dist/runtime/auto-update/resolve-package-name.js +35 -0
- package/dist/runtime/auto-update/resolve-package-name.js.map +1 -1
- package/dist/runtime/auto-update/run-update-command.d.ts.map +1 -1
- package/dist/runtime/auto-update/run-update-command.js +17 -14
- package/dist/runtime/auto-update/run-update-command.js.map +1 -1
- package/dist/runtime/auto-update/types.d.ts +24 -0
- package/dist/runtime/auto-update/types.d.ts.map +1 -1
- package/dist/runtime/auto-update/types.js.map +1 -1
- package/dist/runtime/domain-events.d.ts.map +1 -1
- package/dist/runtime/domain-events.js +7 -0
- package/dist/runtime/domain-events.js.map +1 -1
- package/dist/runtime/lifecycle-events.d.ts +15 -3
- package/dist/runtime/lifecycle-events.d.ts.map +1 -1
- package/dist/runtime/lifecycle-events.js +17 -3
- package/dist/runtime/lifecycle-events.js.map +1 -1
- package/dist/runtime/lifecycle-reaper.d.ts +4 -6
- package/dist/runtime/lifecycle-reaper.d.ts.map +1 -1
- package/dist/runtime/lifecycle-reaper.js +4 -6
- package/dist/runtime/lifecycle-reaper.js.map +1 -1
- package/dist/runtime/reconcile-run.d.ts +13 -3
- package/dist/runtime/reconcile-run.d.ts.map +1 -1
- package/dist/runtime/reconcile-run.js +4 -3
- package/dist/runtime/reconcile-run.js.map +1 -1
- package/dist/runtime/reconcile-state.d.ts +8 -0
- package/dist/runtime/reconcile-state.d.ts.map +1 -1
- package/dist/runtime/reconcile-state.js +4 -1
- package/dist/runtime/reconcile-state.js.map +1 -1
- package/dist/runtime/run.d.ts +1 -0
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js.map +1 -1
- package/dist/runtime/runtime-schema.js +3 -3
- package/dist/runtime/runtime-schema.js.map +1 -1
- package/dist/runtime/runtime.d.ts +1 -0
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +28 -4
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/supervisor/long-running-supervisor.d.ts +13 -0
- package/dist/runtime/supervisor/long-running-supervisor.d.ts.map +1 -1
- package/dist/runtime/supervisor/long-running-supervisor.js +1 -0
- package/dist/runtime/supervisor/long-running-supervisor.js.map +1 -1
- package/dist/runtime/validate-dsl-position-tracking.d.ts.map +1 -1
- package/dist/runtime/validate-dsl-position-tracking.js +2 -1
- package/dist/runtime/validate-dsl-position-tracking.js.map +1 -1
- package/dist/runtime-api/handlers/ingest-signals.d.ts.map +1 -1
- package/dist/runtime-api/handlers/ingest-signals.js +1 -0
- package/dist/runtime-api/handlers/ingest-signals.js.map +1 -1
- package/dist/runtime-api/handlers/types.d.ts +5 -0
- package/dist/runtime-api/handlers/types.d.ts.map +1 -1
- package/dist/runtime-api/intake/ingest-request.d.ts +17 -0
- package/dist/runtime-api/intake/ingest-request.d.ts.map +1 -0
- package/dist/runtime-api/intake/ingest-request.js +34 -0
- package/dist/runtime-api/intake/ingest-request.js.map +1 -0
- package/dist/runtime-api/intake/intake-events.d.ts +1 -1
- package/dist/runtime-api/intake/intake-events.d.ts.map +1 -1
- package/dist/runtime-api/intake/intake-events.js +9 -3
- package/dist/runtime-api/intake/intake-events.js.map +1 -1
- package/dist/runtime-api/intake/intake-mount.d.ts.map +1 -1
- package/dist/runtime-api/intake/intake-mount.js +4 -19
- package/dist/runtime-api/intake/intake-mount.js.map +1 -1
- package/dist/runtime-api/intake/process-error-post.d.ts +6 -1
- package/dist/runtime-api/intake/process-error-post.d.ts.map +1 -1
- package/dist/runtime-api/intake/process-error-post.js +5 -1
- package/dist/runtime-api/intake/process-error-post.js.map +1 -1
- package/dist/runtime-api/intake/process-signal-post.d.ts +7 -1
- package/dist/runtime-api/intake/process-signal-post.d.ts.map +1 -1
- package/dist/runtime-api/intake/process-signal-post.js +5 -0
- package/dist/runtime-api/intake/process-signal-post.js.map +1 -1
- package/dist/runtime-api/intake/scaffold-error-router.js.map +1 -1
- package/dist/runtime-api/intake/scaffold-tick-router.d.ts +39 -0
- package/dist/runtime-api/intake/scaffold-tick-router.d.ts.map +1 -0
- package/dist/runtime-api/intake/scaffold-tick-router.js +122 -0
- package/dist/runtime-api/intake/scaffold-tick-router.js.map +1 -0
- package/dist/runtime-api/intake/scanner-launcher.d.ts.map +1 -1
- package/dist/runtime-api/intake/scanner-launcher.js +15 -0
- package/dist/runtime-api/intake/scanner-launcher.js.map +1 -1
- package/dist/runtime-api/intake/types.d.ts +55 -0
- package/dist/runtime-api/intake/types.d.ts.map +1 -1
- package/dist/runtime-api/routes/signals.d.ts +2 -0
- package/dist/runtime-api/routes/signals.d.ts.map +1 -1
- package/dist/runtime-api/routes/signals.js +5 -1
- package/dist/runtime-api/routes/signals.js.map +1 -1
- package/dist/runtime-api/routes/signals.schema.d.ts +43 -0
- package/dist/runtime-api/routes/signals.schema.d.ts.map +1 -1
- package/dist/runtime-api/routes/signals.schema.js +43 -0
- package/dist/runtime-api/routes/signals.schema.js.map +1 -1
- package/dist/runtime-api/server.d.ts +7 -1
- package/dist/runtime-api/server.d.ts.map +1 -1
- package/dist/runtime-api/server.js +1 -0
- package/dist/runtime-api/server.js.map +1 -1
- package/dist/scanners/engine/engine.d.ts +22 -1
- package/dist/scanners/engine/engine.d.ts.map +1 -1
- package/dist/scanners/engine/engine.js +78 -11
- package/dist/scanners/engine/engine.js.map +1 -1
- package/dist/scanners/engine/lifecycle.d.ts +7 -1
- package/dist/scanners/engine/lifecycle.d.ts.map +1 -1
- package/dist/scanners/events.d.ts +4 -0
- package/dist/scanners/events.d.ts.map +1 -1
- package/dist/scanners/events.js +2 -0
- package/dist/scanners/events.js.map +1 -1
- package/dist/scanners/external/scaffold/delivery.py +194 -25
- package/dist/scanners/external/scaffold/scaffold.py +172 -31
- package/dist/scanners/external/scaffold/senpi_mcp.py +150 -8
- package/dist/scanners/external/scaffold/tick_facts.py +130 -0
- package/dist/scanners/external/scaffold/ulid.py +58 -0
- package/dist/scanners/external-scanner-receiver.d.ts +17 -0
- package/dist/scanners/external-scanner-receiver.d.ts.map +1 -1
- package/dist/scanners/external-scanner-receiver.js +8 -0
- package/dist/scanners/external-scanner-receiver.js.map +1 -1
- package/dist/scanners/runtime-module.d.ts +1 -0
- package/dist/scanners/runtime-module.d.ts.map +1 -1
- package/dist/scanners/runtime-module.js +66 -9
- package/dist/scanners/runtime-module.js.map +1 -1
- package/dist/telemetry/attributes.d.ts +20 -0
- package/dist/telemetry/attributes.d.ts.map +1 -1
- package/dist/telemetry/attributes.js +24 -0
- package/dist/telemetry/attributes.js.map +1 -1
- package/dist/telemetry/dsl-positions.d.ts +111 -0
- package/dist/telemetry/dsl-positions.d.ts.map +1 -0
- package/dist/telemetry/dsl-positions.js +118 -0
- package/dist/telemetry/dsl-positions.js.map +1 -0
- package/dist/telemetry/event-builders.d.ts +81 -6
- package/dist/telemetry/event-builders.d.ts.map +1 -1
- package/dist/telemetry/event-builders.js +141 -17
- package/dist/telemetry/event-builders.js.map +1 -1
- package/dist/telemetry/event-store.d.ts +6 -0
- package/dist/telemetry/event-store.d.ts.map +1 -1
- package/dist/telemetry/event-store.js +12 -8
- package/dist/telemetry/event-store.js.map +1 -1
- package/dist/telemetry/live-telemetry.d.ts +257 -0
- package/dist/telemetry/live-telemetry.d.ts.map +1 -0
- package/dist/telemetry/live-telemetry.js +959 -0
- package/dist/telemetry/live-telemetry.js.map +1 -0
- package/dist/telemetry/metrics.d.ts +14 -2
- package/dist/telemetry/metrics.d.ts.map +1 -1
- package/dist/telemetry/metrics.js +19 -4
- package/dist/telemetry/metrics.js.map +1 -1
- package/dist/telemetry/scanner-stats.d.ts +143 -0
- package/dist/telemetry/scanner-stats.d.ts.map +1 -0
- package/dist/telemetry/scanner-stats.js +426 -0
- package/dist/telemetry/scanner-stats.js.map +1 -0
- package/dist/telemetry/scanner-tick-feed.d.ts +87 -0
- package/dist/telemetry/scanner-tick-feed.d.ts.map +1 -0
- package/dist/telemetry/scanner-tick-feed.js +48 -0
- package/dist/telemetry/scanner-tick-feed.js.map +1 -0
- package/dist/telemetry/spans/redact-pii.d.ts.map +1 -1
- package/dist/telemetry/spans/redact-pii.js +18 -2
- package/dist/telemetry/spans/redact-pii.js.map +1 -1
- package/dist/telemetry/strategy-topology.d.ts +99 -0
- package/dist/telemetry/strategy-topology.d.ts.map +1 -0
- package/dist/telemetry/strategy-topology.js +93 -0
- package/dist/telemetry/strategy-topology.js.map +1 -0
- package/dist/telemetry/telemetry-publisher.d.ts +83 -0
- package/dist/telemetry/telemetry-publisher.d.ts.map +1 -0
- package/dist/telemetry/telemetry-publisher.js +256 -0
- package/dist/telemetry/telemetry-publisher.js.map +1 -0
- package/dist/telemetry/tick-frame.d.ts +212 -0
- package/dist/telemetry/tick-frame.d.ts.map +1 -0
- package/dist/telemetry/tick-frame.js +421 -0
- package/dist/telemetry/tick-frame.js.map +1 -0
- package/dist/telemetry/timeline-buffer.d.ts +95 -0
- package/dist/telemetry/timeline-buffer.d.ts.map +1 -0
- package/dist/telemetry/timeline-buffer.js +237 -0
- package/dist/telemetry/timeline-buffer.js.map +1 -0
- package/dist/telemetry/tracing.d.ts +9 -0
- package/dist/telemetry/tracing.d.ts.map +1 -1
- package/dist/telemetry/tracing.js +36 -0
- package/dist/telemetry/tracing.js.map +1 -1
- package/dist/types/dsl/index.d.ts +48 -0
- package/dist/types/dsl/index.d.ts.map +1 -1
- package/dist/types/scanner.d.ts +15 -0
- package/dist/types/scanner.d.ts.map +1 -1
- package/dist/utils/event-catalog.d.ts +202 -0
- package/dist/utils/event-catalog.d.ts.map +1 -1
- package/dist/utils/event-catalog.js +26 -0
- package/dist/utils/event-catalog.js.map +1 -1
- package/dist/utils/logger.d.ts +4 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/telemetry-required-log.d.ts +60 -0
- package/dist/utils/telemetry-required-log.d.ts.map +1 -0
- package/dist/utils/telemetry-required-log.js +105 -0
- package/dist/utils/telemetry-required-log.js.map +1 -0
- package/dist/utils/ulid.d.ts +9 -0
- package/dist/utils/ulid.d.ts.map +1 -0
- package/dist/utils/ulid.js +43 -0
- package/dist/utils/ulid.js.map +1 -0
- package/dist/validate/recipe-checks.d.ts.map +1 -1
- package/dist/validate/recipe-checks.js +2 -2
- package/dist/validate/recipe-checks.js.map +1 -1
- package/openclaw.plugin.json +4 -4
- 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.
|
|
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,
|
|
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),
|
|
605
|
-
// buildIntakeMount's onScaffoldError
|
|
606
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -1961,6 +2160,75 @@ const senpiRuntimePlugin = {
|
|
|
1961
2160
|
const states = await collectRuntimeSystemStates(runtimeHandles, api.logger, baseStateDir);
|
|
1962
2161
|
respond(true, { states, updater });
|
|
1963
2162
|
}, { scope: "operator.read" });
|
|
2163
|
+
/**
|
|
2164
|
+
* Force the auto-update poll to run now instead of waiting for its timer.
|
|
2165
|
+
*
|
|
2166
|
+
* `operator.write`, not `operator.read`: a forced check can install a new
|
|
2167
|
+
* package version and request a gateway restart. The scope is passed
|
|
2168
|
+
* explicitly because a method registered without one falls back to
|
|
2169
|
+
* `operator.admin`, which the bridge cannot present.
|
|
2170
|
+
*
|
|
2171
|
+
* The coordinator itself decides whether a cycle actually ran; the whole
|
|
2172
|
+
* result is passed through — never re-spread field by field, which drops
|
|
2173
|
+
* anything later added to it — with the post-run snapshot alongside, so the
|
|
2174
|
+
* caller can see what happened and when the next check is due.
|
|
2175
|
+
*
|
|
2176
|
+
* A `disabled` outcome answers `ok: false` / `UNAVAILABLE`, matching
|
|
2177
|
+
* `senpi.skills.update` on the same condition: nothing ran, so a caller that
|
|
2178
|
+
* branches on `ok` must not record the call as a successful check.
|
|
2179
|
+
*/
|
|
2180
|
+
api.registerGatewayMethod("senpi.autoUpdate.checkNow", async (ctx) => {
|
|
2181
|
+
const respond = ctx.respond;
|
|
2182
|
+
try {
|
|
2183
|
+
const result = await autoUpdateCoordinator.checkNow();
|
|
2184
|
+
pluginLogger.info("[senpi-runtime] senpi.autoUpdate.checkNow", { outcome: result.outcome });
|
|
2185
|
+
if (result.outcome === "disabled") {
|
|
2186
|
+
respond(false, undefined, { code: "UNAVAILABLE", message: result.reason });
|
|
2187
|
+
return;
|
|
2188
|
+
}
|
|
2189
|
+
respond(true, {
|
|
2190
|
+
...result,
|
|
2191
|
+
updater: autoUpdateCoordinator.getSnapshot(),
|
|
2192
|
+
});
|
|
2193
|
+
}
|
|
2194
|
+
catch (err) {
|
|
2195
|
+
api.logger.warn("[senpi-runtime] autoUpdate.checkNow error", { err });
|
|
2196
|
+
respond(false, undefined, {
|
|
2197
|
+
code: "INTERNAL_ERROR",
|
|
2198
|
+
message: `Failed to force an auto-update check: ${formatGatewayError(err)}`,
|
|
2199
|
+
});
|
|
2200
|
+
}
|
|
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" });
|
|
1964
2232
|
/**
|
|
1965
2233
|
* Action layer — read-only inspection.
|
|
1966
2234
|
*
|
|
@@ -1980,7 +2248,7 @@ const senpiRuntimePlugin = {
|
|
|
1980
2248
|
* persisted action-store machinery (`src/actions/store/`) usable
|
|
1981
2249
|
* from the operator-facing CLI again.
|
|
1982
2250
|
*/
|
|
1983
|
-
|
|
2251
|
+
registerGatewayMethod("senpi.listActions", async (ctx) => {
|
|
1984
2252
|
const respond = ctx.respond;
|
|
1985
2253
|
const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
|
|
1986
2254
|
const address = typeof ctx.params?.address === "string" ? ctx.params.address : undefined;
|
|
@@ -2010,7 +2278,7 @@ const senpiRuntimePlugin = {
|
|
|
2010
2278
|
}
|
|
2011
2279
|
respond(true, { actions: merged });
|
|
2012
2280
|
}, { scope: "operator.read" });
|
|
2013
|
-
|
|
2281
|
+
registerGatewayMethod("senpi.getActionState", async (ctx) => {
|
|
2014
2282
|
const respond = ctx.respond;
|
|
2015
2283
|
const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
|
|
2016
2284
|
const actionName = typeof ctx.params?.actionName === "string" ? ctx.params.actionName : undefined;
|
|
@@ -2047,7 +2315,7 @@ const senpiRuntimePlugin = {
|
|
|
2047
2315
|
});
|
|
2048
2316
|
}
|
|
2049
2317
|
}, { scope: "operator.read" });
|
|
2050
|
-
|
|
2318
|
+
registerGatewayMethod("senpi.getActionHistory", async (ctx) => {
|
|
2051
2319
|
const respond = ctx.respond;
|
|
2052
2320
|
const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
|
|
2053
2321
|
const actionName = typeof ctx.params?.actionName === "string" ? ctx.params.actionName : undefined;
|
|
@@ -2115,7 +2383,7 @@ const senpiRuntimePlugin = {
|
|
|
2115
2383
|
// reachable on HTTP `/audit`. Passes through the caller-controlled subset
|
|
2116
2384
|
// of the audit_query contract; resource scoping (wallet → strategyId) is
|
|
2117
2385
|
// owned by handle.auditQuery, never the caller.
|
|
2118
|
-
|
|
2386
|
+
registerGatewayMethod("senpi.auditQuery", async (ctx) => {
|
|
2119
2387
|
const respond = ctx.respond;
|
|
2120
2388
|
const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
|
|
2121
2389
|
if (!runtimeId) {
|
|
@@ -2163,7 +2431,7 @@ const senpiRuntimePlugin = {
|
|
|
2163
2431
|
// its state root private, so re-derive it from baseStateDir + the handle's
|
|
2164
2432
|
// wallet (same helper the writer's stateDir was built with); the writer
|
|
2165
2433
|
// nests entries under `<root>/<address>/risk-guard/audit.jsonl`.
|
|
2166
|
-
|
|
2434
|
+
registerGatewayMethod("senpi.getRiskAudit", async (ctx) => {
|
|
2167
2435
|
const respond = ctx.respond;
|
|
2168
2436
|
const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
|
|
2169
2437
|
if (!runtimeId) {
|
|
@@ -2206,7 +2474,7 @@ const senpiRuntimePlugin = {
|
|
|
2206
2474
|
// Per-strategy local domain-event ring (on-disk JSONL) — the trade narrative, queryable locally.
|
|
2207
2475
|
// Same state-root re-derivation as getRiskAudit: the Runtime keeps its root private, so rebuild it
|
|
2208
2476
|
// from baseStateDir + the handle's wallet; the writer nests rows under `<root>/strategies/<address>/events/`.
|
|
2209
|
-
|
|
2477
|
+
registerGatewayMethod("senpi.getEvents", async (ctx) => {
|
|
2210
2478
|
const respond = ctx.respond;
|
|
2211
2479
|
const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
|
|
2212
2480
|
if (!runtimeId) {
|
|
@@ -2263,12 +2531,12 @@ const senpiRuntimePlugin = {
|
|
|
2263
2531
|
}
|
|
2264
2532
|
}, { scope: "operator.read" });
|
|
2265
2533
|
// ─── Skills manager — read + mutate ──────────────────────────────────────
|
|
2266
|
-
|
|
2534
|
+
registerGatewayMethod("senpi.skills.status", async (ctx) => {
|
|
2267
2535
|
const respond = ctx.respond;
|
|
2268
2536
|
const snapshot = skillsCoordinator.getSnapshot();
|
|
2269
2537
|
respond(true, { snapshot });
|
|
2270
2538
|
}, { scope: "operator.read" });
|
|
2271
|
-
|
|
2539
|
+
registerGatewayMethod("senpi.skills.update", async (ctx) => {
|
|
2272
2540
|
const respond = ctx.respond;
|
|
2273
2541
|
const name = typeof ctx.params?.name === "string" ? ctx.params.name.trim() : undefined;
|
|
2274
2542
|
if (!name) {
|
|
@@ -2293,7 +2561,7 @@ const senpiRuntimePlugin = {
|
|
|
2293
2561
|
});
|
|
2294
2562
|
}
|
|
2295
2563
|
}, { scope: "operator.write" });
|
|
2296
|
-
|
|
2564
|
+
registerGatewayMethod("senpi.skills.updateAll", async (ctx) => {
|
|
2297
2565
|
const respond = ctx.respond;
|
|
2298
2566
|
try {
|
|
2299
2567
|
const results = await skillsCoordinator.updateAll();
|
|
@@ -2359,6 +2627,7 @@ function parseGatewayExternalScannerIngestParams(params) {
|
|
|
2359
2627
|
direction: params?.direction,
|
|
2360
2628
|
score: params?.score,
|
|
2361
2629
|
signal_type: params?.signal_type,
|
|
2630
|
+
tick_id: params?.tick_id,
|
|
2362
2631
|
data: params?.data,
|
|
2363
2632
|
signals: params?.signals,
|
|
2364
2633
|
},
|