ownledger 2.1.1 → 2.3.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 +26 -8
- package/CHANGELOG.md +30 -0
- package/README.md +5 -2
- package/dist/cli/statements.js +153 -5
- package/dist/engine/actions.d.ts +37 -0
- package/dist/engine/actions.js +128 -3
- package/dist/modules/cards/terms.d.ts +2 -0
- package/dist/modules/cards/terms.js +7 -0
- package/dist/node/reconcile.d.ts +100 -0
- package/dist/node/reconcile.js +176 -0
- package/dist/node/statement-rows.d.ts +77 -0
- package/dist/node/statement-rows.js +245 -0
- package/dist/node/statements.d.ts +2 -1
- package/dist/worker/api.js +20 -0
- package/dist/worker/mcp.js +39 -7
- package/dist/worker/version.d.ts +1 -1
- package/dist/worker/version.js +1 -1
- package/package.json +1 -1
package/dist/worker/mcp.js
CHANGED
|
@@ -19,14 +19,14 @@ import { yamlText } from "../engine/write.js";
|
|
|
19
19
|
import { dashboardOf } from "./api.js";
|
|
20
20
|
import { cardList } from "../modules/cards/index.js";
|
|
21
21
|
import { cashback, closeOnOrAfter, feeWaiver, lineKind, statements } from "../modules/cards/statements.js";
|
|
22
|
-
import {
|
|
22
|
+
import { STATEMENTS_FILE, termsOf, recordFor, withBankAmounts } from "../modules/cards/terms.js";
|
|
23
23
|
import { bestCard } from "./bestcard.js";
|
|
24
24
|
import { openWalletClient } from "./openwallet.js";
|
|
25
25
|
const out = (v) => ({ content: [{ type: "text", text: typeof v === "string" ? v : JSON.stringify(v) }] });
|
|
26
26
|
const fail = (msg) => ({ content: [{ type: "text", text: msg }], isError: true });
|
|
27
27
|
const INSTRUCTIONS = `ownledger: the owner's personal finance ledger, kept in their private GitHub repo.
|
|
28
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.
|
|
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.
|
|
29
|
+
Writes: the add_/edit_/void_/set_/remove_ tools and batch 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. For more than ~3 transaction writes at once, use batch: one preview, one go, one commit.
|
|
30
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
31
|
Cards: for "which card should I use", call best_card; statements, cashback and fee waivers come from cards and card_statement.`;
|
|
32
32
|
const OPENWALLET_LINE = `
|
|
@@ -92,18 +92,22 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
|
|
|
92
92
|
return fail(`error: ${e.message}`);
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
|
-
const preview = async (build) => {
|
|
95
|
+
const preview = async (build, show = 20) => {
|
|
96
96
|
const s = await snap();
|
|
97
97
|
const p = build(s.files);
|
|
98
98
|
const id = await savePending(env, { baseSha: s.sha, files: p.files, message: p.message, summary: p.summary, created: new Date().toISOString() });
|
|
99
99
|
const shown = [];
|
|
100
|
-
|
|
100
|
+
const all = [...(p.change.addTransactions ?? []), ...(p.change.replaceTransactions ?? [])];
|
|
101
|
+
for (const t of all.slice(0, show))
|
|
101
102
|
shown.push(compactTx(t));
|
|
103
|
+
const b = p;
|
|
102
104
|
return {
|
|
103
105
|
preview_id: id,
|
|
104
106
|
will: p.summary,
|
|
105
107
|
commit_message: p.message,
|
|
106
108
|
...(shown.length ? { transactions: shown } : {}),
|
|
109
|
+
...(all.length > shown.length ? { not_shown: all.length - shown.length } : {}),
|
|
110
|
+
...(b.balanceChange ? { balance_change: b.balanceChange } : {}),
|
|
107
111
|
...(p.warnings.length ? { warnings: p.warnings.map((w) => w.message) } : {}),
|
|
108
112
|
next: "Show this to the owner. Only after their explicit go, call apply with this preview_id.",
|
|
109
113
|
};
|
|
@@ -327,6 +331,36 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
|
|
|
327
331
|
}));
|
|
328
332
|
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)))));
|
|
329
333
|
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)))));
|
|
334
|
+
const batchOp = z.object(txFields).partial().extend({
|
|
335
|
+
op: z.enum(["add", "edit", "void", "statement_amount"]),
|
|
336
|
+
id: z.string().optional().describe("edit / void: the transaction id"),
|
|
337
|
+
amount: z.number().int().optional().describe("add/edit: positive, whole base-currency units; statement_amount: the bank's amount (0 allowed)"),
|
|
338
|
+
statement_date: z.string().optional().describe("statement_amount: the statement's closing date yyyy-mm-dd (with account and amount: the bank's amount, like add_statement_amount)"),
|
|
339
|
+
reason: z.string().trim().max(A.REASON_MAX).optional().describe("optional: this op's own reason, added to the batch's"),
|
|
340
|
+
});
|
|
341
|
+
server.registerTool("batch", {
|
|
342
|
+
description: `PREVIEW many adds, edits and voids as ONE change (writes nothing): one preview, one go, one commit. Use it for more than ~3 writes (e.g. fixes from a statement check). Each op takes the same fields as add_transaction / edit_transaction / void_transaction plus op; op statement_amount (account, statement_date, amount) saves the bank's amount for a card statement like add_statement_amount. Ops run in order; if any op fails, the whole batch is refused and the reply names the op. Max ${A.BATCH_MAX} ops.`,
|
|
343
|
+
inputSchema: z.object({ ops: z.array(batchOp).min(1).max(A.BATCH_MAX), reason }),
|
|
344
|
+
annotations: pv,
|
|
345
|
+
}, wrap(async ({ ops, reason }) => {
|
|
346
|
+
const s = await snap();
|
|
347
|
+
const p = poolOf(s.ledger, dashboardOf(s.files, props.login)?.prefs?.pool, now());
|
|
348
|
+
const list = ops.map((o, i) => {
|
|
349
|
+
if (o.op === "statement_amount") {
|
|
350
|
+
if (!o.account || !o.statement_date || o.amount === undefined)
|
|
351
|
+
throw new A.ActionError(`batch refused: op ${i + 1} (statement_amount) needs account, statement_date and amount`);
|
|
352
|
+
return o;
|
|
353
|
+
}
|
|
354
|
+
if (o.op !== "add" && !o.id)
|
|
355
|
+
throw new A.ActionError(`batch refused: op ${i + 1} (${o.op}) needs an id`);
|
|
356
|
+
if (o.op === "add" && !o.date)
|
|
357
|
+
throw new A.ActionError(`batch refused: op ${i + 1} (add) needs a date`);
|
|
358
|
+
if (o.op === "add" && !o.lines?.length && !o.account && p.on && p.default_account)
|
|
359
|
+
return { ...o, account: p.default_account };
|
|
360
|
+
return o;
|
|
361
|
+
});
|
|
362
|
+
return preview((f) => A.batch(f, list, meta(reason)), A.BATCH_MAX);
|
|
363
|
+
}));
|
|
330
364
|
const accountFields = {
|
|
331
365
|
name: z.string(),
|
|
332
366
|
type: z.string().describe("cash, bank, ewallet, credit_card, bnpl, deposit, savings_goal, gold, fund, stock, etf, crypto, insurance, loan_given, loan_taken, other (or a new one)"),
|
|
@@ -410,9 +444,7 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
|
|
|
410
444
|
const { ledger } = A.loadForAction(f);
|
|
411
445
|
if (!ledger.accounts.some((a) => a.id === account))
|
|
412
446
|
throw new A.ActionError(`no account ${account}`);
|
|
413
|
-
const list =
|
|
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));
|
|
447
|
+
const list = withBankAmounts(ledger, [{ account, statement_date, amount }]);
|
|
416
448
|
return A.plan(f, { putFiles: { [STATEMENTS_FILE]: yamlText(list) } }, `Card statement: ${account} ${statement_date}`);
|
|
417
449
|
})));
|
|
418
450
|
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) => {
|
package/dist/worker/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "2.
|
|
1
|
+
export declare const VERSION = "2.3.0";
|
package/dist/worker/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by scripts/version.mjs
|
|
2
|
-
export const VERSION = "2.
|
|
2
|
+
export const VERSION = "2.3.0";
|
package/package.json
CHANGED