ownledger 2.2.0 → 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 CHANGED
@@ -126,7 +126,9 @@ Propose the fixes to the owner as **one batch** (the connector's `batch` tool: o
126
126
  cover a gap**: find the real rows. If the closing figure isn't found or rows look wrong, add the layout fields to
127
127
  `sources.yaml` (above) rather than working around it. `--save-bank-amounts` saves each month's bank figure in
128
128
  `data/cards/statements.yaml` (preview; `--yes` after the owner's go) so `cards` / `card_statement` show the gap
129
- without the PDFs.
129
+ without the PDFs. When a bank prints its closing figure without a label (reconcile says "no closing figure found"),
130
+ read the figures off the PDFs and save them as `statement_amount` ops in the same `batch` (`account`,
131
+ `statement_date` = the close date, `amount`); reconcile then compares those months too.
130
132
 
131
133
  `npx ownledger statements check <account-id> <YYYY-MM>` shows one statement: ownledger's figures and transactions for
132
134
  the period, the rows read from the PDF, and its text with columns kept.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.3.0 (2026-11-23)
4
+
5
+ - **`batch` saves bank statement amounts too:** op `statement_amount` (`account`, `statement_date`, `amount`; 0
6
+ allowed), the same as `add_statement_amount`, so a whole statement check (the transaction fixes and every month's bank
7
+ figure) is one preview and one commit. For banks whose PDFs print the closing figure without a label.
8
+
3
9
  ## 2.2.0 (2026-11-23)
4
10
 
5
11
  Batch writes, and checking every statement of a card in one run (plan 005). Data format stays 1.
@@ -55,6 +55,14 @@ export type BatchOp = ({
55
55
  op: "void";
56
56
  id: string;
57
57
  reason?: string;
58
+ }
59
+ /** The bank's amount for a card statement (data/cards/statements.yaml), like add_statement_amount. */
60
+ | {
61
+ op: "statement_amount";
62
+ account: string;
63
+ statement_date: string;
64
+ amount: number;
65
+ reason?: string;
58
66
  };
59
67
  export declare const BATCH_MAX = 200;
60
68
  export interface BatchPlanned extends Planned {
@@ -64,6 +72,7 @@ export interface BatchPlanned extends Planned {
64
72
  add: number;
65
73
  edit: number;
66
74
  void: number;
75
+ statement_amount: number;
67
76
  };
68
77
  }
69
78
  /**
@@ -4,6 +4,7 @@ import { flattenCategories } from "./categories.js";
4
4
  import { isDate } from "./dates.js";
5
5
  import { LEDGER_FILE_RE, loadLedger, parseJsonl, PATHS } from "./load.js";
6
6
  import { applyChange, describeChange, yamlText } from "./write.js";
7
+ import { STATEMENTS_FILE, withBankAmounts } from "../modules/cards/terms.js";
7
8
  export class ActionError extends Error {
8
9
  }
9
10
  function newId(prefix = "t_") {
@@ -164,10 +165,21 @@ export function batch(files, ops, meta) {
164
165
  const changed = new Set();
165
166
  const finals = new Map(); // id -> final version
166
167
  const originals = new Map(); // id -> version before the batch (null: added here)
167
- const counts = { add: 0, edit: 0, void: 0 };
168
+ const counts = { add: 0, edit: 0, void: 0, statement_amount: 0 };
169
+ const amounts = [];
168
170
  ops.forEach((o, i) => {
169
171
  const m = meta ? { ...meta, reason: joinReason(meta.reason, o.reason) } : undefined;
170
172
  let b;
173
+ if (o.op === "statement_amount") {
174
+ if (!isDate(o.statement_date) || !Number.isInteger(o.amount))
175
+ throw new ActionError(`batch refused: op ${i + 1} (statement_amount) needs statement_date yyyy-mm-dd and a whole amount`);
176
+ const k = amounts.findIndex((x) => x.account === o.account && x.statement_date === o.statement_date);
177
+ if (k >= 0)
178
+ amounts.splice(k, 1);
179
+ amounts.push({ account: o.account, statement_date: o.statement_date, amount: o.amount });
180
+ counts.statement_amount++;
181
+ return;
182
+ }
171
183
  try {
172
184
  if (o.op === "add") {
173
185
  const { op: _op, reason: _r, ...t } = o;
@@ -195,6 +207,13 @@ export function batch(files, ops, meta) {
195
207
  changed.add(p);
196
208
  cur = { ...cur, ...out };
197
209
  });
210
+ if (amounts.length) {
211
+ const unknown = amounts.find((x) => !loadLedger(cur).ledger.accounts.some((a) => a.id === x.account));
212
+ if (unknown)
213
+ throw new ActionError(`batch refused: statement_amount: no account ${unknown.account}`);
214
+ cur = { ...cur, [STATEMENTS_FILE]: yamlText(withBankAmounts(loadLedger(cur).ledger, amounts)) };
215
+ changed.add(STATEMENTS_FILE);
216
+ }
198
217
  const r = checkFiles(cur);
199
218
  if (!r.ok)
200
219
  throw new ActionError(`batch refused, the result would not pass check:\n${r.errors.slice(0, 10).map((e) => `- ${e.where ? `[${e.where}] ` : ""}${e.message}`).join("\n")}`);
@@ -222,12 +241,12 @@ export function batch(files, ops, meta) {
222
241
  for (const [k, v] of Object.entries(balanceChange))
223
242
  if (v === 0)
224
243
  delete balanceChange[k];
225
- const parts = [counts.add && `${counts.add} add${counts.add > 1 ? "s" : ""}`, counts.edit && `${counts.edit} edit${counts.edit > 1 ? "s" : ""}`, counts.void && `${counts.void} void${counts.void > 1 ? "s" : ""}`].filter(Boolean);
244
+ const parts = [counts.add && `${counts.add} add${counts.add > 1 ? "s" : ""}`, counts.edit && `${counts.edit} edit${counts.edit > 1 ? "s" : ""}`, counts.void && `${counts.void} void${counts.void > 1 ? "s" : ""}`, counts.statement_amount && `${counts.statement_amount} bank amount${counts.statement_amount > 1 ? "s" : ""}`].filter(Boolean);
226
245
  const change = { ...(add.length ? { addTransactions: add } : {}), ...(rep.length ? { replaceTransactions: rep } : {}) };
227
246
  return {
228
247
  change,
229
248
  files: out,
230
- summary: [`batch: ${parts.join(", ")}`, ...describeChange(change)],
249
+ summary: [`batch: ${parts.join(", ")}`, ...describeChange(change), ...amounts.map((x) => `bank amount ${x.account} ${x.statement_date}: ${x.amount}`)],
231
250
  message: withMeta(`Batch: ${parts.join(", ")}`, meta),
232
251
  warnings: r.warnings.filter((w) => !before.has(`${w.file}|${w.where}|${w.message}`)),
233
252
  balanceChange,
@@ -332,18 +332,25 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
332
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)))));
333
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
334
  const batchOp = z.object(txFields).partial().extend({
335
- op: z.enum(["add", "edit", "void"]),
335
+ op: z.enum(["add", "edit", "void", "statement_amount"]),
336
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)"),
337
339
  reason: z.string().trim().max(A.REASON_MAX).optional().describe("optional: this op's own reason, added to the batch's"),
338
340
  });
339
341
  server.registerTool("batch", {
340
- 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. Ops run in order; if any op fails, the whole batch is refused and the reply names the op. Max ${A.BATCH_MAX} ops.`,
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.`,
341
343
  inputSchema: z.object({ ops: z.array(batchOp).min(1).max(A.BATCH_MAX), reason }),
342
344
  annotations: pv,
343
345
  }, wrap(async ({ ops, reason }) => {
344
346
  const s = await snap();
345
347
  const p = poolOf(s.ledger, dashboardOf(s.files, props.login)?.prefs?.pool, now());
346
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
+ }
347
354
  if (o.op !== "add" && !o.id)
348
355
  throw new A.ActionError(`batch refused: op ${i + 1} (${o.op}) needs an id`);
349
356
  if (o.op === "add" && !o.date)
@@ -1 +1 @@
1
- export declare const VERSION = "2.2.0";
1
+ export declare const VERSION = "2.3.0";
@@ -1,2 +1,2 @@
1
1
  // generated by scripts/version.mjs
2
- export const VERSION = "2.2.0";
2
+ export const VERSION = "2.3.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ownledger",
3
- "version": "2.2.0",
3
+ "version": "2.3.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",