@fuzzle/opencode-accountant 0.0.16-next.1 → 0.0.17-next.1
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/README.md +39 -15
- package/agent/accountant.md +56 -52
- package/dist/index.js +38 -1136
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -193,26 +193,33 @@ your-project/
|
|
|
193
193
|
|
|
194
194
|
#### Workflow
|
|
195
195
|
|
|
196
|
+
The `import-pipeline` tool provides an atomic, safe import workflow using git worktrees:
|
|
197
|
+
|
|
196
198
|
1. Drop CSV files into `{paths.import}` (default: `import/incoming/`)
|
|
197
|
-
2. Run `
|
|
198
|
-
3.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
199
|
+
2. Run `import-pipeline` tool with optional provider/currency filters
|
|
200
|
+
3. The tool automatically:
|
|
201
|
+
- Creates an isolated git worktree
|
|
202
|
+
- Classifies CSV files by provider/currency
|
|
203
|
+
- Validates all transactions have matching rules
|
|
204
|
+
- Imports transactions to the appropriate year journal
|
|
205
|
+
- Reconciles closing balance (if available in CSV metadata)
|
|
206
|
+
- Merges changes back to main branch with `--no-ff`
|
|
207
|
+
- Cleans up the worktree
|
|
208
|
+
4. If any step fails, the worktree is discarded and main branch remains untouched
|
|
204
209
|
|
|
205
210
|
### Statement Import
|
|
206
211
|
|
|
207
|
-
The `import-
|
|
212
|
+
The `import-pipeline` tool is the single entry point for importing bank statements. It orchestrates classification, validation, import, and reconciliation in an atomic operation.
|
|
208
213
|
|
|
209
214
|
#### Tool Arguments
|
|
210
215
|
|
|
211
|
-
| Argument
|
|
212
|
-
|
|
|
213
|
-
| `provider`
|
|
214
|
-
| `currency`
|
|
215
|
-
| `
|
|
216
|
+
| Argument | Type | Default | Description |
|
|
217
|
+
| ---------------- | ------- | ------- | ------------------------------------------------------ |
|
|
218
|
+
| `provider` | string | - | Filter by provider (e.g., `revolut`, `ubs`) |
|
|
219
|
+
| `currency` | string | - | Filter by currency (e.g., `chf`, `eur`) |
|
|
220
|
+
| `skipClassify` | boolean | `false` | Skip classification step (if files already classified) |
|
|
221
|
+
| `closingBalance` | string | - | Manual closing balance for reconciliation |
|
|
222
|
+
| `account` | string | - | Manual account override (auto-detected from rules) |
|
|
216
223
|
|
|
217
224
|
#### Rules File Matching
|
|
218
225
|
|
|
@@ -230,9 +237,26 @@ See the hledger documentation for details on rules file format and syntax.
|
|
|
230
237
|
|
|
231
238
|
#### Unknown Postings
|
|
232
239
|
|
|
233
|
-
When a transaction doesn't match any `if` pattern in the rules file, hledger assigns it to `income:unknown` or `expenses:unknown` depending on the transaction direction. The
|
|
240
|
+
When a transaction doesn't match any `if` pattern in the rules file, hledger assigns it to `income:unknown` or `expenses:unknown` depending on the transaction direction. The pipeline will fail at the validation step, reporting the unknown postings so you can add appropriate rules before retrying.
|
|
241
|
+
|
|
242
|
+
#### Closing Balance Reconciliation
|
|
243
|
+
|
|
244
|
+
For providers that include closing balance in CSV metadata (e.g., UBS), the tool automatically validates that the imported transactions result in the correct balance. Configure metadata extraction in `providers.yaml`:
|
|
245
|
+
|
|
246
|
+
```yaml
|
|
247
|
+
metadata:
|
|
248
|
+
- field: closing_balance
|
|
249
|
+
row: 5
|
|
250
|
+
column: 1
|
|
251
|
+
- field: from_date
|
|
252
|
+
row: 2
|
|
253
|
+
column: 1
|
|
254
|
+
- field: until_date
|
|
255
|
+
row: 3
|
|
256
|
+
column: 1
|
|
257
|
+
```
|
|
234
258
|
|
|
235
|
-
For
|
|
259
|
+
For providers without closing balance in metadata (e.g., Revolut), provide it manually via the `closingBalance` argument.
|
|
236
260
|
|
|
237
261
|
## Development
|
|
238
262
|
|
package/agent/accountant.md
CHANGED
|
@@ -8,7 +8,7 @@ tools:
|
|
|
8
8
|
bash: true
|
|
9
9
|
edit: true
|
|
10
10
|
write: true
|
|
11
|
-
# MCP tools available:
|
|
11
|
+
# MCP tools available: import-pipeline, update-prices
|
|
12
12
|
permission:
|
|
13
13
|
bash: allow
|
|
14
14
|
edit: allow
|
|
@@ -56,11 +56,10 @@ When working with accounting tasks:
|
|
|
56
56
|
|
|
57
57
|
You have access to specialized MCP tools that MUST be used for their designated tasks. Do NOT attempt to replicate their functionality with bash commands, direct hledger CLI calls, or manual file edits.
|
|
58
58
|
|
|
59
|
-
| Tool
|
|
60
|
-
|
|
|
61
|
-
| `
|
|
62
|
-
| `
|
|
63
|
-
| `update-prices` | Fetching exchange rates | `curl` to price APIs, manual price entries |
|
|
59
|
+
| Tool | Use For | NEVER Do Instead |
|
|
60
|
+
| ----------------- | ---------------------------------------------------- | --------------------------------------------------------- |
|
|
61
|
+
| `import-pipeline` | Full import workflow (classify → import → reconcile) | Manual file moves, `hledger import`, manual journal edits |
|
|
62
|
+
| `update-prices` | Fetching exchange rates | `curl` to price APIs, manual price entries |
|
|
64
63
|
|
|
65
64
|
These tools handle validation, deduplication, error checking, and file organization automatically. Bypassing them risks data corruption, duplicate transactions, and inconsistent state.
|
|
66
65
|
|
|
@@ -74,26 +73,31 @@ Bash is allowed ONLY for:
|
|
|
74
73
|
|
|
75
74
|
Bash is FORBIDDEN for:
|
|
76
75
|
|
|
77
|
-
- `hledger import` - use `import-
|
|
78
|
-
- Moving/copying CSV files - use `
|
|
76
|
+
- `hledger import` - use `import-pipeline` tool instead
|
|
77
|
+
- Moving/copying CSV files - use `import-pipeline` tool instead
|
|
79
78
|
- Editing journal files directly - use `edit` tool only for rules files
|
|
80
79
|
- Fetching prices - use `update-prices` tool instead
|
|
81
80
|
|
|
82
81
|
## Statement Import Workflow
|
|
83
82
|
|
|
84
|
-
**IMPORTANT:** You MUST use
|
|
83
|
+
**IMPORTANT:** You MUST use `import-pipeline` for statement imports. Do NOT edit journals manually, run `hledger import` directly, or move files with bash commands.
|
|
84
|
+
|
|
85
|
+
The `import-pipeline` tool provides an **atomic, safe workflow** using git worktrees:
|
|
85
86
|
|
|
86
87
|
1. **Prepare**: Drop CSV files into `{paths.import}` (configured in `config/import/providers.yaml`, default: `import/incoming`)
|
|
87
|
-
2. **
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
-
|
|
92
|
-
-
|
|
93
|
-
-
|
|
94
|
-
-
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
2. **Run Pipeline**: Execute `import-pipeline` (optionally filter by `provider` and `currency`)
|
|
89
|
+
3. **Automatic Processing**: The tool creates an isolated git worktree and:
|
|
90
|
+
- Classifies CSV files by provider/currency
|
|
91
|
+
- Validates all transactions have matching rules
|
|
92
|
+
- Imports transactions to the appropriate year journal
|
|
93
|
+
- Reconciles closing balance (if available in CSV metadata)
|
|
94
|
+
- Merges changes back to main branch with `--no-ff`
|
|
95
|
+
- Cleans up the worktree
|
|
96
|
+
4. **Handle Failures**: If any step fails (e.g., unknown postings found):
|
|
97
|
+
- Worktree is discarded, main branch remains untouched
|
|
98
|
+
- Review error output for unknown postings with full CSV row data
|
|
99
|
+
- Update rules file with `if` directives to match the transaction
|
|
100
|
+
- Re-run `import-pipeline`
|
|
97
101
|
|
|
98
102
|
### Rules Files
|
|
99
103
|
|
|
@@ -106,51 +110,51 @@ Bash is FORBIDDEN for:
|
|
|
106
110
|
|
|
107
111
|
The following are MCP tools available to you. Always call these tools directly - do not attempt to replicate their behavior with shell commands.
|
|
108
112
|
|
|
109
|
-
###
|
|
110
|
-
|
|
111
|
-
**Purpose:** Organizes CSV files by auto-detecting provider and currency.
|
|
112
|
-
|
|
113
|
-
**Usage:** `classify-statements()` (no arguments)
|
|
114
|
-
|
|
115
|
-
**Behavior:**
|
|
116
|
-
|
|
117
|
-
- Scans `{paths.import}` for CSV files
|
|
118
|
-
- Detects provider using header matching + filename patterns
|
|
119
|
-
- Moves classified files to `{paths.pending}/<provider>/<currency>/`
|
|
120
|
-
- Moves unrecognized files to `{paths.unrecognized}/`
|
|
121
|
-
- Aborts if any file collision detected (no partial moves)
|
|
113
|
+
### import-pipeline
|
|
122
114
|
|
|
123
|
-
**
|
|
124
|
-
|
|
125
|
-
**Common issues:**
|
|
115
|
+
**Purpose:** Atomic import workflow that classifies, validates, imports, and reconciles bank statements.
|
|
126
116
|
|
|
127
|
-
|
|
128
|
-
- Collisions → Move/rename existing pending files before re-running
|
|
117
|
+
**Usage:**
|
|
129
118
|
|
|
130
|
-
|
|
119
|
+
- Basic: `import-pipeline()`
|
|
120
|
+
- Filtered: `import-pipeline(provider: "ubs", currency: "chf")`
|
|
121
|
+
- With manual closing balance: `import-pipeline(provider: "revolut", closingBalance: "CHF 1234.56")`
|
|
122
|
+
- Skip classification: `import-pipeline(skipClassify: true)` (if files already classified)
|
|
131
123
|
|
|
132
|
-
|
|
124
|
+
**Arguments:**
|
|
133
125
|
|
|
134
|
-
|
|
126
|
+
| Argument | Type | Default | Description |
|
|
127
|
+
| ---------------- | ------- | ------- | -------------------------------------------------- |
|
|
128
|
+
| `provider` | string | - | Filter by provider (e.g., `revolut`, `ubs`) |
|
|
129
|
+
| `currency` | string | - | Filter by currency (e.g., `chf`, `eur`) |
|
|
130
|
+
| `skipClassify` | boolean | `false` | Skip classification step |
|
|
131
|
+
| `closingBalance` | string | - | Manual closing balance for reconciliation |
|
|
132
|
+
| `account` | string | - | Manual account override (auto-detected from rules) |
|
|
135
133
|
|
|
136
|
-
**
|
|
134
|
+
**Behavior:**
|
|
137
135
|
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
1. Creates isolated git worktree
|
|
137
|
+
2. Classifies CSV files (unless `skipClassify: true`)
|
|
138
|
+
3. Validates all transactions have matching rules (dry run)
|
|
139
|
+
4. Imports transactions to year journal
|
|
140
|
+
5. Reconciles closing balance against CSV metadata or manual value
|
|
141
|
+
6. Merges to main with `--no-ff` commit
|
|
142
|
+
7. Cleans up worktree
|
|
140
143
|
|
|
141
|
-
**
|
|
144
|
+
**Output:** Returns step-by-step results with success/failure for each phase
|
|
142
145
|
|
|
143
|
-
|
|
144
|
-
- Matches each CSV to rules file via `source` directive
|
|
145
|
-
- Check mode: Validates transactions, reports unknown postings with full CSV row data
|
|
146
|
-
- Import mode: Only proceeds if ALL transactions have known accounts, moves CSVs to `{paths.done}/`
|
|
146
|
+
**On Failure:**
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
- Worktree is discarded automatically
|
|
149
|
+
- Main branch remains untouched
|
|
150
|
+
- Error details include unknown postings with full CSV row data
|
|
151
|
+
- Fix rules and re-run the pipeline
|
|
149
152
|
|
|
150
|
-
**
|
|
153
|
+
**Common issues:**
|
|
151
154
|
|
|
152
|
-
-
|
|
153
|
-
-
|
|
155
|
+
- Unknown postings → Add `if` directives to rules file
|
|
156
|
+
- Unrecognized files → Add provider config to `config/import/providers.yaml`
|
|
157
|
+
- Balance mismatch → Check for missing transactions or incorrect rules
|
|
154
158
|
|
|
155
159
|
---
|
|
156
160
|
|