@fuzzle/opencode-accountant 0.0.15 → 0.0.16-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/dist/index.js +32 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17701,6 +17701,20 @@ function extractTransactionYears(hledgerOutput) {
|
|
|
17701
17701
|
}
|
|
17702
17702
|
return years;
|
|
17703
17703
|
}
|
|
17704
|
+
async function validateLedger(mainJournalPath, executor = defaultHledgerExecutor) {
|
|
17705
|
+
const errors3 = [];
|
|
17706
|
+
const checkResult = await executor(["check", "--strict", "-f", mainJournalPath]);
|
|
17707
|
+
if (checkResult.exitCode !== 0) {
|
|
17708
|
+
const errorMsg = checkResult.stderr.trim() || checkResult.stdout.trim();
|
|
17709
|
+
errors3.push(`hledger check --strict failed: ${errorMsg}`);
|
|
17710
|
+
}
|
|
17711
|
+
const balResult = await executor(["bal", "-f", mainJournalPath]);
|
|
17712
|
+
if (balResult.exitCode !== 0) {
|
|
17713
|
+
const errorMsg = balResult.stderr.trim() || balResult.stdout.trim();
|
|
17714
|
+
errors3.push(`hledger bal failed: ${errorMsg}`);
|
|
17715
|
+
}
|
|
17716
|
+
return { valid: errors3.length === 0, errors: errors3 };
|
|
17717
|
+
}
|
|
17704
17718
|
|
|
17705
17719
|
// src/utils/rulesParser.ts
|
|
17706
17720
|
function parseSkipRows(rulesContent) {
|
|
@@ -18198,6 +18212,24 @@ async function importStatementsCore(directory, agent, options, configLoader = lo
|
|
|
18198
18212
|
}
|
|
18199
18213
|
importedFiles.push(csvFile);
|
|
18200
18214
|
}
|
|
18215
|
+
const mainJournalPath = path6.join(directory, ".hledger.journal");
|
|
18216
|
+
const validationResult = await validateLedger(mainJournalPath, hledgerExecutor);
|
|
18217
|
+
if (!validationResult.valid) {
|
|
18218
|
+
return JSON.stringify({
|
|
18219
|
+
success: false,
|
|
18220
|
+
files: fileResults,
|
|
18221
|
+
summary: {
|
|
18222
|
+
filesProcessed: csvFiles.length,
|
|
18223
|
+
filesWithErrors: 1,
|
|
18224
|
+
filesWithoutRules,
|
|
18225
|
+
totalTransactions,
|
|
18226
|
+
matched: totalMatched,
|
|
18227
|
+
unknown: totalUnknown
|
|
18228
|
+
},
|
|
18229
|
+
error: `Ledger validation failed after import: ${validationResult.errors.join("; ")}`,
|
|
18230
|
+
hint: "The import created invalid transactions. Check your rules file configuration (e.g., balance vs balance2 for balance assertions). CSV files have NOT been moved to done."
|
|
18231
|
+
});
|
|
18232
|
+
}
|
|
18201
18233
|
for (const csvFile of importedFiles) {
|
|
18202
18234
|
const relativePath = path6.relative(pendingDir, csvFile);
|
|
18203
18235
|
const destPath = path6.join(doneDir, relativePath);
|