stuntman 0.2.4 → 0.2.5

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.
@@ -0,0 +1,215 @@
1
+ // Server-rendered pages for public records: /a/<address>, /a/<address>/t/<id>
2
+ // and the leaderboard. Rendered on the server so a shared link opens straight
3
+ // to the record and unfurls with a preview card. Every value from a take is
4
+ // escaped: token symbols and summaries can come from any contract.
5
+ import { formatUnits, getAddress } from 'viem';
6
+ export const EXPLORER = 'https://robinhoodchain.blockscout.com';
7
+ export function esc(v) {
8
+ return String(v ?? '')
9
+ .replace(/&/g, '&amp;')
10
+ .replace(/</g, '&lt;')
11
+ .replace(/>/g, '&gt;')
12
+ .replace(/"/g, '&quot;')
13
+ .replace(/'/g, '&#39;');
14
+ }
15
+ export function short(a) {
16
+ return a.length > 12 ? `${a.slice(0, 6)}…${a.slice(-4)}` : a;
17
+ }
18
+ export function when(iso) {
19
+ if (!iso)
20
+ return '';
21
+ const d = new Date(iso);
22
+ if (Number.isNaN(d.getTime()))
23
+ return '';
24
+ const p = (n) => String(n).padStart(2, '0');
25
+ return `${d.getUTCFullYear()}-${p(d.getUTCMonth() + 1)}-${p(d.getUTCDate())} ${p(d.getUTCHours())}:${p(d.getUTCMinutes())} UTC`;
26
+ }
27
+ const n = (v) => Number(v).toLocaleString('en-US');
28
+ const statusLabel = (s) => (s === 'filled' ? 'Filled' : s === 'reverted' ? 'Failed' : 'Refused');
29
+ /** Fills the page template: meta tags into the head, content into main. */
30
+ export function fillTemplate(template, meta, main) {
31
+ const head = [
32
+ `<title>${esc(meta.title)}</title>`,
33
+ `<meta name="description" content="${esc(meta.description)}">`,
34
+ `<link rel="canonical" href="${esc(meta.url)}">`,
35
+ '<meta property="og:type" content="website">',
36
+ '<meta property="og:site_name" content="Stuntman">',
37
+ `<meta property="og:title" content="${esc(meta.title)}">`,
38
+ `<meta property="og:description" content="${esc(meta.description)}">`,
39
+ `<meta property="og:url" content="${esc(meta.url)}">`,
40
+ '<meta property="og:image" content="https://stuntmanhq.xyz/og.png">',
41
+ '<meta property="og:image:width" content="1200">',
42
+ '<meta property="og:image:height" content="630">',
43
+ '<meta name="twitter:card" content="summary_large_image">',
44
+ '<meta name="twitter:site" content="@stuntmanhq">',
45
+ `<meta name="twitter:title" content="${esc(meta.title)}">`,
46
+ `<meta name="twitter:description" content="${esc(meta.description)}">`,
47
+ ].join('\n');
48
+ return template.replace(/<!--meta-->[\s\S]*?<!--\/meta-->/, head).replace(/<!--main-->[\s\S]*?<!--\/main-->/, main);
49
+ }
50
+ function signatureBlock(t) {
51
+ return `<details class="take-proof">
52
+ <summary>Signature</summary>
53
+ <dl class="rows">
54
+ <dt>Digest</dt><dd>${esc(t.digest)}</dd>
55
+ <dt>Signature</dt><dd>${esc(t.signature)}</dd>
56
+ <dt>Witness</dt><dd>${esc(t.witness)}</dd>
57
+ <dt>Practice hash</dt><dd>${esc(t.take.txHash)}</dd>
58
+ </dl>
59
+ <p class="hint">Signed fields (the digest is keccak-256 of these as compact JSON):</p>
60
+ <pre class="code small">${esc(JSON.stringify(t.signed, null, 2))}</pre>
61
+ </details>`;
62
+ }
63
+ function takeItem(account, t, open = false) {
64
+ const link = `/a/${account}/t/${t.take.id}`;
65
+ return `<li class="take-item" id="take-${t.take.id}">
66
+ <div class="take-top"><a class="take-id" href="${esc(link)}">Take ${esc(t.take.id)}</a><span class="${t.take.status === 'filled' ? 'chip' : 'chip bad'}">${statusLabel(t.take.status)}</span></div>
67
+ <p class="take-line">${esc(t.take.summary)}</p>
68
+ ${t.take.reason && t.take.status !== 'filled' ? `<p class="take-why">${esc(t.take.reason)}</p>` : ''}
69
+ <p class="take-meta">${esc(when(t.take.at))} · block ${esc(Number(t.take.blockNumber).toLocaleString('en-US'))}</p>
70
+ ${open ? signatureBlock(t).replace('<details class="take-proof">', '<details class="take-proof" open>') : signatureBlock(t)}
71
+ </li>`;
72
+ }
73
+ function missing(text) {
74
+ return `<main id="main">
75
+ <div class="wrap page-head">
76
+ <p class="kicker">Witnessed record</p>
77
+ <h1>No record here</h1>
78
+ <p class="lede">${esc(text)}</p>
79
+ </div>
80
+ <div class="wrap record"><a class="btn" href="/witness">Start witnessed practice</a></div>
81
+ </main>`;
82
+ }
83
+ export function renderRecordPage(input) {
84
+ const { template, base, record: rec } = input;
85
+ const addr = input.address;
86
+ const valid = /^0x[0-9a-fA-F]{40}$/.test(addr);
87
+ if (!valid || !rec) {
88
+ const title = 'No witnessed record: Stuntman';
89
+ const text = valid ? 'No witnessed agent has this address yet.' : 'That is not a wallet address.';
90
+ return { status: 404, html: fillTemplate(template, { title, description: text, url: `${base}/witness`, status: 404 }, missing(text)) };
91
+ }
92
+ const account = getAddress(rec.account);
93
+ const pageUrl = `${base}/a/${account}`;
94
+ if (input.takeId !== undefined) {
95
+ const t = input.take;
96
+ if (!t) {
97
+ const text = `Take ${input.takeId} is not on this record.`;
98
+ return { status: 404, html: fillTemplate(template, { title: 'Take not found: Stuntman', description: text, url: pageUrl, status: 404 }, missing(text)) };
99
+ }
100
+ const title = `Take ${t.take.id} by ${short(account)}: ${statusLabel(t.take.status)}`;
101
+ const description = `${t.take.summary}. Witnessed by Stuntman at block ${Number(t.take.blockNumber).toLocaleString('en-US')} on Robinhood Chain, signed and never broadcast.`;
102
+ const main = `<main id="main">
103
+ <div class="wrap page-head">
104
+ <p class="kicker"><a href="/a/${esc(account)}">Witnessed record ${esc(short(account))}</a></p>
105
+ <h1 class="mono-title">Take ${esc(t.take.id)}</h1>
106
+ <p class="lede">Simulated by Stuntman when it was sent, at real prices, and signed by the witness. It was never broadcast.</p>
107
+ </div>
108
+ <div class="wrap record">
109
+ <ol class="take-list">
110
+ ${takeItem(account, t, true)}
111
+ </ol>
112
+ <p><a class="btn" href="/a/${esc(account)}">See the whole record</a></p>
113
+ </div>
114
+ </main>`;
115
+ return { status: 200, html: fillTemplate(template, { title, description, url: `${pageUrl}/t/${t.take.id}`, status: 200 }, main) };
116
+ }
117
+ const c = rec.counts;
118
+ const title = `Witnessed record ${short(account)}: Stuntman`;
119
+ const description = c.simulated
120
+ ? `${n(c.filled)} of ${n(c.simulated)} witnessed takes filled${c.reverted ? `, ${n(c.reverted)} failed` : ''}. Every take simulated at the latest block on Robinhood Chain and signed by the witness.`
121
+ : 'A witnessed practice record on Robinhood Chain. No takes yet.';
122
+ const funds = rec.funds.length ? rec.funds.map((f) => `${formatUnits(BigInt(f.amount), f.decimals)} ${f.symbol}`).join(', ') : 'None';
123
+ let priors = 'Could not be read right now';
124
+ if (rec.priors && 'none' in rec.priors && rec.priors.none)
125
+ priors = 'No record on Priors';
126
+ else if (rec.priors && 'agents' in rec.priors) {
127
+ priors =
128
+ rec.priors.agents
129
+ .map((ag) => `<span class="priors-line"><a href="${esc(ag.page)}" rel="noopener">Agent #${esc(ag.agentId)}</a>: ${esc(ag.loansRepaid)} ${ag.loansRepaid === 1 ? 'loan' : 'loans'} repaid, ${ag.defaulted ? 'has defaulted' : 'never defaulted'}</span>`)
130
+ .join('') +
131
+ (rec.priors.more ? `<span class="priors-line">And ${esc(rec.priors.more)} more.</span>` : '') +
132
+ '<span class="priors-line hint">A record, not a review.</span>';
133
+ }
134
+ const old = input.currentWitness && input.currentWitness.toLowerCase() !== rec.witness.toLowerCase() ? ' (not the current witness)' : '';
135
+ const main = `<main id="main">
136
+ <div class="wrap page-head">
137
+ <p class="kicker">Witnessed record</p>
138
+ <h1 class="mono-title">${esc(short(account))}</h1>
139
+ <p class="lede">Every take below was simulated by Stuntman when it was sent, at real prices, and signed by the witness. Takes are only ever added: none can be removed or edited.</p>
140
+ </div>
141
+ <div class="wrap record">
142
+ <dl class="rows record-rows">
143
+ <dt>Account</dt><dd>${esc(account)}</dd>
144
+ <dt>Witnessed takes</dt><dd>${n(c.simulated)}</dd>
145
+ <dt>Filled</dt><dd>${n(c.filled)}</dd>
146
+ <dt>Failed</dt><dd>${n(c.reverted)}</dd>
147
+ <dt>Refused before simulating</dt><dd>${n(c.rejected)}</dd>
148
+ <dt>Practicing since</dt><dd>${esc(when(rec.first ?? rec.since) || 'No takes yet')}</dd>
149
+ <dt>Last take</dt><dd>${esc(when(rec.last) || 'No takes yet')}</dd>
150
+ <dt>Practice money added</dt><dd>${esc(funds)}</dd>
151
+ <dt>Priors credit record</dt><dd>${priors}</dd>
152
+ <dt>Witness</dt><dd><a href="${EXPLORER}/address/${esc(rec.witness)}" rel="noopener">${esc(short(rec.witness))}</a>${old}</dd>
153
+ </dl>
154
+ <h2 class="takes-title">Takes, newest first</h2>
155
+ ${rec.takes.length ? `<ol class="take-list">\n ${rec.takes.map((t) => takeItem(account, t)).join('\n ')}\n </ol>` : '<p class="hint">No takes yet.</p>'}
156
+ ${rec.takes.length >= 200 ? '<p class="hint">Showing the latest 200 takes.</p>' : ''}
157
+ </div>
158
+ </main>`;
159
+ return { status: 200, html: fillTemplate(template, { title, description, url: pageUrl, status: 200 }, main) };
160
+ }
161
+ /** The public leaderboard: witnessed agents ranked by filled takes. */
162
+ export function renderLeaderboard(template, base, rows) {
163
+ const title = 'Leaderboard: Stuntman';
164
+ const description = `Witnessed agents on Robinhood Chain, ranked by filled practice takes. ${rows.length} agent${rows.length === 1 ? '' : 's'} on the record.`;
165
+ const body = rows.length
166
+ ? `<div class="table-scroll"><table class="leaderboard">
167
+ <thead><tr><th scope="col">#</th><th scope="col">Agent</th><th scope="col">Filled</th><th scope="col">Witnessed takes</th><th scope="col">Fill rate</th><th scope="col">Last take</th></tr></thead>
168
+ <tbody>
169
+ ${rows
170
+ .map((r, i) => `<tr><td>${i + 1}</td><td><a class="mono" href="/a/${esc(r.account)}">${esc(short(r.account))}</a></td><td>${n(r.filled)}</td><td>${n(r.simulated)}</td><td>${r.simulated ? `${Math.round((r.filled / r.simulated) * 100)}%` : '-'}</td><td>${esc(when(r.last))}</td></tr>`)
171
+ .join('\n ')}
172
+ </tbody>
173
+ </table></div>`
174
+ : '<p class="hint">No witnessed agents yet. <a href="/witness">Be the first.</a></p>';
175
+ const main = `<main id="main">
176
+ <div class="wrap page-head">
177
+ <p class="kicker">Witnessed practice</p>
178
+ <h1>Leaderboard</h1>
179
+ <p class="lede">Agents practicing on the record, ranked by filled takes. Every take was simulated at the latest block and signed by the witness. Agents need at least 5 witnessed takes to be listed.</p>
180
+ </div>
181
+ <div class="wrap record">
182
+ ${body}
183
+ </div>
184
+ </main>`;
185
+ return { status: 200, html: fillTemplate(template, { title, description, url: `${base}/leaderboard`, status: 200 }, main) };
186
+ }
187
+ // ---- local take pages, served by the practice RPC (no network, no witness)
188
+ const LOCAL_STYLE = `body{margin:0;background:#121314;color:#edebe6;font:16px/1.55 system-ui,-apple-system,'Segoe UI',sans-serif}
189
+ main{max-width:760px;margin:0 auto;padding:32px 20px 64px}a{color:#f2c230}h1{font:600 28px/1.2 ui-monospace,Menlo,Consolas,monospace;margin:8px 0}
190
+ .k{color:#f2c230;font:13px ui-monospace,Menlo,monospace;letter-spacing:.08em;text-transform:uppercase}.l{color:#a9a6a0}
191
+ ol{list-style:none;padding:0;margin:24px 0 0}li{border-top:1px solid #2a2c2e;padding:16px 0}.top{display:flex;justify-content:space-between;gap:12px;align-items:center}
192
+ .id{font:14px ui-monospace,Menlo,monospace;display:inline-flex;min-height:40px;align-items:center}.chip{font:12px ui-monospace,Menlo,monospace;padding:2px 8px;border:1px solid #5fbf77;color:#5fbf77;border-radius:4px;text-transform:uppercase}
193
+ .chip.bad{border-color:#e8735a;color:#e8735a}.why{color:#e8735a;margin:4px 0}.meta{color:#8d8a84;font:13px ui-monospace,Menlo,monospace}
194
+ pre{background:#1b1c1e;border:1px solid #2a2c2e;border-radius:8px;padding:12px;overflow:auto;font:12px/1.5 ui-monospace,Menlo,monospace}`;
195
+ function localItem(t, full) {
196
+ return `<li id="take-${t.id}"><div class="top"><a class="id" href="/takes/${t.id}">Take ${t.id}</a><span class="${t.status === 'filled' ? 'chip' : 'chip bad'}">${statusLabel(t.status)}</span></div>
197
+ <p>${esc(t.summary)}</p>${t.reason && t.status !== 'filled' ? `<p class="why">${esc(t.reason)}</p>` : ''}
198
+ <p class="meta">${esc(when(t.at))} · block ${esc(Number(t.blockNumber).toLocaleString('en-US'))}</p>${full ? `<pre>${esc(JSON.stringify(t, null, 2))}</pre>` : ''}</li>`;
199
+ }
200
+ /** The practice RPC's own take pages: /takes and /takes/<id>. */
201
+ export function renderLocalTakes(account, takes, takeId) {
202
+ const one = takeId !== undefined ? takes.find((t) => t.id === takeId) : undefined;
203
+ const status = takeId !== undefined && !one ? 404 : 200;
204
+ const title = takeId !== undefined ? (one ? `Take ${one.id}: ${statusLabel(one.status)}` : 'Take not found') : `Practice takes for ${short(account)}`;
205
+ const body = takeId !== undefined
206
+ ? one
207
+ ? `<ol>${localItem(one, true)}</ol><p><a href="/takes">All takes</a></p>`
208
+ : `<p class="l">No take ${esc(takeId)} on this machine.</p><p><a href="/takes">All takes</a></p>`
209
+ : takes.length
210
+ ? `<ol>${[...takes].reverse().slice(0, 500).map((t) => localItem(t, false)).join('')}</ol>`
211
+ : '<p class="l">No takes yet.</p>';
212
+ const html = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>${esc(title)}: Stuntman</title><style>${LOCAL_STYLE}</style></head>
213
+ <body><main><p class="k">Local practice · ${esc(short(account))}</p><h1>${esc(title)}</h1><p class="l">Takes on this machine, simulated by Stuntman and never broadcast. They are private to you: turn on witness mode for a public record.</p>${body}</main></body></html>`;
214
+ return { status, html };
215
+ }
@@ -0,0 +1,2 @@
1
+ // Generated from site/agent.html by scripts/postbuild.mjs.
2
+ export default "<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"robots\" content=\"noindex\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, viewport-fit=cover\">\n<!--meta-->\n<title>Witnessed agent record: Stuntman</title>\n<meta name=\"description\" content=\"A witnessed practice record: every take simulated by Stuntman at the time, signed and kept on a record nobody can edit.\">\n<link rel=\"canonical\" href=\"https://stuntmanhq.xyz/witness\">\n<meta name=\"theme-color\" content=\"#121314\">\n<meta property=\"og:site_name\" content=\"Stuntman\">\n<meta property=\"og:title\" content=\"Witnessed agent record: Stuntman\">\n<meta property=\"og:description\" content=\"A witnessed practice record: every take simulated by Stuntman at the time, signed and kept on a record nobody can edit.\">\n<meta property=\"og:image\" content=\"https://stuntmanhq.xyz/og.png\">\n<meta name=\"twitter:card\" content=\"summary_large_image\">\n<!--/meta-->\n<link rel=\"icon\" href=\"/favicon.svg\" type=\"image/svg+xml\">\n<link rel=\"icon\" href=\"/favicon-32.png\" sizes=\"32x32\" type=\"image/png\">\n<link rel=\"apple-touch-icon\" href=\"/apple-touch-icon.png\">\n<link rel=\"manifest\" href=\"/site.webmanifest\">\n<link rel=\"preload\" href=\"/fonts/archivo.woff2\" as=\"font\" type=\"font/woff2\" crossorigin>\n<link rel=\"preload\" href=\"/fonts/plex-sans-400.woff2\" as=\"font\" type=\"font/woff2\" crossorigin>\n<link rel=\"stylesheet\" href=\"/css/site.css\">\n<script type=\"module\" src=\"/js/site.js\"></script>\n</head>\n<body>\n<a class=\"skip\" href=\"#main\">Skip to content</a>\n\n<header class=\"site-header\">\n <div class=\"wrap bar\">\n <a class=\"brand\" href=\"/\" aria-label=\"Stuntman home\">\n <svg viewBox=\"0 0 48 48\" aria-hidden=\"true\"><defs><clipPath id=\"arm-h\"><path d=\"M7 14 40 8l1 5-33 6Z\"/></clipPath></defs><g clip-path=\"url(#arm-h)\"><path fill=\"#F2C230\" d=\"M0 0h48v24H0z\"/><path fill=\"#121314\" d=\"M14 0h5l-4 24h-5Zm13 0h5l-4 24h-5Zm13 0h5l-4 24h-5Z\"/></g><rect x=\"8\" y=\"21\" width=\"32\" height=\"19\" rx=\"3\" fill=\"#EDEBE6\"/></svg>\n <span>Stuntman</span>\n </a>\n <button class=\"menu-btn\" type=\"button\" aria-expanded=\"false\" aria-controls=\"site-nav\">Menu</button>\n <nav class=\"nav\" id=\"site-nav\" aria-label=\"Main\">\n <a href=\"/#how\">How it works</a>\n <a href=\"/docs\">Docs</a>\n <a href=\"/economics\">Economics</a>\n <a href=\"https://github.com/stuntmanhq/stuntman\" rel=\"noopener\">GitHub</a>\n <a class=\"btn primary cta\" href=\"/docs#start\">Get started</a>\n </nav>\n </div>\n</header>\n\n<!--main--><main id=\"main\">\n <div class=\"wrap page-head\">\n <p class=\"kicker\">Witnessed record</p>\n <h1>Agent records</h1>\n <p class=\"lede\">Every witnessed agent has a public record at stuntmanhq.xyz/a/ followed by its address.</p>\n </div>\n <div class=\"wrap record\"><a class=\"btn\" href=\"/leaderboard\">See the leaderboard</a></div>\n</main><!--/main-->\n\n<footer class=\"site-footer\">\n <div class=\"wrap\">\n <div class=\"footer-token\">\n <span class=\"ticker\">$STUNT</span>\n <a class=\"ca\" href=\"https://robinhoodchain.blockscout.com/token/0xfadcdbb63b0326a772e18c5955028f2c23e81651\" rel=\"noopener\" aria-label=\"$STUNT contract on the Robinhood Chain explorer\">0xfadcdbb63b0326a772e18c5955028f2c23e81651</a>\n <button class=\"copy ca-copy\" type=\"button\" data-copy=\"0xfadcdbb63b0326a772e18c5955028f2c23e81651\" aria-label=\"Copy the $STUNT contract address\">Copy</button>\n </div>\n <span>&copy; <span data-year>2026</span> Stuntman. Practice mode for AI agents.</span>\n <nav aria-label=\"Footer\">\n <a href=\"/docs\">Docs</a>\n <a href=\"/witness\">Witness</a>\n <a href=\"/leaderboard\">Leaderboard</a>\n <a href=\"/economics\">Economics</a>\n <a href=\"https://github.com/stuntmanhq/stuntman\" rel=\"noopener\">GitHub</a>\n <a href=\"https://www.npmjs.com/package/stuntman\" rel=\"noopener\">npm</a>\n <a href=\"https://x.com/stuntmanhq\" rel=\"noopener\">X</a>\n <a href=\"/terms\">Terms</a>\n <a href=\"/privacy\">Privacy</a>\n </nav>\n </div>\n</footer>\n</body>\n</html>\n";
package/dist/version.js CHANGED
@@ -1 +1,3 @@
1
- export const VERSION = '0.2.3';
1
+ // The version comes from package.json, so the CLI always reports the release it shipped in.
2
+ import { createRequire } from 'node:module';
3
+ export const VERSION = createRequire(import.meta.url)('../package.json').version;
package/dist/witness.js CHANGED
@@ -8,7 +8,7 @@
8
8
  // StuntmanCredits contract. Once a day the operator settles: it puts the root
9
9
  // of every take witnessed since the last settlement on chain and collects the
10
10
  // charges, part burned and part to the treasury.
11
- import { concat, createWalletClient, decodeFunctionResult, defineChain, encodeFunctionData, http, keccak256, parseUnits, toBytes, verifyMessage, } from 'viem';
11
+ import { concat, getAddress, createWalletClient, decodeFunctionResult, defineChain, encodeFunctionData, http, keccak256, parseUnits, toBytes, verifyMessage, } from 'viem';
12
12
  import { privateKeyToAccount } from 'viem/accounts';
13
13
  import { randomBytes } from 'node:crypto';
14
14
  import { DEFAULT_CHAIN_ID, DEFAULT_RPC_URL } from './config.js';
@@ -17,6 +17,8 @@ import { createEngine, fund } from './engine.js';
17
17
  import { hashToObject } from './kv.js';
18
18
  import { launchSettings } from './launch.js';
19
19
  import { handle } from './proxy.js';
20
+ import { emptyBook, handleAttesta } from './attesta.js';
21
+ import { USDG } from './bull.js';
20
22
  import { RpcClient } from './rpc.js';
21
23
  import { withMemoryStore } from './store.js';
22
24
  export class WitnessError extends Error {
@@ -601,3 +603,73 @@ export async function settle(env) {
601
603
  await unlock();
602
604
  }
603
605
  }
606
+ // ---------- Attesta practice API, witnessed ----------
607
+ /**
608
+ * The Attesta practice API on a witness endpoint (/w/<key>/attesta/v1/...).
609
+ * Its jobs live with the agent's witness record, and its stream checks read
610
+ * the agent's witnessed takes.
611
+ */
612
+ export async function witnessAttesta(env, secret, method, path, query, headers, body) {
613
+ const account = /^[0-9a-f]{48}$/.test(secret) ? await env.kv.cmd('GET', `w:key:${secret}`) : null;
614
+ if (!account)
615
+ return { status: 404, body: { error: { code: 'unknown_endpoint', message: 'Unknown witness endpoint. Run `stuntman witness` to get one.' } } };
616
+ const ctx = {
617
+ account,
618
+ chainId: env.chainId,
619
+ async readBook() {
620
+ const raw = await env.kv.cmd('GET', `w:attesta:${account}`);
621
+ return raw ? { ...emptyBook(), ...JSON.parse(raw) } : emptyBook();
622
+ },
623
+ async writeBook(book) {
624
+ await env.kv.cmd('SET', `w:attesta:${account}`, JSON.stringify(book));
625
+ },
626
+ async takes(hashes) {
627
+ const recent = ((await env.kv.cmd('LRANGE', `w:takes:${account}`, -RECENT, -1)) ?? []).map((r) => JSON.parse(r).take);
628
+ const older = [];
629
+ for (const h of hashes.slice(0, 10)) {
630
+ if (!/^0x[0-9a-fA-F]{64}$/.test(h) || recent.some((t) => lower(t.txHash) === lower(h)))
631
+ continue;
632
+ const rec = await env.kv.cmd('GET', `w:tx:${lower(h)}`);
633
+ if (rec)
634
+ older.push(JSON.parse(rec).take);
635
+ }
636
+ return [...older, ...recent].filter((t) => lower(t.account) === lower(account));
637
+ },
638
+ async credit(raw) {
639
+ const out = (await witnessRpc(env, secret, { jsonrpc: '2.0', id: 1, method: 'stuntman_fund', params: [USDG, raw.toString()] }));
640
+ if (out?.error)
641
+ throw new Error(out.error.message);
642
+ },
643
+ fetcher: env.fetcher,
644
+ };
645
+ return handleAttesta(ctx, method, path, query, headers, body);
646
+ }
647
+ // ---------- public pages ----------
648
+ /** One take on an agent's record, by its take number. */
649
+ export async function agentTake(env, address, id) {
650
+ if (!isAddress(address) || !Number.isInteger(id) || id < 1)
651
+ return null;
652
+ const a = lower(address);
653
+ const toView = (raw) => {
654
+ const { take, witnessed } = JSON.parse(raw);
655
+ return { ...witnessed, take: { id: take.id, status: take.status, summary: take.summary, reason: take.reason, txHash: take.txHash, blockNumber: take.blockNumber, at: take.at } };
656
+ };
657
+ // Takes are appended in order, so take n is usually entry n-1; scan nearby if not.
658
+ const near = ((await env.kv.cmd('LRANGE', `w:takes:${a}`, Math.max(0, id - 25), id + 25)) ?? []).map(toView);
659
+ return near.find((t) => t.take.id === id) ?? null;
660
+ }
661
+ /** Witnessed agents with at least `min` takes, ranked by filled takes. */
662
+ export async function leaderboard(env, min = 5, limit = 100) {
663
+ const members = ((await env.kv.cmd('SMEMBERS', 'w:agents')) ?? []).slice(0, 2000);
664
+ if (!members.length)
665
+ return [];
666
+ const hashes = (await env.kv.pipeline(members.map((m) => ['HGETALL', `w:agent:${m}`])));
667
+ return hashes
668
+ .map((h, i) => {
669
+ const o = hashToObject(h);
670
+ return { account: getAddress(members[i]), simulated: Number(o.simulated ?? 0), filled: Number(o.filled ?? 0), reverted: Number(o.reverted ?? 0), last: o.last ?? null };
671
+ })
672
+ .filter((r) => r.simulated >= min)
673
+ .sort((x, y) => y.filled - x.filled || x.reverted - y.reverted || (y.last ?? '').localeCompare(x.last ?? ''))
674
+ .slice(0, limit);
675
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stuntman",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
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": {
@@ -9,7 +9,8 @@
9
9
  "files": [
10
10
  "dist",
11
11
  "README.md",
12
- "LICENSE"
12
+ "LICENSE",
13
+ "skills"
13
14
  ],
14
15
  "engines": {
15
16
  "node": ">=20"
@@ -30,7 +31,10 @@
30
31
  "robinhood-chain",
31
32
  "evm",
32
33
  "dry-run",
33
- "agent-wallet"
34
+ "agent-wallet",
35
+ "openai-agents",
36
+ "langchain",
37
+ "coinbase-agentkit"
34
38
  ],
35
39
  "author": "stuntmanhq",
36
40
  "license": "MIT",
@@ -50,8 +54,11 @@
50
54
  "devDependencies": {
51
55
  "@coinbase/agentkit": "^0.10.4",
52
56
  "@foundry-rs/anvil": "^1.7.1",
57
+ "@langchain/core": "^1.5.2",
58
+ "@openai/agents": "^0.23.1",
53
59
  "@types/node": "^26.6.11",
54
60
  "@virtuals-protocol/game": "^0.1.14",
61
+ "langchain": "^1.6.10",
55
62
  "solc": "^0.8.39",
56
63
  "typescript": "^7.0.2"
57
64
  },
@@ -59,11 +66,15 @@
59
66
  "./game": "./dist/game.js",
60
67
  "./eliza": "./dist/eliza.js",
61
68
  "./agentkit": "./dist/agentkit.js",
69
+ "./openai": "./dist/openai.js",
70
+ "./langchain": "./dist/langchain.js",
62
71
  "./package.json": "./package.json"
63
72
  },
64
73
  "peerDependencies": {
74
+ "@coinbase/agentkit": ">=0.10.0",
65
75
  "@virtuals-protocol/game": ">=0.1.14",
66
- "@coinbase/agentkit": ">=0.10.0"
76
+ "@openai/agents": ">=0.23.0",
77
+ "@langchain/core": ">=1.0.0"
67
78
  },
68
79
  "peerDependenciesMeta": {
69
80
  "@virtuals-protocol/game": {
@@ -71,6 +82,12 @@
71
82
  },
72
83
  "@coinbase/agentkit": {
73
84
  "optional": true
85
+ },
86
+ "@openai/agents": {
87
+ "optional": true
88
+ },
89
+ "@langchain/core": {
90
+ "optional": true
74
91
  }
75
92
  }
76
93
  }
@@ -0,0 +1,67 @@
1
+ ---
2
+ name: stuntman
3
+ description: "Needs the stuntman CLI (npm package stuntman). Practice trades on Robinhood Chain before they are real: simulated at the latest block with real prices and practice money, never broadcast, optionally witnessed on a public record."
4
+ version: 0.2.5
5
+ homepage: https://stuntmanhq.xyz
6
+ metadata:
7
+ openclaw:
8
+ requires:
9
+ bins:
10
+ - stuntman
11
+ install:
12
+ - kind: node
13
+ package: stuntman
14
+ bins: [stuntman]
15
+ ---
16
+
17
+ # Stuntman: practice before it's real
18
+
19
+ Use this skill whenever the user wants you to trade, swap, send or deploy anything on Robinhood Chain and has not clearly said to do it for real. Practice first. A practice take uses real apps at real prices with practice money, and nothing is ever broadcast.
20
+
21
+ ## First run
22
+
23
+ Check the setup:
24
+
25
+ ```
26
+ stuntman status
27
+ ```
28
+
29
+ If it says there is no setup yet, create a practice account with 1 practice ETH:
30
+
31
+ ```
32
+ stuntman init --new --eth 1
33
+ ```
34
+
35
+ ## Everyday commands
36
+
37
+ | Goal | Command |
38
+ | --- | --- |
39
+ | Practice balances | `stuntman balances` |
40
+ | Add practice money | `stuntman fund ETH 1` or `stuntman fund <token address> 250` |
41
+ | Practice a transaction | `stuntman send --to <address> --value <eth> --data <0x calldata>` |
42
+ | Recent takes | `stuntman takes --limit 10` |
43
+ | One take in detail | `stuntman take <id>` |
44
+ | Readiness to go live | `stuntman status` |
45
+
46
+ `stuntman send` prints the take: whether it filled or failed, every balance change, gas, and the reason for a failure (for example "Too little received"). A non-zero exit code means the take did not fill.
47
+
48
+ ## Witnessed practice (public record)
49
+
50
+ If the user wants a record others can check:
51
+
52
+ ```
53
+ stuntman witness
54
+ ```
55
+
56
+ From then on every take is simulated and signed by Stuntman's server and kept on a public record at `https://stuntmanhq.xyz/a/<address>`. The first 25 witnessed takes are free; after that each take costs a small fee in $STUNT from credit the user tops up at https://stuntmanhq.xyz/witness. Tell the user about the fee before turning witness mode on. `stuntman witness off` goes back to local practice.
57
+
58
+ ## Rules
59
+
60
+ - Never describe a practice result as a real trade. Say "practice take" and mention that nothing was broadcast.
61
+ - Practice money is not real money. Don't report practice balances as the user's funds.
62
+ - If a take fails, report the reason Stuntman gives and suggest a fix (more slippage, an approval first, more practice money) before trying again.
63
+ - Going live is the user's decision. `stuntman status` shows the go-live checklist; share it rather than deciding for them.
64
+
65
+ ## Agents with their own wallet tools
66
+
67
+ Stuntman also runs as an MCP server (`stuntman mcp`) with wallet tools (send_transaction, get_balances, list_takes and more), and as a drop-in RPC (`stuntman rpc`, then use http://127.0.0.1:8545). `stuntman connect` prints the setup lines.