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
+8 -51
View File
@@ -18,9 +18,8 @@ const (
RulesFile = "rules.toml"
// AccountFile is the per-account config inside each account folder.
AccountFile = "account.toml"
// StateDir holds the rebuildable SQLite index.
StateDir = ".money"
// IndexFile is the SQLite index inside StateDir.
// IndexFile is the rebuildable SQLite index, at the root of the data
// directory alongside rules.toml.
IndexFile = "index.db"
)
@@ -31,10 +30,6 @@ type Rule struct {
Tag string `toml:"tag"`
Transfer bool `toml:"transfer"`
Account string `toml:"account"` // optional: restrict to one account slug
// Counterparty matches the other side's account number, which for
// movements between the user's own accounts is often the only reliable
// signal. Optional; when set, it must match as well as Match.
Counterparty string `toml:"counterparty"`
// Type matches the bank's own classification, e.g. Revolut's CARD_PAYMENT.
// Optional; when set, it must match as well as Match.
Type string `toml:"type"`
@@ -62,8 +57,8 @@ func LoadRules(root string) (*Rules, error) {
return nil, fmt.Errorf("%s: %w", path, err)
}
for i, rule := range r.Rule {
if rule.Match == "" && rule.Counterparty == "" && rule.Type == "" {
return nil, fmt.Errorf("%s: rule %d has no match, counterparty or type pattern", path, i+1)
if rule.Match == "" && rule.Type == "" {
return nil, fmt.Errorf("%s: rule %d has no match or type pattern", path, i+1)
}
if rule.Tag == "" && !rule.Transfer {
return nil, fmt.Errorf("%s: rule %d (%q) sets neither tag nor transfer", path, i+1, rule.Match)
@@ -79,8 +74,8 @@ func LoadRules(root string) (*Rules, error) {
// The file is rewritten through a temporary file so a failure part-way cannot
// leave the user with a truncated config.
func AppendRule(root string, r Rule) error {
if r.Match == "" && r.Counterparty == "" && r.Type == "" {
return fmt.Errorf("a rule needs a match, counterparty or type pattern")
if r.Match == "" && r.Type == "" {
return fmt.Errorf("a rule needs a match or type pattern")
}
if r.Tag == "" && !r.Transfer {
return fmt.Errorf("a rule needs a tag or transfer = true")
@@ -254,7 +249,6 @@ func formatRule(r Rule) string {
}
}
write("match", r.Match)
write("counterparty", r.Counterparty)
write("type", r.Type)
write("account", r.Account)
write("tag", r.Tag)
@@ -267,41 +261,6 @@ func formatRule(r Rule) string {
return b.String()
}
// Column locates one field in a CSV row.
type Column struct {
Col int `toml:"col"`
Layout string `toml:"layout"` // date only, Go reference layout
Decimal string `toml:"decimal"` // amount only, default "."
Thousands string `toml:"thousands"` // amount only, default ""
}
// CSVConfig describes how to read a delimited statement.
type CSVConfig struct {
Delimiter string `toml:"delimiter"`
SkipRows int `toml:"skip_rows"`
Encoding string `toml:"encoding"` // "" or "utf-8"; other encodings unsupported for now
Date Column `toml:"date"`
Description Column `toml:"description"`
Amount *Column `toml:"amount"` // single signed column...
Debit *Column `toml:"debit"` // ...or a debit/credit pair
Credit *Column `toml:"credit"`
// Invert flips the sign of the parsed amount, for statements that report
// outflows as positive numbers.
Invert bool `toml:"invert"`
}
// CmdConfig runs an external extractor (e.g. one of the existing Python
// scripts) and reads normalised CSV from its stdout.
type CmdConfig struct {
// Argv is the command to run. The literal token "{{file}}" is replaced
// with the absolute path of the statement being imported.
Argv []string `toml:"argv"`
// Layout is the date layout the script emits; defaults to 2006-01-02.
Layout string `toml:"layout"`
// SkipRows skips leading rows of the script's output (e.g. a header).
SkipRows int `toml:"skip_rows"`
}
// Account is a parsed account.toml.
type Account struct {
Slug string // folder name, filled in by LoadAccounts
@@ -312,9 +271,7 @@ type Account struct {
Parser string `toml:"parser"`
// Include restricts which files in the folder are treated as statements.
// Defaults to every regular file except account.toml and dotfiles.
Include []string `toml:"include"`
CSV *CSVConfig `toml:"csv"`
Cmd *CmdConfig `toml:"cmd"`
Include []string `toml:"include"`
}
// Digits returns the configured minor-unit scale, defaulting to 2.
@@ -376,7 +333,7 @@ func loadAccount(dir, slug, cfgPath string) (*Account, error) {
// IndexPath returns the location of the SQLite index for a data root.
func IndexPath(root string) string {
return filepath.Join(root, StateDir, IndexFile)
return filepath.Join(root, IndexFile)
}
// UserConfig is the small file in the user's config directory that says where