@reefclaw/openclaw-plugin 0.1.45 → 0.1.48

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 (74) hide show
  1. package/README.md +1 -1
  2. package/bridge/bridge.d.ts +39 -0
  3. package/bridge/bridge.js +210 -7
  4. package/bridge/config.js +5 -2
  5. package/bridge/gateway/gateway-config.d.ts +5 -0
  6. package/bridge/gateway/gateway-config.js +5 -2
  7. package/bridge/gateway/heartbeat-cron.js +3 -2
  8. package/bridge/heartbeat-runs.d.ts +6 -0
  9. package/bridge/heartbeat-runs.js +45 -4
  10. package/bridge/heartbeat-transcript.d.ts +2 -0
  11. package/bridge/heartbeat-transcript.js +45 -13
  12. package/bridge/index.js +31 -0
  13. package/bridge/providers/connector-update.js +22 -5
  14. package/bridge/providers/emergency-commands.js +2 -3
  15. package/bridge/providers/gateway.d.ts +6 -0
  16. package/bridge/providers/gateway.js +57 -27
  17. package/bridge/providers/onboarding-commands.d.ts +8 -7
  18. package/bridge/setup.js +12 -0
  19. package/bridge/shock-wake.d.ts +7 -0
  20. package/bridge/shock-wake.js +72 -9
  21. package/bridge/types.d.ts +17 -0
  22. package/bridge/utils/base-url.d.ts +26 -0
  23. package/bridge/utils/base-url.js +108 -0
  24. package/bridge/utils/operator-secret.d.ts +7 -0
  25. package/bridge/utils/operator-secret.js +59 -0
  26. package/bridge/utils/relay-host.d.ts +23 -0
  27. package/bridge/utils/relay-host.js +66 -0
  28. package/bridge/utils/untrusted-text.d.ts +9 -0
  29. package/bridge/utils/untrusted-text.js +51 -0
  30. package/bridge/utils/webapp-edge.d.ts +145 -0
  31. package/bridge/utils/webapp-edge.js +366 -0
  32. package/config/agent-config-client.js +18 -2
  33. package/config/agent-config-poller.d.ts +4 -0
  34. package/config/agent-config-poller.js +46 -6
  35. package/config/base-url.d.ts +16 -0
  36. package/config/base-url.js +87 -0
  37. package/config/operator-provenance.d.ts +19 -0
  38. package/config/operator-provenance.js +102 -25
  39. package/config/user-data-stream-config.d.ts +5 -1
  40. package/config/user-data-stream-config.js +7 -5
  41. package/connector-supervisor.d.ts +15 -0
  42. package/connector-supervisor.js +22 -1
  43. package/http/webapp-edge.d.ts +116 -0
  44. package/http/webapp-edge.js +313 -0
  45. package/index.js +36 -24
  46. package/ingest/position-decisions-client.js +51 -11
  47. package/ingest/readiness-reporter.d.ts +13 -0
  48. package/ingest/readiness-reporter.js +78 -8
  49. package/ingest/retry-after.d.ts +5 -0
  50. package/ingest/retry-after.js +21 -0
  51. package/ingest/trade-store-client.js +43 -7
  52. package/lifecycle/process-role.d.ts +4 -0
  53. package/lifecycle/process-role.js +1 -1
  54. package/openclaw.plugin.json +1 -1
  55. package/package.json +2 -2
  56. package/release-integrity.json +10 -0
  57. package/release-notes.json +3 -1
  58. package/risk/pre-trade-check.js +1 -1
  59. package/risk/stop-widening-guard.d.ts +35 -0
  60. package/risk/stop-widening-guard.js +98 -0
  61. package/skills/reefclaw/SKILL.md +2 -2
  62. package/tools/create-order.js +17 -12
  63. package/tools/get-bracket-config.d.ts +3 -1
  64. package/tools/get-bracket-config.js +3 -1
  65. package/tools/get-market-intel.d.ts +4 -0
  66. package/tools/get-market-intel.js +38 -4
  67. package/tools/modify-stop.d.ts +6 -0
  68. package/tools/modify-stop.js +110 -0
  69. package/tools/set-bracket-requirement.d.ts +7 -0
  70. package/tools/set-bracket-requirement.js +12 -0
  71. package/trading-params-bounds.d.ts +32 -0
  72. package/trading-params-bounds.js +113 -0
  73. package/trading-params-cache.d.ts +9 -1
  74. package/trading-params-cache.js +33 -2
@@ -1,6 +1,9 @@
1
1
  // Trading parameters cache — fetches from intelligence API and caches locally.
2
2
  // Plugin tools (score-setup, pre-trade-check) read from this cache.
3
3
  import { fetchIntelApi } from './tools/intel-api.js';
4
+ import { logger } from './logger.js';
5
+ import { sanitizeTradingParams } from './trading-params-bounds.js';
6
+ const TAG = 'trading-params';
4
7
  // Hardcoded defaults (same as intelligence/src/trading-params/types.ts)
5
8
  const DEFAULTS = {
6
9
  regimeConfidenceFloor: 0.35,
@@ -24,7 +27,27 @@ const DEFAULTS = {
24
27
  let cached = { ...DEFAULTS };
25
28
  let cacheExpiry = 0;
26
29
  const CACHE_TTL = 60_000; // 60s
27
- /** Get trading parameters (from cache or fetch). Returns defaults on failure. */
30
+ /** Signature of the last reported adjustment set — the fetch repeats every
31
+ * 60s, the warning should not. */
32
+ let lastAdjustmentSig = '';
33
+ function reportAdjustments(adjustments) {
34
+ const sig = adjustments.map((a) => `${a.key}=${a.received}→${a.applied}(${a.reason})`).join(', ');
35
+ if (sig === lastAdjustmentSig)
36
+ return;
37
+ lastAdjustmentSig = sig;
38
+ if (sig === '') {
39
+ logger.info(TAG, 'intel trading params back within the hardcoded bounds — clamp released');
40
+ return;
41
+ }
42
+ logger.warn(TAG, `intel trading params outside the hardcoded bounds — clamped (the gate uses the applied value): ${sig}`);
43
+ }
44
+ /** Get trading parameters (from cache or fetch). Returns defaults on failure.
45
+ *
46
+ * The fetched payload is UNTRUSTED policy from the network: every field is
47
+ * type-checked and clamped into the hardcoded range (trading-params-bounds.ts)
48
+ * before it can reach the pre-trade gate. Audit 2026-09-27 H4 — a NaN /
49
+ * string / null used to make the gate's comparison `false` and switch that
50
+ * limit off silently. */
28
51
  export async function getTradingParams(deps) {
29
52
  const now = Date.now();
30
53
  if (now < cacheExpiry)
@@ -32,8 +55,10 @@ export async function getTradingParams(deps) {
32
55
  try {
33
56
  const res = await fetchIntelApi('/api/trading-params', deps);
34
57
  if (!('error' in res) && res.params) {
35
- cached = { ...DEFAULTS, ...res.params };
58
+ const { params, adjustments } = sanitizeTradingParams(res.params, DEFAULTS);
59
+ cached = params;
36
60
  cacheExpiry = now + CACHE_TTL;
61
+ reportAdjustments(adjustments);
37
62
  }
38
63
  }
39
64
  catch {
@@ -41,6 +66,12 @@ export async function getTradingParams(deps) {
41
66
  }
42
67
  return cached;
43
68
  }
69
+ /** Test-only: drop the cache back to the hardcoded defaults. */
70
+ export function resetTradingParamsCacheForTest() {
71
+ cached = { ...DEFAULTS };
72
+ cacheExpiry = 0;
73
+ lastAdjustmentSig = '';
74
+ }
44
75
  /** Get cached params synchronously (for pure functions like preTradeRiskCheck). */
45
76
  export function getCachedTradingParams() {
46
77
  return cached;