@senpi/runtime 3.0.198 → 3.0.200

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 (73) hide show
  1. package/dist/cli/deploy-render.d.ts +2 -0
  2. package/dist/cli/deploy-render.d.ts.map +1 -1
  3. package/dist/cli/deploy-render.js +2 -0
  4. package/dist/cli/deploy-render.js.map +1 -1
  5. package/dist/cli/guide-commands.d.ts.map +1 -1
  6. package/dist/cli/guide-commands.js +20 -11
  7. package/dist/cli/guide-commands.js.map +1 -1
  8. package/dist/cli/senpi-commands.d.ts.map +1 -1
  9. package/dist/cli/senpi-commands.js +58 -13
  10. package/dist/cli/senpi-commands.js.map +1 -1
  11. package/dist/cli/update-command.d.ts +13 -0
  12. package/dist/cli/update-command.d.ts.map +1 -1
  13. package/dist/cli/update-command.js +48 -8
  14. package/dist/cli/update-command.js.map +1 -1
  15. package/dist/deploy/messages.d.ts +34 -14
  16. package/dist/deploy/messages.d.ts.map +1 -1
  17. package/dist/deploy/messages.js +83 -30
  18. package/dist/deploy/messages.js.map +1 -1
  19. package/dist/deploy/orchestrator.d.ts +9 -5
  20. package/dist/deploy/orchestrator.d.ts.map +1 -1
  21. package/dist/deploy/orchestrator.js +140 -37
  22. package/dist/deploy/orchestrator.js.map +1 -1
  23. package/dist/deploy/package.d.ts +13 -0
  24. package/dist/deploy/package.d.ts.map +1 -1
  25. package/dist/deploy/package.js +18 -1
  26. package/dist/deploy/package.js.map +1 -1
  27. package/dist/deploy/proof-gate.d.ts.map +1 -1
  28. package/dist/deploy/proof-gate.js +12 -3
  29. package/dist/deploy/proof-gate.js.map +1 -1
  30. package/dist/deploy/register.js +3 -3
  31. package/dist/deploy/register.js.map +1 -1
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +14 -3
  34. package/dist/index.js.map +1 -1
  35. package/dist/runtime/effective-config.d.ts.map +1 -1
  36. package/dist/runtime/effective-config.js +12 -2
  37. package/dist/runtime/effective-config.js.map +1 -1
  38. package/dist/runtime/load-runtime-config.d.ts +20 -0
  39. package/dist/runtime/load-runtime-config.d.ts.map +1 -1
  40. package/dist/runtime/load-runtime-config.js +36 -8
  41. package/dist/runtime/load-runtime-config.js.map +1 -1
  42. package/dist/runtime/map-strategies.d.ts.map +1 -1
  43. package/dist/runtime/map-strategies.js +7 -4
  44. package/dist/runtime/map-strategies.js.map +1 -1
  45. package/dist/runtime/update-apply-deps.d.ts +24 -6
  46. package/dist/runtime/update-apply-deps.d.ts.map +1 -1
  47. package/dist/runtime/update-apply-deps.js +88 -21
  48. package/dist/runtime/update-apply-deps.js.map +1 -1
  49. package/dist/runtime/update-handler.d.ts +9 -6
  50. package/dist/runtime/update-handler.d.ts.map +1 -1
  51. package/dist/runtime/update-handler.js +44 -8
  52. package/dist/runtime/update-handler.js.map +1 -1
  53. package/dist/runtime/update-register.d.ts +99 -0
  54. package/dist/runtime/update-register.d.ts.map +1 -1
  55. package/dist/runtime/update-register.js +233 -40
  56. package/dist/runtime/update-register.js.map +1 -1
  57. package/dist/senpi/__tests__/helpers/fake-paper-mcp.d.ts +8 -0
  58. package/dist/senpi/__tests__/helpers/fake-paper-mcp.d.ts.map +1 -1
  59. package/dist/senpi/__tests__/helpers/fake-paper-mcp.js +21 -8
  60. package/dist/senpi/__tests__/helpers/fake-paper-mcp.js.map +1 -1
  61. package/dist/senpi/client.d.ts +2 -1
  62. package/dist/senpi/client.d.ts.map +1 -1
  63. package/dist/senpi/client.js +5 -6
  64. package/dist/senpi/client.js.map +1 -1
  65. package/dist/senpi/strategy-status.d.ts +3 -0
  66. package/dist/senpi/strategy-status.d.ts.map +1 -1
  67. package/dist/senpi/strategy-status.js +5 -0
  68. package/dist/senpi/strategy-status.js.map +1 -1
  69. package/dist/validate/proof.d.ts.map +1 -1
  70. package/dist/validate/proof.js +20 -5
  71. package/dist/validate/proof.js.map +1 -1
  72. package/openclaw.plugin.json +1 -1
  73. package/package.json +1 -1
@@ -27,7 +27,7 @@ import { loadRuntimeConfig } from "../runtime/load-runtime-config.js";
27
27
  import { catalogCopy, strategyFacts } from "../strategy/facts.js";
28
28
  import { buildUniverseNotLiveRefusal, buildUniverseUnavailableDetail, checkPackageUniverse, describeUniverseVerdict, } from "../universe/package-universe.js";
29
29
  import { instancesWithoutDslExit, nonLowercasePackageId, renderRuntimeYaml, runtimeUsesLlmDecisions, readRuntimeYaml, runtimeIdFor, scannersDeclaringEnabled, unboundWalletInstances, walletName, } from "./package.js";
30
- import { DEAD_STATUSES, INITIALIZING_STATUSES, isDead, isInitializing, } from "../senpi/strategy-status.js";
30
+ import { DEAD_STATUSES, INITIALIZING_STATUSES, isClosable, isClosing, isDead, isInitializing, } from "../senpi/strategy-status.js";
31
31
  import { MIN_WALLET, accessibleUsd, closeCommand, statusCommand, planFunding, resumeCommand, sharesOverAuthorization, underfundedNote, usd, } from "./funding.js";
32
32
  import { DEFAULT_MAX_WAIT_SEC, DEFAULT_TICK_WAIT_SEC, INSTALL_DEADLINE_MS, INSTALL_INDETERMINATE_CODE, isInstallDeadlineExceeded, } from "./deadlines.js";
33
33
  import { packageMinBudget } from "./min-budget.js";
@@ -35,7 +35,7 @@ import { errorText } from "./error-text.js";
35
35
  import { truncateForPush } from "../types/notification.js";
36
36
  import { gateInstance } from "./install-gate-runner.js";
37
37
  import { buildInstanceDirCollisionRefusal, buildProofRefusal, checkPackageProof, collidingInstanceDirs, proofRefusalParts, } from "./proof-gate.js";
38
- import { buildAmbiguousRefusal, buildBindingUnknownRefusal, buildBudgetEscape, buildBudgetNotPositiveRefusal, buildBudgetRequiredRefusal, buildCreateAbandonedDetail, buildCreateDeadDetail, buildCreateNameRetryNotIssuedDetail, buildCreateNotDeployableDetail, buildCreatePendingDetail, buildDecisionModelEnvRefusal, buildDecisionModelRefusal, buildForeignPackageRefusal, buildFundedUnreadableNote, buildInstallGateRefusal, buildInstallGateUnavailableDetail, buildInstallIndeterminateDetail, buildInstallInFlightDetail, buildNoDslExitRefusal, buildNonLowercaseIdRefusal, buildNotDeployableRefusal, buildPaperRoutingUnprovenRefusal, buildPaperCreateWentLiveDetail, buildPartialFundNote, buildScannerEnabledUnsupportedRefusal, buildBoxRuntimeCapRefusal, buildShareOverrunRefusal, buildSoftBudgetNote, buildStrategyLimitRefusal, limitShort, buildUnboundWalletRefusal, buildUnobservedDetail, buildUnreadableWalletRefusal, buildUnwiredInstallDetail, buildRuntimeIdHeldByOtherWorldDetail, buildRuntimeIdHeldByOtherWorldRefusal, buildWalletWorldMismatchDetail, foreignCollisionClause, forwardTense, fundedClause, itsFunded, matchedByClause, reconcileCanMatchByName, rollbackFundedClause, } from "./messages.js";
38
+ import { buildAmbiguousRefusal, buildBindingUnknownRefusal, buildBudgetEscape, buildBudgetNotPositiveRefusal, buildBudgetRequiredRefusal, buildCreateAbandonedDetail, buildCreateDeadDetail, buildCreateNameRetryNotIssuedDetail, buildCreateNotDeployableDetail, buildCreatePendingDetail, buildDecisionModelEnvRefusal, buildDecisionModelRefusal, buildForeignPackageRefusal, buildFundedUnreadableNote, buildInstallGateRefusal, buildInstallGateUnavailableDetail, buildInstallIndeterminateDetail, buildInstallInFlightDetail, buildNoDslExitRefusal, buildNonLowercaseIdRefusal, buildNotDeployableRefusal, buildPaperRoutingUnprovenRefusal, buildPaperCreateWentLiveDetail, buildPartialFundNote, buildScannerEnabledUnsupportedRefusal, buildBoxRuntimeCapRefusal, buildAdoptedOverBoxCapNote, buildShareOverrunRefusal, buildSoftBudgetNote, buildStrategyLimitRefusal, limitShort, buildUnboundWalletRefusal, buildUnobservedDetail, buildUnreadableWalletRefusal, buildUnwiredInstallDetail, buildRuntimeIdHeldByOtherWorldDetail, buildRuntimeIdHeldByOtherWorldRefusal, buildWalletWorldMismatchDetail, foreignCollisionClause, forwardTense, fundedClause, itsFunded, matchedByClause, reconcileCanMatchByName, rollbackFundedClause, } from "./messages.js";
39
39
  /** Stands in for the wallet when rendering a recipe only to read its facts, which never include it. */
40
40
  const FACTS_STAND_IN_WALLET = "0x0000000000000000000000000000000000000000";
41
41
  const CREATE_POLL_MS = 10_000;
@@ -380,6 +380,10 @@ function buildNext(overall, pkg, budget, runs) {
380
380
  // via `strategy_list` first) where that detail ran; this footer only names the command.
381
381
  return `re-run \`${resumeCommand(pkg, budget)}\` to resume — reconcile re-reads the live list before it creates anything, and what it finds there decides the rest`;
382
382
  case "failed":
383
+ if (runs.some((run) => run.report.steps.create.evidence?.wentLive === true)) {
384
+ return (`Read the [E_PAPER_CREATE_WENT_LIVE] step above and follow it. This report offers no re-run: ` +
385
+ `the MCP turned a simulation into a live strategy, and a re-run can do the same.`);
386
+ }
383
387
  // "Fix the cause, then re-run" is false for exactly one failure on this verb: an install this
384
388
  // deploy stopped WAITING on has no cause to fix — it was never cancelled, and its outcome is
385
389
  // unknown — so the footer that outranks every step line (an agent reads the report's `next`
@@ -584,6 +588,7 @@ export async function runDeploy(params, deps) {
584
588
  * having created, which is not known until the report is assembled.
585
589
  */
586
590
  const soft = { min: null, under: [] };
591
+ let boxCapNote;
587
592
  /** Narration is fire-and-forget: a broken journal must never change what a deploy does. */
588
593
  const emit = (event) => {
589
594
  try {
@@ -1354,8 +1359,13 @@ export async function runDeploy(params, deps) {
1354
1359
  await span("deploy.preflight", { "senpi.deploy.step": "preflight" }, async () => {
1355
1360
  if (!boundaryAbandoned()) {
1356
1361
  try {
1357
- if (!(await refusedOnRuntimeIdHeldByOtherWorld()) && needing.length > 0)
1358
- await runPreflight();
1362
+ if (!(await refusedOnRuntimeIdHeldByOtherWorld())) {
1363
+ if (needing.length > 0)
1364
+ await runPreflight();
1365
+ // Only a warning can come of it here, so a failed read must not refuse the deploy.
1366
+ else
1367
+ await refusedOnBoxRuntimeCap().catch((err) => log(`deploy: box cap read failed: ${errorText(err)}`));
1368
+ }
1359
1369
  }
1360
1370
  catch (err) {
1361
1371
  // A thrown preflight is fail-closed: no balance was proven, so nothing is created.
@@ -1491,15 +1501,36 @@ export async function runDeploy(params, deps) {
1491
1501
  }
1492
1502
  return true;
1493
1503
  }
1504
+ /**
1505
+ * Refuses new wallets past the cap. Adopted wallets that still need a runtime count too, but only
1506
+ * toward a warning ({@link DeployReport.boxCapNote}).
1507
+ */
1494
1508
  async function refusedOnBoxRuntimeCap() {
1495
- const box = await deps.boxRuntimes();
1509
+ const adopted = await adoptedWalletsNeedingRuntime().catch((err) => {
1510
+ log(`deploy: counting adopted wallets for the box cap failed: ${errorText(err)}`);
1511
+ return [];
1512
+ });
1496
1513
  const needed = needing.length;
1497
- if (box.running + needed <= box.cap)
1514
+ if (needed === 0 && adopted.length === 0)
1498
1515
  return false;
1516
+ const box = await deps.boxRuntimes();
1517
+ const replaced = await rowsReplacedByNewWallets();
1518
+ const after = box.running - replaced.length + needed;
1519
+ if (needed === 0 || after <= box.cap) {
1520
+ if (after + adopted.length > box.cap) {
1521
+ boxCapNote = buildAdoptedOverBoxCapNote(adopted, after + adopted.length, box.cap, pkg.paper);
1522
+ log(`deploy: ${boxCapNote}`);
1523
+ }
1524
+ return false;
1525
+ }
1499
1526
  refused = true;
1500
- const detail = buildBoxRuntimeCapRefusal(needed, box, pkg, budget);
1527
+ const detail = buildBoxRuntimeCapRefusal(needed, box, pkg, budget, replaced);
1501
1528
  for (const run of needing) {
1502
- record(run, "preflight", { status: "refused", detail, evidence: { needed, ...box } });
1529
+ record(run, "preflight", {
1530
+ status: "refused",
1531
+ detail,
1532
+ evidence: { needed, ...box, ...(replaced.length > 0 ? { replaced } : {}) },
1533
+ });
1503
1534
  }
1504
1535
  return true;
1505
1536
  }
@@ -1533,6 +1564,40 @@ export async function runDeploy(params, deps) {
1533
1564
  }
1534
1565
  return true;
1535
1566
  }
1567
+ /**
1568
+ * Instances whose existing strategy gets its first runtime on this box: no row on its wallet and
1569
+ * no same-world row on its runtime id (a row on another wallet there is replaced, not added).
1570
+ */
1571
+ async function adoptedWalletsNeedingRuntime() {
1572
+ const names = [];
1573
+ for (const run of installing) {
1574
+ if (run.needsWallet)
1575
+ continue;
1576
+ const wallet = run.report.wallet;
1577
+ if (wallet && (await deps.registryFindByWallet(wallet)))
1578
+ continue;
1579
+ const row = await deps.registryFindById(runtimeIdFor(pkg, run.inst));
1580
+ if (row && !registryRowIsOtherWorld(row, pkg.paper))
1581
+ continue;
1582
+ names.push(run.inst.name);
1583
+ }
1584
+ return names;
1585
+ }
1586
+ /**
1587
+ * Registry rows on a new wallet's runtime id. Install deletes such a row and recreates it on the
1588
+ * new wallet, so it is not a runtime this deploy adds. A row from the other world on that id is
1589
+ * never replaced (install refuses it), so it is not one of them.
1590
+ */
1591
+ async function rowsReplacedByNewWallets() {
1592
+ const replaced = [];
1593
+ for (const run of needing) {
1594
+ const id = runtimeIdFor(pkg, run.inst);
1595
+ const row = await deps.registryFindById(id);
1596
+ if (row && !registryRowIsOtherWorld(row, pkg.paper))
1597
+ replaced.push(id);
1598
+ }
1599
+ return replaced;
1600
+ }
1536
1601
  /**
1537
1602
  * The SOFT calculated-minimum tier. The package-level figure is computed over the WHOLE package
1538
1603
  * (every sleeve's share of a hypothetical fresh deploy) and rides the report as CONTEXT — but the
@@ -1786,7 +1851,8 @@ export async function runDeploy(params, deps) {
1786
1851
  if (probe.routed)
1787
1852
  return true;
1788
1853
  refused = true;
1789
- const detail = buildPaperRoutingUnprovenRefusal(probe.reason);
1854
+ const createdEarlier = needing.filter((other) => other.report.strategyId !== undefined).map((other) => other.inst.name);
1855
+ const detail = buildPaperRoutingUnprovenRefusal(probe.reason, createdEarlier);
1790
1856
  for (const target of [run, ...needing.filter((other) => other !== run && !other.recorded.has("create"))]) {
1791
1857
  if (target.recorded.has("create"))
1792
1858
  continue;
@@ -1796,11 +1862,12 @@ export async function runDeploy(params, deps) {
1796
1862
  }
1797
1863
  /**
1798
1864
  * A paper create returned a LIVE strategy id: the MCP dropped `paper` and created a funded live
1799
- * strategy. Close it by that id at once, before any poll or install, then stop the run. Nothing
1800
- * else is created; the step fails loudly with whether the close went through.
1865
+ * strategy. Nothing else is created and the run stops. The MCP closes only an ACTIVE or PAUSED
1866
+ * strategy, so the job waits for one of those on the ACTIVE poll's budget, closes it by id and
1867
+ * reads it back CLOSED, before any install. The step fails with where that left it.
1801
1868
  *
1802
- * The id is journaled before the close is awaited. A process that dies during the close leaves
1803
- * no other record of it, and paper recovery reads only the paper world.
1869
+ * The id is journaled before the wait. A process that dies during it leaves no other record of
1870
+ * the strategy, and paper recovery reads only the paper world.
1804
1871
  */
1805
1872
  async function stopOnLiveCreate(run, strategyId) {
1806
1873
  wentLive = true;
@@ -1811,23 +1878,50 @@ export async function runDeploy(params, deps) {
1811
1878
  evidence: { instance: run.inst.name, world: "live", unexpectedStrategyId: strategyId },
1812
1879
  });
1813
1880
  log(`deploy: paper create for "${run.inst.name}" returned live strategy ${strategyId} — closing it`);
1814
- let closed = false;
1815
- let closeError;
1816
- try {
1817
- const result = await deps.closeStrategyById(strategyId);
1818
- closed = result.success === true;
1819
- if (!closed)
1820
- closeError = result.message ?? "the close reported no success";
1821
- }
1822
- catch (err) {
1823
- closeError = errorText(err);
1824
- }
1881
+ const cleanup = await closeLiveCreate(strategyId);
1825
1882
  record(run, "create", {
1826
1883
  status: "failed",
1827
- detail: buildPaperCreateWentLiveDetail({ strategyId, closed, ...(closeError ? { closeError } : {}) }),
1828
- evidence: { strategyId, paper: true, closed, ...(closeError ? { closeError } : {}) },
1884
+ detail: buildPaperCreateWentLiveDetail(strategyId, cleanup),
1885
+ evidence: {
1886
+ strategyId,
1887
+ paper: true,
1888
+ wentLive: true,
1889
+ closed: cleanup.kind === "closed",
1890
+ cleanup: cleanup.kind,
1891
+ lastStatus: cleanup.status ?? null,
1892
+ ...(cleanup.kind === "close-failed" ? { closeError: cleanup.reason } : {}),
1893
+ },
1829
1894
  });
1830
1895
  }
1896
+ async function closeLiveCreate(strategyId) {
1897
+ const status = await pollStatus(strategyId, false, (s) => !isInitializing(s));
1898
+ if (status === undefined || (!isClosable(status) && !isClosing(status) && !isDead(status))) {
1899
+ return { kind: "unclosable", ...(status ? { status } : {}) };
1900
+ }
1901
+ if (isDead(status))
1902
+ return { kind: "closed", status };
1903
+ let outcome;
1904
+ if (isClosing(status)) {
1905
+ outcome = await pollUntilClosed(strategyId, { kind: "closing", status, strategyId, result: undefined }, false);
1906
+ }
1907
+ else {
1908
+ try {
1909
+ const accepted = readCloseOutcome(await deps.closeStrategyById(strategyId));
1910
+ outcome = accepted.kind === "closing" ? await pollUntilClosed(strategyId, accepted, false) : accepted;
1911
+ }
1912
+ catch (err) {
1913
+ return { kind: "close-failed", status, reason: errorText(err) };
1914
+ }
1915
+ }
1916
+ switch (outcome.kind) {
1917
+ case "closed":
1918
+ return { kind: "closed", status: "CLOSED" };
1919
+ case "closing":
1920
+ return { kind: "closing", ...(outcome.status ? { status: outcome.status } : {}) };
1921
+ case "failed":
1922
+ return { kind: "close-failed", status, reason: outcome.reason };
1923
+ }
1924
+ }
1831
1925
  /**
1832
1926
  * What the create carries beside attribution (ticket 125): the instance's StrategyFacts and the
1833
1927
  * package's catalog copy. Descriptive only, so it never stops a create: facts that cannot be
@@ -2161,7 +2255,7 @@ export async function runDeploy(params, deps) {
2161
2255
  const result = await deps.closeStrategy(wallet);
2162
2256
  const accepted = readCloseOutcome(result);
2163
2257
  const outcome = accepted.kind === "closing"
2164
- ? await pollUntilClosed(run.report.strategyId ?? accepted.strategyId, accepted)
2258
+ ? await pollUntilClosed(run.report.strategyId ?? accepted.strategyId, accepted, pkg.paper)
2165
2259
  : accepted;
2166
2260
  switch (outcome.kind) {
2167
2261
  case "failed":
@@ -2193,28 +2287,36 @@ export async function runDeploy(params, deps) {
2193
2287
  }
2194
2288
  }
2195
2289
  /**
2196
- * Read an accepted close back until the strategy is CLOSED, on the ACTIVE poll's budget and
2197
- * cadence (`--max-wait`, {@link CREATE_POLL_MS}) and the job's deadline. A read that throws is not
2198
- * a CLOSED read, so it only costs one poll.
2290
+ * Read an accepted close back until the strategy is CLOSED. A read that throws is not a CLOSED
2291
+ * read, so it only costs one poll.
2199
2292
  */
2200
- async function pollUntilClosed(strategyId, closing) {
2293
+ async function pollUntilClosed(strategyId, closing, paper) {
2201
2294
  if (strategyId === undefined)
2202
2295
  return closing;
2296
+ const status = (await pollStatus(strategyId, paper, (s) => s.toUpperCase() === "CLOSED")) ?? closing.status;
2297
+ return status?.toUpperCase() === "CLOSED" ? { kind: "closed", result: closing.result } : { ...closing, strategyId, status };
2298
+ }
2299
+ /**
2300
+ * Read one strategy's status until `settled` holds, on the ACTIVE poll's budget and cadence
2301
+ * (`--max-wait`, {@link CREATE_POLL_MS}) and the job's deadline. Resolves the last status read,
2302
+ * undefined when no read returned one.
2303
+ */
2304
+ async function pollStatus(strategyId, paper, settled) {
2203
2305
  const deadline = deps.now() + maxWaitSec * 1000;
2204
- let status = closing.status;
2306
+ let status;
2205
2307
  for (;;) {
2206
2308
  try {
2207
- const [live] = await deps.listStrategies({ paper: pkg.paper, strategyIds: [strategyId] });
2309
+ const [live] = await deps.listStrategies({ paper, strategyIds: [strategyId] });
2208
2310
  if (live?.status)
2209
2311
  status = live.status;
2210
2312
  }
2211
2313
  catch (err) {
2212
- log(`deploy: reading strategy ${strategyId} after its rollback close failed: ${errorText(err)}`);
2314
+ log(`deploy: reading strategy ${strategyId} failed: ${errorText(err)}`);
2213
2315
  }
2214
- if (status?.toUpperCase() === "CLOSED")
2215
- return { kind: "closed", result: closing.result };
2316
+ if (status !== undefined && settled(status))
2317
+ return status;
2216
2318
  if (deps.now() >= deadline || deps.shouldAbandon())
2217
- return { ...closing, strategyId, status };
2319
+ return status;
2218
2320
  await deps.sleep(CREATE_POLL_MS);
2219
2321
  }
2220
2322
  }
@@ -2529,6 +2631,7 @@ export async function runDeploy(params, deps) {
2529
2631
  ...(unreadableFunded.length > 0
2530
2632
  ? { fundedUnreadableNote: buildFundedUnreadableNote(pkg, unreadableFunded, reassures()) }
2531
2633
  : {}),
2634
+ ...(boxCapNote ? { boxCapNote } : {}),
2532
2635
  };
2533
2636
  }
2534
2637
  /**