Repository navigation
feat(examples): daily-budget policy engine for the pre-sign hook (#127) - #146
Conversation
|
@Eras256 un recordatorio amable 🙌 Tengo dos PRs listos para review, con CI en verde donde aplica:
Además ya tengo listos en local el #144 (CI para packages/mcp) y el #145 (Dependabot). No los abro todavía para no saturarte, salvo que prefieras que los suba ya. ¡Gracias! |
|
Reviewed, this is ready. The atomic One small thing before I merge: the last line of the README links to AgentLedger. Since it's your product, could you add a short disclosure so readers know? Something like: see [AgentLedger](https://useagentledger.xyz) (disclosure: built by the author of this example).Push that and I'll merge right away. Thanks! Drafted with AI assistance (Claude Opus 5.5) and reviewed by Giovanny. |
…ium-protocol#127) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
35332d1 to
edb8356
Compare
Eras256
left a comment
There was a problem hiding this comment.
Disclosure added, thanks. Merging.
🤖 Generated with Claude Code
Adds
examples/x402-policy-daily-budget/: a per-agent daily spend cap for the pre-sign policy hook (initX402({ policy })). This PR only adds files underexamples/and does not touch the hook.How each "Done when" item is met
src/budget-store.tstryCommitchecksspent + amount <= capand writes the new total in one synchronous step, with noawaitbetween the read and the write. The README and the source show the multi-process version as one conditional SQLUPDATE … WHERE spent + $amt <= $cap(0 rows means DENY).ctx.contextHash, includespolicyVersion, and setsexpiresAt = now + ttlMs(2 s by default).hook()wirescurrentVersionand setsrequireExpiry: true.update()bumps the version, so the SDK refuses an earlier ALLOW withSTALE.test/daily-budget-policy.test.ts): ALLOW; DENY over the cap (nothing committed); a concurrent pair where exactly one passes; 50 concurrent requests that never overspend; a stale policy version; caps per agent and per UTC day; non-integer and non-positive amounts.What it does not solve
Test results (Node 22.23.3, npm 10; SDK built as in CI)
npm ci: OKnpm test: 7 tests, 7 pass, 0 failnpm run typecheck: no errorsnpm start:600000 => ALLOW,600000 => DENY (daily cap exceeded),400000 => ALLOWCloses #127