apow-cli 0.11.19 → 0.12.3

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,9 +21,13 @@ body{background:var(--bg);color:var(--text);font-family:SFMono-Regular,'SF Mono'
21
21
  a{color:inherit;text-decoration:none}
22
22
  .container{min-height:100vh;padding:12px}
23
23
  /* Header */
24
- .header{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}
24
+ .header{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px;gap:12px}
25
25
  .header h1{font-size:14px;font-weight:700;letter-spacing:.05em}
26
- .status{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--text-dim)}
26
+ .header-actions{display:flex;align-items:center;gap:10px}
27
+ .refresh-btn{border:1px solid var(--card-border);border-radius:4px;background:var(--card);color:var(--text);font:inherit;font-size:11px;padding:4px 10px;cursor:pointer;transition:all .15s}
28
+ .refresh-btn:hover:not(:disabled){border-color:var(--accent);color:var(--accent)}
29
+ .refresh-btn:disabled{cursor:not-allowed;opacity:.45}
30
+ .status{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--text-dim);white-space:nowrap}
27
31
  .pulse{display:inline-block;height:6px;width:6px;border-radius:50%;background:var(--accent);animation:pulse 1.5s infinite}
28
32
  @keyframes pulse{0%,100%{opacity:1}50%{opacity:.3}}
29
33
  /* Banners */
@@ -32,10 +36,6 @@ a{color:inherit;text-decoration:none}
32
36
  .rpc-warning a:hover{color:#fed7aa}
33
37
  .error-banner{border-radius:6px;border:1px solid #7f1d1d;background:rgba(69,10,10,.3);padding:8px 12px;font-size:12px;color:#f87171;margin-bottom:12px}
34
38
  /* Fleet tabs */
35
- .fleet-tabs{display:flex;align-items:center;gap:4px;margin-bottom:12px;overflow-x:auto}
36
- .fleet-tab{padding:4px 12px;font-size:12px;border-radius:4px;cursor:pointer;white-space:nowrap;border:1px solid transparent;background:var(--card);color:var(--text-dim);transition:all .15s}
37
- .fleet-tab:hover{color:var(--text)}
38
- .fleet-tab.active{background:var(--accent);color:#fff;border-color:var(--accent)}
39
39
  /* Stats grid */
40
40
  .stats-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:1px;background:var(--card-border);border-radius:8px;overflow:hidden;margin-bottom:12px}
41
41
  @media(min-width:640px){.stats-grid{grid-template-columns:repeat(5,1fr)}}
@@ -81,30 +81,30 @@ a{color:inherit;text-decoration:none}
81
81
  <div class="container">
82
82
  <div class="header">
83
83
  <h1>APoW DASHBOARD</h1>
84
- <div class="status"><span class="pulse" id="statusDot"></span><span id="statusText">Loading...</span></div>
84
+ <div class="header-actions">
85
+ <button class="refresh-btn" id="refreshBtn" type="button">Refresh</button>
86
+ <div class="status"><span class="pulse" id="statusDot"></span><span id="statusText">Loading...</span></div>
87
+ </div>
85
88
  </div>
86
89
  <div id="rpcWarning" class="rpc-warning" style="display:none">
87
90
  Set <code>RPC_URL</code> in your <code>.env</code> for reliable dashboard refreshes.
88
- A dedicated Base RPC is recommended for fleets.
91
+ A dedicated Base RPC is recommended.
89
92
  </div>
90
93
  <div id="errorBanner" class="error-banner" style="display:none">Failed to fetch data. Check RPC connection.</div>
91
- <div id="fleetTabs" class="fleet-tabs" style="display:none"></div>
92
94
  <div id="statsGrid" class="stats-grid" style="display:none"></div>
93
95
  <div id="walletGrid" class="wallet-grid"></div>
94
96
  <div id="emptyState" class="empty-state" style="display:none">
95
- <h2>No wallets detected.</h2>
96
- <p>To add wallets:</p>
97
+ <h2>No locally generated APoW wallets.</h2>
98
+ <p>Create one with:</p>
97
99
  <div class="cmds">
98
- <div><code>apow dashboard add &lt;address&gt;</code> <span>— add a specific address</span></div>
99
- <div><code>apow dashboard scan</code> <span>— auto-detect from wallet files in current dir</span></div>
100
+ <div><code>apow wallet new</code></div>
100
101
  </div>
101
- <p class="hint">Wallets are also auto-detected from your .env PRIVATE_KEY on dashboard start.</p>
102
+ <p class="hint">The dashboard intentionally ignores imported wallets and filesystem wallet files.</p>
102
103
  </div>
103
104
  <div id="loading" class="loading">Loading...</div>
104
105
  </div>
105
106
  <script>
106
107
  (function(){
107
- var activeFleet = 'All';
108
108
  var balanceHistory = [];
109
109
  var prevMines = {};
110
110
  var activeWallets = {};
@@ -181,27 +181,6 @@ a{color:inherit;text-decoration:none}
181
181
  }
182
182
  }
183
183
 
184
- function renderFleetTabs(fleets) {
185
- var el = document.getElementById('fleetTabs');
186
- if (!fleets || fleets.length <= 1) { el.style.display = 'none'; return; }
187
- el.style.display = 'flex';
188
- var totalCount = 0;
189
- for (var i = 0; i < fleets.length; i++) totalCount += fleets[i].walletCount;
190
- var html = '<div class="fleet-tab' + (activeFleet === 'All' ? ' active' : '') + '" data-fleet="All">All (' + totalCount + ')</div>';
191
- for (var i = 0; i < fleets.length; i++) {
192
- var f = fleets[i];
193
- html += '<div class="fleet-tab' + (activeFleet === f.name ? ' active' : '') + '" data-fleet="' + escapeHtml(f.name) + '">' + escapeHtml(f.name) + ' (' + f.walletCount + ')</div>';
194
- }
195
- el.innerHTML = html;
196
- var tabs = el.querySelectorAll('.fleet-tab');
197
- for (var t = 0; t < tabs.length; t++) {
198
- tabs[t].addEventListener('click', function() {
199
- activeFleet = this.getAttribute('data-fleet');
200
- refresh();
201
- });
202
- }
203
- }
204
-
205
184
  function renderStats(wallets, network) {
206
185
  var el = document.getElementById('statsGrid');
207
186
  if (!wallets && !network) { el.style.display = 'none'; return; }
@@ -287,23 +266,35 @@ a{color:inherit;text-decoration:none}
287
266
  var networkData = null;
288
267
  var walletsData = null;
289
268
  var hasError = false;
269
+ var isRefreshing = false;
290
270
 
291
271
  function setStatus(refreshing) {
272
+ var btn = document.getElementById('refreshBtn');
292
273
  document.getElementById('statusDot').style.display = refreshing ? 'inline-block' : 'none';
293
- document.getElementById('statusText').textContent = refreshing ? 'Refreshing...' : 'Live';
274
+ document.getElementById('statusText').textContent = refreshing ? 'Refreshing...' : 'Manual';
275
+ if (btn) {
276
+ btn.disabled = refreshing;
277
+ btn.textContent = refreshing ? 'Refreshing...' : 'Refresh';
278
+ }
279
+ }
280
+
281
+ function setReadyStatus() {
282
+ var now = new Date();
283
+ var ts = now.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit', second: '2-digit' });
284
+ document.getElementById('statusText').textContent = 'Updated ' + ts;
294
285
  }
295
286
 
296
287
  function refresh() {
288
+ if (isRefreshing) return;
289
+ isRefreshing = true;
297
290
  setStatus(true);
298
- var fleetParam = encodeURIComponent(activeFleet);
299
291
  Promise.all([
300
292
  fetchJson('/api/network').catch(function(e) { return null; }),
301
- fetchJson('/api/wallets?fleet=' + fleetParam).catch(function(e) { return null; }),
302
- fetchJson('/api/fleets').catch(function(e) { return null; }),
293
+ fetchJson('/api/wallets').catch(function(e) { return null; }),
303
294
  fetchJson('/api/config').catch(function(e) { return null; })
304
295
  ]).then(function(results) {
305
296
  document.getElementById('loading').style.display = 'none';
306
- var net = results[0], wal = results[1], fleets = results[2], cfg = results[3];
297
+ var net = results[0], wal = results[1], cfg = results[2];
307
298
  hasError = !net && !wal;
308
299
  document.getElementById('errorBanner').style.display = hasError ? 'block' : 'none';
309
300
  if (net) networkData = net;
@@ -314,19 +305,21 @@ a{color:inherit;text-decoration:none}
314
305
  if (cfg) {
315
306
  document.getElementById('rpcWarning').style.display = cfg.rpcIsDefault ? 'block' : 'none';
316
307
  }
317
- renderFleetTabs(fleets);
318
308
  renderStats(walletsData, networkData);
319
309
  renderWallets(walletsData);
310
+ isRefreshing = false;
320
311
  setStatus(false);
312
+ setReadyStatus();
321
313
  }).catch(function() {
322
314
  document.getElementById('loading').style.display = 'none';
323
315
  document.getElementById('errorBanner').style.display = 'block';
316
+ isRefreshing = false;
324
317
  setStatus(false);
325
318
  });
326
319
  }
327
320
 
321
+ document.getElementById('refreshBtn').addEventListener('click', refresh);
328
322
  refresh();
329
- setInterval(refresh, 30000);
330
323
  })();
331
324
  </script>
332
325
  </body>
package/dist/dashboard.js CHANGED
@@ -38,13 +38,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.startDashboardServer = startDashboardServer;
40
40
  const http = __importStar(require("node:http"));
41
- const node_fs_1 = require("node:fs");
42
- const node_path_1 = require("node:path");
43
41
  const viem_1 = require("viem");
44
42
  const chains_1 = require("viem/chains");
45
43
  const dashboard_html_1 = require("./dashboard-html");
46
- const x402_1 = require("./x402");
47
44
  const wallet_store_1 = require("./wallet-store");
45
+ const x402_1 = require("./x402");
48
46
  const AgentCoin_json_1 = __importDefault(require("./abi/AgentCoin.json"));
49
47
  const MiningAgent_json_1 = __importDefault(require("./abi/MiningAgent.json"));
50
48
  const AgentCoinAbi = AgentCoin_json_1.default;
@@ -52,127 +50,14 @@ const MiningAgentAbi = MiningAgent_json_1.default;
52
50
  const RARITY_LABELS = ["Common", "Uncommon", "Rare", "Epic", "Mythic"];
53
51
  const ADDR_RE = /^0x[0-9a-fA-F]{40}$/;
54
52
  const DEFAULT_RPC = ""; // No default public RPC — user must set RPC_URL or USE_X402
55
- const FLEETS_PATH = (0, node_path_1.join)(process.env.HOME ?? "", ".apow", "fleets.json");
56
- // --- Wallet / Fleet loading ---
57
- function isAddress(s) {
58
- return ADDR_RE.test(s);
59
- }
60
- function extractArray(path) {
61
- const raw = (0, node_fs_1.readFileSync)(path, "utf8");
62
- const data = JSON.parse(raw);
63
- if (!Array.isArray(data))
64
- return [];
65
- return data.filter((a) => typeof a === "string" && isAddress(a));
66
- }
67
- function extractSolkek(path) {
68
- const raw = (0, node_fs_1.readFileSync)(path, "utf8");
69
- const data = JSON.parse(raw);
70
- const addrs = [];
71
- if (data.master?.address && isAddress(data.master.address)) {
72
- addrs.push(data.master.address);
73
- }
74
- if (Array.isArray(data.miners)) {
75
- for (const m of data.miners) {
76
- if (m.address && isAddress(m.address)) {
77
- addrs.push(m.address);
78
- }
79
- }
80
- }
81
- return addrs;
82
- }
83
- function extractRigdirs(dir) {
84
- const addrs = [];
85
- const entries = (0, node_fs_1.readdirSync)(dir, { withFileTypes: true });
86
- for (const entry of entries) {
87
- if (!entry.isDirectory() || !entry.name.startsWith("rig"))
88
- continue;
89
- const rigFiles = (0, node_fs_1.readdirSync)((0, node_path_1.join)(dir, entry.name));
90
- for (const file of rigFiles) {
91
- const address = (0, wallet_store_1.detectWalletAddressFromFilename)(file);
92
- if (address && isAddress(address)) {
93
- addrs.push(address);
94
- }
95
- }
96
- }
97
- return addrs;
98
- }
99
- function extractWalletfiles(dir) {
100
- const addrs = [];
101
- const files = (0, node_fs_1.readdirSync)(dir);
102
- for (const file of files) {
103
- const address = (0, wallet_store_1.detectWalletAddressFromFilename)(file);
104
- if (address && isAddress(address)) {
105
- addrs.push(address);
106
- }
107
- }
108
- return addrs;
109
- }
110
- function getFleets(walletsPath) {
111
- try {
112
- const raw = (0, node_fs_1.readFileSync)(FLEETS_PATH, "utf8");
113
- const configs = JSON.parse(raw);
114
- return configs.map((cfg) => {
115
- let addresses = [];
116
- try {
117
- switch (cfg.type) {
118
- case "array":
119
- addresses = extractArray(cfg.path);
120
- break;
121
- case "solkek":
122
- addresses = extractSolkek(cfg.path);
123
- break;
124
- case "rigdirs":
125
- addresses = extractRigdirs(cfg.path);
126
- break;
127
- case "walletfiles":
128
- addresses = extractWalletfiles(cfg.path);
129
- break;
130
- }
131
- }
132
- catch {
133
- // Skip broken fleet sources silently
134
- }
135
- return { name: cfg.name, addresses };
136
- });
137
- }
138
- catch {
139
- return [{ name: "Main", addresses: getWalletAddresses(walletsPath) }];
140
- }
141
- }
142
- function getWalletAddresses(walletsPath) {
143
- try {
144
- const raw = (0, node_fs_1.readFileSync)(walletsPath, "utf8");
145
- const data = JSON.parse(raw);
146
- if (Array.isArray(data)) {
147
- return data.filter((addr) => typeof addr === "string" && ADDR_RE.test(addr));
148
- }
149
- return [];
150
- }
151
- catch {
152
- return [];
153
- }
53
+ // --- Wallet loading ---
54
+ function normalizeAddress(s) {
55
+ if (!ADDR_RE.test(s))
56
+ return null;
57
+ return (0, viem_1.getAddress)(s.toLowerCase());
154
58
  }
155
- function getAddressesForFleet(fleetName, walletsPath) {
156
- if (!fleetName || fleetName === "All") {
157
- const fleets = getFleets(walletsPath);
158
- const seen = new Set();
159
- const all = [];
160
- for (const f of fleets) {
161
- for (const addr of f.addresses) {
162
- const lower = addr.toLowerCase();
163
- if (!seen.has(lower)) {
164
- seen.add(lower);
165
- all.push(addr);
166
- }
167
- }
168
- }
169
- return all;
170
- }
171
- const fleets = getFleets(walletsPath);
172
- const fleet = fleets.find((f) => f.name === fleetName);
173
- if (fleet)
174
- return fleet.addresses;
175
- return getWalletAddresses(walletsPath);
59
+ function getWalletAddresses() {
60
+ return (0, wallet_store_1.loadGeneratedWalletAddresses)().flatMap((address) => normalizeAddress(address) ?? []);
176
61
  }
177
62
  // --- Art parsing ---
178
63
  function parseArtFromTokenUri(raw) {
@@ -188,9 +73,9 @@ function parseArtFromTokenUri(raw) {
188
73
  }
189
74
  // --- Server ---
190
75
  function startDashboardServer(opts) {
191
- const { port, walletsPath, rpcUrl, useX402, privateKey, miningAgentAddress, agentCoinAddress } = opts;
192
- const transport = useX402 && privateKey
193
- ? (0, x402_1.createX402Transport)(privateKey)
76
+ const { port, rpcUrl, useX402, signer, miningAgentAddress, agentCoinAddress } = opts;
77
+ const transport = useX402 && signer
78
+ ? (0, x402_1.createX402Transport)(signer)
194
79
  : (0, viem_1.http)(rpcUrl);
195
80
  const publicClient = (0, viem_1.createPublicClient)({
196
81
  chain: chains_1.base,
@@ -198,16 +83,16 @@ function startDashboardServer(opts) {
198
83
  });
199
84
  const artCache = new Map();
200
85
  const htmlPage = (0, dashboard_html_1.getDashboardHtml)();
201
- // Response cache with TTL — always serve cached data, refresh in background
86
+ // Response cache with TTL. Manual refreshes wait for fresh stale data instead of
87
+ // returning old values and silently updating after the UI has already rendered.
202
88
  const responseCache = new Map();
203
89
  const pendingFetches = new Map();
204
- const CACHE_TTL = 25_000; // 25s — slightly less than client's 30s poll
90
+ const CACHE_TTL = 25_000;
205
91
  async function cachedHandler(key, handler) {
206
92
  const cached = responseCache.get(key);
207
93
  const now = Date.now();
208
94
  const isStale = !cached || (now - cached.ts > CACHE_TTL);
209
95
  if (isStale && !pendingFetches.has(key)) {
210
- // Fetch fresh data (non-blocking if we have stale data to return)
211
96
  const fetchPromise = handler()
212
97
  .then((result) => {
213
98
  responseCache.set(key, { data: result, ts: Date.now() });
@@ -221,15 +106,12 @@ function startDashboardServer(opts) {
221
106
  throw err;
222
107
  });
223
108
  pendingFetches.set(key, fetchPromise);
224
- // No cached data yet — must wait for first fetch
225
- if (!cached)
226
- return fetchPromise;
227
109
  }
228
- // If we have a pending fetch and no cache, wait for it
229
- if (!cached && pendingFetches.has(key)) {
110
+ // Stale manual refreshes should wait for the in-flight read so the button
111
+ // actually returns current balances.
112
+ if (isStale && pendingFetches.has(key)) {
230
113
  return pendingFetches.get(key);
231
114
  }
232
- // Return cached data immediately (even if stale — background refresh handles it)
233
115
  return cached ? cached.data : "{}";
234
116
  }
235
117
  const MULTICALL_CHUNK = 30; // max calls per multicall batch
@@ -252,8 +134,8 @@ function startDashboardServer(opts) {
252
134
  }
253
135
  return results;
254
136
  }
255
- async function handleWallets(fleetParam) {
256
- const addresses = getAddressesForFleet(fleetParam, walletsPath);
137
+ async function handleWallets() {
138
+ const addresses = getWalletAddresses();
257
139
  if (addresses.length === 0)
258
140
  return "[]";
259
141
  // Phase 1: ETH balance + AGENT balance + NFT count (chunked)
@@ -423,13 +305,9 @@ function startDashboardServer(opts) {
423
305
  supplyPct,
424
306
  });
425
307
  }
426
- function handleFleets() {
427
- const fleets = getFleets(walletsPath);
428
- return JSON.stringify(fleets.map((f) => ({ name: f.name, walletCount: f.addresses.length })));
429
- }
430
308
  function handleConfig() {
431
309
  const rpcIsDefault = !useX402 && rpcUrl === DEFAULT_RPC;
432
- const walletCount = getWalletAddresses(walletsPath).length;
310
+ const walletCount = getWalletAddresses().length;
433
311
  return JSON.stringify({ rpcIsDefault, walletCount });
434
312
  }
435
313
  function jsonResponse(res, body, status = 200) {
@@ -449,9 +327,7 @@ function startDashboardServer(opts) {
449
327
  return;
450
328
  }
451
329
  if (pathname === "/api/wallets") {
452
- const fleet = url.searchParams.get("fleet");
453
- const cacheKey = `wallets:${fleet ?? "All"}`;
454
- const body = await cachedHandler(cacheKey, () => handleWallets(fleet));
330
+ const body = await cachedHandler("wallets", () => handleWallets());
455
331
  jsonResponse(res, body);
456
332
  return;
457
333
  }
@@ -460,11 +336,6 @@ function startDashboardServer(opts) {
460
336
  jsonResponse(res, body);
461
337
  return;
462
338
  }
463
- if (pathname === "/api/fleets") {
464
- const body = handleFleets();
465
- jsonResponse(res, body);
466
- return;
467
- }
468
339
  if (pathname === "/api/config") {
469
340
  const body = handleConfig();
470
341
  jsonResponse(res, body);
@@ -478,6 +349,6 @@ function startDashboardServer(opts) {
478
349
  errorResponse(res, message);
479
350
  }
480
351
  });
481
- server.listen(port);
352
+ server.listen(port, "127.0.0.1");
482
353
  return server;
483
354
  }
package/dist/errors.js CHANGED
@@ -1,7 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.redactUrls = redactUrls;
4
+ exports.errorText = errorText;
3
5
  exports.classifyError = classifyError;
4
6
  const patterns = [
7
+ {
8
+ test: (m) => m.includes("payment outcome is unknown"),
9
+ classify: (msg) => ({ category: "fatal", userMessage: msg, recovery: "Check the service job/payment result before manually resuming. Do not repeat an unknown paid request." }),
10
+ },
11
+ {
12
+ test: (m) => m.includes("Policy denied:"),
13
+ classify: (msg) => ({
14
+ category: "setup",
15
+ userMessage: msg,
16
+ recovery: "Review `apow policy show` and the requested operation. Keep policy enforcement enabled.",
17
+ }),
18
+ },
5
19
  {
6
20
  test: (m) => m.includes("Not your miner"),
7
21
  classify: () => ({
@@ -153,7 +167,7 @@ const patterns = [
153
167
  test: (m) => m.includes("EADDRINUSE") && m.includes("8402"),
154
168
  classify: () => ({
155
169
  category: "setup",
156
- userMessage: "ClawRouter proxy port 8402 is already in use",
170
+ userMessage: "The local x402 LLM service port 8402 is already in use",
157
171
  recovery: "Set CLAWROUTER_PORT in .env to use a different port",
158
172
  }),
159
173
  },
@@ -161,7 +175,7 @@ const patterns = [
161
175
  test: (m) => m.toLowerCase().includes("insufficient") && m.toLowerCase().includes("clawrouter"),
162
176
  classify: () => ({
163
177
  category: "setup",
164
- userMessage: "Insufficient USDC for ClawRouter x402 LLM payment",
178
+ userMessage: "Insufficient USDC for the x402 LLM payment",
165
179
  recovery: "Send USDC to your wallet on Base",
166
180
  }),
167
181
  },
@@ -214,8 +228,17 @@ const patterns = [
214
228
  }),
215
229
  },
216
230
  ];
231
+ // Keyed RPC endpoints embed credentials in the URL path. Keep scheme+host so
232
+ // errors stay debuggable, drop everything after — terminal output may be
233
+ // public (streams, logs, screenshots).
234
+ function redactUrls(text) {
235
+ return text.replace(/(https?:\/\/[^/\s"']+)[^\s"')]*/g, "$1/…");
236
+ }
237
+ function errorText(error) {
238
+ return redactUrls(error instanceof Error ? error.message : String(error));
239
+ }
217
240
  function classifyError(error) {
218
- const message = error instanceof Error ? error.message : String(error);
241
+ const message = errorText(error);
219
242
  for (const pattern of patterns) {
220
243
  if (pattern.test(message)) {
221
244
  return pattern.classify(message);