Heath Ledger
AI bookkeeping skill for Mercury bank accounts.
Quick Start
- 1.
scripts/init_db.mjs — creates DB + seeds ~90 universal vendor→category rules - INLINECODE1 — discovers accounts
- (Optional)
scripts/connect_stripe.sh <entity_id> <stripe_api_key> — connect Stripe for exact revenue + fees - (If Stripe connected)
scripts/pull_stripe_revenue.sh <entity_id> <start_date> <end_date> — pull monthly revenue data - INLINECODE4
- INLINECODE5 — rule-based first, AI for unknowns
- Review ambiguous items, correct with INLINECODE6
- INLINECODE7
Setup Flow
Mercury API Key (Required)
Get from Mercury Dashboard → Settings → API Tokens. The token gives read-only access to transactions.
Stripe API Key (Optional but Recommended)
Without Stripe API: Mercury shows
net Stripe deposits (revenue minus fees). The system estimates gross revenue using a configurable fee rate (default 2.3% + $0.30).
With Stripe API: You get exact gross revenue, exact fees, and proper refund tracking. Always prefer this when available.
To connect: scripts/connect_stripe.sh <entity_id> <stripe_api_key>
Then pull data: INLINECODE9
The P&L generator automatically uses Stripe data when available, falling back to Mercury estimates otherwise.
Entity Settings
Configure per-entity via the
entity_settings table:
| Setting | Default | Description |
|---|
| INLINECODE11 | INLINECODE12 | INLINECODE13 or cash — cash basis uses posted dates only |
| INLINECODE15 |
1 | Fiscal year month offset (1 = calendar year) |
|
stripe_fee_rate |
0.023 | Stripe percentage fee for gross-up calculation |
|
stripe_fee_fixed |
0.30 | Stripe fixed fee per transaction |
|
amortization_monthly |
null | Monthly amortization amount for acquired assets |
Workflow
- 1. Connect Mercury —
scripts/connect_mercury.sh <token> [name] discovers accounts, creates entity - Pull transactions — INLINECODE24
- Categorize —
scripts/categorize.sh <entity_id> [max_transactions] — rule-based first, then AI for unknowns - Review ambiguous — Script outputs low-confidence items. Ask user, then update with INLINECODE26
- Generate books — INLINECODE27
Scripts Reference
All scripts are in scripts/. Run with bash or node. Database is SQLite at data/heath.db.
| Script | Purpose |
|---|
| INLINECODE30 | Create/migrate SQLite database + seed rules |
| INLINECODE31 |
Connect Mercury API, discover accounts |
|
pull_transactions.sh | Pull transactions for date range |
|
categorize.sh | Categorize transactions (rules + AI) |
|
set_category.sh | Manually set category for a transaction |
|
add_rule.sh | Add/update a categorization rule |
|
generate_books.sh | Generate Excel workbook |
|
list_entities.sh | List all entities |
|
connect_stripe.sh | Connect Stripe API to an entity |
|
pull_stripe_revenue.sh | Pull Stripe balance transactions by month |
|
status.sh | Show entity status (accounts, tx counts) |
Chart of Accounts
See references/chart-of-accounts.md for the full chart with P&L sections and cash flow classifications.
Learning & Compounding System
Heath Ledger gets smarter over time through a layered rule system:
Rule Hierarchy
- 1. Entity-specific rules (highest priority) — per-company overrides
- Global rules (
entity_id = NULL) — apply to all entities - Seed rules — universal vendor mappings shipped with the skill
- AI categorization — used when no rule matches
How Learning Works
- - Every manual correction creates or updates a categorization rule
- Rules track
usage_count — heavily-used rules are more reliable - INLINECODE44 field tracks provenance:
seed, ai, human, INLINECODE48 - Human-confirmed rules get INLINECODE49
- AI-generated rules start at
0.85 and can be promoted - Entity-specific rules can be promoted to global when they prove universal
The Compounding Effect
After categorizing ~5,000 transactions across 2 entities, the system now auto-categorizes
~95% of transactions without AI. Each new entity benefits from all previous learnings.
Known Limitations
Stripe Net vs Gross (Without Stripe API)
Mercury deposits from Stripe are
net amounts (revenue minus ~2.9% + $0.30 fees). Without the Stripe API:
- - We estimate gross revenue using configurable fee rates
- This creates "synthetic" Stripe Fee entries
- Accuracy depends on your actual Stripe fee rate (varies by plan, card type, international)
- Solution: Connect Stripe API for exact numbers
Deel Fee Splitting
Deel combines platform fees and contractor payroll in one transaction stream. Pattern:
- - Small fixed amounts (~$2-5) → Deel Platform Fee → categorize as "Software expenses"
- Larger variable amounts → Contractor Payroll → categorize as "Wages & Salaries"
- The system learns this pattern but may need initial human guidance
Mercury API Limitations
- - Only returns posted transactions (not pending)
- Some counterparty names are truncated or normalized differently
- Wire descriptions may include reference numbers that create duplicate rules
Multi-Currency
- - Wise transfers create both a debit (USD) and may show FX fees separately
- International wire fees from Mercury appear as separate line items
- FX gains/losses are not tracked (would need multi-currency ledger)
AI Categorization
The categorize.sh script calls the host agent's model via stdin/stdout JSON protocol. It sends transaction batches and expects category assignments back. The script writes a prompt to stdout that the agent should process and return results for.
When AI confidence < 0.85, transactions are flagged as ambiguous for user review.
Key Details
- - Cash or accrual basis — configurable per entity
- Multiple entities supported — each with own connections and rules
- Rules persist — categorization rules saved to SQLite, reused across runs
- Seed rules — ~90 universal vendor mappings loaded on init
- Excel output — 4-tab workbook: P&L, Balance Sheet, Cash Flow, Transaction Detail
希斯·莱杰
Mercury银行账户的AI记账技能。
快速开始
- 1. scripts/initdb.mjs — 创建数据库 + 预置约90条通用供应商→类别规则
- scripts/connectmercury.sh APITOKEN> [entityname] — 发现账户
- (可选) scripts/connectstripe.sh id> apikey> — 连接Stripe获取精确收入+费用
- (如果已连接Stripe) scripts/pullstriperevenue.sh id> date> date> — 拉取月度收入数据
- scripts/pulltransactions.sh id> date> date>
- scripts/categorize.sh id> — 先基于规则,未知项使用AI
- 审核存疑项目,使用scripts/setcategory.sh进行修正
- scripts/generatebooks.sh id> date> date> [output_path]
设置流程
Mercury API密钥(必需)
从Mercury仪表盘 → 设置 → API令牌获取。该令牌提供交易的只读访问权限。
Stripe API密钥(可选但推荐)
无Stripe API:Mercury显示Stripe存款的
净额(收入减去费用)。系统使用可配置的费率(默认2.3% + $0.30)估算总收入。
有Stripe API:您将获得精确的总收入、精确费用和正确的退款追踪。可用时始终优先选择此方式。
连接方式:scripts/connectstripe.sh id> apikey>
然后拉取数据:scripts/pullstriperevenue.sh id> date>
损益表生成器在有Stripe数据时自动使用,否则回退到Mercury估算值。
实体设置
通过entity_settings表为每个实体配置:
| 设置项 | 默认值 | 描述 |
|---|
| accountingbasis | accrual | accrual(权责发生制)或cash(收付实现制)— 收付实现制仅使用过账日期 |
| monthoffset |
1 | 财年月份偏移量(1 = 日历年度) |
| stripe
feerate | 0.023 | Stripe百分比费率,用于毛额计算 |
| stripe
feefixed | 0.30 | Stripe每笔交易固定费用 |
| amortization_monthly | null | 收购资产的月度摊销金额 |
工作流程
- 1. 连接Mercury — scripts/connectmercury.sh [name] 发现账户,创建实体
- 拉取交易 — scripts/pulltransactions.sh id> date> date>
- 分类 — scripts/categorize.sh id> [maxtransactions] — 先基于规则,未知项使用AI
- 审核存疑项 — 脚本输出低置信度项目。询问用户,然后使用scripts/setcategory.sh id> [subcategory]更新
- 生成账簿 — scripts/generatebooks.sh id> date> date> [outputpath]
脚本参考
所有脚本位于scripts/目录。使用bash或node运行。数据库为SQLite,位于data/heath.db。
| 脚本 | 用途 |
|---|
| initdb.mjs | 创建/迁移SQLite数据库 + 预置规则 |
| connectmercury.sh |
连接Mercury API,发现账户 |
| pull_transactions.sh | 拉取指定日期范围的交易 |
| categorize.sh | 对交易进行分类(规则+AI) |
| set_category.sh | 手动设置交易的类别 |
| add_rule.sh | 添加/更新分类规则 |
| generate_books.sh | 生成Excel工作簿 |
| list_entities.sh | 列出所有实体 |
| connect_stripe.sh | 将Stripe API连接到实体 |
| pull
striperevenue.sh | 按月份拉取Stripe余额交易 |
| status.sh | 显示实体状态(账户、交易数量) |
会计科目表
完整科目表(含损益表分类和现金流量分类)请参见references/chart-of-accounts.md。
学习与累积系统
希斯·莱杰通过分层规则系统随时间变得越来越智能:
规则层级
- 1. 实体特定规则(最高优先级)— 针对特定公司的覆盖规则
- 全局规则(entity_id = NULL)— 适用于所有实体
- 预置规则 — 技能自带的通用供应商映射
- AI分类 — 无规则匹配时使用
学习机制
- - 每次手动修正都会创建或更新一条分类规则
- 规则追踪usage_count(使用次数)— 使用频繁的规则更可靠
- source字段追踪来源:seed(预置)、ai(AI)、human(人工)、manual(手动)
- 人工确认的规则获得confidence: 0.95-1.0(置信度)
- AI生成的规则从0.85开始,可被提升
- 实体特定规则在证明具有通用性后可提升为全局规则
累积效应
在跨2个实体分类约5,000笔交易后,系统现在无需AI即可自动分类
约95%的交易。每个新实体都能受益于之前的所有学习成果。
已知限制
Stripe净额与毛额(无Stripe API时)
来自Stripe的Mercury存款为
净额(收入减去约2.9% + $0.30费用)。无Stripe API时:
- - 我们使用可配置的费率估算毛收入
- 这会创建合成的Stripe费用条目
- 准确性取决于您实际的Stripe费率(因计划、卡类型、国际交易而异)
- 解决方案:连接Stripe API获取精确数字
Deel费用拆分
Deel将平台费用和承包商工资合并到一个交易流中。模式:
- - 小额固定金额(约$2-5)→ Deel平台费用 → 归类为软件费用
- 较大可变金额 → 承包商工资 → 归类为工资与薪金
- 系统会学习此模式,但可能需要初始人工指导
Mercury API限制
- - 仅返回已过账交易(不含待处理交易)
- 部分对手方名称被截断或标准化方式不同
- 电汇描述可能包含参考编号,导致重复规则
多币种
- - Wise转账会同时产生借方(美元),外汇费用可能单独显示
- Mercury的国际电汇费用作为单独项目显示
- 外汇损益不被追踪(需要多币种分类账)
AI分类
categorize.sh脚本通过stdin/stdout JSON协议调用宿主代理的模型。它发送交易批次并期望返回类别分配。脚本向stdout写入提示,代理应处理该提示并返回结果。
当AI置信度< 0.85时,交易被标记为存疑项供用户审核。
关键细节
- - 收付实现制或权责发生制 — 每个实体可配置
- 支持多个实体 — 每个实体有独立的连接和规则
- 规则持久化 — 分类规则保存到SQLite,跨运行复用
- 预置规则 — 初始化时加载约90条通用供应商映射
- Excel输出 — 4标签页工作簿:损益表、资产负债表、现金流量表、交易明细