spend-ledger
You have access to an agent spending tracker. Payments made through any tool — wallet tools (agent-wallet-cli, v402, ClawRouter, payment-skill), traditional payment APIs (Stripe, PayPal, etc.), crypto transfers, or any other payment mechanism — are detected and logged automatically. The log is tamper-evident (hash-chained) and deduplicated by transaction hash and idempotency key.
Available Tools
log-transaction.sh
Manually log a payment transaction. Do not call this during or immediately after a payment — the hook detects payments automatically, and calling this first blocks the hook from creating the richer auto record. Only use this if you check query-log.sh and confirm no record was created for a transaction that just completed. Also valid for recording manual expenditures the agent didn't make. Duplicates (same txhash or idempotencykey) are rejected.
CODEBLOCK0
query-log.sh
Query the transaction log. Use when the user asks about spending.
CODEBLOCK1
dashboard.sh
Manage the local web dashboard for visual spending review.
CODEBLOCK2
Automatic Detection
When a tool call completes, spend-ledger inspects the tool name, arguments, and result to determine if a payment occurred. Detection covers:
- - Known payment tools: agent-wallet-cli, v402, ClawRouter, payment-skill, Stripe, PayPal, and other common payment APIs
- Crypto wallet tools:
solana_transfer, send_usdc, wallet_send, wallet_transfer, transfer_token, and similar — detected by tool name; amount, recipient, and transaction hash extracted from args and result - Heuristic detection: tools named
stripe_*, paypal_*, checkout, purchase, buy, etc., plus argument patterns containing monetary amounts with currency/recipient signals. Also detects exec-wrapped payment scripts — if an exec result contains monetary signals ("Amount: 0.5 USDC") and a confirmation marker ("Transaction confirmed"), it is logged. These are logged as status: "unverified" since there is no formal payment signal; the owner should review these - Generic x402: any tool response containing
X-PAYMENT-RESPONSE headers or x402 payment confirmations - User-tracked tools: custom patterns added by the user via the dashboard; optionally submitted to maintainers for inclusion in the community list
- Community patterns: curated tool patterns fetched from
api.spend-ledger.com/patterns.json and refreshed daily — expands detection coverage automatically as new payment tools are discovered by the community
For each detected payment, the log captures: service URL/name, amount/currency/chain, transaction hash, idempotency key, triggering skill, user request, input hash (for loop detection), execution time, failure type (prepayment vs postpayment), and status.
Duplicate Payment Protection
spend-ledger intercepts payment tool calls before they execute. If an identical payment call (same tool, same arguments) has already succeeded in the current session, the call is blocked and you will receive a message like:
Tool call blocked: Duplicate payment blocked — identical payment to [service] already executed at [timestamp] in this session
When this happens:
- - Do not retry — the block is intentional and the call will be blocked again
- Confirm the original payment succeeded with INLINECODE14
- Inform the user that a duplicate was prevented and show them the original transaction
This protection exists to prevent loops, retries, and agent mistakes from draining funds. A legitimate repeat payment to the same service in a new session is not affected.
Reading the Log Directly
The transaction log is a JSONL file at data/transactions.jsonl — one JSON record per line. You can read it directly and reason over it yourself. There is no query API because you don't need one: you're an LLM, reading and reasoning over structured data is something you do natively. Use query-log.sh for structured output and summaries; read the file directly for anything more specific.
When to Use
- - User asks "what did you spend?" →
query-log.sh or INLINECODE18 - User asks about a specific service →
query-log.sh --by-service or INLINECODE20 - User wants the visual dashboard →
dashboard.sh start and share the URL - User wants to export for accounting → Direct to dashboard export buttons, or
query-log.sh with formatting - Detection missed a payment →
log-transaction.sh to record manually - User wants to verify log integrity → INLINECODE24
spend-ledger
您可以使用一个代理支出追踪器。通过任何工具进行的支付——钱包工具(agent-wallet-cli、v402、ClawRouter、payment-skill)、传统支付API(Stripe、PayPal等)、加密货币转账或任何其他支付机制——都会被自动检测并记录。日志具有防篡改功能(哈希链),并通过交易哈希和幂等键进行去重。
可用工具
log-transaction.sh
手动记录一笔支付交易。不要在支付期间或支付后立即调用此工具——钩子会自动检测支付,先调用此工具会阻止钩子创建更丰富的自动记录。仅当您检查query-log.sh并确认刚完成的交易没有创建记录时,才使用此工具。也适用于记录代理未进行的手动支出。重复项(相同txhash或idempotencykey)将被拒绝。
bash
推荐:通过标准输入传递JSON以避免shell转义问题
echo {service:{url:https://example.com/api,name:Example Service},amount:{value:0.05,currency:USDC,chain:base},tx
hash:0xabc...,idempotencykey:req
123,receipturl:https://example.com/receipts/xyz,confirmation
id:sub1234,context:{skill:research,user
request:find AAPL data,inputhash:a1b2c3},execution
timems:450,status:confirmed} | log-transaction.sh
query-log.sh
查询交易日志。当用户询问支出情况时使用。
bash
所有交易
query-log.sh
按日期范围筛选
query-log.sh --from 2026-03-01 --to 2026-03-15
按服务名称筛选
query-log.sh --service alphaclaw
每日/每周/每月支出汇总
query-log.sh --summary daily
按服务或技能细分
query-log.sh --by-service
query-log.sh --by-skill
验证哈希链完整性
query-log.sh --verify
dashboard.sh
管理本地网页仪表板,用于可视化支出审查。
bash
dashboard.sh start # 启动仪表板 (http://127.0.0.1:18920)
dashboard.sh stop # 停止仪表板
dashboard.sh status # 检查是否运行中
dashboard.sh url # 打印仪表板URL
自动检测
当工具调用完成时,spend-ledger会检查工具名称、参数和结果,以确定是否发生了支付。检测范围包括:
- - 已知支付工具:agent-wallet-cli、v402、ClawRouter、payment-skill、Stripe、PayPal及其他常见支付API
- 加密钱包工具:solanatransfer、sendusdc、walletsend、wallettransfer、transfertoken等——通过工具名称检测;金额、接收方和交易哈希从参数和结果中提取
- 启发式检测:名为stripe、paypal_、checkout、purchase、buy等的工具,以及包含货币金额及货币/接收方信号的参数模式。还会检测exec包装的支付脚本——如果exec结果包含货币信号(Amount: 0.5 USDC)和确认标记(Transaction confirmed),则会被记录。这些记录的状态为unverified,因为没有正式的支付信号;所有者应审查这些记录
- 通用x402:任何包含X-PAYMENT-RESPONSE头或x402支付确认的工具响应
- 用户追踪工具:用户通过仪表板添加的自定义模式;可选择提交给维护者以纳入社区列表
- 社区模式:从api.spend-ledger.com/patterns.json获取的精选工具模式,每日刷新——随着社区发现新的支付工具,自动扩展检测覆盖范围
对于每次检测到的支付,日志会捕获:服务URL/名称、金额/货币/链、交易哈希、幂等键、触发技能、用户请求、输入哈希(用于循环检测)、执行时间、失败类型(prepayment vs postpayment)和状态。
重复支付保护
spend-ledger会在支付工具调用执行前拦截它们。如果相同的支付调用(相同工具、相同参数)在当前会话中已经成功执行,该调用将被阻止,您将收到类似以下消息:
工具调用被阻止:重复支付被阻止——对[服务]的相同支付已在此会话的[时间戳]执行
当发生这种情况时:
- - 不要重试——阻止是有意为之,该调用将再次被阻止
- 使用query-log.sh确认原始支付已成功
- 告知用户已阻止重复支付,并向他们展示原始交易
此保护机制旨在防止循环、重试和代理错误导致资金流失。在新会话中对同一服务进行合法的重复支付不受影响。
直接读取日志
交易日志是一个JSONL文件,位于data/transactions.jsonl——每行一个JSON记录。您可以直接读取并自行推理。没有查询API,因为您不需要:您是LLM,读取和推理结构化数据是您的原生能力。使用query-log.sh获取结构化输出和摘要;对于更具体的内容,直接读取文件。
何时使用
- - 用户问你花了什么? → query-log.sh 或 query-log.sh --summary daily
- 用户询问特定服务 → query-log.sh --by-service 或 query-log.sh --service <名称>
- 用户想要可视化仪表板 → dashboard.sh start 并分享URL
- 用户想要导出用于会计 → 直接使用仪表板导出按钮,或使用带格式的query-log.sh
- 检测遗漏了支付 → 使用log-transaction.sh手动记录
- 用户想要验证日志完整性 → query-log.sh --verify