diff --git a/CHANGELOG.md b/CHANGELOG.md index 0774474..5c6dfbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,32 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). --- +## [1.16.8] — 2026-11-02 + +### Fixed +- **Flags set by transaction rules disappeared after a reload.** + - **Symptom:** a rule under **Transactions → Transaction rules** (for example LIBERTY INTERNET → Bill) flagged its transactions right away. After a reload they were unflagged (6 → 0 on the sample data), although the rule was still listed. Bill, Recurring and Subscription were all affected. A rule that existed when the CSVs were imported did the opposite: removing it unflagged its transactions until the next reload, which flagged them again. + - **Cause:** a transaction's flags were worked out once, when its CSV row was first imported (`mkTx()`), and stored in its IndexedDB row (`DB.importTransactions()`). Adding or removing a rule changed only the transactions in memory (`applyTxRulesToAll()`). A re-import skips rows already stored, so the stored flags never changed either. On reload, `reconstituteTx()` read the flags from the row. + - **The state file had the same problem.** A boot from `finlens-state.json` also read the flags from the file. The file was right only if it was saved while the flags in memory were. Once a reload had lost them, the next save wrote the lost flags into the file as well. + - **The bug was already on `master`** (v1.10.4). There, **Re-apply rules** brought the flags back until the next reload. v1.14.0 removed that button. + - **Fix:** the flags are worked out from your edits and the current rules whenever a transaction is built or loaded. `txFlags()` in `core.js` does it for `mkTx()`, `reconstituteTx()` and `applyTxRulesToAll()`. Stored flags are no longer read. `loadStateFromFile()` uses the file's own rules, which State only gets after the file is read. +- **Also fixed by this:** the Transactions table's Flags column and the transaction drawer's checkboxes, the Bills screen's spotted charges (a confirmed charge is a subscription if its transactions are) and the AI summary's subscription list. Each read the lost flags after a reload. +- **Clear transaction edits** (Settings → Data & reset) rebuilds transactions with `reconstituteTx()`, so it now gets the flags from `txFlags()` too. Since v1.16.1 it already set them from the rules (`DataCleanup._unedited()`), so its result is the same. + +### Unchanged +- **Your own flag edits still win.** A flag set or cleared in the transaction drawer, or with **Mark as bill** / **Mark as subscription**, is kept whatever the rules say. Saving the drawer stores all three flags as its checkboxes show them, even when you only changed the category, so that transaction no longer follows the rules either. +- **Stored data:** new IndexedDB rows still get the flags as they are at import. FinLens no longer reads them (the developer DB Inspector still shows them), so no data needs rewriting. +- **Without transaction rules, nothing changes.** On `samples/` the AI summary and the AI Eval's sample summary are byte-identical to v1.16.0's, so `docs/EVAL.md` stays valid. + +### Technical +- **`core.js`:** `txFlags(desc, ov, rules)` (new); `txRuleFlag()` takes an optional rule list; `mkTx()` and `applyTxRulesToAll()` use `txFlags()`; `loadStateFromFile()` passes the file's `txRules`. +- **`db.js`:** `reconstituteTx(raw, ov, rules)` uses `txFlags()`. + +### Docs +- **CLAUDE.md** — §1 version; §4.2 how the flags are worked out; §8 `txRuleFlag()`, `txFlags()`, `applyTxRulesToAll()`; §19 the flags in the `transactions` store. + +--- + ## [1.16.7] — 2026-11-02 ### Transactions, Budget, Savings buckets, Debt tracker diff --git a/CLAUDE.md b/CLAUDE.md index 70ebb77..a551969 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.7 (updated in `index.html` footer, `README.md`, and `CHANGELOG.md` on every release). +**Current version:** v1.16.8 (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. @@ -247,7 +247,7 @@ Transactions are created by `mkTx()` in `core.js` and never mutated directly — get category(), // Accessor: returns categories[0] || 'Other' account: string, // accountId (e.g. 'bank_checking', 'bank_savings', 'card_...') type: 'debit' | 'credit' | 'transfer' | 'payment', - isRecurring: boolean, + isRecurring: boolean, // the three flags: worked out on every build and load, never read from storage — see below isBill: boolean, isSubscription: boolean, notes: string, @@ -262,6 +262,12 @@ Transactions are created by `mkTx()` in `core.js` and never mutated directly — **What a transaction keeps of its CSV row:** the description (`_originalDesc`), the category and type (`_originalCategories`, `_originalType`), the amount and the date. Notes and plan links (`link`) exist only in its edit, and the flags without an edit come from the transaction rules (`txRuleFlag()`). Together these rebuild it without its edit, from memory alone (`DataCleanup._unedited()`). +**Flags (v1.16.8).** `isRecurring`, `isBill` and `isSubscription` come from `txFlags(desc, ov, rules?)` in `core.js`. An edit in `txOverrides` (the drawer's checkboxes, or bulk **Mark as bill / subscription**) wins. Otherwise a transaction rule (`State.txRules`: `{ contains, flag: 'bill' | 'recurring' | 'subscription' }`) matching `_originalDesc` sets the flag. +- **They are worked out whenever a transaction is built or loaded:** `mkTx()` (CSV import), `reconstituteTx()` (`DB.loadAll()`, `loadStateFromFile()`, Clear transaction edits) and `applyTxRulesToAll()` (after a rule is added or removed). +- **Never read them from storage.** The IndexedDB row and the state file hold the flags as they were when written. Before v1.16.8 `reconstituteTx()` read them from there, so a rule added after the import was lost on reload and a removed one came back. +- **`loadStateFromFile()` passes the file's own `txRules`** to `reconstituteTx()`, because State gets them only after it returns. +- **Saving the transaction drawer stores all three flags** as its checkboxes show them, so that transaction keeps them whatever the rules say later. + ### 4.3 The Account Model ```js @@ -529,6 +535,9 @@ _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 autoCategory(description) // Returns category string based on rules + DEFAULT_RULES +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) // Aggregation (aggregation.js — loaded after core.js) byCategory(txs, filter) // { category, amount }[] sorted by amount desc @@ -1012,7 +1021,7 @@ Multiple credit card files can be loaded simultaneously. Each gets a unique `acc --- -*Last updated: v1.16.7 — 2026-11-02 (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.8 — 2026-11-02 (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)* --- @@ -1028,6 +1037,7 @@ The full IndexedDB implementation is live. See **`docs/archive/INDEXEDDB_PLAN.md - **`State.transactions`** remains the in-memory working array. All views use `filteredTx()` unchanged. - **Bank Schema Registry** — `BANK_SCHEMAS` (global in `core.js`) drives CSV parsing. `detectSchema()` + `normalizeRow()` replace the old hardcoded normalizers. - **Transfer Keywords** — `State.transferKeywords` is user-editable from Settings. `detectTransfers()` builds its regex from this list. +- **Flags in the `transactions` store (v1.16.8)** — `DB.importTransactions()` still writes `isRecurring`, `isBill` and `isSubscription` into each new row, as they are at import, but FinLens never reads them back (only the developer DB Inspector shows them). Rows already stored are skipped on re-import, so they are never updated. `reconstituteTx()` works the flags out from `txOverrides` and the current rules (§4.2). ### Adding a new bank Add a new object to `BANK_SCHEMAS` in `core.js`. No other code changes needed if the bank follows standard column conventions (`date`, `amount`, `description`). For non-standard conventions use: `amountSign: 'inverted'`, custom `columns` map, `dateFormat` (`'YYYY-MM-DD'` | `'MM/DD/YYYY'` | `'DD/MM/YYYY'`), and `postDateFormat` if the post-date column uses a different format than the primary date column (see the `credit_card` schema). diff --git a/README.md b/README.md index 376455b..dc52a23 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.7  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None +**Version:** v1.16.8  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None --- @@ -261,4 +261,4 @@ See [CHANGELOG.md](CHANGELOG.md) for the full release history. --- -*FinLens v1.16.7 — Built for one person's finances, designed to be useful for anyone's.* +*FinLens v1.16.8 — Built for one person's finances, designed to be useful for anyone's.* diff --git a/index.html b/index.html index 1a5775a..46c0ae0 100644 --- a/index.html +++ b/index.html @@ -1164,7 +1164,7 @@
- + diff --git a/js/core.js b/js/core.js index e3c6049..d4f29b8 100644 --- a/js/core.js +++ b/js/core.js @@ -171,8 +171,10 @@ async function loadStateFromFile() { // monthKey()/date comparisons throw or misbehave (Income, Trends, AI summary). if (Array.isArray(loaded.transactions)) { const ovs = loaded.txOverrides || State.txOverrides || {}; + // Rule flags come from the file's own rules: State only gets them after this returns. + const rules = Array.isArray(loaded.txRules) ? loaded.txRules : State.txRules; loaded.transactions = loaded.transactions - .map(raw => reconstituteTx({ ...raw, description: raw._originalDesc || raw.description }, ovs[raw.id] || {})) + .map(raw => reconstituteTx({ ...raw, description: raw._originalDesc || raw.description }, ovs[raw.id] || {}, rules)) .filter(t => !isNaN(t.date)) .sort((a, b) => b.date - a.date); } @@ -593,23 +595,32 @@ function autoCategory(desc) { return 'Other'; } -/* Returns true if any txRule with given flag matches the description */ -function txRuleFlag(desc, flag) { +/* 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) { const u = (desc||'').toUpperCase(); - for (const r of (State.txRules||[])) { + for (const r of (rules||[])) { if (r.flag === flag && r.contains && u.includes(r.contains.toUpperCase())) return true; } return false; } -/* Apply all txRules to already-loaded transactions (called after adding/removing a rule) */ +/* A transaction's three flags: the user's own edit (txOverrides) wins, otherwise a + transaction rule matching the original CSV description sets it. mkTx(), reconstituteTx() + and applyTxRulesToAll() all work them out here and never read them from storage, so a + rule added, changed or removed holds after a reload (CLAUDE.md §4.2). Earlier versions' + reconstituteTx() read them from the stored row, which holds them as they were at import. */ +function txFlags(desc, ov, rules) { + ov = ov || {}; + const f = (key, flag) => key in ov ? !!ov[key] : txRuleFlag(desc, flag, rules); + return { isRecurring: f('isRecurring', 'recurring'), isBill: f('isBill', 'bill'), isSubscription: f('isSubscription', 'subscription') }; +} + +/* Apply all txRules to already-loaded transactions (called after adding/removing a rule). + A flag the user edited keeps its edit (txFlags()). */ function applyTxRulesToAll() { for (const t of State.transactions) { - const ov = State.txOverrides[t.id] || {}; - const src = t._originalDesc || t.description; - if (!('isBill' in ov)) t.isBill = txRuleFlag(src, 'bill'); - if (!('isSubscription' in ov)) t.isSubscription = txRuleFlag(src, 'subscription'); - if (!('isRecurring' in ov)) t.isRecurring = txRuleFlag(src, 'recurring'); + Object.assign(t, txFlags(t._originalDesc || t.description, State.txOverrides[t.id])); } } @@ -643,9 +654,7 @@ function mkTx(o) { get category(){ return this.categories[0] || 'Other'; }, account: ov.accountOverride || o.account, type: ov.type || o.type, - isRecurring: 'isRecurring' in ov ? !!ov.isRecurring : txRuleFlag(o.description, 'recurring'), - isBill: 'isBill' in ov ? !!ov.isBill : txRuleFlag(o.description, 'bill'), - isSubscription: 'isSubscription' in ov ? !!ov.isSubscription : txRuleFlag(o.description, 'subscription'), + ...txFlags(o.description, ov), notes: ov.notes || '', balance: null, _originalDesc: o.description, diff --git a/js/db.js b/js/db.js index c2651fc..bba7a56 100644 --- a/js/db.js +++ b/js/db.js @@ -7,7 +7,10 @@ /* ---------- reconstituteTx: rebuild in-memory tx from a DB record ---------- */ // Mirrors mkTx() but operates on already-stored plain objects (no schema needed). -function reconstituteTx(raw, ov) { +// 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) { ov = ov || {}; const cats = (ov.categories && ov.categories.length) ? ov.categories @@ -22,9 +25,7 @@ function reconstituteTx(raw, ov) { get category() { return this.categories[0] || 'Other'; }, account: ov.accountOverride || raw.account, type: ov.type || raw.type, - isRecurring: 'isRecurring' in ov ? !!ov.isRecurring : !!raw.isRecurring, - isBill: 'isBill' in ov ? !!ov.isBill : !!raw.isBill, - isSubscription: 'isSubscription' in ov ? !!ov.isSubscription : !!raw.isSubscription, + ...txFlags(src, ov, rules), notes: ov.notes || '', balance: null, _originalDesc: src, diff --git a/js/views-settings.js b/js/views-settings.js index 769b035..9e623e9 100644 --- a/js/views-settings.js +++ b/js/views-settings.js @@ -60,7 +60,7 @@ function _renderGeneralSettings(root) { /* ---- About (the Theme row is gone: light only for now) ---- */ appendHtml(root,`

About

-
VersionFinLens v1.16.7
+
VersionFinLens v1.16.8
`); /* ---- Anthropic API key ---- */