Budgets: Suggest offers changes to budgets that are well off from real spending (#3)

The Suggest sheet said "Nothing to suggest right now." once every main category had a budget.
It now lists budgets $25 and a fifth or more away from the suggested amount as current -> suggested,
then main categories with no budget. Apply all saves them, each row can be edited or removed first,
and the sheet carries the page's Ask AI to tune my budget button.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
minimus7andClaude Opus 5.5 authored and GitHub committed 2026-11-10 21:39:15 -06:00
1 parent cebd597708
commit b7dc3a6f57
3 files changed
+41 -10

No files matched your search

+14 -1
View File
@@ -1,6 +1,6 @@
// Run: node src/lib/budget.test.ts
import assert from "node:assert/strict";
import { budgetChanges, daysBetween, scaleBudget, startPeriod, yearView, merge, month, perDay, roundUp, step, suggest, tone } from "./budget.ts";
import { budgetChanges, retune, wellOff, daysBetween, scaleBudget, startPeriod, yearView, merge, month, perDay, roundUp, step, suggest, tone } from "./budget.ts";
assert.equal(roundUp(0), 0);
assert.equal(roundUp(42.1), 50);
@@ -68,3 +68,16 @@ assert.equal(med([100, 200]), 150);
assert.equal(med([]), 0);
assert.equal(ml(["2026-10", "2026-08", "2026-09"]), "August, September and October");
assert.equal(ml(["2026-10"]), "October");
assert.equal(wellOff(650, 350), true);
assert.equal(wellOff(100, 110), false); // $10 gap
assert.equal(wellOff(1600, 1650), false); // $50 is under a fifth
assert.equal(wellOff(100, 0), false); // nothing spent: leave it
{
const cats = [
{ id: "a", suggested: 350, main: true }, { id: "b", suggested: 300, main: true }, { id: "c", suggested: 100, main: true },
{ id: "d", suggested: 80, main: true }, { id: "e", suggested: 200, main: true }, { id: "f", suggested: 5, main: false },
];
assert.deepEqual(retune(cats, { a: 650, b: 100, c: 105 }).map((c) => c.id), ["a", "b", "e", "d"]);
assert.deepEqual(retune(cats, { a: 350, b: 300, c: 100, d: 80, e: 200 }), []);
}