@senpi-ai/runtime 3.0.119 → 3.0.121
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/actions/open-position/open-position.action.d.ts.map +1 -1
- package/dist/actions/open-position/open-position.action.js +9 -0
- package/dist/actions/open-position/open-position.action.js.map +1 -1
- package/dist/cli/guide-commands.d.ts.map +1 -1
- package/dist/cli/guide-commands.js +10 -2
- package/dist/cli/guide-commands.js.map +1 -1
- package/dist/constants/dsl/index.d.ts +24 -0
- package/dist/constants/dsl/index.d.ts.map +1 -1
- package/dist/constants/dsl/index.js +24 -0
- package/dist/constants/dsl/index.js.map +1 -1
- package/dist/dsl/plugin/index.d.ts +21 -0
- package/dist/dsl/plugin/index.d.ts.map +1 -1
- package/dist/dsl/plugin/index.js +96 -4
- package/dist/dsl/plugin/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +122 -8
- package/dist/index.js.map +1 -1
- package/dist/runtime/boot-skip.d.ts +21 -0
- package/dist/runtime/boot-skip.d.ts.map +1 -1
- package/dist/runtime/boot-skip.js +34 -0
- package/dist/runtime/boot-skip.js.map +1 -1
- package/dist/runtime/create-runtime-context.d.ts +2 -0
- package/dist/runtime/create-runtime-context.d.ts.map +1 -1
- package/dist/runtime/create-runtime-context.js +1 -0
- package/dist/runtime/create-runtime-context.js.map +1 -1
- package/dist/runtime/lifecycle-events.d.ts +31 -1
- package/dist/runtime/lifecycle-events.d.ts.map +1 -1
- package/dist/runtime/lifecycle-events.js +56 -1
- package/dist/runtime/lifecycle-events.js.map +1 -1
- package/dist/runtime/lifecycle-reaper.d.ts +202 -0
- package/dist/runtime/lifecycle-reaper.d.ts.map +1 -0
- package/dist/runtime/lifecycle-reaper.js +390 -0
- package/dist/runtime/lifecycle-reaper.js.map +1 -0
- package/dist/runtime/run.d.ts +5 -0
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +1 -0
- package/dist/runtime/run.js.map +1 -1
- package/dist/runtime/runtime.d.ts +2 -0
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +1 -0
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/update-apply-deps.d.ts +23 -2
- package/dist/runtime/update-apply-deps.d.ts.map +1 -1
- package/dist/runtime/update-apply-deps.js +11 -5
- package/dist/runtime/update-apply-deps.js.map +1 -1
- package/dist/skills-manager/manifest.d.ts.map +1 -1
- package/dist/skills-manager/manifest.js +1 -0
- package/dist/skills-manager/manifest.js.map +1 -1
- package/dist/skills-manager/skills-manifest.json +1 -0
- package/dist/types/runtime.d.ts +8 -0
- package/dist/types/runtime.d.ts.map +1 -1
- package/dist/utils/event-catalog.d.ts +65 -0
- package/dist/utils/event-catalog.d.ts.map +1 -1
- package/dist/utils/event-catalog.js +10 -0
- package/dist/utils/event-catalog.js.map +1 -1
- package/dist/utils/keyed-mutex.d.ts +3 -2
- package/dist/utils/keyed-mutex.d.ts.map +1 -1
- package/dist/utils/keyed-mutex.js +3 -2
- package/dist/utils/keyed-mutex.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAsDH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAmB3D,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,mCAAmC,CAAC;AA+B3C,+EAA+E;AAC/E,wBAAgB,QAAQ,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,CAIjD;AAGD,OAAO,EACL,OAAO,EACP,SAAS,EACT,SAAS,EACT,cAAc,EACd,oBAAoB,EACpB,w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Q,CAAC,EAAE,MAAM,CAAA;KAAE,GAC3B,IAAI,CAAC;CACT;AAgFD;;;GAGG;AACH,QAAA,MAAM,kBAAkB;;;;;;qBAUP,OAAO;;kBAQR,SAAS;CA2wExB,CAAC;AAmLF,eAAe,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -16,11 +16,11 @@ import { parse as parseYaml } from "yaml";
|
|
|
16
16
|
import { join, dirname } from "node:path";
|
|
17
17
|
import { SenpiClient } from "./senpi/client.js";
|
|
18
18
|
import { buildWalletStatusHint } from "./senpi/strategy-status.js";
|
|
19
|
-
import { bootSkippedStatusLabel, partitionByWalletStatus, readBootWalletStatuses } from "./runtime/boot-skip.js";
|
|
19
|
+
import { bootSkippedStatusLabel, partitionByWalletStatus, readBootWalletStatuses, trackableWalletKeys, } from "./runtime/boot-skip.js";
|
|
20
20
|
import { DeployJobController } from "./deploy/job.js";
|
|
21
21
|
import { registerDeployGatewayMethods } from "./deploy/register.js";
|
|
22
22
|
import { registerUpdateGatewayMethod } from "./runtime/update-register.js";
|
|
23
|
-
import { checkProofCoversRecipe, makeApplyToRuntime, makeWriteRegistry, } from "./runtime/update-apply-deps.js";
|
|
23
|
+
import { checkProofCoversRecipe, makeApplyToRuntime, makeWriteRegistry, runtimeChangeLock, } from "./runtime/update-apply-deps.js";
|
|
24
24
|
import { INSTALL_DEADLINE_MS, WALLET_INSTALL_IN_FLIGHT_CODE } from "./deploy/deadlines.js";
|
|
25
25
|
import { AuditQueryError } from "./runtime/audit-query.types.js";
|
|
26
26
|
import { buildRuntimeStateDir, archiveStateDir } from "./runtime/state-layout.js";
|
|
@@ -53,6 +53,7 @@ import { registerToolApprovalGate, resolveToolApprovalsMode, } from "./approvals
|
|
|
53
53
|
import { registerShowWidgetTool } from "./widgets/index.js";
|
|
54
54
|
import { EVENT_NAME, SENPI_ERROR_CODE, eventAttrs, scannerUnwiredErrorCode } from "./utils/event-catalog.js";
|
|
55
55
|
import { emitEvent } from "./actions/event-derivation.js";
|
|
56
|
+
import { createLifecycleReaper, resolveReaperBootDelayMs, resolveReaperEnforcement, } from "./runtime/lifecycle-reaper.js";
|
|
56
57
|
import { buildRuntimeBootSkippedEvent, buildRuntimeBootStatusUnreadEvent, buildRuntimeCreatedEvent, buildRuntimeDeletedEvent, buildRuntimeUpdatedEvent, } from "./runtime/lifecycle-events.js";
|
|
57
58
|
import { isWalletAddress } from "./utils/wallet-address.js";
|
|
58
59
|
import { fileURLToPath } from "node:url";
|
|
@@ -489,6 +490,39 @@ const senpiRuntimePlugin = {
|
|
|
489
490
|
now: () => Date.now(),
|
|
490
491
|
log: (line) => api.logger.info(`[senpi-runtime] ${line}`),
|
|
491
492
|
});
|
|
493
|
+
// ── lifecycle reaper ─────────────────────────────────────────────────────────────────────────
|
|
494
|
+
// A runtime exists iff its strategy is open. Every close path ends at the backend and none of
|
|
495
|
+
// them tells this box, so the reaper asks: once after boot, hourly, and whenever the backend
|
|
496
|
+
// rejects an order with STRATEGY_NOT_ACTIVE. Observe-only unless enforcement is on (see
|
|
497
|
+
// runtime/lifecycle-reaper.ts for the safety rule). Constructed here so both `run()` call sites
|
|
498
|
+
// (boot and install) can hand it their not-active rejections; it does no I/O until started.
|
|
499
|
+
const reaperBootDelayOverride = resolveReaperBootDelayMs(process.env);
|
|
500
|
+
const reaper = createLifecycleReaper({
|
|
501
|
+
readRegistry: async () => {
|
|
502
|
+
const { readRegistry } = await import("./runtime/strategy-registry.js");
|
|
503
|
+
return readRegistry(baseStateDir);
|
|
504
|
+
},
|
|
505
|
+
readStatuses: async (wallets, signal) => {
|
|
506
|
+
const client = mcpTransport ? new SenpiClient(mcpTransport) : new SenpiClient({ apiKey });
|
|
507
|
+
if (!mcpTransport)
|
|
508
|
+
await client.connect();
|
|
509
|
+
try {
|
|
510
|
+
return await client.listStrategies({ strategyAddresses: wallets }, { signal });
|
|
511
|
+
}
|
|
512
|
+
finally {
|
|
513
|
+
if (!mcpTransport)
|
|
514
|
+
await client.disconnect().catch(() => { });
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
deleteRuntime: async (id, reason, wallet) => {
|
|
518
|
+
const result = await deleteRuntimeCore({ id, deleteReason: reason, expectWallet: wallet });
|
|
519
|
+
return result.ok ? { ok: true } : { ok: false, code: result.error.code, message: result.error.message };
|
|
520
|
+
},
|
|
521
|
+
emit: (build) => emitEvent(apiLogger, build),
|
|
522
|
+
enforce: resolveReaperEnforcement(process.env),
|
|
523
|
+
logger: pluginLogger,
|
|
524
|
+
...(reaperBootDelayOverride !== undefined ? { bootDelayMs: reaperBootDelayOverride } : {}),
|
|
525
|
+
});
|
|
492
526
|
api.registerService({
|
|
493
527
|
id: "senpi-runtime",
|
|
494
528
|
async start() {
|
|
@@ -577,9 +611,9 @@ const senpiRuntimePlugin = {
|
|
|
577
611
|
// One bounded read: which registered wallets the platform says are dead, so a restart does
|
|
578
612
|
// not re-scaffold runtimes on closed wallets (fail-open — see runtime/boot-skip.ts).
|
|
579
613
|
let walletStatuses = null;
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
614
|
+
// Lower-cased and trackable-only: the backend matches addresses case-sensitively against
|
|
615
|
+
// lower-case storage, and rejects the whole batch on one malformed address.
|
|
616
|
+
const registeredWallets = trackableWalletKeys(registry.runtimes);
|
|
583
617
|
if (registeredWallets.length > 0) {
|
|
584
618
|
const read = await readBootWalletStatuses(registeredWallets, async (wallets, signal) => {
|
|
585
619
|
const client = mcpTransport ? new SenpiClient(mcpTransport) : new SenpiClient({ apiKey });
|
|
@@ -595,6 +629,7 @@ const senpiRuntimePlugin = {
|
|
|
595
629
|
});
|
|
596
630
|
if (read.ok) {
|
|
597
631
|
walletStatuses = read.statuses;
|
|
632
|
+
reaper.recordStatuses(registeredWallets, read.statuses);
|
|
598
633
|
}
|
|
599
634
|
else {
|
|
600
635
|
pluginLogger.warn("[senpi-runtime] Could not read strategy statuses at boot; booting every registered runtime", { reason: read.reason, err: read.message });
|
|
@@ -630,6 +665,7 @@ const senpiRuntimePlugin = {
|
|
|
630
665
|
apiKey,
|
|
631
666
|
scannerProviders,
|
|
632
667
|
runtimeId: entry.id,
|
|
668
|
+
onStrategyNotActive: (address) => reaper.checkWallet(address),
|
|
633
669
|
});
|
|
634
670
|
runtimeHandles.set(entry.id, handle);
|
|
635
671
|
started.push(entry.id);
|
|
@@ -797,8 +833,27 @@ const senpiRuntimePlugin = {
|
|
|
797
833
|
}
|
|
798
834
|
}
|
|
799
835
|
}
|
|
836
|
+
// Last, once everything above is up: the reaper's post-boot pass and hourly sweep. Its
|
|
837
|
+
// not-active escalation is also off until here, so no delete can land while the boot loop is
|
|
838
|
+
// still wiring runtimes and launchers. Nothing here may fail start() — a throw from inside the boot loop takes every runtime down, which
|
|
839
|
+
// is exactly the failure a lifecycle check must never cause. The unit-test seam
|
|
840
|
+
// SENPI_RUNTIME_API_DISABLED keeps its timers off unless a boot delay is set explicitly.
|
|
841
|
+
try {
|
|
842
|
+
if (process.env.SENPI_RUNTIME_API_DISABLED !== "true" || reaperBootDelayOverride !== undefined) {
|
|
843
|
+
reaper.start();
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
catch (err) {
|
|
847
|
+
pluginLogger.warn("[senpi-runtime] lifecycle reaper did not start", {
|
|
848
|
+
err: err instanceof Error ? err.message : String(err),
|
|
849
|
+
});
|
|
850
|
+
}
|
|
800
851
|
},
|
|
801
852
|
async stop() {
|
|
853
|
+
// Stop the reaper first so no pass starts deleting while the runtimes are torn down below,
|
|
854
|
+
// and wait (bounded) for a pass already under way, so its delete cannot stop a handle the
|
|
855
|
+
// teardown below is stopping too.
|
|
856
|
+
await reaper.stop();
|
|
802
857
|
// Drain the HTTP server FIRST so in-flight POST /signals requests
|
|
803
858
|
// finish before the underlying runtime they target is torn down.
|
|
804
859
|
// `apiHandle.close()` never throws.
|
|
@@ -1131,6 +1186,7 @@ const senpiRuntimePlugin = {
|
|
|
1131
1186
|
apiKey,
|
|
1132
1187
|
scannerProviders,
|
|
1133
1188
|
runtimeId: resolvedId,
|
|
1189
|
+
onStrategyNotActive: (address) => reaper.checkWallet(address),
|
|
1134
1190
|
});
|
|
1135
1191
|
runtimeHandles.set(resolvedId, handle);
|
|
1136
1192
|
// Registry create fact — distinct from the runtime.started boot transition (which also fires
|
|
@@ -1277,6 +1333,10 @@ const senpiRuntimePlugin = {
|
|
|
1277
1333
|
? e.runtimeYamlPath
|
|
1278
1334
|
: "(inline)",
|
|
1279
1335
|
status,
|
|
1336
|
+
// What the strategy behind this runtime last read as (open / closing / closed / absent /
|
|
1337
|
+
// unchecked / unknown) — separate from `status`, whose running…/stopped… prefixes other
|
|
1338
|
+
// readers key on.
|
|
1339
|
+
...reaper.lifecycleOf(e.wallet),
|
|
1280
1340
|
// The deploy path installs by CONTENT, not path (orchestrator.ts installRuntime), so
|
|
1281
1341
|
// `source` is "(inline)" for every deployed strategy and the YAML is unreachable through
|
|
1282
1342
|
// it. The engine renders the facts instead of shipping a blob to re-interpret.
|
|
@@ -1291,13 +1351,19 @@ const senpiRuntimePlugin = {
|
|
|
1291
1351
|
* unwired-verdict cleanup all happen exactly once, here.
|
|
1292
1352
|
*/
|
|
1293
1353
|
async function deleteRuntimeCore(params) {
|
|
1294
|
-
const { readRegistry, writeRegistry, withRegistryLock } = await import("./runtime/strategy-registry.js");
|
|
1295
|
-
const registry = await readRegistry(baseStateDir);
|
|
1296
1354
|
let targetId = typeof params?.id === "string" ? params.id : undefined;
|
|
1297
1355
|
const targetAddress = typeof params?.address === "string" ? params.address : undefined;
|
|
1356
|
+
// Set only by the lifecycle reaper: why the strategy counts as gone (stamped on runtime.deleted)
|
|
1357
|
+
// and which wallet that verdict was about (the concurrency guard below).
|
|
1358
|
+
const deleteReason = params?.deleteReason === "closed_status" ? params.deleteReason
|
|
1359
|
+
: undefined;
|
|
1360
|
+
const expectWallet = typeof params?.expectWallet === "string" && params.expectWallet.trim().length > 0
|
|
1361
|
+
? params.expectWallet.trim().toLowerCase()
|
|
1362
|
+
: undefined;
|
|
1298
1363
|
// Resolve target by address if id not provided
|
|
1299
1364
|
if (!targetId && targetAddress) {
|
|
1300
|
-
const
|
|
1365
|
+
const { readRegistry } = await import("./runtime/strategy-registry.js");
|
|
1366
|
+
const entry = (await readRegistry(baseStateDir)).runtimes.find((e) => e.wallet === targetAddress);
|
|
1301
1367
|
if (!entry) {
|
|
1302
1368
|
return { ok: false, error: {
|
|
1303
1369
|
code: "NOT_FOUND",
|
|
@@ -1312,6 +1378,24 @@ const senpiRuntimePlugin = {
|
|
|
1312
1378
|
message: "Please provide the runtime id or wallet address. Example: openclaw senpi runtime delete --id my-runtime",
|
|
1313
1379
|
} };
|
|
1314
1380
|
}
|
|
1381
|
+
// One delete or update apply per runtime at a time (see `runtimeChangeLock`). Operator, agent
|
|
1382
|
+
// and deploy deletes wait their turn; the lifecycle reaper never queues behind someone else's
|
|
1383
|
+
// change to the runtime it judged — it backs off and the next lifecycle check re-reads it.
|
|
1384
|
+
// The check and the acquire below run in one synchronous step.
|
|
1385
|
+
const id = targetId;
|
|
1386
|
+
if (expectWallet !== undefined && runtimeChangeLock.hasKey(id)) {
|
|
1387
|
+
return { ok: false, error: {
|
|
1388
|
+
code: "CONFLICT",
|
|
1389
|
+
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.`,
|
|
1390
|
+
} };
|
|
1391
|
+
}
|
|
1392
|
+
return runtimeChangeLock.withKeyLock(id, () => deleteRuntimeLocked(id, deleteReason, expectWallet));
|
|
1393
|
+
}
|
|
1394
|
+
/** {@link deleteRuntimeCore} past target resolution, under the runtime's change lock. */
|
|
1395
|
+
async function deleteRuntimeLocked(targetId, deleteReason, expectWallet) {
|
|
1396
|
+
const { readRegistry, writeRegistry, withRegistryLock } = await import("./runtime/strategy-registry.js");
|
|
1397
|
+
// Read under the lock: a delete that waited behind another change sees what that change left.
|
|
1398
|
+
const registry = await readRegistry(baseStateDir);
|
|
1315
1399
|
const deletedEntry = registry.runtimes.find((e) => e.id === targetId);
|
|
1316
1400
|
const handle = runtimeHandles.get(targetId);
|
|
1317
1401
|
if (!deletedEntry && !handle) {
|
|
@@ -1320,6 +1404,35 @@ const senpiRuntimePlugin = {
|
|
|
1320
1404
|
message: `No runtime found with id "${targetId}".`,
|
|
1321
1405
|
} };
|
|
1322
1406
|
}
|
|
1407
|
+
/**
|
|
1408
|
+
* The lifecycle reaper's guard. Its verdict was about one wallet at one moment; the delete
|
|
1409
|
+
* below must not land on anything else. Evaluated synchronously between the registry read
|
|
1410
|
+
* above and the first teardown step, so nothing can interleave between check and act:
|
|
1411
|
+
* - an install on that wallet is running (it could land a live runtime under this id);
|
|
1412
|
+
* - a deploy job holds the single-flight slot (it retires and reinstalls runtimes);
|
|
1413
|
+
* - the row under this id no longer carries that wallet (ids derive from name + wallet and
|
|
1414
|
+
* are reused, so a reinstall onto a new wallet can take the old id);
|
|
1415
|
+
* - a live handle under this id trades a different wallet.
|
|
1416
|
+
* Operator, agent and deploy deletes pass no `expectWallet` and are unaffected.
|
|
1417
|
+
*/
|
|
1418
|
+
if (expectWallet !== undefined) {
|
|
1419
|
+
const fold = (w) => (w ?? "").trim().toLowerCase();
|
|
1420
|
+
const conflict = installsInFlight.has(expectWallet)
|
|
1421
|
+
? "an install is running on that wallet"
|
|
1422
|
+
: deployController.running() !== null
|
|
1423
|
+
? "a deploy is in progress"
|
|
1424
|
+
: !deletedEntry || fold(deletedEntry.wallet) !== expectWallet
|
|
1425
|
+
? "the registry row under that id no longer carries that wallet"
|
|
1426
|
+
: handle && fold(handle.wallet) !== expectWallet
|
|
1427
|
+
? "the running runtime under that id trades a different wallet"
|
|
1428
|
+
: undefined;
|
|
1429
|
+
if (conflict !== undefined) {
|
|
1430
|
+
return { ok: false, error: {
|
|
1431
|
+
code: "CONFLICT",
|
|
1432
|
+
message: `Runtime "${targetId}" was not removed: ${conflict}. Nothing was changed; the next lifecycle check re-reads it.`,
|
|
1433
|
+
} };
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1323
1436
|
if (handle) {
|
|
1324
1437
|
await handle.teardownDslForRuntimeDeletion();
|
|
1325
1438
|
await handle.stop();
|
|
@@ -1365,6 +1478,7 @@ const senpiRuntimePlugin = {
|
|
|
1365
1478
|
runtimeId: targetId,
|
|
1366
1479
|
address: deletedEntry?.wallet,
|
|
1367
1480
|
hadLiveHandle: Boolean(handle),
|
|
1481
|
+
deleteReason,
|
|
1368
1482
|
}));
|
|
1369
1483
|
return { ok: true, payload: { id: targetId } };
|
|
1370
1484
|
}
|