bkper 4.16.3 → 4.16.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/agent/system-prompt.ts"],"names":[],"mappings":"AAiGA,wBAAgB,yBAAyB,IAAI,MAAM,CAgDlD;AAED,eAAO,MAAM,yBAAyB,QAqBrC,CAAC"}
1
+ {"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/agent/system-prompt.ts"],"names":[],"mappings":"AAiGA,wBAAgB,yBAAyB,IAAI,MAAM,CAgDlD;AAED,eAAO,MAAM,yBAAyB,QAsBrC,CAAC"}
@@ -142,6 +142,7 @@ ${buildToolPromptSection()}
142
142
  - If a question can be answered by exploring the codebase, explore the codebase instead.
143
143
  - Only perform mutating actions (creating/editing files, destructive shell commands, API writes) when the user has explicitly requested that change in the current turn. When exploring, debugging, or unsure, propose the change and wait for confirmation instead of acting.
144
144
  - Treat any \`bkper\` CLI command that writes to a Book (transactions, accounts, groups, books, collections, apps, imports, batch ops) as irreversible: show the exact command and wait for explicit user confirmation before running it. Read-only commands (list, get, balances, search, export) need no confirmation.
145
+ - For accounting numbers — balances, statements, reconciliations, taxes — never let raw LLM output be final; use or establish a deterministic, auditable route, keep computation separate from commentary, and make assumptions explicit.
145
146
  - Think in resources, movements, and balances — not debits and credits.
146
147
  - Extend meaning with properties before adding structural complexity.
147
148
  - Model domain and flows before coding; represent business reality, not technical shortcuts.
@@ -1 +1 @@
1
- {"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/agent/system-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,wBAAwB,EACxB,wBAAwB,EACxB,wBAAwB,EACxB,yBAAyB,GAC5B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,O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AC;IACtC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChD,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACxD,OAAO,GAAG,yBAAyB;;;;;;;;EAQrC,gBAAgB;;;;;;;;;;;EAWhB,SAAS;;;;;;;;EAQT,UAAU;;;;;;EAMV,cAAc;;;;;;;;CAQf,CAAC;AACF,CAAC;AAED,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;EAQvC,sBAAsB,EAAE;;;;;;;;;;;;;;CAczB,CAAC"}
@@ -96,8 +96,8 @@ More information at the [Bkper Developer Documentation](https://bkper.com/docs/#
96
96
  - `logoUrl?`: `string` — The App logo url
97
97
  - `logoUrlDark?`: `string` — The App logo url in dark mode
98
98
  - `menuOpenMode?`: `"SIDEBAR" | "EXPANDED" | "NEW_TAB"` — How the app menu opens. Default to SIDEBAR
99
- - `menuPopupHeight?`: `string` — The menu popup window height
100
- - `menuPopupWidth?`: `string` — The menu popup window width
99
+ - `menuPopupHeight?`: `string` — Deprecated
100
+ - `menuPopupWidth?`: `string` — Deprecated
101
101
  - `menuText?`: `string` — The contex menu text - default to the App name
102
102
  - `menuUrl?`: `string` — The context menu url
103
103
  - `menuUrlDev?`: `string` — The context menu url in dev mode
@@ -360,6 +360,13 @@ More information at the [Bkper Developer Documentation](https://bkper.com/docs/#
360
360
  - `updatedAt?`: `string` — The last update timestamp, in milliseconds
361
361
  - `url?`: `string` — The file serving url
362
362
 
363
+ ### FileList
364
+
365
+ **Properties:**
366
+
367
+ - `cursor?`: `string` — The cursor, for pagination
368
+ - `items?`: `bkper.File[]` — List items
369
+
363
370
  ### Group
364
371
 
365
372
  **Properties:**
@@ -631,9 +631,10 @@ It contains all `Accounts` where `Transactions` are recorded/posted;
631
631
  - `getTransaction(id: string)` → `Promise<Transaction | undefined>` — Retrieve a transaction by id.
632
632
  - `getVisibility()` / `setVisibility(visibility: Visibility)` → `Visibility` — Gets the visibility of the book.
633
633
  - `json()` → `bkper.Book` — Gets an immutable copy of the JSON payload for this resource.
634
- - `listEvents(afterDate: string | null, beforeDate: string | null, onError: boolean, resourceId: string | null, limit: number, cursor?: string)` → `Promise<EventList>` — Lists events in the Book based on the provided parameters.
634
+ - `listEvents(afterDate: string | null, beforeDate: string | null, onError: boolean | null, resourceId: string | null, limit: number, cursor?: string)` → `Promise<EventList>` — Lists events in the Book based on the provided parameters.
635
+ - `listFiles(limit?: number, cursor?: string)` → `Promise<FileList>` — Lists files in the Book, for pagination.
635
636
  - `listTransactions(query?: string, limit?: number, cursor?: string)` → `Promise<TransactionList>` — Lists transactions in the Book based on the provided query, limit, and cursor, for pagination.
636
- - `mergeTransactions(transaction1: Transaction, transaction2: Transaction)` → `Promise<Transaction>` — Merge two `Transactions` into a single new canonical transaction.
637
+ - `mergeTransactions(transaction1: string | bkper.Transaction | Transaction, transaction2: string | bkper.Transaction | Transaction)` → `Promise<Transaction>` — Merge two `Transactions` into a single new canonical transaction.
637
638
  - `parseDate(date: string)` → `Date` — Parse a date string according to date pattern and timezone of the Book. Also parse ISO yyyy-mm-dd format.
638
639
  - `parseValue(value: string)` → `Amount | undefined` — Parse a value string according to `DecimalSeparator` and fraction digits of the Book.
639
640
  - `remove()` → `Promise<Book>` — Warning!
@@ -909,6 +910,19 @@ A File can be attached to a `Transaction` or used to import data.
909
910
 
910
911
  *Standard property methods (deleteProperty, getProperties, getProperty, getPropertyKeys, getVisibleProperties, setProperties, setProperty, setVisibleProperties, setVisibleProperty) — see Account.*
911
912
 
913
+ ### FileList
914
+
915
+ A list associated with a file query.
916
+
917
+ **Constructor:** `new FileList(book: Book, payload: bkper.FileList)`
918
+
919
+ **Methods:**
920
+
921
+ - `getCursor()` → `string | undefined` — Gets the cursor associated with the query for pagination.
922
+ - `getFirst()` → `File | undefined` — Gets the first File in the list.
923
+ - `getItems()` → `File[]` — Gets the files in the list.
924
+ - `size()` → `number` — Gets the total number of files in the list.
925
+
912
926
  ### Group *(extends ResourceProperty<bkper.Group>)*
913
927
 
914
928
  This class defines a Group of `Accounts`.
@@ -1284,6 +1298,12 @@ Use your own API key for dedicated quota limits and project-level usage tracking
1284
1298
  API keys are for project identification only, not for authentication or agent attribution.
1285
1299
  Agent attribution is handled separately via the `agentIdProvider`.
1286
1300
 
1301
+ **oauthTokenProvider**
1302
+
1303
+ If omitted or if it returns undefined, requests are sent without an Authorization header.
1304
+ This supports environments where authentication is injected outside bkper-js, such as
1305
+ Bkper Platform outbound for server-side app routes.
1306
+
1287
1307
  **requestRetryHandler**
1288
1308
 
1289
1309
  This function is called when a request fails and needs to be retried.
@@ -1330,6 +1350,8 @@ Enum that represents event types.
1330
1350
  - `ACCOUNT_CREATED`
1331
1351
  - `ACCOUNT_DELETED`
1332
1352
  - `ACCOUNT_UPDATED`
1353
+ - `BOOK_AUDITED`
1354
+ - `BOOK_CREATED`
1333
1355
  - `BOOK_DELETED`
1334
1356
  - `BOOK_UPDATED`
1335
1357
  - `COLLABORATOR_ADDED`
@@ -1,225 +1,78 @@
1
- # Financial Statements — Deterministic Workflow
1
+ # Financial Statements — Deterministic Reporting
2
2
 
3
- Use this guide when a user asks for a balance sheet, P&L, income statement, profit and loss, or any other ledger-derived financial report from a Bkper book.
3
+ Use this guide when a user asks for a balance sheet, P&L, income statement, profit and loss, or another ledger-derived financial report from a Bkper Book.
4
4
 
5
- ## Deterministic first
5
+ ## Principle
6
6
 
7
- Financial statements are **deterministic accounting tasks**.
7
+ Financial statements are deterministic accounting work. For the same Book snapshot, statement type, period, and reporting assumptions, the same inputs must produce the same numbers.
8
8
 
9
- For the same book snapshot, statement type, period, and report settings, the agent should be able to run the same local code/config and obtain the same result every time. Use non-deterministic reasoning only for tasks whose nature is interpretive such as suspicious transaction analysis, commentary, or general insights not for deciding how the statement itself is computed.
9
+ Do not make raw LLM reasoning the final source of statement values. Use or establish a deterministic, auditable reporting route, then keep optional AI commentary separate from the computed statement.
10
10
 
11
- Treat the reporting route as something that should be **persisted locally** and reused.
11
+ Prefer existing trusted routes before creating new ones. A trusted route may be a script, CLI pipeline, platform app, bot, report config, template, or another project-standard artifact that the user already relies on.
12
12
 
13
- ---
13
+ If none exists, recommend the smallest auditable route that fits the user's context.
14
14
 
15
- ## Step 0 — Reuse an existing local statement runner
15
+ ## Bkper statement semantics
16
16
 
17
- Before running ad-hoc balance queries, inspect the local project for a canonical deterministic route for financial statements.
17
+ Statements come from balances calculated from Transactions and organized by Groups.
18
18
 
19
- Look for artifacts such as:
19
+ | Statement | Accounts | Time basis | Query pattern |
20
+ | --- | --- | --- | --- |
21
+ | Balance Sheet | Asset and/or Liability | Position at a point in time | `group:'<root>' before:<date>` |
22
+ | P&L / Income Statement | Incoming and/or Outgoing | Activity during a period | `group:'<root>' after:<start> before:<end>` |
20
23
 
21
- - `reports/`
22
- - `scripts/`
23
- - `package.json` scripts
24
- - local config/spec files
25
- - `AGENTS.md`
26
-
27
- If a local statement runner already exists:
28
-
29
- - Use it as the default route
30
- - Pass explicit parameters for book, statement type, and dates/period
31
- - Return the result produced by that runner
32
- - Do **not** rediscover groups or rebuild fresh balance queries unless the user explicitly asks to update or rebuild the reporting logic
33
-
34
- Once a deterministic route exists, prefer it over live ad-hoc querying.
35
-
36
- ---
37
-
38
- ## Step 1 — If none exists, bootstrap one
39
-
40
- If no deterministic runner exists yet, do **not** treat a live one-off balance query as the canonical solution.
41
-
42
- Instead:
43
-
44
- 1. Explain briefly that financial statements should be generated by repeatable local code/config
45
- 2. Offer to create that local statement runner for the project
46
- 3. Ask approval before writing files
47
- 4. Use live Bkper queries only as **bootstrap/discovery steps** to build the deterministic route correctly
48
-
49
- If the request is ambiguous (for example, “run a financial statement”), clarify whether the user wants:
50
-
51
- - Balance Sheet
52
- - Profit & Loss / Income Statement
53
- - Both
54
-
55
- During bootstrap, it is acceptable to create either:
56
-
57
- - a small shell script that runs fixed CLI queries and formats the output, or
58
- - a `bkper-js` script that resolves dates, loads groups, and renders the statement in a stable format
59
-
60
- Prefer the smallest boring solution that is easy to rerun and inspect.
61
-
62
- ---
63
-
64
- ## Step 2 — Discover the correct root groups
65
-
66
- Use these commands during bootstrap to identify the correct statement roots.
67
-
68
- ```bash
69
- bkper group list -b <bookId> --format csv
70
- ```
71
-
72
- Inspect the output and identify **top-level groups** (no parent). Root group names vary by book — common examples: `Total Equity`, `Balance Sheet`, `Profit & Loss`, `Results`, `Net Worth`.
73
-
74
- Identify each root group by the account types it contains:
75
-
76
- | Root group contains | Statement |
77
- | ---------------------------------- | ---------------------------- |
78
- | ASSET and/or LIABILITY accounts | Balance Sheet |
79
- | INCOMING and/or OUTGOING accounts | Profit & Loss / Income Statement |
80
-
81
- When you discover the correct roots, persist them for future runs.
82
-
83
- Prefer storing the **group ID** in the local report config/script. If the execution route also needs the group name for a query string, persist the name as well.
84
-
85
- ### If the book has no usable statement hierarchy
86
-
87
- If Step 2 does **not** reveal clear statement roots, treat that as a modeling gap, not as permission to improvise one silently.
88
-
89
- In that case:
24
+ Rules:
90
25
 
91
- - explain that the book is **not yet statement-ready** for deterministic reporting
92
- - do **not** invent arbitrary roots from subgroup names or partial account matches
93
- - inspect the existing account names, language, and reporting style already present in the book
94
- - propose the **smallest** hierarchy that fits the user's actual use case and local standards
95
- - ask approval before creating groups, moving accounts, or persisting the proposed roots
96
- - once approved, validate the hierarchy with live balance queries and then persist it in the local runner/config
26
+ - Use the relevant **root reporting group**. Do not silently substitute subgroups such as `Assets`, `Liabilities`, `Revenue`, or `Expenses` when the Book has a higher reporting root.
27
+ - Balance Sheet uses `before:` because permanent Accounts accumulate continuously.
28
+ - P&L uses `after:` + `before:` because non-permanent Accounts report activity within a period.
29
+ - `after:` is inclusive and `before:` is exclusive.
30
+ - Do not query the whole Book without a reporting group or account filter.
97
31
 
98
- When relevant, clarify whether the user wants:
32
+ Date examples:
99
33
 
100
- - internal management reporting
101
- - local/statutory reporting
102
- - a simplified starter structure to evolve later
34
+ | Request | Balance Sheet | P&L |
35
+ | --- | --- | --- |
36
+ | Current month | `before:$m` | `after:$m-1 before:$m` |
37
+ | Current year | `before:$y` | `after:$y-1 before:$y` |
38
+ | Full year 2024 | `before:2025-01-01` | `after:2024-01-01 before:2025-01-01` |
103
39
 
104
- If the user only wants a quick answer for now, you may still provide an **exploratory / provisional** result, but state clearly that the book still needs an approved reporting hierarchy for future deterministic statements.
40
+ `$m` and `$y` are Bkper query date variables for current month-end and current year-end. In shell commands, wrap queries containing `$` variables in single quotes to prevent shell expansion.
105
41
 
106
- ---
42
+ ## Working route
107
43
 
108
- ## Step 3 Fetch balances to validate and implement the runner
44
+ Before computing a statement, inspect local project context for an existing reporting route:
109
45
 
110
- Use these commands during bootstrap to validate the accounting logic and to implement the deterministic runner.
111
-
112
- **Balance Sheet** — permanent accounts, cumulative position at a point in time:
113
-
114
- ```bash
115
- bkper balance list -b <bookId> \
116
- -q "group:'<rootGroup>' before:<date>" \
117
- --format csv --expanded 2
118
- ```
119
-
120
- **Profit & Loss / Income Statement** — non-permanent accounts, activity within a period:
121
-
122
- ```bash
123
- bkper balance list -b <bookId> \
124
- -q "group:'<rootGroup>' after:<start> before:<end>" \
125
- --format csv --expanded 2
126
- ```
127
-
128
- Use the output to confirm the correct hierarchy, totals, and period semantics before persisting the script/spec.
129
-
130
- ---
131
-
132
- ## Step 4 — Persist the deterministic route locally
133
-
134
- After discovery and validation, create or update local artifacts so future requests reuse the same route.
135
-
136
- Typical artifacts:
46
+ - `AGENTS.md`
47
+ - `reports/`
48
+ - `scripts/`
49
+ - package scripts
50
+ - report config/spec files
51
+ - platform app or bot code
137
52
 
138
- - `reports/balance-sheet.sh`
139
- - `reports/profit-and-loss.sh`
140
- - `scripts/financial-statements.ts`
141
- - `reports/financial-statements.json`
142
- - `package.json` scripts such as `report:balance-sheet` and `report:pl`
53
+ If a route exists, use it and pass explicit Book, statement, and date parameters. Do not rediscover groups or rebuild the report unless the user asks to change the reporting logic.
143
54
 
144
- Persist the decisions that make the report repeatable:
55
+ If no route exists, use read-only Bkper queries only for discovery and validation, then propose a repeatable route. Persist the decisions that make the report reproducible:
145
56
 
146
- - `bookId`
57
+ - Book ID
147
58
  - statement type
148
- - root group ID
149
- - root group name if needed by the chosen execution path
150
- - timezone, if relevant to date boundaries
151
- - expanded depth / output detail level
152
- - exact date semantics for each statement type
59
+ - root group IDs and names
60
+ - date boundaries and timezone, when relevant
153
61
  - output format
62
+ - detail/expansion level
63
+ - any local reporting assumptions
154
64
 
155
- The canonical runner should produce a stable output shape, such as structured JSON, Markdown, or CSV with clear sections, totals, and period labels.
156
-
157
- If helpful, also create or update a local `AGENTS.md` note telling future agent sessions to use the canonical financial statement script. `AGENTS.md` is **optional persistence**, not a prerequisite for the first request.
158
-
159
- ---
160
-
161
- ## Step 5 — Use the script for future requests
162
-
163
- Once the local statement runner exists:
164
-
165
- - Use it as the default route for balance sheet and P&L requests
166
- - Resolve relative periods like “last year” into explicit date boundaries in code/config
167
- - Keep deterministic statement generation separate from optional AI commentary
168
- - If the reporting logic must change, update the script/config instead of improvising a fresh one-off route
169
-
170
- Do not re-decide the accounting method on every request.
171
-
172
- ---
173
-
174
- ## One-off exploratory fallback
175
-
176
- If the user explicitly does **not** want to create the script now and only wants a quick one-off answer, you may run live balance queries directly.
177
-
178
- In that case:
179
-
180
- - Clearly label the result as **exploratory / provisional**
181
- - State that it is **not yet** the canonical deterministic reporting route for the project
182
- - Recommend persisting a local script/config if the user wants repeatable accounting output in future requests
183
-
184
- ---
185
-
186
- ## Date patterns
187
-
188
- Use these patterns when validating or implementing the deterministic runner.
189
-
190
- | Request | Balance Sheet | Profit & Loss |
191
- | -------------- | -------------------------- | ------------------------------ |
192
- | Current month | `before:$m` | `after:$m-1 before:$m` |
193
- | Current year | `before:$y` | `after:$y-1 before:$y` |
194
- | Full year 2024 | `before:2025-01-01` | `after:2024-01-01 before:2025-01-01` |
195
-
196
- - `after:` is **inclusive**, `before:` is **exclusive**
197
- - `$d` = today, `$m` = current month-end, `$y` = current year-end
198
- - In shell, wrap queries containing `$` variables in **single quotes** to prevent shell expansion
65
+ If the Book has no clear reporting hierarchy, treat that as a modeling gap. Do not invent a hierarchy silently. Inspect the Book's existing language and structure, propose the smallest hierarchy that fits the user's goal, and ask before changing Accounts or Groups.
199
66
 
200
- ---
67
+ ## Examples & Patterns
201
68
 
202
- ## Key rules
69
+ Use the implementation style that matches the user's context:
203
70
 
204
- - **Always use the ROOT group** — never subgroups like `Assets`, `Liabilities`, `Revenue`, `Expenses`
205
- - **Balance Sheet** uses `before:` only permanent accounts accumulate continuously
206
- - **P&L** uses `after:` + `before:` — non-permanent accounts track period activity
207
- - **Use `--format csv`** for token efficiency when loading bootstrap results into an LLM context
208
- - **Use `--expanded 2`** to see meaningful sub-totals in the hierarchy
209
- - Once a canonical local report route exists, **reuse it instead of rediscovering the logic**
210
- - Prefer persisting reporting decisions in code/config rather than relying on session memory
71
+ - **Scripts & CLI** — best for local, inspectable, repeatable reports and lightweight project workflows.
72
+ - **Platform Apps / Bots** best for shared, durable, event-driven, or operational reporting workflows.
211
73
 
212
- ---
74
+ Existing trusted reports or templates may be reused when they are already the user's accepted reporting route, but they are not required by this guide.
213
75
 
214
- ## Common mistakes
76
+ ## Provisional answers
215
77
 
216
- | Wrong | Right |
217
- | --- | --- |
218
- | Immediately running ad-hoc balance queries as the default response to a first statement request | First look for a local runner; if none exists, propose creating one and use queries only for bootstrap |
219
- | Assuming `AGENTS.md` must already exist | `AGENTS.md` can be created or updated during bootstrap to route future requests |
220
- | `group:'Assets' before:2025-01-01` | `group:'Total Equity' before:2025-01-01` — use root group, not subgroup |
221
- | Inventing a new statement hierarchy silently because no roots were found | Explain that the book is not yet statement-ready, propose a minimal hierarchy aligned with the user's language and local standards, and ask approval before changing structure |
222
- | `before:$m` for P&L | `after:$m-1 before:$m` — P&L needs a period, not just an end date |
223
- | `after:$y-1 before:$d` | `after:$y-1 before:$y` — use consistent date basis on both ends |
224
- | `-q 'before:2025-01-01'` without group filter | `-q "group:'<rootGroup>' before:2025-01-01"` — always filter by group |
225
- | Re-interpreting “last year” differently each time | Resolve relative periods into explicit dates inside the canonical script/config |
78
+ If the user explicitly wants a quick answer and does not want to establish a route, live read-only balance queries are acceptable. Label the result as **exploratory / provisional** and recommend a deterministic route for future repeatability.
package/lib/docs/index.md CHANGED
@@ -5,7 +5,7 @@ Reference docs for Bkper tasks. Load only the specific doc(s) relevant to the ta
5
5
  - **data-management.md** — CLI reference for managing financial data and files: books, accounts, groups, files, transactions, per-account balance queries, query operators (on:, after:, before:, account:, group:), output formats (table/json/csv), batch operations via stdin/piping, collections.
6
6
  - **app-management.md** — CLI reference for building and deploying Bkper apps: dev/build/deploy workflow, app install/uninstall, secrets management, app logs, bkper.yaml configuration reference (identity, branding, events, menu integration, deployment).
7
7
  - **app-building.md** — Full app-building reference: single Worker app architecture (`client/` + `server/`), development loop, `/api/*` routes, `/events` handlers, deployment patterns, the Bkper Platform, and self-hosted alternatives. Includes authentication patterns for web clients (`@bkper/web-auth`), server API routes (`Authorization: Bearer` on `/api/*` with outbound auth injection), platform event handlers (`new Bkper()` with outbound auth injection), and local development.
8
- - **financial-statements.md** — Step-by-step workflow for aggregate financial reports (balance sheet, P&L): root group discovery, query patterns, date semantics (before: vs after:+before:), common mistakes to avoid.
9
- - **taxes.md** — Deterministic workflow for tax position and filing summaries: discovering tax-relevant groups, period-based balance queries, persisting a local tax runner. Jurisdiction-agnostic — outputs raw period balances, leaving rate/application to the user.
8
+ - **financial-statements.md** — Deterministic reporting principles and Bkper query semantics for balance sheet and P&L: trusted routes, root reporting groups, permanent vs period date rules, and provisional query patterns.
9
+ - **taxes.md** — Deterministic tax reporting principles: trusted routes, user-approved tax-relevant groups/accounts, period activity queries, explicit jurisdiction assumptions, and provisional query patterns.
10
10
  - **bkper-js.md** — bkper-js Node.js/browser SDK: Bkper, Book, Account, Transaction, Group, Balance classes, all methods, getBalancesReport, OAuth configuration, library setup.
11
11
  - **bkper-api-types.md** — Bkper REST API TypeScript interfaces: Book, Account, Transaction, Group, Balance, Collection, File — field names and types used by the API and bkper-js.
package/lib/docs/taxes.md CHANGED
@@ -1,264 +1,80 @@
1
- # Taxes — Deterministic Workflow
1
+ # Taxes — Deterministic Reporting
2
2
 
3
- Use this guide when a user asks to "do my taxes", compute a tax position, generate a tax filing summary, or derive any period-based tax report from a Bkper book.
3
+ Use this guide when a user asks to do taxes, compute a tax position, prepare a filing summary, or reconcile tax-related balances from a Bkper Book.
4
4
 
5
- ## Deterministic first
5
+ ## Principle
6
6
 
7
- Tax reporting is a **deterministic accounting task**.
7
+ Tax reporting is deterministic accounting work, but tax law is jurisdiction-specific. Do not invent rates, deductions, filing rules, or tax categories from general knowledge.
8
8
 
9
- For the same book snapshot, tax period, and set of tax-relevant groups, the agent should be able to run the same local code/config and obtain the same tax position every time. Use non-deterministic reasoning only for interpretive tasks — such as flagging unusual transactions, commenting on trends, or explaining variances not for deciding how the tax position itself is computed.
9
+ Do not make raw LLM reasoning the final source of tax numbers. Use or establish a deterministic, auditable route, then keep optional AI commentary separate from computed values.
10
10
 
11
- Treat the tax route as something that should be **persisted locally** and reused.
11
+ A tax route may compute tax owed only when the applicable rules, rates, and assumptions are supplied by the user or encoded in a reviewed deterministic artifact. Otherwise, produce raw period data or a filing worksheet for the user or their advisor to apply local rules.
12
12
 
13
- Jurisdiction-specific tax rules (rates, deductions, allowances, filing formats) vary widely and change over time. This workflow intentionally stays **agnostic about those rules**. It provides the deterministic scaffold: discovering tax-relevant account groupings, querying period data, producing a repeatable tax position through a local runner, and persisting that route. The user applies their local tax knowledge to interpret the output.
13
+ Prefer existing trusted routes before creating new ones. If none exists, recommend the smallest auditable route that fits the user's context.
14
14
 
15
- The agent does **not** compute tax owed directly. It builds or reuses a **local tax generation engine** (a script, config, or small program) that queries the book deterministically and outputs raw period data. The engine is the canonical source of truth; the agent merely orchestrates, validates, and persists it.
15
+ ## Bkper tax semantics
16
16
 
17
- ---
17
+ Tax reports usually combine period activity with tax-account positions or movements.
18
18
 
19
- ## Step 0 Reuse an existing local tax runner
19
+ | Need | Time basis | Query pattern |
20
+ | --- | --- | --- |
21
+ | Revenue / income activity | Period activity | `group:'<revenueRoot>' after:<start> before:<end>` |
22
+ | Deductible cost / expense activity | Period activity | `group:'<expenseRoot>' after:<start> before:<end>` |
23
+ | Tax account movements | Period activity | `account:'<taxAccount>' after:<start> before:<end>` |
24
+ | Tax liability / credit balance | Position at period end | `account:'<taxAccount>' before:<end>` |
20
25
 
21
- Before running ad-hoc queries, inspect the local project for a canonical deterministic tax runner.
26
+ Rules:
22
27
 
23
- Look for artifacts such as:
28
+ - Use user-approved tax-relevant Groups and Accounts. Do not assume standard names such as `Revenue`, `VAT`, `Taxes`, or `Deductible Expenses` are correct for the Book.
29
+ - Period activity uses `after:` + `before:`.
30
+ - Tax liability or credit Accounts may need either period movements or an end balance, depending on the question.
31
+ - `after:` is inclusive and `before:` is exclusive.
32
+ - Do not query the whole Book without a tax-relevant group or account filter.
24
33
 
25
- - `reports/`
26
- - `scripts/`
27
- - `package.json` scripts
28
- - local config/spec files
29
- - `AGENTS.md`
30
-
31
- If a local tax runner already exists:
32
-
33
- - Use it as the default route
34
- - Pass explicit parameters for book, period, and any tax-relevant overrides
35
- - Return the result produced by that runner
36
- - Do **not** rediscover groups or rebuild fresh queries unless the user explicitly asks to update or rebuild the tax logic
37
-
38
- Once a deterministic route exists, prefer it over live ad-hoc querying.
39
-
40
- ---
41
-
42
- ## Step 1 — If none exists, bootstrap one
43
-
44
- If no deterministic runner exists yet, do **not** treat a live one-off query as the canonical solution.
45
-
46
- Instead:
47
-
48
- 1. Explain briefly that tax positions should be generated by a repeatable local engine
49
- 2. Offer to create that tax runner for the project
50
- 3. Ask approval before writing files
51
- 4. Use live Bkper queries only as **bootstrap/discovery steps** to build the deterministic route correctly
52
-
53
- If the request is ambiguous (for example, "do my taxes"), clarify what the user wants:
54
-
55
- - Tax position for a specific period (e.g., quarterly VAT, annual income tax)
56
- - Tax filing summary / worksheet for their jurisdiction
57
- - Reconciliation of tax-related balances
58
-
59
- During bootstrap, it is acceptable to create either:
60
-
61
- - a small shell script that runs fixed CLI queries and formats the output, or
62
- - a `bkper-js` script that resolves dates, loads groups, and renders the tax position in a stable format
63
-
64
- Prefer the smallest boring solution that is easy to rerun and inspect.
65
-
66
- ---
67
-
68
- ## Step 2 — Discover the tax-relevant groups
69
-
70
- Tax positions are usually derived from **period activity** — revenue, deductible expenses, and tax liability accounts. The specific groups that matter depend on the user's jurisdiction and how they have structured their book.
71
-
72
- The deterministic engine can work from **aggregated balances** or from **individual transactions**, depending on what the user needs:
73
-
74
- - **Balance-level** — faster, gives period totals per group/account. Good for computing a tax position or filing summary.
75
- - **Transaction-level** — slower, gives itemized detail. Good for audit trails, per-transaction deductions, or reconciling tax-account movements.
76
-
77
- During bootstrap, ask the user which level they need, or default to balance-level and note that transaction-level detail can be added later.
78
-
79
- Use these commands during bootstrap to identify candidate tax-relevant roots:
80
-
81
- ```bash
82
- bkper group list -b <bookId> --format csv
83
- bkper account list -b <bookId> --format csv
84
- ```
85
-
86
- Inspect the output and look for groups or accounts that the user already treats as tax-related. Common patterns include:
87
-
88
- - A root group or account for **revenue / income** (often INCOMING type)
89
- - A root group or account for **deductible expenses** (often OUTGOING type)
90
- - Accounts or groups that track **tax liabilities** or **tax credits** (often LIABILITY or ASSET type)
91
-
92
- Do **not** assume standard names. Root group names vary by book — examples: `Revenue`, `Income`, `Sales`, `Deductible Expenses`, `Operating Costs`, `Taxes`, `VAT`, `Income Tax`.
93
-
94
- Ask the user which groups represent their **tax-relevant activity** for the period in question. If they are unsure, propose the smallest set of top-level groups that cover:
95
-
96
- 1. **Gross revenue or income** for the period
97
- 2. **Deductible costs or expenses** for the period
98
- 3. Any **tax liability or credit accounts** already in use
99
-
100
- When you discover the correct groups, persist them for future runs.
101
-
102
- Prefer storing the **group IDs** in the local tax config/script. If the execution route also needs group names for query strings, persist the names as well.
103
-
104
- ### If the book has no usable tax-relevant grouping
105
-
106
- If Step 2 does not reveal clear tax-relevant roots, treat that as a modeling gap, not as permission to improvise one silently.
107
-
108
- In that case:
109
-
110
- - explain that the book is **not yet tax-ready** for deterministic reporting
111
- - do **not** invent arbitrary tax categories from subgroup names or partial account matches
112
- - inspect the existing account names, language, and reporting style already present in the book
113
- - propose the **smallest** grouping that fits the user's actual use case and local standards
114
- - ask approval before creating groups, moving accounts, or persisting the proposed roots
115
- - once approved, validate the grouping with live queries and then persist it in the local runner/config
116
-
117
- If the user only wants a quick answer for now, you may still provide an **exploratory / provisional** result, but state clearly that the book still needs an approved tax-relevant hierarchy for future deterministic tax runs.
34
+ Date examples:
118
35
 
119
- ---
120
-
121
- ## Step 3 Fetch data to validate and implement the runner
122
-
123
- Use these commands during bootstrap to validate the accounting logic and to implement the deterministic runner.
124
-
125
- Tax positions are period-based — query **activity within a period**, not cumulative position.
126
-
127
- ### Balance-level bootstrap (aggregated)
128
-
129
- ```bash
130
- # Revenue / income activity for the period
131
- bkper balance list -b <bookId> \
132
- -q "group:'<revenueRoot>' after:<start> before:<end>" \
133
- --format csv --expanded 2
134
-
135
- # Deductible expense activity for the period
136
- bkper balance list -b <bookId> \
137
- -q "group:'<expenseRoot>' after:<start> before:<end>" \
138
- --format csv --expanded 2
139
-
140
- # Tax liability or credit balance at period end (optional)
141
- bkper balance list -b <bookId> \
142
- -q "account:'<taxLiabilityAccount>' before:<end>" \
143
- --format csv --expanded 2
144
- ```
145
-
146
- ### Transaction-level bootstrap (itemized)
147
-
148
- ```bash
149
- # Revenue / income transactions for the period
150
- bkper transaction list -b <bookId> \
151
- -q "group:'<revenueRoot>' after:<start> before:<end>" \
152
- --format csv
153
-
154
- # Deductible expense transactions for the period
155
- bkper transaction list -b <bookId> \
156
- -q "group:'<expenseRoot>' after:<start> before:<end>" \
157
- --format csv
158
-
159
- # Tax-account movements for the period (optional)
160
- bkper transaction list -b <bookId> \
161
- -q "account:'<taxLiabilityAccount>' after:<start> before:<end>" \
162
- --format csv
163
- ```
164
-
165
- > **Bootstrap-only flags:** `--format csv` and `--expanded <level>` are conveniences for the discovery phase. CSV is compact for loading into an LLM context to inspect hierarchy structure; `--expanded <level>` reveals sub-totals so you can confirm the group tree is correct. The canonical runner you persist should output whatever format the user actually needs — structured JSON, Markdown tables, plain CSV, or rendered CLI tables — not necessarily the raw CLI dump.
166
-
167
- Use the output to confirm the correct groups, period totals, and hierarchy before persisting the script/spec.
168
-
169
- **Do not compute tax owed in the agent's reasoning.** The deterministic runner should output raw period data. The user (or a jurisdiction-specific layer they add later) applies rates, deductions, and rules.
36
+ | Request | Period activity query |
37
+ | --- | --- |
38
+ | Current month | `after:$m-1 before:$m` |
39
+ | Current year | `after:$y-1 before:$y` |
40
+ | Full year 2024 | `after:2024-01-01 before:2025-01-01` |
41
+ | Last quarter | Resolve to explicit `after:<start> before:<end>` boundaries |
170
42
 
171
- ---
43
+ `$m` and `$y` are Bkper query date variables for current month-end and current year-end. In shell commands, wrap queries containing `$` variables in single quotes to prevent shell expansion.
172
44
 
173
- ## Step 4 — Persist the deterministic route locally
45
+ ## Working route
174
46
 
175
- After discovery and validation, create or update local artifacts so future requests reuse the same route.
47
+ Before computing a tax position, inspect local project context for an existing tax route:
176
48
 
177
- Typical artifacts:
49
+ - `AGENTS.md`
50
+ - `reports/`
51
+ - `scripts/`
52
+ - package scripts
53
+ - tax config/spec files
54
+ - platform app or bot code
178
55
 
179
- - `reports/tax-position.sh`
180
- - `scripts/taxes.ts`
181
- - `reports/taxes.json`
182
- - `package.json` scripts such as `report:taxes`
56
+ If a route exists, use it and pass explicit Book, period, and supported override parameters. Do not rediscover tax Groups or rebuild the logic unless the user asks to change it.
183
57
 
184
- Persist the decisions that make the tax run repeatable:
58
+ If no route exists, clarify the user's goal and recommend a repeatable route. Persist the decisions that make the tax run reproducible:
185
59
 
186
- - `bookId`
187
- - tax-relevant group IDs and names
188
- - query level (balance or transaction)
189
- - period semantics (e.g., calendar quarter, fiscal year)
190
- - timezone, if relevant to date boundaries
191
- - expanded depth for balance queries, if used
60
+ - Book ID
61
+ - tax period and timezone, when relevant
62
+ - tax-relevant Group and Account IDs and names
63
+ - balance-level or transaction-level detail
192
64
  - output format
65
+ - jurisdiction-specific rules, rates, and assumptions, if supplied
193
66
 
194
- The canonical runner should produce a stable output shape using programmatic formatting — structured JSON, Markdown, rendered tables, or CSV with clear sections, period labels, and raw totals. Build the report in code (via `bkper-js`, table builders, or the CLI's own render utilities) rather than passing through raw CLI query output. Keep the output **pre-calculation** — expose revenue, expenses, and any tax-account balances so the user can apply their local rules.
67
+ If the Book has no clear tax-relevant grouping, treat that as a modeling gap. Do not invent tax categories silently. Inspect the Book's existing language and structure, propose the smallest grouping that fits the user's goal, and ask before changing Accounts or Groups.
195
68
 
196
- If helpful, also create or update a local `AGENTS.md` note telling future agent sessions to use the canonical tax script. `AGENTS.md` is **optional persistence**, not a prerequisite for the first request.
69
+ ## Examples & Patterns
197
70
 
198
- ---
71
+ Use the implementation style that matches the user's context:
199
72
 
200
- ## Step 5Use the script for future requests
73
+ - **Scripts & CLI** best for local, inspectable tax worksheets, reconciliations, and lightweight repeatable summaries.
74
+ - **Platform Apps / Bots** — best for shared, durable, event-driven tax automation such as applying configured tax rules when Transactions are posted.
201
75
 
202
- Once the local tax runner exists:
76
+ Existing trusted reports or templates may be reused when they are already the user's accepted tax route, but they are not required by this guide.
203
77
 
204
- - Use it as the default route for tax position and filing summary requests
205
- - Resolve relative periods like "last quarter" or "last year" into explicit date boundaries in code/config
206
- - Keep deterministic tax generation separate from optional AI commentary or filing advice
207
- - If the tax logic must change (new groups, different period boundaries), update the script/config instead of improvising a fresh one-off route
78
+ ## Provisional answers
208
79
 
209
- Do not re-decide which groups are tax-relevant on every request.
210
-
211
- ---
212
-
213
- ## One-off exploratory fallback
214
-
215
- If the user explicitly does **not** want to create the script now and only wants a quick one-off answer, you may run live queries directly.
216
-
217
- In that case:
218
-
219
- - Clearly label the result as **exploratory / provisional**
220
- - State that it is **not yet** the canonical deterministic tax route for the project
221
- - Recommend persisting a local script/config if the user wants repeatable tax output in future requests
222
-
223
- ---
224
-
225
- ## Date patterns
226
-
227
- Use these patterns when validating or implementing the deterministic runner.
228
-
229
- | Request | Period activity query |
230
- | -------------- | ---------------------------------------------- |
231
- | Current month | `after:$m-1 before:$m` |
232
- | Current year | `after:$y-1 before:$y` |
233
- | Full year 2024 | `after:2024-01-01 before:2025-01-01` |
234
- | Last quarter | Resolve to explicit `after:<start> before:<end>` in script |
235
-
236
- - `after:` is **inclusive**, `before:` is **exclusive**
237
- - `$d` = today, `$m` = current month-end, `$y` = current year-end
238
- - In shell, wrap queries containing `$` variables in **single quotes** to prevent shell expansion
239
-
240
- ---
241
-
242
- ## Key rules
243
-
244
- - **The agent orchestrates the engine; the engine produces the output** — the canonical runner is what generates the tax report, not the agent's direct reasoning
245
- - **Tax positions are period-based** — use `after:` + `before:` for revenue and expense activity, not `before:` alone
246
- - **Always query by group or account** — never run unfiltered queries across the whole book
247
- - **Output raw data, not computed tax owed** — the deterministic runner exposes totals; jurisdiction-specific calculation is a user concern
248
- - **Bootstrap queries** may use `--format csv` and `--expanded <level>` to inspect hierarchy structure efficiently; the canonical runner should use programmatic formatting suited to the end user
249
- - Once a canonical local tax route exists, **reuse it instead of rediscovering the logic**
250
- - Prefer persisting tax-relevant group decisions in code/config rather than relying on session memory
251
-
252
- ---
253
-
254
- ## Common mistakes
255
-
256
- | Wrong | Right |
257
- | --- | --- |
258
- | The agent computing tax owed directly from queried data using guessed rates or rules | The agent building or reusing a local runner that outputs raw data; the user applies jurisdiction-specific rules |
259
- | Immediately running ad-hoc queries as the default response to a first tax request | First look for a local runner; if none exists, propose creating one and use queries only for bootstrap |
260
- | Assuming `AGENTS.md` must already exist | `AGENTS.md` can be created or updated during bootstrap to route future requests |
261
- | Using `before:` only for tax-relevant queries | Use `after:` + `before:` for period-based activity (revenue, expenses) |
262
- | Inventing a new tax hierarchy silently because no roots were found | Explain that the book is not yet tax-ready, propose a minimal grouping aligned with the user's language and local standards, and ask approval before changing structure |
263
- | Re-interpreting "last quarter" differently each time | Resolve relative periods into explicit dates inside the canonical script/config |
264
- | Mixing tax-bot specifics into the generic tax workflow | Keep this workflow independent of any bot or automation; it works from plain balances and transactions |
80
+ If the user explicitly wants a quick answer and does not want to establish a route, live read-only queries are acceptable. Label the result as **exploratory / provisional** and avoid applying unsupplied tax law.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper",
3
- "version": "4.16.3",
3
+ "version": "4.16.4",
4
4
  "description": "Command line client for Bkper",
5
5
  "bin": {
6
6
  "bkper": "./lib/cli.js"
@@ -51,7 +51,7 @@
51
51
  "upgrade:api": "bun update @bkper/bkper-api-types --latest && bun update bkper-js --latest"
52
52
  },
53
53
  "dependencies": {
54
- "@earendil-works/pi-coding-agent": "0.79.0",
54
+ "@earendil-works/pi-coding-agent": "0.79.1",
55
55
  "bkper-js": "^2.35.2",
56
56
  "commander": "^13.1.0",
57
57
  "dotenv": "^8.2.0",