ownledger 1.2.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +73 -1
- package/CHANGELOG.md +64 -0
- package/README.md +13 -0
- package/assets/apple-touch-icon.png +0 -0
- package/assets/icon-192.png +0 -0
- package/assets/icon-512.png +0 -0
- package/assets/icon-maskable-512.png +0 -0
- package/assets/index.html +15 -18
- package/assets/manifest.webmanifest +1 -1
- package/assets/static/Account-sw3qGLbB.js +1 -0
- package/assets/static/Accounts-DWyzX3qB.js +1 -0
- package/assets/static/Attention-DxV-4qdY.js +1 -0
- package/assets/static/ByCategory-B4P3ikmE.js +1 -0
- package/assets/static/CardDetail-CayBXBm-.js +1 -0
- package/assets/static/Cards-CVuOP8Bt.js +1 -0
- package/assets/static/Cards-XUBdWxyo.js +1 -0
- package/assets/static/CardsValue-EoW2jG_0.js +1 -0
- package/assets/static/Cashback-BibVYHf_.js +1 -0
- package/assets/static/CategoryIcon-HfjYhH1l.js +1 -0
- package/assets/static/CategoryPicker-BkmvzX2I.js +1 -0
- package/assets/static/ChartWidget-u09-whUU.js +1 -0
- package/assets/static/Combobox-xXeyjGgK.js +1 -0
- package/assets/static/Deposits-CLAda4dj.js +1 -0
- package/assets/static/DrillLink-Bvfam9FA.js +1 -0
- package/assets/static/Field-tKFmKDEF.js +1 -0
- package/assets/static/HomeEditor-4vxj5LMD.js +1 -0
- package/assets/static/Import-DwaaFpRJ.js +2 -0
- package/assets/static/IncomeSpending-RVDSxAK4.js +1 -0
- package/assets/static/KV-DMA1AlP-.js +1 -0
- package/assets/static/Left-C_4gTGSX.js +1 -0
- package/assets/static/Money-PfFNNDOw.js +1 -0
- package/assets/static/NetWorth-BSoseczC.js +1 -0
- package/assets/static/Pace-B8p-9174.js +1 -0
- package/assets/static/Panel-BnfWrw9R.js +1 -0
- package/assets/static/PinDialog-BqAU9Vh4.js +1 -0
- package/assets/static/Plans-2KuQH2_I.js +1 -0
- package/assets/static/Recent-Ccmb34bq.js +1 -0
- package/assets/static/Reports-Dd-dhclr.js +1 -0
- package/assets/static/Settings-BR8WBlen.js +1 -0
- package/assets/static/Transactions-BAuQ-6Eb.js +1 -0
- package/assets/static/TxRow-EKIIMQKa.js +1 -0
- package/assets/static/Unusual-CwFp8aA5.js +1 -0
- package/assets/static/Upcoming-B28roT9r.js +1 -0
- package/assets/static/WhichCard-B3kLc842.js +1 -0
- package/assets/static/arrow-up-D3gxUKLo.js +1 -0
- package/assets/static/bits-Dr2E0ObC.js +1 -0
- package/assets/static/button-rfwMVz0i.js +1 -0
- package/assets/static/cards-Bb5zjzRG.js +1 -0
- package/assets/static/charts-BqP7HKwP.js +65 -0
- package/assets/static/chevron-down-Co1w7ApZ.js +1 -0
- package/assets/static/chevron-right-Dqh3vs9Y.js +1 -0
- package/assets/static/createLucideIcon-flJrJK2p.js +1 -0
- package/assets/static/dialog-BuRqO4sc.js +1 -0
- package/assets/static/dist-B4_eGtNj.js +1 -0
- package/assets/static/dist-B7PR2b0C.js +1 -0
- package/assets/static/dist-BDn7ydjn.js +1 -0
- package/assets/static/dist-Dl-m8cc2.js +1 -0
- package/assets/static/drill-t1zr57xi.js +1 -0
- package/assets/static/es2015-DJh4h8NX.js +41 -0
- package/assets/static/fold-CGWYt9Iu.js +1 -0
- package/assets/static/index-eR1GkdC_.js +14 -0
- package/assets/static/index-iYMxgw-7.css +1 -0
- package/assets/static/queries-DZIMMe4i.js +1 -0
- package/assets/static/react-dom-wK_7mEjs.js +1 -0
- package/assets/static/select-eaSi9K-d.js +1 -0
- package/assets/static/shared-Box7on3B.js +1 -0
- package/assets/static/triangle-exclamation-point-CuL0XSJl.js +1 -0
- package/assets/static/useMutation-_Lw8xXWa.js +1 -0
- package/dist/cli/cards.d.ts +2 -0
- package/dist/cli/cards.js +86 -0
- package/dist/cli/check.js +7 -1
- package/dist/cli/dev.js +22 -2
- package/dist/cli/import.js +12 -2
- package/dist/cli/index.js +6 -0
- package/dist/cli/statements.d.ts +1 -0
- package/dist/cli/statements.js +231 -0
- package/dist/engine/actions.d.ts +5 -0
- package/dist/engine/actions.js +9 -5
- package/dist/engine/attention.d.ts +15 -0
- package/dist/engine/attention.js +63 -0
- package/dist/engine/check.js +8 -1
- package/dist/engine/dashboard.d.ts +72 -0
- package/dist/engine/dashboard.js +180 -0
- package/dist/engine/features.d.ts +20 -0
- package/dist/engine/features.js +37 -0
- package/dist/engine/index.d.ts +5 -0
- package/dist/engine/index.js +5 -0
- package/dist/engine/insights.d.ts +164 -0
- package/dist/engine/insights.js +534 -0
- package/dist/engine/load.js +6 -0
- package/dist/engine/registry.d.ts +2 -0
- package/dist/engine/registry.js +15 -33
- package/dist/engine/reports.d.ts +21 -2
- package/dist/engine/reports.js +51 -3
- package/dist/engine/schedules.d.ts +7 -84
- package/dist/engine/schedules.js +8 -207
- package/dist/engine/types.d.ts +2 -0
- package/dist/engine/write.d.ts +9 -0
- package/dist/engine/write.js +26 -5
- package/dist/import/mapping.js +6 -0
- package/dist/import/run.d.ts +7 -0
- package/dist/import/run.js +28 -1
- package/dist/modules/api.d.ts +22 -0
- package/dist/modules/api.js +16 -0
- package/dist/modules/cards/api.d.ts +3 -0
- package/dist/modules/cards/api.js +105 -0
- package/dist/modules/cards/engine.d.ts +42 -0
- package/dist/modules/cards/engine.js +102 -0
- package/dist/modules/cards/files.d.ts +11 -0
- package/dist/modules/cards/files.js +17 -0
- package/dist/modules/cards/index.d.ts +26 -0
- package/dist/modules/cards/index.js +304 -0
- package/dist/modules/cards/statements.d.ts +128 -0
- package/dist/modules/cards/statements.js +426 -0
- package/dist/modules/cards/terms.d.ts +105 -0
- package/dist/modules/cards/terms.js +194 -0
- package/dist/modules/cards/tracker.d.ts +36 -0
- package/dist/modules/cards/tracker.js +232 -0
- package/dist/modules/cards/types.d.ts +2 -0
- package/dist/modules/cards/types.js +16 -0
- package/dist/modules/deposits/engine.d.ts +14 -0
- package/dist/modules/deposits/engine.js +32 -0
- package/dist/modules/deposits/index.d.ts +2 -0
- package/dist/modules/deposits/index.js +24 -0
- package/dist/modules/deposits/types.d.ts +2 -0
- package/dist/modules/deposits/types.js +15 -0
- package/dist/modules/index.d.ts +5 -0
- package/dist/modules/index.js +10 -0
- package/dist/modules/insurance/index.d.ts +3 -0
- package/dist/modules/insurance/index.js +8 -0
- package/dist/modules/insurance/types.d.ts +2 -0
- package/dist/modules/insurance/types.js +3 -0
- package/dist/modules/investments/index.d.ts +2 -0
- package/dist/modules/investments/index.js +24 -0
- package/dist/modules/investments/types.d.ts +2 -0
- package/dist/modules/investments/types.js +7 -0
- package/dist/modules/loans/engine.d.ts +30 -0
- package/dist/modules/loans/engine.js +77 -0
- package/dist/modules/loans/index.d.ts +2 -0
- package/dist/modules/loans/index.js +27 -0
- package/dist/modules/loans/types.d.ts +2 -0
- package/dist/modules/loans/types.js +5 -0
- package/dist/modules/types.d.ts +39 -0
- package/dist/modules/types.js +1 -0
- package/dist/modules/util.d.ts +8 -0
- package/dist/modules/util.js +8 -0
- package/dist/node/scaffold.js +2 -2
- package/dist/node/statements.d.ts +64 -0
- package/dist/node/statements.js +218 -0
- package/dist/worker/api.d.ts +11 -1
- package/dist/worker/api.js +169 -13
- package/dist/worker/bestcard.d.ts +31 -9
- package/dist/worker/bestcard.js +78 -50
- package/dist/worker/github.d.ts +3 -1
- package/dist/worker/github.js +13 -2
- package/dist/worker/mcp.js +209 -30
- package/dist/worker/store.d.ts +2 -0
- package/dist/worker/store.js +7 -2
- package/dist/worker/tar.d.ts +2 -1
- package/dist/worker/tar.js +4 -1
- package/dist/worker/version.d.ts +1 -1
- package/dist/worker/version.js +1 -1
- package/package.json +28 -4
- package/presets/misa.mapping.yaml +7 -0
- package/assets/app.css +0 -61
- package/assets/app.js +0 -369
package/dist/worker/mcp.js
CHANGED
|
@@ -11,15 +11,26 @@ import { cards, deposits, planStatus, plansDue, today } from "../engine/schedule
|
|
|
11
11
|
import { MainMovedError } from "./github.js";
|
|
12
12
|
import { applyPending, savePending, snapshot, sourceFor } from "./store.js";
|
|
13
13
|
import { VERSION } from "./version.js";
|
|
14
|
+
import { attention } from "../engine/attention.js";
|
|
15
|
+
import { dashboardPath, defaultWidgets, GRID_COLS, poolOf, writeDashboard } from "../engine/dashboard.js";
|
|
16
|
+
import { features } from "../engine/features.js";
|
|
17
|
+
import { series } from "../engine/insights.js";
|
|
18
|
+
import { yamlText } from "../engine/write.js";
|
|
19
|
+
import { dashboardOf } from "./api.js";
|
|
20
|
+
import { cardList } from "../modules/cards/index.js";
|
|
21
|
+
import { cashback, closeOnOrAfter, feeWaiver, lineKind, statements } from "../modules/cards/statements.js";
|
|
22
|
+
import { cardsData, STATEMENTS_FILE, termsOf, recordFor } from "../modules/cards/terms.js";
|
|
14
23
|
import { bestCard } from "./bestcard.js";
|
|
15
24
|
import { openWalletClient } from "./openwallet.js";
|
|
16
25
|
const out = (v) => ({ content: [{ type: "text", text: typeof v === "string" ? v : JSON.stringify(v) }] });
|
|
17
26
|
const fail = (msg) => ({ content: [{ type: "text", text: msg }], isError: true });
|
|
18
27
|
const INSTRUCTIONS = `ownledger: the owner's personal finance ledger, kept in their private GitHub repo.
|
|
19
28
|
Amounts are whole numbers in the base currency (see about). Answers are computed here; never add up raw rows yourself when a tool computes it.
|
|
20
|
-
Writes: the add_/edit_/void_ tools only PREVIEW. Show the owner the preview (what, amounts, accounts), wait for their explicit go, then call apply with the preview_id. Never invent an amount, date, account or category: ask. Call rules once before the first write
|
|
29
|
+
Writes: the add_/edit_/void_/set_/remove_ tools only PREVIEW. Show the owner the preview (what, amounts, accounts), wait for their explicit go, then call apply with the preview_id. Never invent an amount, date, account or category: ask. Call rules once before the first write.
|
|
30
|
+
Dashboard: when the owner asks to "track", "watch" or "put on my dashboard" something, offer a widget (add_widget), using the categories and accounts from rules.
|
|
31
|
+
Cards: for "which card should I use", call best_card; statements, cashback and fee waivers come from cards and card_statement.`;
|
|
21
32
|
const OPENWALLET_LINE = `
|
|
22
|
-
|
|
33
|
+
best_card also asks OpenWallet (an outside card catalog the owner turned on) for cards without the owner's own cashback terms: give it the amount and a merchant or kind. It gets those cards' product names, the purchase and their spend this period. Quote OpenWallet's figures with its date and link (source: openwallet); unknown is not 0. If a card is in not_matched, say so and how to fix it.`;
|
|
23
34
|
function compactTx(t) {
|
|
24
35
|
return {
|
|
25
36
|
id: t.id,
|
|
@@ -48,7 +59,7 @@ const txFields = {
|
|
|
48
59
|
note: z.string().optional(),
|
|
49
60
|
kind: z.enum(["expense", "income", "transfer"]).optional().describe("simple form; or give lines"),
|
|
50
61
|
amount: z.number().int().positive().optional().describe("simple form: positive, whole base-currency units"),
|
|
51
|
-
account: z.string().optional().describe("expense: paid from; income: received into; transfer: from"),
|
|
62
|
+
account: z.string().optional().describe("expense: paid from; income: received into; transfer: from. Omit to use the pool's default account (see rules)"),
|
|
52
63
|
to_account: z.string().optional().describe("transfer: to"),
|
|
53
64
|
category: z.string().optional().describe("category path, e.g. food/eating-out"),
|
|
54
65
|
lines: z.array(lineSchema).optional().describe("full form: balanced lines (sum 0); for splits, assets with qty, etc."),
|
|
@@ -97,6 +108,13 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
|
|
|
97
108
|
next: "Show this to the owner. Only after their explicit go, call apply with this preview_id.",
|
|
98
109
|
};
|
|
99
110
|
};
|
|
111
|
+
/** The signed-in person's "My money" pool: how writes pick an account when none is named. */
|
|
112
|
+
const poolRule = (files, L) => {
|
|
113
|
+
const p = poolOf(L, dashboardOf(files, props.login)?.prefs?.pool, now());
|
|
114
|
+
return p.on
|
|
115
|
+
? { on: true, accounts: p.accounts, default_account: p.default_account, rule: `Everyday money (${p.accounts.join(", ")}) is one pool: when the owner doesn't name a wallet, spending and income go to ${p.default_account} and paying a card is one transfer ${p.default_account} → card. A named wallet ("paid by MoMo") is used as named.` }
|
|
116
|
+
: { on: false, rule: "Ask which account when it isn't named." };
|
|
117
|
+
};
|
|
100
118
|
/* ---------------------------------------------------------------- read */
|
|
101
119
|
server.registerTool("about", { description: "Version, data repo, last commit, base currency, counts, today's date.", annotations: ro }, wrap(async () => {
|
|
102
120
|
const s = await snap();
|
|
@@ -112,6 +130,7 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
|
|
|
112
130
|
accounts: s.ledger.accounts.length,
|
|
113
131
|
transactions: s.ledger.transactions.filter((t) => !t.void).length,
|
|
114
132
|
check: { errors: s.errors, warnings: s.warnings },
|
|
133
|
+
dashboard: `data/dashboards/${props.login.toLowerCase()}.yaml (dashboard / add_widget tools)`,
|
|
115
134
|
};
|
|
116
135
|
}));
|
|
117
136
|
server.registerTool("rules", { description: "What to follow before writing, plus the category list and the accounts (ids). Call once before the first write.", annotations: ro }, wrap(async () => {
|
|
@@ -133,6 +152,7 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
|
|
|
133
152
|
system: Object.entries(SYSTEM_CATEGORIES).map(([k, v]) => `${k}: ${v.en}`),
|
|
134
153
|
},
|
|
135
154
|
accounts: s.ledger.accounts.filter((a) => !a.closed).map((a) => `${a.id}: ${a.name} (${a.type})`),
|
|
155
|
+
pool: poolRule(s.files, s.ledger),
|
|
136
156
|
};
|
|
137
157
|
}));
|
|
138
158
|
server.registerTool("accounts", {
|
|
@@ -229,35 +249,50 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
|
|
|
229
249
|
...(months ? { series: netWorthSeries(s.ledger, addMonths(asOf.slice(0, 7) + "-01", -(months - 1)), asOf).map((x) => ({ date: x.date, net: x.net, assets: x.assets, liabilities: x.liabilities })) } : {}),
|
|
230
250
|
};
|
|
231
251
|
}));
|
|
232
|
-
server.registerTool("cards", {
|
|
233
|
-
|
|
252
|
+
server.registerTool("cards", { description: "Credit cards: owed, limit, last statement (to pay, due, paid or not), cashback this period, this statement period (spent by category, refunds, cashback booked), product name, annual fee waiver, terms still missing.", inputSchema: z.object({ date: z.string().optional(), include_closed: z.boolean().optional() }), annotations: ro }, wrap(async ({ date, include_closed }) => {
|
|
253
|
+
const s = await snap();
|
|
254
|
+
const asOf = date ?? now();
|
|
255
|
+
const per = new Map(cards(s.ledger, asOf).map((x) => [x.account, x]));
|
|
256
|
+
return cardList(s.ledger, asOf, { includeClosed: include_closed }).map((c) => ({
|
|
257
|
+
account: c.account,
|
|
258
|
+
name: c.name,
|
|
259
|
+
owed: c.owed,
|
|
260
|
+
limit: c.limit ?? (c.limitAtLeast ? `at least ${c.limitAtLeast} (most ever owed; limit not set)` : null),
|
|
261
|
+
last_statement: c.last ? { date: c.last.close, amount_due: c.last.amountDue, paid: c.last.paid, to_pay: c.last.toPay, due: c.last.due, status: c.last.status, ...(c.last.bank !== null ? { bank: c.last.bank, diff: c.last.bankDiff } : {}) } : null,
|
|
262
|
+
this_period: c.current ? { from: c.current.from, purchases: c.current.purchases } : null,
|
|
263
|
+
cashback: c.cashback ? { spend: c.cashback.spend, expected: c.cashback.expected, cap_left: c.cashback.capLeft, min_met: c.cashback.minMet, need_for_min: c.cashback.needForMin, ...(c.cashback.incomplete ? { note: "some rates not set" } : {}) } : null,
|
|
264
|
+
...(c.bank ? { bank: c.bank } : {}),
|
|
265
|
+
...(per.get(c.account)?.product ? { product: per.get(c.account).product } : {}),
|
|
266
|
+
...(per.get(c.account) ? { period: (({ from, to, spent, refunds, byCategory, cashback }) => ({ from, to, spent, refunds, by_category: byCategory, cashback_booked: cashback }))(per.get(c.account).period) } : {}),
|
|
267
|
+
fee_waiver: feeWaiver(s.ledger, c.account, asOf),
|
|
268
|
+
...(c.missing.length ? { missing: c.missing } : {}),
|
|
269
|
+
}));
|
|
270
|
+
}));
|
|
271
|
+
server.registerTool("card_statement", { description: "One card statement in detail (default: the last closed one): opening, purchases, refunds, cashback, fees, payments, closing, due, paid, and its transactions.", inputSchema: z.object({ account: z.string(), statement_date: z.string().optional().describe("yyyy-mm-dd") }), annotations: ro }, wrap(async ({ account, statement_date }) => {
|
|
272
|
+
const s = await snap();
|
|
273
|
+
const all = statements(s.ledger, account, now());
|
|
274
|
+
const st = statement_date ? all.find((x) => x.close === statement_date) : [...all].reverse().find((x) => !x.open);
|
|
275
|
+
if (!st)
|
|
276
|
+
throw new A.ActionError(`no statement${statement_date ? ` on ${statement_date}` : ""} for ${account} (statement dates: ${all.slice(-6).map((x) => x.close).join(", ")})`);
|
|
277
|
+
const { map } = flattenCategories(s.ledger.categories);
|
|
278
|
+
const txs = s.ledger.transactions.filter((t) => !t.void && t.date >= st.from && t.date <= st.close && t.lines.some((l) => l.account === account));
|
|
279
|
+
return { statement: st, transactions: txs.map((t) => ({ ...compactTx(t), kind: lineKind(t, account, map)?.kind })), cashback: cashback(s.ledger, account, now()).find((p) => p.close === st.close) ?? null };
|
|
280
|
+
}));
|
|
281
|
+
server.registerTool("best_card", {
|
|
282
|
+
description: "Which card to use for one purchase: open cards ranked by cashback (cap left, minimum spend), then interest-free days, then limit left, each with its source. Cards with the owner's own cashback terms are ranked here; with OpenWallet on, cards without terms are looked up there (needs amount and merchant or kind; sends those cards' product names and banks, the purchase, and their spend and cashback this period).",
|
|
234
283
|
inputSchema: z.object({
|
|
235
|
-
|
|
236
|
-
|
|
284
|
+
category: z.string().optional().describe("the owner's category path, e.g. food/groceries: picks the rate from the owner's terms, adds the budget left"),
|
|
285
|
+
amount: z.number().int().positive().optional().describe("the purchase, whole base-currency units"),
|
|
286
|
+
merchant: z.string().optional().describe("OpenWallet: where, e.g. Shopee, Co.opmart, Grab"),
|
|
287
|
+
kind: z.string().optional().describe("OpenWallet: what kind when no merchant, e.g. groceries, dining, fuel, travel"),
|
|
288
|
+
date: z.string().optional().describe("yyyy-mm-dd, default today"),
|
|
289
|
+
accounts: z.array(z.string()).optional().describe("only these card account ids"),
|
|
237
290
|
}),
|
|
238
|
-
annotations:
|
|
239
|
-
}, wrap(async (
|
|
291
|
+
annotations: { readOnlyHint: true, openWorldHint: Boolean(ow) },
|
|
292
|
+
}, wrap(async (a) => {
|
|
240
293
|
const s = await snap();
|
|
241
|
-
|
|
242
|
-
return all ? list : list.filter((c) => c.owed !== 0 || (c.toPay ?? 0) > 0);
|
|
294
|
+
return bestCard(s.ledger, now(), ow, a);
|
|
243
295
|
}));
|
|
244
|
-
if (ow) {
|
|
245
|
-
server.registerTool("best_card", {
|
|
246
|
-
description: "Which of the owner's credit cards pays the most cashback for one purchase, given what each card already spent and earned this statement period; with available credit, due date and (with category) the budget left. Asks OpenWallet (outside source the owner turned on): sends the cards' product names and banks, the purchase, and each card's spend and cashback this period.",
|
|
247
|
-
inputSchema: z.object({
|
|
248
|
-
amount: z.number().int().positive().describe("the purchase, whole base-currency units"),
|
|
249
|
-
merchant: z.string().optional().describe("where, e.g. Shopee, Co.opmart, Grab"),
|
|
250
|
-
kind: z.string().optional().describe("what kind, when no merchant: OpenWallet spending kind, e.g. groceries, dining, fuel, travel"),
|
|
251
|
-
date: z.string().optional().describe("yyyy-mm-dd, default today"),
|
|
252
|
-
category: z.string().optional().describe("the owner's category path for this purchase (e.g. food/groceries): adds the budget left"),
|
|
253
|
-
accounts: z.array(z.string()).optional().describe("only these card account ids"),
|
|
254
|
-
}),
|
|
255
|
-
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
256
|
-
}, wrap(async (a) => {
|
|
257
|
-
const s = await snap();
|
|
258
|
-
return bestCard(s.ledger, now(), ow, a);
|
|
259
|
-
}));
|
|
260
|
-
}
|
|
261
296
|
server.registerTool("plans_due", { description: "Instalments, loan payments and premiums due in the next N days (and overdue), plus what's left per plan.", inputSchema: z.object({ days: z.number().int().max(366).optional() }), annotations: ro }, wrap(async ({ days }) => {
|
|
262
297
|
const s = await snap();
|
|
263
298
|
const asOf = now();
|
|
@@ -271,7 +306,8 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
|
|
|
271
306
|
const s = await snap();
|
|
272
307
|
const t = today(s.ledger, now());
|
|
273
308
|
const m = report(s.ledger, now().slice(0, 7), { compare: false });
|
|
274
|
-
|
|
309
|
+
const needs = attention(s.ledger, now(), { files: s.files, check: { errors: s.errors, warnings: s.warnings } }).map((a) => ({ severity: a.severity, kind: a.kind, title: a.title, ...(a.amount !== undefined ? { amount: a.amount } : {}), date: a.date }));
|
|
310
|
+
return { ...t, needs_you: needs, this_month: { income: m.income, expense: m.expense } };
|
|
275
311
|
}));
|
|
276
312
|
/* ---------------------------------------------------------------- write (preview) */
|
|
277
313
|
const pv = { readOnlyHint: true, openWorldHint: false }; // previews change nothing
|
|
@@ -279,7 +315,16 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
|
|
|
279
315
|
description: "PREVIEW a new transaction (writes nothing). Simple form: kind + amount + account (+ category or to_account). Full form: lines.",
|
|
280
316
|
inputSchema: z.object({ ...txFields, reason }),
|
|
281
317
|
annotations: pv,
|
|
282
|
-
}, wrap(async ({ reason, ...a }) =>
|
|
318
|
+
}, wrap(async ({ reason, ...a }) => {
|
|
319
|
+
// with the pool on, an unnamed account is the pool's default account
|
|
320
|
+
if (!a.lines?.length && !a.account) {
|
|
321
|
+
const s = await snap();
|
|
322
|
+
const p = poolOf(s.ledger, dashboardOf(s.files, props.login)?.prefs?.pool, now());
|
|
323
|
+
if (p.on && p.default_account)
|
|
324
|
+
a = { ...a, account: p.default_account };
|
|
325
|
+
}
|
|
326
|
+
return preview((f) => A.addTransaction(f, a, meta(reason)));
|
|
327
|
+
}));
|
|
283
328
|
server.registerTool("edit_transaction", { description: "PREVIEW changes to a transaction by id (only the fields given change).", inputSchema: z.object({ id: z.string(), ...txFields, date: z.string().optional(), reason }), annotations: pv }, wrap(async ({ id, reason, ...patch }) => preview((f) => A.editTransaction(f, id, patch, meta(reason)))));
|
|
284
329
|
server.registerTool("void_transaction", { description: "PREVIEW voiding a transaction (kept in history, excluded everywhere).", inputSchema: z.object({ id: z.string(), reason }), annotations: pv }, wrap(async ({ id, reason }) => preview((f) => A.voidTransaction(f, id, reason, meta(reason)))));
|
|
285
330
|
const accountFields = {
|
|
@@ -318,6 +363,140 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
|
|
|
318
363
|
server.registerTool("add_price", { description: "PREVIEW a price for an asset (base currency per unit) on a date.", inputSchema: z.object({ date: z.string(), asset: z.string(), price: z.number() }), annotations: pv }, wrap(async (p) => preview((f) => A.addPrice(f, p))));
|
|
319
364
|
server.registerTool("add_category", { description: "PREVIEW a new category.", inputSchema: z.object({ kind: z.enum(["income", "expense"]), parent: z.string().optional(), id: z.string(), name: z.string() }), annotations: pv }, wrap(async (c) => preview((f) => A.addCategory(f, c))));
|
|
320
365
|
server.registerTool("edit_category", { description: "PREVIEW renaming a category, or moving it to a new path (every line using it is remapped).", inputSchema: z.object({ path: z.string(), name: z.string().optional(), new_path: z.string().optional() }), annotations: pv }, wrap(async ({ path, ...set }) => preview((f) => A.editCategory(f, path, set))));
|
|
366
|
+
/* ---------------------------------------------------------------- cards (preview) */
|
|
367
|
+
server.registerTool("set_card_details", {
|
|
368
|
+
description: "PREVIEW card terms on a credit card account: statement and due days, limit, annual fee and its month, fee waiver target, cashback rules. Only the fields given change; they're kept over codes read from wallet names.",
|
|
369
|
+
inputSchema: z.object({
|
|
370
|
+
account: z.string(),
|
|
371
|
+
statement_day: z.number().int().min(1).max(31).optional(),
|
|
372
|
+
due_day: z.number().int().min(1).max(31).optional(),
|
|
373
|
+
limit: z.number().int().positive().optional(),
|
|
374
|
+
annual_fee: z.number().int().min(0).optional(),
|
|
375
|
+
fee_month: z.number().int().min(1).max(12).optional(),
|
|
376
|
+
fee_waiver_spend: z.number().int().positive().optional().describe("spend per card year that waives the annual fee"),
|
|
377
|
+
free_days_max: z.number().int().optional(),
|
|
378
|
+
cashback: z.object({
|
|
379
|
+
base: z.number().min(0).max(100).optional(),
|
|
380
|
+
rules: z.array(z.object({ categories: z.array(z.string()), rate: z.number().min(0).max(100) })).optional(),
|
|
381
|
+
cap: z.object({ amount: z.number().int().positive(), per: z.enum(["statement", "month"]) }).optional(),
|
|
382
|
+
min_spend: z.object({ amount: z.number().int().positive(), per: z.enum(["statement", "month"]) }).optional(),
|
|
383
|
+
spend_max: z.object({ amount: z.number().int().positive(), per: z.enum(["statement", "month"]) }).optional(),
|
|
384
|
+
paid_on: z.string().optional().describe("next_statement or days_after:<n>"),
|
|
385
|
+
}).optional().describe("merged into the card's cashback terms"),
|
|
386
|
+
}),
|
|
387
|
+
annotations: pv,
|
|
388
|
+
}, wrap(async ({ account, fee_waiver_spend, cashback: cb, ...rest }) => preview((f) => {
|
|
389
|
+
const { ledger } = A.loadForAction(f);
|
|
390
|
+
const a = ledger.accounts.find((x) => x.id === account);
|
|
391
|
+
if (!a)
|
|
392
|
+
throw new A.ActionError(`no account ${account}`);
|
|
393
|
+
const details = { ...(a.details ?? {}) };
|
|
394
|
+
const set = Object.fromEntries(Object.entries(rest).filter(([, v]) => v !== undefined));
|
|
395
|
+
if (fee_waiver_spend !== undefined)
|
|
396
|
+
set.fee_waiver = { spend: fee_waiver_spend, within: "year" };
|
|
397
|
+
if (cb)
|
|
398
|
+
set.cashback = { ...(details.cashback ?? {}), ...Object.fromEntries(Object.entries(cb).filter(([, v]) => v !== undefined)) };
|
|
399
|
+
if (!Object.keys(set).length)
|
|
400
|
+
throw new A.ActionError("nothing to change");
|
|
401
|
+
Object.assign(details, set);
|
|
402
|
+
const fromName = Array.isArray(details.from_name) ? details.from_name.filter((k) => !(k in set)) : undefined;
|
|
403
|
+
if (fromName)
|
|
404
|
+
details.from_name = fromName.length ? fromName : undefined;
|
|
405
|
+
if (details.from_name === undefined)
|
|
406
|
+
delete details.from_name;
|
|
407
|
+
return A.editAccount(f, account, { details });
|
|
408
|
+
})));
|
|
409
|
+
server.registerTool("add_statement_amount", { description: "PREVIEW the bank's amount for a card statement (from the bank's statement), to compare with the computed one.", inputSchema: z.object({ account: z.string(), statement_date: z.string().describe("yyyy-mm-dd, the statement's closing date"), amount: z.number().int() }), annotations: pv }, wrap(async ({ account, statement_date, amount }) => preview((f) => {
|
|
410
|
+
const { ledger } = A.loadForAction(f);
|
|
411
|
+
if (!ledger.accounts.some((a) => a.id === account))
|
|
412
|
+
throw new A.ActionError(`no account ${account}`);
|
|
413
|
+
const list = cardsData(ledger).statements.filter((x) => !(x.account === account && x.statement_date === statement_date));
|
|
414
|
+
list.push({ account, statement_date, amount });
|
|
415
|
+
list.sort((x, y) => (x.statement_date < y.statement_date ? -1 : x.statement_date > y.statement_date ? 1 : x.account < y.account ? -1 : 1));
|
|
416
|
+
return A.plan(f, { putFiles: { [STATEMENTS_FILE]: yamlText(list) } }, `Card statement: ${account} ${statement_date}`);
|
|
417
|
+
})));
|
|
418
|
+
server.registerTool("add_instalment", { description: "PREVIEW turning a card purchase into a 0% instalment plan (trả góp 0%): each statement then counts only the monthly amount.", inputSchema: z.object({ transaction: z.string().describe("id of the purchase on the card"), count: z.number().int().min(2).max(60), fee: z.number().int().min(0).optional().describe("conversion fee per month, if any"), id: z.string().optional(), name: z.string().optional(), first_statement: z.string().optional().describe("yyyy-mm-dd; default the first statement after the purchase") }), annotations: pv }, wrap(async ({ transaction, count, fee, id, name, first_statement }) => preview((f) => {
|
|
419
|
+
const { ledger } = A.loadForAction(f);
|
|
420
|
+
const t = ledger.transactions.find((x) => x.id === transaction);
|
|
421
|
+
if (!t)
|
|
422
|
+
throw new A.ActionError(`no transaction ${transaction}`);
|
|
423
|
+
const line = t.lines.find((l) => l.account && ledger.accounts.find((a) => a.id === l.account)?.type === "credit_card" && l.amount < 0);
|
|
424
|
+
if (!line)
|
|
425
|
+
throw new A.ActionError("that transaction isn't a purchase on a credit card");
|
|
426
|
+
const acc = ledger.accounts.find((a) => a.id === line.account);
|
|
427
|
+
const sd = termsOf(acc, recordFor(ledger, acc.id)).statementDay;
|
|
428
|
+
if (!sd && !first_statement)
|
|
429
|
+
throw new A.ActionError(`${acc.id} has no statement_day: give first_statement`);
|
|
430
|
+
const start = first_statement ?? closeOnOrAfter(t.date, sd);
|
|
431
|
+
const principal = -line.amount;
|
|
432
|
+
return A.addPlan(f, { id: id ?? `${acc.id}-${t.date.replace(/-/g, "")}-0pct`, kind: "instalment", account: acc.id, name: name ?? (t.note || `Trả góp ${acc.name}`), principal, count, every: "month", start, ...(fee ? { fee } : {}), rate: 0, source: t.id });
|
|
433
|
+
})));
|
|
434
|
+
/* ---------------------------------------------------------------- dashboard (preview) */
|
|
435
|
+
const queryShape = z.object({
|
|
436
|
+
metric: z.enum(["spending", "income", "net", "balance", "count"]),
|
|
437
|
+
category: z.string().optional(),
|
|
438
|
+
account: z.string().optional(),
|
|
439
|
+
who: z.string().optional(),
|
|
440
|
+
event: z.string().optional(),
|
|
441
|
+
tag: z.string().optional(),
|
|
442
|
+
text: z.string().optional(),
|
|
443
|
+
period: z.string().optional().describe("this-month, last-month, last-3-months, last-6-months, this-year, last-year, last-12-months, all, yyyy-mm or yyyy"),
|
|
444
|
+
by: z.enum(["day", "week", "month", "category", "top", "account", "who", "event", "tag"]).optional(),
|
|
445
|
+
compare: z.enum(["previous", "usual"]).optional(),
|
|
446
|
+
});
|
|
447
|
+
const myDashboard = async () => {
|
|
448
|
+
const s = await snap();
|
|
449
|
+
const d = dashboardOf(s.files, props.login);
|
|
450
|
+
const widgets = d?.widgets ?? defaultWidgets(features(s.ledger, now(), s.files));
|
|
451
|
+
return { s, d: { version: 1, ...(d ?? {}), widgets } };
|
|
452
|
+
};
|
|
453
|
+
const saveLayout = (d, message) => (f) => A.plan(f, { putFiles: { [dashboardPath(props.login)]: writeDashboard(d) } }, message);
|
|
454
|
+
const firstNumbers = async (q) => {
|
|
455
|
+
const s = await snap();
|
|
456
|
+
const pool = poolOf(s.ledger, dashboardOf(s.files, props.login)?.prefs?.pool, now());
|
|
457
|
+
const r = series(s.ledger, q.account === "pool" ? { ...q, account: pool.accounts } : q, now());
|
|
458
|
+
return { period: r.period, total: r.total, ...(r.compareTotal !== undefined ? { compare: r.compareTotal } : {}), first: r.points.slice(0, 8).map((p) => [p.name, p.value]) };
|
|
459
|
+
};
|
|
460
|
+
server.registerTool("dashboard", { description: "The signed-in owner's dashboard layout: widgets with ids, types, titles, queries and positions (12-column grid), from data/dashboards/<login>.yaml (defaults when there is no file yet).", annotations: ro }, wrap(async () => {
|
|
461
|
+
const { s, d } = await myDashboard();
|
|
462
|
+
return { file: dashboardPath(props.login), saved: Boolean(dashboardOf(s.files, props.login)), grid_columns: GRID_COLS, widgets: d.widgets };
|
|
463
|
+
}));
|
|
464
|
+
server.registerTool("add_widget", {
|
|
465
|
+
description: "PREVIEW adding a widget to the owner's dashboard: a chart from a query (type chart), or a built-in widget by type (pace, left, attention, unusual, net_worth, by_category, income_spending, recent, account, upcoming, cards, cashback, which_card, cards_value, deposits). Shows the first numbers so the owner can see it's right.",
|
|
466
|
+
inputSchema: z.object({ type: z.string().default("chart"), title: z.string().max(80).optional(), query: queryShape.optional(), chart: z.enum(["stat", "line", "bar", "hbar", "table"]).optional(), account: z.string().optional(), period: z.string().optional(), w: z.number().int().min(1).max(12).optional(), h: z.number().int().min(1).max(24).optional(), id: z.string().optional() }),
|
|
467
|
+
annotations: pv,
|
|
468
|
+
}, wrap(async ({ type, title, query, chart, account, period, w, h, id }) => {
|
|
469
|
+
const { d } = await myDashboard();
|
|
470
|
+
if (type === "chart" && !query)
|
|
471
|
+
throw new A.ActionError("a chart widget needs a query");
|
|
472
|
+
const y = d.widgets.reduce((m, x) => Math.max(m, x.y + x.h), 0);
|
|
473
|
+
const base = (id ?? title ?? type).normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/đ/gi, "d").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "widget";
|
|
474
|
+
let wid = base;
|
|
475
|
+
for (let i = 2; d.widgets.some((x) => x.id === wid); i++)
|
|
476
|
+
wid = `${base}-${i}`;
|
|
477
|
+
const widget = { id: wid, type, x: 0, y, w: w ?? 6, h: h ?? 3, ...(title ? { title } : {}), ...(query ? { query: query, chart: chart ?? "bar" } : {}), ...(account ? { account } : {}), ...(period ? { period } : {}), by_ai: true };
|
|
478
|
+
const next = { ...d, widgets: [...d.widgets, widget] };
|
|
479
|
+
const shows = query ? await firstNumbers(query) : undefined;
|
|
480
|
+
return { ...(await preview(saveLayout(next, `Dashboard: add widget ${title ?? type} (${props.login})`))), widget, ...(shows ? { shows } : {}) };
|
|
481
|
+
}));
|
|
482
|
+
server.registerTool("edit_widget", { description: "PREVIEW changing a dashboard widget by id (title, query, chart kind, size, options).", inputSchema: z.object({ id: z.string(), title: z.string().max(80).optional(), query: queryShape.optional(), chart: z.enum(["stat", "line", "bar", "hbar", "table"]).optional(), account: z.string().optional(), period: z.string().optional(), w: z.number().int().min(1).max(12).optional(), h: z.number().int().min(1).max(24).optional() }), annotations: pv }, wrap(async ({ id, ...set }) => {
|
|
483
|
+
const { d } = await myDashboard();
|
|
484
|
+
const w = d.widgets.find((x) => x.id === id);
|
|
485
|
+
if (!w)
|
|
486
|
+
throw new A.ActionError(`no widget ${id} (ids: ${d.widgets.map((x) => x.id).join(", ")})`);
|
|
487
|
+
const changed = { ...w, ...Object.fromEntries(Object.entries(set).filter(([, v]) => v !== undefined)) };
|
|
488
|
+
if (changed.x + changed.w > GRID_COLS)
|
|
489
|
+
changed.x = GRID_COLS - changed.w;
|
|
490
|
+
const next = { ...d, widgets: d.widgets.map((x) => (x.id === id ? changed : x)) };
|
|
491
|
+
const shows = changed.query ? await firstNumbers(changed.query) : undefined;
|
|
492
|
+
return { ...(await preview(saveLayout(next, `Dashboard: edit widget ${id} (${props.login})`))), widget: changed, ...(shows ? { shows } : {}) };
|
|
493
|
+
}));
|
|
494
|
+
server.registerTool("remove_widget", { description: "PREVIEW removing a dashboard widget by id.", inputSchema: z.object({ id: z.string() }), annotations: pv }, wrap(async ({ id }) => {
|
|
495
|
+
const { d } = await myDashboard();
|
|
496
|
+
if (!d.widgets.some((x) => x.id === id))
|
|
497
|
+
throw new A.ActionError(`no widget ${id} (ids: ${d.widgets.map((x) => x.id).join(", ")})`);
|
|
498
|
+
return preview(saveLayout({ ...d, widgets: d.widgets.filter((x) => x.id !== id) }, `Dashboard: remove widget ${id} (${props.login})`));
|
|
499
|
+
}));
|
|
321
500
|
/* ---------------------------------------------------------------- apply */
|
|
322
501
|
server.registerTool("apply", {
|
|
323
502
|
description: "Commit a preview, ONLY after the owner explicitly said go. Refused if the data changed since the preview.",
|
package/dist/worker/store.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ import type { Env } from "./env.js";
|
|
|
6
6
|
export interface DataSource {
|
|
7
7
|
head(): Promise<string>;
|
|
8
8
|
files(sha: string): Promise<FileMap>;
|
|
9
|
+
/** One file's bytes at a commit (statement PDFs), streamed; null if missing. */
|
|
10
|
+
blob(sha: string, path: string): Promise<Response | null>;
|
|
9
11
|
commit(baseSha: string, files: CommitFile[], message: string): Promise<string>;
|
|
10
12
|
label: string;
|
|
11
13
|
}
|
package/dist/worker/store.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { checkFiles } from "../engine/check.js";
|
|
2
|
-
import { commit, filesAt, headSha } from "./github.js";
|
|
2
|
+
import { blobAt, commit, filesAt, headSha } from "./github.js";
|
|
3
3
|
export function githubSource(env) {
|
|
4
4
|
const c = { appId: env.GITHUB_APP_ID, privateKey: env.GITHUB_APP_PRIVATE_KEY, repo: env.DATA_REPO, branch: env.DATA_BRANCH || "main" };
|
|
5
5
|
return {
|
|
6
6
|
label: `github.com/${c.repo}@${c.branch}`,
|
|
7
7
|
head: () => headSha(c),
|
|
8
8
|
files: (sha) => filesAt(c, sha),
|
|
9
|
+
blob: (sha, path) => blobAt(c, sha, path),
|
|
9
10
|
commit: (base, files, message) => commit(c, base, files, message),
|
|
10
11
|
};
|
|
11
12
|
}
|
|
@@ -16,6 +17,10 @@ export function devSource(env) {
|
|
|
16
17
|
label: `local ${base}`,
|
|
17
18
|
head: async () => (await (await fetch(`${base}/head`)).text()).trim(),
|
|
18
19
|
files: async () => (await (await fetch(`${base}/files`)).json()),
|
|
20
|
+
blob: async (_sha, path) => {
|
|
21
|
+
const r = await fetch(`${base}/blob?path=${encodeURIComponent(path)}`);
|
|
22
|
+
return r.status === 404 ? null : r.ok ? r : Promise.reject(new Error(`dev blob: ${r.status}`));
|
|
23
|
+
},
|
|
19
24
|
commit: async (baseSha, files, message) => {
|
|
20
25
|
const r = await fetch(`${base}/commit`, { method: "POST", body: JSON.stringify({ baseSha, files, message }) });
|
|
21
26
|
if (r.status === 409) {
|
|
@@ -34,7 +39,7 @@ export function sourceFor(env) {
|
|
|
34
39
|
// Parsed ledgers live in the isolate's memory (keyed by commit); raw files also in KV, so a cold isolate
|
|
35
40
|
// needs no GitHub tarball for a commit it has seen. Both are safe to drop: GitHub is the only store.
|
|
36
41
|
const memory = new Map();
|
|
37
|
-
const KV_PREFIX = "ownledger:
|
|
42
|
+
const KV_PREFIX = "ownledger:files2:"; // 2: with statement PDF paths (plan 004)
|
|
38
43
|
export async function snapshot(env, src, sha) {
|
|
39
44
|
const head = sha ?? (await src.head());
|
|
40
45
|
const hit = memory.get(head);
|
package/dist/worker/tar.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
/** Minimal streaming tar reader (ustar + pax path headers), enough for GitHub's tarballs. */
|
|
2
|
-
|
|
2
|
+
/** `keep`: files whose text is returned. `pathOnly`: files returned with "" (their bytes are skipped, never decoded). */
|
|
3
|
+
export declare function untar(stream: ReadableStream<Uint8Array>, keep: (path: string) => boolean, pathOnly?: (path: string) => boolean): Promise<Record<string, string>>;
|
package/dist/worker/tar.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Minimal streaming tar reader (ustar + pax path headers), enough for GitHub's tarballs. */
|
|
2
|
-
|
|
2
|
+
/** `keep`: files whose text is returned. `pathOnly`: files returned with "" (their bytes are skipped, never decoded). */
|
|
3
|
+
export async function untar(stream, keep, pathOnly) {
|
|
3
4
|
const out = {};
|
|
4
5
|
const reader = stream.getReader();
|
|
5
6
|
let buf = new Uint8Array(0);
|
|
@@ -56,6 +57,8 @@ export async function untar(stream, keep) {
|
|
|
56
57
|
const rel = full.slice(full.indexOf("/") + 1); // strip "<repo>-<sha>/"
|
|
57
58
|
if (keep(rel))
|
|
58
59
|
out[rel] = dec.decode(body);
|
|
60
|
+
else if (pathOnly?.(rel))
|
|
61
|
+
out[rel] = "";
|
|
59
62
|
}
|
|
60
63
|
reader.cancel().catch(() => undefined);
|
|
61
64
|
return out;
|
package/dist/worker/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "
|
|
1
|
+
export declare const VERSION = "2.1.0";
|
package/dist/worker/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by scripts/version.mjs
|
|
2
|
-
export const VERSION = "
|
|
2
|
+
export const VERSION = "2.1.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ownledger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Personal finance ledger used through AI chat (MCP). Your data in your own private GitHub repo, served by your own Cloudflare Worker.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "phucbm",
|
|
@@ -43,25 +43,49 @@
|
|
|
43
43
|
"CHANGELOG.md"
|
|
44
44
|
],
|
|
45
45
|
"scripts": {
|
|
46
|
-
"build": "node scripts/version.mjs && rm -rf dist && tsc -p tsconfig.build.json && chmod +x dist/cli/index.js",
|
|
47
|
-
"typecheck": "node scripts/version.mjs && tsc --noEmit",
|
|
46
|
+
"build": "node scripts/version.mjs && rm -rf dist && tsc -p tsconfig.build.json && chmod +x dist/cli/index.js && pnpm build:web",
|
|
47
|
+
"typecheck": "node scripts/version.mjs && tsc --noEmit && tsc --noEmit -p web/tsconfig.json",
|
|
48
48
|
"test": "vitest run",
|
|
49
49
|
"fixtures": "tsx scripts/make-fixtures.ts && tsx scripts/make-misa-fixture.ts",
|
|
50
|
-
"prepublishOnly": "pnpm typecheck && pnpm test && pnpm build"
|
|
50
|
+
"prepublishOnly": "pnpm typecheck && pnpm test && pnpm build",
|
|
51
|
+
"build:web": "vite build --config web/vite.config.ts && node scripts/web-size.mjs",
|
|
52
|
+
"dev:web": "vite --config web/vite.config.ts"
|
|
51
53
|
},
|
|
52
54
|
"dependencies": {
|
|
53
55
|
"@cloudflare/workers-oauth-provider": "1.2.4",
|
|
54
56
|
"@modelcontextprotocol/server": "2.4.0",
|
|
57
|
+
"@neslinesli93/qpdf-wasm": "0.3.1",
|
|
55
58
|
"fflate": "0.8.3",
|
|
59
|
+
"unpdf": "2.2.1",
|
|
56
60
|
"yaml": "2.9.1",
|
|
57
61
|
"zod": "4.6.7"
|
|
58
62
|
},
|
|
59
63
|
"devDependencies": {
|
|
60
64
|
"@cloudflare/workers-types": "5.20261121.1",
|
|
65
|
+
"@tailwindcss/vite": "4.3.5",
|
|
66
|
+
"@tanstack/react-query": "5.108.2",
|
|
61
67
|
"@types/node": "26.6.6",
|
|
68
|
+
"@types/react": "19.3.0",
|
|
69
|
+
"@types/react-dom": "19.3.0",
|
|
70
|
+
"@vitejs/plugin-react": "6.3.0",
|
|
71
|
+
"class-variance-authority": "0.7.1",
|
|
72
|
+
"clsx": "2.1.1",
|
|
73
|
+
"cmdk": "1.1.1",
|
|
74
|
+
"lucide-react": "1.77.0",
|
|
75
|
+
"radix-ui": "1.8.1",
|
|
76
|
+
"react": "19.3.1",
|
|
77
|
+
"react-dom": "19.3.1",
|
|
78
|
+
"react-grid-layout": "2.3.0",
|
|
79
|
+
"recharts": "3.11.0",
|
|
80
|
+
"shadcn": "4.23.0",
|
|
81
|
+
"tailwind-merge": "3.7.1",
|
|
82
|
+
"tailwindcss": "4.3.5",
|
|
62
83
|
"tsx": "4.23.15",
|
|
84
|
+
"tw-animate-css": "1.4.0",
|
|
63
85
|
"typescript": "7.0.2",
|
|
86
|
+
"vite": "8.3.8",
|
|
64
87
|
"vitest": "5.1.1",
|
|
88
|
+
"wouter": "3.13.0",
|
|
65
89
|
"wrangler": "4.166.0"
|
|
66
90
|
},
|
|
67
91
|
"bin": {
|
|
@@ -32,11 +32,18 @@ transfers:
|
|
|
32
32
|
# Sheet name (as in the file) → account. Sheet names are cut to 31 characters and repeated names get
|
|
33
33
|
# a _NN suffix; put the full wallet name(s) from the transfer notes in `names`.
|
|
34
34
|
# Lift facts users write into wallet names (card statement/due day, deposit term and start) into details.
|
|
35
|
+
# Credit card codes are also read on every import: 🗓️7 statement day, 💸3 due day, *1234 last 4, 🎉02/25 card
|
|
36
|
+
# anniversary (fee month), 1-5tr cashback spend band, category emoji before the first "•" (cashback categories).
|
|
37
|
+
# Quote any name with a comma: name: "Đầu tư khác (chứng khoán, CCQ)".
|
|
35
38
|
accounts: {}
|
|
36
39
|
# "cash": { id: cash, name: Tiền mặt, type: cash }
|
|
37
40
|
# "vcb _1234 🗓️20💸5": { id: card-vcb, name: VCB Visa, type: credit_card, names: ["vcb _1234 🗓️20💸5"], details: { statement_day: 20, due_day: 5 } }
|
|
38
41
|
# "gửi 6 tháng từ 01_07_2025": { id: dep-20250701, name: Gửi 6 tháng từ 01/07/2025, type: deposit, names: ["gửi 6 tháng từ 01/07/2025"], details: { term_months: 6, start: 2025-07-01 } }
|
|
39
42
|
|
|
43
|
+
# Category emoji in card names → category path (defaults: 🛒 shopping, 🏋️ health/sport, 🍿 fun/entertainment,
|
|
44
|
+
# 📞 subscriptions, 🍜 food/eating-out, ☕ food/cafe, ⛽ transport/fuel, ✈️ fun/trips). Add or change your own here.
|
|
45
|
+
card_emoji: {}
|
|
46
|
+
|
|
40
47
|
# "Hạng mục cha/Hạng mục con" (or just the parent) → ownledger category path.
|
|
41
48
|
categories: {}
|
|
42
49
|
# "Chi tiêu hàng ngày/Ăn uống": food/eating-out
|
package/assets/app.css
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
:root {
|
|
2
|
-
color-scheme: light;
|
|
3
|
-
--surface-0: #f4f4f2;
|
|
4
|
-
--surface-1: #fcfcfb;
|
|
5
|
-
--border: #e3e2de;
|
|
6
|
-
--grid: #ecebe7;
|
|
7
|
-
--text-primary: #0b0b0b;
|
|
8
|
-
--text-secondary: #52514e;
|
|
9
|
-
--text-muted: #7c7b76;
|
|
10
|
-
--series-1: #2a78d6; /* income, net worth, magnitude */
|
|
11
|
-
--series-2: #eb6834; /* spending */
|
|
12
|
-
--good: #1f7a1f;
|
|
13
|
-
--critical: #c0392b;
|
|
14
|
-
--radius: 12px;
|
|
15
|
-
}
|
|
16
|
-
* { box-sizing: border-box; }
|
|
17
|
-
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text-primary); background: var(--surface-0); }
|
|
18
|
-
a { color: var(--series-1); text-decoration: none; }
|
|
19
|
-
a:hover { text-decoration: underline; }
|
|
20
|
-
.top { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; padding: .75rem 1.25rem; background: var(--surface-1); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
|
|
21
|
-
.brand { font-weight: 700; color: var(--text-primary); }
|
|
22
|
-
nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
|
|
23
|
-
nav a { color: var(--text-secondary); padding: .3rem .6rem; border-radius: 8px; }
|
|
24
|
-
nav a.on { background: var(--surface-0); color: var(--text-primary); }
|
|
25
|
-
main { max-width: 1120px; margin: 0 auto; padding: 1.25rem; }
|
|
26
|
-
h1 { font-size: 1.35rem; margin: .25rem 0 1rem; }
|
|
27
|
-
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
|
|
28
|
-
.muted { color: var(--text-muted); }
|
|
29
|
-
.small { font-size: .85rem; }
|
|
30
|
-
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
|
|
31
|
-
.grid.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
|
|
32
|
-
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; min-width: 0; }
|
|
33
|
-
.stat .label { color: var(--text-secondary); font-size: .85rem; }
|
|
34
|
-
.stat .value { font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; }
|
|
35
|
-
.stat .delta { font-size: .85rem; color: var(--text-secondary); }
|
|
36
|
-
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
|
|
37
|
-
.neg { color: var(--critical); }
|
|
38
|
-
.pos { color: var(--good); }
|
|
39
|
-
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
|
|
40
|
-
th, td { padding: .45rem .5rem; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: top; }
|
|
41
|
-
th { color: var(--text-secondary); font-weight: 600; font-size: .82rem; }
|
|
42
|
-
tr.void td { color: var(--text-muted); text-decoration: line-through; }
|
|
43
|
-
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
|
|
44
|
-
input, select, button { font: inherit; padding: .4rem .6rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-1); color: var(--text-primary); }
|
|
45
|
-
button { cursor: pointer; }
|
|
46
|
-
button.primary { background: var(--text-primary); color: var(--surface-1); border-color: var(--text-primary); }
|
|
47
|
-
button:disabled { opacity: .5; cursor: default; }
|
|
48
|
-
.pill { display: inline-block; padding: 0 .45rem; border-radius: 999px; background: var(--surface-0); color: var(--text-secondary); font-size: .78rem; margin-right: .25rem; }
|
|
49
|
-
.status { display: inline-flex; gap: .3rem; align-items: center; font-weight: 600; }
|
|
50
|
-
.status.bad { color: var(--critical); }
|
|
51
|
-
.status.ok { color: var(--good); }
|
|
52
|
-
.legend { display: flex; gap: 1rem; font-size: .85rem; color: var(--text-secondary); margin-bottom: .4rem; }
|
|
53
|
-
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }
|
|
54
|
-
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
|
|
55
|
-
svg.chart text { fill: var(--text-muted); font-size: 11px; font-family: inherit; }
|
|
56
|
-
svg.chart .grid line { stroke: var(--grid); }
|
|
57
|
-
.tip { position: fixed; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: .4rem .6rem; font-size: .85rem; box-shadow: 0 4px 16px rgba(0,0,0,.08); z-index: 10; }
|
|
58
|
-
details.table summary { cursor: pointer; color: var(--text-secondary); font-size: .85rem; margin-top: .5rem; }
|
|
59
|
-
.empty { padding: 2rem; text-align: center; color: var(--text-muted); }
|
|
60
|
-
pre { white-space: pre-wrap; font-size: .82rem; background: var(--surface-0); padding: .6rem; border-radius: 8px; }
|
|
61
|
-
@media (max-width: 640px) { .grid.two { grid-template-columns: 1fr; } .stat .value { font-size: 1.3rem; } main { padding: .75rem; } }
|