@reefclaw/connect 0.1.11 → 0.1.12

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 (397) hide show
  1. package/assets/bridge/gateway/heartbeat-cron.d.ts +27 -0
  2. package/assets/bridge/gateway/heartbeat-cron.js +85 -0
  3. package/assets/bridge/providers/gateway.d.ts +2 -0
  4. package/assets/bridge/providers/gateway.js +57 -16
  5. package/assets/bridge/setup.js +6 -51
  6. package/dist/deps.js +2 -2
  7. package/dist/plugin.js +35 -7
  8. package/package.json +1 -1
  9. package/assets/plugin/audit/mode-transition-audit.d.ts +0 -11
  10. package/assets/plugin/audit/mode-transition-audit.js +0 -29
  11. package/assets/plugin/balance-utils.d.ts +0 -36
  12. package/assets/plugin/balance-utils.js +0 -98
  13. package/assets/plugin/ccxt/binance-ban-gate.d.ts +0 -47
  14. package/assets/plugin/ccxt/binance-ban-gate.js +0 -420
  15. package/assets/plugin/ccxt/binance-private.d.ts +0 -346
  16. package/assets/plugin/ccxt/binance-private.js +0 -1525
  17. package/assets/plugin/ccxt/binance-public.d.ts +0 -34
  18. package/assets/plugin/ccxt/binance-public.js +0 -180
  19. package/assets/plugin/ccxt/intel-public.d.ts +0 -25
  20. package/assets/plugin/ccxt/intel-public.js +0 -80
  21. package/assets/plugin/ccxt/public-market-data-api.d.ts +0 -26
  22. package/assets/plugin/ccxt/public-market-data-api.js +0 -23
  23. package/assets/plugin/config/agent-config-client.d.ts +0 -77
  24. package/assets/plugin/config/agent-config-client.js +0 -188
  25. package/assets/plugin/config/agent-config-poller.d.ts +0 -32
  26. package/assets/plugin/config/agent-config-poller.js +0 -101
  27. package/assets/plugin/config/brackets-config.d.ts +0 -22
  28. package/assets/plugin/config/brackets-config.js +0 -58
  29. package/assets/plugin/config/entitlement-gate.d.ts +0 -51
  30. package/assets/plugin/config/entitlement-gate.js +0 -137
  31. package/assets/plugin/config/gate-store.d.ts +0 -18
  32. package/assets/plugin/config/gate-store.js +0 -61
  33. package/assets/plugin/config/plugin-config-io.d.ts +0 -222
  34. package/assets/plugin/config/plugin-config-io.js +0 -126
  35. package/assets/plugin/config/position-review-config.d.ts +0 -35
  36. package/assets/plugin/config/position-review-config.js +0 -105
  37. package/assets/plugin/config/tool-gate.d.ts +0 -53
  38. package/assets/plugin/config/tool-gate.js +0 -128
  39. package/assets/plugin/config/user-data-stream-config.d.ts +0 -89
  40. package/assets/plugin/config/user-data-stream-config.js +0 -239
  41. package/assets/plugin/connector-supervisor.d.ts +0 -36
  42. package/assets/plugin/connector-supervisor.js +0 -149
  43. package/assets/plugin/exchange-adapter.d.ts +0 -65
  44. package/assets/plugin/exchange-adapter.js +0 -4
  45. package/assets/plugin/index.d.ts +0 -30
  46. package/assets/plugin/index.js +0 -2756
  47. package/assets/plugin/ingest/pending-entry-metadata.d.ts +0 -74
  48. package/assets/plugin/ingest/pending-entry-metadata.js +0 -236
  49. package/assets/plugin/ingest/position-auto-capture.d.ts +0 -171
  50. package/assets/plugin/ingest/position-auto-capture.js +0 -709
  51. package/assets/plugin/ingest/position-decisions-client.d.ts +0 -327
  52. package/assets/plugin/ingest/position-decisions-client.js +0 -306
  53. package/assets/plugin/ingest/readiness-reporter.d.ts +0 -42
  54. package/assets/plugin/ingest/readiness-reporter.js +0 -163
  55. package/assets/plugin/ingest/reconcile-db-vs-exchange.d.ts +0 -51
  56. package/assets/plugin/ingest/reconcile-db-vs-exchange.js +0 -170
  57. package/assets/plugin/ingest/reconciler-cleanup.d.ts +0 -37
  58. package/assets/plugin/ingest/reconciler-cleanup.js +0 -147
  59. package/assets/plugin/ingest/rest-gap-filler.d.ts +0 -191
  60. package/assets/plugin/ingest/rest-gap-filler.js +0 -565
  61. package/assets/plugin/ingest/touched-symbols-store.d.ts +0 -25
  62. package/assets/plugin/ingest/touched-symbols-store.js +0 -96
  63. package/assets/plugin/ingest/trade-store-client.d.ts +0 -40
  64. package/assets/plugin/ingest/trade-store-client.js +0 -125
  65. package/assets/plugin/ingest/ws-ingest.d.ts +0 -43
  66. package/assets/plugin/ingest/ws-ingest.js +0 -126
  67. package/assets/plugin/learning/setup-family.d.ts +0 -21
  68. package/assets/plugin/learning/setup-family.js +0 -103
  69. package/assets/plugin/lifecycle/install-signal-handlers.d.ts +0 -33
  70. package/assets/plugin/lifecycle/install-signal-handlers.js +0 -112
  71. package/assets/plugin/lifecycle/shutdown-coordinator.d.ts +0 -43
  72. package/assets/plugin/lifecycle/shutdown-coordinator.js +0 -131
  73. package/assets/plugin/lifecycle/trading-operation-lock.d.ts +0 -17
  74. package/assets/plugin/lifecycle/trading-operation-lock.js +0 -14
  75. package/assets/plugin/live/bracket-id.d.ts +0 -26
  76. package/assets/plugin/live/bracket-id.js +0 -112
  77. package/assets/plugin/live/bracket-ledger.d.ts +0 -54
  78. package/assets/plugin/live/bracket-ledger.js +0 -267
  79. package/assets/plugin/live/bracket-manager.d.ts +0 -82
  80. package/assets/plugin/live/bracket-manager.js +0 -478
  81. package/assets/plugin/live/bracket-params.d.ts +0 -22
  82. package/assets/plugin/live/bracket-params.js +0 -124
  83. package/assets/plugin/live/bracket-reconciler.d.ts +0 -95
  84. package/assets/plugin/live/bracket-reconciler.js +0 -573
  85. package/assets/plugin/live/bracket-types.d.ts +0 -102
  86. package/assets/plugin/live/bracket-types.js +0 -8
  87. package/assets/plugin/live/deposit-tracker.d.ts +0 -62
  88. package/assets/plugin/live/deposit-tracker.js +0 -97
  89. package/assets/plugin/live/emergency-controls.d.ts +0 -32
  90. package/assets/plugin/live/emergency-controls.js +0 -226
  91. package/assets/plugin/live/exchange-errors.d.ts +0 -12
  92. package/assets/plugin/live/exchange-errors.js +0 -130
  93. package/assets/plugin/live/exchange-info-cache.d.ts +0 -37
  94. package/assets/plugin/live/exchange-info-cache.js +0 -134
  95. package/assets/plugin/live/fact-subscriber.d.ts +0 -78
  96. package/assets/plugin/live/fact-subscriber.js +0 -182
  97. package/assets/plugin/live/fill-price.d.ts +0 -13
  98. package/assets/plugin/live/fill-price.js +0 -37
  99. package/assets/plugin/live/intent-journal.d.ts +0 -42
  100. package/assets/plugin/live/intent-journal.js +0 -122
  101. package/assets/plugin/live/listen-key-manager.d.ts +0 -70
  102. package/assets/plugin/live/listen-key-manager.js +0 -169
  103. package/assets/plugin/live/live-adapter.d.ts +0 -319
  104. package/assets/plugin/live/live-adapter.js +0 -1906
  105. package/assets/plugin/live/live-balance-enricher.d.ts +0 -32
  106. package/assets/plugin/live/live-balance-enricher.js +0 -104
  107. package/assets/plugin/live/live-bracket-api.d.ts +0 -13
  108. package/assets/plugin/live/live-bracket-api.js +0 -20
  109. package/assets/plugin/live/live-state-store.d.ts +0 -194
  110. package/assets/plugin/live/live-state-store.js +0 -450
  111. package/assets/plugin/live/local-signal-service.d.ts +0 -57
  112. package/assets/plugin/live/local-signal-service.js +0 -151
  113. package/assets/plugin/live/local-strategy-evaluator.d.ts +0 -62
  114. package/assets/plugin/live/local-strategy-evaluator.js +0 -131
  115. package/assets/plugin/live/microstructure-assembler.d.ts +0 -54
  116. package/assets/plugin/live/microstructure-assembler.js +0 -148
  117. package/assets/plugin/live/order-poller.d.ts +0 -29
  118. package/assets/plugin/live/order-poller.js +0 -125
  119. package/assets/plugin/live/position-state-store.d.ts +0 -87
  120. package/assets/plugin/live/position-state-store.js +0 -237
  121. package/assets/plugin/live/proposal-decision-listener.d.ts +0 -70
  122. package/assets/plugin/live/proposal-decision-listener.js +0 -292
  123. package/assets/plugin/live/proposal-manager.d.ts +0 -76
  124. package/assets/plugin/live/proposal-manager.js +0 -140
  125. package/assets/plugin/live/rate-limiter.d.ts +0 -47
  126. package/assets/plugin/live/rate-limiter.js +0 -159
  127. package/assets/plugin/live/reconciler.d.ts +0 -39
  128. package/assets/plugin/live/reconciler.js +0 -175
  129. package/assets/plugin/live/setup-buckets.d.ts +0 -7
  130. package/assets/plugin/live/setup-buckets.js +0 -33
  131. package/assets/plugin/live/slippage-tracker.d.ts +0 -45
  132. package/assets/plugin/live/slippage-tracker.js +0 -78
  133. package/assets/plugin/live/stop-watcher.d.ts +0 -67
  134. package/assets/plugin/live/stop-watcher.js +0 -218
  135. package/assets/plugin/live/user-data-active-probe.d.ts +0 -54
  136. package/assets/plugin/live/user-data-active-probe.js +0 -180
  137. package/assets/plugin/live/user-data-stream-controller.d.ts +0 -200
  138. package/assets/plugin/live/user-data-stream-controller.js +0 -579
  139. package/assets/plugin/live/user-data-stream-ws.d.ts +0 -22
  140. package/assets/plugin/live/user-data-stream-ws.js +0 -63
  141. package/assets/plugin/live/user-data-stream.d.ts +0 -243
  142. package/assets/plugin/live/user-data-stream.js +0 -704
  143. package/assets/plugin/logger.d.ts +0 -2
  144. package/assets/plugin/logger.js +0 -2
  145. package/assets/plugin/mfe.d.ts +0 -21
  146. package/assets/plugin/mfe.js +0 -68
  147. package/assets/plugin/onboarding/mode-ladder.d.ts +0 -1
  148. package/assets/plugin/onboarding/mode-ladder.js +0 -3
  149. package/assets/plugin/onboarding/runtime.d.ts +0 -90
  150. package/assets/plugin/onboarding/runtime.js +0 -184
  151. package/assets/plugin/openclaw.plugin.json +0 -92
  152. package/assets/plugin/paper-adapter.d.ts +0 -24
  153. package/assets/plugin/paper-adapter.js +0 -91
  154. package/assets/plugin/persistence/state-manager.d.ts +0 -66
  155. package/assets/plugin/persistence/state-manager.js +0 -222
  156. package/assets/plugin/pinned-plan.d.ts +0 -9
  157. package/assets/plugin/pinned-plan.js +0 -23
  158. package/assets/plugin/portfolio/reentry-tracker.d.ts +0 -36
  159. package/assets/plugin/portfolio/reentry-tracker.js +0 -127
  160. package/assets/plugin/portfolio/wave9-admission.d.ts +0 -67
  161. package/assets/plugin/portfolio/wave9-admission.js +0 -262
  162. package/assets/plugin/portfolio/wave9-policy.d.ts +0 -36
  163. package/assets/plugin/portfolio/wave9-policy.js +0 -183
  164. package/assets/plugin/risk/pre-trade-check.d.ts +0 -38
  165. package/assets/plugin/risk/pre-trade-check.js +0 -345
  166. package/assets/plugin/risk/pre-trade-types.d.ts +0 -60
  167. package/assets/plugin/risk/pre-trade-types.js +0 -3
  168. package/assets/plugin/shadow/shadow-tracker.d.ts +0 -36
  169. package/assets/plugin/shadow/shadow-tracker.js +0 -151
  170. package/assets/plugin/shadow/types.d.ts +0 -42
  171. package/assets/plugin/shadow/types.js +0 -20
  172. package/assets/plugin/shared/indicators-extended.d.ts +0 -52
  173. package/assets/plugin/shared/indicators-extended.js +0 -291
  174. package/assets/plugin/shared/indicators.d.ts +0 -15
  175. package/assets/plugin/shared/indicators.js +0 -114
  176. package/assets/plugin/signals/conditions/registry.d.ts +0 -16
  177. package/assets/plugin/signals/conditions/registry.js +0 -1333
  178. package/assets/plugin/signals/conditions/types.d.ts +0 -1
  179. package/assets/plugin/signals/conditions/types.js +0 -4
  180. package/assets/plugin/signals/direction-rules.d.ts +0 -3
  181. package/assets/plugin/signals/direction-rules.js +0 -24
  182. package/assets/plugin/signals/entry-rules.d.ts +0 -6
  183. package/assets/plugin/signals/entry-rules.js +0 -33
  184. package/assets/plugin/signals/serialize-context.d.ts +0 -4
  185. package/assets/plugin/signals/serialize-context.js +0 -39
  186. package/assets/plugin/signals/stop-rules.d.ts +0 -3
  187. package/assets/plugin/signals/stop-rules.js +0 -48
  188. package/assets/plugin/signals/strategy-adapter.d.ts +0 -47
  189. package/assets/plugin/signals/strategy-adapter.js +0 -209
  190. package/assets/plugin/signals/types.d.ts +0 -1
  191. package/assets/plugin/signals/types.js +0 -8
  192. package/assets/plugin/simulator/exchange-simulator.d.ts +0 -105
  193. package/assets/plugin/simulator/exchange-simulator.js +0 -759
  194. package/assets/plugin/simulator/fill-engine.d.ts +0 -53
  195. package/assets/plugin/simulator/fill-engine.js +0 -280
  196. package/assets/plugin/simulator/paper-market-feed.d.ts +0 -26
  197. package/assets/plugin/simulator/paper-market-feed.js +0 -104
  198. package/assets/plugin/simulator/realistic-fills.d.ts +0 -59
  199. package/assets/plugin/simulator/realistic-fills.js +0 -175
  200. package/assets/plugin/simulator/types.d.ts +0 -228
  201. package/assets/plugin/simulator/types.js +0 -43
  202. package/assets/plugin/strategy/builtin-strategies.d.ts +0 -2
  203. package/assets/plugin/strategy/builtin-strategies.js +0 -113
  204. package/assets/plugin/strategy/condition-registry.d.ts +0 -3
  205. package/assets/plugin/strategy/condition-registry.js +0 -153
  206. package/assets/plugin/strategy/evaluator.d.ts +0 -70
  207. package/assets/plugin/strategy/evaluator.js +0 -98
  208. package/assets/plugin/tools/assessment-validation.d.ts +0 -141
  209. package/assets/plugin/tools/assessment-validation.js +0 -473
  210. package/assets/plugin/tools/attach-brackets.d.ts +0 -39
  211. package/assets/plugin/tools/attach-brackets.js +0 -564
  212. package/assets/plugin/tools/audit-bracket-protection.d.ts +0 -49
  213. package/assets/plugin/tools/audit-bracket-protection.js +0 -683
  214. package/assets/plugin/tools/bracket-control.d.ts +0 -12
  215. package/assets/plugin/tools/bracket-control.js +0 -35
  216. package/assets/plugin/tools/cancel-all-orders.d.ts +0 -9
  217. package/assets/plugin/tools/cancel-all-orders.js +0 -8
  218. package/assets/plugin/tools/cancel-order.d.ts +0 -14
  219. package/assets/plugin/tools/cancel-order.js +0 -60
  220. package/assets/plugin/tools/check-position-health.d.ts +0 -46
  221. package/assets/plugin/tools/check-position-health.js +0 -194
  222. package/assets/plugin/tools/clear-exchange-credentials.d.ts +0 -24
  223. package/assets/plugin/tools/clear-exchange-credentials.js +0 -70
  224. package/assets/plugin/tools/close-position.d.ts +0 -45
  225. package/assets/plugin/tools/close-position.js +0 -722
  226. package/assets/plugin/tools/create-order.d.ts +0 -82
  227. package/assets/plugin/tools/create-order.js +0 -1544
  228. package/assets/plugin/tools/exit-gate.d.ts +0 -58
  229. package/assets/plugin/tools/exit-gate.js +0 -162
  230. package/assets/plugin/tools/fetch-balance.d.ts +0 -5
  231. package/assets/plugin/tools/fetch-balance.js +0 -4
  232. package/assets/plugin/tools/fetch-ohlcv.d.ts +0 -11
  233. package/assets/plugin/tools/fetch-ohlcv.js +0 -8
  234. package/assets/plugin/tools/fetch-open-orders.d.ts +0 -7
  235. package/assets/plugin/tools/fetch-open-orders.js +0 -4
  236. package/assets/plugin/tools/fetch-positions.d.ts +0 -7
  237. package/assets/plugin/tools/fetch-positions.js +0 -4
  238. package/assets/plugin/tools/fetch-ticker.d.ts +0 -11
  239. package/assets/plugin/tools/fetch-ticker.js +0 -5
  240. package/assets/plugin/tools/get-agent-profile.d.ts +0 -4
  241. package/assets/plugin/tools/get-agent-profile.js +0 -6
  242. package/assets/plugin/tools/get-analytics.d.ts +0 -6
  243. package/assets/plugin/tools/get-analytics.js +0 -7
  244. package/assets/plugin/tools/get-backtest.d.ts +0 -12
  245. package/assets/plugin/tools/get-backtest.js +0 -91
  246. package/assets/plugin/tools/get-basis.d.ts +0 -7
  247. package/assets/plugin/tools/get-basis.js +0 -7
  248. package/assets/plugin/tools/get-bracket-config.d.ts +0 -11
  249. package/assets/plugin/tools/get-bracket-config.js +0 -24
  250. package/assets/plugin/tools/get-cascade-risk.d.ts +0 -7
  251. package/assets/plugin/tools/get-cascade-risk.js +0 -8
  252. package/assets/plugin/tools/get-crypto-metrics.d.ts +0 -18
  253. package/assets/plugin/tools/get-crypto-metrics.js +0 -62
  254. package/assets/plugin/tools/get-cvd.d.ts +0 -6
  255. package/assets/plugin/tools/get-cvd.js +0 -6
  256. package/assets/plugin/tools/get-divergences.d.ts +0 -6
  257. package/assets/plugin/tools/get-divergences.js +0 -6
  258. package/assets/plugin/tools/get-funding-context.d.ts +0 -6
  259. package/assets/plugin/tools/get-funding-context.js +0 -16
  260. package/assets/plugin/tools/get-liquidation-levels.d.ts +0 -7
  261. package/assets/plugin/tools/get-liquidation-levels.js +0 -7
  262. package/assets/plugin/tools/get-liquidation-pulse.d.ts +0 -9
  263. package/assets/plugin/tools/get-liquidation-pulse.js +0 -22
  264. package/assets/plugin/tools/get-market-breadth.d.ts +0 -6
  265. package/assets/plugin/tools/get-market-breadth.js +0 -8
  266. package/assets/plugin/tools/get-market-intel.d.ts +0 -19
  267. package/assets/plugin/tools/get-market-intel.js +0 -116
  268. package/assets/plugin/tools/get-market-structure.d.ts +0 -47
  269. package/assets/plugin/tools/get-market-structure.js +0 -198
  270. package/assets/plugin/tools/get-my-mined-patterns.d.ts +0 -20
  271. package/assets/plugin/tools/get-my-mined-patterns.js +0 -61
  272. package/assets/plugin/tools/get-my-proposed-learnings.d.ts +0 -20
  273. package/assets/plugin/tools/get-my-proposed-learnings.js +0 -55
  274. package/assets/plugin/tools/get-my-recent-reviews.d.ts +0 -22
  275. package/assets/plugin/tools/get-my-recent-reviews.js +0 -66
  276. package/assets/plugin/tools/get-orderbook.d.ts +0 -21
  277. package/assets/plugin/tools/get-orderbook.js +0 -32
  278. package/assets/plugin/tools/get-pattern-scan.d.ts +0 -7
  279. package/assets/plugin/tools/get-pattern-scan.js +0 -8
  280. package/assets/plugin/tools/get-regime.d.ts +0 -6
  281. package/assets/plugin/tools/get-regime.js +0 -7
  282. package/assets/plugin/tools/get-relevant-learnings.d.ts +0 -21
  283. package/assets/plugin/tools/get-relevant-learnings.js +0 -65
  284. package/assets/plugin/tools/get-resting-liquidity.d.ts +0 -6
  285. package/assets/plugin/tools/get-resting-liquidity.js +0 -11
  286. package/assets/plugin/tools/get-risk-scenario.d.ts +0 -29
  287. package/assets/plugin/tools/get-risk-scenario.js +0 -47
  288. package/assets/plugin/tools/get-risk-summary.d.ts +0 -51
  289. package/assets/plugin/tools/get-risk-summary.js +0 -118
  290. package/assets/plugin/tools/get-sentiment.d.ts +0 -4
  291. package/assets/plugin/tools/get-sentiment.js +0 -6
  292. package/assets/plugin/tools/get-session-review.d.ts +0 -7
  293. package/assets/plugin/tools/get-session-review.js +0 -8
  294. package/assets/plugin/tools/get-setup-detail.d.ts +0 -7
  295. package/assets/plugin/tools/get-setup-detail.js +0 -322
  296. package/assets/plugin/tools/get-signals.d.ts +0 -15
  297. package/assets/plugin/tools/get-signals.js +0 -54
  298. package/assets/plugin/tools/get-sizing.d.ts +0 -6
  299. package/assets/plugin/tools/get-sizing.js +0 -6
  300. package/assets/plugin/tools/get-trade-feedback.d.ts +0 -7
  301. package/assets/plugin/tools/get-trade-feedback.js +0 -8
  302. package/assets/plugin/tools/get-trade-flow.d.ts +0 -7
  303. package/assets/plugin/tools/get-trade-flow.js +0 -7
  304. package/assets/plugin/tools/get-volume-analysis.d.ts +0 -21
  305. package/assets/plugin/tools/get-volume-analysis.js +0 -74
  306. package/assets/plugin/tools/get-volume-profile.d.ts +0 -7
  307. package/assets/plugin/tools/get-volume-profile.js +0 -7
  308. package/assets/plugin/tools/get-wave9-status.d.ts +0 -127
  309. package/assets/plugin/tools/get-wave9-status.js +0 -796
  310. package/assets/plugin/tools/helpers.d.ts +0 -26
  311. package/assets/plugin/tools/helpers.js +0 -39
  312. package/assets/plugin/tools/intel-api.d.ts +0 -34
  313. package/assets/plugin/tools/intel-api.js +0 -119
  314. package/assets/plugin/tools/intel-cache.d.ts +0 -25
  315. package/assets/plugin/tools/intel-cache.js +0 -148
  316. package/assets/plugin/tools/list-strategies.d.ts +0 -17
  317. package/assets/plugin/tools/list-strategies.js +0 -23
  318. package/assets/plugin/tools/modify-stop.d.ts +0 -21
  319. package/assets/plugin/tools/modify-stop.js +0 -120
  320. package/assets/plugin/tools/modify-target.d.ts +0 -21
  321. package/assets/plugin/tools/modify-target.js +0 -110
  322. package/assets/plugin/tools/propose-learning.d.ts +0 -22
  323. package/assets/plugin/tools/propose-learning.js +0 -65
  324. package/assets/plugin/tools/query-review-outcomes.d.ts +0 -30
  325. package/assets/plugin/tools/query-review-outcomes.js +0 -64
  326. package/assets/plugin/tools/query-trades.d.ts +0 -21
  327. package/assets/plugin/tools/query-trades.js +0 -37
  328. package/assets/plugin/tools/record-position-reviews.d.ts +0 -38
  329. package/assets/plugin/tools/record-position-reviews.js +0 -147
  330. package/assets/plugin/tools/save-strategy.d.ts +0 -16
  331. package/assets/plugin/tools/save-strategy.js +0 -46
  332. package/assets/plugin/tools/scan-pairs.d.ts +0 -22
  333. package/assets/plugin/tools/scan-pairs.js +0 -234
  334. package/assets/plugin/tools/score-setup.d.ts +0 -31
  335. package/assets/plugin/tools/score-setup.js +0 -268
  336. package/assets/plugin/tools/set-bracket-requirement.d.ts +0 -18
  337. package/assets/plugin/tools/set-bracket-requirement.js +0 -81
  338. package/assets/plugin/tools/set-exchange-credentials.d.ts +0 -25
  339. package/assets/plugin/tools/set-exchange-credentials.js +0 -80
  340. package/assets/plugin/tools/set-trading-mode.d.ts +0 -26
  341. package/assets/plugin/tools/set-trading-mode.js +0 -135
  342. package/assets/plugin/tools/test-exchange-credentials.d.ts +0 -16
  343. package/assets/plugin/tools/test-exchange-credentials.js +0 -100
  344. package/assets/plugin/tools/toggle-strategy.d.ts +0 -8
  345. package/assets/plugin/tools/toggle-strategy.js +0 -15
  346. package/assets/plugin/trading-params-cache.d.ts +0 -26
  347. package/assets/plugin/trading-params-cache.js +0 -52
  348. package/assets/plugin/types.d.ts +0 -134
  349. package/assets/plugin/types.js +0 -7
  350. package/assets/plugin/util/plugin-paths.d.ts +0 -3
  351. package/assets/plugin/util/plugin-paths.js +0 -15
  352. package/assets/plugin/venues/hyperliquid/hl-balance.d.ts +0 -116
  353. package/assets/plugin/venues/hyperliquid/hl-balance.js +0 -145
  354. package/assets/plugin/venues/hyperliquid/hl-bracket-coordinator.d.ts +0 -123
  355. package/assets/plugin/venues/hyperliquid/hl-bracket-coordinator.js +0 -533
  356. package/assets/plugin/venues/hyperliquid/hl-brackets.d.ts +0 -102
  357. package/assets/plugin/venues/hyperliquid/hl-brackets.js +0 -172
  358. package/assets/plugin/venues/hyperliquid/hl-cloid.d.ts +0 -22
  359. package/assets/plugin/venues/hyperliquid/hl-cloid.js +0 -82
  360. package/assets/plugin/venues/hyperliquid/hl-info-cache.d.ts +0 -46
  361. package/assets/plugin/venues/hyperliquid/hl-info-cache.js +0 -125
  362. package/assets/plugin/venues/hyperliquid/hl-live-adapter.d.ts +0 -146
  363. package/assets/plugin/venues/hyperliquid/hl-live-adapter.js +0 -728
  364. package/assets/plugin/venues/hyperliquid/hl-precision.d.ts +0 -61
  365. package/assets/plugin/venues/hyperliquid/hl-precision.js +0 -176
  366. package/assets/plugin/venues/hyperliquid/hl-private.d.ts +0 -88
  367. package/assets/plugin/venues/hyperliquid/hl-private.js +0 -357
  368. package/assets/plugin/venues/hyperliquid/hl-public.d.ts +0 -79
  369. package/assets/plugin/venues/hyperliquid/hl-public.js +0 -436
  370. package/assets/plugin/venues/hyperliquid/hl-rate-gate.d.ts +0 -57
  371. package/assets/plugin/venues/hyperliquid/hl-rate-gate.js +0 -220
  372. package/assets/plugin/venues/hyperliquid/hl-user-stream.d.ts +0 -90
  373. package/assets/plugin/venues/hyperliquid/hl-user-stream.js +0 -220
  374. package/assets/plugin/venues/registry.d.ts +0 -38
  375. package/assets/plugin/venues/registry.js +0 -46
  376. package/assets/plugin/venues/symbols.d.ts +0 -43
  377. package/assets/plugin/venues/symbols.js +0 -107
  378. package/assets/plugin/wave9/live-account-capture.d.ts +0 -67
  379. package/assets/plugin/wave9/live-account-capture.js +0 -435
  380. package/assets/plugin/wave9/live-autonomous-protection.d.ts +0 -39
  381. package/assets/plugin/wave9/live-autonomous-protection.js +0 -112
  382. package/assets/plugin/wave9/live-durable-reconciliation-scheduler.d.ts +0 -33
  383. package/assets/plugin/wave9/live-durable-reconciliation-scheduler.js +0 -115
  384. package/assets/plugin/wave9/live-execution-ledger.d.ts +0 -107
  385. package/assets/plugin/wave9/live-execution-ledger.js +0 -498
  386. package/assets/plugin/wave9/live-position-confirmation.d.ts +0 -18
  387. package/assets/plugin/wave9/live-position-confirmation.js +0 -111
  388. package/assets/plugin/wave9/live-residual-protection.d.ts +0 -18
  389. package/assets/plugin/wave9/live-residual-protection.js +0 -250
  390. package/assets/plugin/wave9/live-startup-reconciliation.d.ts +0 -38
  391. package/assets/plugin/wave9/live-startup-reconciliation.js +0 -454
  392. package/assets/plugin/wave9/live-symbol-ownership.d.ts +0 -20
  393. package/assets/plugin/wave9/live-symbol-ownership.js +0 -132
  394. package/assets/plugin/wave9/paper-admission-guard.d.ts +0 -199
  395. package/assets/plugin/wave9/paper-admission-guard.js +0 -650
  396. package/assets/plugin/wave9/usdm-evidence-provider.d.ts +0 -42
  397. package/assets/plugin/wave9/usdm-evidence-provider.js +0 -133
@@ -1,96 +0,0 @@
1
- // Persistent set of "every symbol this user has ever traded".
2
- //
3
- // WHY THIS EXISTS
4
- // ---------------
5
- // The REST gap-filler must call /fapi/v1/userTrades per symbol — there is no
6
- // portfolio-wide trades endpoint. Within a session it discovers symbols
7
- // from WS orderUpdate events + open-position snapshots. Across restarts that
8
- // in-memory set is lost: a symbol that opened AND closed entirely during a
9
- // plugin outage will (a) not appear in the next start's open-position seed
10
- // (already closed) and (b) never have emitted an orderUpdate to the new
11
- // process. Without this on-disk anchor, gap-fill skips it forever and the
12
- // fill rows are missing from the audit trail.
13
- //
14
- // WHAT THIS DOES
15
- // --------------
16
- // JSON file under ~/.reefclaw, atomic write (tmp + rename), per-user file
17
- // name. Append-only in practice — symbols are added on every WS orderUpdate
18
- // and on each open-position seed. Load returns an empty set on missing /
19
- // corrupt file so a bad save can't permanently break ingest.
20
- import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync, } from 'node:fs';
21
- import { homedir } from 'node:os';
22
- import { dirname, join } from 'node:path';
23
- import { logger, formatError } from '../logger.js';
24
- const TAG = 'touched-symbols';
25
- const SCHEMA_VERSION = 1;
26
- /** Default per-user path. The userId scoping prevents two parallel plugin
27
- * instances on the same machine (rare, but possible during ops) from
28
- * clobbering each other's history. */
29
- export function defaultTouchedSymbolsPath(userId) {
30
- // Sanitize — userId comes from the trusted plugin-config but should still
31
- // be safe as a filename component.
32
- const safe = userId.replace(/[^a-zA-Z0-9_-]/g, '_').slice(0, 64) || 'unknown';
33
- return join(homedir(), '.reefclaw', `touched-symbols-${safe}.json`);
34
- }
35
- export class TouchedSymbolsStore {
36
- path;
37
- userId;
38
- now;
39
- constructor(opts) {
40
- this.path = opts.path ?? defaultTouchedSymbolsPath(opts.userId);
41
- this.userId = opts.userId;
42
- this.now = opts.now ?? (() => Date.now());
43
- }
44
- /** Read the persisted set. Returns an empty Set on any error so a corrupt
45
- * file can't block ingest startup. The corrupt file isn't deleted —
46
- * the next save() naturally overwrites it via tmp+rename. */
47
- load() {
48
- try {
49
- if (!existsSync(this.path))
50
- return new Set();
51
- const raw = readFileSync(this.path, 'utf-8');
52
- const parsed = JSON.parse(raw);
53
- if (!parsed ||
54
- typeof parsed !== 'object' ||
55
- parsed.v !== SCHEMA_VERSION ||
56
- !Array.isArray(parsed.symbols)) {
57
- logger.warn(TAG, `unexpected on-disk shape at ${this.path} — ignoring`);
58
- return new Set();
59
- }
60
- const out = new Set();
61
- for (const s of parsed.symbols) {
62
- if (typeof s === 'string' && s.length > 0)
63
- out.add(s);
64
- }
65
- return out;
66
- }
67
- catch (err) {
68
- logger.warn(TAG, `failed to load ${this.path}: ${formatError(err)} — starting fresh`);
69
- return new Set();
70
- }
71
- }
72
- /** Atomically persist the set to disk. Best-effort — failures are logged
73
- * but never thrown; persistence is a recovery helper, not on the hot path. */
74
- save(symbols) {
75
- try {
76
- const dir = dirname(this.path);
77
- if (!existsSync(dir))
78
- mkdirSync(dir, { recursive: true });
79
- const body = {
80
- v: SCHEMA_VERSION,
81
- userId: this.userId,
82
- symbols: [...symbols].sort(),
83
- updatedAt: this.now(),
84
- };
85
- const tmp = `${this.path}.tmp`;
86
- writeFileSync(tmp, JSON.stringify(body, null, 2) + '\n', {
87
- encoding: 'utf-8',
88
- mode: 0o600,
89
- });
90
- renameSync(tmp, this.path);
91
- }
92
- catch (err) {
93
- logger.warn(TAG, `failed to save ${this.path}: ${formatError(err)}`);
94
- }
95
- }
96
- }
@@ -1,40 +0,0 @@
1
- import type { FillEvent } from '@reefclaw/shared';
2
- export interface TradeStoreClientOptions {
3
- baseUrl: string;
4
- ingestToken: string;
5
- /** Injectable for unit tests + observability shims. */
6
- fetchImpl?: typeof fetch;
7
- /** Per-attempt request timeout. */
8
- requestTimeoutMs?: number;
9
- /** Max total attempts (initial + retries). Default 4. */
10
- maxAttempts?: number;
11
- /** Initial backoff between retries. Doubles each attempt; ±20% jitter. */
12
- baseBackoffMs?: number;
13
- /** Cap on the exponential backoff. */
14
- backoffCapMs?: number;
15
- }
16
- export interface TradeStoreClientHealth {
17
- inFlight: number;
18
- totalPosted: number;
19
- totalSucceeded: number;
20
- totalDroppedTerminal: number;
21
- totalDroppedRetriesExhausted: number;
22
- }
23
- export declare class TradeStoreClient {
24
- private readonly opts;
25
- private inFlight;
26
- private totalPosted;
27
- private totalSucceeded;
28
- private totalDroppedTerminal;
29
- private totalDroppedRetriesExhausted;
30
- constructor(options: TradeStoreClientOptions);
31
- /** Fire-and-forget post. Returns immediately; response handled in the
32
- * background. Use `drain()` at shutdown to await all in-flight posts. */
33
- post(userId: string, fill: FillEvent): void;
34
- /** Await all in-flight posts. Resolves when the queue is empty.
35
- * Used at shutdown so we don't lose fills mid-flight. */
36
- drain(): Promise<void>;
37
- getHealth(): TradeStoreClientHealth;
38
- private run;
39
- private sleepBackoff;
40
- }
@@ -1,125 +0,0 @@
1
- // HTTP client for the webapp's /api/internal/trades ingest endpoint.
2
- //
3
- // Phase 1 of TRADE_AUDIT_TRAIL_PLAN. Posts a FillEvent over a shared-secret
4
- // bearer channel and treats the response with three buckets:
5
- //
6
- // - 2xx : success (including the implicit "no-op on conflict"
7
- // that the upsert returns as 200 + ok:true).
8
- // - 4xx (e.g. 400, 409) : terminal failure. Logged + dropped. Retrying
9
- // won't help: either the payload is malformed or
10
- // we're racing on a duplicate that's already
11
- // persisted. Both are correct outcomes for an
12
- // idempotent ingest.
13
- // - 5xx, network errors : transient. Retry with exponential backoff up to
14
- // `maxAttempts` (default 4 = ~7 s end-to-end).
15
- // After the final retry the row is dropped. The
16
- // REST reconciler (Phase 2) will rescue it on its
17
- // next pass.
18
- //
19
- // We intentionally do NOT block the caller waiting for the response. The WS
20
- // hot path runs `client.post(...)` and continues; the request happens in the
21
- // background. In-flight requests are tracked so `drain()` can be awaited at
22
- // shutdown to avoid losing the last fills before stop.
23
- import { logger, formatError } from '../logger.js';
24
- const TAG = 'trade-store-client';
25
- export class TradeStoreClient {
26
- opts;
27
- inFlight = new Set();
28
- totalPosted = 0;
29
- totalSucceeded = 0;
30
- totalDroppedTerminal = 0;
31
- totalDroppedRetriesExhausted = 0;
32
- constructor(options) {
33
- this.opts = {
34
- baseUrl: options.baseUrl.replace(/\/+$/, ''),
35
- ingestToken: options.ingestToken,
36
- fetchImpl: options.fetchImpl ?? fetch,
37
- requestTimeoutMs: options.requestTimeoutMs ?? 10_000,
38
- maxAttempts: options.maxAttempts ?? 4,
39
- baseBackoffMs: options.baseBackoffMs ?? 250,
40
- backoffCapMs: options.backoffCapMs ?? 5_000,
41
- };
42
- }
43
- /** Fire-and-forget post. Returns immediately; response handled in the
44
- * background. Use `drain()` at shutdown to await all in-flight posts. */
45
- post(userId, fill) {
46
- this.totalPosted++;
47
- const promise = this.run(userId, fill).finally(() => {
48
- this.inFlight.delete(promise);
49
- });
50
- this.inFlight.add(promise);
51
- }
52
- /** Await all in-flight posts. Resolves when the queue is empty.
53
- * Used at shutdown so we don't lose fills mid-flight. */
54
- async drain() {
55
- if (this.inFlight.size === 0)
56
- return;
57
- logger.info(TAG, `Draining ${this.inFlight.size} in-flight trade post(s)...`);
58
- await Promise.allSettled(Array.from(this.inFlight));
59
- }
60
- getHealth() {
61
- return {
62
- inFlight: this.inFlight.size,
63
- totalPosted: this.totalPosted,
64
- totalSucceeded: this.totalSucceeded,
65
- totalDroppedTerminal: this.totalDroppedTerminal,
66
- totalDroppedRetriesExhausted: this.totalDroppedRetriesExhausted,
67
- };
68
- }
69
- // ---- Internals ----
70
- async run(userId, fill) {
71
- const url = `${this.opts.baseUrl}/api/internal/trades`;
72
- const body = JSON.stringify(fill);
73
- for (let attempt = 1; attempt <= this.opts.maxAttempts; attempt++) {
74
- try {
75
- const ac = new AbortController();
76
- const tid = setTimeout(() => ac.abort(), this.opts.requestTimeoutMs);
77
- let res;
78
- try {
79
- res = await this.opts.fetchImpl(url, {
80
- method: 'POST',
81
- headers: {
82
- 'content-type': 'application/json',
83
- authorization: `Bearer ${this.opts.ingestToken}`,
84
- 'x-user-id': userId,
85
- },
86
- body,
87
- signal: ac.signal,
88
- });
89
- }
90
- finally {
91
- clearTimeout(tid);
92
- }
93
- if (res.status >= 200 && res.status < 300) {
94
- this.totalSucceeded++;
95
- return;
96
- }
97
- if (res.status >= 400 && res.status < 500) {
98
- // Terminal — re-tries won't change the outcome. 409 is a duplicate
99
- // (idempotency win); 400/401/404 are bugs we want logged loudly.
100
- this.totalDroppedTerminal++;
101
- logger.warn(TAG, `POST ${url} → ${res.status} (terminal, dropped). userId=${userId} tradeId=${fill.exchangeTradeId}`);
102
- return;
103
- }
104
- // 5xx — fall through to retry.
105
- logger.warn(TAG, `POST ${url} → ${res.status} (attempt ${attempt}/${this.opts.maxAttempts}).`);
106
- }
107
- catch (err) {
108
- // Network error / abort. Retry.
109
- logger.warn(TAG, `POST ${url} threw (attempt ${attempt}/${this.opts.maxAttempts}): ${formatError(err)}`);
110
- }
111
- if (attempt < this.opts.maxAttempts) {
112
- await this.sleepBackoff(attempt);
113
- }
114
- }
115
- // All attempts exhausted.
116
- this.totalDroppedRetriesExhausted++;
117
- logger.error(TAG, `POST ${url} dropped after ${this.opts.maxAttempts} attempts. userId=${userId} tradeId=${fill.exchangeTradeId}. REST reconciler (Phase 2) will rescue.`);
118
- }
119
- async sleepBackoff(attempt) {
120
- const exp = Math.min(this.opts.baseBackoffMs * 2 ** (attempt - 1), this.opts.backoffCapMs);
121
- const jitter = exp * 0.2 * (Math.random() * 2 - 1); // ±20%
122
- const delay = Math.max(0, Math.round(exp + jitter));
123
- await new Promise((resolve) => setTimeout(resolve, delay));
124
- }
125
- }
@@ -1,43 +0,0 @@
1
- import type { UserDataStream } from '../live/user-data-stream.js';
2
- import type { TradeStoreClient } from './trade-store-client.js';
3
- import { type AutoCaptureContext } from './position-auto-capture.js';
4
- export interface WsIngestOptions {
5
- /** The already-running user-data WS the controller hands us. */
6
- stream: UserDataStream;
7
- /** HTTP client for the webapp ingest endpoint. */
8
- client: TradeStoreClient;
9
- /** Trader identity — the userId that owns the trading account. */
10
- userId: string;
11
- /** Exchange identifier. Today always 'binance_futures'. */
12
- exchange?: string;
13
- /** Position-decision auto-capture context. When provided, every TRADE event
14
- * is also routed through `onWsFillObserved` to capture limit-order entries
15
- * and scale-ins that the synchronous create_order path can't see (the order
16
- * hadn't filled yet when create_order returned). Optional — when absent,
17
- * ws-ingest behaves exactly as before. */
18
- autoCapture?: AutoCaptureContext;
19
- }
20
- export declare class WsIngest {
21
- private readonly stream;
22
- private readonly client;
23
- private readonly userId;
24
- private readonly exchange;
25
- private readonly autoCapture?;
26
- private readonly handler;
27
- private started;
28
- /** Total ORDER_TRADE_UPDATE events the listener saw (any executionType). */
29
- private totalSeen;
30
- /** Subset of events that were actual fills (executionType='TRADE' + tradeId). */
31
- private totalFills;
32
- /** Events skipped because executionType !== 'TRADE' or tradeId missing. */
33
- private totalSkipped;
34
- constructor(opts: WsIngestOptions);
35
- start(): void;
36
- stop(): void;
37
- getHealth(): {
38
- totalSeen: number;
39
- totalFills: number;
40
- totalSkipped: number;
41
- };
42
- private onOrderUpdate;
43
- }
@@ -1,126 +0,0 @@
1
- // WS-side ingest — converts Binance ORDER_TRADE_UPDATE events into FillEvents
2
- // and pushes them to the webapp's audit-trail store.
3
- //
4
- // Phase 1 of TRADE_AUDIT_TRAIL_PLAN. Subscribes to the existing
5
- // `UserDataStream.orderUpdate` event (already running in shadow on prod) and
6
- // filters for true fills (`executionType === 'TRADE'` with a non-null
7
- // tradeId). Order-state transitions like NEW / CANCELED / EXPIRED are NOT
8
- // fills and are intentionally ignored — they don't move money or position.
9
- //
10
- // Idempotency lives in the upstream HTTP store: same Binance tradeId twice
11
- // (e.g. listenKey rotation re-deliver) collapses to one DB row. This module
12
- // is therefore safe to subscribe in shadow alongside the legacy poller-write
13
- // path; the unique index makes double-write impossible at the DB level.
14
- //
15
- // `start()` is idempotent and `stop()` is reversible. The class holds no
16
- // state beyond the bound listener so dispose-and-recreate is cheap during
17
- // stream reconnects.
18
- import { logger, formatError } from '../logger.js';
19
- import { onWsFillObserved } from './position-auto-capture.js';
20
- const TAG = 'ws-ingest';
21
- export class WsIngest {
22
- stream;
23
- client;
24
- userId;
25
- exchange;
26
- autoCapture;
27
- handler;
28
- started = false;
29
- /** Total ORDER_TRADE_UPDATE events the listener saw (any executionType). */
30
- totalSeen = 0;
31
- /** Subset of events that were actual fills (executionType='TRADE' + tradeId). */
32
- totalFills = 0;
33
- /** Events skipped because executionType !== 'TRADE' or tradeId missing. */
34
- totalSkipped = 0;
35
- constructor(opts) {
36
- this.stream = opts.stream;
37
- this.client = opts.client;
38
- this.userId = opts.userId;
39
- this.exchange = opts.exchange ?? 'binance_futures';
40
- this.autoCapture = opts.autoCapture;
41
- this.handler = (ev) => this.onOrderUpdate(ev);
42
- }
43
- start() {
44
- if (this.started)
45
- return;
46
- this.stream.on('orderUpdate', this.handler);
47
- this.started = true;
48
- logger.info(TAG, `Started — userId=${this.userId} exchange=${this.exchange}`);
49
- }
50
- stop() {
51
- if (!this.started)
52
- return;
53
- this.stream.off('orderUpdate', this.handler);
54
- this.started = false;
55
- logger.info(TAG, 'Stopped');
56
- }
57
- getHealth() {
58
- return {
59
- totalSeen: this.totalSeen,
60
- totalFills: this.totalFills,
61
- totalSkipped: this.totalSkipped,
62
- };
63
- }
64
- onOrderUpdate(ev) {
65
- this.totalSeen++;
66
- // Only TRUE fills (executionType='TRADE' with a real tradeId) become
67
- // audit-trail rows. NEW / CANCELED / EXPIRED / CALCULATED carry no
68
- // monetary movement — they're order-state transitions handled by the
69
- // existing live-state-store.
70
- if (ev.executionType !== 'TRADE' || ev.tradeId == null) {
71
- this.totalSkipped++;
72
- return;
73
- }
74
- // A TRADE event MUST have a positive lastFilledQty + lastFillPrice.
75
- // If those are absent the parser is broken — log loudly and skip.
76
- if (!(ev.lastFilledQty > 0) || ev.lastFillPrice == null || !(ev.lastFillPrice > 0)) {
77
- this.totalSkipped++;
78
- logger.warn(TAG, `Skipped TRADE event with missing qty/price: orderId=${ev.orderId} tradeId=${ev.tradeId} qty=${ev.lastFilledQty} px=${ev.lastFillPrice}`);
79
- return;
80
- }
81
- const fill = {
82
- exchange: this.exchange,
83
- exchangeTradeId: ev.tradeId,
84
- exchangeOrderId: ev.orderId,
85
- clientOrderId: ev.clientOrderId,
86
- source: 'ws',
87
- userId: this.userId,
88
- symbol: ev.symbol,
89
- side: ev.side === 'sell' ? 'SELL' : 'BUY',
90
- quantity: ev.lastFilledQty,
91
- price: ev.lastFillPrice,
92
- maker: ev.maker,
93
- reduceOnly: ev.reduceOnly,
94
- commission: ev.commission,
95
- commissionAsset: ev.commissionAsset,
96
- realizedPnl: ev.realizedPnl,
97
- exchangeTime: ev.transactionTime,
98
- // The full ParsedOrderUpdate is the rawPayload — we keep it as our
99
- // forensic record. The webapp persists this to JSONB so any future
100
- // re-derivation has the same fields the parser saw.
101
- rawPayload: ev,
102
- };
103
- this.totalFills++;
104
- this.client.post(this.userId, fill);
105
- // Position-decision auto-capture for the WS-driven path. Resolves the PR1
106
- // deferral that limit-order fills + scale-ins were silently dropped. Runs
107
- // as fire-and-forget — never block the audit-trail path on a decision-row
108
- // POST blip.
109
- if (this.autoCapture) {
110
- onWsFillObserved(this.autoCapture, {
111
- symbol: ev.symbol,
112
- side: ev.side,
113
- exchangeOrderId: ev.orderId,
114
- exchangeTradeId: ev.tradeId,
115
- fillPrice: ev.lastFillPrice,
116
- fillSize: ev.lastFilledQty,
117
- reduceOnly: ev.reduceOnly,
118
- realizedPnl: ev.realizedPnl,
119
- clientOrderId: ev.clientOrderId,
120
- exchangeTimeMs: ev.transactionTime,
121
- }).catch((err) => {
122
- logger.warn(TAG, `onWsFillObserved threw for orderId=${ev.orderId}: ${formatError(err)}`);
123
- });
124
- }
125
- }
126
- }
@@ -1,21 +0,0 @@
1
- export type SetupFamily = 'trend' | 'mean_reversion' | 'range' | 'breakout' | 'funding' | 'unknown' | 'other';
2
- export declare const ALL_SETUP_FAMILIES: readonly SetupFamily[];
3
- /**
4
- * Normalize a free-text `setup_type` into a stable `setup_family`.
5
- * Case- and whitespace-insensitive. `null` / `undefined` / `''` → 'unknown'.
6
- * Unrecognized non-empty strings → 'other' (never silently merged).
7
- */
8
- export declare function normalizeSetupFamily(setupType: string | null | undefined): SetupFamily;
9
- /**
10
- * Resolve a learning's `trigger_condition` setup constraint into the family/families
11
- * it targets, for family-aware matching. Used IDENTICALLY by both matchers (the
12
- * webapp `get_relevant_learnings` route and the plugin `scan_pairs` veto) so they
13
- * can never diverge.
14
- *
15
- * - Prefers an explicit `setup_family` (the family-keyed miner's output), taken
16
- * verbatim (scalar or array).
17
- * - Else normalizes `setup_type` (legacy / operator-authored) to family(ies).
18
- * - Returns `null` when the trigger pins NO setup constraint — the caller decides
19
- * whether that means wildcard (decision-time matcher) or no-veto (scan matcher).
20
- */
21
- export declare function resolveTriggerFamilies(triggerSetupFamily: unknown, triggerSetupType: unknown): SetupFamily[] | null;
@@ -1,103 +0,0 @@
1
- // Canonical `setup_type` → `setup_family` normalizer + trigger resolution.
2
- //
3
- // WHY THIS EXISTS (2026-06-22 prod finding). Learnings + mined patterns key on an
4
- // EXACT match against `setup_type`, but the agent invents free-text setup_type
5
- // strings continuously: `mean_reversion` → `mean_reversion_high_volume` →
6
- // `vwap_reversion`; `trend_continuation` → `daily_trend_pullback_v4` →
7
- // `livermore_tape_follow_v4` (drift accelerated by model swaps). An exact-match
8
- // learning therefore ORPHANS the moment the vocabulary moves — measured at ~0%
9
- // learning-citation on prod, with the dominant live setup (`daily_trend_pullback_v4`,
10
- // 118 entries) carrying no matching learning at all. Keying on a STABLE family
11
- // instead of the raw string is the prerequisite that lets a learning keep matching
12
- // as the agent renames its setups.
13
- // See docs/CLAUDE/learning-loop.md (2026-06-22 finding) +
14
- // memory/project_learning_loop_application_path_broken_jun22.md.
15
- //
16
- // DESIGN. An ORDERED keyword ruleset, first match wins. Robust to NEW invented
17
- // names as long as they carry a recognizable token (they almost always do).
18
- // Ordering is load-bearing:
19
- // - `funding` is tested BEFORE reversion, else `funding_reversion` would be
20
- // mislabelled mean_reversion.
21
- // - `range` is tested BEFORE the generic `fade` token, because `range_fade` is a
22
- // DISTINCT family that the data shows is profitable, whereas generic
23
- // `mean_reversion` underperforms — merging them would let an "avoid
24
- // mean_reversion" learning wrongly veto the profitable range fade.
25
- // Unrecognized strings map to 'other' (never silently merged into a real family;
26
- // 'other' is a signal to extend the ruleset, not a dumping ground).
27
- //
28
- // ★ CANONICAL SOURCE — KEEP IN SYNC. The plugin keeps a byte-identical copy at
29
- // `plugin/src/learning/setup-family.ts` (the deploy bundle strips workspace deps,
30
- // so shared runtime code is duplicated, not imported — same reason redact.ts is
31
- // duplicated ×3). Both copies are guarded by an identical behavioural test
32
- // (`setup-family.test.ts` in each package). Divergence between the webapp matcher
33
- // and the plugin scan_pairs matcher is exactly the bug class that caused the
34
- // 2026-05-15 wildcard-match incident (see memory/feedback_canonical_jsonb_key_naming).
35
- export const ALL_SETUP_FAMILIES = [
36
- 'trend',
37
- 'mean_reversion',
38
- 'range',
39
- 'breakout',
40
- 'funding',
41
- 'unknown',
42
- 'other',
43
- ];
44
- const has = (...tokens) => (s) => tokens.some((t) => s.includes(t));
45
- // First match wins. ORDER IS LOAD-BEARING — see the header comment.
46
- const RULES = [
47
- { family: 'unknown', test: (s) => s === 'unknown' },
48
- // `funding` before reversion: `funding_reversion` is its own family.
49
- { family: 'funding', test: has('funding') },
50
- // `range` before the generic `fade`: `range_fade` is distinct from mean_reversion.
51
- { family: 'range', test: has('range') },
52
- { family: 'breakout', test: has('breakout', 'squeeze', 'breakdown') },
53
- { family: 'trend', test: has('trend', 'pullback', 'tape_follow', 'livermore') },
54
- {
55
- family: 'mean_reversion',
56
- test: has('mean_rev', 'revers', // matches both "reversion" and "reversal"
57
- 'vwap', 'oversold', 'overbought', 'fade', 'cvd', 'divergence', 'exhaustion', 'macd'),
58
- },
59
- ];
60
- /**
61
- * Normalize a free-text `setup_type` into a stable `setup_family`.
62
- * Case- and whitespace-insensitive. `null` / `undefined` / `''` → 'unknown'.
63
- * Unrecognized non-empty strings → 'other' (never silently merged).
64
- */
65
- export function normalizeSetupFamily(setupType) {
66
- if (setupType == null)
67
- return 'unknown';
68
- const s = String(setupType).trim().toLowerCase();
69
- if (s === '')
70
- return 'unknown';
71
- for (const rule of RULES) {
72
- if (rule.test(s))
73
- return rule.family;
74
- }
75
- return 'other';
76
- }
77
- /**
78
- * Resolve a learning's `trigger_condition` setup constraint into the family/families
79
- * it targets, for family-aware matching. Used IDENTICALLY by both matchers (the
80
- * webapp `get_relevant_learnings` route and the plugin `scan_pairs` veto) so they
81
- * can never diverge.
82
- *
83
- * - Prefers an explicit `setup_family` (the family-keyed miner's output), taken
84
- * verbatim (scalar or array).
85
- * - Else normalizes `setup_type` (legacy / operator-authored) to family(ies).
86
- * - Returns `null` when the trigger pins NO setup constraint — the caller decides
87
- * whether that means wildcard (decision-time matcher) or no-veto (scan matcher).
88
- */
89
- export function resolveTriggerFamilies(triggerSetupFamily, triggerSetupType) {
90
- if (triggerSetupFamily != null) {
91
- const arr = Array.isArray(triggerSetupFamily)
92
- ? triggerSetupFamily
93
- : [triggerSetupFamily];
94
- return arr.map((x) => String(x));
95
- }
96
- if (triggerSetupType != null) {
97
- const arr = Array.isArray(triggerSetupType)
98
- ? triggerSetupType
99
- : [triggerSetupType];
100
- return arr.map((x) => normalizeSetupFamily(String(x)));
101
- }
102
- return null;
103
- }
@@ -1,33 +0,0 @@
1
- import type { PluginRuntime } from '../onboarding/runtime.js';
2
- /** Drain helper interface — only the methods we need on the trade-store
3
- * client. Avoids importing the full class so this module can stay narrow. */
4
- export interface DrainableTradeStore {
5
- drain(): Promise<void>;
6
- }
7
- /** Stop helper interface for the approval-mode ProposalDecisionListener.
8
- * Same single-method shape as DrainableTradeStore — kept narrow on purpose. */
9
- export interface StoppableListener {
10
- stop(): Promise<void>;
11
- }
12
- /** Flush helper for the paper StateManager. Narrow on purpose — we only need
13
- * flush() to force out the 1s-debounced save before the process exits. */
14
- export interface FlushableStateManager {
15
- flush(): Promise<void>;
16
- }
17
- export interface SignalHandlerDeps {
18
- runtime: PluginRuntime;
19
- tradeStore?: DrainableTradeStore;
20
- proposalListener?: StoppableListener;
21
- /** Paper-mode state persistence. Flushed last in the drain so the final ~1s
22
- * of debounced fills/closes/PnL are not lost on every restart. */
23
- stateManager?: FlushableStateManager;
24
- }
25
- /** The phase-2 drain body. Exported for direct unit-testing of the teardown
26
- * ordering + the StateManager flush wiring (the signal handler itself can't
27
- * be tested without process.exit). Every step is individually guarded so one
28
- * failing teardown never aborts the rest. */
29
- export declare function performShutdownDrain(deps: SignalHandlerDeps): Promise<void>;
30
- /** Register graceful-shutdown handlers. Idempotent — repeat signals during
31
- * the drain are logged + ignored. After the coordinator resolves we call
32
- * process.exit(0) so systemd doesn't escalate to SIGKILL. */
33
- export declare function installSignalHandlers(deps: SignalHandlerDeps): void;