stuntman 0.2.0 → 0.2.1
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 +12 -1
- package/dist/cli.js +40 -3
- package/dist/game.js +173 -0
- package/dist/launch.js +3 -2
- package/dist/version.js +1 -1
- package/package.json +14 -1
package/README.md
CHANGED
|
@@ -93,6 +93,17 @@ npx stuntman fund ETH 2
|
|
|
93
93
|
npx stuntman fund 0xTokenAddress 500
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
+
## Virtuals agents
|
|
97
|
+
|
|
98
|
+
Virtuals GAME agents practice two ways. Agents whose plugins send their own transactions: sign the agent wallet up with `stuntman witness --key-env WALLET_PRIVATE_KEY` and point the plugin's `RPC_PROVIDER_URL` at the endpoint it prints. TypeScript GAME agents can also add Stuntman as a worker:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { stuntmanWorker } from 'stuntman/game'; // npm install stuntman @virtuals-protocol/game
|
|
102
|
+
workers: [await stuntmanWorker({ endpoint: process.env.STUNTMAN_ENDPOINT })]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`stuntman connect virtuals` prints both setups.
|
|
106
|
+
|
|
96
107
|
## Witnessed practice
|
|
97
108
|
|
|
98
109
|
Practice on your own machine is private, so nobody else can trust it. `stuntman witness` moves your agent's takes to Stuntman's server: each one is simulated at the latest block, signed by the witness and added to a public record at `stuntmanhq.xyz/a/<address>`. Takes are only ever added, never removed.
|
|
@@ -111,7 +122,7 @@ Agents that send their own transactions use the printed endpoint as their RPC ad
|
|
|
111
122
|
stuntman init --address <wallet> | --new [--rpc <url>] [--eth <amount>]
|
|
112
123
|
stuntman mcp MCP server over stdio
|
|
113
124
|
stuntman rpc [--port 8545] Practice RPC
|
|
114
|
-
stuntman connect [claude|codex|json|raxol]
|
|
125
|
+
stuntman connect [claude|codex|json|raxol|virtuals]
|
|
115
126
|
stuntman takes [--limit 20] [--json]
|
|
116
127
|
stuntman take <id> [--json]
|
|
117
128
|
stuntman balances [token ...]
|
package/dist/cli.js
CHANGED
|
@@ -56,7 +56,7 @@ Start
|
|
|
56
56
|
Connect your agent
|
|
57
57
|
stuntman mcp Practice wallet as an MCP server (stdio)
|
|
58
58
|
stuntman rpc [--port 8545] Practice RPC for agents that send their own transactions
|
|
59
|
-
stuntman connect [claude|codex|json|raxol] Print the setup line for your agent
|
|
59
|
+
stuntman connect [claude|codex|json|raxol|virtuals] Print the setup line for your agent
|
|
60
60
|
|
|
61
61
|
Watch the takes
|
|
62
62
|
stuntman takes [--limit 20] Recent takes
|
|
@@ -68,6 +68,7 @@ Witnessed practice
|
|
|
68
68
|
stuntman witness Practice on Stuntman's server: every take signed and kept
|
|
69
69
|
on a public record. The MCP tools switch over to it.
|
|
70
70
|
stuntman witness off Go back to practicing on this machine only
|
|
71
|
+
stuntman witness --key-env VAR Sign up an agent's own wallet (key read from env VAR)
|
|
71
72
|
|
|
72
73
|
Practice money
|
|
73
74
|
stuntman fund ETH <amount>
|
|
@@ -107,6 +108,20 @@ function connectLines(target) {
|
|
|
107
108
|
'# In code, the Xochi config raxol_payments takes:',
|
|
108
109
|
`%{base_url: "http://127.0.0.1:${DEFAULT_PORT}/xochi", auth: {:member, token}}`,
|
|
109
110
|
].join('\n');
|
|
111
|
+
case 'virtuals':
|
|
112
|
+
return [
|
|
113
|
+
'# Virtuals GAME agents, two ways (use a witness endpoint to put takes on a public record):',
|
|
114
|
+
'',
|
|
115
|
+
'# 1. Agents whose plugins send their own transactions (RPC_PROVIDER_URL + WALLET_PRIVATE_KEY):',
|
|
116
|
+
'# register the agent wallet with the witness, then point the plugin RPC at the endpoint it prints.',
|
|
117
|
+
`${installed ? 'stuntman' : 'npx stuntman'} witness --key-env WALLET_PRIVATE_KEY`,
|
|
118
|
+
'RPC_PROVIDER_URL=<the endpoint>',
|
|
119
|
+
'',
|
|
120
|
+
'# 2. Give the agent Stuntman practice functions as a GAME worker:',
|
|
121
|
+
'npm install stuntman @virtuals-protocol/game',
|
|
122
|
+
"import { stuntmanWorker } from 'stuntman/game';",
|
|
123
|
+
'workers: [await stuntmanWorker({ endpoint: process.env.STUNTMAN_ENDPOINT })]',
|
|
124
|
+
].join('\n');
|
|
110
125
|
default:
|
|
111
126
|
return [
|
|
112
127
|
`Claude Code: claude mcp add stuntman -- ${shellLine}`,
|
|
@@ -116,6 +131,7 @@ function connectLines(target) {
|
|
|
116
131
|
'',
|
|
117
132
|
`Agents that send their own transactions: run "${rpc}" and use http://127.0.0.1:${DEFAULT_PORT} as the RPC address.`,
|
|
118
133
|
`Raxol agents: run "${rpc}", then "${installed ? 'stuntman' : 'npx stuntman'} connect raxol" for the two settings.`,
|
|
134
|
+
`Virtuals GAME agents: "${installed ? 'stuntman' : 'npx stuntman'} connect virtuals".`,
|
|
119
135
|
].join('\n');
|
|
120
136
|
}
|
|
121
137
|
}
|
|
@@ -321,7 +337,28 @@ async function cmdRpc(flags) {
|
|
|
321
337
|
err(`Xochi practice gateway on http://${host}:${port}/xochi (quotes from ${xochiUrl()}, executes stay here).`);
|
|
322
338
|
err('Press Ctrl+C to stop.');
|
|
323
339
|
}
|
|
324
|
-
async function cmdWitness(args) {
|
|
340
|
+
async function cmdWitness(args, flags) {
|
|
341
|
+
// An agent's own wallet (for example a Virtuals agent's WALLET_PRIVATE_KEY):
|
|
342
|
+
// register it without touching this machine's practice settings. The key is
|
|
343
|
+
// read from an environment variable so it never appears in the command line.
|
|
344
|
+
if (typeof flags['key-env'] === 'string') {
|
|
345
|
+
const name = flags['key-env'];
|
|
346
|
+
const key = process.env[name];
|
|
347
|
+
if (!key || !/^(0x)?[0-9a-fA-F]{64}$/.test(key.trim()))
|
|
348
|
+
throw new Error(`Set ${name} to the agent's private key first. It is only used to sign the sign-up message.`);
|
|
349
|
+
const k = (key.trim().startsWith('0x') ? key.trim() : `0x${key.trim()}`);
|
|
350
|
+
const { account, endpoint } = await registerWitness({ version: 1, rpcUrl: '', chainId: 0, account: '0x0000000000000000000000000000000000000000', mode: 'practice-key', practiceKey: k, createdAt: '' });
|
|
351
|
+
out(`Witnessed practice is on for ${account}.`);
|
|
352
|
+
out('');
|
|
353
|
+
out('Endpoint (keep it private, it is your agent\'s key to the record). Use it as the agent\'s RPC address:');
|
|
354
|
+
out(` ${endpoint}`);
|
|
355
|
+
out('Public record:');
|
|
356
|
+
out(` ${witnessBase()}/a/${account}`);
|
|
357
|
+
out('');
|
|
358
|
+
out('The agent signs as usual; Stuntman simulates every transaction it sends there and broadcasts nothing.');
|
|
359
|
+
out('Practice money for this agent: the endpoint accepts stuntman_fund, or use the GAME worker\'s add_practice_money.');
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
325
362
|
const cfg = requireConfig();
|
|
326
363
|
if (args[0] === 'off') {
|
|
327
364
|
delete cfg.witness;
|
|
@@ -392,7 +429,7 @@ async function main() {
|
|
|
392
429
|
case 'connect':
|
|
393
430
|
return out(connectLines(args[0] ?? 'all'));
|
|
394
431
|
case 'witness':
|
|
395
|
-
return cmdWitness(args);
|
|
432
|
+
return cmdWitness(args, flags);
|
|
396
433
|
default:
|
|
397
434
|
throw new Error(`Unknown command "${cmd}". Run "stuntman help".`);
|
|
398
435
|
}
|
package/dist/game.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Stuntman for Virtuals GAME agents.
|
|
2
|
+
//
|
|
3
|
+
// import { GameAgent } from '@virtuals-protocol/game';
|
|
4
|
+
// import { stuntmanWorker } from 'stuntman/game';
|
|
5
|
+
//
|
|
6
|
+
// const agent = new GameAgent(process.env.GAME_API_KEY, {
|
|
7
|
+
// name: 'My trader',
|
|
8
|
+
// goal: 'Trade on Robinhood Chain',
|
|
9
|
+
// description: '...',
|
|
10
|
+
// workers: [await stuntmanWorker({ endpoint: process.env.STUNTMAN_ENDPOINT })],
|
|
11
|
+
// });
|
|
12
|
+
//
|
|
13
|
+
// The worker gives the agent practice functions: every transaction it sends is
|
|
14
|
+
// played out at the latest block with practice money and never broadcast. With
|
|
15
|
+
// a witness endpoint (from `stuntman witness`), every take is also signed and
|
|
16
|
+
// kept on the agent's public record.
|
|
17
|
+
import { parseUnits } from 'viem';
|
|
18
|
+
import { formatTake } from './report.js';
|
|
19
|
+
import { remoteCall, RemoteError } from './remote.js';
|
|
20
|
+
async function loadGame() {
|
|
21
|
+
const name = '@virtuals-protocol/game';
|
|
22
|
+
try {
|
|
23
|
+
return (await import(name));
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
throw new Error('stuntman/game needs the Virtuals GAME SDK. Install it with: npm install @virtuals-protocol/game');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const isAddress = (s) => typeof s === 'string' && /^0x[0-9a-fA-F]{40}$/.test(s);
|
|
30
|
+
/** The practice functions as plain async functions, independent of the GAME SDK. */
|
|
31
|
+
export function practiceActions(endpoint) {
|
|
32
|
+
const call = (method, params = []) => remoteCall(endpoint, method, params);
|
|
33
|
+
let account = null;
|
|
34
|
+
const who = async () => (account ??= (await call('stuntman_status')).account);
|
|
35
|
+
return {
|
|
36
|
+
async status() {
|
|
37
|
+
const s = await call('stuntman_status');
|
|
38
|
+
const takes = await call('stuntman_takes', [200]);
|
|
39
|
+
const filled = takes.filter((t) => t.status === 'filled').length;
|
|
40
|
+
const failed = takes.filter((t) => t.status === 'reverted').length;
|
|
41
|
+
const witnessed = /\/w\/[0-9a-f]{48}$/.test(endpoint);
|
|
42
|
+
return [
|
|
43
|
+
`Practicing as ${s.account} on chain ${s.chainId}. Nothing is ever broadcast.`,
|
|
44
|
+
`Recent takes: ${takes.length} (${filled} filled, ${failed} failed).`,
|
|
45
|
+
witnessed ? `Witnessed: every take is signed and kept on the public record at ${new URL(endpoint).origin}/a/${s.account}.` : 'Local practice: takes stay on this machine.',
|
|
46
|
+
].join('\n');
|
|
47
|
+
},
|
|
48
|
+
async balances() {
|
|
49
|
+
const rows = await call('stuntman_balances');
|
|
50
|
+
return rows.map((r) => `${r.symbol}: ${r.formatted}${r.practice ? '' : ' (real balance)'}${r.token === 'ETH' ? '' : ` [${r.token}]`}`).join('\n');
|
|
51
|
+
},
|
|
52
|
+
async send(to, data, value) {
|
|
53
|
+
const from = await who();
|
|
54
|
+
const tx = { from, data: data && /^0x[0-9a-fA-F]*$/.test(data) ? data : '0x' };
|
|
55
|
+
if (to) {
|
|
56
|
+
if (!isAddress(to))
|
|
57
|
+
return { ok: false, text: 'to must be a contract or wallet address (0x followed by 40 characters), or empty to deploy a contract.' };
|
|
58
|
+
tx.to = to;
|
|
59
|
+
}
|
|
60
|
+
if (value) {
|
|
61
|
+
if (!/^[0-9]+$/.test(value))
|
|
62
|
+
return { ok: false, text: 'value must be a whole number of wei, for example 50000000000000000 for 0.05 ETH.' };
|
|
63
|
+
tx.value = `0x${BigInt(value).toString(16)}`;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const hash = await call('eth_sendTransaction', [tx]);
|
|
67
|
+
const take = (await call('stuntman_takes', [5])).find((t) => t.txHash.toLowerCase() === hash.toLowerCase());
|
|
68
|
+
if (!take)
|
|
69
|
+
return { ok: true, text: `Practice transaction ${hash}. Nothing was broadcast.` };
|
|
70
|
+
return { ok: take.status === 'filled', text: `${formatTake(take)}\nNothing was broadcast.` };
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
const latest = (await call('stuntman_takes', [1]).catch(() => []))[0];
|
|
74
|
+
if (err instanceof RemoteError && latest?.status === 'rejected' && Date.now() - Date.parse(latest.at) < 15_000) {
|
|
75
|
+
return { ok: false, text: `${formatTake(latest)}\nNothing was broadcast.` };
|
|
76
|
+
}
|
|
77
|
+
return { ok: false, text: err.message };
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
async takes(limit = 10) {
|
|
81
|
+
const takes = await call('stuntman_takes', [Math.max(1, Math.min(50, limit))]);
|
|
82
|
+
return takes.length ? takes.map((t) => formatTake(t)).join('\n\n') : 'No takes yet.';
|
|
83
|
+
},
|
|
84
|
+
async fund(asset, amount) {
|
|
85
|
+
if (!asset || !amount)
|
|
86
|
+
return { ok: false, text: 'Give an asset (ETH or a token address) and an amount, for example ETH and 1.' };
|
|
87
|
+
const isEth = asset.toUpperCase() === 'ETH';
|
|
88
|
+
if (!isEth && !isAddress(asset))
|
|
89
|
+
return { ok: false, text: 'asset must be ETH or a token address.' };
|
|
90
|
+
let decimals = 18;
|
|
91
|
+
if (!isEth) {
|
|
92
|
+
const raw = await call('eth_call', [{ to: asset, data: '0x313ce567' }, 'latest']);
|
|
93
|
+
decimals = Number(BigInt(raw));
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const units = parseUnits(amount, decimals);
|
|
97
|
+
const r = await call('stuntman_fund', [isEth ? 'ETH' : asset, units.toString()]);
|
|
98
|
+
return { ok: true, text: `Added ${amount} ${r.symbol} of practice money.` };
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
const msg = err.message;
|
|
102
|
+
return {
|
|
103
|
+
ok: false,
|
|
104
|
+
text: /method|not found|unsupported/i.test(msg) ? 'This endpoint does not add practice money. Use "stuntman fund" on the machine running it.' : msg,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** A GAME worker with Stuntman's practice functions. */
|
|
111
|
+
export async function stuntmanWorker(options = {}) {
|
|
112
|
+
const endpoint = options.endpoint ?? process.env.STUNTMAN_ENDPOINT ?? 'http://127.0.0.1:8545';
|
|
113
|
+
const game = await loadGame();
|
|
114
|
+
const actions = practiceActions(endpoint);
|
|
115
|
+
const done = (text) => new game.ExecutableGameFunctionResponse(game.ExecutableGameFunctionStatus.Done, text);
|
|
116
|
+
const failed = (text) => new game.ExecutableGameFunctionResponse(game.ExecutableGameFunctionStatus.Failed, text);
|
|
117
|
+
const safe = (fn) => async (args) => {
|
|
118
|
+
try {
|
|
119
|
+
const out = await fn(args);
|
|
120
|
+
return typeof out === 'string' ? done(out) : out.ok ? done(out.text) : failed(out.text);
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
return failed(err.message);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const functions = [
|
|
127
|
+
new game.GameFunction({
|
|
128
|
+
name: 'practice_status',
|
|
129
|
+
description: 'Show the practice account, recent takes and whether takes are witnessed on a public record.',
|
|
130
|
+
args: [],
|
|
131
|
+
executable: safe(() => actions.status()),
|
|
132
|
+
}),
|
|
133
|
+
new game.GameFunction({
|
|
134
|
+
name: 'practice_balances',
|
|
135
|
+
description: 'Practice balances of ETH and tokens. These are practice money, not real funds.',
|
|
136
|
+
args: [],
|
|
137
|
+
executable: safe(() => actions.balances()),
|
|
138
|
+
}),
|
|
139
|
+
new game.GameFunction({
|
|
140
|
+
name: 'send_practice_transaction',
|
|
141
|
+
description: 'Send a transaction in practice: it is simulated at the latest block of Robinhood Chain with real prices and practice money, and never broadcast. Returns whether it filled or failed and what changed.',
|
|
142
|
+
args: [
|
|
143
|
+
{ name: 'to', description: 'Contract or wallet address. Leave empty to deploy a contract.', optional: true },
|
|
144
|
+
{ name: 'data', description: 'Calldata as 0x hex. Empty for a plain ETH send.', optional: true },
|
|
145
|
+
{ name: 'value', description: 'ETH to send, in wei as a whole number.', optional: true },
|
|
146
|
+
],
|
|
147
|
+
executable: safe((a) => actions.send(a.to, a.data, a.value)),
|
|
148
|
+
}),
|
|
149
|
+
new game.GameFunction({
|
|
150
|
+
name: 'list_practice_takes',
|
|
151
|
+
description: 'Recent practice takes, newest first, with results and reasons for failures.',
|
|
152
|
+
args: [{ name: 'limit', description: 'How many takes, up to 50. Default 10.', optional: true }],
|
|
153
|
+
executable: safe((a) => actions.takes(Number(a.limit ?? 10) || 10)),
|
|
154
|
+
}),
|
|
155
|
+
new game.GameFunction({
|
|
156
|
+
name: 'add_practice_money',
|
|
157
|
+
description: 'Add practice money (witness endpoints only). It shows on the public record.',
|
|
158
|
+
args: [
|
|
159
|
+
{ name: 'asset', description: 'ETH or a token address' },
|
|
160
|
+
{ name: 'amount', description: 'Amount in whole units, for example 1 or 250.5' },
|
|
161
|
+
],
|
|
162
|
+
executable: safe((a) => actions.fund(a.asset, a.amount)),
|
|
163
|
+
}),
|
|
164
|
+
];
|
|
165
|
+
return new game.GameWorker({
|
|
166
|
+
id: options.id ?? 'stuntman_practice',
|
|
167
|
+
name: options.name ?? 'Stuntman practice',
|
|
168
|
+
description: options.description ??
|
|
169
|
+
'Practices trades on Robinhood Chain before they are real: transactions are simulated at the latest block with real prices and practice money, and never broadcast.',
|
|
170
|
+
functions,
|
|
171
|
+
getEnvironment: async () => ({ practice: true, endpoint: new URL(endpoint).origin }),
|
|
172
|
+
});
|
|
173
|
+
}
|
package/dist/launch.js
CHANGED
|
@@ -13,8 +13,9 @@ const addr = (v) => (v && /^0x[0-9a-fA-F]{40}$/.test(v) ? v : null);
|
|
|
13
13
|
export function launchSettings(env = process.env) {
|
|
14
14
|
return {
|
|
15
15
|
...LAUNCH,
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// "none" turns a setting off, for local runs away from Robinhood Chain.
|
|
17
|
+
token: env.STUNTMAN_TOKEN === 'none' ? null : (addr(env.STUNTMAN_TOKEN) ?? LAUNCH.token),
|
|
18
|
+
credits: env.STUNTMAN_CREDITS === 'none' ? null : (addr(env.STUNTMAN_CREDITS) ?? LAUNCH.credits),
|
|
18
19
|
freeTakes: env.STUNTMAN_FREE_TAKES !== undefined ? Number(env.STUNTMAN_FREE_TAKES) : LAUNCH.freeTakes,
|
|
19
20
|
takePriceUsd: env.STUNTMAN_TAKE_PRICE_USD !== undefined ? Number(env.STUNTMAN_TAKE_PRICE_USD) : LAUNCH.takePriceUsd,
|
|
20
21
|
};
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.2.
|
|
1
|
+
export const VERSION = '0.2.1';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stuntman",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
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": {
|
|
@@ -50,7 +50,20 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@foundry-rs/anvil": "^1.7.1",
|
|
52
52
|
"@types/node": "^26.6.11",
|
|
53
|
+
"@virtuals-protocol/game": "^0.1.14",
|
|
53
54
|
"solc": "^0.8.39",
|
|
54
55
|
"typescript": "^7.0.2"
|
|
56
|
+
},
|
|
57
|
+
"exports": {
|
|
58
|
+
"./game": "./dist/game.js",
|
|
59
|
+
"./package.json": "./package.json"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@virtuals-protocol/game": ">=0.1.14"
|
|
63
|
+
},
|
|
64
|
+
"peerDependenciesMeta": {
|
|
65
|
+
"@virtuals-protocol/game": {
|
|
66
|
+
"optional": true
|
|
67
|
+
}
|
|
55
68
|
}
|
|
56
69
|
}
|