@senpi-ai/runtime 3.0.179 → 3.0.188

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 (163) hide show
  1. package/dist/actions/llm-decision/openclaw-llm-decision.d.ts +8 -0
  2. package/dist/actions/llm-decision/openclaw-llm-decision.d.ts.map +1 -1
  3. package/dist/actions/llm-decision/openclaw-llm-decision.js +56 -1
  4. package/dist/actions/llm-decision/openclaw-llm-decision.js.map +1 -1
  5. package/dist/approvals/approval-store.d.ts +37 -7
  6. package/dist/approvals/approval-store.d.ts.map +1 -1
  7. package/dist/approvals/approval-store.js +127 -23
  8. package/dist/approvals/approval-store.js.map +1 -1
  9. package/dist/approvals/telemetry.d.ts +28 -3
  10. package/dist/approvals/telemetry.d.ts.map +1 -1
  11. package/dist/approvals/telemetry.js +8 -4
  12. package/dist/approvals/telemetry.js.map +1 -1
  13. package/dist/approvals/tool-approval-gate.d.ts +85 -0
  14. package/dist/approvals/tool-approval-gate.d.ts.map +1 -1
  15. package/dist/approvals/tool-approval-gate.js +197 -15
  16. package/dist/approvals/tool-approval-gate.js.map +1 -1
  17. package/dist/approvals/turn-context.d.ts +296 -0
  18. package/dist/approvals/turn-context.d.ts.map +1 -0
  19. package/dist/approvals/turn-context.js +594 -0
  20. package/dist/approvals/turn-context.js.map +1 -0
  21. package/dist/cli/guide-commands.d.ts.map +1 -1
  22. package/dist/cli/guide-commands.js +18 -3
  23. package/dist/cli/guide-commands.js.map +1 -1
  24. package/dist/cli/senpi-commands.d.ts.map +1 -1
  25. package/dist/cli/senpi-commands.js +80 -5
  26. package/dist/cli/senpi-commands.js.map +1 -1
  27. package/dist/deploy/job.d.ts +32 -0
  28. package/dist/deploy/job.d.ts.map +1 -1
  29. package/dist/deploy/job.js +72 -7
  30. package/dist/deploy/job.js.map +1 -1
  31. package/dist/deploy/register.d.ts +12 -0
  32. package/dist/deploy/register.d.ts.map +1 -1
  33. package/dist/deploy/register.js +85 -2
  34. package/dist/deploy/register.js.map +1 -1
  35. package/dist/dsl/monitor/dsl-failure-events.d.ts +38 -2
  36. package/dist/dsl/monitor/dsl-failure-events.d.ts.map +1 -1
  37. package/dist/dsl/monitor/dsl-failure-events.js +67 -4
  38. package/dist/dsl/monitor/dsl-failure-events.js.map +1 -1
  39. package/dist/dsl/monitor/process-one-position.d.ts.map +1 -1
  40. package/dist/dsl/monitor/process-one-position.js +25 -1
  41. package/dist/dsl/monitor/process-one-position.js.map +1 -1
  42. package/dist/host/openclaw-host.d.ts +138 -0
  43. package/dist/host/openclaw-host.d.ts.map +1 -0
  44. package/dist/host/openclaw-host.js +177 -0
  45. package/dist/host/openclaw-host.js.map +1 -0
  46. package/dist/host/plugin-logger.d.ts +99 -0
  47. package/dist/host/plugin-logger.d.ts.map +1 -0
  48. package/dist/host/plugin-logger.js +142 -0
  49. package/dist/host/plugin-logger.js.map +1 -0
  50. package/dist/index.d.ts +56 -7
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +695 -161
  53. package/dist/index.js.map +1 -1
  54. package/dist/runtime/auto-update/coordinator.d.ts +220 -0
  55. package/dist/runtime/auto-update/coordinator.d.ts.map +1 -1
  56. package/dist/runtime/auto-update/coordinator.js +715 -22
  57. package/dist/runtime/auto-update/coordinator.js.map +1 -1
  58. package/dist/runtime/auto-update/gateway-restart.d.ts +60 -1
  59. package/dist/runtime/auto-update/gateway-restart.d.ts.map +1 -1
  60. package/dist/runtime/auto-update/gateway-restart.js +95 -21
  61. package/dist/runtime/auto-update/gateway-restart.js.map +1 -1
  62. package/dist/runtime/auto-update/idle-gate.d.ts +175 -0
  63. package/dist/runtime/auto-update/idle-gate.d.ts.map +1 -0
  64. package/dist/runtime/auto-update/idle-gate.js +229 -0
  65. package/dist/runtime/auto-update/idle-gate.js.map +1 -0
  66. package/dist/runtime/auto-update/install-results.d.ts +130 -0
  67. package/dist/runtime/auto-update/install-results.d.ts.map +1 -0
  68. package/dist/runtime/auto-update/install-results.js +264 -0
  69. package/dist/runtime/auto-update/install-results.js.map +1 -0
  70. package/dist/runtime/auto-update/money-call-tracker.d.ts +36 -0
  71. package/dist/runtime/auto-update/money-call-tracker.d.ts.map +1 -0
  72. package/dist/runtime/auto-update/money-call-tracker.js +129 -0
  73. package/dist/runtime/auto-update/money-call-tracker.js.map +1 -0
  74. package/dist/runtime/auto-update/register-idle-gate.d.ts +70 -0
  75. package/dist/runtime/auto-update/register-idle-gate.d.ts.map +1 -0
  76. package/dist/runtime/auto-update/register-idle-gate.js +127 -0
  77. package/dist/runtime/auto-update/register-idle-gate.js.map +1 -0
  78. package/dist/runtime/auto-update/run-update-command.d.ts +13 -0
  79. package/dist/runtime/auto-update/run-update-command.d.ts.map +1 -1
  80. package/dist/runtime/auto-update/run-update-command.js +18 -0
  81. package/dist/runtime/auto-update/run-update-command.js.map +1 -1
  82. package/dist/runtime/auto-update/state-store.d.ts +14 -1
  83. package/dist/runtime/auto-update/state-store.d.ts.map +1 -1
  84. package/dist/runtime/auto-update/state-store.js +37 -3
  85. package/dist/runtime/auto-update/state-store.js.map +1 -1
  86. package/dist/runtime/auto-update/types.d.ts +52 -0
  87. package/dist/runtime/auto-update/types.d.ts.map +1 -1
  88. package/dist/runtime/auto-update/types.js.map +1 -1
  89. package/dist/runtime/auto-update/update-marker.d.ts +95 -0
  90. package/dist/runtime/auto-update/update-marker.d.ts.map +1 -0
  91. package/dist/runtime/auto-update/update-marker.js +185 -0
  92. package/dist/runtime/auto-update/update-marker.js.map +1 -0
  93. package/dist/runtime/auto-update/update-schedule.d.ts +67 -0
  94. package/dist/runtime/auto-update/update-schedule.d.ts.map +1 -0
  95. package/dist/runtime/auto-update/update-schedule.js +91 -0
  96. package/dist/runtime/auto-update/update-schedule.js.map +1 -0
  97. package/dist/runtime/decision-errors.d.ts +7 -0
  98. package/dist/runtime/decision-errors.d.ts.map +1 -1
  99. package/dist/runtime/decision-errors.js +15 -0
  100. package/dist/runtime/decision-errors.js.map +1 -1
  101. package/dist/runtime/process-state.d.ts +168 -0
  102. package/dist/runtime/process-state.d.ts.map +1 -0
  103. package/dist/runtime/process-state.js +81 -0
  104. package/dist/runtime/process-state.js.map +1 -0
  105. package/dist/runtime/reconcile-state.d.ts.map +1 -1
  106. package/dist/runtime/reconcile-state.js +18 -4
  107. package/dist/runtime/reconcile-state.js.map +1 -1
  108. package/dist/runtime/strategy-registry.d.ts +16 -0
  109. package/dist/runtime/strategy-registry.d.ts.map +1 -1
  110. package/dist/runtime/strategy-registry.js +7 -3
  111. package/dist/runtime/strategy-registry.js.map +1 -1
  112. package/dist/runtime/update-apply-deps.d.ts +5 -3
  113. package/dist/runtime/update-apply-deps.d.ts.map +1 -1
  114. package/dist/runtime/update-apply-deps.js +15 -3
  115. package/dist/runtime/update-apply-deps.js.map +1 -1
  116. package/dist/senpi/client.d.ts +29 -0
  117. package/dist/senpi/client.d.ts.map +1 -1
  118. package/dist/senpi/client.js +71 -2
  119. package/dist/senpi/client.js.map +1 -1
  120. package/dist/telemetry/metrics.d.ts +15 -1
  121. package/dist/telemetry/metrics.d.ts.map +1 -1
  122. package/dist/telemetry/metrics.js +25 -1
  123. package/dist/telemetry/metrics.js.map +1 -1
  124. package/dist/telemetry/otel-sdk.d.ts +12 -0
  125. package/dist/telemetry/otel-sdk.d.ts.map +1 -1
  126. package/dist/telemetry/otel-sdk.js +47 -1
  127. package/dist/telemetry/otel-sdk.js.map +1 -1
  128. package/dist/telemetry/spans/span-hooks.d.ts +18 -1
  129. package/dist/telemetry/spans/span-hooks.d.ts.map +1 -1
  130. package/dist/telemetry/spans/span-hooks.js +306 -96
  131. package/dist/telemetry/spans/span-hooks.js.map +1 -1
  132. package/dist/telemetry/tool-plane.d.ts +2 -0
  133. package/dist/telemetry/tool-plane.d.ts.map +1 -1
  134. package/dist/telemetry/tool-plane.js +1 -0
  135. package/dist/telemetry/tool-plane.js.map +1 -1
  136. package/dist/test-setup.js +7 -1
  137. package/dist/test-setup.js.map +1 -1
  138. package/dist/tool-surface/crib-cache.d.ts +21 -0
  139. package/dist/tool-surface/crib-cache.d.ts.map +1 -0
  140. package/dist/tool-surface/crib-cache.js +54 -0
  141. package/dist/tool-surface/crib-cache.js.map +1 -0
  142. package/dist/tool-surface/crib-hook.d.ts +78 -0
  143. package/dist/tool-surface/crib-hook.d.ts.map +1 -0
  144. package/dist/tool-surface/crib-hook.js +225 -0
  145. package/dist/tool-surface/crib-hook.js.map +1 -0
  146. package/dist/tool-surface/crib-sheet.d.ts +56 -0
  147. package/dist/tool-surface/crib-sheet.d.ts.map +1 -0
  148. package/dist/tool-surface/crib-sheet.js +129 -0
  149. package/dist/tool-surface/crib-sheet.js.map +1 -0
  150. package/dist/tool-surface/mcp-tool-source.d.ts +64 -0
  151. package/dist/tool-surface/mcp-tool-source.d.ts.map +1 -0
  152. package/dist/tool-surface/mcp-tool-source.js +189 -0
  153. package/dist/tool-surface/mcp-tool-source.js.map +1 -0
  154. package/dist/utils/event-catalog.d.ts +144 -6
  155. package/dist/utils/event-catalog.d.ts.map +1 -1
  156. package/dist/utils/event-catalog.js +25 -0
  157. package/dist/utils/event-catalog.js.map +1 -1
  158. package/dist/widgets/tool.d.ts +9 -0
  159. package/dist/widgets/tool.d.ts.map +1 -1
  160. package/dist/widgets/tool.js +1 -0
  161. package/dist/widgets/tool.js.map +1 -1
  162. package/openclaw.plugin.json +11 -1
  163. package/package.json +5 -2
package/dist/index.js CHANGED
@@ -14,15 +14,17 @@
14
14
  import { readFileSync } from "node:fs";
15
15
  import { parse as parseYaml } from "yaml";
16
16
  import { join, dirname } from "node:path";
17
- import { SenpiClient } from "./senpi/client.js";
17
+ import { isMoneyCallTool, SenpiClient, senpiOrderCallsInFlight } from "./senpi/client.js";
18
+ import { MoneyCallTracker, registerMoneyCallHooks } from "./runtime/auto-update/money-call-tracker.js";
18
19
  import { buildWalletStatusHint } from "./senpi/strategy-status.js";
19
20
  import { bootSkippedStatusLabel, partitionByWalletStatus, readBootWalletStatuses, trackableWalletKeys, } from "./runtime/boot-skip.js";
20
21
  import { DeployJobController } from "./deploy/job.js";
21
- import { registerDeployGatewayMethods } from "./deploy/register.js";
22
+ import { DEPLOY_CAPABILITIES, registerDeployGatewayMethods } from "./deploy/register.js";
22
23
  import { registerUpdateGatewayMethod } from "./runtime/update-register.js";
23
24
  import { createStrategiesPublisher } from "./runtime/strategies-telemetry.js";
24
25
  import { buildEventsReplay, createEventsPublisher, } from "./runtime/events-telemetry.js";
25
26
  import { strategiesStore, strategyRecordFromConfig } from "./runtime/strategies-store.js";
27
+ import { bindProcessLogger, processLog, runtimeProcessState, } from "./runtime/process-state.js";
26
28
  import { checkProofCoversRecipe, makeApplyToRuntime, makeWriteRegistry, runtimeChangeLock, } from "./runtime/update-apply-deps.js";
27
29
  import { INSTALL_DEADLINE_MS, WALLET_INSTALL_IN_FLIGHT_CODE } from "./deploy/deadlines.js";
28
30
  import { AuditQueryError } from "./runtime/audit-query.types.js";
@@ -47,15 +49,21 @@ import { readEvents } from "./telemetry/event-store.js";
47
49
  import { VERSION } from "./version.js";
48
50
  import { resolvePackageName } from "./runtime/auto-update/resolve-package-name.js";
49
51
  import { runOpenClawPluginsUpdate } from "./runtime/auto-update/run-update-command.js";
52
+ import { UpdateIdleGate, createIdleGateActivity } from "./runtime/auto-update/idle-gate.js";
53
+ import { registerIdleGateHooks, resolveUpdateMid } from "./runtime/auto-update/register-idle-gate.js";
54
+ import { resolveUpdateMarkerPath } from "./runtime/auto-update/update-marker.js";
55
+ import { INSTALL_RESULTS_OTEL_FLUSH_MS, INSTALL_RESULTS_OTEL_READY_MS, resolveInstallResultsPath, } from "./runtime/auto-update/install-results.js";
50
56
  import { registerSpanHooks } from "./telemetry/spans/index.js";
51
57
  import { registerSessionContextSeedHook } from "./prompt/session-context-seed-hook.js";
58
+ import { registerCribSheet } from "./tool-surface/crib-hook.js";
52
59
  import { registerSkillRouterHook } from "./prompt/skill-router-hook.js";
53
60
  import { getDefaultPiiRedactor, initDefaultPiiRedactor } from "./telemetry/spans/redact-pii.js";
54
- import { initOtelSdk, shutdownOtelSdk } from "./telemetry/otel-sdk.js";
61
+ import { flushOtelLogs, initOtelSdk, shutdownOtelSdk, waitForOtelInit } from "./telemetry/otel-sdk.js";
55
62
  import { getLogLevel, getLogLevelSource, parseLogLevel, setLogLevel, } from "./utils/logger.js";
56
63
  import { ExternalScannerIngestError, } from "./scanners/external-scanner-receiver.js";
57
64
  import { createLogger } from "./utils/logger.js";
58
- import { registerToolApprovalGate, resolveToolApprovalsMode, } from "./approvals/tool-approval-gate.js";
65
+ import { PendingApprovalTracker, registerToolApprovalGate, resolveToolApprovalsMode, } from "./approvals/tool-approval-gate.js";
66
+ import { registerTurnContextHooks, turnClassificationAvailable, TurnContextTracker, } from "./approvals/turn-context.js";
59
67
  import { registerShowWidgetTool } from "./widgets/index.js";
60
68
  import { EVENT_NAME, SENPI_ERROR_CODE, eventAttrs, scannerUnwiredErrorCode } from "./utils/event-catalog.js";
61
69
  import { emitEvent } from "./actions/event-derivation.js";
@@ -72,6 +80,9 @@ import { ingestDispatchMutex, ingestDispatchKey } from "./runtime-api/intake/ing
72
80
  import { buildScaffoldErrorRouter } from "./runtime-api/intake/scaffold-error-router.js";
73
81
  import { loadRuntimeConfig } from "./runtime/load-runtime-config.js";
74
82
  import { errorText } from "./deploy/error-text.js";
83
+ import { getOpenClawHost, initOpenClawHost } from "./host/openclaw-host.js";
84
+ import { createRegisterPluginLogger, withEventLogger } from "./host/plugin-logger.js";
85
+ import { hostname } from "node:os";
75
86
  import { BOOT_FACTS_CALL_TIMEOUT_MS, planBootFacts, syncBootFacts, } from "./strategy/facts-sync.js";
76
87
  /** Initialize all core features (DSL, risk, health) on the given event bus. */
77
88
  export function initCore(bus) {
@@ -102,21 +113,6 @@ export { createScannerRuntimeModule, createSenpiScannerProviders, emergingMovers
102
113
  export { run } from "./runtime/run.js";
103
114
  export { loadRuntimeConfig } from "./runtime/load-runtime-config.js";
104
115
  export { Runtime } from "./runtime/runtime.js";
105
- /**
106
- * A coordinator logger: info/warn/error route through `pluginLogger` unchanged (the gateway's own
107
- * sink), and `event()` goes to a dedicated OTel-backed logger tagged `tag`. `PluginLogger`
108
- * (api.logger) predates the event catalog and has no `event()`, so coordinators that emit
109
- * first-class events (auto-update, skills-manager) get this split.
110
- */
111
- function withEventLogger(pluginLogger, tag) {
112
- const eventLogger = createLogger(tag);
113
- return {
114
- info: (...args) => pluginLogger.info(...args),
115
- warn: (...args) => pluginLogger.warn(...args),
116
- error: (message, meta) => pluginLogger.error(message, meta),
117
- event: eventLogger.event,
118
- };
119
- }
120
116
  /**
121
117
  * Read the plugin version from the sibling `openclaw.plugin.json` manifest.
122
118
  * Performed once at module load — the manifest is shipped alongside the
@@ -185,11 +181,50 @@ const WALLET_INSTALL_IN_FLIGHT = `[${WALLET_INSTALL_IN_FLIGHT_CODE}]`;
185
181
  */
186
182
  const RUNTIME_ID_TAKEN = "[E_RUNTIME_ID_TAKEN]";
187
183
  /**
188
- * One StrategyFacts send per runtime at a time, keyed on runtime id, across the whole process: a
189
- * second `register()` in the same process shares it. Separate from `runtimeChangeLock`. Delete does
190
- * not take it; an apply queues its send here and does not wait.
184
+ * One StrategyFacts send per runtime at a time, keyed on runtime id, across the whole process.
185
+ * Held in the process state (`runtime/process-state.ts`), not this module: a 10.x plugin reload
186
+ * evaluates a new copy of this module, and the previous registration's send may still be running.
187
+ * Separate from `runtimeChangeLock`. Delete does not take it; an apply queues its send here and
188
+ * does not wait.
189
+ */
190
+ function factsSendLock() {
191
+ const state = runtimeProcessState();
192
+ state.factsSendLock ??= new KeyedMutex();
193
+ return state.factsSendLock;
194
+ }
195
+ /**
196
+ * Clears the process-state latch for the 5.x "cannot classify runs" notice
197
+ * (`legacyTurnClassificationNoticeLogged`). Tests only.
198
+ *
199
+ * The latch lives in the process state so a plugin reload (which re-registers the plugin and
200
+ * restarts its service in the same process, from a new copy of this module) does not repeat the
201
+ * notice. The 5.x case is a host-version limit with no config fix, so one info line per process is
202
+ * the whole message; the fixable 10.x case stays an ERROR at every registration and does not read
203
+ * this latch.
204
+ */
205
+ export function resetLegacyTurnClassificationNoticeForTests() {
206
+ runtimeProcessState().legacyTurnClassificationNoticeLogged = false;
207
+ }
208
+ /**
209
+ * The whole of `register()` in the `"cli-metadata"` pass: the `senpi` CLI root, under the same
210
+ * preconditions and with the same metadata as the full pass, and nothing else.
211
+ *
212
+ * Reads no `api.runtime`: on 10.x that pass's runtime throws on any read, and the host prints the
213
+ * throw as `runtime failed during register` on every `openclaw senpi …` call (RT566-04). Logs
214
+ * nothing: a skipped precondition is reported by the full pass, which follows in the same process.
191
215
  */
192
- const factsSendLock = new KeyedMutex();
216
+ function registerSenpiCliMetadata(api) {
217
+ const config = api.pluginConfig;
218
+ if (!config)
219
+ return;
220
+ const mcpTransport = api.mcpTransport;
221
+ const apiKey = resolveSenpiApiKeyFromStore(readSenpiCliStore(), typeof config.apiKey === "string" && config.apiKey.length > 0 ? config.apiKey : undefined);
222
+ if (!mcpTransport && !apiKey)
223
+ return;
224
+ api.registerCli((ctx) => {
225
+ registerSenpiCli(ctx.program);
226
+ }, { commands: ["senpi"] });
227
+ }
193
228
  /**
194
229
  * OpenClaw plugin entry.
195
230
  * Boots from internal registry (installed_runtimes.json) in stateDir; does not read runtime list from config.
@@ -220,16 +255,34 @@ const senpiRuntimePlugin = {
220
255
  // The diagnostics are not dropped, only moved to stderr where diagnostics belong. Warnings and
221
256
  // errors are left on the logger untouched: those are not routine chatter, and a caller piping
222
257
  // stdout to a parser still wants them visible.
223
- const jsonMode = process.argv.includes("--json");
224
- const pluginLogger = {
225
- info: (...args) =>
226
- // No added prefix: these messages already carry their own `[senpi-runtime]` /
227
- // `[senpi-tool-approvals]` tag, and prepending another produced doubled labels on stderr.
228
- jsonMode ? console.error(...args) : api.logger.info(...args),
229
- warn: (...args) => api.logger.warn(...args),
230
- error: (message, meta) => api.logger.error(message, meta),
231
- };
258
+ //
259
+ // OpenClaw 2026.5.20+ (every modern host) moves plugin logs to stderr itself under `--json` and
260
+ // files them at their real level, so the reroute is kept for 5.x only: on 10.x it made the
261
+ // console capture file every registration line at ERROR (F5). See host/plugin-logger.ts.
262
+ //
263
+ // The cli-metadata pass only collects CLI command roots. 10.x hands it a runtime that throws on
264
+ // any read (RT566-04), so register the `senpi` root and nothing else — and read no api.runtime.
265
+ if (api.registrationMode === "cli-metadata") {
266
+ registerSenpiCliMetadata(api);
267
+ return;
268
+ }
269
+ // Host facts first: the logger and every version-gated registration below read them. 10.x also
270
+ // registers plugins in non-full modes inside the gateway (`tool-discovery` for tools.catalog);
271
+ // that pass must keep registering tools, but its throwaway api must not replace the record the
272
+ // live registration made.
273
+ const fullRegistration = api.registrationMode === undefined || api.registrationMode === "full";
274
+ const openClawHost = (!fullRegistration && getOpenClawHost()) || initOpenClawHost(api);
275
+ // State kept across a reload (the deploy controller, the gate trackers) logs through the latest
276
+ // full registration's logger, never through an `api` a reload has replaced.
277
+ const processState = runtimeProcessState();
278
+ if (fullRegistration)
279
+ bindProcessLogger(api.logger);
280
+ const pluginLogger = createRegisterPluginLogger(api.logger, {
281
+ jsonMode: process.argv.includes("--json"),
282
+ hostRoutesJsonLogsToStderr: openClawHost.modern,
283
+ });
232
284
  pluginLogger.info("[senpi-runtime] register(api) invoked");
285
+ pluginLogger.info(`[senpi-runtime] host OpenClaw ${openClawHost.version ?? "unknown"} (${openClawHost.modern ? "modern" : "legacy"})`);
233
286
  const config = api.pluginConfig;
234
287
  if (!config) {
235
288
  pluginLogger.warn("[senpi-runtime] No plugin config found — skipping registration");
@@ -292,8 +345,8 @@ const senpiRuntimePlugin = {
292
345
  // Agent telemetry — gateway hooks emit gen_ai spans (llm/tool/subagent) through
293
346
  // the shared tracer; on-site MCP calls emit their own spans from SenpiClient.
294
347
  try {
295
- registerSpanHooks({ api });
296
- pluginLogger.info("[senpi-runtime] gen_ai span hooks registered (9 hooks)");
348
+ const spanHookCount = registerSpanHooks({ api, modernHost: openClawHost.modern });
349
+ pluginLogger.info(`[senpi-runtime] gen_ai span hooks registered (${spanHookCount} hooks)`);
297
350
  }
298
351
  catch (err) {
299
352
  pluginLogger.warn("[senpi-runtime] failed to register span hooks", {
@@ -312,6 +365,32 @@ const senpiRuntimePlugin = {
312
365
  err: err instanceof Error ? err.message : String(err),
313
366
  });
314
367
  }
368
+ // senpi__ crib sheet (OpenClaw 10.x tool-search directory mode only): the
369
+ // directory folds every MCP tool into one sentence, so the runtime puts
370
+ // the names back as prependSystemContext. Registers nothing on 5.x.
371
+ // Its `before_prompt_build` hook needs the same host grant as the approval
372
+ // turn classification below; without it 10.x drops the hook, so the line
373
+ // says the crib is inactive and why instead of "registered".
374
+ try {
375
+ if (registerCribSheet({
376
+ api: api,
377
+ baseStateDir,
378
+ pluginConfig: config,
379
+ logger: pluginLogger,
380
+ })) {
381
+ // Registered, so the host is modern; only the hook grant is left to check.
382
+ const cribHook = turnClassificationAvailable({ modernHost: true, config: api.config, pluginId: api.id });
383
+ pluginLogger.info(cribHook.available
384
+ ? "[senpi-runtime] senpi__ crib sheet registered (directory mode only)"
385
+ : `[senpi-runtime] senpi__ crib inactive: ${cribHook.reason}` +
386
+ (cribHook.configFix ? `; fix: ${cribHook.configFix}` : ""));
387
+ }
388
+ }
389
+ catch (err) {
390
+ pluginLogger.warn("[senpi-runtime] failed to register the senpi__ crib sheet", {
391
+ err: err instanceof Error ? err.message : String(err),
392
+ });
393
+ }
315
394
  // Skill router — on an eligible user turn, asks senpi-backend which installed skill the
316
395
  // prompt needs and (mode `on`) points the model at its SKILL.md. Registered after the seed
317
396
  // hook so the seed instruction comes first if both inject. Off unless SENPI_SKILL_ROUTER is
@@ -337,9 +416,82 @@ const senpiRuntimePlugin = {
337
416
  // the bridge's operator.approvals-scoped gateway connection; allow-always
338
417
  // decisions persist in <stateDir>/tool-approvals.json.
339
418
  // See docs/mcp-tool-approvals-design.md.
419
+ // Open trade-approval prompts, read by the self-update idle gate (R2).
420
+ // This and the turn tracker are process state: a 10.x reload re-registers in the same process
421
+ // while a prompt is open or a run is in flight (r4467406809, r4427720076).
422
+ processState.pendingApprovals ??= new PendingApprovalTracker();
423
+ const pendingApprovalTracker = processState.pendingApprovals;
424
+ // The turn kind (chat / cron / heartbeat) and session key of each gated
425
+ // call, for approval telemetry and the 10.x scheduled-turn block (R6, D13).
426
+ processState.turnContext ??= new TurnContextTracker();
427
+ const turnContextTracker = processState.turnContext;
428
+ // One boot-time fact (D15): can this host classify runs at all? Only then
429
+ // does the gate stop prompts outside a direct chat turn. Without it every
430
+ // run reads unknown and keeps the pre-10.x prompt, so a box missing the
431
+ // setting never blocks chat trades; it is reported loudly instead.
432
+ let turnClassification = turnClassificationAvailable({
433
+ modernHost: openClawHost.modern,
434
+ config: api.config,
435
+ pluginId: api.id,
436
+ });
437
+ try {
438
+ registerTurnContextHooks({ api, tracker: turnContextTracker });
439
+ }
440
+ catch (err) {
441
+ turnClassification = { available: false, reason: "the turn-context hooks failed to register" };
442
+ pluginLogger.warn("[senpi-runtime] failed to register the approval turn-context hooks", {
443
+ err: err instanceof Error ? err.message : String(err),
444
+ });
445
+ }
446
+ // Only the logging and the status flag differ by host; the gate below reads the same boolean
447
+ // either way. On 10.x it is an ERROR at every registration (a box config to fix, or hooks that
448
+ // failed to register). On 5.x it is a host limit no config can fix, so it is one info line per
449
+ // process, logged from the service start below: that runs in the gateway only, so the
450
+ // `openclaw senpi …` CLI children (deploy.py, close.py, an agent exec) register without
451
+ // printing it.
452
+ const turnClassificationHostLimit = !turnClassification.available && !openClawHost.modern;
453
+ const turnClassificationNotice = turnClassification.available
454
+ ? undefined
455
+ : `[senpi-tool-approvals] cannot tell chat turns from scheduled or background runs: ${turnClassification.reason}. ` +
456
+ "Trade approvals are requested in every run, scheduled ones included, " +
457
+ (turnClassification.configFix
458
+ ? `until the box config is fixed (${turnClassification.configFix}).`
459
+ : turnClassificationHostLimit
460
+ ? "on this OpenClaw version; a 10.x host lifts this."
461
+ : "until the runtime registers its turn-context hooks.");
462
+ const legacyTurnClassificationNotice = turnClassificationHostLimit ? turnClassificationNotice : undefined;
463
+ if (turnClassificationNotice !== undefined && !turnClassificationHostLimit && fullRegistration) {
464
+ pluginLogger.error(turnClassificationNotice);
465
+ }
466
+ const approvalsHostStatus = turnClassification.available
467
+ ? { turnClassification: "available" }
468
+ : {
469
+ turnClassification: "unavailable",
470
+ reason: turnClassification.reason,
471
+ ...(turnClassificationHostLimit ? { hostLimit: true } : {}),
472
+ };
473
+ // Process state, like the run-kind tracker beside it: a reload must not zero the count that
474
+ // `senpi status` warns about while chat trades are being refused.
475
+ const approvalsStatus = () => approvalsHostStatus.turnClassification === "available"
476
+ ? {
477
+ ...approvalsHostStatus,
478
+ runsRecorded: turnContextTracker.runsRecorded,
479
+ unclassifiedBlocks: processState.unclassifiedBlocks,
480
+ ...(processState.lastUnclassifiedBlockAt
481
+ ? { lastUnclassifiedBlockAt: processState.lastUnclassifiedBlockAt }
482
+ : {}),
483
+ }
484
+ : approvalsHostStatus;
340
485
  try {
341
486
  registerToolApprovalGate({
342
487
  api,
488
+ pendingApprovals: pendingApprovalTracker,
489
+ turnContext: turnContextTracker,
490
+ turnClassification: turnClassification.available,
491
+ onUnclassifiedBlock: (at) => {
492
+ processState.unclassifiedBlocks += 1;
493
+ processState.lastUnclassifiedBlockAt = new Date(at).toISOString();
494
+ },
343
495
  mode: resolveToolApprovalsMode({
344
496
  pluginConfig: config,
345
497
  env: process.env,
@@ -461,8 +613,21 @@ const senpiRuntimePlugin = {
461
613
  * row, sees no live handle, deletes it and reinstalls — and the first install then lands on top,
462
614
  * clobbering `runtimeHandles` under a runtime id both installs derive identically. Two exit
463
615
  * engines, one margin account: the exact state `[E_WALLET_HAS_RUNTIME]` exists to prevent.
616
+ *
617
+ * Process state (`runtime/process-state.ts`), not this registration: a 10.x plugin reload
618
+ * re-registers in the same process while a deploy job's install from the previous registration
619
+ * runs on, and the new registration must still refuse a second install on that wallet.
620
+ */
621
+ const installsInFlight = processState.installsInFlight;
622
+ /**
623
+ * This registration's service lifecycle, for an install or adoption that outlives it. A 10.x
624
+ * plugin reload stops this service and starts the next registration's in the same process;
625
+ * `serviceStops` counts this registration's stops, so a stop followed by a later start is still
626
+ * seen. Only a stop counts: an install that began before the first start (the gateway may call
627
+ * installRuntime before start()) and spans it is not orphaned.
464
628
  */
465
- const installsInFlight = new Map();
629
+ let serviceState = "idle";
630
+ let serviceStops = 0;
466
631
  // Dedicated logger for the runtime-api subtree — required because the
467
632
  // PluginLogger surface (info/warn/error) lacks `debug`, while the
468
633
  // Logger contract used by `runtime-api/` includes it.
@@ -503,26 +668,106 @@ const senpiRuntimePlugin = {
503
668
  stateDir: join(baseStateDir, "skills-manager"),
504
669
  logger: withEventLogger(pluginLogger, "[senpi-core][skills-manager]"),
505
670
  });
506
- const autoUpdateLogger = withEventLogger(pluginLogger, "[senpi-core][auto-update]");
507
671
  const autoUpdateConfig = resolveAutoUpdateConfig(config?.autoUpdate);
672
+ // OpenClaw 10.x (>= 2026.8.1): restart-to-apply (R2). The runtime cannot
673
+ // install itself there, so it waits for its spread slot and an idle box,
674
+ // writes the install marker, and restarts through mutateConfigFile; the
675
+ // senpi-agent wrapper installs before the next gateway spawn. On 5.7 and
676
+ // 5.12 the wiring is the in-process install + config-bump restart.
677
+ const modernHost = openClawHost.modern;
678
+ // 10.x: every `auto_update.*` event is also written to the gateway log as one key=value line,
679
+ // so a box with no collector still keeps the update's fields (F8). 5.x keeps OTel only.
680
+ const autoUpdateLogger = withEventLogger(pluginLogger, "[senpi-core][auto-update]", modernHost ? { mirrorTag: "[senpi-auto-update]" } : {});
681
+ let idleGate;
682
+ if (modernHost) {
683
+ // Money calls on every route: the runtime's own in-process MCP calls, plus
684
+ // the agent's senpi__ calls (direct or through the dispatcher), seen at the
685
+ // tool hooks. A deploy job is read from the controller (this process) and
686
+ // its journals (any process).
687
+ // Process state, like the approval trackers: a call that started under the previous
688
+ // registration still counts, and its after-hook (now this registration's) closes it.
689
+ processState.moneyCalls ??= new MoneyCallTracker();
690
+ const moneyCalls = processState.moneyCalls;
691
+ try {
692
+ registerMoneyCallHooks({
693
+ api: api,
694
+ tracker: moneyCalls,
695
+ isMoneyTool: isMoneyCallTool,
696
+ });
697
+ }
698
+ catch (err) {
699
+ pluginLogger.warn("[senpi-runtime] failed to register the self-update money-call hooks", {
700
+ err: err instanceof Error ? err.message : String(err),
701
+ });
702
+ }
703
+ idleGate = new UpdateIdleGate({
704
+ pendingApprovals: () => pendingApprovalTracker.count(),
705
+ ordersInFlight: () => senpiOrderCallsInFlight() + moneyCalls.count(Date.now()),
706
+ // Read only from ticks, after register() has constructed the controller below.
707
+ deploysInFlight: () => deployController.inFlight(Date.now()),
708
+ // The process start, not this registration: a config edit under `plugins` re-registers in
709
+ // the same process (10.10 reloadGatewayPlugins), and repeated reloads under 15 min apart
710
+ // must not hold an update until the forced window.
711
+ startedAt: Date.now() - Math.round(process.uptime() * 1000),
712
+ // Process state: a reload builds this gate again, and must not forget a user turn that is
713
+ // running, a message that is queued, or when the user last wrote.
714
+ activity: (processState.idleGateActivity ??= createIdleGateActivity()),
715
+ logger: pluginLogger,
716
+ });
717
+ try {
718
+ registerIdleGateHooks({ api: api, gate: idleGate, logger: pluginLogger });
719
+ }
720
+ catch (err) {
721
+ pluginLogger.warn("[senpi-runtime] failed to register the self-update idle gate hooks", {
722
+ err: err instanceof Error ? err.message : String(err),
723
+ });
724
+ }
725
+ }
726
+ const openclawStateDir = typeof api.runtime?.state?.resolveStateDir === "function" ? api.runtime.state.resolveStateDir() : undefined;
508
727
  const autoUpdateCoordinator = new AutoUpdateCoordinator({
509
728
  enabled: true,
510
729
  config: autoUpdateConfig,
511
730
  packageName: PLUGIN_PACKAGE_NAME,
512
731
  currentVersion: VERSION,
732
+ // The version this process loaded; "applied" is decided from it alone.
733
+ loadedVersion: VERSION,
513
734
  stateDir: join(baseStateDir, "auto-update"),
514
735
  logger: autoUpdateLogger,
515
736
  // Use the resolved npm package name (not a hardcoded plugin id) so
516
737
  // the update follows the same npm channel as the version check —
517
- // see runtime/auto-update/run-update-command.ts.
518
- runUpdateCommand: runOpenClawPluginsUpdate,
738
+ // see runtime/auto-update/run-update-command.ts. Not on 10.x, which
739
+ // refuses plugins update while the gateway runs.
740
+ runUpdateCommand: modernHost ? undefined : runOpenClawPluginsUpdate,
519
741
  configFromApi: api.config,
520
- loadConfig: api.runtime?.config
742
+ loadConfig: !modernHost && api.runtime?.config
521
743
  ? () => api.runtime.config.loadConfig()
522
744
  : undefined,
523
- writeConfigFile: api.runtime?.config
745
+ writeConfigFile: !modernHost && api.runtime?.config
524
746
  ? (c) => api.runtime.config.writeConfigFile(c)
525
747
  : undefined,
748
+ modernHost,
749
+ mutateConfigFile: modernHost && typeof api.runtime?.config?.mutateConfigFile === "function"
750
+ ? (p) => api.runtime.config.mutateConfigFile(p)
751
+ : undefined,
752
+ readLiveConfig: modernHost ? openClawHost.currentConfig : undefined,
753
+ idleGate,
754
+ mid: modernHost
755
+ ? resolveUpdateMid({
756
+ token: apiKey ?? process.env.SENPI_AUTH_TOKEN ?? process.env.SENPI_API_KEY,
757
+ env: process.env,
758
+ hostname,
759
+ })
760
+ : undefined,
761
+ updateMarkerPath: modernHost && openclawStateDir ? resolveUpdateMarkerPath(openclawStateDir) : undefined,
762
+ // The wrapper's install outcomes, reported once per coordinator start (gateway only),
763
+ // with auto-update on or off. The report runs off the start path: it waits for the OTel
764
+ // init register() started (else the events go to the no-op logger and the file is gone)
765
+ // and flushes the logs before deleting the file.
766
+ installResultsPath: modernHost && openclawStateDir ? resolveInstallResultsPath(openclawStateDir) : undefined,
767
+ installResultsTelemetry: {
768
+ ready: () => waitForOtelInit(INSTALL_RESULTS_OTEL_READY_MS),
769
+ flush: () => flushOtelLogs(INSTALL_RESULTS_OTEL_FLUSH_MS),
770
+ },
526
771
  pluginId: api.id,
527
772
  // Drive skills-manager off the auto-update tick. Both success and
528
773
  // failure branches of auto-update's tick fire this hook so skills
@@ -560,11 +805,20 @@ const senpiRuntimePlugin = {
560
805
  // boot scan: declaring it after would leave that reference in the temporal dead zone for any
561
806
  // future refactor that starts the service earlier. The rest of the deploy wiring lives in
562
807
  // src/deploy/register.ts behind an explicit context; this closure contributes collaborators only.
563
- const deployController = new DeployJobController({
564
- deploysDir: join(baseStateDir, "deploys"),
565
- now: () => Date.now(),
566
- log: (line) => api.logger.info(`[senpi-runtime] ${line}`),
567
- });
808
+ //
809
+ // One controller per deploys dir per process (process state): a full re-registration (10.10
810
+ // reloadGatewayPlugins, same process) reuses the one that may be running a deploy, so its
811
+ // `running()` keeps single-flight and `inFlight()` keeps the idle gate's deploy blocker. It
812
+ // logs through `processLog`, the current registration's logger, so a job that outlives its
813
+ // registration still narrates and writes its terminal journal line.
814
+ const deploysDir = join(baseStateDir, "deploys");
815
+ const deployController = processState.deployControllers.get(deploysDir) ??
816
+ new DeployJobController({
817
+ deploysDir,
818
+ now: () => Date.now(),
819
+ log: (line) => processLog.info(`[senpi-runtime] ${line}`),
820
+ });
821
+ processState.deployControllers.set(deploysDir, deployController);
568
822
  // ── lifecycle reaper ─────────────────────────────────────────────────────────────────────────
569
823
  // A runtime exists iff its strategy is open. Every close path ends at the backend and none of
570
824
  // them tells this box, so the reaper asks: once after boot, hourly, and whenever the backend
@@ -602,10 +856,20 @@ const senpiRuntimePlugin = {
602
856
  api.registerService({
603
857
  id: "senpi-runtime",
604
858
  async start() {
859
+ serviceState = "running";
860
+ // The 5.x classification notice (see the approval gate above), once per process.
861
+ if (legacyTurnClassificationNotice !== undefined && !processState.legacyTurnClassificationNoticeLogged) {
862
+ processState.legacyTurnClassificationNoticeLogged = true;
863
+ pluginLogger.info(legacyTurnClassificationNotice);
864
+ }
605
865
  // Deploy-journal janitor: stamp anything a restart left unterminated as `interrupted`.
606
866
  // It never re-enters a deploy state machine — discovery is pull-based via
607
- // `senpi deploy status`.
608
- await deployController.scanOnBoot();
867
+ // `senpi deploy status`. Once per process: after a reload an unterminated journal may be
868
+ // the deploy this process is still running (r4469086155).
869
+ if (!processState.bootScanned.has(deploysDir)) {
870
+ processState.bootScanned.add(deploysDir);
871
+ await deployController.scanOnBoot();
872
+ }
609
873
  await autoUpdateCoordinator.start();
610
874
  // SENPI_RUNTIME_API_DISABLED=true also disables the skills coordinator.
611
875
  // Skills bootstrap performs a real `git clone` synchronously during
@@ -925,6 +1189,17 @@ const senpiRuntimePlugin = {
925
1189
  }
926
1190
  }
927
1191
  }
1192
+ // This registration now runs the box's runtimes: publish it, then start what an install from a
1193
+ // stopped registration handed over while none was live (see `handOffRuntime`). Detached and
1194
+ // never throwing, like the facts send: one adoption must not hold or fail the boot.
1195
+ processState.runtimeHost = runtimeHost;
1196
+ const pendingHandOffs = [...processState.pendingRuntimeHandOffs];
1197
+ processState.pendingRuntimeHandOffs.clear();
1198
+ for (const [runtimeId, walletKey] of pendingHandOffs) {
1199
+ void runtimeHost.adoptRuntime({ runtimeId, walletKey }).then((handOff) => {
1200
+ pluginLogger.info("[senpi-runtime] handed-over runtime settled at service start", { runtimeId, outcome: handOff.outcome });
1201
+ });
1202
+ }
928
1203
  // Ticks once now, with every booted runtime in the store, then every 30 s.
929
1204
  strategiesPublisher.start();
930
1205
  // Sends the events added since the previous send, every 1 s.
@@ -946,6 +1221,12 @@ const senpiRuntimePlugin = {
946
1221
  }
947
1222
  },
948
1223
  async stop() {
1224
+ // First: an install or adoption still running in this registration sees the stop from here
1225
+ // on and hands its runtime to the next registration instead of keeping it in this one.
1226
+ serviceState = "stopped";
1227
+ serviceStops += 1;
1228
+ if (processState.runtimeHost === runtimeHost)
1229
+ processState.runtimeHost = null;
949
1230
  // Stop the reaper first so no pass starts deleting while the runtimes are torn down below,
950
1231
  // and wait (bounded) for a pass already under way, so its delete cannot stop a handle the
951
1232
  // teardown below is stopping too.
@@ -997,7 +1278,310 @@ const senpiRuntimePlugin = {
997
1278
  * `senpi deploy` installs through the SAME gates (wallet ownership, one-runtime-per-wallet,
998
1279
  * scanner-path resolution) instead of a parallel path that could drift.
999
1280
  */
1281
+ /**
1282
+ * Start an already-registered runtime in THIS registration while its service runs: `run()`,
1283
+ * the handle in `runtimeHandles`, then the hot-install scanner wire (the API is already
1284
+ * listening, so the launcher starts at once). Shared by `installRuntimeCore` and by
1285
+ * {@link runtimeHost}'s adoption of a runtime another registration handed over.
1286
+ *
1287
+ * `orphaned` says whether this registration's service stopped since the caller began (a 10.x
1288
+ * plugin reload). It is read after `run()` returns and again after the wire: a stopped
1289
+ * registration's `stop()` has already torn its runtimes down, so a runtime started here now
1290
+ * would keep ticking in a registration nothing can stop or delete. In that case this stops what
1291
+ * it started (the launcher, then the handle), removes them from this registration's maps, and
1292
+ * returns `orphaned`; the caller hands the runtime to the live registration.
1293
+ *
1294
+ * Throws what `run()` throws. Wire failures do not throw: they are reported as `unwiredPhase`,
1295
+ * exactly as the install has always reported them.
1296
+ */
1297
+ async function startRuntimeLive(spec, orphaned,
1298
+ /** Called once the runtime runs in this registration, before the scanner wire. */
1299
+ onRunning) {
1300
+ const { runtimeId, pathOrContent, fromPath, recipeDir, wallet, parsedConfig } = spec;
1301
+ /**
1302
+ * The unwired verdict for THIS start, tracked locally rather than read back out of
1303
+ * `unwiredRuntimes`, so the result reports what this call did and never a leftover verdict
1304
+ * from an earlier runtime that happened to share the id. Set at each of the three sites that
1305
+ * leave the runtime without live entry scanners; cleared by the wire-success path.
1306
+ */
1307
+ let unwiredPhase;
1308
+ let hotLauncher = null;
1309
+ const scannerProviders = await createScannerProvidersForRun({
1310
+ mcpTransport,
1311
+ apiKey,
1312
+ });
1313
+ const entryStateDir = buildRuntimeStateDir(baseStateDir, runtimeId, wallet);
1314
+ const handle = await run(pathOrContent, {
1315
+ fromPath,
1316
+ stateDir: entryStateDir,
1317
+ mcpTransport,
1318
+ apiKey,
1319
+ scannerProviders,
1320
+ runtimeId,
1321
+ onStrategyNotActive: (address) => reaper.checkWallet(address),
1322
+ });
1323
+ /** Stops what this call started and leaves this registration's maps as they were. */
1324
+ const abandon = async () => {
1325
+ if (hotLauncher) {
1326
+ await hotLauncher.stop().catch(() => { });
1327
+ if (launchers.get(runtimeId) === hotLauncher)
1328
+ launchers.delete(runtimeId);
1329
+ }
1330
+ await handle.stop().catch((err) => {
1331
+ pluginLogger.warn("[senpi-runtime] could not stop a runtime started by a stopped registration", {
1332
+ runtimeId,
1333
+ err: err instanceof Error ? err.message : String(err),
1334
+ });
1335
+ });
1336
+ if (runtimeHandles.get(runtimeId) === handle) {
1337
+ runtimeHandles.delete(runtimeId);
1338
+ unwiredRuntimes.delete(runtimeId);
1339
+ }
1340
+ return { status: "orphaned" };
1341
+ };
1342
+ if (orphaned())
1343
+ return abandon();
1344
+ runtimeHandles.set(runtimeId, handle);
1345
+ onRunning?.();
1346
+ // ── hot-install supervised scanner wire ───────────────────────────────
1347
+ // Live-install path: used when a runtime is registered after boot via
1348
+ // senpi.installRuntime, while the API is already listening — the
1349
+ // counterpart to the boot-time `launcher` above. A runtime takes exactly
1350
+ // one path: boot-present → `launcher` (deferred start); installed live →
1351
+ // `hotLauncher` (immediate start). The two are mutually exclusive because
1352
+ // installRuntime rejects any id/wallet already in the registry before
1353
+ // wiring (the hasId guard), so a boot-present runtime never re-enters here;
1354
+ // an adoption starts only a row the live registration does not run.
1355
+ // The API is already listening at this point, so we wire and start
1356
+ // immediately (no deferred start needed). Any failure is swallowed so
1357
+ // the install itself is not rolled back — the runtime is already up.
1358
+ // Gate on the same API-disabled flag as the boot path: when the HTTP API
1359
+ // is off (a test-only seam), the /signals route is never mounted, so
1360
+ // starting scanners would only spawn children that POST to a closed port.
1361
+ if (parsedConfig &&
1362
+ sharedIntakeContext &&
1363
+ process.env.SENPI_RUNTIME_API_DISABLED !== "true") {
1364
+ try {
1365
+ const apiConfig = loadApiConfig(api.pluginConfig);
1366
+ const scaffoldPackageDir = fileURLToPath(new URL("./scanners/external", import.meta.url));
1367
+ hotLauncher = wireRuntime({
1368
+ runtimeConfig: parsedConfig,
1369
+ recipeDir,
1370
+ runtimeId,
1371
+ wallet,
1372
+ sharedCtx: sharedIntakeContext,
1373
+ runtimeHandles,
1374
+ intakeUrl: intakeUrlFor(apiConfig.host, apiConfig.port),
1375
+ scaffoldPackageDir,
1376
+ runtimeStateDir: entryStateDir,
1377
+ logger: apiLogger,
1378
+ });
1379
+ if (hotLauncher) {
1380
+ const launcher = hotLauncher;
1381
+ try {
1382
+ await launcher.start();
1383
+ launchers.set(runtimeId, launcher);
1384
+ unwiredRuntimes.delete(runtimeId);
1385
+ unwiredPhase = undefined;
1386
+ runtimeHandles.get(runtimeId)?.attachSupervisionSource(() => ({
1387
+ unwired: false,
1388
+ rows: launcher.describeSupervision(),
1389
+ }));
1390
+ }
1391
+ catch (startErr) {
1392
+ await launcher.stop().catch(() => { });
1393
+ hotLauncher = null;
1394
+ unwiredRuntimes.set(runtimeId, "install_launch");
1395
+ unwiredPhase = "install_launch";
1396
+ runtimeHandles.get(runtimeId)?.attachSupervisionSource(() => ({
1397
+ unwired: true,
1398
+ unwiredPhase: "install_launch",
1399
+ rows: [],
1400
+ }));
1401
+ eventScannersUnwired("install_launch", runtimeId, wallet, appendCause("[senpi-runtime] hot-install supervised scanner launch failed — runtime running without it", startErr), startErr);
1402
+ }
1403
+ }
1404
+ }
1405
+ catch (wireErr) {
1406
+ // Wire failure must NOT fail the install — the runtime is already up. It IS reported
1407
+ // across the result boundary (payload.unwired) so a funding caller can refuse it.
1408
+ unwiredRuntimes.set(runtimeId, "install_wire");
1409
+ unwiredPhase = "install_wire";
1410
+ runtimeHandles.get(runtimeId)?.attachSupervisionSource(() => ({
1411
+ unwired: true,
1412
+ unwiredPhase: "install_wire",
1413
+ rows: [],
1414
+ }));
1415
+ eventScannersUnwired("install_wire", runtimeId, wallet, appendCause("[senpi-runtime] hot-install wiring failed — runtime running without supervised scanners", wireErr), wireErr);
1416
+ }
1417
+ }
1418
+ else if (parsedConfig && !sharedIntakeContext && selectScanners(parsedConfig).length > 0) {
1419
+ // Supervised intake is DISABLED for the whole box (corrupt acceptance record).
1420
+ // The wire block above is skipped, so this hot-installed runtime declares
1421
+ // external scanners but has NO live entry scanners. Record that fail-closed
1422
+ // state (state only, no new event) so listRuntimes/health don't lie.
1423
+ unwiredRuntimes.set(runtimeId, "no_intake");
1424
+ unwiredPhase = "no_intake";
1425
+ runtimeHandles.get(runtimeId)?.attachSupervisionSource(() => ({
1426
+ unwired: true,
1427
+ unwiredPhase: "no_intake",
1428
+ rows: [],
1429
+ }));
1430
+ }
1431
+ // ──────────────────────────────────────────────────────────────────────
1432
+ // The stop may have landed during the wire: its teardown then missed the launcher above.
1433
+ if (orphaned())
1434
+ return abandon();
1435
+ return unwiredPhase ? { status: "started", unwiredPhase } : { status: "started" };
1436
+ }
1437
+ /**
1438
+ * Give a runtime an orphaned install (or adoption) started to the live registration
1439
+ * ({@link RuntimeProcessState.runtimeHost}), or queue it for the next service start when no
1440
+ * registration is live. Never throws.
1441
+ */
1442
+ async function handOffRuntime(runtimeId, walletKey) {
1443
+ const host = processState.runtimeHost;
1444
+ if (!host) {
1445
+ // The strategies store is left as it is: a registration that is starting may already run this
1446
+ // row from its boot, and the next start's boot or adoption sets the entry either way.
1447
+ processState.pendingRuntimeHandOffs.set(runtimeId, walletKey);
1448
+ pluginLogger.info("[senpi-runtime] runtime handed to the next service start (no live registration)", { runtimeId });
1449
+ return { outcome: "pending" };
1450
+ }
1451
+ try {
1452
+ return await host.adoptRuntime({ runtimeId, walletKey });
1453
+ }
1454
+ catch (err) {
1455
+ // Nothing runs it: drop the entry the stopped start wrote, so the apps do not draw it.
1456
+ strategiesStore.delete(runtimeId);
1457
+ return { outcome: "failed", message: err instanceof Error ? err.message : String(err) };
1458
+ }
1459
+ }
1460
+ /**
1461
+ * The live registration, when this registration's service has stopped (a 10.x plugin reload)
1462
+ * and another one is running. A deploy job from before the reload keeps this registration's
1463
+ * closures; its deletes and liveness reads go to the registration that holds the runtimes.
1464
+ */
1465
+ function liveHostIfStopped() {
1466
+ if (serviceState !== "stopped")
1467
+ return undefined;
1468
+ const host = processState.runtimeHost;
1469
+ return host && host !== runtimeHost ? host : undefined;
1470
+ }
1471
+ /**
1472
+ * The install result for a runtime this install handed over. A stopped runtime is never
1473
+ * reported as running here: `handedOff` names who runs it, and the result is an error when
1474
+ * nothing does.
1475
+ */
1476
+ function installHandOffResult(handOff, runtime) {
1477
+ switch (handOff.outcome) {
1478
+ case "running":
1479
+ case "booted":
1480
+ return {
1481
+ ok: true,
1482
+ payload: {
1483
+ ...runtime,
1484
+ id: handOff.runtimeId,
1485
+ ...(handOff.unwired ? { unwired: handOff.unwired } : {}),
1486
+ handedOff: "The runtime plugin's service stopped during this install (a plugin reload or a gateway " +
1487
+ "stop), so the plugin registration that is running now runs this runtime " +
1488
+ `(runtime "${handOff.runtimeId}"). Check it: openclaw senpi runtime list.`,
1489
+ },
1490
+ };
1491
+ case "pending":
1492
+ return {
1493
+ ok: true,
1494
+ payload: {
1495
+ ...runtime,
1496
+ handedOff: "The runtime plugin's service stopped during this install (a plugin reload or a gateway " +
1497
+ "stop), and no plugin registration had finished starting when it ended. The runtime is " +
1498
+ "installed; the plugin's service runs it when its start finishes. Check it: " +
1499
+ "openclaw senpi runtime list.",
1500
+ },
1501
+ };
1502
+ case "no-row":
1503
+ return { ok: false, error: {
1504
+ code: "UNAVAILABLE",
1505
+ message: `The runtime plugin's service stopped during this install and runtime "${runtime.id}" is no ` +
1506
+ "longer in the registry, so nothing runs it. Nothing is trading on this wallet from this " +
1507
+ "install. Check: openclaw senpi runtime list.",
1508
+ } };
1509
+ case "failed":
1510
+ return { ok: false, error: {
1511
+ code: "UNAVAILABLE",
1512
+ message: `The runtime plugin's service stopped during this install and the running plugin ` +
1513
+ `registration could not start runtime "${runtime.id}": ${handOff.message}. It is installed; ` +
1514
+ "the next restart tries to start it. Check: openclaw senpi runtime list.",
1515
+ } };
1516
+ }
1517
+ }
1518
+ /**
1519
+ * This registration as the process's {@link RuntimeHost}: published at the end of the service
1520
+ * start, withdrawn at the start of its stop.
1521
+ */
1522
+ const runtimeHost = {
1523
+ async adoptRuntime(request) {
1524
+ const handOff = await adoptRuntimeCore(request);
1525
+ // Nothing runs it here: drop the entry the stopped registration's start wrote (run() sets it,
1526
+ // and that start's abandon does not clear it), so the apps do not draw a strategy that is not
1527
+ // running. A different id on the wallet leaves this id's entry just as stale.
1528
+ if (handOff.outcome === "no-row" ||
1529
+ handOff.outcome === "failed" ||
1530
+ (handOff.outcome === "running" && handOff.runtimeId !== request.runtimeId)) {
1531
+ strategiesStore.delete(request.runtimeId);
1532
+ }
1533
+ return handOff;
1534
+ },
1535
+ deleteRuntime: (params) => deleteRuntimeCore(params),
1536
+ runtimeIsLive: async (id) => runtimeHandles.has(id) && !unwiredRuntimes.has(id),
1537
+ getScannerRows: (id) => readScannerRows(id),
1538
+ };
1539
+ async function adoptRuntimeCore({ runtimeId, walletKey }) {
1540
+ const stopsAtAdopt = serviceStops;
1541
+ const orphaned = () => serviceState !== "running" || serviceStops !== stopsAtAdopt;
1542
+ try {
1543
+ const onWallet = runtimeHandles.has(runtimeId)
1544
+ ? runtimeId
1545
+ : walletKey
1546
+ ? [...runtimeHandles].find(([, h]) => (h.wallet ?? "").trim().toLowerCase() === walletKey)?.[0]
1547
+ : undefined;
1548
+ if (onWallet !== undefined) {
1549
+ // The live verdict, as for a start: a runtime running blind is not a clean install.
1550
+ const unwired = unwiredRuntimes.get(onWallet);
1551
+ return unwired ? { outcome: "running", runtimeId: onWallet, unwired } : { outcome: "running", runtimeId: onWallet };
1552
+ }
1553
+ const { readRegistry } = await import("./runtime/strategy-registry.js");
1554
+ const entry = (await readRegistry(baseStateDir)).runtimes.find((e) => e.id === runtimeId);
1555
+ if (!entry)
1556
+ return { outcome: "no-row" };
1557
+ const inputs = factsPlanInputs(entry);
1558
+ if (!inputs)
1559
+ return { outcome: "failed", message: "its registry row has no readable recipe" };
1560
+ const parsedConfig = await loadRuntimeConfig(inputs.pathOrContent, { fromPath: inputs.fromPath });
1561
+ const started = await startRuntimeLive({
1562
+ runtimeId: entry.id,
1563
+ pathOrContent: inputs.pathOrContent,
1564
+ fromPath: inputs.fromPath,
1565
+ recipeDir: inputs.runtimeYamlDir,
1566
+ wallet: entry.wallet ?? "",
1567
+ parsedConfig,
1568
+ }, orphaned);
1569
+ if (started.status === "orphaned")
1570
+ return handOffRuntime(runtimeId, walletKey);
1571
+ pluginLogger.info("[senpi-runtime] started a runtime handed over by a stopped registration", {
1572
+ runtimeId: entry.id,
1573
+ });
1574
+ return started.unwiredPhase
1575
+ ? { outcome: "booted", runtimeId: entry.id, unwired: started.unwiredPhase }
1576
+ : { outcome: "booted", runtimeId: entry.id };
1577
+ }
1578
+ catch (err) {
1579
+ return { outcome: "failed", message: err instanceof Error ? err.message : String(err) };
1580
+ }
1581
+ }
1000
1582
  async function installRuntimeCore(params) {
1583
+ // How many times this registration's service had stopped when this install began; see `orphaned` below.
1584
+ const stopsAtInstall = serviceStops;
1001
1585
  const toError = (message) => ({ code: "INVALID_REQUEST", message });
1002
1586
  const toUnavailable = (message) => ({ code: "UNAVAILABLE", message });
1003
1587
  const { readRegistry, writeRegistry, withRegistryLock, validateEntry, hasId, findByWallet, deriveRuntimeId, sanitizeId } = await import("./runtime/strategy-registry.js");
@@ -1265,127 +1849,64 @@ const senpiRuntimePlugin = {
1265
1849
  const current = await readRegistry(baseStateDir);
1266
1850
  await writeRegistry(baseStateDir, { ...current, runtimes: [...current.runtimes, entry] });
1267
1851
  });
1268
- /**
1269
- * The unwired verdict for THIS install, tracked locally rather than read back out of
1270
- * `unwiredRuntimes`, so the result reports what this call did and never a leftover verdict
1271
- * from an earlier runtime that happened to share the id. Set at each of the three sites that
1272
- * leave the runtime without live entry scanners; cleared by the wire-success path.
1273
- */
1274
- let unwiredPhase;
1852
+ // The registration's service stopped since this install began (a 10.x plugin reload): the
1853
+ // runtime belongs to the live registration, so this install hands it over instead of keeping
1854
+ // one in a stopped registration that nothing can stop or delete.
1855
+ const orphaned = () => serviceState === "stopped" || serviceStops !== stopsAtInstall;
1856
+ // Registry create fact — distinct from the runtime.started boot transition (which also fires
1857
+ // on a transient restart). Once per install, as soon as a registration runs the row: right
1858
+ // after run() here, or at the hand-off. Inside emitEvent's guard so telemetry never fails the
1859
+ // install.
1860
+ let createdEmitted = false;
1861
+ const emitCreated = () => {
1862
+ if (createdEmitted)
1863
+ return;
1864
+ createdEmitted = true;
1865
+ emitEvent(apiLogger, () => buildRuntimeCreatedEvent({ runtimeId: resolvedId, address: wallet, recipeName: runtimeName }));
1866
+ };
1867
+ const handOffInstall = async () => {
1868
+ const handOff = await handOffRuntime(resolvedId, walletKey);
1869
+ if (handOff.outcome === "running" || handOff.outcome === "booted" || handOff.outcome === "pending")
1870
+ emitCreated();
1871
+ return installHandOffResult(handOff, { id: resolvedId, name: runtimeName, wallet });
1872
+ };
1275
1873
  try {
1276
- const scannerProviders = await createScannerProvidersForRun({
1277
- mcpTransport,
1278
- apiKey,
1279
- });
1280
- const entryStateDir = buildRuntimeStateDir(baseStateDir, resolvedId, wallet);
1281
- const handle = await run(pathOrContent, {
1282
- fromPath: hasPath,
1283
- stateDir: entryStateDir,
1284
- mcpTransport,
1285
- apiKey,
1286
- scannerProviders,
1874
+ // Stopped before the start: do not start a runtime here at all.
1875
+ if (orphaned())
1876
+ return await handOffInstall();
1877
+ const started = await startRuntimeLive({
1287
1878
  runtimeId: resolvedId,
1288
- onStrategyNotActive: (address) => reaper.checkWallet(address),
1289
- });
1290
- runtimeHandles.set(resolvedId, handle);
1291
- // Registry create fact — distinct from the runtime.started boot transition (which also fires
1292
- // on a transient restart). Emitted inside emitEvent's guard so telemetry never fails the install.
1293
- emitEvent(apiLogger, () => buildRuntimeCreatedEvent({ runtimeId: resolvedId, address: wallet, recipeName: runtimeName }));
1294
- // ── hot-install supervised scanner wire ───────────────────────────────
1295
- // Live-install path: used when a runtime is registered after boot via
1296
- // senpi.installRuntime, while the API is already listening — the
1297
- // counterpart to the boot-time `launcher` above. A runtime takes exactly
1298
- // one path: boot-present → `launcher` (deferred start); installed live →
1299
- // `hotLauncher` (immediate start). The two are mutually exclusive because
1300
- // installRuntime rejects any id/wallet already in the registry before
1301
- // wiring (the hasId guard), so a boot-present runtime never re-enters here.
1302
- // The API is already listening at this point, so we wire and start
1303
- // immediately (no deferred start needed). Any failure is swallowed so
1304
- // the install itself is not rolled back — the runtime is already up.
1305
- // Gate on the same API-disabled flag as the boot path: when the HTTP API
1306
- // is off (a test-only seam), the /signals route is never mounted, so
1307
- // starting scanners would only spawn children that POST to a closed port.
1308
- if (parsedConfig &&
1309
- sharedIntakeContext &&
1310
- process.env.SENPI_RUNTIME_API_DISABLED !== "true") {
1311
- try {
1312
- const apiConfig = loadApiConfig(api.pluginConfig);
1313
- const scaffoldPackageDir = fileURLToPath(new URL("./scanners/external", import.meta.url));
1314
- const entryStateDir = buildRuntimeStateDir(baseStateDir, resolvedId, wallet);
1315
- const hotLauncher = wireRuntime({
1316
- runtimeConfig: parsedConfig,
1317
- recipeDir: hasPath ? dirname(pathOrContent) : runtimeYamlDir,
1318
- runtimeId: resolvedId,
1319
- wallet,
1320
- sharedCtx: sharedIntakeContext,
1321
- runtimeHandles,
1322
- intakeUrl: intakeUrlFor(apiConfig.host, apiConfig.port),
1323
- scaffoldPackageDir,
1324
- runtimeStateDir: entryStateDir,
1325
- logger: apiLogger,
1326
- });
1327
- if (hotLauncher) {
1328
- try {
1329
- await hotLauncher.start();
1330
- launchers.set(resolvedId, hotLauncher);
1331
- unwiredRuntimes.delete(resolvedId);
1332
- unwiredPhase = undefined;
1333
- runtimeHandles.get(resolvedId)?.attachSupervisionSource(() => ({
1334
- unwired: false,
1335
- rows: hotLauncher.describeSupervision(),
1336
- }));
1337
- }
1338
- catch (startErr) {
1339
- await hotLauncher.stop().catch(() => { });
1340
- unwiredRuntimes.set(resolvedId, "install_launch");
1341
- unwiredPhase = "install_launch";
1342
- runtimeHandles.get(resolvedId)?.attachSupervisionSource(() => ({
1343
- unwired: true,
1344
- unwiredPhase: "install_launch",
1345
- rows: [],
1346
- }));
1347
- eventScannersUnwired("install_launch", resolvedId, wallet, appendCause("[senpi-runtime] hot-install supervised scanner launch failed — runtime running without it", startErr), startErr);
1348
- }
1349
- }
1350
- }
1351
- catch (wireErr) {
1352
- // Wire failure must NOT fail the install — the runtime is already up. It IS reported
1353
- // across the result boundary (payload.unwired) so a funding caller can refuse it.
1354
- unwiredRuntimes.set(resolvedId, "install_wire");
1355
- unwiredPhase = "install_wire";
1356
- runtimeHandles.get(resolvedId)?.attachSupervisionSource(() => ({
1357
- unwired: true,
1358
- unwiredPhase: "install_wire",
1359
- rows: [],
1360
- }));
1361
- eventScannersUnwired("install_wire", resolvedId, wallet, appendCause("[senpi-runtime] hot-install wiring failed — runtime running without supervised scanners", wireErr), wireErr);
1362
- }
1363
- }
1364
- else if (parsedConfig && !sharedIntakeContext && selectScanners(parsedConfig).length > 0) {
1365
- // Supervised intake is DISABLED for the whole box (corrupt acceptance record).
1366
- // The wire block above is skipped, so this hot-installed runtime declares
1367
- // external scanners but has NO live entry scanners. Record that fail-closed
1368
- // state (state only, no new event) so listRuntimes/health don't lie.
1369
- unwiredRuntimes.set(resolvedId, "no_intake");
1370
- unwiredPhase = "no_intake";
1371
- runtimeHandles.get(resolvedId)?.attachSupervisionSource(() => ({
1372
- unwired: true,
1373
- unwiredPhase: "no_intake",
1374
- rows: [],
1375
- }));
1376
- }
1377
- // ──────────────────────────────────────────────────────────────────────
1879
+ pathOrContent,
1880
+ fromPath: hasPath,
1881
+ recipeDir: hasPath ? dirname(pathOrContent) : runtimeYamlDir,
1882
+ wallet,
1883
+ parsedConfig,
1884
+ }, orphaned, emitCreated);
1885
+ if (started.status === "orphaned")
1886
+ return await handOffInstall();
1378
1887
  return {
1379
1888
  ok: true,
1380
1889
  payload: {
1381
1890
  id: resolvedId,
1382
1891
  name: runtimeName,
1383
1892
  wallet,
1384
- ...(unwiredPhase ? { unwired: unwiredPhase } : {}),
1893
+ ...(started.unwiredPhase ? { unwired: started.unwiredPhase } : {}),
1385
1894
  },
1386
1895
  };
1387
1896
  }
1388
1897
  catch (err) {
1898
+ // run() threw after this registration's service stopped: the live registration may already
1899
+ // run this row (its boot read it), so it decides, not this catch. It runs it, or starts it,
1900
+ // or (no registration live yet) the next start does; only when it cannot start the row
1901
+ // either is the row removed, as below for an install with no reload.
1902
+ if (orphaned()) {
1903
+ const handOff = await handOffRuntime(resolvedId, walletKey);
1904
+ if (handOff.outcome !== "failed") {
1905
+ if (handOff.outcome !== "no-row")
1906
+ emitCreated();
1907
+ return installHandOffResult(handOff, { id: resolvedId, name: runtimeName, wallet });
1908
+ }
1909
+ }
1389
1910
  await withRegistryLock(baseStateDir, async () => {
1390
1911
  const current = await readRegistry(baseStateDir);
1391
1912
  await writeRegistry(baseStateDir, { ...current, runtimes: current.runtimes.filter((e) => e.id !== resolvedId) });
@@ -1450,6 +1971,12 @@ const senpiRuntimePlugin = {
1450
1971
  * unwired-verdict cleanup all happen exactly once, here.
1451
1972
  */
1452
1973
  async function deleteRuntimeCore(params) {
1974
+ // This registration's service stopped (a 10.x reload) and holds no runtimes; the live one does.
1975
+ // A delete from here (a deploy job from before the reload) would remove the row and archive the
1976
+ // state dir under a runtime that keeps trading.
1977
+ const live = liveHostIfStopped();
1978
+ if (live)
1979
+ return live.deleteRuntime(params);
1453
1980
  let targetId = typeof params?.id === "string" ? params.id : undefined;
1454
1981
  const targetAddress = typeof params?.address === "string" ? params.address : undefined;
1455
1982
  // Set only by the lifecycle reaper: why the strategy counts as gone (stamped on runtime.deleted)
@@ -1687,7 +2214,7 @@ const senpiRuntimePlugin = {
1687
2214
  * the strategy id is read for this one wallet; a failed read logs its reason and sends nothing.
1688
2215
  */
1689
2216
  function queueFactsSend(runtimeId, strategyIds) {
1690
- return factsSendLock.withKeyLock(runtimeId, async () => {
2217
+ return factsSendLock().withKeyLock(runtimeId, async () => {
1691
2218
  const { readRegistry } = await import("./runtime/strategy-registry.js");
1692
2219
  const entry = (await readRegistry(baseStateDir)).runtimes.find((e) => e.id === runtimeId);
1693
2220
  const inputs = entry ? factsPlanInputs(entry) : null;
@@ -1946,16 +2473,21 @@ const senpiRuntimePlugin = {
1946
2473
  },
1947
2474
  registryFindByWallet: findRegistryEntryByWallet,
1948
2475
  registryFindById: findRegistryEntryById,
1949
- getScannerRows: readScannerRows,
2476
+ // A deploy job outlives a reload; it reads the runtime where it runs (see `liveHostIfStopped`).
2477
+ getScannerRows: (id) => liveHostIfStopped()?.getScannerRows(id) ?? readScannerRows(id),
1950
2478
  // H4: `runtimeHandles` holds the live `run()` handles. A registry row without one is a
1951
2479
  // previous install whose runtime died before start — deploy must reinstall, not report it
1952
2480
  // adopted. `unwiredRuntimes` is the same judgement one step further in: a runtime that is up
1953
2481
  // but whose entry scanners never wired is running BLIND (the health surface already renders
1954
2482
  // it "running — NO ENTRY SCANNERS"), and reporting `install: skipped` over it would be the
1955
2483
  // same clean line over a runtime that cannot tick.
1956
- runtimeIsLive: async (id) => runtimeHandles.has(id) && !unwiredRuntimes.has(id),
2484
+ runtimeIsLive: async (id) => liveHostIfStopped()?.runtimeIsLive(id) ?? (runtimeHandles.has(id) && !unwiredRuntimes.has(id)),
1957
2485
  installPendingOnWallet: async (wallet) => installsInFlight.has(wallet.trim().toLowerCase()),
1958
- logger: { info: (line) => api.logger.info(`[senpi-runtime] ${line}`) },
2486
+ // The process logger, not this registration's: a deploy job outlives a reload.
2487
+ logger: {
2488
+ info: (line) => processLog.info(`[senpi-runtime] ${line}`),
2489
+ warn: (line) => processLog.warn(`[senpi-runtime] ${line}`),
2490
+ },
1959
2491
  });
1960
2492
  /**
1961
2493
  * Gateway shim for `senpi.ingestExternalScannerData`.
@@ -2158,6 +2690,8 @@ const senpiRuntimePlugin = {
2158
2690
  respond(true, {
2159
2691
  status: status ? { ...status, runtimeId } : null,
2160
2692
  updater,
2693
+ approvals: approvalsStatus(),
2694
+ deploy: { capabilities: DEPLOY_CAPABILITIES },
2161
2695
  });
2162
2696
  }
2163
2697
  catch (err) {
@@ -2170,7 +2704,7 @@ const senpiRuntimePlugin = {
2170
2704
  return;
2171
2705
  }
2172
2706
  const statuses = await collectRuntimeHealthStatuses(runtimeHandles, api.logger);
2173
- respond(true, { statuses, updater });
2707
+ respond(true, { statuses, updater, approvals: approvalsStatus(), deploy: { capabilities: DEPLOY_CAPABILITIES } });
2174
2708
  }, { scope: "operator.read" });
2175
2709
  api.registerGatewayMethod("senpi.getSystemState", async (ctx) => {
2176
2710
  const respond = ctx.respond;