Drop counterparty, the generic parsers and .money/

counterparty was a structured field only nlb could fill honestly. revolut
and traderepublic invented one by running an IBAN-shaped regex over the
description they had just built, and the two spellings disagreed --
SI56 1234 5678 9012 345 against SI56123456789012345 -- so a literal rule
pattern that worked on one account silently matched nothing on another. It
is gone from the model, the index, the rule keys, ls --wide and the rules
screen. nlb now appends its IBAN column to the end of the description,
where the other two already keep theirs, so match = "*SI56*" works
everywhere. That changes those descriptions and with them their
fingerprints, so a statement overlapping an already-imported period will
re-add rather than dedupe those rows until the index is rebuilt. An index
built by an older binary drops the column when it is opened.

The index itself moves from .money/index.db up to index.db beside
rules.toml. Nothing looks in the old location, so an existing one has to be
moved by hand -- otherwise the tool quietly starts a fresh index and the
manual tags in the old file, the only thing statements cannot reproduce,
stay behind in it.

The csv and cmd parsers are gone along with the [csv] and [cmd] config they
carried. cmd shelled out to the Python extractors, which were ported to Go
and deleted, so it bridged to nothing; csv was a generic column-mapped
fallback that no account used, and between them they were the largest
configuration surface in the tool. A bank is now described in Go, where it
can be tested. The importer tests register their own three-column parser
rather than borrow a bank's, so they stay about the directory walk, dedupe
and per-file error reporting.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-11 22:51:20 +02:00
co-authored by Claude Opus 5
parent 2a2c0c1db9
commit 16c2585637
23 changed files with 182 additions and 627 deletions
+3 -7
View File
@@ -37,16 +37,15 @@ func (e *Engine) Match(accountSlug string, t model.Transaction) *config.Rule {
// MatchIndex returns the position of the first rule matching a transaction, or
// -1 if none does. Every pattern a rule sets must match: a rule with both
// match and counterparty is an "and", not an "or".
// match and type is an "and", not an "or".
//
// The position matters as well as the rule: because the first match wins, a
// rule that is fully shadowed by an earlier one never applies to anything, and
// only the index reveals that.
func (e *Engine) MatchIndex(accountSlug string, t model.Transaction) int {
var (
description = model.NormalizeDescription(t.Description)
counterparty = model.NormalizeDescription(t.Counterparty)
kind = model.NormalizeDescription(t.Type)
description = model.NormalizeDescription(t.Description)
kind = model.NormalizeDescription(t.Type)
)
for i := range e.rules {
r := &e.rules[i]
@@ -56,9 +55,6 @@ func (e *Engine) MatchIndex(accountSlug string, t model.Transaction) int {
if r.Match != "" && !glob.Match(r.Match, description) {
continue
}
if r.Counterparty != "" && !glob.Match(r.Counterparty, counterparty) {
continue
}
if r.Type != "" && !glob.Match(r.Type, kind) {
continue
}
+4 -13
View File
@@ -201,25 +201,16 @@ func TestAccountScopedRule(t *testing.T) {
}
}
// Movements between the user's own accounts are often only identifiable by
// the counterparty IBAN, so rules can match on it.
func TestCounterpartyAndTypeRules(t *testing.T) {
// Besides the description, a rule can match the bank's own classification of
// the transaction, on its own or alongside a description glob.
func TestTypeRules(t *testing.T) {
engine := New(&config.Rules{Rule: []config.Rule{
{Counterparty: "SI56123456789012345", Tag: "transfer", Transfer: true},
{Type: "CARD_PAYMENT", Match: "*LIDL*", Tag: "groceries"},
{Type: "ATM", Tag: "cash"},
}})
// Counterparty alone is enough, whatever the description says.
tag, transfer := engine.ApplyTxn("checking", model.Transaction{
Description: "Standing order", Counterparty: "SI56123456789012345",
})
if tag != "transfer" || !transfer {
t.Errorf("tag=%q transfer=%v, want transfer/true", tag, transfer)
}
// A rule setting several patterns requires all of them to match.
tag, _ = engine.ApplyTxn("checking", model.Transaction{
tag, _ := engine.ApplyTxn("checking", model.Transaction{
Description: "LIDL SOFIA", Type: "CARD_PAYMENT",
})
if tag != "groceries" {