@fuzzle/opencode-accountant 0.8.1 → 0.9.0-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 +3 -0
- package/agent/accountant.md +20 -9
- package/dist/index.js +15 -1
- package/docs/tools/import-pipeline.md +5 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -101,6 +101,7 @@ paths:
|
|
|
101
101
|
|
|
102
102
|
providers:
|
|
103
103
|
revolut:
|
|
104
|
+
importOrder: 10
|
|
104
105
|
detect:
|
|
105
106
|
- filenamePattern: '^account-statement_'
|
|
106
107
|
header: 'Type,Product,Started Date,Completed Date,Description,Amount,Fee,Currency,State,Balance'
|
|
@@ -115,6 +116,7 @@ providers:
|
|
|
115
116
|
BTC: btc
|
|
116
117
|
|
|
117
118
|
ubs:
|
|
119
|
+
importOrder: 0
|
|
118
120
|
detect:
|
|
119
121
|
# Note: UBS exports have a trailing semicolon in the header row, which creates
|
|
120
122
|
# an empty field when parsed. The header must include a trailing comma to match.
|
|
@@ -167,6 +169,7 @@ providers:
|
|
|
167
169
|
| `renamePattern` | No | Output filename pattern with `{placeholder}` substitutions |
|
|
168
170
|
| `metadata` | No | Array of metadata extraction rules (see below) |
|
|
169
171
|
| `currencies` | Yes | Map of raw currency values to normalized folder names |
|
|
172
|
+
| `importOrder` | No | Numeric priority for import sequencing (default: `0`, lower imports first) |
|
|
170
173
|
|
|
171
174
|
\* **Note on trailing delimiters:** If the CSV header row ends with a trailing delimiter (e.g., `Field1;Field2;`), this creates an empty field when parsed. The `header` config must include a trailing comma to account for this (e.g., `Field1,Field2,`).
|
|
172
175
|
|
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: import-pipeline, fetch-currency-prices
|
|
11
|
+
# MCP tools available: import-pipeline, fetch-currency-prices, hledger-mcp (read-only queries)
|
|
12
12
|
permissions:
|
|
13
13
|
bash: allow
|
|
14
14
|
edit: allow
|
|
@@ -45,7 +45,7 @@ before performing any accounting task.**
|
|
|
45
45
|
When working with accounting tasks:
|
|
46
46
|
|
|
47
47
|
1. **Follow conventions precisely** - Use the exact patterns from `config/conventions/*.md`
|
|
48
|
-
1. **Always validate** - Run hledger
|
|
48
|
+
1. **Always validate** - Run hledger check after changes
|
|
49
49
|
1. **Balance checking** - Ensure all transactions balance with `@ price` notation for conversions
|
|
50
50
|
1. **File organization** - Keep transactions in appropriate year journals
|
|
51
51
|
1. **Duplicate checking** - Take extra care to avoid duplicate transactions
|
|
@@ -60,25 +60,32 @@ You have access to specialized MCP tools that MUST be used for their designated
|
|
|
60
60
|
| ----------------------- | ---------------------------------------------------- | --------------------------------------------------------- |
|
|
61
61
|
| `import-pipeline` | Full import workflow (classify → import → reconcile) | Manual file moves, `hledger import`, manual journal edits |
|
|
62
62
|
| `fetch-currency-prices` | Fetching exchange rates | `curl` to price APIs, manual price entries |
|
|
63
|
+
| hledger MCP tools | Read-only queries (balance, register, accounts, etc.) | `hledger bal`, `hledger reg`, `hledger print` via bash |
|
|
63
64
|
|
|
64
65
|
These tools handle validation, deduplication, error checking, and file organization automatically. Bypassing them risks data corruption, duplicate transactions, and inconsistent state.
|
|
65
66
|
|
|
66
67
|
## Bash Usage Policy
|
|
67
68
|
|
|
68
|
-
Bash is allowed ONLY for
|
|
69
|
+
Bash is allowed ONLY for:
|
|
69
70
|
|
|
70
|
-
- **Validation**: `hledger check
|
|
71
|
-
- **Formatting check**: `hledger-fmt` (WITHOUT `--fix` - shows diff only)
|
|
72
|
-
- **Queries**: `hledger print`, `hledger reg`, `hledger accounts`
|
|
71
|
+
- **Validation**: `hledger check`
|
|
73
72
|
- **File inspection**: `cat`, `head`, `tail`, `grep`
|
|
74
73
|
|
|
74
|
+
For all hledger queries, use the hledger MCP tools instead of bash:
|
|
75
|
+
|
|
76
|
+
- `balance` / `balancesheet` / `incomestatement` / `cashflow` for reports
|
|
77
|
+
- `register` / `aregister` for transaction history
|
|
78
|
+
- `print` for displaying transactions
|
|
79
|
+
- `accounts` for listing accounts
|
|
80
|
+
- `stats` / `activity` / `payees` / `descriptions` for analysis
|
|
81
|
+
|
|
75
82
|
Bash is **FORBIDDEN** for:
|
|
76
83
|
|
|
77
|
-
- **`hledger-fmt --fix`** - Mass-reformats files, destroys formatting
|
|
78
84
|
- **`hledger import`** - Use `import-pipeline` tool instead
|
|
79
85
|
- **Moving/copying CSV files** - Use `import-pipeline` tool instead
|
|
80
86
|
- **Writing to files** - Use `edit`/`write` tools with user approval only
|
|
81
87
|
- **Fetching prices** - Use `fetch-currency-prices` tool instead
|
|
88
|
+
- **`hledger -f <file>`** - Never specify journal files explicitly; `.hledger.journal` includes all journals automatically
|
|
82
89
|
|
|
83
90
|
## Manual Editing Policy
|
|
84
91
|
|
|
@@ -97,7 +104,6 @@ Bash is **FORBIDDEN** for:
|
|
|
97
104
|
|
|
98
105
|
### Absolutely Forbidden
|
|
99
106
|
|
|
100
|
-
❌ **NEVER run `hledger-fmt --fix`** - mass-reformats entire files
|
|
101
107
|
❌ **NEVER reformat existing transactions** - preserve exact spacing/separators
|
|
102
108
|
❌ **NEVER use `hledger print` to rewrite transactions** - changes formatting
|
|
103
109
|
|
|
@@ -105,7 +111,7 @@ Bash is **FORBIDDEN** for:
|
|
|
105
111
|
|
|
106
112
|
1. **Use edit tool surgically** - change only necessary lines
|
|
107
113
|
2. **Preserve formatting exactly** - match spacing, indentation, separators
|
|
108
|
-
3. **Validate after**: Run `hledger check
|
|
114
|
+
3. **Validate after**: Run `hledger check` to verify no unintended changes
|
|
109
115
|
|
|
110
116
|
## Statement Import Workflow
|
|
111
117
|
|
|
@@ -128,6 +134,11 @@ The `import-pipeline` tool operates directly on the working directory:
|
|
|
128
134
|
- Update rules file with `if` directives to match the transaction
|
|
129
135
|
- Re-run `import-pipeline` (use `--skipClassify true` if files are already classified)
|
|
130
136
|
|
|
137
|
+
⚠️ **On import failure, your role is investigator only:**
|
|
138
|
+
- Investigate the error using read-only tools (hledger check, print, reg, file inspection)
|
|
139
|
+
- Present findings and root cause analysis to the user
|
|
140
|
+
- **NEVER manually edit journal files to fix import issues** — suggest the fix, wait for approval
|
|
141
|
+
|
|
131
142
|
**Logs:**
|
|
132
143
|
|
|
133
144
|
- Every import run generates a detailed log: `.memory/import-<timestamp>.md`
|
package/dist/index.js
CHANGED
|
@@ -17314,7 +17314,16 @@ function validateProviderConfig(name, config2) {
|
|
|
17314
17314
|
if (Object.keys(currencies).length === 0) {
|
|
17315
17315
|
throw new Error(`Invalid config for provider '${name}': 'currencies' must contain at least one mapping`);
|
|
17316
17316
|
}
|
|
17317
|
-
|
|
17317
|
+
if (configObj.importOrder !== undefined) {
|
|
17318
|
+
if (typeof configObj.importOrder !== "number") {
|
|
17319
|
+
throw new Error(`Invalid config for provider '${name}': 'importOrder' must be a number`);
|
|
17320
|
+
}
|
|
17321
|
+
}
|
|
17322
|
+
return {
|
|
17323
|
+
detect,
|
|
17324
|
+
currencies,
|
|
17325
|
+
importOrder: configObj.importOrder
|
|
17326
|
+
};
|
|
17318
17327
|
}
|
|
17319
17328
|
function loadImportConfig(directory) {
|
|
17320
17329
|
return loadYamlConfig(directory, CONFIG_FILE2, (parsedObj) => {
|
|
@@ -25254,9 +25263,14 @@ async function importPipeline(directory, agent, options, configLoader = loadImpo
|
|
|
25254
25263
|
executePreprocessFiatStep(context, contextIds, logger);
|
|
25255
25264
|
executePreprocessBtcStep(context, contextIds, logger);
|
|
25256
25265
|
await executeBtcPurchaseStep(context, contextIds, logger);
|
|
25266
|
+
const importConfig = loadImportConfig(context.directory);
|
|
25257
25267
|
const orderedContextIds = [...contextIds].sort((a, b) => {
|
|
25258
25268
|
const ctxA = loadContext(context.directory, a);
|
|
25259
25269
|
const ctxB = loadContext(context.directory, b);
|
|
25270
|
+
const orderA = importConfig.providers[ctxA.provider]?.importOrder ?? 0;
|
|
25271
|
+
const orderB = importConfig.providers[ctxB.provider]?.importOrder ?? 0;
|
|
25272
|
+
if (orderA !== orderB)
|
|
25273
|
+
return orderA - orderB;
|
|
25260
25274
|
const isBtcA = ctxA.provider === "revolut" && ctxA.currency === "btc" ? 1 : 0;
|
|
25261
25275
|
const isBtcB = ctxB.provider === "revolut" && ctxB.currency === "btc" ? 1 : 0;
|
|
25262
25276
|
return isBtcA - isBtcB;
|
|
@@ -348,10 +348,13 @@ See [reconcile-statement](reconcile-statement.md) for details.
|
|
|
348
348
|
|
|
349
349
|
### Sequential Processing (Fail-Fast)
|
|
350
350
|
|
|
351
|
-
The pipeline processes contexts **one at a time
|
|
351
|
+
The pipeline processes contexts **one at a time**, ordered by:
|
|
352
|
+
|
|
353
|
+
1. **Provider `importOrder`** — lower values first (default: `0`). Configure in `providers.yaml` to control which provider imports first (e.g., UBS before Revolut).
|
|
354
|
+
2. **BTC-last** — within the same `importOrder`, Revolut BTC contexts are sorted after fiat contexts (needed for fiat→BTC purchase matching).
|
|
352
355
|
|
|
353
356
|
```
|
|
354
|
-
for each contextId:
|
|
357
|
+
for each contextId (sorted by importOrder, then BTC-last):
|
|
355
358
|
1. Load context
|
|
356
359
|
2. Run steps 2-4 for this context
|
|
357
360
|
3. If ANY step fails → STOP PIPELINE
|