@sherwoodagent/cli 0.47.1 → 0.51.0

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.
@@ -21,8 +21,12 @@ import {
21
21
  calculateMACD,
22
22
  calculateRSI,
23
23
  getLatestSignals,
24
- safeNumber
25
- } from "./chunk-R2P4C2I7.js";
24
+ hlMarketBuy,
25
+ hlMarketSell,
26
+ resolveHLCoin,
27
+ safeNumber,
28
+ validateHLEnv
29
+ } from "./chunk-OMW47WOO.js";
26
30
  import {
27
31
  chatCompletion
28
32
  } from "./chunk-7HJXZ4NM.js";
@@ -36,7 +40,7 @@ import {
36
40
  import chalk9 from "chalk";
37
41
  import { readFile as readFile14, writeFile as writeFile14, mkdir as mkdir16 } from "fs/promises";
38
42
  import { join as join17 } from "path";
39
- import { homedir as homedir16 } from "os";
43
+ import { homedir as homedir15 } from "os";
40
44
  import ora from "ora";
41
45
 
42
46
  // src/agent/index.ts
@@ -247,7 +251,7 @@ var CoinGeckoProvider = class {
247
251
  const now = Date.now();
248
252
  const elapsed = now - sharedLastCallTime;
249
253
  if (elapsed < MIN_INTERVAL) {
250
- await new Promise((resolve2) => setTimeout(resolve2, MIN_INTERVAL - elapsed));
254
+ await new Promise((resolve) => setTimeout(resolve, MIN_INTERVAL - elapsed));
251
255
  }
252
256
  sharedLastCallTime = Date.now();
253
257
  const headers = {};
@@ -643,7 +647,7 @@ var DexScreenerProvider = class {
643
647
  const now = Date.now();
644
648
  const elapsed = now - sharedLastCallTime2;
645
649
  if (elapsed < SHARED_MIN_INTERVAL) {
646
- await new Promise((resolve2) => setTimeout(resolve2, SHARED_MIN_INTERVAL - elapsed));
650
+ await new Promise((resolve) => setTimeout(resolve, SHARED_MIN_INTERVAL - elapsed));
647
651
  }
648
652
  sharedLastCallTime2 = Date.now();
649
653
  }
@@ -1183,12 +1187,12 @@ function rpcSend(method, params) {
1183
1187
  const proc = ensureProcess();
1184
1188
  const id = nextId++;
1185
1189
  const msg = JSON.stringify({ jsonrpc: "2.0", id, method, params }) + "\n";
1186
- return new Promise((resolve2, reject) => {
1190
+ return new Promise((resolve, reject) => {
1187
1191
  const timer = setTimeout(() => {
1188
1192
  pending.delete(id);
1189
1193
  reject(new Error(`MCP RPC timeout for ${method} (${RPC_TIMEOUT_MS}ms)`));
1190
1194
  }, RPC_TIMEOUT_MS);
1191
- pending.set(id, { resolve: resolve2, reject, timer });
1195
+ pending.set(id, { resolve, reject, timer });
1192
1196
  proc.stdin.write(msg, (err) => {
1193
1197
  if (err) {
1194
1198
  clearTimeout(timer);
@@ -2321,7 +2325,7 @@ async function callFincept(script, args = [], timeoutMs = DEFAULT_TIMEOUT_MS, ca
2321
2325
  }
2322
2326
  const scriptPath = join4(FINCEPT_SCRIPTS_DIR, script);
2323
2327
  const t0 = Date.now();
2324
- return new Promise((resolve2) => {
2328
+ return new Promise((resolve) => {
2325
2329
  execFile(
2326
2330
  "python3",
2327
2331
  [scriptPath, ...args],
@@ -2333,7 +2337,7 @@ async function callFincept(script, args = [], timeoutMs = DEFAULT_TIMEOUT_MS, ca
2333
2337
  (error, stdout, _stderr) => {
2334
2338
  const latencyMs = Date.now() - t0;
2335
2339
  if (error && "killed" in error && error.killed) {
2336
- resolve2({
2340
+ resolve({
2337
2341
  ok: false,
2338
2342
  error: `Script "${script}" timed out after ${timeoutMs}ms`,
2339
2343
  latencyMs
@@ -2341,7 +2345,7 @@ async function callFincept(script, args = [], timeoutMs = DEFAULT_TIMEOUT_MS, ca
2341
2345
  return;
2342
2346
  }
2343
2347
  if (error) {
2344
- resolve2({
2348
+ resolve({
2345
2349
  ok: false,
2346
2350
  error: `Script "${script}" failed: ${error.message}`,
2347
2351
  latencyMs
@@ -2350,7 +2354,7 @@ async function callFincept(script, args = [], timeoutMs = DEFAULT_TIMEOUT_MS, ca
2350
2354
  }
2351
2355
  const raw = stdout.trim();
2352
2356
  if (!raw) {
2353
- resolve2({
2357
+ resolve({
2354
2358
  ok: false,
2355
2359
  error: `Script "${script}" returned empty output`,
2356
2360
  latencyMs
@@ -2361,7 +2365,7 @@ async function callFincept(script, args = [], timeoutMs = DEFAULT_TIMEOUT_MS, ca
2361
2365
  try {
2362
2366
  parsed = JSON.parse(raw);
2363
2367
  } catch {
2364
- resolve2({
2368
+ resolve({
2365
2369
  ok: false,
2366
2370
  error: `Script "${script}" returned invalid JSON: ${raw.slice(0, 200)}`,
2367
2371
  latencyMs
@@ -2369,7 +2373,7 @@ async function callFincept(script, args = [], timeoutMs = DEFAULT_TIMEOUT_MS, ca
2369
2373
  return;
2370
2374
  }
2371
2375
  if (parsed !== null && typeof parsed === "object" && "error" in parsed && typeof parsed.error === "string") {
2372
- resolve2({
2376
+ resolve({
2373
2377
  ok: false,
2374
2378
  error: parsed.error,
2375
2379
  latencyMs
@@ -2379,7 +2383,7 @@ async function callFincept(script, args = [], timeoutMs = DEFAULT_TIMEOUT_MS, ca
2379
2383
  if (cacheTtlMs > 0) {
2380
2384
  cache2.set(cacheKey2, { ts: Date.now(), data: parsed });
2381
2385
  }
2382
- resolve2({ ok: true, data: parsed, latencyMs });
2386
+ resolve({ ok: true, data: parsed, latencyMs });
2383
2387
  }
2384
2388
  );
2385
2389
  });
@@ -2629,7 +2633,7 @@ async function getKronosVolForecast(tokenId, candles, samples = 5, predLen = 24)
2629
2633
  }))
2630
2634
  });
2631
2635
  const scriptPath = join5(FINCEPT_SCRIPTS_DIR, "kronos_predict.py");
2632
- return new Promise((resolve2) => {
2636
+ return new Promise((resolve) => {
2633
2637
  const proc = execFile2(
2634
2638
  KRONOS_PYTHON,
2635
2639
  [scriptPath, "--samples", String(samples), "--pred-len", String(predLen)],
@@ -2641,22 +2645,22 @@ async function getKronosVolForecast(tokenId, candles, samples = 5, predLen = 24)
2641
2645
  (error, stdout, stderr) => {
2642
2646
  if (error) {
2643
2647
  console.error(` [kronos] Inference failed: ${error.message}`);
2644
- resolve2(null);
2648
+ resolve(null);
2645
2649
  return;
2646
2650
  }
2647
2651
  try {
2648
2652
  const result = JSON.parse(stdout.trim());
2649
2653
  if (result.error) {
2650
2654
  console.error(` [kronos] ${result.error}`);
2651
- resolve2(null);
2655
+ resolve(null);
2652
2656
  return;
2653
2657
  }
2654
2658
  const forecast = result;
2655
2659
  cache3.set(cacheKey2, { ts: Date.now(), data: forecast });
2656
- resolve2(forecast);
2660
+ resolve(forecast);
2657
2661
  } catch {
2658
2662
  console.error(` [kronos] Invalid JSON output`);
2659
- resolve2(null);
2663
+ resolve(null);
2660
2664
  }
2661
2665
  }
2662
2666
  );
@@ -2974,8 +2978,8 @@ var SignalSmoother = class {
2974
2978
  const prev = this.writeLock;
2975
2979
  let release = () => {
2976
2980
  };
2977
- this.writeLock = new Promise((resolve2) => {
2978
- release = resolve2;
2981
+ this.writeLock = new Promise((resolve) => {
2982
+ release = resolve;
2979
2983
  });
2980
2984
  await prev;
2981
2985
  try {
@@ -5089,120 +5093,10 @@ var DynamicTokenSelector = class {
5089
5093
  import chalk7 from "chalk";
5090
5094
  import { mkdir as mkdir13, appendFile as appendFile2 } from "fs/promises";
5091
5095
  import { join as join14 } from "path";
5092
- import { homedir as homedir13 } from "os";
5096
+ import { homedir as homedir12 } from "os";
5093
5097
 
5094
5098
  // src/agent/executor.ts
5095
5099
  import chalk3 from "chalk";
5096
-
5097
- // src/lib/hyperliquid-executor.ts
5098
- import { execFile as execFile3 } from "child_process";
5099
- import { resolve } from "path";
5100
- import { homedir as homedir10 } from "os";
5101
- var HL_SCRIPT = resolve(
5102
- homedir10(),
5103
- ".hermes/skills/openclaw-imports/hyperliquid/scripts/hyperliquid.mjs"
5104
- );
5105
- var TOKEN_TO_HL_COIN = {
5106
- bitcoin: "BTC",
5107
- ethereum: "ETH",
5108
- solana: "SOL",
5109
- arbitrum: "ARB",
5110
- dogecoin: "DOGE",
5111
- chainlink: "LINK",
5112
- aave: "AAVE",
5113
- uniswap: "UNI",
5114
- ripple: "XRP",
5115
- polkadot: "DOT",
5116
- avalanche: "AVAX",
5117
- hyperliquid: "HYPE",
5118
- zcash: "ZEC",
5119
- bittensor: "TAO",
5120
- "worldcoin-wld": "WLD",
5121
- fartcoin: "FARTCOIN",
5122
- "fetch-ai": "FET",
5123
- pepe: "PEPE",
5124
- pendle: "PENDLE",
5125
- sui: "SUI",
5126
- near: "NEAR",
5127
- aptos: "APT"
5128
- };
5129
- function resolveHLCoin(tokenId) {
5130
- return TOKEN_TO_HL_COIN[tokenId];
5131
- }
5132
- function runHLScript(command, args = []) {
5133
- return new Promise((resolve2, reject) => {
5134
- const env = { ...process.env };
5135
- if (process.env.HYPERLIQUID_PRIVATE_KEY) {
5136
- env.HYPERLIQUID_PRIVATE_KEY = process.env.HYPERLIQUID_PRIVATE_KEY;
5137
- }
5138
- if (process.env.HYPERLIQUID_ADDRESS) {
5139
- env.HYPERLIQUID_ADDRESS = process.env.HYPERLIQUID_ADDRESS;
5140
- }
5141
- execFile3(
5142
- "node",
5143
- [HL_SCRIPT, command, ...args],
5144
- { env, timeout: 3e4 },
5145
- (error, stdout, stderr) => {
5146
- if (error) {
5147
- const msg = stderr?.trim() || error.message;
5148
- reject(new Error(`HL script failed: ${msg}`));
5149
- return;
5150
- }
5151
- resolve2(stdout.trim());
5152
- }
5153
- );
5154
- });
5155
- }
5156
- function parseOrderResponse(raw) {
5157
- try {
5158
- const data = JSON.parse(raw);
5159
- const statuses = data?.response?.data?.statuses;
5160
- if (!statuses || statuses.length === 0) {
5161
- if (data?.response?.type === "error") {
5162
- return { success: false, error: data.response.data || "Unknown HL error" };
5163
- }
5164
- return { success: false, error: `Unexpected response: ${raw.slice(0, 200)}` };
5165
- }
5166
- const status = statuses[0];
5167
- if (status.filled) {
5168
- return {
5169
- success: true,
5170
- orderId: String(status.filled.oid),
5171
- executedPrice: parseFloat(status.filled.avgPx),
5172
- executedSize: parseFloat(status.filled.totalSz)
5173
- };
5174
- }
5175
- if (status.resting) {
5176
- return {
5177
- success: true,
5178
- orderId: String(status.resting.oid)
5179
- };
5180
- }
5181
- if (status.error) {
5182
- return { success: false, error: status.error };
5183
- }
5184
- return { success: false, error: `Unrecognized status: ${JSON.stringify(status)}` };
5185
- } catch {
5186
- return { success: false, error: `Failed to parse HL response: ${raw.slice(0, 200)}` };
5187
- }
5188
- }
5189
- async function hlMarketBuy(coin, sizeInToken) {
5190
- const raw = await runHLScript("market-buy", [coin, String(sizeInToken)]);
5191
- return parseOrderResponse(raw);
5192
- }
5193
- async function hlMarketSell(coin, sizeInToken) {
5194
- const raw = await runHLScript("market-sell", [coin, String(sizeInToken)]);
5195
- return parseOrderResponse(raw);
5196
- }
5197
- function validateHLEnv() {
5198
- if (!process.env.HYPERLIQUID_PRIVATE_KEY) {
5199
- throw new Error(
5200
- "HYPERLIQUID_PRIVATE_KEY env var is required for hyperliquid-perp mode. Export it before running with --mode hyperliquid-perp."
5201
- );
5202
- }
5203
- }
5204
-
5205
- // src/agent/executor.ts
5206
5100
  var DIRECTIONAL_LEVERAGE = 1;
5207
5101
  function convictionMultiplier(_score) {
5208
5102
  return 1;
@@ -5570,7 +5464,7 @@ var TradeExecutor = class _TradeExecutor {
5570
5464
  // src/agent/portfolio.ts
5571
5465
  import { mkdir as mkdir11, readFile as readFile10, writeFile as writeFile10, rename as rename2 } from "fs/promises";
5572
5466
  import { dirname as dirname3, join as join12 } from "path";
5573
- import { homedir as homedir11 } from "os";
5467
+ import { homedir as homedir10 } from "os";
5574
5468
  import chalk4 from "chalk";
5575
5469
  var MARGIN_FRACTION = 0.33;
5576
5470
  function computeTotalValue(cash, positions) {
@@ -5642,7 +5536,7 @@ var PortfolioTracker = class {
5642
5536
  * overlapping cycles from double-closing positions or double-debiting cash. */
5643
5537
  _lock = Promise.resolve();
5644
5538
  constructor() {
5645
- const base = join12(homedir11(), ".sherwood", "agent");
5539
+ const base = join12(homedir10(), ".sherwood", "agent");
5646
5540
  this.statePath = join12(base, "portfolio.json");
5647
5541
  this.historyPath = join12(base, "trades.json");
5648
5542
  this.state = createDefaultPortfolio();
@@ -5652,8 +5546,8 @@ var PortfolioTracker = class {
5652
5546
  * then `release()` in a finally block. */
5653
5547
  acquireLock() {
5654
5548
  let release;
5655
- const next = new Promise((resolve2) => {
5656
- release = resolve2;
5549
+ const next = new Promise((resolve) => {
5550
+ release = resolve;
5657
5551
  });
5658
5552
  const prev = this._lock;
5659
5553
  this._lock = next;
@@ -6722,7 +6616,7 @@ var Reporter = class {
6722
6616
  // src/agent/price-validator.ts
6723
6617
  import { mkdir as mkdir12, readFile as readFile11, writeFile as writeFile11, rename as rename3 } from "fs/promises";
6724
6618
  import { join as join13 } from "path";
6725
- import { homedir as homedir12 } from "os";
6619
+ import { homedir as homedir11 } from "os";
6726
6620
  var PRICE_FLOOR = 1e-9;
6727
6621
  var MAX_DELTA_PCT = 0.2;
6728
6622
  var STALE_ANCHOR_MS = 2 * 60 * 60 * 1e3;
@@ -6737,7 +6631,7 @@ var PriceValidator = class {
6737
6631
  /** Override Date.now() for tests. */
6738
6632
  clock;
6739
6633
  constructor(opts) {
6740
- this.cacheDir = opts?.cacheDir ?? join13(homedir12(), ".sherwood", "agent", "cache");
6634
+ this.cacheDir = opts?.cacheDir ?? join13(homedir11(), ".sherwood", "agent", "cache");
6741
6635
  this.cacheFile = join13(this.cacheDir, "price-validator.json");
6742
6636
  this.clock = opts?.clock ?? (() => Date.now());
6743
6637
  this.loadPromise = this.load();
@@ -6844,7 +6738,7 @@ var AgentLoop = class {
6844
6738
  /** Start the autonomous loop */
6845
6739
  async start() {
6846
6740
  this.running = true;
6847
- const stateDir = join14(homedir13(), ".sherwood", "agent");
6741
+ const stateDir = join14(homedir12(), ".sherwood", "agent");
6848
6742
  await mkdir13(stateDir, { recursive: true });
6849
6743
  if (this.config.execution.strategyClone && this.config.execution.chain) {
6850
6744
  await this.portfolio.initFromOnChain(
@@ -7064,9 +6958,9 @@ var AgentLoop = class {
7064
6958
  }
7065
6959
  /** Log cycle result to a JSONL file */
7066
6960
  async logCycle(result) {
7067
- const logPath = this.config.logPath ?? join14(homedir13(), ".sherwood", "agent", "cycles.jsonl");
6961
+ const logPath = this.config.logPath ?? join14(homedir12(), ".sherwood", "agent", "cycles.jsonl");
7068
6962
  try {
7069
- await mkdir13(join14(homedir13(), ".sherwood", "agent"), { recursive: true });
6963
+ await mkdir13(join14(homedir12(), ".sherwood", "agent"), { recursive: true });
7070
6964
  await appendFile2(logPath, JSON.stringify(result) + "\n", "utf-8");
7071
6965
  } catch (err) {
7072
6966
  console.error(chalk7.dim(` Failed to write cycle log: ${err.message}`));
@@ -7078,14 +6972,14 @@ var AgentLoop = class {
7078
6972
  }
7079
6973
  /** Sleep that can be interrupted by stop() */
7080
6974
  sleepInterruptible(ms) {
7081
- return new Promise((resolve2) => {
6975
+ return new Promise((resolve) => {
7082
6976
  let resolved = false;
7083
6977
  const done = () => {
7084
6978
  if (resolved) return;
7085
6979
  resolved = true;
7086
6980
  clearTimeout(timer);
7087
6981
  clearInterval(check);
7088
- resolve2();
6982
+ resolve();
7089
6983
  };
7090
6984
  const timer = setTimeout(done, ms);
7091
6985
  const check = setInterval(() => {
@@ -7828,7 +7722,7 @@ var Backtester = class _Backtester {
7828
7722
  // src/agent/calibrator.ts
7829
7723
  import { mkdir as mkdir14, writeFile as writeFile12 } from "fs/promises";
7830
7724
  import { join as join15 } from "path";
7831
- import { homedir as homedir14 } from "os";
7725
+ import { homedir as homedir13 } from "os";
7832
7726
  var WEIGHT_PROFILES = {
7833
7727
  // ── Live production profiles (from scoring.ts; keep in sync) ──
7834
7728
  "default-live": { smartMoney: 0.15, technical: 0.1, sentiment: 0.4, onchain: 0.2, fundamental: 0.1, event: 0.05 },
@@ -8014,10 +7908,10 @@ function configKey(cfg) {
8014
7908
  return `${cfg.profileName}|buy=${cfg.buyThreshold}|sell=${cfg.sellThreshold}`;
8015
7909
  }
8016
7910
  function sleep(ms) {
8017
- return new Promise((resolve2) => setTimeout(resolve2, ms));
7911
+ return new Promise((resolve) => setTimeout(resolve, ms));
8018
7912
  }
8019
7913
  async function saveResults(results) {
8020
- const dir = join15(homedir14(), ".sherwood", "agent");
7914
+ const dir = join15(homedir13(), ".sherwood", "agent");
8021
7915
  await mkdir14(dir, { recursive: true });
8022
7916
  const path = join15(dir, "calibration-results.json");
8023
7917
  const payload = {
@@ -8080,7 +7974,7 @@ function formatCalibrationTable(results, topN = 20) {
8080
7974
  }
8081
7975
  }
8082
7976
  lines.push("");
8083
- const savePath = join15(homedir14(), ".sherwood", "agent", "calibration-results.json");
7977
+ const savePath = join15(homedir13(), ".sherwood", "agent", "calibration-results.json");
8084
7978
  lines.push(` Full results saved to ${savePath}`);
8085
7979
  lines.push("");
8086
7980
  return lines.join("\n");
@@ -8089,7 +7983,7 @@ function formatCalibrationTable(results, topN = 20) {
8089
7983
  // src/agent/replay-calibrator.ts
8090
7984
  import { readFile as readFile12, mkdir as mkdir15, writeFile as writeFile13 } from "fs/promises";
8091
7985
  import { join as join16 } from "path";
8092
- import { homedir as homedir15 } from "os";
7986
+ import { homedir as homedir14 } from "os";
8093
7987
  var STOP_LOSS_PCT = 0.03;
8094
7988
  var TAKE_PROFIT_PCT = 0.06;
8095
7989
  var TRAIL_PCT = 0.025;
@@ -8238,7 +8132,7 @@ function replayToken(tokenRows, config, useRegime) {
8238
8132
  };
8239
8133
  }
8240
8134
  async function runHistoryReplay(options = {}) {
8241
- const historyPath = options.historyPath ?? join16(homedir15(), ".sherwood", "agent", "signal-history.jsonl");
8135
+ const historyPath = options.historyPath ?? join16(homedir14(), ".sherwood", "agent", "signal-history.jsonl");
8242
8136
  const log = options.onProgress ?? (() => {
8243
8137
  });
8244
8138
  const useRegime = options.useRegime ?? true;
@@ -8304,7 +8198,7 @@ async function runHistoryReplay(options = {}) {
8304
8198
  return results;
8305
8199
  }
8306
8200
  async function saveResults2(results) {
8307
- const dir = join16(homedir15(), ".sherwood", "agent");
8201
+ const dir = join16(homedir14(), ".sherwood", "agent");
8308
8202
  await mkdir15(dir, { recursive: true });
8309
8203
  const path = join16(dir, "replay-calibration-results.json");
8310
8204
  const payload = {
@@ -9059,7 +8953,7 @@ function registerAgentCommands(program) {
9059
8953
  const cycle = options.cycle ?? "4h";
9060
8954
  let savedRiskConfig = {};
9061
8955
  try {
9062
- const configPath = join17(homedir16(), ".sherwood", "agent", "config.json");
8956
+ const configPath = join17(homedir15(), ".sherwood", "agent", "config.json");
9063
8957
  const data = await readFile14(configPath, "utf-8");
9064
8958
  const parsed = JSON.parse(data);
9065
8959
  for (const [k, v] of Object.entries(parsed)) {
@@ -9229,7 +9123,7 @@ function registerAgentCommands(program) {
9229
9123
  }
9230
9124
  riskConfig[key] = numVal;
9231
9125
  console.log(chalk9.green(` Set ${key} = ${numVal}`));
9232
- const configDir = join17(homedir16(), ".sherwood", "agent");
9126
+ const configDir = join17(homedir15(), ".sherwood", "agent");
9233
9127
  const configPath = join17(configDir, "config.json");
9234
9128
  let existingConfig = {};
9235
9129
  try {
@@ -9421,7 +9315,7 @@ function registerAgentCommands(program) {
9421
9315
  const dropThreshold = parseFloat(options.dropThreshold ?? "0.1");
9422
9316
  const result = await auditSignalHistory();
9423
9317
  if (options.save) {
9424
- await mkdir16(join17(homedir16(), ".sherwood", "agent"), { recursive: true });
9318
+ await mkdir16(join17(homedir15(), ".sherwood", "agent"), { recursive: true });
9425
9319
  await writeFile14(options.save, JSON.stringify(result, null, 2), "utf-8");
9426
9320
  console.log(chalk9.green(` Saved baseline snapshot to ${options.save}`));
9427
9321
  console.log(chalk9.dim(` ${result.totalEntries} entries, ${result.perSignal.length} signals`));
@@ -9650,4 +9544,4 @@ function formatFearGreed(value) {
9650
9544
  export {
9651
9545
  registerAgentCommands
9652
9546
  };
9653
- //# sourceMappingURL=agent-4HKHLQEJ.js.map
9547
+ //# sourceMappingURL=agent-ZPAZTJG3.js.map