From bdd73867f9f57b7bb1e89e6ca1201b7cee289797 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 14:51:31 +0000 Subject: [PATCH] Fix "Re-categorize all" changes being lost after a reload (v1.16.25) recategorizeAll() changed categories in memory only and saved nothing. Category rules don't re-apply on load, so a reload from IndexedDB took the import's category from each stored row, and a boot from finlens-state.json had the new categories only if another change had scheduled the debounced save. A CSV re-import also brought card rows' CSV categories back. What Re-categorize all gives is now saved in State.ruleCategories ({ [txId]: category }), where it differs from the import's category or from the stored row's: localStorage, IndexedDB app_state and the state file. mkTx() and reconstituteTx() apply it after an edit, so it holds after a reload from either place and after a re-import. Saved, two things it did wrong would have become permanent, so they are fixed with it: card rows with no matching rule now keep their CSV Category (categoryFromRules()), and detected transfers keep Transfer in / Transfer out. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft --- CHANGELOG.md | 35 +++++++++++++++++++++++++++++++++ CLAUDE.md | 24 ++++++++++++++++------- README.md | 6 +++--- index.html | 2 +- js/core.js | 33 ++++++++++++++++++++++++++++--- js/db.js | 11 +++++++++-- js/ui.js | 46 +++++++++++++++++++++++++++++++++++++++----- js/views-db.js | 2 +- js/views-eval.js | 2 +- js/views-settings.js | 2 +- 10 files changed, 139 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff2db9f..2dffb99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/CLAUDE.md b/CLAUDE.md index 7cd8fd6..f8a1724 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -59,7 +59,7 @@ Until then, this section is the rule. FinLens is a **single-origin, zero-build, vanilla JavaScript personal finance dashboard** that runs entirely in the browser. There is no server, no npm, no bundler, no framework, and no TypeScript. The entry point is `index.html`; everything else is a plain `.js` file in the `js/` folder. -**Current version:** v1.16.24 (updated in `index.html` footer, `README.md`, and `CHANGELOG.md` on every release). +**Current version:** v1.16.25 (updated in `index.html` footer, `README.md`, and `CHANGELOG.md` on every release). **What it does:** Imports CSV exports from a bank (checking + savings) and credit cards, parses and normalizes them into a unified transaction model, and renders a multi-tab financial dashboard with budgeting, debt tracking, savings forecasting, investment planning, and Claude-powered AI analysis. @@ -159,6 +159,7 @@ const State = { txOverrides: {}, // { [txId]: TxOverride } — user edits on transactions (shape below) manualBalances: {}, // { [accountId]: number, [accountId+'_limit']: number, [accountId+'_initial']: number } categoryRules: [], // { contains: string, category: string }[] + ruleCategories: {}, // { [txId]: category } — what Re-categorize all gave, where it differs from the import's (v1.16.25, §4.2) categories: [], // string[] — user-editable category list apiKey: '', // Anthropic API key aiHistory: [], // { timestamp, question, response, truncated?, model? }[] — model since v1.16.0 @@ -275,6 +276,13 @@ Transactions are created by `mkTx()` in `core.js` and never mutated directly — - **`loadStateFromFile()` passes the file's own `txRules`** to `reconstituteTx()`, because State gets them only after it returns. - **Store a flag only when the user changes it (v1.16.9).** `showTxDrawer()` remembers what its three boxes showed on opening. On save, a box changed from that is stored, ticked or unticked. An untouched box stores nothing, so it keeps following the rules, or keeps an edit already stored. Bulk **Mark as bill / subscription** stores only that one flag. Up to v1.16.8 every drawer save stored all three, so a transaction saved for its category alone stopped following the rules. Those stored flags are kept: they can't be told apart from deliberate ones. +**Categories (v1.16.25).** A transaction shows, in this order: its edit (`txOverrides[id].categories`, from the drawer, bulk Set category or deleting a category); for a detected transfer, Transfer in / Transfer out (`detectTransfers()`); what **Re-categorize all** gave it (`State.ruleCategories[id]`); else its import's category (`_originalCategories`). +- **Category rules don't re-apply on load,** unlike flag rules. They apply when a CSV is imported (`normalizeRow()`: a checking or savings row gets `autoCategory()`; a card row with a CSV Category keeps it) and to what's already loaded only when the user clicks Re-categorize all. So its result is data to save, not something worked out again. +- **Re-categorize all** (`recategorizeAll()`, ui.js) gives each loaded transaction `categoryFromRules()`: a category rule matching `_originalDesc`, else the CSV's own Category for a format that has the column (the card export), else the built-in rules (`DEFAULT_RULES`). It saves the result in `State.ruleCategories` only where it differs from the import's category or from the IndexedDB row's, and removes it where it's the same as both again (a rule removed). 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. It saves it under edits and detected transfers too, without changing what they show. +- **Applied by `mkTx()` and `reconstituteTx()`,** so it holds after a reload from IndexedDB or `finlens-state.json`, a re-import, Rebuild and Clear transaction edits. `reconstituteTx()` leaves a record that is a transfer alone: a state file's transfers keep the category detection gave them, and that boot doesn't detect transfers again. `loadStateFromFile()` passes the file's own `ruleCategories`. +- **Not in the IndexedDB rows.** They can be missing (§4.5), Rebuild and Clear transactions empty the store, a re-import skips rows already stored, and a row holds the CSV's values (§10). +- **Up to v1.16.24** Re-categorize all changed only memory, so a reload brought the import's categories back. It also gave card rows with no matching rule the built-in category and overwrote transfer categories. + ### 4.3 The Account Model ```js @@ -549,6 +557,7 @@ _saveStateDebounced() // Debounced wrapper (5s) — called by lsSet() filteredTx() // State.transactions filtered by active range + selected accounts orderedAccounts() // Object.values(State.accounts) in user-defined display order (ids with no account are skipped) autoCategory(description) // Returns category string based on rules + DEFAULT_RULES +categoryFromRules(t, importCat) // Re-categorize all's category for t: a rule, else importCat for a format with a Category column, else autoCategory() (§4.2) txRuleFlag(desc, flag, rules?) // true if a transaction rule for that flag matches; rules default to State.txRules txFlags(desc, ov, rules?) // { isRecurring, isBill, isSubscription }: the edit in ov, else the rules (§4.2) applyTxRulesToAll() // re-works out every loaded transaction's flags (after a rule changes) @@ -700,7 +709,7 @@ linkedTransactions(type, id) // transactions linked to it, newest first unlinkPlanItems(type, ids) // remove links to those items (an id or a list; a missing id removes nothing), or ids 'all': every item of the type; saves txOverrides; returns the count ensurePlanIds() // give an item without an id one (the transaction drawer calls it before listing items) confirmRecurring(r), dismissRecurring(key), undoDismissRecurring(key) // r: a detectRecurring() entry -addCatRule(), delCatRule(i), recategorizeAll() +addCatRule(), delCatRule(i), recategorizeAll() // recategorizeAll() is async and saves State.ruleCategories (v1.16.25, §4.2) exportAllData(), importJsonFile(ev) // Settings → Data & reset → Export / Import JSON (v1.16.0; before, no button called them) // JSON_EXPORT_KEYS: what's in the file, version 1.2 (v1.16.6, §20) applyImportedEdits(before) // (v1.16.18) after a JSON import with edits: each loaded transaction = its CSV values + its edit, then detectTransfers() @@ -1102,7 +1111,7 @@ Multiple credit card files can be loaded simultaneously. Each gets a unique `acc --- -*Last updated: v1.16.24 — 2026-11-02 (a transfer that stops being one gets its own type and category back: §8 `undoTransferDetection()`, §11 un-transferring; v1.16.23: transfer detection respects the user's type and categories: §1 version, §4.1 the drawers note, §11 the user's edit wins; v1.16.22: §13 the AI summary's trend stops at a past period's end, subscriptions labelled current; §21 the parser finds sections by their heading's start; v1.16.21: §8 `overrideBalanceAt()`, `balanceAt()`; §18 a card's amount owed is taken back plus the later transactions, a bank balance minus them; the sign of a card's balance; v1.16.20: §18 a balance override at the end of every range is the override less the later transactions, no 7-day exception; v1.16.19: overlapping exports of one account count each shared row once: §4.5 one transaction per id; §8 `mergeImported()`, `importParsedCsv()`; §10 overlapping exports of one account; §19 the leftover-copy check keeps the import's ids; v1.16.18: a JSON import's transaction edits show at once: §9 `applyImportedEdits()`; §20 what takes effect without a reload; v1.16.17: a file read into another account takes its rows with it: §4.3 the account's `files`, `accountFiles()`; §4.5 the exception to an import never dropping rows; §8 `accountFiles()`, `earlierCopies()`, `moveEarlierCopies()`; §10 Read as changes the ids; §19 `DB.removeTransactions()`, `DB.patchAccount()`; §22 `_rekey()` is also used by imports; v1.16.16: the transaction and transfer drawers store only the fields you change: §4.1 TxOverride, §11 transfer keywords, §12 state mutations; v1.16.15: §1 desktop only; §3 `views-database.js` removed, the Changelog view reads CHANGELOG.md; §6, §18, §19 point to the current screens; v1.16.14: §9 the drawer is a modal dialog: inert page, Tab wraps, first field focused, focus returns after a re-render; v1.16.13: account order: §4.1 `accountOrder` keeps ids not loaded; §8 `orderedAccounts()`; §18 display order; v1.16.12: account names: §4.1 `accountLabels`; §4.3 an account's `name` is its default; §8 `defaultAccountName()`; §9 `acctName()`; §13 the summary lists accounts by `acctName()`; §18 names you type, and clearing them; v1.16.11: AI summary balances at the end of the selected period: §13 `summaryBalanceEnd()` and the date notes; §21 the parser reads the balance lines by how they start; v1.16.10: starting balance counted in every range: §8 `startingBalance()`, `currentBalances()`; §13 summary balances; §18 one balance rule; v1.16.9: the transaction drawer stores only the flags you change: §4.2 flags, §12 state mutations; v1.16.8: flags from transaction rules are worked out on load, never read from storage: §4.2 flags, §8 `txRuleFlag()` / `txFlags()` / `applyTxRulesToAll()`, §19 flags in the transactions store; v1.16.7: transaction links to budgets, buckets and debts by id: §1 version; §3 migrate.js role; §4.1 the `id` fields, TxOverride and its `link` shape; §8 `PLAN_LINK_TYPES`, `newPlanId()`; §9 `planItem()`, `linkedTransactions()`, `unlinkPlanItems()`, `ensurePlanIds()`; §20 clearing budgets, buckets or debts removes their links; §22 the plan-link migration; v1.16.6: JSON export carries account names and order, Read as, flag rules, transfer keywords and theme: §9 `JSON_EXPORT_KEYS`; §12 adding a persisted field; §20 what the export holds; v1.16.5: a new database copies every saved setting: §4.5 the keys that go through `storageKey()`; §12 adding a persisted field; §19 `DB.APP_STATE_KEYS`; v1.16.4: JSON import saves under the storage keys: §4.5 `STORAGE_KEYS` / `storageKey()`; §8 `storageKey()`; §12 adding a persisted field uses the State name; v1.16.3: An import keeps the loaded transactions it doesn't replace: §4.5 an import never drops loaded transactions; §8 `mergeImported()`, `undoTransferDetection()`; §10 memory follows the same re-upload rules; §11 kept transfers are detected again; v1.16.2: Imports read every file before changing anything: §8 `loadFiles()` options and result, `parseCsvFile()` reads only, `importParsedCsv()`, `importProblemText()`, `reloadFromDirHandle()`; §20 Rebuild from your folder reads before it clears, read before clearing; v1.16.1: Clear transaction edits works from memory: §4.2 `_originalCategories`, `_originalType` and what a transaction keeps of its row; §4.5 IndexedDB may not hold the loaded transactions; §10 a stored row holds the CSV's values; §20 Clear transaction edits; v1.16.0: Trends, AI Analysis, Settings and the Welcome rebuilt: §3 file roles; §4.1 `cardDetails`, `sampleData`, AI history `model`; §6 tile tokens and Insights/Settings/Welcome components; §7 rule 7 covers Trends; §8 `loadFiles()` sample option; §9 `shellHero()`, `NO_RANGE_VIEWS`, ☰ → ×, JSON export/import buttons; §12 Settings tabs renamed, the Welcome, range label hidden on Trends and Settings; §13 quick analyses, tab state, history; §20 new fields, Use my own files, Export/Import JSON; §21 quick analyses send `AI_PROMPTS`; v1.15.0: Plan screens rebuilt: §3 file roles; §4.1 `debtPlan` and the Budget / Bucket / Debt / Scenario shapes; §6 `--teal-text` and Plan components; §7 rule 7 covers the Plan charts; §8 plan helpers (`payoffPlan()`, `growthByYear()` …); §9 plan form helpers, `simulatePayoff()` kept unused; §12 Plan titles, Forecast tabs, range label hidden on Plan screens; §13 debt balances in the summary; §20 Clear forecast scenarios / investment mix, Clear debts resets `debtPlan`; v1.14.0: Finances screens rebuilt: §4.1 Bill shape and `recurringConfirmed`; §6 new tokens and Finances components; §7 rule 7 inline SVG charts; §8 new aggregation helpers; §9 drawer, `TX_VIEWS`, SVG/heatmap/format helpers, bill helpers, removed renderers; §11 keywords re-run detection, `transferPairs()`, card payments; §12 page actions and Transactions pills; §20 Clear bills also clears spotted-charge choices; v1.13.0: Clarity redesign — §6 tokens and components; §9 theme, chart colors and app bar helpers; §12 app bar navigation replaces the sidebar and the emoji rule; §17 footer; §20 Data & Reset; v1.12.0: bank-neutral account codes, names, samples and docs; §22 `migrate.js` added; §3, §4, §5, §10, §18, §21 updated; v1.10.5: no section changes: Import Logs race fix; v1.10.4: §8, §13 single `~` is literal; §21 excerpts escape `~`; v1.10.3: §13 refusals; §21 declined runs; v1.10.2: §13 summary states its dates; §21 per-month derivations; v1.10.1: §13 `AI_MAX_TOKENS`, thinking and cut-off answers; v1.10.0: §21 AI Eval added; §13 `callClaude()` raw mode; v1.9.6: §14 folder access lasts until the last tab closes, not one page load; v1.9.5: §7 chart guard; v1.9.4: views-db.js changelog reads CRLF checkouts; v1.9.3: §14 folder permission: re-request on click, Reconnect banner, browser copy wins; v1.9.2: §0 branch, PR and approval workflow added; v1.9.1: §4.5 rehydrate transactions loaded from JSON; v1.9.0: §20 Data & Reset added; v1.8.1: §10 re-upload dedup rewritten for the occurrence-suffix fix; v1.8.0: AI Analysis restored with API-key and output hardening; `renderMarkdown()` added; `samples/` added; §1–3, §13, §14, §17 corrected to match the code)* +*Last updated: v1.16.25 — 2026-11-02 (Re-categorize all is saved: §1 version; §4.1 `ruleCategories`; §4.2 categories; §8 `categoryFromRules()`; §9 `recategorizeAll()`; §20 where `ruleCategories` is kept, what clears it, left out of the JSON export; v1.16.24: a transfer that stops being one gets its own type and category back: §8 `undoTransferDetection()`, §11 un-transferring; v1.16.23: transfer detection respects the user's type and categories: §1 version, §4.1 the drawers note, §11 the user's edit wins; v1.16.22: §13 the AI summary's trend stops at a past period's end, subscriptions labelled current; §21 the parser finds sections by their heading's start; v1.16.21: §8 `overrideBalanceAt()`, `balanceAt()`; §18 a card's amount owed is taken back plus the later transactions, a bank balance minus them; the sign of a card's balance; v1.16.20: §18 a balance override at the end of every range is the override less the later transactions, no 7-day exception; v1.16.19: overlapping exports of one account count each shared row once: §4.5 one transaction per id; §8 `mergeImported()`, `importParsedCsv()`; §10 overlapping exports of one account; §19 the leftover-copy check keeps the import's ids; v1.16.18: a JSON import's transaction edits show at once: §9 `applyImportedEdits()`; §20 what takes effect without a reload; v1.16.17: a file read into another account takes its rows with it: §4.3 the account's `files`, `accountFiles()`; §4.5 the exception to an import never dropping rows; §8 `accountFiles()`, `earlierCopies()`, `moveEarlierCopies()`; §10 Read as changes the ids; §19 `DB.removeTransactions()`, `DB.patchAccount()`; §22 `_rekey()` is also used by imports; v1.16.16: the transaction and transfer drawers store only the fields you change: §4.1 TxOverride, §11 transfer keywords, §12 state mutations; v1.16.15: §1 desktop only; §3 `views-database.js` removed, the Changelog view reads CHANGELOG.md; §6, §18, §19 point to the current screens; v1.16.14: §9 the drawer is a modal dialog: inert page, Tab wraps, first field focused, focus returns after a re-render; v1.16.13: account order: §4.1 `accountOrder` keeps ids not loaded; §8 `orderedAccounts()`; §18 display order; v1.16.12: account names: §4.1 `accountLabels`; §4.3 an account's `name` is its default; §8 `defaultAccountName()`; §9 `acctName()`; §13 the summary lists accounts by `acctName()`; §18 names you type, and clearing them; v1.16.11: AI summary balances at the end of the selected period: §13 `summaryBalanceEnd()` and the date notes; §21 the parser reads the balance lines by how they start; v1.16.10: starting balance counted in every range: §8 `startingBalance()`, `currentBalances()`; §13 summary balances; §18 one balance rule; v1.16.9: the transaction drawer stores only the flags you change: §4.2 flags, §12 state mutations; v1.16.8: flags from transaction rules are worked out on load, never read from storage: §4.2 flags, §8 `txRuleFlag()` / `txFlags()` / `applyTxRulesToAll()`, §19 flags in the transactions store; v1.16.7: transaction links to budgets, buckets and debts by id: §1 version; §3 migrate.js role; §4.1 the `id` fields, TxOverride and its `link` shape; §8 `PLAN_LINK_TYPES`, `newPlanId()`; §9 `planItem()`, `linkedTransactions()`, `unlinkPlanItems()`, `ensurePlanIds()`; §20 clearing budgets, buckets or debts removes their links; §22 the plan-link migration; v1.16.6: JSON export carries account names and order, Read as, flag rules, transfer keywords and theme: §9 `JSON_EXPORT_KEYS`; §12 adding a persisted field; §20 what the export holds; v1.16.5: a new database copies every saved setting: §4.5 the keys that go through `storageKey()`; §12 adding a persisted field; §19 `DB.APP_STATE_KEYS`; v1.16.4: JSON import saves under the storage keys: §4.5 `STORAGE_KEYS` / `storageKey()`; §8 `storageKey()`; §12 adding a persisted field uses the State name; v1.16.3: An import keeps the loaded transactions it doesn't replace: §4.5 an import never drops loaded transactions; §8 `mergeImported()`, `undoTransferDetection()`; §10 memory follows the same re-upload rules; §11 kept transfers are detected again; v1.16.2: Imports read every file before changing anything: §8 `loadFiles()` options and result, `parseCsvFile()` reads only, `importParsedCsv()`, `importProblemText()`, `reloadFromDirHandle()`; §20 Rebuild from your folder reads before it clears, read before clearing; v1.16.1: Clear transaction edits works from memory: §4.2 `_originalCategories`, `_originalType` and what a transaction keeps of its row; §4.5 IndexedDB may not hold the loaded transactions; §10 a stored row holds the CSV's values; §20 Clear transaction edits; v1.16.0: Trends, AI Analysis, Settings and the Welcome rebuilt: §3 file roles; §4.1 `cardDetails`, `sampleData`, AI history `model`; §6 tile tokens and Insights/Settings/Welcome components; §7 rule 7 covers Trends; §8 `loadFiles()` sample option; §9 `shellHero()`, `NO_RANGE_VIEWS`, ☰ → ×, JSON export/import buttons; §12 Settings tabs renamed, the Welcome, range label hidden on Trends and Settings; §13 quick analyses, tab state, history; §20 new fields, Use my own files, Export/Import JSON; §21 quick analyses send `AI_PROMPTS`; v1.15.0: Plan screens rebuilt: §3 file roles; §4.1 `debtPlan` and the Budget / Bucket / Debt / Scenario shapes; §6 `--teal-text` and Plan components; §7 rule 7 covers the Plan charts; §8 plan helpers (`payoffPlan()`, `growthByYear()` …); §9 plan form helpers, `simulatePayoff()` kept unused; §12 Plan titles, Forecast tabs, range label hidden on Plan screens; §13 debt balances in the summary; §20 Clear forecast scenarios / investment mix, Clear debts resets `debtPlan`; v1.14.0: Finances screens rebuilt: §4.1 Bill shape and `recurringConfirmed`; §6 new tokens and Finances components; §7 rule 7 inline SVG charts; §8 new aggregation helpers; §9 drawer, `TX_VIEWS`, SVG/heatmap/format helpers, bill helpers, removed renderers; §11 keywords re-run detection, `transferPairs()`, card payments; §12 page actions and Transactions pills; §20 Clear bills also clears spotted-charge choices; v1.13.0: Clarity redesign — §6 tokens and components; §9 theme, chart colors and app bar helpers; §12 app bar navigation replaces the sidebar and the emoji rule; §17 footer; §20 Data & Reset; v1.12.0: bank-neutral account codes, names, samples and docs; §22 `migrate.js` added; §3, §4, §5, §10, §18, §21 updated; v1.10.5: no section changes: Import Logs race fix; v1.10.4: §8, §13 single `~` is literal; §21 excerpts escape `~`; v1.10.3: §13 refusals; §21 declined runs; v1.10.2: §13 summary states its dates; §21 per-month derivations; v1.10.1: §13 `AI_MAX_TOKENS`, thinking and cut-off answers; v1.10.0: §21 AI Eval added; §13 `callClaude()` raw mode; v1.9.6: §14 folder access lasts until the last tab closes, not one page load; v1.9.5: §7 chart guard; v1.9.4: views-db.js changelog reads CRLF checkouts; v1.9.3: §14 folder permission: re-request on click, Reconnect banner, browser copy wins; v1.9.2: §0 branch, PR and approval workflow added; v1.9.1: §4.5 rehydrate transactions loaded from JSON; v1.9.0: §20 Data & Reset added; v1.8.1: §10 re-upload dedup rewritten for the occurrence-suffix fix; v1.8.0: AI Analysis restored with API-key and output hardening; `renderMarkdown()` added; `samples/` added; §1–3, §13, §14, §17 corrected to match the code)* --- @@ -1151,9 +1160,9 @@ CSV files on disk are **never** modified. | Action | Does | Keeps | |---|---|---| -| Clear transactions & accounts | Empties memory + `transactions`/`accounts` stores; turns `sampleData` off; with a folder connected, sets `csvAutoImportPaused` | Plans, edits, account labels/balances, `cardDetails`, settings | +| Clear transactions & accounts | Empties memory + `transactions`/`accounts` stores; turns `sampleData` off; with a folder connected, sets `csvAutoImportPaused` | Plans, edits, `ruleCategories`, account labels/balances, `cardDetails`, settings | | Clear import log | Empties `import_log` | Everything else | -| Clear transaction edits | `txOverrides` + `tx_overrides` store; rebuilds each loaded transaction without its edit, from memory (`_unedited()`), then `detectTransfers()` | Every loaded transaction; the `transactions` store as it is | +| Clear transaction edits | `txOverrides` + `tx_overrides` store; rebuilds each loaded transaction without its edit, from memory (`_unedited()`), then `detectTransfers()` | Every loaded transaction; the `transactions` store as it is; `ruleCategories` (not edits: a transaction re-categorized under its edit shows the rule's category) | | Clear budgets / bills / buckets / debts / forecast scenarios / investment mix / AI history | `State[key] = []` (`{}` for `investAlloc`; the empty value is `PLAN_ITEMS[i][2]`) + `lsSet`. Bills also resets `recurringConfirmed` (confirmed/dismissed spotted charges); Debts also resets `debtPlan` (`PLAN_ALSO`). Budgets, buckets and debts also remove the transaction links to them (`unlinkPlanItems(type, 'all')`, saved as `txOverrides`, v1.16.7) | Other edits on those transactions | | Rebuild from folder | `reloadFromDirHandle()` reads every CSV first; only if they can all be read (`_rebuildBlockers()`) it clears transactions, accounts and import log (in `beforeImport`), then imports them | Plans, edits, settings; everything, when a CSV can't be read | | Disconnect folder | `forgetDataFolder()` — stops CSV auto-reload and state-file writes | Files on disk | @@ -1178,10 +1187,11 @@ CSV files on disk are **never** modified. - **After the clear, the import finishes.** `importParsedCsv()` logs a failing IndexedDB write and carries on, so `_finish()` still saves every transaction to the file. - **Start over must leave nothing behind.** It sets `State._resetInProgress` so a pending debounced save can't re-create the file, and `DB.open()` registers `onversionchange` so other tabs release the database. `idbGet`/`idbSet`/`idbDel` close their connections so `finlens_fs` can be deleted. - **Fields added in v1.16.0:** `cardDetails` and `sampleData` live in localStorage, IndexedDB `app_state` (`DB.loadAll()`) and `finlens-state.json`; Start over erases both with everything else. `cardDetails` is also in the JSON export. Importing your own files turns `sampleData` off after clearing the samples (`loadFiles()`). -- **No link outlives its item (v1.16.7).** Clearing budgets, buckets or debts removes the `txOverrides[…].link`s of that type, as deleting one item removes the links to it. Clear transaction edits and Start over remove every link with the rest of the edits. The ids live inside `budgets`, `buckets` and `debts`, so no new place stores data. +- **`ruleCategories` (v1.16.25)** lives in localStorage, IndexedDB `app_state` and `finlens-state.json`, like `txOverrides`, and is kept by the same actions (it's keyed by transaction id, so an import brings it back with the transactions). Only Start over erases it. Re-categorize all removes a transaction's entry once its category is the import's again (its rule removed). Not in the JSON export (below). +- **No link outlives its item (v1.16.7). Clearing budgets, buckets or debts removes the `txOverrides[…].link`s of that type, as deleting one item removes the links to it. Clear transaction edits and Start over remove every link with the rest of the edits. The ids live inside `budgets`, `buckets` and `debts`, so no new place stores data. - `clearAllData()` is kept as a wrapper for `DataCleanup.startOver('archive')`. Up to v1.8.1 it only cleared `localStorage`, which IndexedDB and the state file then restored on reload. - **The JSON export holds everything you entered or chose (v1.16.6).** `JSON_EXPORT_KEYS` (`ui.js`) lists the State keys and the kind of value each holds (`list`, `map`, `theme`); `exportAllData()` writes them with `version: '1.2'` and `importJsonFile()` reads the same list. - - **Left out:** transactions and accounts (the CSVs bring them back), the API key (§15), this browser's own state (`sampleData`, `csvAutoImportPaused`, `lastFolderName`), the session (date range, accounts filter, current view) and `customSchemas` (nothing creates one, §19). + - **Left out:** transactions and accounts (the CSVs bring them back), the API key (§15), this browser's own state (`sampleData`, `csvAutoImportPaused`, `lastFolderName`), the session (date range, accounts filter, current view), `customSchemas` (nothing creates one, §19) and `ruleCategories` (worked out from the category rules, which are in it: Re-categorize all after an import gives it again). - **Import:** accepts any version (1.0, 1.1, 1.2). A key that's missing, null or of the wrong kind keeps its current value. Each key is saved through `storageKey()` (§4.5). A file that isn't a JSON object is refused. - **Takes effect without a reload** (`_applyImportedSettings()`, for keys whose value changed): account names and order, flag rules (`applyTxRulesToAll()`), transfer keywords (`reapplyTransferKeywords()`), the theme (`applyTheme()`) and transaction edits (v1.16.18). Category rules apply to the next import, "Read as" choices to the next CSV read. - **Transaction edits** (`applyImportedEdits()`, v1.16.18): every loaded transaction is rebuilt from its CSV values (`DataCleanup._unedited()`, as Clear transaction edits does) with its imported edit on top (`reconstituteTx()`), then `detectTransfers()` runs. That's what importing the CSVs with these edits makes. A transaction the file has no edit for goes back to its CSV values, and flags an edit doesn't set follow the rules now in State. This rebuild covers new flag rules and transfer keywords too, so with new edits those two steps don't run on their own. Plan links need nothing: they're read from `State.txOverrides`. Up to v1.16.17 the edits were only saved: every screen kept the old values until a reload, and a reload from `finlens-state.json` kept an old edit's category and type where the file had no edit. diff --git a/README.md b/README.md index 94f0ffb..c24decc 100644 --- a/README.md +++ b/README.md @@ -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 --- @@ -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). @@ -263,4 +263,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.* diff --git a/index.html b/index.html index 16a1dbc..bcb400f 100644 --- a/index.html +++ b/index.html @@ -1202,7 +1202,7 @@
-
v1.16.24 · FinLens
+
v1.16.25 · FinLens
diff --git a/js/core.js b/js/core.js index a77c07b..4912ffe 100644 --- a/js/core.js +++ b/js/core.js @@ -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); } @@ -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, @@ -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', @@ -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) { @@ -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, diff --git a/js/db.js b/js/db.js index cc53bc1..0b31a19 100644 --- a/js/db.js +++ b/js/db.js @@ -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, @@ -54,6 +60,7 @@ const DB = { ['txOverrides', {}], ['manualBalances', {}], ['categoryRules', []], // stored as 'catRules' + ['ruleCategories', {}], ['categories', null], ['apiKey', ''], ['aiHistory', []], diff --git a/js/ui.js b/js/ui.js index 2a72d4f..fe8ce5c 100644 --- a/js/ui.js +++ b/js/ui.js @@ -550,12 +550,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(); } @@ -906,7 +941,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={ diff --git a/js/views-db.js b/js/views-db.js index 89a0a99..6007ff7 100644 --- a/js/views-db.js +++ b/js/views-db.js @@ -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', }, ]; diff --git a/js/views-eval.js b/js/views-eval.js index 2b441b6..97e0508 100644 --- a/js/views-eval.js +++ b/js/views-eval.js @@ -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: [], diff --git a/js/views-settings.js b/js/views-settings.js index 94da85f..4b309a3 100644 --- a/js/views-settings.js +++ b/js/views-settings.js @@ -67,7 +67,7 @@ function _renderGeneralSettings(root) { ``).join('')} -
VersionFinLens v1.16.24
+
VersionFinLens v1.16.25
`); const opts=$$('[data-theme-opt]',root); opts.forEach((b,i)=>{