@senpi/runtime 3.0.315 → 3.0.317

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/dist/index.js CHANGED
@@ -76,7 +76,8 @@ import { getDefaultPiiRedactor, initDefaultPiiRedactor } from "./telemetry/spans
76
76
  import { flushOtelLogs, initOtelSdk, otelInitSettled, shutdownOtelSdk, waitForOtelInit } from "./telemetry/otel-sdk.js";
77
77
  import { createBoxMemoryReader } from "./telemetry/box-memory.js";
78
78
  import { registerBoxMemoryGauges } from "./telemetry/metrics.js";
79
- import { walletMode } from "./senpi/simulation.js";
79
+ import { isSimulationAddress, walletMode } from "./senpi/simulation.js";
80
+ import { simulationRuntimeRemovalRemedy } from "./deploy/funding.js";
80
81
  import { getLogLevel, getLogLevelSource, parseLogLevel, setLogLevel, } from "./utils/logger.js";
81
82
  import { ExternalScannerIngestError, } from "./scanners/external-scanner-receiver.js";
82
83
  import { createLogger } from "./utils/logger.js";
@@ -91,6 +92,7 @@ import { EVENT_NAME, SENPI_ERROR_CODE, eventAttrs, scannerUnwiredErrorCode } fro
91
92
  import { registerAskUserQuestion } from "./questions/index.js";
92
93
  import { emitEvent } from "./actions/event-derivation.js";
93
94
  import { createLifecycleReaper, resolveReaperBootDelayMs, resolveReaperEnforcement, } from "./runtime/lifecycle-reaper.js";
95
+ import { guardedSimulationWallet, openSimulationRefusal } from "./runtime/delete-simulation-guard.js";
94
96
  import { buildRuntimeBootSkippedEvent, buildRuntimeBootStatusUnreadEvent, buildRuntimeCreatedEvent, buildRuntimeDeletedEvent, buildRuntimeUpdatedEvent, } from "./runtime/lifecycle-events.js";
95
97
  import { isWalletAddress } from "./utils/wallet-address.js";
96
98
  import { fileURLToPath } from "node:url";
@@ -204,6 +206,13 @@ const WALLET_INSTALL_IN_FLIGHT = `[${WALLET_INSTALL_IN_FLIGHT_CODE}]`;
204
206
  * anyone's money is being claimed, which is precisely why it must not answer with the wallet code.
205
207
  */
206
208
  const RUNTIME_ID_TAKEN = "[E_RUNTIME_ID_TAKEN]";
209
+ /** The tail of an install refusal that sends the reader to remove a runtime, in its wallet's world. */
210
+ function removeRuntimeHint(runtimeId, wallet, byIdFlag) {
211
+ if (wallet !== undefined && isSimulationAddress(wallet)) {
212
+ return `. ${simulationRuntimeRemovalRemedy(runtimeId, wallet.trim().toLowerCase())}`;
213
+ }
214
+ return `: openclaw senpi runtime delete ${byIdFlag ? "--id " : ""}${runtimeId}`;
215
+ }
207
216
  /**
208
217
  * One StrategyFacts send per runtime at a time, keyed on runtime id, across the whole process.
209
218
  * Held in the process state (`runtime/process-state.ts`), not this module: a 10.x plugin reload
@@ -1059,23 +1068,24 @@ const senpiRuntimePlugin = {
1059
1068
  // runtime/lifecycle-reaper.ts for the safety rule). Constructed here so both `run()` call sites
1060
1069
  // (boot and install) can hand it their not-active rejections; it does no I/O until started.
1061
1070
  const reaperBootDelayOverride = resolveReaperBootDelayMs(process.env);
1071
+ const readStrategyStatuses = async (wallets, signal) => {
1072
+ const client = mcpTransport ? new SenpiClient(mcpTransport) : new SenpiClient({ apiKey });
1073
+ if (!mcpTransport)
1074
+ await client.connect();
1075
+ try {
1076
+ return await client.listStrategiesForWallets(wallets, { signal });
1077
+ }
1078
+ finally {
1079
+ if (!mcpTransport)
1080
+ await client.disconnect().catch(() => { });
1081
+ }
1082
+ };
1062
1083
  const reaper = createLifecycleReaper({
1063
1084
  readRegistry: async () => {
1064
1085
  const { readRegistry } = await import("./runtime/strategy-registry.js");
1065
1086
  return readRegistry(baseStateDir);
1066
1087
  },
1067
- readStatuses: async (wallets, signal) => {
1068
- const client = mcpTransport ? new SenpiClient(mcpTransport) : new SenpiClient({ apiKey });
1069
- if (!mcpTransport)
1070
- await client.connect();
1071
- try {
1072
- return await client.listStrategiesForWallets(wallets, { signal });
1073
- }
1074
- finally {
1075
- if (!mcpTransport)
1076
- await client.disconnect().catch(() => { });
1077
- }
1078
- },
1088
+ readStatuses: readStrategyStatuses,
1079
1089
  deleteRuntime: async (id, reason, wallet) => {
1080
1090
  const result = await deleteRuntimeCore({ id, deleteReason: reason, expectWallet: wallet });
1081
1091
  return result.ok ? { ok: true } : { ok: false, code: result.error.code, message: result.error.message };
@@ -2003,7 +2013,7 @@ const senpiRuntimePlugin = {
2003
2013
  : deriveRuntimeId(runtimeName, wallet);
2004
2014
  const walletKey = (wallet ?? "").trim().toLowerCase();
2005
2015
  if (hasId(registry, resolvedId)) {
2006
- return { ok: false, error: toError(`${RUNTIME_ID_TAKEN} A runtime with id "${resolvedId}" already exists. Use a different id (e.g. --runtime-id another-name) or remove the existing one first: openclaw senpi runtime delete ${resolvedId}`) };
2016
+ return { ok: false, error: toError(`${RUNTIME_ID_TAKEN} A runtime with id "${resolvedId}" already exists. Use a different id (e.g. --runtime-id another-name) or remove the existing one first${removeRuntimeHint(resolvedId, registry.runtimes.find((e) => e.id === resolvedId)?.wallet, false)}`) };
2007
2017
  }
2008
2018
  /**
2009
2019
  * One runtime per wallet address — asked of PERSISTED state, not only of this process.
@@ -2059,7 +2069,7 @@ const senpiRuntimePlugin = {
2059
2069
  // it sends the reader to, because that is where the reader checks it.
2060
2070
  if (runtimeHandles.has(holderId)) {
2061
2071
  return { ok: false, error: toError(`${WALLET_HAS_RUNTIME} A runtime for wallet "${wallet}" is already running (runtime "${holderId}"). ` +
2062
- `Stop it first: openclaw senpi runtime delete --id ${holderId}`) };
2072
+ `Stop it first${removeRuntimeHint(holderId, wallet, true)}`) };
2063
2073
  }
2064
2074
  return { ok: false, error: toError(
2065
2075
  // What is CLAIMED here is only what the two reads above prove: a registry row exists,
@@ -2074,8 +2084,8 @@ const senpiRuntimePlugin = {
2074
2084
  `restart will try to start it — installing a second runtime on the same wallet would ` +
2075
2085
  `put two exit engines on one wallet's margin, each tracking its own high-water floor. ` +
2076
2086
  `Nothing was installed. See what that runtime is before removing anything: ` +
2077
- `openclaw senpi runtime list. If it is genuinely unwanted, remove it first: ` +
2078
- `openclaw senpi runtime delete --id ${holderId}`) };
2087
+ `openclaw senpi runtime list. If it is genuinely unwanted, remove it first` +
2088
+ removeRuntimeHint(holderId, wallet, true)) };
2079
2089
  }
2080
2090
  }
2081
2091
  if (walletKey)
@@ -2294,6 +2304,13 @@ const senpiRuntimePlugin = {
2294
2304
  const expectWallet = typeof params?.expectWallet === "string" && params.expectWallet.trim().length > 0
2295
2305
  ? params.expectWallet.trim().toLowerCase()
2296
2306
  : undefined;
2307
+ if (params?.refuseOpenSimulation !== undefined && typeof params.refuseOpenSimulation !== "boolean") {
2308
+ return { ok: false, error: {
2309
+ code: "INVALID_REQUEST",
2310
+ message: `[INVALID_REQUEST] refuseOpenSimulation must be true or false. Nothing was changed.`,
2311
+ } };
2312
+ }
2313
+ const refuseOpenSimulation = params?.refuseOpenSimulation === true;
2297
2314
  // Resolve target by address if id not provided
2298
2315
  if (!targetId && targetAddress) {
2299
2316
  const { readRegistry } = await import("./runtime/strategy-registry.js");
@@ -2323,10 +2340,10 @@ const senpiRuntimePlugin = {
2323
2340
  message: `Runtime "${id}" was not removed: another delete or an update is already running on it. Nothing was changed; the next lifecycle check re-reads it.`,
2324
2341
  } };
2325
2342
  }
2326
- return runtimeChangeLock.withKeyLock(id, () => deleteRuntimeLocked(id, deleteReason, expectWallet));
2343
+ return runtimeChangeLock.withKeyLock(id, () => deleteRuntimeLocked(id, deleteReason, expectWallet, refuseOpenSimulation));
2327
2344
  }
2328
2345
  /** {@link deleteRuntimeCore} past target resolution, under the runtime's change lock. */
2329
- async function deleteRuntimeLocked(targetId, deleteReason, expectWallet) {
2346
+ async function deleteRuntimeLocked(targetId, deleteReason, expectWallet, refuseOpenSimulation) {
2330
2347
  const { readRegistry, writeRegistry, withRegistryLock } = await import("./runtime/strategy-registry.js");
2331
2348
  // Read under the lock: a delete that waited behind another change sees what that change left.
2332
2349
  const registry = await readRegistry(baseStateDir);
@@ -2338,6 +2355,15 @@ const senpiRuntimePlugin = {
2338
2355
  message: `No runtime found with id "${targetId}".`,
2339
2356
  } };
2340
2357
  }
2358
+ const simulationWallet = refuseOpenSimulation
2359
+ ? guardedSimulationWallet(deletedEntry?.wallet ?? handle?.wallet)
2360
+ : undefined;
2361
+ if (simulationWallet !== undefined) {
2362
+ const read = await readWalletStatusesByWorld([simulationWallet], readStrategyStatuses);
2363
+ const refusal = openSimulationRefusal(targetId, simulationWallet, read);
2364
+ if (refusal !== undefined)
2365
+ return { ok: false, error: refusal };
2366
+ }
2341
2367
  /**
2342
2368
  * The lifecycle reaper's guard. Its verdict was about one wallet at one moment; the delete
2343
2369
  * below must not land on anything else. Evaluated synchronously between the registry read