@senpi-ai/runtime 1.0.96 → 1.0.98

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 (436) hide show
  1. package/README.md +113 -2
  2. package/dist/actions/action-runtime-module.d.ts +55 -0
  3. package/dist/actions/action-runtime-module.d.ts.map +1 -0
  4. package/dist/actions/action-runtime-module.js +491 -0
  5. package/dist/actions/action-runtime-module.js.map +1 -0
  6. package/dist/actions/close-position/close-position.action.d.ts +1 -0
  7. package/dist/actions/close-position/close-position.action.d.ts.map +1 -1
  8. package/dist/actions/close-position/close-position.action.js +93 -25
  9. package/dist/actions/close-position/close-position.action.js.map +1 -1
  10. package/dist/actions/decision-engine.d.ts.map +1 -1
  11. package/dist/actions/decision-engine.js +5 -0
  12. package/dist/actions/decision-engine.js.map +1 -1
  13. package/dist/actions/decision-meta.d.ts +9 -0
  14. package/dist/actions/decision-meta.d.ts.map +1 -0
  15. package/dist/actions/decision-meta.js +18 -0
  16. package/dist/actions/decision-meta.js.map +1 -0
  17. package/dist/actions/llm-decision/openclaw-llm-decision.d.ts.map +1 -1
  18. package/dist/actions/llm-decision/openclaw-llm-decision.js +6 -0
  19. package/dist/actions/llm-decision/openclaw-llm-decision.js.map +1 -1
  20. package/dist/actions/llm-decision/shared.d.ts +1 -1
  21. package/dist/actions/llm-decision/shared.d.ts.map +1 -1
  22. package/dist/actions/llm-decision/shared.js +1 -1
  23. package/dist/actions/llm-decision/shared.js.map +1 -1
  24. package/dist/actions/notifications/formatter.d.ts +39 -0
  25. package/dist/actions/notifications/formatter.d.ts.map +1 -0
  26. package/dist/actions/notifications/formatter.js +68 -0
  27. package/dist/actions/notifications/formatter.js.map +1 -0
  28. package/dist/actions/notifications/index.d.ts +37 -0
  29. package/dist/actions/notifications/index.d.ts.map +1 -0
  30. package/dist/actions/notifications/index.js +89 -0
  31. package/dist/actions/notifications/index.js.map +1 -0
  32. package/dist/actions/open-position/open-position.action.d.ts +1 -0
  33. package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
  34. package/dist/actions/open-position/open-position.action.js +197 -34
  35. package/dist/actions/open-position/open-position.action.js.map +1 -1
  36. package/dist/actions/open-position/resolve-margin.d.ts +30 -0
  37. package/dist/actions/open-position/resolve-margin.d.ts.map +1 -0
  38. package/dist/actions/open-position/resolve-margin.js +41 -0
  39. package/dist/actions/open-position/resolve-margin.js.map +1 -0
  40. package/dist/actions/position-tracker/position-tracker.action.d.ts.map +1 -1
  41. package/dist/actions/position-tracker/position-tracker.action.js +4 -1
  42. package/dist/actions/position-tracker/position-tracker.action.js.map +1 -1
  43. package/dist/actions/store/action-store.d.ts +45 -0
  44. package/dist/actions/store/action-store.d.ts.map +1 -0
  45. package/dist/actions/store/action-store.js +127 -0
  46. package/dist/actions/store/action-store.js.map +1 -0
  47. package/dist/actions/store/index.d.ts +11 -0
  48. package/dist/actions/store/index.d.ts.map +1 -0
  49. package/dist/actions/store/index.js +9 -0
  50. package/dist/actions/store/index.js.map +1 -0
  51. package/dist/actions/store/paths.d.ts +15 -0
  52. package/dist/actions/store/paths.d.ts.map +1 -0
  53. package/dist/actions/store/paths.js +29 -0
  54. package/dist/actions/store/paths.js.map +1 -0
  55. package/dist/actions/store/types.d.ts +126 -0
  56. package/dist/actions/store/types.d.ts.map +1 -0
  57. package/dist/actions/store/types.js +48 -0
  58. package/dist/actions/store/types.js.map +1 -0
  59. package/dist/actions/tracking-helpers.d.ts +13 -0
  60. package/dist/actions/tracking-helpers.d.ts.map +1 -0
  61. package/dist/actions/tracking-helpers.js +47 -0
  62. package/dist/actions/tracking-helpers.js.map +1 -0
  63. package/dist/actions/types.d.ts +8 -0
  64. package/dist/actions/types.d.ts.map +1 -1
  65. package/dist/cli/guide-commands.d.ts.map +1 -1
  66. package/dist/cli/guide-commands.js +106 -4
  67. package/dist/cli/guide-commands.js.map +1 -1
  68. package/dist/cli/senpi-commands.d.ts.map +1 -1
  69. package/dist/cli/senpi-commands.js +447 -1
  70. package/dist/cli/senpi-commands.js.map +1 -1
  71. package/dist/constants/dsl/index.d.ts +12 -0
  72. package/dist/constants/dsl/index.d.ts.map +1 -1
  73. package/dist/constants/dsl/index.js +12 -0
  74. package/dist/constants/dsl/index.js.map +1 -1
  75. package/dist/constants/order-types.d.ts +7 -0
  76. package/dist/constants/order-types.d.ts.map +1 -0
  77. package/dist/constants/order-types.js +6 -0
  78. package/dist/constants/order-types.js.map +1 -0
  79. package/dist/context/interpolate.d.ts +6 -2
  80. package/dist/context/interpolate.d.ts.map +1 -1
  81. package/dist/context/interpolate.js +6 -2
  82. package/dist/context/interpolate.js.map +1 -1
  83. package/dist/context/types.d.ts +8 -1
  84. package/dist/context/types.d.ts.map +1 -1
  85. package/dist/context/types.js +8 -1
  86. package/dist/context/types.js.map +1 -1
  87. package/dist/dsl/config/exit-block.d.ts +7 -0
  88. package/dist/dsl/config/exit-block.d.ts.map +1 -1
  89. package/dist/dsl/config/parse-plugin-config.d.ts.map +1 -1
  90. package/dist/dsl/config/parse-plugin-config.js +27 -1
  91. package/dist/dsl/config/parse-plugin-config.js.map +1 -1
  92. package/dist/dsl/config/unknown-keys.d.ts.map +1 -1
  93. package/dist/dsl/config/unknown-keys.js +3 -1
  94. package/dist/dsl/config/unknown-keys.js.map +1 -1
  95. package/dist/dsl/engine-client/event-mapping.d.ts +21 -1
  96. package/dist/dsl/engine-client/event-mapping.d.ts.map +1 -1
  97. package/dist/dsl/engine-client/event-mapping.js +10 -0
  98. package/dist/dsl/engine-client/event-mapping.js.map +1 -1
  99. package/dist/dsl/engine-client/index.d.ts +1 -1
  100. package/dist/dsl/engine-client/index.d.ts.map +1 -1
  101. package/dist/dsl/events/build-closed-event.d.ts +15 -0
  102. package/dist/dsl/events/build-closed-event.d.ts.map +1 -0
  103. package/dist/dsl/events/build-closed-event.js +31 -0
  104. package/dist/dsl/events/build-closed-event.js.map +1 -0
  105. package/dist/dsl/events/handlers.d.ts +2 -1
  106. package/dist/dsl/events/handlers.d.ts.map +1 -1
  107. package/dist/dsl/events/handlers.js +15 -10
  108. package/dist/dsl/events/handlers.js.map +1 -1
  109. package/dist/dsl/events/initial-state.d.ts +2 -2
  110. package/dist/dsl/events/initial-state.d.ts.map +1 -1
  111. package/dist/dsl/events/initial-state.js +4 -1
  112. package/dist/dsl/events/initial-state.js.map +1 -1
  113. package/dist/dsl/index.js +1 -1
  114. package/dist/dsl/index.js.map +1 -1
  115. package/dist/dsl/monitor/create-monitor.d.ts +4 -0
  116. package/dist/dsl/monitor/create-monitor.d.ts.map +1 -1
  117. package/dist/dsl/monitor/create-monitor.js +8 -5
  118. package/dist/dsl/monitor/create-monitor.js.map +1 -1
  119. package/dist/dsl/monitor/process-one-position.d.ts +4 -0
  120. package/dist/dsl/monitor/process-one-position.d.ts.map +1 -1
  121. package/dist/dsl/monitor/process-one-position.js +129 -40
  122. package/dist/dsl/monitor/process-one-position.js.map +1 -1
  123. package/dist/dsl/notifications/close-resolver.d.ts +92 -0
  124. package/dist/dsl/notifications/close-resolver.d.ts.map +1 -0
  125. package/dist/dsl/notifications/close-resolver.js +309 -0
  126. package/dist/dsl/notifications/close-resolver.js.map +1 -0
  127. package/dist/dsl/notifications/format-utils.d.ts +24 -0
  128. package/dist/dsl/notifications/format-utils.d.ts.map +1 -0
  129. package/dist/dsl/notifications/format-utils.js +102 -0
  130. package/dist/dsl/notifications/format-utils.js.map +1 -0
  131. package/dist/dsl/notifications/formatter.d.ts +23 -4
  132. package/dist/dsl/notifications/formatter.d.ts.map +1 -1
  133. package/dist/dsl/notifications/formatter.js +109 -34
  134. package/dist/dsl/notifications/formatter.js.map +1 -1
  135. package/dist/dsl/notifications/index.d.ts +7 -0
  136. package/dist/dsl/notifications/index.d.ts.map +1 -1
  137. package/dist/dsl/notifications/index.js +22 -10
  138. package/dist/dsl/notifications/index.js.map +1 -1
  139. package/dist/dsl/notifications/types.d.ts +27 -0
  140. package/dist/dsl/notifications/types.d.ts.map +1 -0
  141. package/dist/dsl/notifications/types.js +5 -0
  142. package/dist/dsl/notifications/types.js.map +1 -0
  143. package/dist/dsl/plugin/index.d.ts +1 -1
  144. package/dist/dsl/plugin/index.d.ts.map +1 -1
  145. package/dist/dsl/plugin/index.js +29 -1
  146. package/dist/dsl/plugin/index.js.map +1 -1
  147. package/dist/health/index.d.ts +5 -2
  148. package/dist/health/index.d.ts.map +1 -1
  149. package/dist/health/index.js +106 -6
  150. package/dist/health/index.js.map +1 -1
  151. package/dist/health/types.d.ts +102 -0
  152. package/dist/health/types.d.ts.map +1 -1
  153. package/dist/health/types.js +7 -1
  154. package/dist/health/types.js.map +1 -1
  155. package/dist/index.d.ts +10 -2
  156. package/dist/index.d.ts.map +1 -1
  157. package/dist/index.js +459 -8
  158. package/dist/index.js.map +1 -1
  159. package/dist/risk/guardrail.types.d.ts +58 -0
  160. package/dist/risk/guardrail.types.d.ts.map +1 -0
  161. package/dist/risk/guardrail.types.js +5 -0
  162. package/dist/risk/guardrail.types.js.map +1 -0
  163. package/dist/risk/index.d.ts +2 -4
  164. package/dist/risk/index.d.ts.map +1 -1
  165. package/dist/risk/index.js +2 -6
  166. package/dist/risk/index.js.map +1 -1
  167. package/dist/risk/risk-audit-log.d.ts +25 -0
  168. package/dist/risk/risk-audit-log.d.ts.map +1 -0
  169. package/dist/risk/risk-audit-log.js +30 -0
  170. package/dist/risk/risk-audit-log.js.map +1 -0
  171. package/dist/runtime/__tests__/helpers/runtime-gateway-harness.d.ts +162 -0
  172. package/dist/runtime/__tests__/helpers/runtime-gateway-harness.d.ts.map +1 -0
  173. package/dist/runtime/__tests__/helpers/runtime-gateway-harness.js +285 -0
  174. package/dist/runtime/__tests__/helpers/runtime-gateway-harness.js.map +1 -0
  175. package/dist/runtime/audit-query.types.d.ts +113 -0
  176. package/dist/runtime/audit-query.types.d.ts.map +1 -0
  177. package/dist/runtime/audit-query.types.js +35 -0
  178. package/dist/runtime/audit-query.types.js.map +1 -0
  179. package/dist/runtime/auto-update/coordinator.d.ts +12 -8
  180. package/dist/runtime/auto-update/coordinator.d.ts.map +1 -1
  181. package/dist/runtime/auto-update/coordinator.js +18 -17
  182. package/dist/runtime/auto-update/coordinator.js.map +1 -1
  183. package/dist/runtime/auto-update/gateway-restart.d.ts +9 -2
  184. package/dist/runtime/auto-update/gateway-restart.d.ts.map +1 -1
  185. package/dist/runtime/auto-update/gateway-restart.js +23 -13
  186. package/dist/runtime/auto-update/gateway-restart.js.map +1 -1
  187. package/dist/runtime/create-actions.d.ts +6 -2
  188. package/dist/runtime/create-actions.d.ts.map +1 -1
  189. package/dist/runtime/create-actions.js +30 -8
  190. package/dist/runtime/create-actions.js.map +1 -1
  191. package/dist/runtime/create-scanner-module.d.ts +5 -0
  192. package/dist/runtime/create-scanner-module.d.ts.map +1 -1
  193. package/dist/runtime/create-scanner-module.js +12 -1
  194. package/dist/runtime/create-scanner-module.js.map +1 -1
  195. package/dist/runtime/load-runtime-config.d.ts +1 -1
  196. package/dist/runtime/load-runtime-config.d.ts.map +1 -1
  197. package/dist/runtime/load-runtime-config.js +37 -1
  198. package/dist/runtime/load-runtime-config.js.map +1 -1
  199. package/dist/runtime/map-exit-config.d.ts +2 -1
  200. package/dist/runtime/map-exit-config.d.ts.map +1 -1
  201. package/dist/runtime/map-exit-config.js +11 -1
  202. package/dist/runtime/map-exit-config.js.map +1 -1
  203. package/dist/runtime/map-strategies.d.ts +1 -1
  204. package/dist/runtime/map-strategies.d.ts.map +1 -1
  205. package/dist/runtime/map-strategies.js +38 -1
  206. package/dist/runtime/map-strategies.js.map +1 -1
  207. package/dist/runtime/notifications.d.ts.map +1 -1
  208. package/dist/runtime/notifications.js +53 -7
  209. package/dist/runtime/notifications.js.map +1 -1
  210. package/dist/runtime/risk-guard.d.ts +26 -2
  211. package/dist/runtime/risk-guard.d.ts.map +1 -1
  212. package/dist/runtime/risk-guard.js +539 -5
  213. package/dist/runtime/risk-guard.js.map +1 -1
  214. package/dist/runtime/run.d.ts +96 -2
  215. package/dist/runtime/run.d.ts.map +1 -1
  216. package/dist/runtime/run.js +21 -0
  217. package/dist/runtime/run.js.map +1 -1
  218. package/dist/runtime/runtime-schema.d.ts +1169 -24
  219. package/dist/runtime/runtime-schema.d.ts.map +1 -1
  220. package/dist/runtime/runtime-schema.js +105 -2
  221. package/dist/runtime/runtime-schema.js.map +1 -1
  222. package/dist/runtime/runtime.d.ts +85 -2
  223. package/dist/runtime/runtime.d.ts.map +1 -1
  224. package/dist/runtime/runtime.js +374 -10
  225. package/dist/runtime/runtime.js.map +1 -1
  226. package/dist/runtime/scanner-composition.d.ts +10 -0
  227. package/dist/runtime/scanner-composition.d.ts.map +1 -1
  228. package/dist/runtime/scanner-composition.js +10 -0
  229. package/dist/runtime/scanner-composition.js.map +1 -1
  230. package/dist/runtime/scanner-registry.d.ts +39 -1
  231. package/dist/runtime/scanner-registry.d.ts.map +1 -1
  232. package/dist/runtime/scanner-registry.js +105 -2
  233. package/dist/runtime/scanner-registry.js.map +1 -1
  234. package/dist/runtime/state-layout.d.ts +2 -0
  235. package/dist/runtime/state-layout.d.ts.map +1 -1
  236. package/dist/runtime/state-layout.js +1 -0
  237. package/dist/runtime/state-layout.js.map +1 -1
  238. package/dist/runtime/validate-action-prompts.d.ts +30 -0
  239. package/dist/runtime/validate-action-prompts.d.ts.map +1 -0
  240. package/dist/runtime/validate-action-prompts.js +110 -0
  241. package/dist/runtime/validate-action-prompts.js.map +1 -0
  242. package/dist/runtime-api/config.d.ts +47 -0
  243. package/dist/runtime-api/config.d.ts.map +1 -0
  244. package/dist/runtime-api/config.js +74 -0
  245. package/dist/runtime-api/config.js.map +1 -0
  246. package/dist/runtime-api/handlers/audit.d.ts +78 -0
  247. package/dist/runtime-api/handlers/audit.d.ts.map +1 -0
  248. package/dist/runtime-api/handlers/audit.js +65 -0
  249. package/dist/runtime-api/handlers/audit.js.map +1 -0
  250. package/dist/runtime-api/handlers/group-by-scanner.d.ts +43 -0
  251. package/dist/runtime-api/handlers/group-by-scanner.d.ts.map +1 -0
  252. package/dist/runtime-api/handlers/group-by-scanner.js +43 -0
  253. package/dist/runtime-api/handlers/group-by-scanner.js.map +1 -0
  254. package/dist/runtime-api/handlers/ingest-signals.d.ts +54 -0
  255. package/dist/runtime-api/handlers/ingest-signals.d.ts.map +1 -0
  256. package/dist/runtime-api/handlers/ingest-signals.js +124 -0
  257. package/dist/runtime-api/handlers/ingest-signals.js.map +1 -0
  258. package/dist/runtime-api/handlers/runtime-lookup.d.ts +36 -0
  259. package/dist/runtime-api/handlers/runtime-lookup.d.ts.map +1 -0
  260. package/dist/runtime-api/handlers/runtime-lookup.js +31 -0
  261. package/dist/runtime-api/handlers/runtime-lookup.js.map +1 -0
  262. package/dist/runtime-api/handlers/types.d.ts +85 -0
  263. package/dist/runtime-api/handlers/types.d.ts.map +1 -0
  264. package/dist/runtime-api/handlers/types.js +8 -0
  265. package/dist/runtime-api/handlers/types.js.map +1 -0
  266. package/dist/runtime-api/lifecycle.d.ts +98 -0
  267. package/dist/runtime-api/lifecycle.d.ts.map +1 -0
  268. package/dist/runtime-api/lifecycle.js +137 -0
  269. package/dist/runtime-api/lifecycle.js.map +1 -0
  270. package/dist/runtime-api/readiness.d.ts +37 -0
  271. package/dist/runtime-api/readiness.d.ts.map +1 -0
  272. package/dist/runtime-api/readiness.js +35 -0
  273. package/dist/runtime-api/readiness.js.map +1 -0
  274. package/dist/runtime-api/routes/audit.d.ts +40 -0
  275. package/dist/runtime-api/routes/audit.d.ts.map +1 -0
  276. package/dist/runtime-api/routes/audit.js +90 -0
  277. package/dist/runtime-api/routes/audit.js.map +1 -0
  278. package/dist/runtime-api/routes/audit.schema.d.ts +75 -0
  279. package/dist/runtime-api/routes/audit.schema.d.ts.map +1 -0
  280. package/dist/runtime-api/routes/audit.schema.js +78 -0
  281. package/dist/runtime-api/routes/audit.schema.js.map +1 -0
  282. package/dist/runtime-api/routes/health.d.ts +53 -0
  283. package/dist/runtime-api/routes/health.d.ts.map +1 -0
  284. package/dist/runtime-api/routes/health.js +48 -0
  285. package/dist/runtime-api/routes/health.js.map +1 -0
  286. package/dist/runtime-api/routes/signals.d.ts +50 -0
  287. package/dist/runtime-api/routes/signals.d.ts.map +1 -0
  288. package/dist/runtime-api/routes/signals.js +90 -0
  289. package/dist/runtime-api/routes/signals.js.map +1 -0
  290. package/dist/runtime-api/routes/signals.schema.d.ts +94 -0
  291. package/dist/runtime-api/routes/signals.schema.d.ts.map +1 -0
  292. package/dist/runtime-api/routes/signals.schema.js +58 -0
  293. package/dist/runtime-api/routes/signals.schema.js.map +1 -0
  294. package/dist/runtime-api/routes/state.d.ts +51 -0
  295. package/dist/runtime-api/routes/state.d.ts.map +1 -0
  296. package/dist/runtime-api/routes/state.js +94 -0
  297. package/dist/runtime-api/routes/state.js.map +1 -0
  298. package/dist/runtime-api/server.d.ts +79 -0
  299. package/dist/runtime-api/server.d.ts.map +1 -0
  300. package/dist/runtime-api/server.js +114 -0
  301. package/dist/runtime-api/server.js.map +1 -0
  302. package/dist/scanners/__tests__/test-helpers.d.ts +10 -0
  303. package/dist/scanners/__tests__/test-helpers.d.ts.map +1 -1
  304. package/dist/scanners/__tests__/test-helpers.js +52 -0
  305. package/dist/scanners/__tests__/test-helpers.js.map +1 -1
  306. package/dist/scanners/engine/engine.d.ts +37 -0
  307. package/dist/scanners/engine/engine.d.ts.map +1 -1
  308. package/dist/scanners/engine/engine.js +132 -14
  309. package/dist/scanners/engine/engine.js.map +1 -1
  310. package/dist/scanners/engine/result-builder.d.ts +16 -0
  311. package/dist/scanners/engine/result-builder.d.ts.map +1 -1
  312. package/dist/scanners/engine/result-builder.js +22 -0
  313. package/dist/scanners/engine/result-builder.js.map +1 -1
  314. package/dist/scanners/engine/strategy-registry.d.ts +2 -0
  315. package/dist/scanners/engine/strategy-registry.d.ts.map +1 -1
  316. package/dist/scanners/engine/strategy-registry.js +5 -1
  317. package/dist/scanners/engine/strategy-registry.js.map +1 -1
  318. package/dist/scanners/external/liquidation-watchdog/README.md +107 -0
  319. package/dist/scanners/external/liquidation-watchdog/liquidation-watchdog.yaml +48 -0
  320. package/dist/scanners/external/liquidation-watchdog/producer.mjs +336 -0
  321. package/dist/scanners/external/momentum/README.md +148 -0
  322. package/dist/scanners/external/momentum/momentum.yaml +116 -0
  323. package/dist/scanners/external/momentum/producer.mjs +251 -0
  324. package/dist/scanners/external/shared/ingest.mjs +112 -0
  325. package/dist/scanners/external-scanner-receiver.d.ts +118 -0
  326. package/dist/scanners/external-scanner-receiver.d.ts.map +1 -0
  327. package/dist/scanners/external-scanner-receiver.js +266 -0
  328. package/dist/scanners/external-scanner-receiver.js.map +1 -0
  329. package/dist/scanners/implementations/external-scanner.d.ts +17 -0
  330. package/dist/scanners/implementations/external-scanner.d.ts.map +1 -0
  331. package/dist/scanners/implementations/external-scanner.js +51 -0
  332. package/dist/scanners/implementations/external-scanner.js.map +1 -0
  333. package/dist/scanners/implementations/index.d.ts +1 -0
  334. package/dist/scanners/implementations/index.d.ts.map +1 -1
  335. package/dist/scanners/implementations/index.js +1 -0
  336. package/dist/scanners/implementations/index.js.map +1 -1
  337. package/dist/scanners/implementations/position-tracker.d.ts.map +1 -1
  338. package/dist/scanners/implementations/position-tracker.js +3 -1
  339. package/dist/scanners/implementations/position-tracker.js.map +1 -1
  340. package/dist/scanners/index.d.ts +4 -1
  341. package/dist/scanners/index.d.ts.map +1 -1
  342. package/dist/scanners/index.js +2 -0
  343. package/dist/scanners/index.js.map +1 -1
  344. package/dist/scanners/protocol/scanner.d.ts +3 -1
  345. package/dist/scanners/protocol/scanner.d.ts.map +1 -1
  346. package/dist/scanners/providers/client.d.ts.map +1 -1
  347. package/dist/scanners/providers/client.js +0 -8
  348. package/dist/scanners/providers/client.js.map +1 -1
  349. package/dist/scanners/runtime-module.d.ts +10 -0
  350. package/dist/scanners/runtime-module.d.ts.map +1 -1
  351. package/dist/scanners/runtime-module.js +19 -3
  352. package/dist/scanners/runtime-module.js.map +1 -1
  353. package/dist/scanners/scanner-definition.d.ts +12 -1
  354. package/dist/scanners/scanner-definition.d.ts.map +1 -1
  355. package/dist/scanners/schema-utils.d.ts +22 -2
  356. package/dist/scanners/schema-utils.d.ts.map +1 -1
  357. package/dist/scanners/schema-utils.js +14 -2
  358. package/dist/scanners/schema-utils.js.map +1 -1
  359. package/dist/scanners/types.d.ts +3 -0
  360. package/dist/scanners/types.d.ts.map +1 -1
  361. package/dist/scanners/types.js.map +1 -1
  362. package/dist/scripts/run-dsl-standalone-live.js +2 -2
  363. package/dist/scripts/run-dsl-standalone-live.js.map +1 -1
  364. package/dist/scripts/run-dsl-standalone-mock.js +2 -2
  365. package/dist/scripts/run-dsl-standalone-mock.js.map +1 -1
  366. package/dist/senpi/client.d.ts +123 -4
  367. package/dist/senpi/client.d.ts.map +1 -1
  368. package/dist/senpi/client.js +304 -15
  369. package/dist/senpi/client.js.map +1 -1
  370. package/dist/senpi/index.d.ts +1 -1
  371. package/dist/senpi/index.d.ts.map +1 -1
  372. package/dist/senpi/types.d.ts +70 -0
  373. package/dist/senpi/types.d.ts.map +1 -1
  374. package/dist/state/state-manager.d.ts +3 -0
  375. package/dist/state/state-manager.d.ts.map +1 -1
  376. package/dist/state/state-manager.js +9 -0
  377. package/dist/state/state-manager.js.map +1 -1
  378. package/dist/strategy/strategy-state.d.ts +4 -1
  379. package/dist/strategy/strategy-state.d.ts.map +1 -1
  380. package/dist/strategy/strategy-state.js +7 -2
  381. package/dist/strategy/strategy-state.js.map +1 -1
  382. package/dist/tracking/constants.d.ts +24 -0
  383. package/dist/tracking/constants.d.ts.map +1 -0
  384. package/dist/tracking/constants.js +50 -0
  385. package/dist/tracking/constants.js.map +1 -0
  386. package/dist/tracking/index.d.ts +13 -0
  387. package/dist/tracking/index.d.ts.map +1 -0
  388. package/dist/tracking/index.js +9 -0
  389. package/dist/tracking/index.js.map +1 -0
  390. package/dist/tracking/plugin-event-tracker.d.ts +13 -0
  391. package/dist/tracking/plugin-event-tracker.d.ts.map +1 -0
  392. package/dist/tracking/plugin-event-tracker.js +27 -0
  393. package/dist/tracking/plugin-event-tracker.js.map +1 -0
  394. package/dist/tracking/tracker.d.ts +30 -0
  395. package/dist/tracking/tracker.d.ts.map +1 -0
  396. package/dist/tracking/tracker.js +66 -0
  397. package/dist/tracking/tracker.js.map +1 -0
  398. package/dist/tracking/tracking-handler.d.ts +12 -0
  399. package/dist/tracking/tracking-handler.d.ts.map +1 -0
  400. package/dist/tracking/tracking-handler.js +148 -0
  401. package/dist/tracking/tracking-handler.js.map +1 -0
  402. package/dist/tracking/transport.d.ts +35 -0
  403. package/dist/tracking/transport.d.ts.map +1 -0
  404. package/dist/tracking/transport.js +133 -0
  405. package/dist/tracking/transport.js.map +1 -0
  406. package/dist/tracking/types.d.ts +21 -0
  407. package/dist/tracking/types.d.ts.map +1 -0
  408. package/dist/tracking/types.js +6 -0
  409. package/dist/tracking/types.js.map +1 -0
  410. package/dist/types/action.d.ts +13 -2
  411. package/dist/types/action.d.ts.map +1 -1
  412. package/dist/types/dsl/index.d.ts +72 -3
  413. package/dist/types/dsl/index.d.ts.map +1 -1
  414. package/dist/types/strategy.d.ts +11 -3
  415. package/dist/types/strategy.d.ts.map +1 -1
  416. package/dist/utils/logger.d.ts +6 -1
  417. package/dist/utils/logger.d.ts.map +1 -1
  418. package/dist/utils/logger.js +35 -2
  419. package/dist/utils/logger.js.map +1 -1
  420. package/dist/utils/resolve-order-type.d.ts +5 -0
  421. package/dist/utils/resolve-order-type.d.ts.map +1 -0
  422. package/dist/utils/resolve-order-type.js +29 -0
  423. package/dist/utils/resolve-order-type.js.map +1 -0
  424. package/examples/strategies/dsl-showcase.yaml +7 -2
  425. package/examples/strategies/dsl.yaml +5 -1
  426. package/examples/strategies/fox-minimal-loosened.yaml +18 -3
  427. package/examples/strategies/fox-minimal.yaml +25 -3
  428. package/examples/strategies/minimal.yaml +4 -2
  429. package/examples/strategies/momentum/how-it-works.md +48 -0
  430. package/examples/strategies/momentum/momentum-guarded.yaml +161 -0
  431. package/examples/strategies/risk-showcase.yaml +93 -0
  432. package/examples/strategies/viper.yaml +11 -3
  433. package/examples/strategies/wolf.yaml +11 -3
  434. package/examples/yamls/sample-with-dsl-and-emerging-movers.yaml +12 -4
  435. package/openclaw.plugin.json +35 -1
  436. package/package.json +12 -7
package/dist/index.js CHANGED
@@ -3,7 +3,27 @@
3
3
  * actions, scanners, dsl, risk, health.
4
4
  * Default export: OpenClaw plugin entry (register(api)).
5
5
  * Named export run(): programmatic/standalone entry.
6
+ *
7
+ * Why this file is monolithic (vs. a thin wrapper that imports ./plugin.js):
8
+ * openclaw 2026.2.22's plugin loader follows relative imports from the
9
+ * entry through a CJS-fallback path that rejects `import.meta` syntax.
10
+ * The wrapper-style entry introduced in d919805 broke loadability for
11
+ * that reason. Keeping every export in a single file (this one) avoids
12
+ * the loader's relative-import path entirely.
6
13
  */
14
+ // dd-trace init MUST be the first executable statement in this file so it
15
+ // patches Node core modules (http, fs, etc.) before any traceable resource is
16
+ // constructed by the imports below. Gated on DD_TRACE_ENABLED=true so unit
17
+ // tests and standalone CLI invocations do not pay the init cost.
18
+ // `createRequire` is used because `dd-trace` is a CJS module and our
19
+ // tsconfig uses Node16 modules — a top-level `import "dd-trace"` would
20
+ // be hoisted above this gate by the bundler/loader.
21
+ import { createRequire } from "node:module";
22
+ const __require = createRequire(import.meta.url);
23
+ if (process.env.DD_TRACE_ENABLED === "true") {
24
+ __require("dd-trace").init();
25
+ }
26
+ import { readFileSync } from "node:fs";
7
27
  import { join } from "node:path";
8
28
  import { SenpiClient } from "./senpi/client.js";
9
29
  import { buildRuntimeStateDir, archiveStateDir } from "./runtime/state-layout.js";
@@ -20,7 +40,14 @@ import { initDsl } from "./dsl/index.js";
20
40
  import { initHealth } from "./health/index.js";
21
41
  import { initRisk } from "./risk/index.js";
22
42
  import { VERSION } from "./version.js";
23
- import { setErrorNotifier, } from "./utils/logger.js";
43
+ import { BUS_EVENT_MAP } from "./tracking/constants.js";
44
+ import { createPluginEventTracker } from "./tracking/plugin-event-tracker.js";
45
+ import { getLogLevel, getLogLevelSource, parseLogLevel, setErrorNotifier, setLogLevel, } from "./utils/logger.js";
46
+ import { ExternalScannerIngestError, } from "./scanners/external-scanner-receiver.js";
47
+ import { createLogger } from "./utils/logger.js";
48
+ import { loadApiConfig } from "./runtime-api/config.js";
49
+ import { startApi } from "./runtime-api/lifecycle.js";
50
+ import { ingestSignalsHandler } from "./runtime-api/handlers/ingest-signals.js";
24
51
  /** Initialize all core features (DSL, risk, health) on the given event bus. */
25
52
  export function initCore(bus) {
26
53
  initDsl(bus);
@@ -134,6 +161,29 @@ function fireAndForgetErrorNotification(notifications, message) {
134
161
  // Intentionally swallow; error notifications must never fail call sites.
135
162
  }
136
163
  }
164
+ /**
165
+ * Read the plugin version from the sibling `openclaw.plugin.json` manifest.
166
+ * Performed once at module load — the manifest is shipped alongside the
167
+ * compiled `dist/index.js` so the relative URL resolves at runtime.
168
+ *
169
+ * Falls back to the imported `VERSION` constant (compiled into the bundle)
170
+ * if the manifest cannot be read; both should always agree.
171
+ */
172
+ function readPluginManifestVersion() {
173
+ try {
174
+ const manifestUrl = new URL("../openclaw.plugin.json", import.meta.url);
175
+ const raw = readFileSync(manifestUrl, "utf-8");
176
+ const parsed = JSON.parse(raw);
177
+ if (typeof parsed.version === "string" && parsed.version.length > 0) {
178
+ return parsed.version;
179
+ }
180
+ }
181
+ catch {
182
+ // Fall through to VERSION fallback.
183
+ }
184
+ return VERSION;
185
+ }
186
+ const PLUGIN_MANIFEST_VERSION = readPluginManifestVersion();
137
187
  /**
138
188
  * OpenClaw plugin entry.
139
189
  * Boots from internal registry (installed_runtimes.json) in stateDir; does not read runtime list from config.
@@ -163,6 +213,23 @@ const senpiRuntimePlugin = {
163
213
  pluginLogger.warn("[senpi-runtime] No plugin config found — skipping registration");
164
214
  return;
165
215
  }
216
+ if (typeof config.logLevel === "string" && config.logLevel.length > 0) {
217
+ const parsed = parseLogLevel(config.logLevel);
218
+ if (parsed !== null) {
219
+ setLogLevel(parsed, "config");
220
+ }
221
+ else {
222
+ pluginLogger.warn(`[senpi-runtime] Ignoring invalid plugin config logLevel="${config.logLevel}" (expected debug|info|warn|error); keeping ${getLogLevel()}.`);
223
+ }
224
+ }
225
+ const startupLogLevel = getLogLevel();
226
+ const startupLogLevelSource = getLogLevelSource();
227
+ const logLevelSourceLabel = startupLogLevelSource === "config"
228
+ ? "plugin config logLevel"
229
+ : startupLogLevelSource === "env"
230
+ ? "env SENPI_LOG_LEVEL"
231
+ : "default";
232
+ pluginLogger.info(`[senpi-runtime] log level: ${startupLogLevel} (source: ${logLevelSourceLabel}). Set plugin config "logLevel" or env SENPI_LOG_LEVEL to debug|info|warn|error to override.`);
166
233
  const senpiCliStore = readSenpiCliStore();
167
234
  const baseStateDir = resolveSenpiBaseStateDir({
168
235
  store: senpiCliStore,
@@ -178,7 +245,13 @@ const senpiRuntimePlugin = {
178
245
  pluginLogger.error("[senpi-runtime] mcpTransport or apiKey is required (provide via gateway, api, or config)");
179
246
  return;
180
247
  }
248
+ const pluginEventTracker = createPluginEventTracker(apiKey ?? process.env.SENPI_API_KEY);
181
249
  const runtimeHandles = new Map();
250
+ let apiHandle;
251
+ // Dedicated logger for the runtime-api subtree — required because the
252
+ // PluginLogger surface (info/warn/error) lacks `debug`, while the
253
+ // Logger contract used by `runtime-api/` includes it.
254
+ const apiLogger = createLogger("[senpi-core][api]");
182
255
  const lifecycleChatId = resolveTelegramChatIdFromStore(senpiCliStore);
183
256
  const lifecycleNotifications = lifecycleChatId
184
257
  ? createNotificationService({
@@ -271,6 +344,48 @@ const senpiRuntimePlugin = {
271
344
  throw err;
272
345
  }
273
346
  pluginLogger.info(`[senpi-runtime] Started ${started.length} runtime${started.length === 1 ? "" : "s"}`);
347
+ // ── HTTP API ──────────────────────────────────────────────────────
348
+ // Bind the HTTP server AFTER runtimes are hydrated so `/health` and
349
+ // `/signals` see the live `runtimeHandles` map.
350
+ //
351
+ // If the API fails to bind (e.g. EADDRINUSE) we treat the lifecycle as
352
+ // a single transactional unit: stop the auto-update coordinator first
353
+ // (otherwise it could schedule a tick mid-rollback), then stop every
354
+ // runtime handle that was already hydrated, then re-throw. The goal
355
+ // is "either everything is up or nothing is" — so openclaw never sees
356
+ // a half-started state where some runtimes are alive but the API
357
+ // they expect to be reachable on isn't.
358
+ //
359
+ // SENPI_RUNTIME_API_DISABLED=true skips API startup. Used by unit
360
+ // tests that exercise `plugin.register()` in parallel workers without
361
+ // contending for the same TCP port.
362
+ if (process.env.SENPI_RUNTIME_API_DISABLED !== "true") {
363
+ try {
364
+ const apiConfig = loadApiConfig(api.pluginConfig);
365
+ apiHandle = await startApi({
366
+ runtimeHandles,
367
+ apiConfig,
368
+ logger: apiLogger,
369
+ version: PLUGIN_MANIFEST_VERSION,
370
+ });
371
+ apiHandle.ready();
372
+ }
373
+ catch (err) {
374
+ pluginLogger.error("[senpi-runtime] HTTP API failed to start; rolling back lifecycle", { err });
375
+ // Mirror the lifecycle-stop teardown order: stop the coordinator
376
+ // first so it cannot schedule a tick or call stopRuntimesForUpdate
377
+ // mid-rollback, then stop every runtime handle that was hydrated
378
+ // above.
379
+ await autoUpdateCoordinator.stop().catch(() => { });
380
+ for (let i = started.length - 1; i >= 0; i--) {
381
+ const h = runtimeHandles.get(started[i]);
382
+ if (h)
383
+ await h.stop().catch(() => { });
384
+ runtimeHandles.delete(started[i]);
385
+ }
386
+ throw err;
387
+ }
388
+ }
274
389
  if (lifecycleNotifications) {
275
390
  const n = started.length;
276
391
  lifecycleNotifications
@@ -285,8 +400,16 @@ const senpiRuntimePlugin = {
285
400
  if (lifecycleNotifications) {
286
401
  lifecycleNotifications.notify("Senpi shutting down.").catch(() => { });
287
402
  }
288
- // Stop the coordinator first so it cannot schedule a new tick or call
289
- // stopRuntimesForUpdate() while we are tearing down the handles below.
403
+ // Drain the HTTP server FIRST so in-flight POST /signals requests
404
+ // finish before the underlying runtime they target is torn down.
405
+ // `apiHandle.close()` never throws.
406
+ if (apiHandle) {
407
+ await apiHandle.close();
408
+ apiHandle = undefined;
409
+ }
410
+ // Stop the coordinator next so it cannot schedule a new tick or call
411
+ // stopRuntimesForUpdate() (auto-restart path after an update) while
412
+ // we are tearing down the handles below.
290
413
  await autoUpdateCoordinator.stop();
291
414
  const ids = Array.from(runtimeHandles.keys());
292
415
  for (let i = ids.length - 1; i >= 0; i--) {
@@ -296,6 +419,13 @@ const senpiRuntimePlugin = {
296
419
  runtimeHandles.delete(ids[i]);
297
420
  }
298
421
  pluginLogger.info("[senpi-runtime] All runtimes stopped");
422
+ // Flush plugin-scoped telemetry (lifecycle.runtime.created/deleted); otherwise
423
+ // BatchingTransport may still hold buffered events until the interval fires.
424
+ await pluginEventTracker.shutdown().catch((err) => {
425
+ pluginLogger.warn("[senpi-runtime] plugin telemetry shutdown failed", {
426
+ err: err instanceof Error ? err.message : String(err),
427
+ });
428
+ });
299
429
  },
300
430
  });
301
431
  pluginLogger.info("[senpi-runtime] calling api.registerCli(..., { commands: ['senpi'] })");
@@ -442,6 +572,21 @@ const senpiRuntimePlugin = {
442
572
  }
443
573
  registry.runtimes.push(entry);
444
574
  await writeRegistry(baseStateDir, registry);
575
+ const createdMapping = BUS_EVENT_MAP["tracking.runtime_created"];
576
+ pluginEventTracker.capture({
577
+ eventType: createdMapping.eventType,
578
+ category: createdMapping.category,
579
+ address: wallet,
580
+ data: {
581
+ id: resolvedId,
582
+ name: runtimeName,
583
+ wallet,
584
+ schemaVersion: parsedSchemaVersion,
585
+ source: hasPath ? "file" : "inline",
586
+ config: entry,
587
+ timestamp: new Date().toISOString(),
588
+ },
589
+ });
445
590
  try {
446
591
  const scannerProviders = await createScannerProvidersForRun({
447
592
  mcpTransport,
@@ -503,29 +648,146 @@ const senpiRuntimePlugin = {
503
648
  });
504
649
  return;
505
650
  }
651
+ const deletedEntry = registry.runtimes.find((e) => e.id === targetId);
506
652
  const handle = runtimeHandles.get(targetId);
653
+ if (!deletedEntry && !handle) {
654
+ respond(false, undefined, {
655
+ code: "NOT_FOUND",
656
+ message: `No runtime found with id "${targetId}".`,
657
+ });
658
+ return;
659
+ }
660
+ const targetWallet = deletedEntry?.wallet ??
661
+ handle?.wallet ??
662
+ (typeof targetAddress === "string" ? targetAddress : "");
663
+ let openPositionsAbandoned = 0;
664
+ let archivePath;
507
665
  if (handle) {
508
- await handle.teardownDslForRuntimeDeletion();
666
+ openPositionsAbandoned = await handle.teardownDslForRuntimeDeletion();
509
667
  await handle.stop();
510
668
  runtimeHandles.delete(targetId);
511
669
  }
512
670
  // Archive state directory before removing from registry
513
- const deletedEntry = registry.runtimes.find((e) => e.id === targetId);
514
671
  if (deletedEntry) {
515
672
  const runtimeStateDir = buildRuntimeStateDir(baseStateDir, targetId, deletedEntry.wallet ?? "");
516
673
  const archivesDir = join(baseStateDir, "archives");
517
674
  try {
518
- const archivePath = await archiveStateDir(runtimeStateDir, archivesDir, targetId, deletedEntry.wallet ?? "");
675
+ archivePath = await archiveStateDir(runtimeStateDir, archivesDir, targetId, deletedEntry.wallet ?? "");
519
676
  api.logger.info(`[senpi-runtime] Archived state to ${archivePath}`);
520
677
  }
521
678
  catch (err) {
522
679
  api.logger.warn("[senpi-runtime] Failed to archive state dir", { err });
523
680
  }
524
681
  }
525
- const next = registry.runtimes.filter((e) => e.id !== targetId);
526
- await writeRegistry(baseStateDir, { ...registry, runtimes: next });
682
+ const deletedMapping = BUS_EVENT_MAP["tracking.runtime_deleted"];
683
+ pluginEventTracker.capture({
684
+ eventType: deletedMapping.eventType,
685
+ category: deletedMapping.category,
686
+ address: targetWallet,
687
+ data: {
688
+ id: targetId,
689
+ wallet: targetWallet,
690
+ schemaVersion: deletedEntry?.schemaVersion,
691
+ reason: "user_initiated",
692
+ openPositionsAbandoned,
693
+ ...(typeof archivePath === "string" ? { archivedAt: archivePath } : {}),
694
+ timestamp: new Date().toISOString(),
695
+ },
696
+ });
697
+ if (deletedEntry) {
698
+ const next = registry.runtimes.filter((e) => e.id !== targetId);
699
+ await writeRegistry(baseStateDir, { ...registry, runtimes: next });
700
+ }
527
701
  respond(true, { id: targetId });
528
702
  });
703
+ /**
704
+ * Gateway shim for `senpi.ingestExternalScannerData`.
705
+ *
706
+ * Thin wrapper over the shared {@link ingestSignalsHandler} that backs
707
+ * `POST /signals`. Both transports go through the same in-process logic;
708
+ * this shim only translates between the legacy gateway envelope and the
709
+ * shared handler's per-item discriminant.
710
+ *
711
+ * Response shape is preserved for backward compatibility with existing
712
+ * producers — slated for removal in Task 5 once the migration counter
713
+ * decays to zero (see `runtime-phase-2-api-plan.md` Section 8).
714
+ */
715
+ api.registerGatewayMethod("senpi.ingestExternalScannerData", async (ctx) => {
716
+ const respond = ctx.respond;
717
+ // TODO(s11): wire actual telemetry counter for
718
+ // runtime.deprecated_gateway_ingest_call (event name, properties:
719
+ // { address, scanner }). Reuse the existing tracking transport once
720
+ // it is plumbed through the plugin lifecycle in S11.
721
+ try {
722
+ const { address, request } = parseGatewayExternalScannerIngestParams(ctx.params);
723
+ pluginLogger.info("[senpi-runtime] senpi.ingestExternalScannerData", {
724
+ address,
725
+ scanner: request.scanner,
726
+ });
727
+ const item = {
728
+ address,
729
+ scanner: request.scanner,
730
+ ...(request.asset !== undefined && { asset: request.asset }),
731
+ ...(request.direction !== undefined && { direction: request.direction }),
732
+ ...(request.score !== undefined && { score: request.score }),
733
+ ...(request.signal_type !== undefined && { signal_type: request.signal_type }),
734
+ ...(request.data !== undefined && { data: request.data }),
735
+ ...(request.signals !== undefined && { signals: request.signals }),
736
+ };
737
+ const result = await ingestSignalsHandler(item, {
738
+ runtimeHandles,
739
+ logger: apiLogger,
740
+ transport: "gateway",
741
+ });
742
+ if (result.success) {
743
+ respond(true, {
744
+ accepted: true,
745
+ address: result.address,
746
+ scanner: result.scanner,
747
+ timestamp: result.timestamp,
748
+ signalCount: result.signalCount,
749
+ contextUpdated: result.contextUpdated,
750
+ });
751
+ return;
752
+ }
753
+ // Preserve the legacy "Failed to ingest external scanner data: ..."
754
+ // prefix on UNAVAILABLE so existing callers see the same error text
755
+ // they see today. INVALID_REQUEST and NOT_FOUND messages are already
756
+ // descriptive on their own and pass through unchanged.
757
+ if (result.code === "UNAVAILABLE") {
758
+ respond(false, undefined, {
759
+ code: "UNAVAILABLE",
760
+ message: `Failed to ingest external scanner data: ${result.message}`,
761
+ });
762
+ return;
763
+ }
764
+ respond(false, undefined, {
765
+ code: result.code,
766
+ message: result.message,
767
+ });
768
+ }
769
+ catch (error) {
770
+ // `parseGatewayExternalScannerIngestParams` throws synchronously for
771
+ // malformed routing fields. The shared handler never throws — any
772
+ // other error here is unexpected.
773
+ if (error instanceof ExternalScannerIngestError) {
774
+ respond(false, undefined, {
775
+ code: error.code,
776
+ message: error.message,
777
+ });
778
+ return;
779
+ }
780
+ pluginLogger.warn("[senpi-runtime] ingestExternalScannerData error", {
781
+ address: typeof ctx.params?.address === "string" ? ctx.params.address : undefined,
782
+ scanner: typeof ctx.params?.scanner === "string" ? ctx.params.scanner : undefined,
783
+ err: error,
784
+ });
785
+ respond(false, undefined, {
786
+ code: "UNAVAILABLE",
787
+ message: `Failed to ingest external scanner data: ${formatGatewayError(error)}`,
788
+ });
789
+ }
790
+ });
529
791
  api.registerGatewayMethod("senpi.listDslPositions", async (ctx) => {
530
792
  const respond = ctx.respond;
531
793
  const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
@@ -674,6 +936,156 @@ const senpiRuntimePlugin = {
674
936
  const states = await collectRuntimeSystemStates(runtimeHandles, api.logger, baseStateDir);
675
937
  respond(true, { states, updater });
676
938
  });
939
+ /**
940
+ * Action layer — read-only inspection.
941
+ *
942
+ * Three sibling methods (`senpi.listActions`, `senpi.getActionState`,
943
+ * `senpi.getActionHistory`) back the `openclaw senpi action …`
944
+ * subcommand family. They are intentionally read-only: they never
945
+ * mutate persisted state, never trigger an action, and never call the
946
+ * decision engine. All three resolve their `address` argument from
947
+ * caller params first, then fall back to the runtime handle's own
948
+ * `wallet`, so the CLI can omit `-a` for single-strategy runtimes.
949
+ *
950
+ * History note: these three methods were unregistered from
951
+ * `2026-04-16` (`15a51d7` "merge conflict resolution") through this
952
+ * fix — the CLI shipped wired against gateway methods that no longer
953
+ * existed, so the four `action` subcommands all returned
954
+ * `unknown method: senpi.getActionHistory`. Restoring them keeps the
955
+ * persisted action-store machinery (`src/actions/store/`) usable
956
+ * from the operator-facing CLI again.
957
+ */
958
+ api.registerGatewayMethod("senpi.listActions", async (ctx) => {
959
+ const respond = ctx.respond;
960
+ const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
961
+ const address = typeof ctx.params?.address === "string" ? ctx.params.address : undefined;
962
+ const actionName = typeof ctx.params?.actionName === "string" ? ctx.params.actionName : undefined;
963
+ const filter = {};
964
+ if (address) {
965
+ filter.address = address;
966
+ }
967
+ if (actionName) {
968
+ filter.actionName = actionName;
969
+ }
970
+ const hasFilter = Object.keys(filter).length > 0;
971
+ const merged = [];
972
+ for (const [id, handle] of runtimeHandles) {
973
+ if (runtimeId && id !== runtimeId) {
974
+ continue;
975
+ }
976
+ try {
977
+ const items = await handle.listActionLatestStates(hasFilter ? filter : undefined);
978
+ for (const a of items) {
979
+ merged.push({ ...a, runtimeId: id });
980
+ }
981
+ }
982
+ catch (err) {
983
+ api.logger.warn("[senpi-runtime] listActions error", { runtimeId: id, err });
984
+ }
985
+ }
986
+ respond(true, { actions: merged });
987
+ });
988
+ api.registerGatewayMethod("senpi.getActionState", async (ctx) => {
989
+ const respond = ctx.respond;
990
+ const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
991
+ const actionName = typeof ctx.params?.actionName === "string" ? ctx.params.actionName : undefined;
992
+ if (!runtimeId || !actionName) {
993
+ respond(false, undefined, {
994
+ code: "INVALID_REQUEST",
995
+ message: "runtimeId and actionName are required",
996
+ });
997
+ return;
998
+ }
999
+ const handle = getRuntimeHandleOrRespond(runtimeHandles, runtimeId, respond);
1000
+ if (!handle) {
1001
+ return;
1002
+ }
1003
+ const resolvedAddress = typeof ctx.params?.address === "string" && ctx.params.address.length > 0
1004
+ ? ctx.params.address
1005
+ : handle.wallet;
1006
+ if (!resolvedAddress) {
1007
+ respond(false, undefined, {
1008
+ code: "INVALID_REQUEST",
1009
+ message: "address is required when the runtime wallet is unknown",
1010
+ });
1011
+ return;
1012
+ }
1013
+ try {
1014
+ const latest = await handle.getActionLatestState(resolvedAddress, actionName);
1015
+ respond(true, { latest });
1016
+ }
1017
+ catch (err) {
1018
+ api.logger.warn("[senpi-runtime] getActionState error", { runtimeId, err });
1019
+ respond(false, undefined, {
1020
+ code: "INTERNAL_ERROR",
1021
+ message: `Failed to read action state: ${formatGatewayError(err)}`,
1022
+ });
1023
+ }
1024
+ });
1025
+ api.registerGatewayMethod("senpi.getActionHistory", async (ctx) => {
1026
+ const respond = ctx.respond;
1027
+ const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
1028
+ const actionName = typeof ctx.params?.actionName === "string" ? ctx.params.actionName : undefined;
1029
+ if (!runtimeId) {
1030
+ respond(false, undefined, {
1031
+ code: "INVALID_REQUEST",
1032
+ message: "runtimeId is required",
1033
+ });
1034
+ return;
1035
+ }
1036
+ const handle = getRuntimeHandleOrRespond(runtimeHandles, runtimeId, respond);
1037
+ if (!handle) {
1038
+ api.logger.warn("[senpi-runtime] getActionHistory: no running runtime for the requested id", { runtimeId });
1039
+ return;
1040
+ }
1041
+ const resolvedAddress = typeof ctx.params?.address === "string" && ctx.params.address.length > 0
1042
+ ? ctx.params.address
1043
+ : handle.wallet;
1044
+ if (!resolvedAddress) {
1045
+ respond(false, undefined, {
1046
+ code: "INVALID_REQUEST",
1047
+ message: "address is required when the runtime wallet is unknown",
1048
+ });
1049
+ return;
1050
+ }
1051
+ const limit = typeof ctx.params?.limit === "number" && ctx.params.limit > 0
1052
+ ? ctx.params.limit
1053
+ : 50;
1054
+ // Pass through every value the underlying store and the CLI guide
1055
+ // already advertise (`ActionHistoryOutcomeFilter` =
1056
+ // "all" | "with_decision" | "executed"). "all" is the default
1057
+ // behaviour, so we collapse it to `undefined` and otherwise keep
1058
+ // "with_decision" / "executed" intact instead of silently dropping
1059
+ // them on the floor.
1060
+ const rawFilter = ctx.params?.outcomeFilter;
1061
+ const outcomeFilter = rawFilter === "with_decision" || rawFilter === "executed" ? rawFilter : undefined;
1062
+ try {
1063
+ if (actionName) {
1064
+ const history = await handle.getActionExecutionHistory(resolvedAddress, actionName, { limit, outcomeFilter });
1065
+ respond(true, { history });
1066
+ return;
1067
+ }
1068
+ // No actionName: merge histories across every action under this
1069
+ // wallet, then re-sort + cap to `limit`. The per-action fetch is
1070
+ // padded to `max(limit, 100)` so a small caller-supplied `limit`
1071
+ // doesn't truncate the merge before ordering globally.
1072
+ const latest = await handle.listActionLatestStates({ address: resolvedAddress });
1073
+ const records = [];
1074
+ for (const L of latest) {
1075
+ const part = await handle.getActionExecutionHistory(resolvedAddress, L.actionName, { limit: Math.max(limit, 100), outcomeFilter });
1076
+ records.push(...part);
1077
+ }
1078
+ records.sort((a, b) => b.startedAt - a.startedAt);
1079
+ respond(true, { history: records.slice(0, limit) });
1080
+ }
1081
+ catch (err) {
1082
+ api.logger.warn("[senpi-runtime] getActionHistory error", { runtimeId, err });
1083
+ respond(false, undefined, {
1084
+ code: "INTERNAL_ERROR",
1085
+ message: `Failed to read action history: ${formatGatewayError(err)}`,
1086
+ });
1087
+ }
1088
+ });
677
1089
  api.logger.info(`[senpi-runtime] v${VERSION} plugin registered — stateDir: ${baseStateDir}`);
678
1090
  },
679
1091
  };
@@ -688,6 +1100,43 @@ function getRuntimeHandleOrRespond(runtimeHandles, runtimeId, respond) {
688
1100
  });
689
1101
  return null;
690
1102
  }
1103
+ /**
1104
+ * Parse the gateway request shape for `senpi.ingestExternalScannerData`.
1105
+ *
1106
+ * The plugin contract keeps `address` at the gateway layer because the plugin
1107
+ * owns the map of running runtimes keyed by runtime id, while the runtime's
1108
+ * programmatic ingest API is already scoped to one strategy wallet. This
1109
+ * helper validates only the routing-critical fields (`address`, `scanner`) and
1110
+ * forwards the remaining payload as-is so the runtime keeps ownership of the
1111
+ * external-scanner data contract.
1112
+ *
1113
+ * @deprecated Used only by the `senpi.ingestExternalScannerData` gateway shim,
1114
+ * which itself is slated for removal in Task 5 of the runtime-phase-2-api plan
1115
+ * once external producers migrate to `POST /signals`. Delete alongside the
1116
+ * gateway-method registration in that task.
1117
+ */
1118
+ function parseGatewayExternalScannerIngestParams(params) {
1119
+ const address = typeof params?.address === "string" ? params.address.trim() : "";
1120
+ if (!address) {
1121
+ throw new ExternalScannerIngestError("INVALID_REQUEST", "External scanner ingest requires address as a non-empty string.");
1122
+ }
1123
+ const scanner = typeof params?.scanner === "string" ? params.scanner.trim() : "";
1124
+ if (!scanner) {
1125
+ throw new ExternalScannerIngestError("INVALID_REQUEST", "External scanner ingest requires scanner as a non-empty string.");
1126
+ }
1127
+ return {
1128
+ address,
1129
+ request: {
1130
+ scanner,
1131
+ asset: params?.asset,
1132
+ direction: params?.direction,
1133
+ score: params?.score,
1134
+ signal_type: params?.signal_type,
1135
+ data: params?.data,
1136
+ signals: params?.signals,
1137
+ },
1138
+ };
1139
+ }
691
1140
  async function collectRuntimeHealthStatuses(runtimeHandles, logger) {
692
1141
  return (await Promise.all(Array.from(runtimeHandles, async ([runtimeId, handle]) => {
693
1142
  try {
@@ -721,6 +1170,7 @@ function createGatewayHealthErrorStatus(runtimeId, error) {
721
1170
  startedAt: now,
722
1171
  generatedAt: now,
723
1172
  health: "unhealthy",
1173
+ logLevel: getLogLevel(),
724
1174
  components: {
725
1175
  scanners: {
726
1176
  component: "scanners",
@@ -750,6 +1200,7 @@ function createGatewaySystemStateError(runtimeId, stateDir, error) {
750
1200
  startedAt: now,
751
1201
  generatedAt: now,
752
1202
  health: "unhealthy",
1203
+ logLevel: getLogLevel(),
753
1204
  components: {
754
1205
  scanners: {
755
1206
  component: "scanners",