stuntman 0.2.2 → 0.2.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.
package/README.md CHANGED
@@ -113,6 +113,10 @@ import { stuntmanPlugin } from 'stuntman/eliza'; // npm install stuntman
113
113
  // character: plugins: [stuntmanPlugin], settings: { secrets: { STUNTMAN_ENDPOINT: '...' } }
114
114
  ```
115
115
 
116
+ ### Priors
117
+
118
+ Point Priors' MCP server at a Stuntman endpoint and its on-chain transactions (borrows, stock trades) are practiced, never broadcast. Keep `PRIORS_MAX_SPEND_USD=0` while practicing: `pay_url` pays over HTTPS, outside any RPC. Repaying a practice loan isn't carried forward yet. `stuntman connect priors` prints the setup, and every Stuntman record also shows the agent's Priors credit record.
119
+
116
120
  ### OpenClaw
117
121
 
118
122
  The Stuntman skill is in `skills/stuntman`. Until it is listed on ClawHub, copy that folder into `~/.openclaw/skills/`.
@@ -135,7 +139,7 @@ Agents that send their own transactions use the printed endpoint as their RPC ad
135
139
  stuntman init --address <wallet> | --new [--rpc <url>] [--eth <amount>]
136
140
  stuntman mcp MCP server over stdio
137
141
  stuntman rpc [--port 8545] Practice RPC
138
- stuntman connect [claude|codex|json|raxol|virtuals|eliza|openclaw]
142
+ stuntman connect [claude|codex|json|raxol|virtuals|eliza|openclaw|priors]
139
143
  stuntman takes [--limit 20] [--json]
140
144
  stuntman take <id> [--json]
141
145
  stuntman balances [token ...]
package/dist/cli.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  // Stuntman command line. `npx stuntman` with no arguments shows where you are.
3
- import { existsSync } from 'node:fs';
3
+ import { existsSync, readFileSync } from 'node:fs';
4
+ import { homedir } from 'node:os';
4
5
  import { parseUnits } from 'viem';
5
6
  import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
6
7
  import { DEFAULT_PORT, DEFAULT_RPC_URL, configPath, xochiUrl, loadConfig, requireConfig, saveConfig, stuntmanHome, } from './config.js';
@@ -56,7 +57,7 @@ Start
56
57
  Connect your agent
57
58
  stuntman mcp Practice wallet as an MCP server (stdio)
58
59
  stuntman rpc [--port 8545] Practice RPC for agents that send their own transactions
59
- stuntman connect [claude|codex|json|raxol|virtuals|eliza|openclaw] Print the setup line for your agent
60
+ stuntman connect [claude|codex|json|raxol|virtuals|eliza|openclaw|priors] Print the setup line for your agent
60
61
 
61
62
  Watch the takes
62
63
  stuntman takes [--limit 20] Recent takes
@@ -69,6 +70,7 @@ Witnessed practice
69
70
  on a public record. The MCP tools switch over to it.
70
71
  stuntman witness off Go back to practicing on this machine only
71
72
  stuntman witness --key-env VAR Sign up an agent's own wallet (key read from env VAR)
73
+ stuntman witness --key-file PATH The same, with the key read from a file
72
74
 
73
75
  Practice a transaction
74
76
  stuntman send --to <address> [--value <eth>] [--data 0x...]
@@ -113,6 +115,20 @@ function connectLines(target) {
113
115
  '# In code, the Xochi config raxol_payments takes:',
114
116
  `%{base_url: "http://127.0.0.1:${DEFAULT_PORT}/xochi", auth: {:member, token}}`,
115
117
  ].join('\n');
118
+ case 'priors':
119
+ return [
120
+ '# Priors agents: rehearse borrows, repays and stock trades before they are real.',
121
+ '# 1. Sign the agent wallet up for witnessed practice (key read from the file, never printed):',
122
+ `${installed ? 'stuntman' : 'npx stuntman'} witness --key-file ~/.priors/agent.key`,
123
+ '',
124
+ '# 2. Run the Priors MCP server against the endpoint it prints, with payments switched off:',
125
+ 'PRIORS_RPC=<the endpoint>',
126
+ 'PRIORS_MAX_SPEND_USD=0',
127
+ '',
128
+ '# PRIORS_MAX_SPEND_USD=0 matters: pay_url pays x402 APIs over HTTPS, outside any RPC,',
129
+ '# so Stuntman cannot catch it. Every on-chain transaction the server sends is practiced.',
130
+ `# For local practice instead of witnessed, run "${installed ? 'stuntman' : 'npx stuntman'} rpc" and use http://127.0.0.1:8545.`,
131
+ ].join('\n');
116
132
  case 'eliza':
117
133
  return [
118
134
  '# ElizaOS agents: add the Stuntman plugin and give it an endpoint.',
@@ -156,7 +172,7 @@ function connectLines(target) {
156
172
  '',
157
173
  `Agents that send their own transactions: run "${rpc}" and use http://127.0.0.1:${DEFAULT_PORT} as the RPC address.`,
158
174
  `Raxol agents: run "${rpc}", then "${installed ? 'stuntman' : 'npx stuntman'} connect raxol" for the two settings.`,
159
- `Virtuals GAME agents: "${installed ? 'stuntman' : 'npx stuntman'} connect virtuals". ElizaOS: "connect eliza". OpenClaw: "connect openclaw".`,
175
+ `Virtuals GAME agents: "${installed ? 'stuntman' : 'npx stuntman'} connect virtuals". ElizaOS: "connect eliza". OpenClaw: "connect openclaw". Priors: "connect priors".`,
160
176
  ].join('\n');
161
177
  }
162
178
  }
@@ -366,11 +382,25 @@ async function cmdWitness(args, flags) {
366
382
  // An agent's own wallet (for example a Virtuals agent's WALLET_PRIVATE_KEY):
367
383
  // register it without touching this machine's practice settings. The key is
368
384
  // read from an environment variable so it never appears in the command line.
369
- if (typeof flags['key-env'] === 'string') {
370
- const name = flags['key-env'];
371
- const key = process.env[name];
372
- if (!key || !/^(0x)?[0-9a-fA-F]{64}$/.test(key.trim()))
373
- throw new Error(`Set ${name} to the agent's private key first. It is only used to sign the sign-up message.`);
385
+ if (typeof flags['key-env'] === 'string' || typeof flags['key-file'] === 'string') {
386
+ let key;
387
+ if (typeof flags['key-file'] === 'string') {
388
+ const path = flags['key-file'].replace(/^~(?=$|[\\/])/, homedir());
389
+ try {
390
+ key = readFileSync(path, 'utf8');
391
+ }
392
+ catch {
393
+ throw new Error(`Could not read the key file ${path}.`);
394
+ }
395
+ if (!/^(0x)?[0-9a-fA-F]{64}$/.test(key.trim()))
396
+ throw new Error(`${path} does not hold a private key (64 hex characters).`);
397
+ }
398
+ else {
399
+ const name = flags['key-env'];
400
+ key = process.env[name];
401
+ if (!key || !/^(0x)?[0-9a-fA-F]{64}$/.test(key.trim()))
402
+ throw new Error(`Set ${name} to the agent's private key first. It is only used to sign the sign-up message.`);
403
+ }
374
404
  const k = (key.trim().startsWith('0x') ? key.trim() : `0x${key.trim()}`);
375
405
  const { account, endpoint } = await registerWitness({ version: 1, rpcUrl: '', chainId: 0, account: '0x0000000000000000000000000000000000000000', mode: 'practice-key', practiceKey: k, createdAt: '' });
376
406
  out(`Witnessed practice is on for ${account}.`);
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.2.2';
1
+ export const VERSION = '0.2.3';
package/dist/witness.js CHANGED
@@ -377,6 +377,58 @@ async function runBatch(env, account, requests, batch) {
377
377
  await kv.pipeline(cmds);
378
378
  return batch ? out : out[0];
379
379
  }
380
+ const howOf = (matchedAs) => {
381
+ const as = Array.isArray(matchedAs) ? matchedAs : [];
382
+ const w = as.includes('declared wallet');
383
+ const o = as.includes('owner');
384
+ return w && o ? 'both' : w ? 'wallet' : o ? 'owner' : null;
385
+ };
386
+ /** Read Priors' check API answer the way Priors itself does (no score, no amounts). */
387
+ export function readPriors(body) {
388
+ const agents = body?.agents;
389
+ if (!Array.isArray(agents))
390
+ return null;
391
+ if (agents.some((x) => x && Number.isInteger(x.agentId) && !howOf(x.matchedAs)))
392
+ return null;
393
+ const seen = new Set();
394
+ const found = [];
395
+ for (const x of agents) {
396
+ if (!x || !Number.isInteger(x.agentId) || seen.has(x.agentId))
397
+ continue;
398
+ seen.add(x.agentId);
399
+ const n = Number(x.record?.loansRepaid);
400
+ found.push({
401
+ agentId: x.agentId,
402
+ page: `https://priors.trade/agent?id=${x.agentId}`,
403
+ how: howOf(x.matchedAs),
404
+ loansRepaid: Number.isSafeInteger(n) && n >= 0 ? n : 0,
405
+ defaulted: !!x.record?.defaulted,
406
+ });
407
+ }
408
+ if (!found.length)
409
+ return { none: true };
410
+ return { agents: found.slice(0, 3), more: Math.max(found.length - 3, 0) };
411
+ }
412
+ /** Priors' credit record for an address, cached for ten minutes. */
413
+ export async function priorsRecord(env, address, fetcher = fetch) {
414
+ const key = `w:priors:${lower(address)}`;
415
+ const cached = await env.kv.cmd('GET', key);
416
+ if (cached)
417
+ return JSON.parse(cached);
418
+ let reading = null;
419
+ try {
420
+ const res = await fetcher(`https://priors.trade/api/check?address=${lower(address)}`, { signal: AbortSignal.timeout(4000) });
421
+ if (res.ok)
422
+ reading = readPriors(await res.json());
423
+ }
424
+ catch {
425
+ reading = null;
426
+ }
427
+ // A failed read is not cached, so it is tried again next time.
428
+ if (reading)
429
+ await env.kv.cmd('SET', key, JSON.stringify(reading), 'EX', 600);
430
+ return reading;
431
+ }
380
432
  export async function agentRecord(env, address, limit = 50) {
381
433
  if (!isAddress(address))
382
434
  throw new WitnessError(400, 'address must be an address');
@@ -399,6 +451,7 @@ export async function agentRecord(env, address, limit = 50) {
399
451
  counts: { simulated: n('simulated'), filled: n('filled'), reverted: n('reverted'), rejected: n('rejected') },
400
452
  charged: (BigInt(agent.charged ?? '0') * scale).toString(),
401
453
  witness: witnessAddress(env),
454
+ priors: await priorsRecord(env, a, env.fetcher),
402
455
  funds: (fundsRaw ?? []).map((f) => JSON.parse(f)),
403
456
  takes: (recentRaw ?? [])
404
457
  .map((r) => JSON.parse(r))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stuntman",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Practice mode for AI agents. Real apps, real prices, practice money. Every send is played out against the live chain and nothing is broadcast.",
5
5
  "type": "module",
6
6
  "bin": {