@reefclaw/openclaw-plugin 0.1.49 → 0.1.51

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 (35) hide show
  1. package/README.md +10 -6
  2. package/bridge/config.js +10 -3
  3. package/bridge/gateway/gateway-ws-client.d.ts +79 -1
  4. package/bridge/gateway/gateway-ws-client.js +99 -5
  5. package/bridge/gateway/heartbeat-cron.d.ts +39 -2
  6. package/bridge/gateway/heartbeat-cron.js +62 -8
  7. package/bridge/heartbeat-transcript.d.ts +3 -1
  8. package/bridge/heartbeat-transcript.js +26 -5
  9. package/bridge/index.js +2 -2
  10. package/bridge/providers/connector-update-direct.d.ts +3 -0
  11. package/bridge/providers/connector-update-direct.js +11 -1
  12. package/bridge/providers/connector-update-openclaw.d.ts +268 -0
  13. package/bridge/providers/connector-update-openclaw.js +772 -0
  14. package/bridge/providers/connector-update.d.ts +115 -1
  15. package/bridge/providers/connector-update.js +228 -13
  16. package/bridge/providers/gateway.d.ts +31 -10
  17. package/bridge/providers/gateway.js +144 -28
  18. package/bridge/setup.js +6 -3
  19. package/bridge/utils/relay-host.d.ts +16 -0
  20. package/bridge/utils/relay-host.js +30 -1
  21. package/config/first-start-venue.d.ts +147 -0
  22. package/config/first-start-venue.js +400 -0
  23. package/config/plugin-config-io.d.ts +9 -2
  24. package/config/plugin-config-io.js +29 -5
  25. package/connector-supervisor.d.ts +20 -0
  26. package/connector-supervisor.js +27 -1
  27. package/index.js +32 -1
  28. package/openclaw.plugin.json +333 -1
  29. package/package.json +1 -1
  30. package/release-integrity.json +10 -0
  31. package/release-notes.json +3 -1
  32. package/skills/reefclaw/SKILL.md +21 -8
  33. package/strategy/builtin-strategies.js +2 -2
  34. package/tools/venue-quote-hint.d.ts +49 -0
  35. package/tools/venue-quote-hint.js +200 -0
@@ -0,0 +1,200 @@
1
+ // Hyperliquid quote-asset hint on FAILED tool calls (2026-09-30).
2
+ //
3
+ // Why: on a Hyperliquid box the agent keeps reaching for Binance-shaped
4
+ // symbols (get_market_structure("BTC/USDT"), fetch_ticker("BTCUSDT")), and the
5
+ // call fails with a bare "Failed to fetch candle data for BTC/USDT" /
6
+ // "Failed to fetch current price for BTCUSDT" (tools/helpers.ts,
7
+ // tools/get-market-structure.ts, tools/create-order.ts; ~44 tools take a
8
+ // symbol) that never says the pair is on the wrong quote asset. The agent then
9
+ // retries the same symbol, or concludes the market-data path is down.
10
+ //
11
+ // What this does: ONE additive field, applied centrally at the tool dispatch
12
+ // wrapper (index.ts, inside the ToolGate + entitlement gate). When a call has
13
+ // ALREADY failed (its result carries a non-empty `error`), the running venue
14
+ // is hyperliquid, and the call's `symbol` / `symbols` arguments look
15
+ // USDT-quoted ("X/USDT", "X/USDT:USDT", "XUSDT"), the result gains
16
+ // hint: "Hyperliquid pairs are quoted in USDC: use X/USDC"
17
+ //
18
+ // What it never does (CLAUDE.md: never silently translate quote assets):
19
+ // - translate, rewrite or retry the call: the agent reads the hint and
20
+ // decides what to call next;
21
+ // - touch a successful result (get_regime('BTCUSDT') works on both venues);
22
+ // - change the error text, or a `hint` a tool already set;
23
+ // - throw: any exception on this path returns the original result as is,
24
+ // and a tool's own rejection passes through untouched.
25
+ //
26
+ // Deriving the base is deliberately conservative. Hyperliquid coin names are
27
+ // case-sensitive ('kPEPE' is 1000 PEPE; venues/symbols.ts), so only a trailing
28
+ // exact-case "USDT" / "/USDT" / "/USDT:USDT" is stripped and the base is kept
29
+ // verbatim. A lowercase quote ("btcusdt"), a base that starts with a digit, or
30
+ // anything else unusual gets the generic hint, which names no pair. The one
31
+ // mapping is for the coins Hyperliquid lists per 1000 under a 'k' prefix
32
+ // (HL_PER_1000_BASES): "PEPEUSDT" and Binance's "1000PEPEUSDT" both name
33
+ // "kPEPE/USDC", because "PEPE/USDC" does not trade there, and a hint naming it
34
+ // would send the agent into a second failure that carries no hint (the retried
35
+ // symbol is no longer USDT-quoted). That is still wording only: the call the
36
+ // agent made is never rewritten.
37
+ import { VENUE_QUOTE_ASSET } from '../venues/symbols.js';
38
+ const HL_QUOTE = VENUE_QUOTE_ASSET.hyperliquid; // 'USDC'
39
+ /** Generic wording: used whenever a specific pair cannot be named safely. */
40
+ export const HL_GENERIC_QUOTE_HINT = `Hyperliquid pairs are quoted in ${HL_QUOTE} (e.g. BTC/${HL_QUOTE})`;
41
+ /** At most this many pairs are named in one hint. */
42
+ const MAX_NAMED_PAIRS = 5;
43
+ /** At most this many `symbols` entries are inspected (bounded work). */
44
+ const MAX_SYMBOLS_INSPECTED = 50;
45
+ /** A base we are willing to echo back as "<base>/USDC": starts with a letter,
46
+ * letters and digits only, short. Case is preserved, never changed. */
47
+ const SAFE_BASE = /^[A-Za-z][A-Za-z0-9]{0,19}$/;
48
+ /** Plain bases Hyperliquid lists only per 1000, as 'k' + base ('kPEPE' = 1000
49
+ * PEPE). Checked against Hyperliquid's live `meta` universe on 2026-09-30:
50
+ * kPEPE, kSHIB, kBONK, kFLOKI, kLUNC and kNEIRO trade, none of the plain
51
+ * bases does (kDOGS is in the universe but delisted, so DOGS is not here).
52
+ * Wording only, both ways: a k-coin this list misses keeps the plain
53
+ * '<base>/USDC' wording, and an entry delisted later names a pair that no
54
+ * longer trades; the call itself is never touched. */
55
+ export const HL_PER_1000_BASES = new Set(['PEPE', 'SHIB', 'BONK', 'FLOKI', 'LUNC', 'NEIRO']);
56
+ /** The Hyperliquid coin to name for a USDT base: 'k' + base for a coin listed
57
+ * per 1000 (from the plain 'PEPE' or Binance's '1000PEPE'), the base itself
58
+ * otherwise; null when the base is not safe to name at all. */
59
+ function hyperliquidBaseFor(base) {
60
+ const thousands = /^1000([A-Z]+)$/.exec(base);
61
+ if (thousands)
62
+ return HL_PER_1000_BASES.has(thousands[1]) ? `k${thousands[1]}` : null;
63
+ if (!SAFE_BASE.test(base))
64
+ return null;
65
+ const upper = base.toUpperCase();
66
+ if (upper === 'USDT' || upper === HL_QUOTE)
67
+ return null;
68
+ return HL_PER_1000_BASES.has(base) ? `k${base}` : base;
69
+ }
70
+ /** Does this argument look like a Binance USDT-quoted pair? Pure, never throws
71
+ * (non-strings are simply not USDT-quoted). */
72
+ export function classifyUsdtSymbol(raw) {
73
+ if (typeof raw !== 'string')
74
+ return { kind: 'not-usdt' };
75
+ const s = raw.trim();
76
+ if (s === '')
77
+ return { kind: 'not-usdt' };
78
+ // Exact case: canonical "X/USDT", CCXT "X/USDT:USDT", Binance-native "XUSDT".
79
+ const m = /^(.*)\/USDT(?::USDT)?$/.exec(s) ?? /^([^/:]*)USDT$/.exec(s);
80
+ if (m) {
81
+ const base = hyperliquidBaseFor(m[1]);
82
+ return base !== null ? { kind: 'usdt', base } : { kind: 'usdt-unclear' };
83
+ }
84
+ // Any other casing of the same shapes: still USDT-quoted, but the base's
85
+ // true Hyperliquid casing is unknown, so it is never echoed back.
86
+ if (/^.*\/usdt(?::usdt)?$/i.test(s) || /^[^/:]*usdt$/i.test(s))
87
+ return { kind: 'usdt-unclear' };
88
+ return { kind: 'not-usdt' };
89
+ }
90
+ /** The hint for a call's arguments, or null when none of its `symbol` /
91
+ * `symbols` look USDT-quoted. Pure. Only those two fields are read (never
92
+ * any other argument, some of which are credentials). */
93
+ export function buildHyperliquidQuoteHint(params) {
94
+ if (!params || typeof params !== 'object' || Array.isArray(params))
95
+ return null;
96
+ const p = params;
97
+ const candidates = [p.symbol];
98
+ if (Array.isArray(p.symbols))
99
+ candidates.push(...p.symbols.slice(0, MAX_SYMBOLS_INSPECTED));
100
+ const bases = [];
101
+ let unclear = false;
102
+ for (const c of candidates) {
103
+ const v = classifyUsdtSymbol(c);
104
+ if (v.kind === 'usdt') {
105
+ if (!bases.includes(v.base))
106
+ bases.push(v.base);
107
+ }
108
+ else if (v.kind === 'usdt-unclear') {
109
+ unclear = true;
110
+ }
111
+ }
112
+ if (bases.length === 0 && !unclear)
113
+ return null;
114
+ // One unclear symbol makes the whole hint generic: naming some pairs and
115
+ // not others would read as "these are the only fix".
116
+ if (unclear)
117
+ return HL_GENERIC_QUOTE_HINT;
118
+ const shown = bases.slice(0, MAX_NAMED_PAIRS);
119
+ const named = shown.map((b) => `${b}/${HL_QUOTE}`);
120
+ const more = bases.length > MAX_NAMED_PAIRS ? ', …' : '';
121
+ // A per-1000 coin says so: one unit is 1000 of the plain coin (1000x the price).
122
+ const per1000 = shown.flatMap((b) => {
123
+ const plain = b.startsWith('k') ? b.slice(1) : '';
124
+ return HL_PER_1000_BASES.has(plain) ? [`${b} = 1000 ${plain}`] : [];
125
+ });
126
+ const note = per1000.length > 0 ? ` (${per1000.join(', ')})` : '';
127
+ return `Hyperliquid pairs are quoted in ${HL_QUOTE}: use ${named.join(', ')}${more}${note}`;
128
+ }
129
+ /** A tool result's details that report a failure: a plain object whose own
130
+ * `error` is a non-empty string, `true`, or an object. `error: null`,
131
+ * `false` or `''` is not a failure. */
132
+ export function carriesError(details) {
133
+ if (!details || typeof details !== 'object' || Array.isArray(details))
134
+ return false;
135
+ if (!Object.prototype.hasOwnProperty.call(details, 'error'))
136
+ return false;
137
+ const e = details.error;
138
+ if (typeof e === 'string')
139
+ return e.trim() !== '';
140
+ return e === true || (typeof e === 'object' && e !== null);
141
+ }
142
+ /** The result, with the hint added when every condition holds; otherwise the
143
+ * SAME object, untouched. Only a result in index.ts jsonResult's exact shape
144
+ * (one text block that is JSON.stringify(details)) is ever rebuilt, so no
145
+ * hand-built result can be mangled. Never throws. */
146
+ export function addHyperliquidQuoteHint(result, params, venue) {
147
+ try {
148
+ if (venue !== 'hyperliquid')
149
+ return result;
150
+ const r = result;
151
+ if (!r || typeof r !== 'object' || !Array.isArray(r.content) || r.content.length !== 1)
152
+ return result;
153
+ const details = r.details;
154
+ if (!carriesError(details))
155
+ return result;
156
+ if (Object.prototype.hasOwnProperty.call(details, 'hint'))
157
+ return result;
158
+ const block = r.content[0];
159
+ if (!block || block.type !== 'text' || block.text !== JSON.stringify(details))
160
+ return result;
161
+ const hint = buildHyperliquidQuoteHint(params);
162
+ if (hint === null)
163
+ return result;
164
+ const next = { ...details, hint };
165
+ return {
166
+ ...r,
167
+ content: [{ type: 'text', text: JSON.stringify(next) }],
168
+ details: next,
169
+ };
170
+ }
171
+ catch {
172
+ return result;
173
+ }
174
+ }
175
+ /** Wrap a tool's execute with the hint. `getVenue` is called per call, AFTER
176
+ * the tool returned, and only feeds the hint path (a throwing getter = no
177
+ * hint). The tool's own promise rejection, or a non-promise return, passes
178
+ * through untouched; every other property of the tool is kept. */
179
+ export function wrapToolWithHyperliquidQuoteHint(tool, getVenue) {
180
+ const originalExecute = tool.execute.bind(tool);
181
+ return {
182
+ ...tool,
183
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
184
+ execute: (...args) => {
185
+ const out = originalExecute(...args);
186
+ if (!out || typeof out.then !== 'function')
187
+ return out;
188
+ return out.then((result) => {
189
+ let venue;
190
+ try {
191
+ venue = getVenue();
192
+ }
193
+ catch {
194
+ return result;
195
+ }
196
+ return addHyperliquidQuoteHint(result, args[1], venue);
197
+ });
198
+ },
199
+ };
200
+ }