@senpi-ai/runtime 3.0.70 → 3.0.78

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 (189) hide show
  1. package/README.md +76 -2
  2. package/dist/cli/deploy-render.d.ts +93 -0
  3. package/dist/cli/deploy-render.d.ts.map +1 -0
  4. package/dist/cli/deploy-render.js +438 -0
  5. package/dist/cli/deploy-render.js.map +1 -0
  6. package/dist/cli/guide-commands.d.ts.map +1 -1
  7. package/dist/cli/guide-commands.js +94 -9
  8. package/dist/cli/guide-commands.js.map +1 -1
  9. package/dist/cli/senpi-commands.d.ts +6 -1
  10. package/dist/cli/senpi-commands.d.ts.map +1 -1
  11. package/dist/cli/senpi-commands.js +290 -41
  12. package/dist/cli/senpi-commands.js.map +1 -1
  13. package/dist/cli/validate-command.d.ts.map +1 -1
  14. package/dist/cli/validate-command.js +10 -1
  15. package/dist/cli/validate-command.js.map +1 -1
  16. package/dist/deploy/deadlines.d.ts +107 -0
  17. package/dist/deploy/deadlines.d.ts.map +1 -0
  18. package/dist/deploy/deadlines.js +139 -0
  19. package/dist/deploy/deadlines.js.map +1 -0
  20. package/dist/deploy/error-text.d.ts +25 -0
  21. package/dist/deploy/error-text.d.ts.map +1 -0
  22. package/dist/deploy/error-text.js +42 -0
  23. package/dist/deploy/error-text.js.map +1 -0
  24. package/dist/deploy/funding.d.ts +125 -0
  25. package/dist/deploy/funding.d.ts.map +1 -0
  26. package/dist/deploy/funding.js +268 -0
  27. package/dist/deploy/funding.js.map +1 -0
  28. package/dist/deploy/install-gate-runner.d.ts +12 -0
  29. package/dist/deploy/install-gate-runner.d.ts.map +1 -0
  30. package/dist/deploy/install-gate-runner.js +17 -0
  31. package/dist/deploy/install-gate-runner.js.map +1 -0
  32. package/dist/deploy/job.d.ts +215 -0
  33. package/dist/deploy/job.d.ts.map +1 -0
  34. package/dist/deploy/job.js +484 -0
  35. package/dist/deploy/job.js.map +1 -0
  36. package/dist/deploy/messages.d.ts +603 -0
  37. package/dist/deploy/messages.d.ts.map +1 -0
  38. package/dist/deploy/messages.js +1388 -0
  39. package/dist/deploy/messages.js.map +1 -0
  40. package/dist/deploy/min-budget.d.ts +68 -0
  41. package/dist/deploy/min-budget.d.ts.map +1 -0
  42. package/dist/deploy/min-budget.js +297 -0
  43. package/dist/deploy/min-budget.js.map +1 -0
  44. package/dist/deploy/orchestrator.d.ts +314 -0
  45. package/dist/deploy/orchestrator.d.ts.map +1 -0
  46. package/dist/deploy/orchestrator.js +2171 -0
  47. package/dist/deploy/orchestrator.js.map +1 -0
  48. package/dist/deploy/package.d.ts +228 -0
  49. package/dist/deploy/package.d.ts.map +1 -0
  50. package/dist/deploy/package.js +542 -0
  51. package/dist/deploy/package.js.map +1 -0
  52. package/dist/deploy/proof-gate.d.ts +86 -0
  53. package/dist/deploy/proof-gate.d.ts.map +1 -0
  54. package/dist/deploy/proof-gate.js +278 -0
  55. package/dist/deploy/proof-gate.js.map +1 -0
  56. package/dist/deploy/python-float.d.ts +34 -0
  57. package/dist/deploy/python-float.d.ts.map +1 -0
  58. package/dist/deploy/python-float.js +46 -0
  59. package/dist/deploy/python-float.js.map +1 -0
  60. package/dist/deploy/recheck-commands.d.ts +50 -0
  61. package/dist/deploy/recheck-commands.d.ts.map +1 -0
  62. package/dist/deploy/recheck-commands.js +77 -0
  63. package/dist/deploy/recheck-commands.js.map +1 -0
  64. package/dist/deploy/register.d.ts +101 -0
  65. package/dist/deploy/register.d.ts.map +1 -0
  66. package/dist/deploy/register.js +714 -0
  67. package/dist/deploy/register.js.map +1 -0
  68. package/dist/deploy/taxonomy.d.ts +43 -0
  69. package/dist/deploy/taxonomy.d.ts.map +1 -0
  70. package/dist/deploy/taxonomy.js +59 -0
  71. package/dist/deploy/taxonomy.js.map +1 -0
  72. package/dist/dsl/events/handlers.d.ts +6 -4
  73. package/dist/dsl/events/handlers.d.ts.map +1 -1
  74. package/dist/dsl/events/handlers.js +29 -17
  75. package/dist/dsl/events/handlers.js.map +1 -1
  76. package/dist/dsl/events/initial-state.d.ts +21 -11
  77. package/dist/dsl/events/initial-state.d.ts.map +1 -1
  78. package/dist/dsl/events/initial-state.js +6 -0
  79. package/dist/dsl/events/initial-state.js.map +1 -1
  80. package/dist/dsl/notifications/floor-store.d.ts.map +1 -1
  81. package/dist/dsl/notifications/floor-store.js +34 -5
  82. package/dist/dsl/notifications/floor-store.js.map +1 -1
  83. package/dist/dsl/notifications/formatter.d.ts.map +1 -1
  84. package/dist/dsl/notifications/formatter.js +13 -5
  85. package/dist/dsl/notifications/formatter.js.map +1 -1
  86. package/dist/dsl/notifications/index.d.ts +18 -1
  87. package/dist/dsl/notifications/index.d.ts.map +1 -1
  88. package/dist/dsl/notifications/index.js +78 -11
  89. package/dist/dsl/notifications/index.js.map +1 -1
  90. package/dist/dsl/notifications/stop-raise-debounce.d.ts +113 -0
  91. package/dist/dsl/notifications/stop-raise-debounce.d.ts.map +1 -0
  92. package/dist/dsl/notifications/stop-raise-debounce.js +223 -0
  93. package/dist/dsl/notifications/stop-raise-debounce.js.map +1 -0
  94. package/dist/index.d.ts.map +1 -1
  95. package/dist/index.js +467 -222
  96. package/dist/index.js.map +1 -1
  97. package/dist/runtime/env-resolve.d.ts +13 -0
  98. package/dist/runtime/env-resolve.d.ts.map +1 -1
  99. package/dist/runtime/env-resolve.js +14 -1
  100. package/dist/runtime/env-resolve.js.map +1 -1
  101. package/dist/runtime/runtime-descriptor.d.ts +37 -0
  102. package/dist/runtime/runtime-descriptor.d.ts.map +1 -0
  103. package/dist/runtime/runtime-descriptor.js +163 -0
  104. package/dist/runtime/runtime-descriptor.js.map +1 -0
  105. package/dist/runtime/runtime-schema.d.ts +100 -100
  106. package/dist/runtime/strategy-registry.d.ts +8 -0
  107. package/dist/runtime/strategy-registry.d.ts.map +1 -1
  108. package/dist/runtime/strategy-registry.js +14 -1
  109. package/dist/runtime/strategy-registry.js.map +1 -1
  110. package/dist/runtime-api/intake/intake-mount.d.ts.map +1 -1
  111. package/dist/runtime-api/intake/intake-mount.js +7 -4
  112. package/dist/runtime-api/intake/intake-mount.js.map +1 -1
  113. package/dist/scanners/external/scaffold/preflight.py +39 -0
  114. package/dist/scanners/implementations/market-regime.d.ts +1 -1
  115. package/dist/senpi/client.d.ts +58 -4
  116. package/dist/senpi/client.d.ts.map +1 -1
  117. package/dist/senpi/client.js +262 -18
  118. package/dist/senpi/client.js.map +1 -1
  119. package/dist/senpi/strategy-status.d.ts +32 -0
  120. package/dist/senpi/strategy-status.d.ts.map +1 -0
  121. package/dist/senpi/strategy-status.js +70 -0
  122. package/dist/senpi/strategy-status.js.map +1 -0
  123. package/dist/senpi/types.d.ts +65 -3
  124. package/dist/senpi/types.d.ts.map +1 -1
  125. package/dist/skills-manager/manifest.js +3 -3
  126. package/dist/skills-manager/skills-manifest.json +3 -3
  127. package/dist/telemetry/metrics.d.ts +30 -0
  128. package/dist/telemetry/metrics.d.ts.map +1 -1
  129. package/dist/telemetry/metrics.js +72 -0
  130. package/dist/telemetry/metrics.js.map +1 -1
  131. package/dist/types/dsl/index.d.ts +14 -0
  132. package/dist/types/dsl/index.d.ts.map +1 -1
  133. package/dist/types/strategy.d.ts +9 -1
  134. package/dist/types/strategy.d.ts.map +1 -1
  135. package/dist/universe/package-universe.d.ts +97 -0
  136. package/dist/universe/package-universe.d.ts.map +1 -0
  137. package/dist/universe/package-universe.js +304 -0
  138. package/dist/universe/package-universe.js.map +1 -0
  139. package/dist/validate/codes.d.ts +30 -0
  140. package/dist/validate/codes.d.ts.map +1 -1
  141. package/dist/validate/codes.js +74 -1
  142. package/dist/validate/codes.js.map +1 -1
  143. package/dist/validate/index.d.ts +1 -1
  144. package/dist/validate/index.d.ts.map +1 -1
  145. package/dist/validate/index.js.map +1 -1
  146. package/dist/validate/install-gate.d.ts.map +1 -1
  147. package/dist/validate/install-gate.js +10 -2
  148. package/dist/validate/install-gate.js.map +1 -1
  149. package/dist/validate/live-instruments.d.ts +44 -0
  150. package/dist/validate/live-instruments.d.ts.map +1 -0
  151. package/dist/validate/live-instruments.js +71 -0
  152. package/dist/validate/live-instruments.js.map +1 -0
  153. package/dist/validate/live-stage.d.ts +8 -0
  154. package/dist/validate/live-stage.d.ts.map +1 -1
  155. package/dist/validate/live-stage.js +87 -18
  156. package/dist/validate/live-stage.js.map +1 -1
  157. package/dist/validate/package-gates-stage.d.ts +61 -0
  158. package/dist/validate/package-gates-stage.d.ts.map +1 -0
  159. package/dist/validate/package-gates-stage.js +215 -0
  160. package/dist/validate/package-gates-stage.js.map +1 -0
  161. package/dist/validate/proof.d.ts +11 -1
  162. package/dist/validate/proof.d.ts.map +1 -1
  163. package/dist/validate/proof.js +10 -6
  164. package/dist/validate/proof.js.map +1 -1
  165. package/dist/validate/recipe-checks.d.ts.map +1 -1
  166. package/dist/validate/recipe-checks.js +6 -4
  167. package/dist/validate/recipe-checks.js.map +1 -1
  168. package/dist/validate/run.d.ts +29 -1
  169. package/dist/validate/run.d.ts.map +1 -1
  170. package/dist/validate/run.js +65 -6
  171. package/dist/validate/run.js.map +1 -1
  172. package/dist/validate/target.d.ts +41 -0
  173. package/dist/validate/target.d.ts.map +1 -1
  174. package/dist/validate/target.js +192 -16
  175. package/dist/validate/target.js.map +1 -1
  176. package/dist/validate/taxonomy-finding.d.ts +22 -0
  177. package/dist/validate/taxonomy-finding.d.ts.map +1 -0
  178. package/dist/validate/taxonomy-finding.js +25 -0
  179. package/dist/validate/taxonomy-finding.js.map +1 -0
  180. package/dist/validate/universe-stage.d.ts +71 -0
  181. package/dist/validate/universe-stage.d.ts.map +1 -0
  182. package/dist/validate/universe-stage.js +165 -0
  183. package/dist/validate/universe-stage.js.map +1 -0
  184. package/dist/validate/wallet-binding-stage.d.ts +44 -0
  185. package/dist/validate/wallet-binding-stage.d.ts.map +1 -0
  186. package/dist/validate/wallet-binding-stage.js +92 -0
  187. package/dist/validate/wallet-binding-stage.js.map +1 -0
  188. package/openclaw.plugin.json +1 -1
  189. package/package.json +1 -1
@@ -11,8 +11,20 @@ import { spawnSync } from "../utils/safe-spawn.js";
11
11
  import path from "node:path";
12
12
  import { registerGuideCommands, CHEATSHEET_TEXT } from "./guide-commands.js";
13
13
  import { registerSenpiConfigCommands } from "./senpi-config-commands.js";
14
+ import { exitCodeForDeploy, renderDeploySnapshot } from "./deploy-render.js";
15
+ import { isRefusalMessage } from "../deploy/taxonomy.js";
14
16
  import { registerValidateCommand } from "./validate-command.js";
15
17
  import { VERSION } from "../version.js";
18
+ /**
19
+ * Write a --json response document straight to the stdout stream. Never console.log here:
20
+ * OpenClaw's --json mode diverts every console.* call to stderr once any command in the parse
21
+ * chain declares --json (its own words: "in --json mode, all console.* writes are diagnostics").
22
+ * process.stdout.write is the one channel that survives that diversion, so it is the only
23
+ * correct destination for the document a --json caller actually reads.
24
+ */
25
+ function writeJson(payload) {
26
+ process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
27
+ }
16
28
  /**
17
29
  * Register senpi subcommands on the given Commander program.
18
30
  */
@@ -27,14 +39,18 @@ export function registerSenpiCli(program) {
27
39
  });
28
40
  registerSenpiConfigCommands(senpi);
29
41
  registerValidateCommand(senpi);
42
+ registerDeployCommands(senpi);
30
43
  const runtime = senpi.command("runtime");
31
44
  runtime.description("Manage runtimes");
32
45
  runtime
33
- .command("create")
34
- .description("Add a runtime from a YAML file or paste YAML; the gateway validates and runs it")
46
+ // Demoted, not deleted: `senpi deploy` is the supported path (funds preflight + attribution +
47
+ // observing it running). Hidden keeps it out of help/routing while deploy.py keeps working.
48
+ .command("create", { hidden: true })
49
+ .description("Internal — prefer `senpi deploy` (funds preflight + attribution + observing it running). Direct create skips those gates.")
35
50
  .option("-p, --path <path>", "Path to your strategy YAML file")
36
51
  .option("-c, --content <content>", "Paste YAML content directly")
37
52
  .option("--runtime-id <id>", "Name for this runtime (default: from file name or content)")
53
+ .option("--runtime-yaml-dir <dir>", "Directory to resolve relative scanner paths against (content installs only)")
38
54
  .action(async (opts) => {
39
55
  const hasPath = typeof opts.path === "string" && opts.path.length > 0;
40
56
  const hasContent = typeof opts.content === "string";
@@ -75,7 +91,13 @@ export function registerSenpiCli(program) {
75
91
  // scanner's relative `path: ./` and the scaffold can import scan.py. We
76
92
  // send content (not path) so remote gateways work, but that drops the
77
93
  // directory; this hint restores it for FS-sharing (local/box) setups.
78
- ...(hasPath ? { runtimeYamlDir: path.dirname(path.resolve(process.cwd(), opts.path)) } : {}),
94
+ // An explicit --runtime-yaml-dir wins: it is the only way a content install can name
95
+ // the directory its relative scanner paths resolve against (otherwise refused).
96
+ ...(typeof opts.runtimeYamlDir === "string" && opts.runtimeYamlDir.length > 0
97
+ ? { runtimeYamlDir: path.resolve(process.cwd(), opts.runtimeYamlDir) }
98
+ : hasPath
99
+ ? { runtimeYamlDir: path.dirname(path.resolve(process.cwd(), opts.path)) }
100
+ : {}),
79
101
  ...(typeof opts.runtimeId === "string" && opts.runtimeId.length > 0 ? { id: opts.runtimeId } : {}),
80
102
  };
81
103
  // Runtime create is a SLOW synchronous call: the handler starts a long-lived
@@ -115,26 +137,28 @@ export function registerSenpiCli(program) {
115
137
  runtime
116
138
  .command("list")
117
139
  .description("List all installed runtimes with their id, source, and status (running / stopped / running — NO ENTRY SCANNERS when a live runtime's scanners never wired)")
118
- .action(async () => {
119
- const result = spawnSync(process.argv[0], [process.argv[1], "gateway", "call", "senpi.listRuntimes", "--json", "--params", "{}"], {
120
- stdio: ["inherit", "pipe", "inherit"],
121
- cwd: process.cwd(),
122
- encoding: "utf8",
123
- });
124
- if (result.status !== 0) {
125
- process.exitCode = result.status ?? 1;
126
- console.error("\nTip: If the gateway is not running, start it with: openclaw gateway run");
140
+ .option("--json", "Print raw JSON from the gateway")
141
+ .action(async (opts) => {
142
+ // Same helper every other read command uses. The hand-rolled spawnSync this replaces exited 0
143
+ // after reading nothing, dropped the refusal exit code, and never re-emitted the child stderr
144
+ // a refusal arrives on.
145
+ const data = callGatewayJson("senpi.listRuntimes", {}, (cause) => reportUnreadableGateway("senpi runtime list", cause, " No runtimes were read."));
146
+ if (!data) {
127
147
  return;
128
148
  }
129
- let data;
130
- try {
131
- data = JSON.parse(result.stdout ?? "{}");
149
+ if (data.ok === false) {
150
+ const err = data.error;
151
+ const message = err?.message ?? "Request failed.";
152
+ console.error(message);
153
+ process.exitCode = isRefusalMessage(message) ? DEPLOY_REFUSED_EXIT : 1;
154
+ return;
132
155
  }
133
- catch {
134
- process.stdout.write(result.stdout ?? "");
156
+ const payload = (data.payload ?? data);
157
+ const runtimes = payload.runtimes ?? [];
158
+ if (opts.json) {
159
+ writeJson({ ok: true, runtimes });
135
160
  return;
136
161
  }
137
- const runtimes = data.payload?.runtimes ?? data.runtimes ?? [];
138
162
  if (runtimes.length === 0) {
139
163
  console.log("No runtimes installed.");
140
164
  return;
@@ -176,7 +200,7 @@ export function registerSenpiCli(program) {
176
200
  const inner = (data.payload ?? data);
177
201
  const positions = (inner.positions ?? []);
178
202
  if (opts.json) {
179
- console.log(JSON.stringify({ ok: data.ok, positions }, null, 2));
203
+ writeJson({ ok: data.ok, positions });
180
204
  return;
181
205
  }
182
206
  if (positions.length === 0) {
@@ -245,7 +269,7 @@ export function registerSenpiCli(program) {
245
269
  const inner = (data.payload ?? data);
246
270
  const rows = (inner.positions ?? []);
247
271
  if (opts.json) {
248
- console.log(JSON.stringify({ ok: true, positions: rows }, null, 2));
272
+ writeJson({ ok: true, positions: rows });
249
273
  return;
250
274
  }
251
275
  for (const row of rows) {
@@ -299,7 +323,7 @@ export function registerSenpiCli(program) {
299
323
  const inner = (data.payload ?? data);
300
324
  const closes = (inner.closes ?? []);
301
325
  if (opts.json) {
302
- console.log(JSON.stringify({ ok: data.ok, closes }, null, 2));
326
+ writeJson({ ok: data.ok, closes });
303
327
  return;
304
328
  }
305
329
  if (closes.length === 0) {
@@ -371,7 +395,7 @@ export function registerSenpiCli(program) {
371
395
  const inner = (data.payload ?? data);
372
396
  const rows = (inner.actions ?? []);
373
397
  if (opts.json) {
374
- console.log(JSON.stringify({ ok: true, actions: rows }, null, 2));
398
+ writeJson({ ok: true, actions: rows });
375
399
  return;
376
400
  }
377
401
  if (rows.length === 0) {
@@ -434,7 +458,7 @@ export function registerSenpiCli(program) {
434
458
  const inner = (data.payload ?? data);
435
459
  const latest = inner.latest;
436
460
  if (opts.json) {
437
- console.log(JSON.stringify({ ok: true, latest }, null, 2));
461
+ writeJson({ ok: true, latest });
438
462
  return;
439
463
  }
440
464
  if (!latest) {
@@ -501,7 +525,7 @@ export function registerSenpiCli(program) {
501
525
  const inner = (data.payload ?? data);
502
526
  const history = (inner.history ?? []);
503
527
  if (opts.json) {
504
- console.log(JSON.stringify({ ok: true, history }, null, 2));
528
+ writeJson({ ok: true, history });
505
529
  return;
506
530
  }
507
531
  if (history.length === 0) {
@@ -571,7 +595,7 @@ export function registerSenpiCli(program) {
571
595
  const inner = (data.payload ?? data);
572
596
  const history = (inner.history ?? []);
573
597
  if (opts.json) {
574
- console.log(JSON.stringify({ ok: true, history }, null, 2));
598
+ writeJson({ ok: true, history });
575
599
  return;
576
600
  }
577
601
  if (history.length === 0) {
@@ -600,20 +624,25 @@ export function registerSenpiCli(program) {
600
624
  const params = {};
601
625
  if (typeof opts.runtime === "string" && opts.runtime.length > 0)
602
626
  params.runtimeId = opts.runtime;
603
- const data = callGatewayJson("senpi.getHealthStatus", params);
627
+ // Same class as the deploy verbs' null-data path: a health surface that exits 0 after
628
+ // reading no health is the one thing it exists not to do.
629
+ const data = callGatewayJson("senpi.getHealthStatus", params, (cause) => reportUnreadableGateway("senpi status", cause, " No health was read."));
604
630
  if (!data) {
605
631
  return;
606
632
  }
607
633
  if (data.ok === false) {
608
634
  const err = data.error;
609
- console.error(err?.message ?? "Request failed.");
610
- process.exitCode = 1;
635
+ const message = err?.message ?? "Request failed.";
636
+ console.error(message);
637
+ // Same reading as the deploy verbs, and the same reason: a coded refusal is something to
638
+ // obey, not to retry. Kept here so this branch and the subprocess-level one below agree.
639
+ process.exitCode = isRefusalMessage(message) ? DEPLOY_REFUSED_EXIT : 1;
611
640
  return;
612
641
  }
613
642
  const payload = (data.payload ?? data);
614
643
  const statuses = selectMany(payload.status, payload.statuses ?? []);
615
644
  if (opts.json) {
616
- console.log(JSON.stringify({ ok: true, statuses }, null, 2));
645
+ writeJson({ ok: true, statuses });
617
646
  return;
618
647
  }
619
648
  if (statuses.length === 0) {
@@ -648,7 +677,7 @@ export function registerSenpiCli(program) {
648
677
  const payload = (data.payload ?? data);
649
678
  const states = selectMany(payload.state, payload.states ?? []);
650
679
  if (opts.json) {
651
- console.log(JSON.stringify({ ok: true, states }, null, 2));
680
+ writeJson({ ok: true, states });
652
681
  return;
653
682
  }
654
683
  if (states.length === 0) {
@@ -687,7 +716,7 @@ export function registerSenpiCli(program) {
687
716
  runtimeId: s.runtimeId ?? s.runtimeName,
688
717
  scanners: s.components?.scanners?.state?.scanners ?? [],
689
718
  }));
690
- console.log(JSON.stringify({ ok: true, scanners }, null, 2));
719
+ writeJson({ ok: true, scanners });
691
720
  return;
692
721
  }
693
722
  if (states.length === 0) {
@@ -726,7 +755,7 @@ export function registerSenpiCli(program) {
726
755
  runtimeId: s.runtimeId ?? s.runtimeName,
727
756
  risk: s.components?.risk ?? null,
728
757
  }));
729
- console.log(JSON.stringify({ ok: true, risk }, null, 2));
758
+ writeJson({ ok: true, risk });
730
759
  return;
731
760
  }
732
761
  if (statuses.length === 0) {
@@ -776,7 +805,7 @@ export function registerSenpiCli(program) {
776
805
  if (opts.since)
777
806
  entries = entries.filter((e) => e.ts >= opts.since);
778
807
  if (opts.json) {
779
- console.log(JSON.stringify({ ok: true, entries }, null, 2));
808
+ writeJson({ ok: true, entries });
780
809
  return;
781
810
  }
782
811
  console.log(renderRiskAuditDigest(entries));
@@ -827,7 +856,7 @@ export function registerSenpiCli(program) {
827
856
  const inner = (data.payload ?? data);
828
857
  const result = inner.result ?? { entries: [], count: 0, total: 0, has_more: false };
829
858
  if (opts.json) {
830
- console.log(JSON.stringify({ ok: true, result }, null, 2));
859
+ writeJson({ ok: true, result });
831
860
  return;
832
861
  }
833
862
  if (result.entries.length === 0) {
@@ -864,7 +893,7 @@ export function registerSenpiCli(program) {
864
893
  if (entries === null)
865
894
  return;
866
895
  if (opts.json) {
867
- console.log(JSON.stringify({ ok: true, entries }, null, 2));
896
+ writeJson({ ok: true, entries });
868
897
  return;
869
898
  }
870
899
  console.log(renderEventsDigest(entries));
@@ -886,7 +915,7 @@ export function registerSenpiCli(program) {
886
915
  if (entries === null)
887
916
  return;
888
917
  if (opts.json) {
889
- console.log(JSON.stringify({ ok: true, asset, entries }, null, 2));
918
+ writeJson({ ok: true, asset, entries });
890
919
  return;
891
920
  }
892
921
  console.log(renderExplain(asset, entries));
@@ -914,7 +943,7 @@ export function registerSenpiCli(program) {
914
943
  return;
915
944
  }
916
945
  if (opts.json) {
917
- console.log(JSON.stringify(data, null, 2));
946
+ writeJson(data);
918
947
  return;
919
948
  }
920
949
  const payload = (data.payload ?? data);
@@ -996,7 +1025,7 @@ export function registerSenpiCli(program) {
996
1025
  return;
997
1026
  }
998
1027
  if (opts.json) {
999
- console.log(JSON.stringify(data, null, 2));
1028
+ writeJson(data);
1000
1029
  return;
1001
1030
  }
1002
1031
  // Surface gateway-level errors (ok: false) using the structured error
@@ -1040,7 +1069,7 @@ export function registerSenpiCli(program) {
1040
1069
  return;
1041
1070
  }
1042
1071
  if (opts.json) {
1043
- console.log(JSON.stringify(data, null, 2));
1072
+ writeJson(data);
1044
1073
  return;
1045
1074
  }
1046
1075
  const payload = (data.payload ?? data);
@@ -1101,11 +1130,226 @@ function fmtMetricNum(n) {
1101
1130
  return String(n);
1102
1131
  return n.toFixed(2);
1103
1132
  }
1104
- function callGatewayJson(method, params) {
1105
- const result = spawnSync(process.argv[0], [process.argv[1], "gateway", "call", method, "--json", "--params", JSON.stringify(params)], { stdio: ["inherit", "pipe", "inherit"], cwd: process.cwd(), encoding: "utf8" });
1133
+ /**
1134
+ * The `senpi deploy` verb pair — the agent-facing surface for the whole go-live
1135
+ * path. There is no `cancel` (D-4): undeploying a strategy is closing it, and a
1136
+ * wedged job frees its own slot at the deadline. `deploy` starts a DETACHED job and returns in ~1s; monitoring is explicit
1137
+ * polling of `deploy status`. The `senpi.deploy.*` gateway methods behind these
1138
+ * verbs are internal transport and are deliberately not documented anywhere an
1139
+ * agent reads.
1140
+ */
1141
+ function registerDeployCommands(senpi) {
1142
+ const deploy = senpi
1143
+ .command("deploy")
1144
+ .description("Deploy a strategy package end-to-end (detached): funds preflight, wallet create+fund, install, observe it running. " +
1145
+ "Starts the job and returns — watch with `senpi deploy status`. " +
1146
+ "Start exit codes: 0 job started · 2 refused (the message leads with the code) · 1 internal/transport error")
1147
+ // NOT `requiredOption`: Commander checks mandatory options by walking the ancestor chain from
1148
+ // the leaf command, so a mandatory `-p` on this parent makes `deploy status` fail before
1149
+ // dispatch ("required option '-p, --path <dir>' not specified"). The start action carries its
1150
+ // own explicit guard below, so nothing is lost.
1151
+ .option("-p, --path <dir>", "Strategy package directory (contains strategy.yaml)")
1152
+ .option("--budget <usd>", "Total budget in USD across the package's wallets (min $10/wallet)")
1153
+ .option("--decision-model <model>", "Model for llm-decision actions (required if the package uses decision_mode: llm)")
1154
+ .option("--tick-wait <seconds>", "How long the job waits to observe one scanner tick — or, for an external scanner, one fresh liveness post (default 120, 0 skips)")
1155
+ .option("--max-wait <seconds>", "How long the job waits for wallets to reach ACTIVE (default 150)")
1156
+ .option("--json", "Print the raw start response JSON")
1157
+ .action(async (opts) => {
1158
+ // Every numeric flag is validated the same way. A silently-dropped NaN would run the job
1159
+ // with the default window while the agent believes its own value took effect.
1160
+ // These local guards are REFUSALS, not usage errors: nothing was started, and re-running
1161
+ // the same command can only refuse again. They carry the taxonomy code and exit 2 like
1162
+ // every other start-time refusal — reported as 1 the newly-taught start map reads them as
1163
+ // "transport error, state unknown", whose natural handling is to poll `deploy status`.
1164
+ const numeric = (flag, raw, example) => {
1165
+ if (raw === undefined)
1166
+ return undefined;
1167
+ const value = Number(raw);
1168
+ if (!Number.isFinite(value)) {
1169
+ console.error(`[INVALID_REQUEST] ${flag} must be a number, e.g. ${flag} ${example}. Nothing was started.`);
1170
+ return null;
1171
+ }
1172
+ return value;
1173
+ };
1174
+ const budget = numeric("--budget", opts.budget, "500");
1175
+ const tickWaitSec = numeric("--tick-wait", opts.tickWait, "120");
1176
+ const maxWaitSec = numeric("--max-wait", opts.maxWait, "150");
1177
+ if (budget === null || tickWaitSec === null || maxWaitSec === null) {
1178
+ process.exitCode = DEPLOY_REFUSED_EXIT;
1179
+ return;
1180
+ }
1181
+ if (!opts.path) {
1182
+ // This guard fires BEFORE the gateway is called, so the gateway's own coded
1183
+ // missing-package-dir refusal is unreachable from the CLI — this surface has to carry
1184
+ // it verbatim rather than degrade it to a codeless usage error.
1185
+ console.error("[INVALID_REQUEST] A strategy package directory is required. Nothing was started. " +
1186
+ "Run: senpi deploy -p <package-dir> --budget <usd>");
1187
+ process.exitCode = DEPLOY_REFUSED_EXIT;
1188
+ return;
1189
+ }
1190
+ const params = {
1191
+ packageDir: path.resolve(process.cwd(), opts.path),
1192
+ ...(budget !== undefined ? { budget } : {}),
1193
+ ...(opts.decisionModel ? { decisionModel: opts.decisionModel } : {}),
1194
+ ...(tickWaitSec !== undefined ? { tickWaitSec } : {}),
1195
+ ...(maxWaitSec !== undefined ? { maxWaitSec } : {}),
1196
+ };
1197
+ const data = callGatewayJson("senpi.deploy.start", params, (cause) => reportUnreadableGateway("senpi deploy", cause, DEPLOY_STATE_UNKNOWN_HINT));
1198
+ if (!data)
1199
+ return;
1200
+ if (data.ok === false) {
1201
+ const err = data.error;
1202
+ const message = err?.message ?? "Deploy start failed.";
1203
+ console.error(message);
1204
+ // D-12 all the way down: `2 = refused`, `1 = internal/transport`. Every start-time gate
1205
+ // (the [INVALID_REQUEST] family — no DSL exit, missing decision model/env, scanner
1206
+ // `enabled` key, non-positive budget, missing/unreadable package — plus
1207
+ // [E_DEPLOY_IN_PROGRESS]) is a refusal, and the taught surfaces tell agents to branch on
1208
+ // the code. Reported as 1 they read as "internal/transport error", whose natural
1209
+ // handling is retry rather than obey — a retried no-stop-loss refusal is the whole bug.
1210
+ process.exitCode = isRefusalMessage(message) ? DEPLOY_REFUSED_EXIT : 1;
1211
+ return;
1212
+ }
1213
+ const started = (data.payload ?? data);
1214
+ if (opts.json) {
1215
+ writeJson(started);
1216
+ return;
1217
+ }
1218
+ console.log(`deploy ${started.deployId} started — phase: ${started.phase}`);
1219
+ console.log(" watch: openclaw senpi deploy status");
1220
+ });
1221
+ deploy
1222
+ .command("status [deployId]")
1223
+ .description("Show the deploy job: phase while running; the full verified report once terminal. " +
1224
+ "Exit codes: 0 live · 2 refused · 3 failed · 4 installed-unobserved · 5 interrupted · " +
1225
+ "6 pending/still running · 1 error")
1226
+ .option("--json", "Print the raw snapshot JSON")
1227
+ .action(async (deployId, opts) => {
1228
+ const data = callGatewayJson("senpi.deploy.status", deployId ? { deployId } : {}, (cause) => reportUnreadableGateway("senpi deploy status", cause, DEPLOY_STATUS_STATE_UNKNOWN_HINT));
1229
+ if (!data)
1230
+ return;
1231
+ if (data.ok === false) {
1232
+ const message = data.error?.message ?? "Status failed.";
1233
+ console.error(message);
1234
+ // Read the same way the start verb reads its own gateway error, and for the same reason:
1235
+ // `[NOT_FOUND] No deploy has been started on this agent` is a fact, not a fault. Exit 1
1236
+ // would tell an agent to retry a read whose answer cannot change until a deploy is started.
1237
+ process.exitCode = isRefusalMessage(message) ? DEPLOY_REFUSED_EXIT : 1;
1238
+ return;
1239
+ }
1240
+ const snap = (data.payload ?? data);
1241
+ // D-12: the exit code applies on the --json path too, so a JSON consumer gets the code AND
1242
+ // the payload rather than having to choose.
1243
+ process.exitCode = exitCodeForDeploy(snap);
1244
+ if (opts?.json) {
1245
+ writeJson(snap);
1246
+ return;
1247
+ }
1248
+ renderDeploySnapshot(snap);
1249
+ });
1250
+ }
1251
+ /**
1252
+ * D-12: `2 = refused`. Named so the start action's guards, its gateway branch, and the one place
1253
+ * every verb's gateway call is classified (`callGatewayJson`) cannot drift. `2` means the same thing
1254
+ * wherever it comes from — a deliberate no, to obey rather than retry — so `senpi status` reports a
1255
+ * coded refusal with it too, even though only the deploy verbs publish the full map.
1256
+ */
1257
+ const DEPLOY_REFUSED_EXIT = 2;
1258
+ /** Appended to a deploy verb's unreadable-gateway message: the one surface that can still answer. */
1259
+ const DEPLOY_STATE_UNKNOWN_HINT = " This says nothing about the deploy itself — if the gateway is up, ask `senpi deploy status` " +
1260
+ "for the job's real state, and check the gateway log if that keeps failing.";
1261
+ /**
1262
+ * The `deploy status` variant of the same teaching.
1263
+ *
1264
+ * `DEPLOY_STATE_UNKNOWN_HINT` names `senpi deploy status` as the surface that can still answer,
1265
+ * which is a loop when the verb the reader just ran IS status. Same content — the deploy is
1266
+ * untouched by this failure, and the job may be running right now — routed to the thing that
1267
+ * actually has to change first.
1268
+ */
1269
+ const DEPLOY_STATUS_STATE_UNKNOWN_HINT = " This says nothing about the deploy itself — a started job may be running right now. Start the " +
1270
+ "gateway if it is down (`openclaw gateway run`), check the gateway log, then re-read.";
1271
+ /**
1272
+ * Did the gateway ANSWER this failed `gateway call`, with a refusal?
1273
+ *
1274
+ * `openclaw gateway call` collapses two different worlds into one process status: it catches
1275
+ * everything its RPC throws, prints `Gateway call failed: <error>` to stderr, and exits **1** —
1276
+ * whether the gateway was never reachable or the gateway answered `respond(false, undefined, error)`
1277
+ * and the client rethrew that answer as a `GatewayClientRequestError`. There is no second signal to
1278
+ * read: stdout carries the payload only on success, and the exit code is a constant.
1279
+ *
1280
+ * What DOES separate them is this plugin's own message taxonomy. Every refusal these gateway methods
1281
+ * produce leads with its bracketed code — `[INVALID_REQUEST]`, `[E_UNIVERSE_NOT_LIVE]`,
1282
+ * `[E_NO_DSL_EXIT]`, `[E_WALLET_INSTALL_IN_FLIGHT]`, `[NOT_FOUND]` — and no transport failure does:
1283
+ * those read `gateway closed (1006 …)`, `gateway timeout after 10000ms`, `connect ECONNREFUSED …`,
1284
+ * `gateway … requires credentials`. So the classifier is the taxonomy, not openclaw's error class
1285
+ * names (which are its internals and free to change), and the reader is the ONE reader —
1286
+ * `isRefusalMessage`, which is built on `extractTaxonomyCode` and already knows the advisory `W_`
1287
+ * family is not a refusal.
1288
+ *
1289
+ * Every bracket is tried, not just the first: the code sits behind a `Gateway call failed: ` label
1290
+ * and an error name, and a colourised or otherwise decorated stderr can put other brackets ahead
1291
+ * of it.
1292
+ */
1293
+ function gatewayAnsweredRefusal(stderr) {
1294
+ for (let i = stderr.indexOf("["); i >= 0; i = stderr.indexOf("[", i + 1)) {
1295
+ if (isRefusalMessage(stderr.slice(i)))
1296
+ return true;
1297
+ }
1298
+ return false;
1299
+ }
1300
+ /**
1301
+ * The answer for a `gateway call` that produced nothing this CLI could read.
1302
+ *
1303
+ * Always 1 (internal/transport), never 0 — under D-12 a 0 from a deploy verb means `live`, and this
1304
+ * path learned nothing about the job. Deliberately overrides whatever exit code the subprocess
1305
+ * carried, so a `gateway call` that happened to exit 3 cannot masquerade as D-12 `failed`. It never
1306
+ * claims the deploy failed either: a started job may be running right now.
1307
+ */
1308
+ function reportUnreadableGateway(verb, cause, followUp = "") {
1309
+ process.exitCode = 1;
1310
+ console.error((cause === "dispatch"
1311
+ ? `${verb}: the \`gateway call\` subprocess failed, so nothing was read back — exit 1 (transport/internal).`
1312
+ : `${verb}: the gateway answered but its response could not be read — exit 1 (transport/internal).`) +
1313
+ followUp);
1314
+ }
1315
+ /**
1316
+ * `onFailure` fires on either null path, naming which one. Callers that pass it own the exit code
1317
+ * and the message; callers that omit it keep the historical behaviour (the subprocess's own code
1318
+ * plus the gateway-not-running tip, and a silent return on unparseable stdout).
1319
+ *
1320
+ * A gateway-answered REFUSAL takes neither path: it is classified and exited here, so no caller can
1321
+ * print an unreadable-gateway message over an answer the user has already read.
1322
+ */
1323
+ function callGatewayJson(method, params, onFailure) {
1324
+ const result = spawnSync(process.argv[0], [process.argv[1], "gateway", "call", method, "--json", "--params", JSON.stringify(params)],
1325
+ // stderr is PIPED, where it used to be inherited, for one reason: a gateway REFUSAL arrives
1326
+ // only there, and a stderr this process never sees is a stderr it can contradict. The child
1327
+ // still owns every character of it — see the verbatim re-emit directly below.
1328
+ { stdio: ["inherit", "pipe", "pipe"], cwd: process.cwd(), encoding: "utf8" });
1329
+ const stderr = typeof result.stderr === "string" ? result.stderr : "";
1330
+ // FIRST, before anything this CLI prints, which is exactly where an inherited stderr put it —
1331
+ // the child has already exited, so its whole output is ordered ahead of ours. Unmodified: no
1332
+ // reformatting, no truncation, no prefix. The only edit is a terminating newline when the child
1333
+ // did not write one, so the next line cannot be glued onto the last word of a refusal.
1334
+ if (stderr.length > 0) {
1335
+ process.stderr.write(stderr.endsWith("\n") ? stderr : `${stderr}\n`);
1336
+ }
1106
1337
  if (result.status !== 0) {
1338
+ if (gatewayAnsweredRefusal(stderr)) {
1339
+ // The gateway answered, and it refused. D-12: `2 = refused` — the code agents branch on to
1340
+ // OBEY rather than retry. Reported as 1 (internal/transport) these read as "try again", and
1341
+ // a delisted instrument, a package with no DSL exit, or a wallet another package's stamp
1342
+ // claims will refuse identically forever.
1343
+ //
1344
+ // Nothing further is printed. The refusal above is the answer; the unreadable-gateway text
1345
+ // ("nothing was read back", "if the gateway is not running") would contradict it one line
1346
+ // later, which is the defect this branch exists to end.
1347
+ process.exitCode = DEPLOY_REFUSED_EXIT;
1348
+ return null;
1349
+ }
1107
1350
  process.exitCode = result.status ?? 1;
1108
1351
  console.error("\nTip: If the gateway is not running, start it with: openclaw gateway run");
1352
+ onFailure?.("dispatch");
1109
1353
  return null;
1110
1354
  }
1111
1355
  try {
@@ -1113,6 +1357,11 @@ function callGatewayJson(method, params) {
1113
1357
  }
1114
1358
  catch {
1115
1359
  process.stdout.write(result.stdout ?? "");
1360
+ // Unparseable stdout means this command did NOT do what its output implies, so it must never
1361
+ // exit 0. Set here rather than per-verb so the swallow cannot re-seed itself on the next
1362
+ // caller; verbs that pass `onFailure` refine the message, not the code.
1363
+ process.exitCode = 1;
1364
+ onFailure?.("unreadable");
1116
1365
  return null;
1117
1366
  }
1118
1367
  }