Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,41 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

---

## [1.16.25] — 2026-11-02

### Fixed
- **"Re-categorize all" changes were lost after a reload.**
- **Symptom:** on the samples, with the rule WALMART → Shopping, **Re-categorize all** (Spending → Category rules) showed the 16 WALMART rows as Shopping. After a reload they were Groceries again, though the rule was still listed. STARBUCKS → Personal on the card file went back to Food & Drink the same way.
- **Cause:** `recategorizeAll()` (`ui.js`) changed the categories in memory and saved nothing. Category rules don't re-apply on load. A reload from IndexedDB takes each category from the transaction's stored row, which holds the import's (`DB.loadAll()`). A boot from `finlens-state.json` takes the categories the file was saved with, and Re-categorize all didn't save it: the file got them only if another change (adding a rule, say) had scheduled the debounced save less than 5 seconds before. Importing the card CSV again also brought its CSV categories back.
- **The bug is also on `master`** (v1.10.5), in the same `recategorizeAll()`.
- **Fix:** what Re-categorize all gives each transaction is saved in `State.ruleCategories`, by transaction id, where it differs from the import's category or from its stored row's. (They differ after a rule is added and the CSVs imported again: memory re-reads a checking row with the rule, the store keeps its first import's row.) It's saved like a setting (localStorage, IndexedDB `app_state`, `finlens-state.json`), and the click schedules the state-file save. `mkTx()` and `reconstituteTx()` apply it, so it holds after a reload from either place and after a re-import.
- **Re-categorize all also overwrote card categories and transfers.** Saved, these would have become permanent, so they're fixed with it:
- **Card rows with no matching rule** got the built-in category instead of their CSV Category. With no rules at all, it changed 136 sample rows: every UBER TRIP from Travel to Transport, every CVS from Health & Wellness to Health. A card row now keeps its CSV Category unless one of your rules matches it. Checking and savings exports have no Category column, so their rows get your rules, then the built-in ones, as at import (`categoryFromRules()`, `core.js`).
- **Transfers** lost Transfer in / Transfer out: the 12 checking ↔ savings legs became Transfer, or the category of a rule matching them. A detected transfer now keeps its transfer category.

### Unchanged
- **Your own category edits win:** a category set in the transaction drawer, with bulk Set category, or by deleting a category. Under an edit, what Re-categorize all gives is still saved, and shows if **Clear transaction edits** removes the edit, as flags from the rules do.
- **When rules apply:** to each import, as before, and to what's already imported only when you click Re-categorize all. Adding or removing a rule changes nothing until then.
- **Removing a rule, then Re-categorize all,** puts its transactions back to the import's category and removes what was saved for them.
- **Without category rules, nothing changes.** Re-categorize all saves nothing, and the AI summary and the AI Eval's sample summary are the same.

### Known limits
- **A transaction from a `finlens-state.json` written before v1.16.1** doesn't record its import category (`_originalCategories`). Re-categorize all then uses its IndexedDB row's, or with no row (a new browser) the category it shows, when nothing else can have set it. A card row re-categorized that way, whose rule is later removed, gets the built-in category. Importing its CSV again and clicking Re-categorize all brings its CSV Category back.
- **Not in the JSON export.** It's worked out from the category rules, which are: click Re-categorize all after importing one.

### Technical
- **`core.js`:** `State.ruleCategories` (new, `{ [txId]: category }`); `categoryFromRules(t, importCat)` (new); `mkTx()` applies it; `saveStateToFile()` writes it; `loadStateFromFile()` passes the file's own to `reconstituteTx()`.
- **`db.js`:** `reconstituteTx(raw, ov, rules, ruleCats)` applies it after an edit, except to a record that is a transfer (a state file's transfers keep the category detection gave them); `DB.APP_STATE_KEYS` has it.
- **`ui.js`:** `recategorizeAll()` is async: it reads the IndexedDB rows (the import's category for a transaction that doesn't record it, and what a reload from IndexedDB starts from), then saves with `lsSet()`. Entries for transactions not loaded are kept, as edits are.
- **`views-eval.js`:** the AI Eval sandbox sets `ruleCategories` to `{}`, since `mkTx()` reads it. **`views-db.js`:** the DB Schema's `app_state` note lists it.
- **Why not in the IndexedDB rows:** after a boot from `finlens-state.json` the `transactions` store can be empty or hold only some rows (CLAUDE.md §4.5); Rebuild and Clear transactions empty it; a re-import skips rows already stored; and a row holds the CSV's values (§10). Edits live in `txOverrides` for the same reasons.

### Docs
- **CLAUDE.md** — §1 version; §4.1 `ruleCategories`; §4.2 categories; §8 `categoryFromRules()`; §9 `recategorizeAll()`; §20 where it's kept and what clears it.
- **README.md** — Spending: Re-categorize all.

---

## [1.16.24] — 2026-11-02

### Fixed
Expand Down
24 changes: 17 additions & 7 deletions CLAUDE.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> A zero-install, browser-native finance dashboard. Drop in your bank CSVs, get instant clarity on your money.

**Version:** v1.16.24  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None
**Version:** v1.16.25  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None

---

Expand Down Expand Up @@ -116,7 +116,7 @@ Total income, average per month, interest earned and refunds. Income by source a
**Spotted recurring charges**: FinLens finds charges that repeat and shows its confidence. Confirm the real bills, or dismiss the rest (Undo brings one back). Add bills by hand with **+ Add bill**. Each bill has how often it repeats, its next due date, the account it pays from and when it was last paid (found in your transactions). Also a month calendar you can hide, and what your bills and subscriptions cost per month.

### Spending
Total spent, average per day, top category and highest month. Categories ranked by spend: pick one to see its transactions. A daily spending heatmap, the monthly trend, top merchants, and **category rules** (keyword → category).
Total spent, average per day, top category and highest month. Categories ranked by spend: pick one to see its transactions. A daily spending heatmap, the monthly trend, top merchants, and **category rules** (keyword → category). **Re-categorize all** applies them to everything already imported, and the result is kept. A category you set yourself wins, transfers keep theirs, and a card transaction no rule matches keeps the category its CSV gave it.

### Transfers
Both legs of a transfer are paired automatically. A diagram shows where money moved between your accounts, and what left FinLens (e.g. Zelle payments). Filter the list by From and To account. **Transfer keywords** decide which unpaired transactions count as transfers; changing them re-runs detection right away. A type you set on a transaction wins: detection leaves that transaction alone, so one you set to Expense stays an expense and isn't paired. Categories you add to a detected transfer are kept. A transaction that stops being a transfer (say, you remove its keyword) gets its own type and category back: a card's Category and Sale, Return or Payment from its file, otherwise the category it was imported with (your category rules first, then the built-in ones).
Expand Down Expand Up @@ -261,4 +261,4 @@ See [CHANGELOG.md](CHANGELOG.md) for the full release history.

---

*FinLens v1.16.24 — Built for one person's finances, designed to be useful for anyone's.*
*FinLens v1.16.25 — Built for one person's finances, designed to be useful for anyone's.*
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@
<div class="folder-banner-wrap" id="folderBanner" hidden></div>
<div class="content" id="content"></div>
</main>
<footer class="appfoot">v1.16.24 · FinLens</footer>
<footer class="appfoot">v1.16.25 · FinLens</footer>

<!-- side drawer: transaction detail, bill and plan forms (ui.js openDrawer) -->
<div class="drawer-scrim" id="drawerScrim" onclick="closeDrawer()" hidden></div>
Expand Down
33 changes: 30 additions & 3 deletions js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,12 @@ async function loadStateFromFile() {
_saveStateDebounced(State);
}
const ovs = loaded.txOverrides || State.txOverrides || {};
// Rule flags come from the file's own rules: State only gets them after this returns.
// Rule flags come from the file's own rules, and re-categorized categories from its own
// ruleCategories: State only gets them after this returns.
const rules = Array.isArray(loaded.txRules) ? loaded.txRules : State.txRules;
const ruleCats = loaded.ruleCategories && typeof loaded.ruleCategories === 'object' ? loaded.ruleCategories : State.ruleCategories;
loaded.transactions = loaded.transactions
.map(raw => reconstituteTx({ ...raw, description: raw._originalDesc || raw.description }, ovs[raw.id] || {}, rules))
.map(raw => reconstituteTx({ ...raw, description: raw._originalDesc || raw.description }, ovs[raw.id] || {}, rules, ruleCats))
.filter(t => !isNaN(t.date))
.sort((a, b) => b.date - a.date);
}
Expand Down Expand Up @@ -244,6 +246,7 @@ async function saveStateToFile(state) {
txOverrides: state.txOverrides,
manualBalances: state.manualBalances,
categoryRules: state.categoryRules,
ruleCategories: state.ruleCategories,
categories: state.categories,
aiHistory: state.aiHistory,
scenarios: state.scenarios,
Expand Down Expand Up @@ -407,6 +410,9 @@ const State = {
txOverrides: lsGet('txOverrides', {}), // id -> { description, categories, notes, isBill, isRecurring, isSubscription, type, accountOverride, link: { type, id } }
manualBalances: lsGet('manualBalances', {}), // id -> amount; id+'_limit' -> limit; id+'_initial' -> initial balance
categoryRules: lsGet(storageKey('categoryRules'), []), // stored as 'catRules'
// What Re-categorize all gave each transaction, where it differs from its import's category:
// { [txId]: category } (v1.16.25). mkTx() and reconstituteTx() apply it; an edit wins.
ruleCategories: lsGet('ruleCategories', {}),
categories: lsGet('categories', null) || [
'Food & Dining','Groceries','Housing','Transport','Entertainment',
'Health','Shopping','Bills & Utilities','Subscriptions','Personal',
Expand Down Expand Up @@ -605,6 +611,25 @@ function autoCategory(desc) {
return 'Other';
}

// The category Re-categorize all gives a loaded transaction (v1.16.25, recategorizeAll() in
// ui.js): a category rule matching its CSV description; else its CSV's own Category, which
// `importCat` holds (the card export has the column; null when it isn't known); else the
// built-in rules (DEFAULT_RULES), else Other. Checking and savings exports have no Category
// column, so their import category came from the rules and is worked out again. Up to v1.16.24
// a card row with no matching rule got the built-in category, losing its CSV Category.
function categoryFromRules(t, importCat) {
const desc = t._originalDesc || t.description || '';
const u = desc.toUpperCase();
const rule = (State.categoryRules || []).find(r => r.contains && u.includes(r.contains.toUpperCase()));
if (rule) return rule.category;
// The account's CSV format; an account FinLens doesn't know keeps what its import gave.
const a = State.accounts[t.account];
const schema = a && [...BANK_SCHEMAS, ...(State.customSchemas || [])].find(s => s.id === a.kind);
const ownColumn = !schema || !!(schema.columns && schema.columns.category);
if (ownColumn && importCat) return importCat;
return autoCategory(desc);
}

/* Returns true if any txRule with given flag matches the description.
`rules` defaults to State.txRules; loadStateFromFile() passes the file's own list. */
function txRuleFlag(desc, flag, rules = State.txRules) {
Expand Down Expand Up @@ -654,7 +679,9 @@ function mkTx(o) {
// parseCsvFile). The suffix is part of the ID everywhere — memory, IndexedDB, overrides.
const id = hash(hashKey) + (o.occurrence > 1 ? '_' + o.occurrence : '');
const ov = State.txOverrides[id] || {};
const cats = ov.categories && ov.categories.length ? ov.categories : (ov.category ? [ov.category] : [o.category]);
// An edit wins; then what Re-categorize all gave it (v1.16.25); then the import's category.
const rc = (State.ruleCategories || {})[id];
const cats = ov.categories && ov.categories.length ? ov.categories : (ov.category ? [ov.category] : [rc || o.category]);
return {
id,
date: o.date,
Expand Down
11 changes: 9 additions & 2 deletions js/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
// The flags come from txFlags() (the edit, else the current rules), never from the
// record: a stored row or a finlens-state.json entry holds them as they were when it was
// written. `rules` defaults to State.txRules.
function reconstituteTx(raw, ov, rules) {
// The category: an edit wins, then what Re-categorize all gave it (`ruleCats`, default
// State.ruleCategories, v1.16.25), then the record's. A record that is a transfer keeps its
// own: a finlens-state.json entry holds the 'Transfer in' / 'Transfer out' detection gave it,
// and that boot doesn't detect transfers again. (A stored row holds the CSV's type, and
// DB.loadAll() detects transfers after.)
function reconstituteTx(raw, ov, rules, ruleCats = State.ruleCategories) {
ov = ov || {};
const rc = raw.type !== 'transfer' && (ruleCats || {})[raw.id];
const cats = (ov.categories && ov.categories.length)
? ov.categories
: (raw.categories && raw.categories.length ? raw.categories : ['Other']);
: rc ? [rc] : (raw.categories && raw.categories.length ? raw.categories : ['Other']);
const src = raw._originalDesc || raw.description || '';
return {
id: raw.id,
Expand Down Expand Up @@ -54,6 +60,7 @@ const DB = {
['txOverrides', {}],
['manualBalances', {}],
['categoryRules', []], // stored as 'catRules'
['ruleCategories', {}],
['categories', null],
['apiKey', ''],
['aiHistory', []],
Expand Down
46 changes: 41 additions & 5 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,12 +532,47 @@ function addCatRule() {
renderActive();
}
function delCatRule(i){ State.categoryRules.splice(i,1); lsSet('catRules',State.categoryRules); renderActive(); }
function recategorizeAll() {
// Re-categorize all (Spending → Category rules): every loaded transaction gets the category the
// rules give it now (categoryFromRules(), core.js), and the result is saved (v1.16.25). Up to
// v1.16.24 it changed the categories in memory only: nothing saved them, so a reload from
// browser storage brought the imported ones back, and finlens-state.json kept them only if
// another change happened to save it afterwards.
// - Saved in State.ruleCategories, by transaction id, where it differs from the import's
// category or from its IndexedDB row's (lsSet: localStorage, IndexedDB app_state, then the
// debounced state-file save). The two can differ: a re-import re-reads a checking row with
// the current rules, but the store keeps the row from its first import. mkTx() and
// reconstituteTx() apply it, so it holds after a reload from IndexedDB or the state file,
// and after a re-import. Ids not loaded keep their entry, as edits do.
// - Shown on every transaction except one with a category edit (the edit wins) and a detected
// transfer (it keeps Transfer in / Transfer out). Under those it's still saved, and shows
// once the edit is cleared or the transaction stops being a transfer.
// - The import's category is _originalCategories; a transaction from a finlens-state.json
// written before v1.16.1 doesn't record it: then its IndexedDB row's, else the category it
// shows, if nothing but the import can have set it (no edit, not a transfer, not re-categorized).
async function recategorizeAll() {
const has=(c)=>Array.isArray(c)&&c.length>0;
const prev=State.ruleCategories||{};
// The stored rows: what a reload from IndexedDB starts from. A row only fills in a value
// the transaction doesn't record (CLAUDE.md §4.5); the store can be empty or partial.
const rows=typeof DB!=='undefined'&&DB._db
? new Map((await DB._getAllTransactions()).map(r=>[r.id,r])) : new Map();
const loaded=new Set(State.transactions.map(t=>t.id));
const next=Object.fromEntries(Object.entries(prev).filter(([id])=>!loaded.has(id)));
for (const t of State.transactions) {
const ov=State.txOverrides[t.id];
if (ov&&ov.categories&&ov.categories.length) continue;
t.categories=[autoCategory(t._originalDesc||t.description)];
const ov=State.txOverrides[t.id]||{};
const edited=!!((ov.categories&&ov.categories.length)||ov.category);
const detected=t.type==='transfer'&&ov.type!=='transfer';
const row=rows.get(t.id);
const rowCat=row&&has(row.categories) ? row.categories[0] : null;
const importCat=has(t._originalCategories) ? t._originalCategories[0]
: rowCat!==null ? rowCat
: (!edited&&t.type!=='transfer'&&!(t.id in prev)) ? t.category : null;
const cat=categoryFromRules(t,importCat);
if (cat!==importCat||(rowCat!==null&&cat!==rowCat)) next[t.id]=cat;
if (!edited&&!detected) t.categories=[cat];
}
State.ruleCategories=next;
lsSet('ruleCategories',next);
renderActive();
}

Expand Down Expand Up @@ -888,7 +923,8 @@ function setPayoffExtra(v) {
// Left out on purpose: transactions and accounts (your CSVs bring them back), the API key
// (never written anywhere, CLAUDE.md §15), this browser's own state (sampleData,
// csvAutoImportPaused, lastFolderName), the session (date range, accounts filter, current
// screen) and customSchemas (nothing in the app creates one).
// screen), customSchemas (nothing in the app creates one) and ruleCategories (worked out from
// the category rules, which are in it: Re-categorize all after importing gives them again).
// Version 1.2 (v1.16.6) added accountLabels … theme; 1.1 had the keys above them.
const JSON_EXPORT_VERSION='1.2';
const JSON_EXPORT_KEYS={
Expand Down
2 changes: 1 addition & 1 deletion js/views-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ registerView('db-schema', 'DB Schema', (root) => {
{ name: 'key', type: 'string', key: 'PK', note: 'lsSet() key' },
{ name: 'value', type: 'any', key: '', note: 'JSON-serializable' },
],
note: 'budgets · bills · debts · buckets · categories · apiKey · aiHistory · scenarios · investAlloc · debtPlan · manualBalances · txOverrides · accountOrder · accountLabels · categoryRules · txRules · transferKeywords · customSchemas · fileAssignments · theme',
note: 'budgets · bills · debts · buckets · categories · apiKey · aiHistory · scenarios · investAlloc · debtPlan · manualBalances · txOverrides · accountOrder · accountLabels · categoryRules · ruleCategories · txRules · transferKeywords · customSchemas · fileAssignments · theme',
},
];

Expand Down
2 changes: 1 addition & 1 deletion js/views-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const AIEval = {
// is in place, so the user's data is never mixed with samples, sent, or persisted.
_withSampleState(fn) {
const sandbox = {
transactions: [], accounts: {}, txOverrides: {}, txRules: [], categoryRules: [],
transactions: [], accounts: {}, txOverrides: {}, txRules: [], categoryRules: [], ruleCategories: {},
customSchemas: [], accountLabels: {}, accountOrder: [], manualBalances: {},
transferKeywords: DEFAULT_TRANSFER_KEYWORDS.slice(),
debts: [], buckets: [], budgets: [], bills: [], recurringConfirmed: {}, fileMeta: [],
Expand Down
2 changes: 1 addition & 1 deletion js/views-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function _renderGeneralSettings(root) {
/* ---- About (the Theme row is gone: light only for now) ---- */
appendHtml(root,`<section class="panel" aria-labelledby="dispH">
<h2 id="dispH">About</h2>
<div class="set-row"><span class="t">Version</span><span class="v">FinLens v1.16.24</span></div>
<div class="set-row"><span class="t">Version</span><span class="v">FinLens v1.16.25</span></div>
</section>`);

/* ---- Anthropic API key ---- */
Expand Down