@senpi-ai/runtime 3.0.98 → 3.0.105
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/cli/guide-commands.d.ts.map +1 -1
- package/dist/cli/guide-commands.js +38 -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 +29 -1
- package/dist/cli/senpi-commands.js.map +1 -1
- package/dist/cli/update-command.d.ts +69 -0
- package/dist/cli/update-command.d.ts.map +1 -0
- package/dist/cli/update-command.js +153 -0
- package/dist/cli/update-command.js.map +1 -0
- package/dist/dsl/plugin/index.d.ts +35 -1
- package/dist/dsl/plugin/index.d.ts.map +1 -1
- package/dist/dsl/plugin/index.js +62 -7
- package/dist/dsl/plugin/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +205 -27
- package/dist/index.js.map +1 -1
- package/dist/runtime/effective-config.d.ts +67 -0
- package/dist/runtime/effective-config.d.ts.map +1 -0
- package/dist/runtime/effective-config.js +324 -0
- package/dist/runtime/effective-config.js.map +1 -0
- package/dist/runtime/lifecycle-events.d.ts +19 -0
- package/dist/runtime/lifecycle-events.d.ts.map +1 -1
- package/dist/runtime/lifecycle-events.js +27 -0
- package/dist/runtime/lifecycle-events.js.map +1 -1
- package/dist/runtime/rebuild-errors.d.ts +26 -0
- package/dist/runtime/rebuild-errors.d.ts.map +1 -0
- package/dist/runtime/rebuild-errors.js +36 -0
- package/dist/runtime/rebuild-errors.js.map +1 -0
- package/dist/runtime/run.d.ts +10 -0
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +13 -1
- package/dist/runtime/run.js.map +1 -1
- package/dist/runtime/runtime.d.ts +146 -1
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +511 -148
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/strategy-registry.d.ts +1 -0
- package/dist/runtime/strategy-registry.d.ts.map +1 -1
- package/dist/runtime/strategy-registry.js +19 -0
- package/dist/runtime/strategy-registry.js.map +1 -1
- package/dist/runtime/update-apply-deps.d.ts +101 -0
- package/dist/runtime/update-apply-deps.d.ts.map +1 -0
- package/dist/runtime/update-apply-deps.js +159 -0
- package/dist/runtime/update-apply-deps.js.map +1 -0
- package/dist/runtime/update-handler.d.ts +197 -0
- package/dist/runtime/update-handler.d.ts.map +1 -0
- package/dist/runtime/update-handler.js +381 -0
- package/dist/runtime/update-handler.js.map +1 -0
- package/dist/runtime/update-plan.d.ts +60 -0
- package/dist/runtime/update-plan.d.ts.map +1 -0
- package/dist/runtime/update-plan.js +203 -0
- package/dist/runtime/update-plan.js.map +1 -0
- package/dist/runtime/update-register.d.ts +67 -0
- package/dist/runtime/update-register.d.ts.map +1 -0
- package/dist/runtime/update-register.js +173 -0
- package/dist/runtime/update-register.js.map +1 -0
- package/dist/runtime/update-report.d.ts +125 -0
- package/dist/runtime/update-report.d.ts.map +1 -0
- package/dist/runtime/update-report.js +215 -0
- package/dist/runtime/update-report.js.map +1 -0
- package/dist/runtime-api/intake/intake-events.d.ts +4 -2
- package/dist/runtime-api/intake/intake-events.d.ts.map +1 -1
- package/dist/runtime-api/intake/intake-events.js +4 -2
- package/dist/runtime-api/intake/intake-events.js.map +1 -1
- package/dist/runtime-api/intake/intake-mount.d.ts +2 -0
- package/dist/runtime-api/intake/intake-mount.d.ts.map +1 -1
- package/dist/runtime-api/intake/intake-mount.js +8 -20
- package/dist/runtime-api/intake/intake-mount.js.map +1 -1
- package/dist/runtime-api/intake/scaffold-error-router.d.ts +43 -0
- package/dist/runtime-api/intake/scaffold-error-router.d.ts.map +1 -0
- package/dist/runtime-api/intake/scaffold-error-router.js +63 -0
- package/dist/runtime-api/intake/scaffold-error-router.js.map +1 -0
- package/dist/scanners/external/scaffold/scaffold.py +94 -1
- package/dist/scanners/external/scaffold/senpi_mcp.py +427 -71
- package/dist/utils/event-catalog.d.ts +29 -2
- package/dist/utils/event-catalog.d.ts.map +1 -1
- package/dist/utils/event-catalog.js +2 -1
- package/dist/utils/event-catalog.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,11 +12,14 @@
|
|
|
12
12
|
* the loader's relative-import path entirely.
|
|
13
13
|
*/
|
|
14
14
|
import { readFileSync } from "node:fs";
|
|
15
|
+
import { parse as parseYaml } from "yaml";
|
|
15
16
|
import { join, dirname } from "node:path";
|
|
16
17
|
import { SenpiClient } from "./senpi/client.js";
|
|
17
18
|
import { buildWalletStatusHint } from "./senpi/strategy-status.js";
|
|
18
19
|
import { DeployJobController } from "./deploy/job.js";
|
|
19
20
|
import { registerDeployGatewayMethods } from "./deploy/register.js";
|
|
21
|
+
import { registerUpdateGatewayMethod } from "./runtime/update-register.js";
|
|
22
|
+
import { checkProofCoversRecipe, makeApplyToRuntime, makeWriteRegistry, } from "./runtime/update-apply-deps.js";
|
|
20
23
|
import { INSTALL_DEADLINE_MS, WALLET_INSTALL_IN_FLIGHT_CODE } from "./deploy/deadlines.js";
|
|
21
24
|
import { AuditQueryError } from "./runtime/audit-query.types.js";
|
|
22
25
|
import { buildRuntimeStateDir, archiveStateDir } from "./runtime/state-layout.js";
|
|
@@ -48,7 +51,7 @@ import { createLogger } from "./utils/logger.js";
|
|
|
48
51
|
import { registerToolApprovalGate, resolveToolApprovalsMode, } from "./approvals/tool-approval-gate.js";
|
|
49
52
|
import { EVENT_NAME, SENPI_ERROR_CODE, eventAttrs, scannerUnwiredErrorCode } from "./utils/event-catalog.js";
|
|
50
53
|
import { emitEvent } from "./actions/event-derivation.js";
|
|
51
|
-
import { buildRuntimeCreatedEvent, buildRuntimeDeletedEvent } from "./runtime/lifecycle-events.js";
|
|
54
|
+
import { buildRuntimeCreatedEvent, buildRuntimeDeletedEvent, buildRuntimeUpdatedEvent } from "./runtime/lifecycle-events.js";
|
|
52
55
|
import { isWalletAddress } from "./utils/wallet-address.js";
|
|
53
56
|
import { fileURLToPath } from "node:url";
|
|
54
57
|
import { loadApiConfig } from "./runtime-api/config.js";
|
|
@@ -57,6 +60,7 @@ import { ingestSignalsHandler } from "./runtime-api/handlers/ingest-signals.js";
|
|
|
57
60
|
import { createIntakeContext } from "./runtime-api/intake/intake-context.js";
|
|
58
61
|
import { wireRuntime, intakeUrlFor, selectScanners } from "./runtime-api/intake/intake-mount.js";
|
|
59
62
|
import { ingestDispatchMutex, ingestDispatchKey } from "./runtime-api/intake/ingest-mutex.js";
|
|
63
|
+
import { buildScaffoldErrorRouter } from "./runtime-api/intake/scaffold-error-router.js";
|
|
60
64
|
import { loadRuntimeConfig } from "./runtime/load-runtime-config.js";
|
|
61
65
|
/** Initialize all core features (DSL, risk, health) on the given event bus. */
|
|
62
66
|
export function initCore(bus) {
|
|
@@ -175,8 +179,21 @@ const senpiRuntimePlugin = {
|
|
|
175
179
|
},
|
|
176
180
|
},
|
|
177
181
|
register(api) {
|
|
182
|
+
// `--json` promises ONE document on stdout, and `api.logger.info` writes there. Startup
|
|
183
|
+
// diagnostics therefore land ahead of the document and no consumer can parse it — measured on a
|
|
184
|
+
// live box, where `senpi update --json`, `runtime list --json` and `dsl positions --json` were
|
|
185
|
+
// all unparseable, and not even recoverable by skipping to the first `{` because the ANSI colour
|
|
186
|
+
// codes contain braces.
|
|
187
|
+
//
|
|
188
|
+
// The diagnostics are not dropped, only moved to stderr where diagnostics belong. Warnings and
|
|
189
|
+
// errors are left on the logger untouched: those are not routine chatter, and a caller piping
|
|
190
|
+
// stdout to a parser still wants them visible.
|
|
191
|
+
const jsonMode = process.argv.includes("--json");
|
|
178
192
|
const pluginLogger = {
|
|
179
|
-
info: (...args) =>
|
|
193
|
+
info: (...args) =>
|
|
194
|
+
// No added prefix: these messages already carry their own `[senpi-runtime]` /
|
|
195
|
+
// `[senpi-tool-approvals]` tag, and prepending another produced doubled labels on stderr.
|
|
196
|
+
jsonMode ? console.error(...args) : api.logger.info(...args),
|
|
180
197
|
warn: (...args) => api.logger.warn(...args),
|
|
181
198
|
error: (message, meta) => api.logger.error(message, meta),
|
|
182
199
|
};
|
|
@@ -525,22 +542,15 @@ const senpiRuntimePlugin = {
|
|
|
525
542
|
// The single server-level onError closure — the `/errors` counterpart of
|
|
526
543
|
// routeAcceptedSignalToRuntime. It records a scaffold-reported tick failure into
|
|
527
544
|
// the owning runtime's scanner telemetry so a scanner that fails every tick stops
|
|
528
|
-
// rendering "healthy".
|
|
529
|
-
//
|
|
530
|
-
//
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
if (!resolved)
|
|
538
|
-
return;
|
|
539
|
-
const h = runtimeHandles.get(resolved.runtimeId);
|
|
540
|
-
if (!h)
|
|
541
|
-
return;
|
|
542
|
-
h.recordExternalScannerError(resolved.scannerName, error);
|
|
543
|
-
};
|
|
545
|
+
// rendering "healthy".
|
|
546
|
+
//
|
|
547
|
+
// This is the SHARED implementation (scaffold-error-router.ts), not a copy of
|
|
548
|
+
// buildIntakeMount's onScaffoldError. It used to be a copy, and the copy had its
|
|
549
|
+
// own hardcoded three-type filter: when `mcp_error` was added to the tick-failure
|
|
550
|
+
// list it reached the tested seam and never reached this route, so the
|
|
551
|
+
// wedged-scanner signal was green in CI and inert in production. There is now one
|
|
552
|
+
// filter, and scaffold-error-router.test.ts drives THIS closure.
|
|
553
|
+
routeScaffoldErrorToRuntime = buildScaffoldErrorRouter(ctx, runtimeHandles);
|
|
544
554
|
}
|
|
545
555
|
const started = [];
|
|
546
556
|
try {
|
|
@@ -776,7 +786,7 @@ const senpiRuntimePlugin = {
|
|
|
776
786
|
async function installRuntimeCore(params) {
|
|
777
787
|
const toError = (message) => ({ code: "INVALID_REQUEST", message });
|
|
778
788
|
const toUnavailable = (message) => ({ code: "UNAVAILABLE", message });
|
|
779
|
-
const { readRegistry, writeRegistry, validateEntry, hasId, findByWallet, deriveRuntimeId, sanitizeId } = await import("./runtime/strategy-registry.js");
|
|
789
|
+
const { readRegistry, writeRegistry, withRegistryLock, validateEntry, hasId, findByWallet, deriveRuntimeId, sanitizeId } = await import("./runtime/strategy-registry.js");
|
|
780
790
|
const id = typeof params?.id === "string" ? params.id : undefined;
|
|
781
791
|
const runtimeYamlPath = typeof params?.runtimeYamlPath === "string" ? params.runtimeYamlPath : undefined;
|
|
782
792
|
const runtimeYamlContent = typeof params?.runtimeYamlContent === "string" ? params.runtimeYamlContent : undefined;
|
|
@@ -1034,8 +1044,13 @@ const senpiRuntimePlugin = {
|
|
|
1034
1044
|
if (!valid.ok) {
|
|
1035
1045
|
return { ok: false, error: toError(valid.error) };
|
|
1036
1046
|
}
|
|
1037
|
-
registry
|
|
1038
|
-
|
|
1047
|
+
// Re-read under the registry lock rather than writing back `registry`: that snapshot predates
|
|
1048
|
+
// the gate and the checks above, and writing it would drop whatever another writer (an
|
|
1049
|
+
// update, a delete) changed in between. Same for the rollback and for delete below.
|
|
1050
|
+
await withRegistryLock(baseStateDir, async () => {
|
|
1051
|
+
const current = await readRegistry(baseStateDir);
|
|
1052
|
+
await writeRegistry(baseStateDir, { ...current, runtimes: [...current.runtimes, entry] });
|
|
1053
|
+
});
|
|
1039
1054
|
/**
|
|
1040
1055
|
* The unwired verdict for THIS install, tracked locally rather than read back out of
|
|
1041
1056
|
* `unwiredRuntimes`, so the result reports what this call did and never a leftover verdict
|
|
@@ -1156,8 +1171,10 @@ const senpiRuntimePlugin = {
|
|
|
1156
1171
|
};
|
|
1157
1172
|
}
|
|
1158
1173
|
catch (err) {
|
|
1159
|
-
|
|
1160
|
-
|
|
1174
|
+
await withRegistryLock(baseStateDir, async () => {
|
|
1175
|
+
const current = await readRegistry(baseStateDir);
|
|
1176
|
+
await writeRegistry(baseStateDir, { ...current, runtimes: current.runtimes.filter((e) => e.id !== resolvedId) });
|
|
1177
|
+
});
|
|
1161
1178
|
const msg = err instanceof Error ? err.message : String(err);
|
|
1162
1179
|
return { ok: false, error: toUnavailable(`Could not start the runtime. This is usually due to invalid or incomplete YAML.\n\n${msg}`) };
|
|
1163
1180
|
}
|
|
@@ -1211,7 +1228,7 @@ const senpiRuntimePlugin = {
|
|
|
1211
1228
|
* unwired-verdict cleanup all happen exactly once, here.
|
|
1212
1229
|
*/
|
|
1213
1230
|
async function deleteRuntimeCore(params) {
|
|
1214
|
-
const { readRegistry, writeRegistry } = await import("./runtime/strategy-registry.js");
|
|
1231
|
+
const { readRegistry, writeRegistry, withRegistryLock } = await import("./runtime/strategy-registry.js");
|
|
1215
1232
|
const registry = await readRegistry(baseStateDir);
|
|
1216
1233
|
let targetId = typeof params?.id === "string" ? params.id : undefined;
|
|
1217
1234
|
const targetAddress = typeof params?.address === "string" ? params.address : undefined;
|
|
@@ -1272,8 +1289,10 @@ const senpiRuntimePlugin = {
|
|
|
1272
1289
|
}
|
|
1273
1290
|
}
|
|
1274
1291
|
if (deletedEntry) {
|
|
1275
|
-
|
|
1276
|
-
|
|
1292
|
+
await withRegistryLock(baseStateDir, async () => {
|
|
1293
|
+
const current = await readRegistry(baseStateDir);
|
|
1294
|
+
await writeRegistry(baseStateDir, { ...current, runtimes: current.runtimes.filter((e) => e.id !== targetId) });
|
|
1295
|
+
});
|
|
1277
1296
|
}
|
|
1278
1297
|
// Registry delete fact — the permanent-removal discriminator a transient runtime.stopped can't
|
|
1279
1298
|
// give. Unconditional (a never-booted runtime stops no handle, so emits no runtime.stopped) and
|
|
@@ -1346,6 +1365,165 @@ const senpiRuntimePlugin = {
|
|
|
1346
1365
|
return null;
|
|
1347
1366
|
}
|
|
1348
1367
|
}
|
|
1368
|
+
// `senpi update` — plan only. Internal transport for the CLI verb, like senpi.deploy.*.
|
|
1369
|
+
registerUpdateGatewayMethod(api, {
|
|
1370
|
+
listRuntimes: async () => {
|
|
1371
|
+
const { readRegistry } = await import("./runtime/strategy-registry.js");
|
|
1372
|
+
const registry = await readRegistry(baseStateDir);
|
|
1373
|
+
return registry.runtimes.map((e) => ({
|
|
1374
|
+
id: e.id,
|
|
1375
|
+
wallet: e.wallet ?? "",
|
|
1376
|
+
source: typeof e.runtimeYamlPath === "string" && e.runtimeYamlPath.length > 0
|
|
1377
|
+
? { path: e.runtimeYamlPath }
|
|
1378
|
+
: {
|
|
1379
|
+
content: e.runtimeYamlContent ?? "",
|
|
1380
|
+
...(e.runtimeYamlDir ? { dir: e.runtimeYamlDir } : {}),
|
|
1381
|
+
},
|
|
1382
|
+
}));
|
|
1383
|
+
},
|
|
1384
|
+
parseConfig: async (source) => {
|
|
1385
|
+
const { loadRuntimeConfig } = await import("./runtime/load-runtime-config.js");
|
|
1386
|
+
return source.path !== undefined
|
|
1387
|
+
? loadRuntimeConfig(source.path, { fromPath: true })
|
|
1388
|
+
: loadRuntimeConfig(source.content ?? "", { fromPath: false });
|
|
1389
|
+
},
|
|
1390
|
+
// Full DslState rather than the position summaries: the report needs `handoffStatus` to say
|
|
1391
|
+
// which positions the backend ratchet owns, and the summary shape drops it.
|
|
1392
|
+
activePositions: async (runtimeId) => {
|
|
1393
|
+
const handle = runtimeHandles.get(runtimeId);
|
|
1394
|
+
return handle?.dsl?.listActiveDslStates() ?? [];
|
|
1395
|
+
},
|
|
1396
|
+
recipeFindings: async (source) => {
|
|
1397
|
+
const { collectRecipeFindings } = await import("./validate/recipe.js");
|
|
1398
|
+
const baseDir = source.path !== undefined ? dirname(source.path) : source.dir;
|
|
1399
|
+
const result = await collectRecipeFindings(source.path !== undefined
|
|
1400
|
+
? { path: source.path, baseDir }
|
|
1401
|
+
: { content: source.content ?? "", baseDir });
|
|
1402
|
+
return result.findings;
|
|
1403
|
+
},
|
|
1404
|
+
installGate: async (findings) => {
|
|
1405
|
+
const { checkInstallGate } = await import("./validate/install-gate.js");
|
|
1406
|
+
const gate = checkInstallGate(findings);
|
|
1407
|
+
return { ok: gate.ok, blocking: gate.blocking };
|
|
1408
|
+
},
|
|
1409
|
+
verifyProof: async (packageDir, appliedRecipe) => {
|
|
1410
|
+
const { verifyProof } = await import("./validate/index.js");
|
|
1411
|
+
return checkProofCoversRecipe(packageDir, verifyProof(packageDir), appliedRecipe, (f) => readFileSync(f, "utf8"));
|
|
1412
|
+
},
|
|
1413
|
+
applyToRuntime: makeApplyToRuntime(runtimeHandles, async (runtimeId, next, recipe) => {
|
|
1414
|
+
// Restart this runtime's external scanner children against the new package.
|
|
1415
|
+
//
|
|
1416
|
+
// The rebuild swaps in-process components; these are separate OS processes, spawned once
|
|
1417
|
+
// from a launch config written at install and reading their entrypoint at spawn. Without
|
|
1418
|
+
// this, an apply reported success while every external scanner went on running the code,
|
|
1419
|
+
// `inputs` and cadence it booted with.
|
|
1420
|
+
//
|
|
1421
|
+
// Same shape as the hot-install path above, plus stopping the outgoing launcher first.
|
|
1422
|
+
if (!sharedIntakeContext || process.env.SENPI_RUNTIME_API_DISABLED === "true")
|
|
1423
|
+
return {};
|
|
1424
|
+
const wallet = runtimeHandles.get(runtimeId)?.wallet ?? "";
|
|
1425
|
+
const previous = launchers.get(runtimeId);
|
|
1426
|
+
if (previous) {
|
|
1427
|
+
// Stopped before the replacement is built: two supervisors on one scanner would both
|
|
1428
|
+
// spawn a child against the same state directory and delivery journal.
|
|
1429
|
+
await previous.stop().catch(() => { });
|
|
1430
|
+
launchers.delete(runtimeId);
|
|
1431
|
+
}
|
|
1432
|
+
let launcher = null;
|
|
1433
|
+
try {
|
|
1434
|
+
const apiConfig = loadApiConfig(api.pluginConfig);
|
|
1435
|
+
launcher = wireRuntime({
|
|
1436
|
+
runtimeConfig: next,
|
|
1437
|
+
// Where a scanner's relative `path: ./scanners` resolves. The apply carries the package
|
|
1438
|
+
// directory precisely so this keeps working for a recipe supplied as content.
|
|
1439
|
+
recipeDir: recipe.dir ?? (recipe.path !== undefined ? dirname(recipe.path) : undefined),
|
|
1440
|
+
runtimeId,
|
|
1441
|
+
wallet,
|
|
1442
|
+
sharedCtx: sharedIntakeContext,
|
|
1443
|
+
runtimeHandles,
|
|
1444
|
+
intakeUrl: intakeUrlFor(apiConfig.host, apiConfig.port),
|
|
1445
|
+
scaffoldPackageDir: fileURLToPath(new URL("./scanners/external", import.meta.url)),
|
|
1446
|
+
runtimeStateDir: buildRuntimeStateDir(baseStateDir, runtimeId, wallet),
|
|
1447
|
+
logger: apiLogger,
|
|
1448
|
+
});
|
|
1449
|
+
if (!launcher) {
|
|
1450
|
+
// The new recipe declares no external scanners. The old children are already stopped,
|
|
1451
|
+
// and reporting "not unwired, no rows" is the truth rather than a fault.
|
|
1452
|
+
unwiredRuntimes.delete(runtimeId);
|
|
1453
|
+
runtimeHandles.get(runtimeId)?.attachSupervisionSource(() => ({ unwired: false, rows: [] }));
|
|
1454
|
+
return {};
|
|
1455
|
+
}
|
|
1456
|
+
await launcher.start();
|
|
1457
|
+
launchers.set(runtimeId, launcher);
|
|
1458
|
+
unwiredRuntimes.delete(runtimeId);
|
|
1459
|
+
const started = launcher;
|
|
1460
|
+
// Re-pointed at the NEW launcher: the runtime remembers the source it was handed, but
|
|
1461
|
+
// that closure reads the outgoing launcher, which is now stopped.
|
|
1462
|
+
runtimeHandles.get(runtimeId)?.attachSupervisionSource(() => ({
|
|
1463
|
+
unwired: false,
|
|
1464
|
+
rows: started.describeSupervision(),
|
|
1465
|
+
}));
|
|
1466
|
+
return {};
|
|
1467
|
+
}
|
|
1468
|
+
catch (err) {
|
|
1469
|
+
// `start()` loops over every scanner, so a throw on the third leaves the first two
|
|
1470
|
+
// supervisors already spawning and restarting children. `launchers.set` never ran, so
|
|
1471
|
+
// the object is unreachable — neither shutdown nor `runtime delete` iterate to it — and
|
|
1472
|
+
// those children would be respawned for the life of the gateway process. The hot-install
|
|
1473
|
+
// path stops a half-started launcher for exactly this reason; this one must too.
|
|
1474
|
+
if (launcher)
|
|
1475
|
+
await launcher.stop().catch(() => { });
|
|
1476
|
+
// Deliberately not rethrown. The recipe is already live in-process, so failing the apply
|
|
1477
|
+
// here would report FAILED over a change that did land. It is a degraded runtime —
|
|
1478
|
+
// recorded the same way a failed hot-install launch is, and visible in scanner health.
|
|
1479
|
+
unwiredRuntimes.set(runtimeId, "update_launch");
|
|
1480
|
+
runtimeHandles.get(runtimeId)?.attachSupervisionSource(() => ({
|
|
1481
|
+
unwired: true,
|
|
1482
|
+
unwiredPhase: "update_launch",
|
|
1483
|
+
rows: [],
|
|
1484
|
+
}));
|
|
1485
|
+
eventScannersUnwired("update_launch", runtimeId, wallet, appendCause("[senpi-runtime] scanner relaunch after update failed — runtime is running the new " +
|
|
1486
|
+
"recipe with NO external scanners", err), err);
|
|
1487
|
+
// Reported, not thrown: the recipe IS live, so this is a degraded runtime rather than a
|
|
1488
|
+
// failed apply. The caller renders it as a warning on an otherwise successful report.
|
|
1489
|
+
return { unwired: err instanceof Error ? err.message : String(err) };
|
|
1490
|
+
}
|
|
1491
|
+
}),
|
|
1492
|
+
writeRegistry: makeWriteRegistry(baseStateDir),
|
|
1493
|
+
onApplied: (info) => {
|
|
1494
|
+
// The audit answer to "who changed this strategy and to what". Hashed over the UNRESOLVED
|
|
1495
|
+
// recipe so the value is comparable with the one `runtime.started` stamps — otherwise the
|
|
1496
|
+
// same attribute name would carry two incomparable hashes and a restart could not be told
|
|
1497
|
+
// apart from a revert. Inside emitEvent's guard so telemetry never fails an apply that has
|
|
1498
|
+
// already landed.
|
|
1499
|
+
emitEvent(apiLogger, () => {
|
|
1500
|
+
const unresolved = (source) => {
|
|
1501
|
+
try {
|
|
1502
|
+
const raw = source.path !== undefined
|
|
1503
|
+
? readFileSync(source.path, "utf8")
|
|
1504
|
+
: (source.content ?? "");
|
|
1505
|
+
return parseYaml(raw);
|
|
1506
|
+
}
|
|
1507
|
+
catch {
|
|
1508
|
+
// A hash is worth less than the event carrying it; an unreadable previous recipe must
|
|
1509
|
+
// not swallow the record that the update happened.
|
|
1510
|
+
return undefined;
|
|
1511
|
+
}
|
|
1512
|
+
};
|
|
1513
|
+
return buildRuntimeUpdatedEvent({
|
|
1514
|
+
runtimeId: info.runtimeId,
|
|
1515
|
+
...(info.address ? { address: info.address } : {}),
|
|
1516
|
+
...(unresolved(info.recipe) ? { unresolvedConfig: unresolved(info.recipe) } : {}),
|
|
1517
|
+
...(unresolved(info.previousRecipe)
|
|
1518
|
+
? { previousUnresolvedConfig: unresolved(info.previousRecipe) }
|
|
1519
|
+
: {}),
|
|
1520
|
+
exitPresetChanged: info.exitPresetChanged,
|
|
1521
|
+
openPositions: info.openPositions,
|
|
1522
|
+
...(info.slots !== undefined ? { slots: info.slots } : {}),
|
|
1523
|
+
});
|
|
1524
|
+
});
|
|
1525
|
+
},
|
|
1526
|
+
});
|
|
1349
1527
|
registerDeployGatewayMethods(api, {
|
|
1350
1528
|
controller: deployController,
|
|
1351
1529
|
withSenpiClient,
|
|
@@ -1956,7 +2134,7 @@ const senpiRuntimePlugin = {
|
|
|
1956
2134
|
});
|
|
1957
2135
|
}
|
|
1958
2136
|
}, { scope: "operator.write" });
|
|
1959
|
-
|
|
2137
|
+
pluginLogger.info(`[senpi-runtime] v${VERSION} plugin registered — stateDir: ${baseStateDir}`);
|
|
1960
2138
|
},
|
|
1961
2139
|
};
|
|
1962
2140
|
function getRuntimeHandleOrRespond(runtimeHandles, runtimeId, respond) {
|