@fuzzle/opencode-accountant 0.4.6-next.1 → 0.4.6

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 CHANGED
@@ -202,18 +202,22 @@ your-project/
202
202
 
203
203
  #### Workflow
204
204
 
205
- The `import-pipeline` tool operates directly on the working directory:
205
+ The `import-pipeline` tool provides an atomic, safe import workflow using git worktrees:
206
206
 
207
207
  1. Drop CSV files into `{paths.import}` (default: `import/incoming/`)
208
- 2. Run `import-pipeline` tool
208
+ 2. Run `import-pipeline` tool with optional provider/currency filters
209
209
  3. The tool automatically:
210
- - Classifies CSV files by provider/currency (creates import contexts in `.memory/`)
210
+ - Creates an isolated git worktree
211
+ - Syncs CSV files from main repo to worktree
212
+ - Classifies CSV files by provider/currency
211
213
  - Extracts accounts from rules and creates declarations in year journal
212
214
  - Validates all transactions have matching rules
213
215
  - Imports transactions to the appropriate year journal
214
216
  - Reconciles closing balance (auto-detected from CSV metadata or data analysis)
215
- - CSV files move: `incoming/` `pending/` `done/`
216
- 4. All changes remain uncommitted for inspection. If any step fails, partially processed files remain in place for debugging
217
+ - Merges changes back to main branch with `--no-ff`
218
+ - Deletes processed CSV files from main repo's import/incoming
219
+ - Cleans up the worktree
220
+ 4. If any step fails, the worktree is discarded and main branch remains untouched (CSV files are preserved for retry)
217
221
 
218
222
  ### Statement Import
219
223
 
@@ -82,23 +82,71 @@ Bash is FORBIDDEN for:
82
82
 
83
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
84
 
85
- The `import-pipeline` tool operates directly on the working directory:
85
+ The `import-pipeline` tool provides an **atomic, safe workflow** using git worktrees:
86
86
 
87
87
  1. **Prepare**: Drop CSV files into `{paths.import}` (configured in `config/import/providers.yaml`, default: `import/incoming`)
88
- 2. **Run Pipeline**: Execute `import-pipeline`
89
- 3. **Automatic Processing**: The tool:
90
- - Classifies CSV files by provider/currency (creates import contexts in `.memory/`)
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
+ - Syncs CSV files from main repo to worktree
91
+ - Classifies CSV files by provider/currency
91
92
  - Extracts required accounts from rules files and updates year journal
92
- - Validates all transactions have matching rules (dry run)
93
+ - Validates all transactions have matching rules
93
94
  - Imports transactions to the appropriate year journal
94
95
  - Reconciles closing balance (auto-detected from CSV metadata or data, or manual override)
95
- - CSV files move: `incoming/` `pending/` `done/`
96
- 4. **After Pipeline**: All changes remain uncommitted in your working directory for inspection
97
- 5. **Handle Failures**: If any step fails (e.g., unknown postings found):
98
- - Changes remain in place for inspection (partially processed files stay in `pending/`)
96
+ - Merges changes back to main branch with `--no-ff`
97
+ - Deletes processed CSV files from main repo's import/incoming
98
+ - Cleans up the worktree
99
+ 4. **Handle Failures**: If any step fails (e.g., unknown postings found):
100
+ - Worktree is preserved by default at `/tmp/import-worktree-<uuid>` for debugging
101
+ - Main branch remains untouched
99
102
  - Review error output for unknown postings with full CSV row data
100
103
  - Update rules file with `if` directives to match the transaction
101
- - Re-run `import-pipeline` (use `--skipClassify true` if files are already classified)
104
+ - Re-run `import-pipeline`
105
+
106
+ ### Error Recovery and Worktree Preservation
107
+
108
+ **Default Behavior:**
109
+
110
+ - On success: Worktrees are automatically cleaned up
111
+ - On error: Worktrees are preserved in `/tmp/import-worktree-<uuid>` for debugging
112
+ - Worktrees in `/tmp` are automatically cleaned up on system reboot
113
+
114
+ **Manual Recovery from Failed Import:**
115
+
116
+ If an import fails and the worktree is preserved, you can:
117
+
118
+ 1. **Inspect the worktree:**
119
+
120
+ ```bash
121
+ cd /tmp/import-worktree-<uuid>
122
+ hledger check # Validate journal
123
+ hledger balance # Check balances
124
+ cat ledger/2026.journal # View imported transactions
125
+ ```
126
+
127
+ 2. **Continue the import manually:**
128
+
129
+ ```bash
130
+ cd /tmp/import-worktree-<uuid>
131
+ # Fix any issues (edit rules, fix transactions, etc.)
132
+ git add .
133
+ git commit -m "Fix import issues"
134
+ git checkout main
135
+ git merge --no-ff import-<uuid>
136
+ ```
137
+
138
+ 3. **Clean up when done:**
139
+
140
+ ```bash
141
+ git worktree remove /tmp/import-worktree-<uuid>
142
+ ```
143
+
144
+ 4. **Or use the cleanup tool:**
145
+ ```bash
146
+ cleanup-worktrees # Removes worktrees >24h old
147
+ cleanup-worktrees --all true # Removes all import worktrees
148
+ cleanup-worktrees --dryRun true # Preview without removing
149
+ ```
102
150
 
103
151
  **Logs:**
104
152
 
@@ -107,6 +155,13 @@ The `import-pipeline` tool operates directly on the working directory:
107
155
  - Log path is included in import-pipeline output
108
156
  - Review the log to understand what failed and why
109
157
 
158
+ **Force Cleanup on Error:**
159
+ If you prefer the old behavior (always cleanup, even on error):
160
+
161
+ ```bash
162
+ import-pipeline --keepWorktreeOnError false
163
+ ```
164
+
110
165
  ### Rules Files
111
166
 
112
167
  - The location of the rules files is configured in `config/import/providers.yaml`
@@ -141,39 +196,44 @@ The following are MCP tools available to you. Always call these tools directly -
141
196
 
142
197
  ### import-pipeline
143
198
 
144
- **Purpose:** Import workflow that classifies, validates, imports, and reconciles bank statements.
199
+ **Purpose:** Atomic import workflow that classifies, validates, imports, and reconciles bank statements.
145
200
 
146
201
  **Usage:**
147
202
 
148
203
  - Basic: `import-pipeline()`
149
- - With manual closing balance: `import-pipeline(closingBalance: "CHF 1234.56")`
204
+ - Filtered: `import-pipeline(provider: "ubs", currency: "chf")`
205
+ - With manual closing balance: `import-pipeline(provider: "revolut", closingBalance: "CHF 1234.56")`
150
206
  - Skip classification: `import-pipeline(skipClassify: true)` (if files already classified)
151
207
 
152
208
  **Arguments:**
153
209
 
154
- | Argument | Type | Default | Description |
155
- | ---------------- | ------- | ------- | ------------------------------------------------------------------------------ |
156
- | `provider` | string | - | Logger metadata (does not filter CSV selection — use classify step for that) |
157
- | `currency` | string | - | Logger metadata (does not filter CSV selection — use classify step for that) |
158
- | `skipClassify` | boolean | `false` | Skip classification step |
159
- | `closingBalance` | string | - | Manual closing balance for reconciliation |
160
- | `account` | string | - | Manual account override (auto-detected from rules) |
210
+ | Argument | Type | Default | Description |
211
+ | ---------------- | ------- | ------- | -------------------------------------------------- |
212
+ | `provider` | string | - | Filter by provider (e.g., `revolut`, `ubs`) |
213
+ | `currency` | string | - | Filter by currency (e.g., `chf`, `eur`) |
214
+ | `skipClassify` | boolean | `false` | Skip classification step |
215
+ | `closingBalance` | string | - | Manual closing balance for reconciliation |
216
+ | `account` | string | - | Manual account override (auto-detected from rules) |
161
217
 
162
218
  **Behavior:**
163
219
 
164
- 1. Classifies CSV files and creates import contexts (unless `skipClassify: true`)
165
- 2. For each context (sequentially, fail-fast):
166
- - Extracts accounts from matched rules and updates year journal with declarations
167
- - Validates all transactions have matching rules (dry run)
168
- - Imports transactions to year journal, moves CSV from `pending/` to `done/`
169
- - Reconciles closing balance (auto-detected from CSV metadata/data or manual override)
170
- 3. All changes remain uncommitted in the working directory
220
+ 1. Creates isolated git worktree
221
+ 2. Syncs CSV files from main repo to worktree
222
+ 3. Classifies CSV files (unless `skipClassify: true`)
223
+ 4. Extracts accounts from matched rules and updates year journal with declarations
224
+ 5. Validates all transactions have matching rules (dry run)
225
+ 6. Imports transactions to year journal
226
+ 7. Reconciles closing balance (auto-detected from CSV metadata/data or manual override)
227
+ 8. Merges to main with `--no-ff` commit
228
+ 9. Deletes processed CSV files from main repo's import/incoming
229
+ 10. Cleans up worktree
171
230
 
172
231
  **Output:** Returns step-by-step results with success/failure for each phase
173
232
 
174
233
  **On Failure:**
175
234
 
176
- - Changes remain in place for inspection
235
+ - Worktree is discarded automatically
236
+ - Main branch remains untouched
177
237
  - Error details include unknown postings with full CSV row data
178
238
  - Fix rules and re-run the pipeline
179
239