diff --git a/CHANGELOG.md b/CHANGELOG.md index a6a7437..05223e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,21 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). --- +## [1.16.10] — 2026-11-02 + +### Overview and balances +- **A bank account's starting balance now counts in every date range, All time included.** Before, All time left it out, so the Overview's net worth and account cards changed with the range. + - **What went wrong:** `currentBalances()` added up an account's transactions but never its starting balance (`manualBalances[id+'_initial']`, Settings → Accounts). `periodEndBalance()` uses it for All time. Every other range, the net worth chart, the sparklines and Trends (`balanceAt()`) did add it. With the samples and starting balances of $1,000 (checking) and $250.50 (savings), All time showed a net worth of $15,499.81 while its own chart ended at $16,750.31. Last 6 months showed $16,750.31. + - **Fix:** `currentBalances()` adds the starting balance. A new `startingBalance()` reads it, and `periodEndBalance()` and `balanceAt()` now use it too, so the three follow one rule (`aggregation.js`, CLAUDE.md §18). +- **Also fixed, since they read today's balance:** Savings buckets' "Unassigned savings", the starting checking and savings on Forecast → Savings, and the savings card's "assigned to buckets" note on All time. +- **Unchanged:** a balance override still wins. That's a card's amount owed, or a bank "current balance" saved before v1.16.0, which takes the place of the starting balance as before. With no starting balance set, every number is what it was. +- **A card with a starting balance** (possible only from older data or a JSON import) now counts it on All time too, as the other ranges already did. + +### AI Analysis +- **The summary's balances include the starting balance:** the Accounts and Total Cash lines, in every range. Nothing else in the summary changed. With no manual balances it is byte-identical to v1.16.0. The AI Eval's sandbox sets none, so the published eval results still hold. + +--- + ## [1.16.9] — 2026-11-02 ### Fixed diff --git a/CLAUDE.md b/CLAUDE.md index d29f752..c9ed6cb 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.9 (updated in `index.html` footer, `README.md`, and `CHANGELOG.md` on every release). +**Current version:** v1.16.10 (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. @@ -545,8 +545,9 @@ byMonth(txs) // { month, income, expense, transfer }[] sorted by m sumIncome(txs) // Sum of positive non-transfer, non-payment amounts sumExpense(txs) // Sum of abs(negative non-transfer amounts) sumTransfers(txs) // Sum of transfer amounts / 2 (to avoid double-counting) -currentBalances() // { [accountId]: number } — best available current balances -periodEndBalance(accountId) // Balance at end of the active date range +currentBalances() // { [accountId]: number } — today's balances: an override, else starting balance + every transaction (§18) +periodEndBalance(accountId) // Balance at end of the active date range; All time = currentBalances() +startingBalance(accountId) // manualBalances[id+'_initial'], or 0 — shared by the three balance helpers (v1.16.10) detectRecurring() // Recurring charge detection across all transactions detectRecurringDeposits() // Recurring income detection recurringKey(desc), depositKey(desc) // the grouping keys the two detectors use @@ -884,7 +885,7 @@ Views build a fresh DOM on every `showView()` call. This is intentional. Do not - Uses the model in `AI_MODEL` (currently `claude-sonnet-5-5`) via direct browser fetch to `https://api.anthropic.com/v1/messages`. `claude-sonnet-4-20250514` was retired 2026-06-15 — check Anthropic's model deprecations page before changing models. - Requires `anthropic-dangerous-direct-browser-access: true` header (CORS bypass). - API key is stored in `State.apiKey` (localStorage + IndexedDB `app_state` only — **never** in `finlens-state.json`, see §4.5). It is entered in **Settings → General → Anthropic API Key**; the settings card never renders the stored value back into the DOM. **Never log or expose it.** -- `buildFinancialSummary()` assembles a plain-text snapshot of current State. Debts report `debtBalance(d)`: a debt linked to a card account gives the card's current balance (v1.15.0); others give `d.balance` as before. **It always states its dates (v1.10.2):** +- `buildFinancialSummary()` assembles a plain-text snapshot of current State. Account balances, total cash and net worth are `currentBalances()`: today's balances, whatever the range, with the starting balance included (v1.16.10; before, it was left out). The eval sandbox sets no manual balances, so the eval's summary didn't change. Debts report `debtBalance(d)`: a debt linked to a card account gives the card's current balance (v1.15.0); others give `d.balance` as before. **It always states its dates (v1.10.2):** - **The period line** gives the span of the transactions it covers (`summarySpan()`), e.g. "Period: All time (transactions from May 1, 2026 to Oct 20, 2026: 173 days, about 5.7 months)". - **A partial month** in the monthly trend is marked (`partialMonthNote()`), e.g. "2026-10 (through Oct 20)". @@ -1017,11 +1018,17 @@ Also update **Current version** in §1 of this file. Never close out a change wi | `credit_card` | Bank Credit Card(s) | Manual override in Data tab | | `unknown` | Any other CSV | Computed from transactions + initial balance | +**One balance rule** for `currentBalances()`, `periodEndBalance()` and `balanceAt()`, in every date range, All time included (v1.16.10): +- **A balance override** (`manualBalances[id]`: a card's amount owed, or a bank's current balance saved before v1.16.0) is today's balance. At an earlier date it's the override minus the later transactions. The starting balance doesn't count. `periodEndBalance()` keeps one exception: a range that ends within 7 days of today shows the override as it is. +- **Otherwise:** the starting balance (`manualBalances[id+'_initial']`, read by `startingBalance()`) plus the transactions up to that date. + +Up to v1.16.9, `currentBalances()` left the starting balance out, so All time and the AI summary ignored it while every other range used it. Keep the three helpers on this one rule. + Multiple credit card files can be loaded simultaneously. Each gets a unique `accountId` derived from the filename: `card_` + sanitized filename, and a default name `Bank Credit Card ()`. --- -*Last updated: v1.16.9 — 2026-11-02 (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.10 — 2026-11-02 (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)* --- diff --git a/README.md b/README.md index a52391d..c28cecc 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.9  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None +**Version:** v1.16.10  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None --- @@ -261,4 +261,4 @@ See [CHANGELOG.md](CHANGELOG.md) for the full release history. --- -*FinLens v1.16.9 — Built for one person's finances, designed to be useful for anyone's.* +*FinLens v1.16.10 — Built for one person's finances, designed to be useful for anyone's.* diff --git a/index.html b/index.html index f0ea441..ea277d8 100644 --- a/index.html +++ b/index.html @@ -1164,7 +1164,7 @@
- + diff --git a/js/aggregation.js b/js/aggregation.js index 9264b95..939ced1 100644 --- a/js/aggregation.js +++ b/js/aggregation.js @@ -42,13 +42,25 @@ function byMonth(txs) { } /* ---------- BALANCE COMPUTATION ---------- */ +// One rule for an account's balance, in currentBalances(), periodEndBalance() and balanceAt(): +// - a balance override (manualBalances[id]: a card's amount owed, or a bank balance saved +// before v1.16.0) is today's balance, and the starting balance doesn't count; +// - otherwise the starting balance plus the transactions so far. +// The starting balance: what the account held before its first imported transaction +// (Settings → Accounts, manualBalances[id+'_initial']). 0 when not set. +function startingBalance(accountId) { + const v=State.manualBalances[accountId+'_initial']; + return v!=null?Number(v):0; +} +// Today's balance of every account. Up to v1.16.9 the starting balance was left out here, +// so All time on the Overview and the AI summary ignored it while every other range used it. function currentBalances() { const out={}; Object.values(State.accounts).forEach(a=>{ if (State.manualBalances[a.id]!=null) { out[a.id]=Number(State.manualBalances[a.id]); return; } const withBal=State.transactions.filter(t=>t.account===a.id&&t.balance!=null).sort((x,y)=>y.date-x.date)[0]; if (withBal) { out[a.id]=withBal.balance; return; } - out[a.id]=State.transactions.filter(t=>t.account===a.id).reduce((s,t)=>s+t.amount,0); + out[a.id]=startingBalance(a.id)+State.transactions.filter(t=>t.account===a.id).reduce((s,t)=>s+t.amount,0); }); return out; } @@ -58,7 +70,7 @@ function currentBalances() { transactions from initial balance up to the period end. */ function periodEndBalance(accountId) { const r=State.range; - // For "all time" use the normal current-balance logic + // All time: today's balance (the same rule, with every transaction) if (!r.start&&!r.end) return currentBalances()[accountId]; const endDate=r.end||new Date(); @@ -76,9 +88,8 @@ function periodEndBalance(accountId) { } // Fallback: initial balance + sum of all transactions up to period end - const initial=State.manualBalances[accountId+'_initial']!=null?Number(State.manualBalances[accountId+'_initial']):0; const sum=State.transactions.filter(t=>t.account===accountId&&t.date<=endDate).reduce((s,t)=>s+t.amount,0); - return initial+sum; + return startingBalance(accountId)+sum; } /* ---------- RECURRING DETECTION ---------- */ @@ -178,8 +189,7 @@ function balanceAt(accountId, date) { if (State.manualBalances[accountId]!=null) { return Number(State.manualBalances[accountId])-txs.filter(t=>t.date>date).reduce((s,t)=>s+t.amount,0); } - const initial=State.manualBalances[accountId+'_initial']!=null?Number(State.manualBalances[accountId+'_initial']):0; - return initial+txs.filter(t=>t.date<=date).reduce((s,t)=>s+t.amount,0); + return startingBalance(accountId)+txs.filter(t=>t.date<=date).reduce((s,t)=>s+t.amount,0); } /* ---------- SPANS AND MONTHS (v1.14.0) ---------- */ diff --git a/js/views-settings.js b/js/views-settings.js index 3eac57e..f7944d3 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.9
+
VersionFinLens v1.16.10
`); /* ---- Anthropic API key ---- */