@fuzzle/opencode-accountant 0.1.2-next.1 → 0.1.3-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 -1
- package/agent/accountant.md +14 -10
- package/dist/index.js +99 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -199,13 +199,15 @@ The `import-pipeline` tool provides an atomic, safe import workflow using git wo
|
|
|
199
199
|
2. Run `import-pipeline` tool with optional provider/currency filters
|
|
200
200
|
3. The tool automatically:
|
|
201
201
|
- Creates an isolated git worktree
|
|
202
|
+
- Syncs CSV files from main repo to worktree
|
|
202
203
|
- Classifies CSV files by provider/currency
|
|
203
204
|
- Validates all transactions have matching rules
|
|
204
205
|
- Imports transactions to the appropriate year journal
|
|
205
206
|
- Reconciles closing balance (if available in CSV metadata)
|
|
206
207
|
- Merges changes back to main branch with `--no-ff`
|
|
208
|
+
- Deletes processed CSV files from main repo's import/incoming
|
|
207
209
|
- Cleans up the worktree
|
|
208
|
-
4. If any step fails, the worktree is discarded and main branch remains untouched
|
|
210
|
+
4. If any step fails, the worktree is discarded and main branch remains untouched (CSV files are preserved for retry)
|
|
209
211
|
|
|
210
212
|
### Statement Import
|
|
211
213
|
|
package/agent/accountant.md
CHANGED
|
@@ -56,10 +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
|
-
| `import-pipeline`
|
|
62
|
-
| `fetch-currency-prices`
|
|
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
|
+
| `fetch-currency-prices` | Fetching exchange rates | `curl` to price APIs, manual price entries |
|
|
63
63
|
|
|
64
64
|
These tools handle validation, deduplication, error checking, and file organization automatically. Bypassing them risks data corruption, duplicate transactions, and inconsistent state.
|
|
65
65
|
|
|
@@ -87,11 +87,13 @@ The `import-pipeline` tool provides an **atomic, safe workflow** using git workt
|
|
|
87
87
|
1. **Prepare**: Drop CSV files into `{paths.import}` (configured in `config/import/providers.yaml`, default: `import/incoming`)
|
|
88
88
|
2. **Run Pipeline**: Execute `import-pipeline` (optionally filter by `provider` and `currency`)
|
|
89
89
|
3. **Automatic Processing**: The tool creates an isolated git worktree and:
|
|
90
|
+
- Syncs CSV files from main repo to worktree
|
|
90
91
|
- Classifies CSV files by provider/currency
|
|
91
92
|
- Validates all transactions have matching rules
|
|
92
93
|
- Imports transactions to the appropriate year journal
|
|
93
94
|
- Reconciles closing balance (if available in CSV metadata)
|
|
94
95
|
- Merges changes back to main branch with `--no-ff`
|
|
96
|
+
- Deletes processed CSV files from main repo's import/incoming
|
|
95
97
|
- Cleans up the worktree
|
|
96
98
|
4. **Handle Failures**: If any step fails (e.g., unknown postings found):
|
|
97
99
|
- Worktree is discarded, main branch remains untouched
|
|
@@ -134,12 +136,14 @@ The following are MCP tools available to you. Always call these tools directly -
|
|
|
134
136
|
**Behavior:**
|
|
135
137
|
|
|
136
138
|
1. Creates isolated git worktree
|
|
137
|
-
2.
|
|
138
|
-
3.
|
|
139
|
-
4.
|
|
140
|
-
5.
|
|
141
|
-
6.
|
|
142
|
-
7.
|
|
139
|
+
2. Syncs CSV files from main repo to worktree
|
|
140
|
+
3. Classifies CSV files (unless `skipClassify: true`)
|
|
141
|
+
4. Validates all transactions have matching rules (dry run)
|
|
142
|
+
5. Imports transactions to year journal
|
|
143
|
+
6. Reconciles closing balance against CSV metadata or manual value
|
|
144
|
+
7. Merges to main with `--no-ff` commit
|
|
145
|
+
8. Deletes processed CSV files from main repo's import/incoming
|
|
146
|
+
9. Cleans up worktree
|
|
143
147
|
|
|
144
148
|
**Output:** Returns step-by-step results with success/failure for each phase
|
|
145
149
|
|
package/dist/index.js
CHANGED
|
@@ -17731,6 +17731,53 @@ function ensureDirectory(dirPath) {
|
|
|
17731
17731
|
fs5.mkdirSync(dirPath, { recursive: true });
|
|
17732
17732
|
}
|
|
17733
17733
|
}
|
|
17734
|
+
function syncCSVFilesToWorktree(mainRepoPath, worktreePath, importDir) {
|
|
17735
|
+
const result = {
|
|
17736
|
+
synced: [],
|
|
17737
|
+
errors: []
|
|
17738
|
+
};
|
|
17739
|
+
const mainImportDir = path6.join(mainRepoPath, importDir);
|
|
17740
|
+
const worktreeImportDir = path6.join(worktreePath, importDir);
|
|
17741
|
+
const csvFiles = findCSVFiles(mainImportDir);
|
|
17742
|
+
if (csvFiles.length === 0) {
|
|
17743
|
+
return result;
|
|
17744
|
+
}
|
|
17745
|
+
ensureDirectory(worktreeImportDir);
|
|
17746
|
+
for (const file2 of csvFiles) {
|
|
17747
|
+
try {
|
|
17748
|
+
const sourcePath = path6.join(mainImportDir, file2);
|
|
17749
|
+
const destPath = path6.join(worktreeImportDir, file2);
|
|
17750
|
+
fs5.copyFileSync(sourcePath, destPath);
|
|
17751
|
+
result.synced.push(file2);
|
|
17752
|
+
} catch (error45) {
|
|
17753
|
+
const errorMsg = error45 instanceof Error ? error45.message : String(error45);
|
|
17754
|
+
result.errors.push({ file: file2, error: errorMsg });
|
|
17755
|
+
}
|
|
17756
|
+
}
|
|
17757
|
+
return result;
|
|
17758
|
+
}
|
|
17759
|
+
function cleanupProcessedCSVFiles(mainRepoPath, importDir) {
|
|
17760
|
+
const result = {
|
|
17761
|
+
deleted: [],
|
|
17762
|
+
errors: []
|
|
17763
|
+
};
|
|
17764
|
+
const mainImportDir = path6.join(mainRepoPath, importDir);
|
|
17765
|
+
const csvFiles = findCSVFiles(mainImportDir);
|
|
17766
|
+
if (csvFiles.length === 0) {
|
|
17767
|
+
return result;
|
|
17768
|
+
}
|
|
17769
|
+
for (const file2 of csvFiles) {
|
|
17770
|
+
try {
|
|
17771
|
+
const filePath = path6.join(mainImportDir, file2);
|
|
17772
|
+
fs5.unlinkSync(filePath);
|
|
17773
|
+
result.deleted.push(file2);
|
|
17774
|
+
} catch (error45) {
|
|
17775
|
+
const errorMsg = error45 instanceof Error ? error45.message : String(error45);
|
|
17776
|
+
result.errors.push({ file: file2, error: errorMsg });
|
|
17777
|
+
}
|
|
17778
|
+
}
|
|
17779
|
+
return result;
|
|
17780
|
+
}
|
|
17734
17781
|
|
|
17735
17782
|
// src/tools/classify-statements.ts
|
|
17736
17783
|
function buildSuccessResult2(classified, unrecognized, message) {
|
|
@@ -19060,19 +19107,67 @@ async function importPipeline(directory, agent, options, configLoader = loadImpo
|
|
|
19060
19107
|
path: worktree.path,
|
|
19061
19108
|
branch: worktree.branch
|
|
19062
19109
|
});
|
|
19110
|
+
try {
|
|
19111
|
+
const config2 = configLoader(directory);
|
|
19112
|
+
const syncResult = syncCSVFilesToWorktree(directory, worktree.path, config2.paths.import);
|
|
19113
|
+
if (syncResult.synced.length === 0 && syncResult.errors.length === 0) {
|
|
19114
|
+
result.steps.sync = buildStepResult(true, "No CSV files to sync", {
|
|
19115
|
+
synced: []
|
|
19116
|
+
});
|
|
19117
|
+
} else if (syncResult.errors.length > 0) {
|
|
19118
|
+
result.steps.sync = buildStepResult(true, `Synced ${syncResult.synced.length} file(s) with ${syncResult.errors.length} error(s)`, { synced: syncResult.synced, errors: syncResult.errors });
|
|
19119
|
+
} else {
|
|
19120
|
+
result.steps.sync = buildStepResult(true, `Synced ${syncResult.synced.length} CSV file(s) to worktree`, { synced: syncResult.synced });
|
|
19121
|
+
}
|
|
19122
|
+
} catch (error45) {
|
|
19123
|
+
const errorMsg = error45 instanceof Error ? error45.message : String(error45);
|
|
19124
|
+
result.steps.sync = buildStepResult(false, `Failed to sync CSV files: ${errorMsg}`, { synced: [], errors: [{ file: "unknown", error: errorMsg }] });
|
|
19125
|
+
}
|
|
19063
19126
|
try {
|
|
19064
19127
|
await executeClassifyStep(context, worktree);
|
|
19065
19128
|
await executeDryRunStep(context, worktree);
|
|
19066
19129
|
await executeImportStep(context, worktree);
|
|
19067
19130
|
await executeReconcileStep(context, worktree);
|
|
19131
|
+
try {
|
|
19132
|
+
const config2 = configLoader(directory);
|
|
19133
|
+
const cleanupResult = cleanupProcessedCSVFiles(directory, config2.paths.import);
|
|
19134
|
+
if (cleanupResult.deleted.length === 0 && cleanupResult.errors.length === 0) {
|
|
19135
|
+
result.steps.cleanup = buildStepResult(true, "No CSV files to cleanup", { csvCleanup: { deleted: [] } });
|
|
19136
|
+
} else if (cleanupResult.errors.length > 0) {
|
|
19137
|
+
result.steps.cleanup = buildStepResult(true, `Deleted ${cleanupResult.deleted.length} CSV file(s) with ${cleanupResult.errors.length} error(s)`, {
|
|
19138
|
+
csvCleanup: {
|
|
19139
|
+
deleted: cleanupResult.deleted,
|
|
19140
|
+
errors: cleanupResult.errors
|
|
19141
|
+
}
|
|
19142
|
+
});
|
|
19143
|
+
} else {
|
|
19144
|
+
result.steps.cleanup = buildStepResult(true, `Deleted ${cleanupResult.deleted.length} CSV file(s) from main repo`, { csvCleanup: { deleted: cleanupResult.deleted } });
|
|
19145
|
+
}
|
|
19146
|
+
} catch (error45) {
|
|
19147
|
+
const errorMsg = error45 instanceof Error ? error45.message : String(error45);
|
|
19148
|
+
result.steps.cleanup = buildStepResult(false, `Failed to cleanup CSV files: ${errorMsg}`, {
|
|
19149
|
+
csvCleanup: {
|
|
19150
|
+
deleted: [],
|
|
19151
|
+
errors: [{ file: "unknown", error: errorMsg }]
|
|
19152
|
+
}
|
|
19153
|
+
});
|
|
19154
|
+
}
|
|
19068
19155
|
await executeMergeStep(context, worktree);
|
|
19069
|
-
result.steps.cleanup
|
|
19070
|
-
|
|
19071
|
-
|
|
19156
|
+
const existingCleanup = result.steps.cleanup;
|
|
19157
|
+
if (existingCleanup) {
|
|
19158
|
+
existingCleanup.message += ", worktree cleaned up";
|
|
19159
|
+
existingCleanup.details = {
|
|
19160
|
+
...existingCleanup.details,
|
|
19161
|
+
cleanedAfterSuccess: true
|
|
19162
|
+
};
|
|
19163
|
+
}
|
|
19072
19164
|
const transactionCount = context.result.steps.import?.details?.summary?.totalTransactions || 0;
|
|
19073
19165
|
return buildSuccessResult5(result, `Successfully imported ${transactionCount} transaction(s)`);
|
|
19074
19166
|
} catch (error45) {
|
|
19075
|
-
result.steps.cleanup = buildStepResult(true, "Worktree cleaned up after failure
|
|
19167
|
+
result.steps.cleanup = buildStepResult(true, "Worktree cleaned up after failure (CSV files preserved for retry)", {
|
|
19168
|
+
cleanedAfterFailure: true,
|
|
19169
|
+
csvCleanup: { deleted: [] }
|
|
19170
|
+
});
|
|
19076
19171
|
if (error45 instanceof NoTransactionsError) {
|
|
19077
19172
|
return handleNoTransactions(result);
|
|
19078
19173
|
}
|
package/package.json
CHANGED