bkper 4.12.30 → 4.12.31
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/lib/docs/index.md +1 -0
- package/lib/docs/taxes.md +264 -0
- package/package.json +1 -1
package/lib/docs/index.md
CHANGED
|
@@ -6,5 +6,6 @@ Reference docs for Bkper tasks. Load only the specific doc(s) relevant to the ta
|
|
|
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: architecture (packages, client/server/events), development loop, event handlers, deployment patterns, the Bkper Platform, and self-hosted alternatives. Includes authentication patterns for web clients (`@bkper/web-auth`), event handlers (`bkper-oauth-token` headers), and local development. Load this for scaffolding apps, understanding app structure, or debugging the dev/build/deploy lifecycle.
|
|
8
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.
|
|
9
10
|
- **bkper-js.md** — bkper-js Node.js/browser SDK: Bkper, Book, Account, Transaction, Group, Balance classes, all methods, getBalancesReport, OAuth configuration, library setup.
|
|
10
11
|
- **bkper-api-types.md** — Bkper REST API TypeScript interfaces: Book, Account, Transaction, Group, Balance, Collection — field names and types used by the API and bkper-js.
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# Taxes — Deterministic Workflow
|
|
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.
|
|
4
|
+
|
|
5
|
+
## Deterministic first
|
|
6
|
+
|
|
7
|
+
Tax reporting is a **deterministic accounting task**.
|
|
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.
|
|
10
|
+
|
|
11
|
+
Treat the tax route as something that should be **persisted locally** and reused.
|
|
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.
|
|
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.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Step 0 — Reuse an existing local tax runner
|
|
20
|
+
|
|
21
|
+
Before running ad-hoc queries, inspect the local project for a canonical deterministic tax runner.
|
|
22
|
+
|
|
23
|
+
Look for artifacts such as:
|
|
24
|
+
|
|
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.
|
|
118
|
+
|
|
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.
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Step 4 — Persist the deterministic route locally
|
|
174
|
+
|
|
175
|
+
After discovery and validation, create or update local artifacts so future requests reuse the same route.
|
|
176
|
+
|
|
177
|
+
Typical artifacts:
|
|
178
|
+
|
|
179
|
+
- `reports/tax-position.sh`
|
|
180
|
+
- `scripts/taxes.ts`
|
|
181
|
+
- `reports/taxes.json`
|
|
182
|
+
- `package.json` scripts such as `report:taxes`
|
|
183
|
+
|
|
184
|
+
Persist the decisions that make the tax run repeatable:
|
|
185
|
+
|
|
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
|
|
192
|
+
- output format
|
|
193
|
+
|
|
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.
|
|
195
|
+
|
|
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.
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## Step 5 — Use the script for future requests
|
|
201
|
+
|
|
202
|
+
Once the local tax runner exists:
|
|
203
|
+
|
|
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
|
|
208
|
+
|
|
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 |
|