apow-cli 0.11.4 → 0.11.6

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.
package/.env.example CHANGED
@@ -11,7 +11,7 @@ ALLOW_LOCAL_FALLBACK_WITH_X402=false
11
11
  # RPC_URL=https://base-mainnet.g.alchemy.com/v2/YOUR_KEY
12
12
  # USE_X402=false
13
13
 
14
- # LLM Provider (clawrouter / openai / anthropic / gemini / ollama / claude-code / codex)
14
+ # LLM Provider (clawrouter / openai / anthropic / gemini / deepseek / qwen / ollama / claude-code / codex)
15
15
  # Default: clawrouter when USE_X402=true, openai otherwise
16
16
  # LLM_PROVIDER=clawrouter
17
17
  # LLM_MODEL=blockrun/eco
@@ -42,9 +42,9 @@ ALLOW_LOCAL_FALLBACK_WITH_X402=false
42
42
  # GPU Mining (optional — auto-detected, massive speed boost)
43
43
  # Run `apow build-grinders` to compile native binaries automatically.
44
44
  # GRINDER_MODE=auto # auto (default) or js (force JS-only)
45
- # GPU_GRINDER_PATH=./gpu/grinder-gpu # Metal binary (macOS, auto-detected)
46
- # CUDA_GRINDER_PATH=~/.apow/grinder-cuda # CUDA binary (NVIDIA GPU, auto-detected)
47
- # CPU_GRINDER_PATH=./gpu/grinder-cpu # C binary (any platform, auto-detected)
45
+ # GPU_GRINDER_PATH=local/gpu/grinder-gpu # Metal binary (macOS, source install)
46
+ # CUDA_GRINDER_PATH=~/.apow/grinder-cuda # CUDA binary (NVIDIA GPU, after build-grinders)
47
+ # CPU_GRINDER_PATH=local/gpu/grinder-cpu # C binary (any platform, source install)
48
48
  # CPU_THREADS=16 # Threads for CPU-C grinder (default: all cores)
49
49
  # Remote GPU via Vast.ai (see: local/vast-setup.sh)
50
50
  # VAST_IP= # Remote GPU host IP
package/README.md CHANGED
@@ -8,6 +8,9 @@ Mining client for the [APoW (Agentic Proof of Work)](https://github.com/Agentosh
8
8
  - `Easy Mode`: no config, x402 for RPC + LLM + GPU grinding
9
9
  - `Advanced Mode`: choose which credentials you supply and which services stay autonomous
10
10
 
11
+ `apow start` is the fastest path when you want the full flow in one command:
12
+ setup, funding checks, minting, and mining.
13
+
11
14
  ## Install
12
15
 
13
16
  ```bash
@@ -32,20 +35,10 @@ npx apow-cli
32
35
  ## For AI Agents
33
36
 
34
37
  Any AI agent can go from zero to actively mining with no human interaction except funding the wallet.
38
+ If the wallet is already configured, `apow start` skips ahead automatically.
35
39
 
36
40
  ```bash
37
- # 1. Run setup and choose Easy Mode
38
- npx apow-cli setup
39
-
40
- # 2. Fund the wallet (bridge from any chain, auto-splits into ETH + USDC)
41
- npx apow-cli fund --chain solana --token sol # bridge SOL → ETH+USDC on Base
42
- # Or send ETH/USDC on Base directly
43
-
44
- # 3. Mint a mining rig NFT (proves AI via LLM, one-time)
45
- npx apow-cli mint
46
-
47
- # 4. Start mining (Easy Mode uses remote x402 GPU by default)
48
- npx apow-cli mine
41
+ npx apow-cli start
49
42
  ```
50
43
 
51
44
  Easy Mode writes an `.env` equivalent to:
@@ -78,35 +71,28 @@ Each wallet gets one rig, each rig mines independently. More wallets = more chan
78
71
  If you prefer to do it yourself:
79
72
 
80
73
  ```bash
81
- # 1. Interactive setup: wallet, RPC, LLM config
82
- npx apow-cli setup
83
-
84
- # 2. Fund your wallet (bridge from Solana/Ethereum or send ETH directly)
85
- npx apow-cli fund
86
-
87
- # 3. Mint a mining rig NFT
88
- npx apow-cli mint
89
-
90
- # 4. Start mining
91
- npx apow-cli mine
74
+ npx apow-cli start # guided happy path: setup -> fund -> mint -> mine
92
75
  ```
93
76
 
77
+ If you want to control each step manually, the older `setup -> fund -> mint -> mine` flow is still supported below.
78
+
94
79
  ## Commands
95
80
 
96
81
  | Command | Description |
97
82
  |---------|-------------|
83
+ | `apow start` | Guided happy path: setup -> fund -> mint -> mine |
98
84
  | `apow setup` | Agent-first setup wizard: Easy Mode (x402 everywhere) or Advanced Mode |
99
85
  | `apow fund` | Fund your wallet: bridge from Solana/Ethereum or send on Base, auto-split ETH+USDC |
100
- | `apow wallet new` | Generate a new mining wallet |
86
+ | `apow wallet new` | Generate a new mining wallet, plus optional encrypted JSON keystore backup |
101
87
  | `apow wallet show` | Show configured wallet address |
102
- | `apow wallet export` | Export your wallet's private key |
88
+ | `apow wallet export` | Export your wallet's private key and optional backups |
103
89
  | `apow wallet fund <addr> [eth]` | Send ETH to another address (default: mint price + gas) |
104
90
  | `apow mint` | Mint a MiningAgent NFT (one per wallet) |
105
91
  | `apow mine [tokenId]` | Mine $AGENT with your NFT (auto-detects best rig) |
106
92
  | `apow stats [tokenId]` | View mining stats, earnings, difficulty |
107
93
  | `apow dashboard start` | Launch multi-wallet mining dashboard |
108
94
  | `apow dashboard add <addr>` | Add a wallet to the dashboard |
109
- | `apow dashboard scan [dir]` | Auto-detect wallet files in a directory |
95
+ | `apow dashboard scan [dir]` | Auto-detect `wallet-0x*.txt` and `wallet-0x*.json` files in a directory |
110
96
 
111
97
  ## Configuration
112
98
 
@@ -114,13 +100,14 @@ Create a `.env` file or use `apow setup`:
114
100
 
115
101
  ```bash
116
102
  PRIVATE_KEY=0x... # Your wallet private key
117
- USE_X402=true # Auto-pay RPC + LLM via x402 ($10 USDC for ~1M calls, zero API keys)
103
+ USE_X402=true # Auto-pay RPC + LLM via x402 (2.00 USDC minimum starting balance, zero API keys)
118
104
  USE_X402_GRIND=true # Auto-pay remote GPU grinding via x402
119
105
  ALLOW_LOCAL_FALLBACK_WITH_X402=false # Easy Mode default: do not burn local CPU while x402 GPU is active
120
106
  # RPC_URL=https://... # Or: bring your own RPC (free from Alchemy, QuickNode, etc.)
121
107
  # LLM_PROVIDER=clawrouter # clawrouter (auto with x402) | openai | gemini | deepseek | qwen | anthropic | ollama (for minting)
122
108
  # LLM_MODEL=blockrun/eco # Auto-detected per provider; override only if needed
123
109
  # LLM_API_KEY=sk-... # Not needed with clawrouter/ollama; required for openai/gemini/etc.
110
+ # KEYSTORE_PASSWORD=... # Optional: create encrypted wallet JSON backups during wallet new/export
124
111
  # Bridging (only for `apow fund`)
125
112
  # SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
126
113
  # ETHEREUM_RPC_URL=https://cloudflare-eth.com
@@ -148,7 +135,7 @@ An LLM is required to mint your Mining Rig NFT (one-time identity verification).
148
135
 
149
136
  ## Funding (v0.7.0+)
150
137
 
151
- Mining requires two assets on Base: **ETH** (gas) and **USDC** (x402 RPC). The `fund` command bridges from Solana or Ethereum, or accepts deposits on Base, and auto-splits into both:
138
+ Mining requires two assets on Base: **ETH** (gas) and **USDC** (x402 RPC). `apow start` checks both and can auto-split the wallet into the right mix. The `fund` command also bridges from Solana or Ethereum, or accepts deposits on Base, and auto-splits into both:
152
139
 
153
140
  ```bash
154
141
  # From Solana (deposit address — send from any wallet, QR code included)
@@ -168,7 +155,7 @@ apow fund --chain base --no-swap
168
155
 
169
156
  **Solana/Ethereum bridging:** Uses [Squid Router](https://squidrouter.com/) (Chainflip). Generates a one-time deposit address with QR code — send from any wallet. Requires `SQUID_INTEGRATOR_ID` in `.env` (free at [squidrouter.com](https://app.squidrouter.com/)).
170
157
 
171
- **Auto-split targets:** 0.003 ETH (gas for ~100 mine txns) + 2.00 USDC (~100K x402 RPC calls). If both are already met, the CLI skips the swap.
158
+ **Auto-split targets:** 0.003 ETH (gas for ~100 mine txns) + 2.00 USDC (minimum x402 starting balance). If both are already met, the CLI skips the swap.
172
159
 
173
160
  ## x402 GPU Grinding
174
161
 
@@ -233,7 +220,7 @@ Monitor your entire mining fleet from a single web UI. Zero external dependencie
233
220
 
234
221
  ```bash
235
222
  # Quick start: scan wallet files and launch
236
- apow dashboard scan . # detect wallet-0x*.txt files in current directory
223
+ apow dashboard scan . # detect wallet-0x*.txt / .json files in current directory
237
224
  apow dashboard start # open dashboard at http://localhost:3847
238
225
  ```
239
226
 
@@ -244,7 +231,7 @@ apow dashboard start # open dashboard at http://localhost:3847
244
231
  | `apow dashboard start` | Launch dashboard web UI (default port 3847) |
245
232
  | `apow dashboard add <addr>` | Add a wallet address to monitor |
246
233
  | `apow dashboard remove <addr>` | Remove a wallet from monitoring |
247
- | `apow dashboard scan [dir]` | Auto-detect wallets from `wallet-0x*.txt` files |
234
+ | `apow dashboard scan [dir]` | Auto-detect wallets from `wallet-0x*.txt` and `wallet-0x*.json` files |
248
235
  | `apow dashboard wallets` | List all monitored wallets |
249
236
 
250
237
  ### Fleet Configuration
@@ -259,7 +246,7 @@ Wallets are stored in `~/.apow/wallets.json` (plain JSON array of addresses). Fo
259
246
  ]
260
247
  ```
261
248
 
262
- Fleet types: `array` (JSON array of addresses), `solkek` (master/miners JSON), `rigdirs` (scan `rig*/wallet-0x*.txt`), `walletfiles` (scan `wallet-0x*.txt`).
249
+ Fleet types: `array` (JSON array of addresses), `solkek` (master/miners JSON), `rigdirs` (scan `rig*/wallet-0x*.txt` / `.json`), `walletfiles` (scan `wallet-0x*.txt` / `.json`).
263
250
 
264
251
  ## Protocol
265
252
 
package/dist/config.js CHANGED
@@ -11,11 +11,12 @@ exports.requireLlmApiKey = requireLlmApiKey;
11
11
  exports.isExpensiveModel = isExpensiveModel;
12
12
  exports.writeEnvFile = writeEnvFile;
13
13
  const dotenv_1 = require("dotenv");
14
+ const node_fs_1 = require("node:fs");
14
15
  const promises_1 = require("node:fs/promises");
15
16
  const node_os_1 = __importDefault(require("node:os"));
16
17
  const node_path_1 = require("node:path");
17
18
  const chains_1 = require("viem/chains");
18
- (0, dotenv_1.config)();
19
+ (0, dotenv_1.config)({ quiet: true });
19
20
  const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
20
21
  const DEFAULT_OLLAMA_URL = "http://127.0.0.1:11434";
21
22
  const DEFAULT_CHAIN_NAME = "base";
@@ -157,10 +158,32 @@ function isExpensiveModel(model) {
157
158
  return EXPENSIVE_MODELS.some((e) => m.startsWith(e));
158
159
  }
159
160
  async function writeEnvFile(values) {
160
- const lines = Object.entries(values)
161
- .map(([key, value]) => `${key}=${value}`)
162
- .join("\n");
163
- await (0, promises_1.writeFile)((0, node_path_1.join)(process.cwd(), ".env"), lines + "\n", "utf8");
161
+ const envPath = (0, node_path_1.join)(process.cwd(), ".env");
162
+ const preserved = [];
163
+ if ((0, node_fs_1.existsSync)(envPath)) {
164
+ const existingContent = await (0, promises_1.readFile)(envPath, "utf8").catch(() => "");
165
+ const seenKeys = new Set(Object.keys(values));
166
+ for (const line of existingContent.split(/\r?\n/)) {
167
+ const trimmed = line.trim();
168
+ if (!trimmed || trimmed.startsWith("#")) {
169
+ continue;
170
+ }
171
+ const eq = line.indexOf("=");
172
+ if (eq === -1) {
173
+ preserved.push(line);
174
+ continue;
175
+ }
176
+ const key = line.slice(0, eq).trim();
177
+ if (!seenKeys.has(key)) {
178
+ preserved.push(line);
179
+ }
180
+ }
181
+ }
182
+ const lines = [
183
+ ...preserved,
184
+ ...Object.entries(values).map(([key, value]) => `${key}=${value}`),
185
+ ].join("\n");
186
+ await (0, promises_1.writeFile)(envPath, lines + "\n", "utf8");
164
187
  for (const [key, value] of Object.entries(values)) {
165
188
  process.env[key] = value;
166
189
  }
@@ -84,8 +84,8 @@ a{color:inherit;text-decoration:none}
84
84
  <div class="status"><span class="pulse" id="statusDot"></span><span id="statusText">Loading...</span></div>
85
85
  </div>
86
86
  <div id="rpcWarning" class="rpc-warning" style="display:none">
87
- Using public Base RPC (mainnet.base.org) — this is unreliable for dashboards with many wallets.
88
- Get a free dedicated endpoint at <a href="https://www.alchemy.com/base" target="_blank" rel="noopener noreferrer">alchemy.com</a> for reliable data.
87
+ Set <code>RPC_URL</code> in your <code>.env</code> for reliable dashboard refreshes.
88
+ A dedicated Base RPC is recommended for fleets.
89
89
  </div>
90
90
  <div id="errorBanner" class="error-banner" style="display:none">Failed to fetch data. Check RPC connection.</div>
91
91
  <div id="fleetTabs" class="fleet-tabs" style="display:none"></div>
package/dist/dashboard.js CHANGED
@@ -44,6 +44,7 @@ const viem_1 = require("viem");
44
44
  const chains_1 = require("viem/chains");
45
45
  const dashboard_html_1 = require("./dashboard-html");
46
46
  const x402_1 = require("./x402");
47
+ const wallet_store_1 = require("./wallet-store");
47
48
  const AgentCoin_json_1 = __importDefault(require("./abi/AgentCoin.json"));
48
49
  const MiningAgent_json_1 = __importDefault(require("./abi/MiningAgent.json"));
49
50
  const AgentCoinAbi = AgentCoin_json_1.default;
@@ -87,9 +88,9 @@ function extractRigdirs(dir) {
87
88
  continue;
88
89
  const rigFiles = (0, node_fs_1.readdirSync)((0, node_path_1.join)(dir, entry.name));
89
90
  for (const file of rigFiles) {
90
- const match = file.match(/^wallet-(0x[0-9a-fA-F]{40})\.txt$/);
91
- if (match && isAddress(match[1])) {
92
- addrs.push(match[1]);
91
+ const address = (0, wallet_store_1.detectWalletAddressFromFilename)(file);
92
+ if (address && isAddress(address)) {
93
+ addrs.push(address);
93
94
  }
94
95
  }
95
96
  }
@@ -99,9 +100,9 @@ function extractWalletfiles(dir) {
99
100
  const addrs = [];
100
101
  const files = (0, node_fs_1.readdirSync)(dir);
101
102
  for (const file of files) {
102
- const match = file.match(/^wallet-(0x[0-9a-fA-F]{40})\.txt$/);
103
- if (match && isAddress(match[1])) {
104
- addrs.push(match[1]);
103
+ const address = (0, wallet_store_1.detectWalletAddressFromFilename)(file);
104
+ if (address && isAddress(address)) {
105
+ addrs.push(address);
105
106
  }
106
107
  }
107
108
  return addrs;
package/dist/detect.js CHANGED
@@ -23,14 +23,14 @@ async function detectMinersWithClient(client, owner) {
23
23
  if (balance === 0n) {
24
24
  return [];
25
25
  }
26
- const miners = [];
27
- for (let i = 0n; i < balance; i++) {
28
- const tokenId = (await client.readContract({
29
- address: config_1.config.miningAgentAddress,
30
- abi: miningAgentAbi,
31
- functionName: "tokenOfOwnerByIndex",
32
- args: [owner, i],
33
- }));
26
+ const indexes = Array.from({ length: Number(balance) }, (_, i) => BigInt(i));
27
+ const tokenIds = await Promise.all(indexes.map((index) => client.readContract({
28
+ address: config_1.config.miningAgentAddress,
29
+ abi: miningAgentAbi,
30
+ functionName: "tokenOfOwnerByIndex",
31
+ args: [owner, index],
32
+ })));
33
+ const miners = await Promise.all(tokenIds.map(async (tokenId) => {
34
34
  const [rarityRaw, hashpowerRaw] = await Promise.all([
35
35
  client.readContract({
36
36
  address: config_1.config.miningAgentAddress,
@@ -46,13 +46,13 @@ async function detectMinersWithClient(client, owner) {
46
46
  }),
47
47
  ]);
48
48
  const rarity = Number(rarityRaw);
49
- miners.push({
49
+ return {
50
50
  tokenId,
51
51
  rarity,
52
52
  rarityLabel: exports.rarityLabels[rarity] ?? `Tier ${rarity}`,
53
53
  hashpower: Number(hashpowerRaw),
54
- });
55
- }
54
+ };
55
+ }));
56
56
  return miners;
57
57
  }
58
58
  async function detectMiners(owner) {
package/dist/errors.js CHANGED
@@ -106,15 +106,15 @@ const patterns = [
106
106
  classify: () => ({
107
107
  category: "transient",
108
108
  userMessage: "QuickNode x402 credit purchase failed — check USDC balance on Base",
109
- recovery: "Send USDC to your wallet on Base (~$10 for ~1M RPC calls), or set RPC_URL in .env to use a custom RPC",
109
+ recovery: "Send at least 2.00 USDC to your wallet on Base for x402 starting balance, or set RPC_URL in .env to use a custom RPC",
110
110
  }),
111
111
  },
112
112
  {
113
- test: (m) => m.toLowerCase().includes("insufficient funds"),
113
+ test: (m) => m.includes("Not enough ETH for gas") || m.toLowerCase().includes("insufficient funds"),
114
114
  classify: () => ({
115
115
  category: "setup",
116
116
  userMessage: "Not enough ETH for gas",
117
- recovery: "Send ETH to your wallet on Base",
117
+ recovery: "Send ETH to your wallet on Base, or run `apow fund` to top up gas before mining again",
118
118
  }),
119
119
  },
120
120
  {
@@ -153,8 +153,16 @@ const patterns = [
153
153
  test: (m) => m.includes("Remote GPU grind timed out") || (m.includes("GrindProxy") && /\b504\b/.test(m)),
154
154
  classify: () => ({
155
155
  category: "transient",
156
- userMessage: "Remote GPU grind timed out (120s)",
157
- recovery: "High difficulty — local grinders may still find a nonce.",
156
+ userMessage: "Remote GPU grind timed out",
157
+ recovery: "Retrying with a fresh remote grind request...",
158
+ }),
159
+ },
160
+ {
161
+ test: (m) => m.includes("Remote GPU grind request failed"),
162
+ classify: () => ({
163
+ category: "transient",
164
+ userMessage: "Remote GPU grind request failed",
165
+ recovery: "Retrying with a fresh remote grind request...",
158
166
  }),
159
167
  },
160
168
  {
package/dist/fund.js CHANGED
@@ -177,7 +177,7 @@ async function showFinalBalances() {
177
177
  const ethBal = Number((0, viem_1.formatEther)(await (0, wallet_1.getEthBalance)()));
178
178
  const usdcBal = Number((0, viem_1.formatUnits)(await (0, uniswap_1.getUsdcBalance)(wallet_1.account.address), 6));
179
179
  console.log("");
180
- console.log(` ${ui.green("Ready to mine!")}`);
180
+ console.log(` ${ui.green("Ready to mint!")}`);
181
181
  ui.table([
182
182
  ["ETH", `${ethBal.toFixed(6)} ETH (gas)`],
183
183
  ["USDC", `${usdcBal.toFixed(2)} USDC (x402 RPC)`],
@@ -506,9 +506,12 @@ async function runFundFlow(options) {
506
506
  console.log("");
507
507
  // Already funded?
508
508
  if (ethBalance >= constants_1.MIN_ETH && usdcBalance >= constants_1.MIN_USDC) {
509
- console.log(` ${ui.green("Already funded! Ready to mine.")}`);
509
+ console.log(` ${ui.green("Already funded! Ready to mint.")}`);
510
510
  console.log(` Next: ${ui.cyan("apow mint")}`);
511
511
  console.log("");
512
+ if (!ui.isInteractiveSession()) {
513
+ return;
514
+ }
512
515
  // Allow explicit re-run if user wants to add more
513
516
  const addMore = await ui.confirm("Add more funds?");
514
517
  if (!addMore)
@@ -50,6 +50,7 @@ exports.getGrindUrl = getGrindUrl;
50
50
  exports.grindNonceHttp = grindNonceHttp;
51
51
  const config_1 = require("./config");
52
52
  const DEFAULT_GRIND_URL = "https://grind.apow.io/grind";
53
+ const GRIND_HTTP_TIMEOUT_MS = 20_000;
53
54
  // Lazy singleton — created on first grind, reused across calls
54
55
  let _fetchWithPayment = null;
55
56
  function resetPaymentFetch() {
@@ -92,6 +93,8 @@ function getGrindUrl() {
92
93
  }
93
94
  async function grindNonceHttp(challengeNumber, target, minerAddress, grindUrl, privateKey, signal) {
94
95
  const start = process.hrtime();
96
+ const timeoutSignal = AbortSignal.timeout(GRIND_HTTP_TIMEOUT_MS);
97
+ const requestSignal = signal ? AbortSignal.any([signal, timeoutSignal]) : timeoutSignal;
95
98
  const requestInit = {
96
99
  method: "POST",
97
100
  headers: { "Content-Type": "application/json" },
@@ -100,12 +103,28 @@ async function grindNonceHttp(challengeNumber, target, minerAddress, grindUrl, p
100
103
  target: target.toString(),
101
104
  address: minerAddress,
102
105
  }),
103
- signal,
106
+ signal: requestSignal,
104
107
  };
105
108
  let response = null;
106
109
  for (let attempt = 1; attempt <= 2; attempt += 1) {
107
110
  const paidFetch = await getPaymentFetch(privateKey);
108
- response = await paidFetch(grindUrl, requestInit);
111
+ try {
112
+ response = await paidFetch(grindUrl, requestInit);
113
+ }
114
+ catch (err) {
115
+ if (signal?.aborted) {
116
+ throw err;
117
+ }
118
+ if (timeoutSignal.aborted) {
119
+ resetPaymentFetch();
120
+ throw new Error(`Remote GPU grind timed out (${GRIND_HTTP_TIMEOUT_MS / 1000}s)`);
121
+ }
122
+ resetPaymentFetch();
123
+ if (attempt === 1) {
124
+ continue;
125
+ }
126
+ throw new Error(`Remote GPU grind request failed: ${err instanceof Error ? err.message : String(err)}`);
127
+ }
109
128
  if (response.ok) {
110
129
  break;
111
130
  }
@@ -121,23 +140,28 @@ async function grindNonceHttp(challengeNumber, target, minerAddress, grindUrl, p
121
140
  catch { /* ignore decode errors */ }
122
141
  }
123
142
  const combinedError = `${reason} ${bodyDetail}`.trim();
124
- if (attempt === 1 && combinedError.includes("No matching payment requirements")) {
143
+ const stalePaymentSession = /No matching payment requirements|facilitator|payment session|authorization/i.test(combinedError);
144
+ if (attempt === 1 && (stalePaymentSession || response.status >= 500)) {
125
145
  resetPaymentFetch();
126
146
  continue;
127
147
  }
128
148
  if (response.status === 402) {
149
+ resetPaymentFetch();
129
150
  if (reason.includes("insufficient_balance")) {
130
151
  throw new Error("x402 GPU payment failed: insufficient USDC balance");
131
152
  }
132
153
  else if (reason.includes("simulation_failed")) {
133
154
  throw new Error(`x402 GPU payment failed: EVM simulation failed (USDC approval issue?) [${reason}]`);
134
155
  }
156
+ else if (attempt === 1) {
157
+ continue;
158
+ }
135
159
  else {
136
160
  throw new Error(`x402 GPU payment failed: ${reason || bodyDetail.slice(0, 200) || "unknown"}`);
137
161
  }
138
162
  }
139
163
  if (response.status === 504) {
140
- throw new Error("Remote GPU grind timed out (120s)");
164
+ throw new Error(`Remote GPU grind timed out (${GRIND_HTTP_TIMEOUT_MS / 1000}s)`);
141
165
  }
142
166
  throw new Error(`GrindProxy HTTP ${response.status}: ${(bodyDetail || body).slice(0, 200)}`);
143
167
  }