Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ flowchart LR
A[c16ab56 monolith] --> B[0.76.0-alpha.1 wallet repository staging]
```

## Unreleased — instant-wallet first-call wording (2026-10-28)

- Remove the duplicate `operator_admission_budget_exhausted` reason key: the later payment text ("same request_id") overwrote the creation text, and a new inner wallet creation has no request id to repeat (live 2026-10-28, `src/mcp-wallet-tool.mjs:81`, `:91`).
- Tool description, `balance` action, `new` and `wallet_key` now state the instant first call: `balance` with `new:true`, no `wallet_key`, no session, no signup; `wallet_key` always only after the first answer (`src/mcp-wallet-tool.mjs:124,129-130,141`).
- Bare `balance` (`askFirst`) names that exact call instead of asking "new or existing?" (`src/mcp-wallet-merge.mjs:36-37`).
- `scripts/check-wallet-ask.mjs` asserts the single reason mapping, the creation-correct sentence without `request_id`, and the instant-call wording in schema and bare answer.

## Unreleased — wallet ask with session (2026-10-18)

- wallet ask accepts the person's session as well as a wallet_key, like pay does (live 2026-10-18: a connected person got 'Ask needs wallet_key').
Expand Down
4 changes: 4 additions & 0 deletions PROMPTLOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Prompt log

## 2026-10-28 — Emin via Hermes parent; implementer Hermes worker

- "The first live instant-wallet call failed with payment retry advice and tools-only models asked new/existing; fix the duplicate reason key and make the schema name the instant first call." Diagnosis `wallet-agent-diagnosis/VERDICT.md` at live SHA `9513a44339cd`; mechanical text only, no `create` action, no auto-create, no custody or capacity change.


## 2026-10-17 — Emin; recorded by Hermes

Expand Down
80 changes: 72 additions & 8 deletions scripts/check-wallet-ask.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,26 @@ const SELLER = '0x2222222222222222222222222222222222222222';
const USDC = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
const KEY = 'A'.repeat(44); // Synthetic, never usable as a real wallet credential.
assert.equal(KEY.length, 44);
const state = { signatures: 0, payments: 0, calls: [], invoices: new Map(), nonces: new Set(), receipts: new Map(), loseBody: false, badAnswer: false, recovery402: false };
const state = { signatures: 0, payments: 0, calls: [], invoices: new Map(), nonces: new Set(), receipts: new Map(), loseBody: false, badAnswer: false, recovery402: false, block: 100n, noReceipt: false, wrongNonce: false, badTransfer: null };
globalThis.fetch = async () => { throw new Error('Unexpected network access in offline ask check'); };
mock.module('viem', { namedExports: { ...viem, createPublicClient: () => ({
getChainId: async () => 8453,
getBlockNumber: async () => 100n,
getBlockNumber: async () => state.block,
getLogs: async ({ address, args, fromBlock, toBlock }) => {
assert.equal(address, USDC); assert.deepEqual(args, { from: SAFE, to: SELLER });
return [...state.receipts.values()].filter(r => r.blockNumber >= fromBlock && r.blockNumber <= toBlock)
.map(r => ({ transactionHash: r.transactionHash, args: { value: 2070n }, removed: false }));
},
getCode: async () => '0x01',
readContract: async ({ functionName, args }) => {
if (functionName === 'balanceOf') return 1000000n;
if (functionName === 'permissionConfig') return { signer: SAFE };
if (functionName === 'authorizationState') return state.nonces.has(args[1]);
throw new Error(`Unexpected fake RPC: ${functionName}`);
},
waitForTransactionReceipt: async ({ hash }) => {
getTransaction: async ({ hash }) => state.receipts.get(hash).transaction,
waitForTransactionReceipt: async ({ hash, confirmations }) => {
assert.equal(confirmations, 2);
assert.ok(state.receipts.has(hash), 'Only known synthetic settlements may confirm');
return state.receipts.get(hash);
},
Expand All @@ -42,9 +49,10 @@ mock.module('../src/agent-kernel-wallet.mjs', { namedExports: { ...kernel,
mock.module('../src/privy-agent-app-signer.mjs', { namedExports: { ...privy, connectedSafeAgentSigner: async () => ({ address: SAFE }) } });
mock.module('../src/safe-pay-relay.mjs', { namedExports: { ...relay, safeSignatureAccepted: async () => true } });
const { createKernelRuntime } = await import('../src/agent-kernel-runtime.mjs');
const { createMcpWalletTool, ASK_URL, ASK_MODELS } = await import('../src/mcp-wallet-tool.mjs');
const { createMcpWalletTool, WALLET_TOOL, ASK_URL, ASK_MODELS } = await import('../src/mcp-wallet-tool.mjs');
const { decimalToUnits } = await import('../src/wallet-units.mjs');
const { instructions } = await import('../src/mcp-instructions.mjs');
const { askFirst } = await import('../src/mcp-wallet-merge.mjs');

async function fakeRouter(url, headers, onHeaders, shape) {
assert.equal(url, ASK_URL);
Expand Down Expand Up @@ -73,11 +81,22 @@ async function fakeRouter(url, headers, onHeaders, shape) {
state.payments++;
const tx = `0x${state.payments.toString(16).padStart(64, '0')}`;
invoice.receipt = { success: true, network: 'eip155:8453', transaction: tx, payer: SAFE };
state.receipts.set(tx, { transactionHash: tx, status: 'success', blockNumber: 101n, logs: [{
state.block += 2n;
state.receipts.set(tx, { transactionHash: tx, status: 'success', blockNumber: state.block, logs: [{
address: state.badTransfer === 'asset' ? SELLER : USDC,
topics: viem.encodeEventTopics({ abi: viem.parseAbi(['event Transfer(address indexed from,address indexed to,uint256 value)']), eventName: 'Transfer', args: { from: SAFE, to: state.badTransfer === 'to' ? SAFE : SELLER } }),
data: viem.encodeAbiParameters([{ type: 'uint256' }], [state.badTransfer === 'amount' ? 2071n : 2070n]),
}, {
address: USDC,
topics: viem.encodeEventTopics({ abi: viem.parseAbi(['event Transfer(address indexed from,address indexed to,uint256 value)']), eventName: 'Transfer', args: { from: SAFE, to: SELLER } }),
data: viem.encodeAbiParameters([{ type: 'uint256' }], [2070n]),
topics: viem.encodeEventTopics({ abi: viem.parseAbi(['event AuthorizationUsed(address indexed authorizer,bytes32 indexed nonce)']), eventName: 'AuthorizationUsed',
args: { authorizer: SAFE, nonce: state.wrongNonce ? `0x${'ff'.repeat(32)}` : payment.payload.authorization.nonce } }), data: '0x',
}] });
if (state.badTransfer === 'missing-event-unrelated-tx') {
const receipt = state.receipts.get(tx);
receipt.logs.pop();
receipt.transaction = { to: USDC, input: viem.encodeFunctionData({
abi: viem.parseAbi(['function transfer(address,uint256) returns(bool)']), functionName: 'transfer', args: [SELLER, 2070n] }) };
}
}
if (!invoice.paid || (!signature && state.recovery402)) {
const required = { x402Version: 2, resource: { url: `${ASK_URL}?invoice=${id}`, mimeType: 'application/json' }, accepts: [{
Expand All @@ -86,7 +105,7 @@ async function fakeRouter(url, headers, onHeaders, shape) {
}] };
return { status: 402, headers: { 'payment-required': Buffer.from(JSON.stringify(required)).toString('base64') }, bytes: Buffer.from('{}') };
}
const responseHeaders = { 'content-type': 'application/json', 'payment-response': Buffer.from(JSON.stringify(invoice.receipt)).toString('base64') };
const responseHeaders = { 'content-type': 'application/json', ...(!state.noReceipt ? { 'payment-response': Buffer.from(JSON.stringify(invoice.receipt)).toString('base64') } : {}) };
onHeaders?.(200, responseHeaders);
if (signature && state.loseBody) { state.loseBody = false; throw new Error('Synthetic disconnect after settlement headers'); }
return { status: 200, headers: responseHeaders, bytes: Buffer.from(JSON.stringify(invoice.answer)) };
Expand Down Expand Up @@ -151,6 +170,25 @@ try {
assert.equal(refused.ok, false);
assert.match(refused.error, /send again with a NEW request_id and a higher max_amount/);
assert.ok(instructions(['wallet']).includes('NEW request_id and a higher max_amount'));
// Live 2026-10-28: creation refusals are not payment retries. A duplicate reason key at the
// payment block silently replaced the creation text with "same request_id" advice, and creation
// has no request ID to reuse. Schema and bare-balance answer must name the instant first call.
const toolSource = readFileSync(new URL('../src/mcp-wallet-tool.mjs', import.meta.url), 'utf8');
assert.equal(toolSource.split('operator_admission_budget_exhausted:').length - 1, 1, 'Reason key must be mapped once');
const admission = toolSource.split('\n').find(line => line.includes('operator_admission_budget_exhausted:'));
assert.match(admission, /No new wallet can be opened right now/);
assert.doesNotMatch(admission, /request_id/);
const instant = 'call balance with new:true and no wallet_key or session';
assert.ok(WALLET_TOOL.description.includes(instant), 'Tool description must name the instant first call');
assert.match(WALLET_TOOL.description, /After the first answer, always send wallet_key/);
assert.match(WALLET_TOOL.inputSchema.properties.new.description, /First call only/);
assert.match(WALLET_TOOL.inputSchema.properties.action.description, /new:true it opens an instant wallet/);
assert.match(WALLET_TOOL.inputSchema.properties.wallet_key.description, /Not needed on the first call/);
const bare = await askFirst();
assert.ok(bare.next.includes('call wallet {action:"balance", new:true}'), bare.next);
assert.match(bare.next, /no wallet_key and no session; no signup/);
assert.match(bare.next, /After the first answer, always send wallet_key/);
assert.doesNotMatch(bare.next, /new or existing/);
assert.equal(state.payments, 1);
assert.equal(state.signatures, 1, 'Over-cap invoice must be rejected before signing');
const failed = runtime.history(row.id).find(op => op.reason === 'payment_exceeds_max_amount');
Expand Down Expand Up @@ -192,6 +230,32 @@ try {
assert.match(empty.error, /no answer/);
assert.ok(empty.receipt);
assert.deepEqual(await tool.call(emptyArgs), empty);
state.noReceipt = true; state.badAnswer = false;
const pay = { action: 'pay', wallet_key: KEY, url: ASK_URL, method: 'POST',
body: { messages: [{ role: 'user', content: 'Receipt-free payment' }], model: ASK_MODELS.fast, stream: false }, max_amount: '0.05' };
const discovered = await tool.call({ ...pay, request_id: 'receipt-free' });
assert.equal(discovered.status, 'done', JSON.stringify(discovered));
assert.ok(runtime.history(row.id).some(op => op.status === 'paid' && op.settlement === 'chain_discovered'));
const count = state.payments;
tool.close(); tool = openTool();
assert.deepEqual(await tool.call({ ...pay, request_id: 'receipt-free' }), discovered);
assert.equal(state.payments, count, 'Discovered settlement is durable; replay never repays');
for (const mismatch of ['nonce', 'missing-event-unrelated-tx', 'asset', 'to', 'amount']) {
state.wrongNonce = mismatch === 'nonce'; state.badTransfer = mismatch;
const unverified = await tool.call({ ...pay, request_id: `receipt-free-wrong-${mismatch}` });
assert.equal(unverified.status, 'delivered_unverified', JSON.stringify(unverified));
assert.ok(unverified.resource); assert.match(unverified.next, /settlement is not confirmed/);
assert.ok(runtime.history(row.id).some(op => op.status === 'unknown' && op.reason === 'settlement_unconfirmed'));
// Supply the missing evidence and reconcile the same request before another spend.
const receipt = [...state.receipts.values()].at(-1);
receipt.logs[0] = { ...receipt.logs[0], address: USDC,
topics: viem.encodeEventTopics({ abi: viem.parseAbi(['event Transfer(address indexed from,address indexed to,uint256 value)']), eventName: 'Transfer', args: { from: SAFE, to: SELLER } }),
data: viem.encodeAbiParameters([{ type: 'uint256' }], [2070n]) };
const authorization = JSON.parse(Buffer.from(state.calls.at(-1).headers['PAYMENT-SIGNATURE'], 'base64').toString()).payload.authorization;
receipt.logs[1] = { address: USDC, data: '0x', topics: viem.encodeEventTopics({ abi: viem.parseAbi(['event AuthorizationUsed(address indexed authorizer,bytes32 indexed nonce)']), eventName: 'AuthorizationUsed', args: { authorizer: SAFE, nonce: authorization.nonce } }) };
assert.equal((await tool.call({ ...pay, request_id: `receipt-free-wrong-${mismatch}` })).status, 'done');
}
console.log('settlement fallback ok: receipt-free -> chain_discovered/paid; durable replay; wrong nonce/asset/payTo/amount stay unknown and surface delivered_unverified content; 2 confirmations required');
console.log(`wallet ask ok: 402 -> signed 200; ${state.payments} synthetic payments; cap rejects before signing; new-id higher-cap retry; durable replay; fast/smart; lost-body recovery without payment; validation and malformed answer`);
const runtimeSource = readFileSync(new URL('../src/agent-kernel-runtime.mjs', import.meta.url), 'utf8');
assert.ok(runtimeSource.includes('url === ROUTER_CHAT_URL ? 190000 : 20000'), 'Router receives a generation-sized bounded timeout');
Expand Down
Loading
Loading