diff --git a/CHANGELOG.md b/CHANGELOG.md index 05223e3..1cbeb74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,19 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). --- +## [1.16.11] — 2026-11-02 + +### AI Analysis +- **The summary's balances now belong to the period it describes.** Before, it always sent today's balances, even when you picked a past date range. Its "Period:" line named the range, so the model read today's balances as that period's. + - **What went wrong:** `buildFinancialSummary()` read the Accounts, Total Cash, Total Debt and Net Worth figures from `currentBalances()` in every range. The Overview shows `periodEndBalance()`. With the samples and a range of Jul 1 – Aug 15, 2026, the Overview showed a net worth of $10,602.37 and the summary sent $16,750.31. + - **Fix:** when the range ends before the last transaction (Last year, a custom range ending in August, or Last month when you have transactions from this month), the summary sends each account's `periodEndBalance()`, the Overview's numbers. It says the date: "Accounts at the end of the period (Aug 15, 2026): …" and "… Net Worth: $10,602.37 (all on Aug 15, 2026)". A new `summaryBalanceEnd()` (`views-ai.js`) gives that date, or none. + - **Debts stay as they are now.** On those ranges their heading says so: "Debts (current balances, not at the end of the period):". A debt linked to a card can then show a different balance from the card in the Accounts line, and the heading explains why. +- **Unchanged:** All time, This month and every range that reaches the last transaction send the same summary as before, byte for byte. Their period-end balances are today's. +- **The AI Eval's summary is unchanged.** Its sandbox always uses All time, so the published results still hold. `parseSummary()` reads the new notes without a change: it finds the lines by how they start, and the notes hold no amounts. +- **Not changed:** "Recent monthly trend" and "Subscriptions" still come from all your transactions, whatever the range. Each trend line names its month. + +--- + ## [1.16.10] — 2026-11-02 ### Overview and balances diff --git a/CLAUDE.md b/CLAUDE.md index c9ed6cb..f59a694 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.10 (updated in `index.html` footer, `README.md`, and `CHANGELOG.md` on every release). +**Current version:** v1.16.11 (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. @@ -885,9 +885,13 @@ 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. 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):** +- `buildFinancialSummary()` assembles a plain-text snapshot of current State. Account balances, total cash and net worth are the balances at the end of the selected period, the numbers the Overview shows (v1.16.11). The starting balance is included (v1.16.10). 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)". + - **Balances on a past range (v1.16.11).** `summaryBalanceEnd()` gives the range end when it is before the last transaction, else null. + - **Null** (All time, This month, any range reaching the last transaction): `currentBalances()`, which equals `periodEndBalance()` there, and the summary is byte-identical to v1.16.10. + - **A date:** each account's `periodEndBalance()`, with the date on both balance lines: "Accounts at the end of the period (Aug 15, 2026): …" and "… Net Worth: $10,602.37 (all on Aug 15, 2026)". The Debts heading becomes "Debts (current balances, not at the end of the period):". + - **Why:** up to v1.16.10 the summary sent today's balances under a past period's "Period:" line, and the model read them as that period's. The eval sandbox always uses All time, so the eval's summary didn't change. Without them the model guessed the period length (6, 6.5 or even 9 months) to work out monthly figures, so the same data gave different answers. Never send totals without the dates they cover. - The summary is sent inside `` tags, and the system prompt tells the model to treat that content as data, not instructions (account names and merchant descriptions come from CSVs and are untrusted). @@ -1028,7 +1032,7 @@ Multiple credit card files can be loaded simultaneously. Each gets a unique `acc --- -*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)* +*Last updated: v1.16.11 — 2026-11-02 (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)* --- @@ -1127,7 +1131,7 @@ A developer-only view (`showView('ai-eval')`) that measures how well AI Analysis - **Declined runs** (`stop_reason` `refusal`) have no answer: they are counted in the *Calls* row, like failed calls, and left out of the scoring and token averages. - **Nothing persisted.** Results live in memory only and leave via the download buttons, so §20 needs no entry. Don't add `lsSet()` calls here. The API key is never put in results, exports or logs. - **A summary loaded from a results JSON is never sent.** It can be re-scored locally (`loadResults()` sets `dataset.fromFile`), but Run stays disabled until samples are reloaded and verified. -- **The summary format is parsed** by `parseSummary()`: the period line (`S.days`, `S.periodMonths`) and month lines with an optional `(through …)` / `(from …)` note. If `buildFinancialSummary()` changes, update the parser and its derivations *before* the next run. Example: the per-month figures over the period (total ÷ months as stated, or ÷ days/30.44) were added in v1.10.2 together with the dates. +- **The summary format is parsed** by `parseSummary()`: the period line (`S.days`, `S.periodMonths`) and month lines with an optional `(through …)` / `(from …)` note. If `buildFinancialSummary()` changes, update the parser and its derivations *before* the next run. Example: the per-month figures over the period (total ÷ months as stated, or ÷ days/30.44) were added in v1.10.2 together with the dates. The balance lines are matched by how they start (`Total Cash: `, `Debts`), so keep those starts: a past range's notes (v1.16.11, §13) go after `Accounts` and at the end of the Total Cash line, hold no amounts, and needed no parser change. - **Publishing a new run:** move the current `docs/EVAL.md` and `docs/eval-results.json` to `docs/eval-runs/v/` unchanged except for a one-line "Archived" banner, its JSON link label, and relative links the move would break (`eval-runs/vX/…` becomes `../vX/…`). Put the new results JSON in `docs/`, generate EVAL.md by loading it in the view (**Load results JSON** → **Download EVAL.md**), then add the hand-written sections before *Method*: the **Runs** table (one column per run: `max_tokens`, cut-off answers, tokens, figures, grounded, derived, traceable, unsupported), what changed between runs, and *Changes made after the run*. Keep README's Evaluation numbers in step. - **Changing the matcher after a run:** fix only bugs against the method EVAL.md states. Record each fix in EVAL.md's "Changes made after the run" with before and after numbers. Never add a rule just because it raises the score on answers you've already seen. - **Classification** (`classifyText()`): grounded → explicit equation (a wrong one is a math error) → standard derivations (`_candidates()`, each with context keys) → restatements, correct equations and same-line arithmetic on anchored figures → forecast (the 12-month prediction prompt only) or unsupported. When adding a derivation, give it context keys; check the chance-match rate in the report doesn't rise noticeably — it is the matcher's false-positive rate and is published alongside the headline. diff --git a/README.md b/README.md index c28cecc..f0d6a07 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.10  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None +**Version:** v1.16.11  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None --- @@ -261,4 +261,4 @@ See [CHANGELOG.md](CHANGELOG.md) for the full release history. --- -*FinLens v1.16.10 — Built for one person's finances, designed to be useful for anyone's.* +*FinLens v1.16.11 — Built for one person's finances, designed to be useful for anyone's.* diff --git a/index.html b/index.html index ea277d8..a5fd2b6 100644 --- a/index.html +++ b/index.html @@ -1164,7 +1164,7 @@
-
v1.16.10 · FinLens
+
v1.16.11 · FinLens
diff --git a/js/views-ai.js b/js/views-ai.js index c90bb06..4e4ffd3 100644 --- a/js/views-ai.js +++ b/js/views-ai.js @@ -43,8 +43,29 @@ function partialMonthNote(monthKeyStr, allTxs) { return notes.length?` (${notes.join(', ')})`:''; } +// The date the summary's balances are at, when the selected period ends before the last +// transaction (Last year, a custom range ending in August…); null otherwise (v1.16.11). +// Up to v1.16.10 the summary always sent today's balances (currentBalances()) under the +// period's "Period:" line, so on a past range the model read them as that period's. +// When the period ends at or after the last transaction (All time, This month, any range +// reaching today) its end balances are today's, and the summary is exactly as before. +function summaryBalanceEnd() { + const r=State.range; + if (!r.start&&!r.end) return null; + const end=r.end||new Date(); // the end periodEndBalance() uses + const span=dataSpan(State.transactions); + return span&&end{ balances[a.id]=periodEndBalance(a.id); }); + const asOfText=asOf?dayjs(asOf).format('MMM D, YYYY'):''; const txs=filteredTx(); const allMonths=byMonth(State.transactions); const recent3=allMonths.slice(-3); @@ -57,8 +78,8 @@ function buildFinancialSummary() { const expense=sumExpense(txs); const lines=[]; lines.push(`Period: ${describeRange()}${summarySpan(txs)}`); - lines.push(`Accounts: ${Object.values(State.accounts).map(a=>`${a.name} (${fmt(balances[a.id])})`).join(', ')}`); - lines.push(`Total Cash: ${fmt(cash)}, Total Debt: ${fmt(debt)}, Net Worth: ${fmt(cash-debt)}`); + lines.push(`Accounts${asOf?` at the end of the period (${asOfText})`:''}: ${Object.values(State.accounts).map(a=>`${a.name} (${fmt(balances[a.id])})`).join(', ')}`); + lines.push(`Total Cash: ${fmt(cash)}, Total Debt: ${fmt(debt)}, Net Worth: ${fmt(cash-debt)}${asOf?` (all on ${asOfText})`:''}`); lines.push(`Period Income: ${fmt(income)}, Spending: ${fmt(expense)}, Savings Rate: ${pct(income>0?(income-expense)/income:0)}`); lines.push(''); lines.push('Top spending categories:'); cats.forEach(c=>lines.push(` - ${c.category}: ${fmt(c.amount)}`)); @@ -66,7 +87,7 @@ function buildFinancialSummary() { incomeCats.forEach(c=>lines.push(` - ${c.category}: ${fmt(c.amount)}`)); lines.push(''); lines.push('Recent monthly trend:'); recent3.forEach(m=>lines.push(` - ${m.month}${partialMonthNote(m.month, State.transactions)}: income ${fmt(m.income)}, expense ${fmt(m.expense)}, net ${fmt(m.income-m.expense)}`)); - if (State.debts&&State.debts.length){ lines.push(''); lines.push('Debts:'); State.debts.forEach(d=>lines.push(` - ${d.name}: balance ${fmt(debtBalance(d))}, APR ${(d.apr||0).toFixed(2)}%, min pmt ${fmt(d.minPayment||0)}`)); } + if (State.debts&&State.debts.length){ lines.push(''); lines.push(asOf?'Debts (current balances, not at the end of the period):':'Debts:'); State.debts.forEach(d=>lines.push(` - ${d.name}: balance ${fmt(debtBalance(d))}, APR ${(d.apr||0).toFixed(2)}%, min pmt ${fmt(d.minPayment||0)}`)); } if (recurring.length){ lines.push(''); lines.push('Subscriptions:'); recurring.forEach(r=>lines.push(` - ${r.merchant}: ${fmt(r.avg)} ${r.freq}`)); } return lines.join('\n'); } diff --git a/js/views-settings.js b/js/views-settings.js index f7944d3..ed163da 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.10
+
VersionFinLens v1.16.11
`); /* ---- Anthropic API key ---- */