Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2f90047
Accept MPP method tempo (push mode) when MPP_TEMPO_RECIPIENT is set
claude Oct 4, 2026
6ada795
Clearer /api/explain description for agents
claude Oct 5, 2026
e2c21e4
Merge remote branch (already merged history)
claude Oct 5, 2026
57e398c
Add glama.json to claim the Glama listing
claude Oct 5, 2026
88577ee
Merge remote branch (already merged history)
claude Oct 5, 2026
2eeeeec
MCP registry: clearer description (says when an agent would use it)
claude Oct 5, 2026
ce242d7
Merge remote branch (already merged history)
claude Oct 5, 2026
71f6a3e
Homepage: a row of prices right under the intro
claude Oct 6, 2026
fd7ae48
Merge remote branch (already merged history)
claude Oct 6, 2026
193799b
Usage log: record the network a refused payment was tried on
claude Oct 6, 2026
2d888e4
Merge branch 'claude/x402-agents-solana-payments-nceg9b' of https://g…
claude Oct 6, 2026
322505c
Pay in RLUSD on the XRP Ledger (x402 exact, xrpl:0)
claude Oct 7, 2026
aa35a9d
Merge branch 'claude/x402-agents-solana-payments-nceg9b' of https://g…
claude Oct 7, 2026
633f050
XRPL: also accept payers built on t54's SDK
claude Oct 7, 2026
3033055
Merge remote-tracking branch 'origin/main' into claude/x402-agents-so…
claude Oct 7, 2026
fdab3b3
SEO: canonical tag, robots.txt and sitemap.xml for the homepage
claude Oct 7, 2026
0027283
Merge branch 'claude/x402-agents-solana-payments-nceg9b' of https://g…
claude Oct 7, 2026
823b132
CI: run the tests on every pull request and on main
claude Oct 7, 2026
60e2caa
Merge branch 'claude/x402-agents-solana-payments-nceg9b' of https://g…
claude Oct 7, 2026
d81e01e
Usage log: record why an MPP credential was refused
claude Oct 7, 2026
7a491d3
Merge branch 'claude/x402-agents-solana-payments-nceg9b' of https://g…
claude Oct 7, 2026
84c2f4e
Pay in USDC on Algorand (ALGORAND_PAY_TO)
claude Oct 8, 2026
a6cec2a
Merge remote branch
claude Oct 8, 2026
aa499c8
Name the seller in the 402: x402-merchant extension
claude Oct 9, 2026
7ec7ce1
Merge remote branch (already in main)
claude Oct 9, 2026
9c7b5d0
MCP: output schemas and structured content on every tool
claude Oct 9, 2026
3fdf50f
Merge remote branch (already in main)
claude Oct 9, 2026
80dd8e2
Merge stale remote branch claude/x402-agents-solana-payments-nceg9b
claude Oct 13, 2026
725218e
Discovery: a name and description per resource in /.well-known/x402
claude Oct 13, 2026
97ffd96
Merge stale remote branch claude/x402-agents-solana-payments-nceg9b
claude Oct 13, 2026
775fa73
Security headers on every answer
claude Oct 13, 2026
f2ea313
Merge stale remote branch claude/x402-agents-solana-payments-nceg9b
claude Oct 13, 2026
3ff3a26
Weekly dependency audit with one issue while a finding is open
claude Oct 13, 2026
5aba932
Merge stale remote branch claude/x402-agents-solana-payments-nceg9b
claude Oct 13, 2026
95976ef
Usage log: say why an x402 payment was refused
claude Oct 13, 2026
915ba79
Merge stale remote branch claude/x402-agents-solana-payments-nceg9b
claude Oct 14, 2026
aa20d90
Usage log: write in batches (at most every 10 minutes) and read the d…
claude Oct 14, 2026
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
24 changes: 24 additions & 0 deletions test/usage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,27 @@ test('usage log: an MCP reply sent as an event stream is read (the verdict is lo
assert.equal(e.route, 'check_wallet_approvals');
assert.deepEqual(e.result, { verdict: 'RISK' });
});

test('usage log: writes are batched (one read and one write for several calls), and a day file over 1 MB keeps its lines', async () => {
const { createUsageLog } = require('../usage-log');
const path = 'events/plaintext/2026-10-14.jsonl';
const old = `${'x'.repeat(1100 * 1024)}\n`;
let file = old;
const calls = [];
const fetchFn = async (url, opts = {}) => {
const method = opts.method || 'GET';
calls.push(`${method} ${new URL(url).pathname}`);
// Like GitHub: the JSON form has no content for files over 1 MB, the raw form has the bytes.
if (method === 'GET') return /raw/.test(opts.headers?.accept || '') ? new Response(file) : Response.json({ sha: 'x', content: '' });
file = Buffer.from(JSON.parse(opts.body).content, 'base64').toString('utf8');
return Response.json({}, { status: 200 });
};
const log = createUsageLog({ service: 'plaintext', env: { USAGE_LOG_TOKEN: 't' }, fetchFn, now: () => new Date('2026-10-14T10:00:00Z'), log: { warn() {}, error() {} } });
log.record({ route: 'check-wallet', status: 402 });
log.record({ route: 'explain', status: 200 });
assert.equal(calls.length, 0, 'nothing written until the flush');
await log.flush();
assert.ok(file.startsWith(old), 'the old lines are still there');
assert.equal(file.slice(old.length).trim().split('\n').length, 2);
assert.deepEqual(calls, [`GET /repos/Fizzl13/usage-log/contents/${path}`, `PUT /repos/Fizzl13/usage-log/contents/${path}`]);
});
33 changes: 27 additions & 6 deletions usage-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

const crypto = require('node:crypto');

// Git's blob id of a file's bytes: what the contents API calls its sha.
const blobSha = (buf) => crypto.createHash('sha1').update(`blob ${buf.length}\0`).update(buf).digest('hex');
const MAX_QUEUE = 200;
// Tests pass their own fetch; only the real service exits on SIGTERM.
const fetchFnGiven = (fn) => fn !== globalThis.fetch;

const DEFAULT_REPO = 'Fizzl13/usage-log';
const API = 'https://api.github.com';
const MAX_TEXT = 300;
Expand Down Expand Up @@ -141,12 +147,20 @@ function x402Refusal(res) {
return null;
}

function createUsageLog({ service, env = process.env, fetchFn = globalThis.fetch, now = () => new Date(), log = console } = {}) {
function createUsageLog({ service, env = process.env, fetchFn = globalThis.fetch, now = () => new Date(), log = console, flushDelayMs = 10 * 60 * 1000, exitOnSignal = !fetchFnGiven(fetchFn) } = {}) {
const token = env.USAGE_LOG_TOKEN;
const repo = env.USAGE_LOG_REPO || DEFAULT_REPO;
const visitorSecret = env.USAGE_LOG_SALT || token;
const queue = [];
let flushing = null;
let timer = null;
// Every write re-sends the whole day file to GitHub, so writes are batched: at most one per flushMs
// (USAGE_LOG_FLUSH_MS, default 10 minutes). On shutdown (a deploy, or the free plan going to sleep) the queue is
// written first.
const flushMs = Number(env.USAGE_LOG_FLUSH_MS) || flushDelayMs;
if (token && exitOnSignal) {
process.once('SIGTERM', () => { flush().finally(() => process.exit(0)); });
}
let warned = false;

const headers = {
Expand All @@ -160,13 +174,15 @@ function createUsageLog({ service, env = process.env, fetchFn = globalThis.fetch
async function append(path, lines) {
for (let attempt = 0; attempt < 4; attempt++) {
const url = `${API}/repos/${repo}/contents/${path}`;
const current = await fetchFn(url, { headers });
// The raw file: the JSON form leaves out the content of files over 1 MB, which would then be overwritten
// with only the new lines. The sha GitHub wants back is the git blob sha of exactly these bytes.
const current = await fetchFn(url, { headers: { ...headers, accept: 'application/vnd.github.raw+json' } });
let sha;
let text = '';
if (current.status === 200) {
const file = await current.json();
sha = file.sha;
text = Buffer.from(file.content || '', 'base64').toString('utf8');
const raw = Buffer.from(await current.arrayBuffer());
sha = blobSha(raw);
text = raw.toString('utf8');
} else if (current.status !== 404) {
throw new Error(`read ${path}: HTTP ${current.status}`);
}
Expand All @@ -184,6 +200,7 @@ function createUsageLog({ service, env = process.env, fetchFn = globalThis.fetch
}

async function flush() {
if (timer) { clearTimeout(timer); timer = null; }
if (flushing) return flushing;
flushing = (async () => {
while (queue.length) {
Expand Down Expand Up @@ -215,7 +232,11 @@ function createUsageLog({ service, env = process.env, fetchFn = globalThis.fetch
return;
}
queue.push({ t: now().toISOString(), service, ...event, input: clipAll(event.input), result: clipAll(event.result) });
flush();
if (queue.length >= MAX_QUEUE) flush();
else if (!timer) {
timer = setTimeout(() => { timer = null; flush(); }, flushMs);
timer.unref?.();
}
}

// Express middleware. describe(req, res, body) returns { route, input, result, via, payment? }
Expand Down
Loading