@fuzzle/opencode-accountant 0.0.14 → 0.0.15-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.
Files changed (2) hide show
  1. package/dist/index.js +39 -1
  2. 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) {
@@ -17931,7 +17945,13 @@ function ensureYearJournalExists(directory, year) {
17931
17945
  }
17932
17946
  const mainJournalContent = fs7.readFileSync(mainJournalPath, "utf-8");
17933
17947
  const includeDirective = `include ledger/${year}.journal`;
17934
- if (!mainJournalContent.includes(includeDirective)) {
17948
+ const lines = mainJournalContent.split(`
17949
+ `);
17950
+ const includeExists = lines.some((line) => {
17951
+ const trimmed = line.trim();
17952
+ return trimmed === includeDirective || trimmed.startsWith(includeDirective + " ");
17953
+ });
17954
+ if (!includeExists) {
17935
17955
  const newContent = mainJournalContent.trimEnd() + `
17936
17956
  ` + includeDirective + `
17937
17957
  `;
@@ -18192,6 +18212,24 @@ async function importStatementsCore(directory, agent, options, configLoader = lo
18192
18212
  }
18193
18213
  importedFiles.push(csvFile);
18194
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
+ }
18195
18233
  for (const csvFile of importedFiles) {
18196
18234
  const relativePath = path6.relative(pendingDir, csvFile);
18197
18235
  const destPath = path6.join(doneDir, relativePath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fuzzle/opencode-accountant",
3
- "version": "0.0.14",
3
+ "version": "0.0.15-next.1",
4
4
  "description": "An OpenCode accounting agent, specialized in double-entry-bookkepping with hledger",
5
5
  "author": {
6
6
  "name": "ali bengali",