feat(assistant): expose loan terms, transaction context and cleaned labels
Second of the stacked PRs split out of #3402, and the base the rest of them build on. No migration, and nothing here changes what the app stores: it exposes data the schema already holds and that the tools were dropping on the floor.
get_accounts kept the balance and threw away the account
get_accounts dropped the entire delegated accountable record. A loan's interest_rate, term_months and rate_type, and a card's apr, minimum_payment and annual_fee were invisible to an assistant despite sitting in the schema, and the amortized Loan#monthly_payment was only ever rendered in a view. Accounts now carry a terms object, populated per accountable type.
A key is absent when the user never recorded it, so a missing key reads as unknown rather than as zero. terms.available_credit means different things across providers (some report the limit, others the remaining credit), and rather than reason over that silently the tool description says so and tells the model to confirm with the user.
get_transactions loaded the counterparty and dropped it
The matched transfer was fetched into memory and discarded, so an assistant could not tell a real expense from money moving between the user's own accounts. Rows now carry kind, pending, excluded, entry_id and the counterparty account, with the counterparty omitted when the caller cannot access it.
The description also states plainly that amount is always positive and that direction lives in classification. Summing amounts without reading it is the single easiest way to produce a confidently wrong total, and it is the kind of error that surfaces to a user as a number rather than as a mistake.
Merchants are null on a plain install, and nothing said why
merchant_id is only ever set through a Rule, rules.active defaults to false, and Family::AutoMerchantDetector raises without an LLM provider. On a self-hosted install with no provider configured, every transaction therefore keeps its raw bank label forever, and there is no deterministic fallback anywhere.
Transaction::LabelNormalizer is that fallback. No LLM, no network: it strips the French banking prefixes (CB, PRLV SEPA, VIR SEPA, RETRAIT DAB, PAIEMENT PSC), embedded dates, card fragments and PAYPAL *XYZ suffixes. It has leverage beyond display, since RecurringTransaction::Identifier groups on entry.name when there is no merchant.
get_uncategorized_transactions groups by payee rather than listing rows, because the useful unit of work is one payee with twelve charges, not twelve charges. It also reports whether any enrichment rule is active at all, so an assistant can explain why everything is uncategorized instead of just observing that it is.
Tests
2259 tests green across the assistant, transaction and account suites. Rubocop clean, Brakeman reports no warnings.
On the stacking
This is the base of the split you suggested in #3402. Four of the remaining lots build on it:
main
├── G Wise SCA key encryption → #3415 (independent)
├── E document vault (independent, 1 migration)
└── A this PR
├── D seasonal recurring detection
└── B overdraft and loan terms, get_liabilities (2 migrations)
├── C cash-flow projection and scenarios
└── F category trends and loan amortization
One practical snag worth raising now, since this PR is what unblocks the rest. I have no push access here, so the branches can only live on my fork, and a cross-fork PR has to take its base from this repository. D and B cannot be based on this branch: opened today they would each replay this PR's diff on top of their own, and C and F would replay two.
I plan to open each one once its parent has merged, so every PR stays a clean single-purpose diff. If you would rather have real stacked PRs in the sense of the docs you linked, that needs the branches to exist on we-promise/sure, which only a maintainer can do. Happy either way, just say which you prefer.
🤖 Generated with Claude Code
Summary by CodeRabbit
-
New Features
- Added uncategorized transaction summaries grouped by payee, with date, account, currency, income/expense totals, and enrichment details.
- Account information now includes subtypes and available loan or credit-card terms.
- Transaction results now provide identifiers, transfer details, status flags, payment methods, cleaned merchant names, and operation dates.
- Added regional normalization for bank statement labels and payment details.
- Improved assistant guidance for interpreting account and transaction data.
-
Bug Fixes
- Transfer counterparties are shown only when accessible.
- Missing account and transaction details are omitted instead of reported with misleading empty values.