@fuzzle/opencode-accountant 0.5.0-next.1 → 0.5.1-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 +26 -38
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17079,9 +17079,6 @@ function buildPricehistArgs(startDate, endDate, currencyConfig) {
|
|
|
17079
17079
|
}
|
|
17080
17080
|
return cmdArgs;
|
|
17081
17081
|
}
|
|
17082
|
-
function buildErrorResult(error45) {
|
|
17083
|
-
return buildToolErrorResult(error45);
|
|
17084
|
-
}
|
|
17085
17082
|
function buildSuccessResult(results, endDate, backfill) {
|
|
17086
17083
|
return buildToolSuccessResult({
|
|
17087
17084
|
success: results.every((r) => !("error" in r)),
|
|
@@ -17116,7 +17113,7 @@ async function fetchCurrencyPrices(directory, agent, backfill, priceFetcher = de
|
|
|
17116
17113
|
config2 = configLoader(directory);
|
|
17117
17114
|
} catch (err) {
|
|
17118
17115
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
17119
|
-
return
|
|
17116
|
+
return buildToolErrorResult(errorMessage);
|
|
17120
17117
|
}
|
|
17121
17118
|
const endDate = getYesterday();
|
|
17122
17119
|
const defaultBackfillDate = getDefaultBackfillDate();
|
|
@@ -17433,9 +17430,6 @@ import { randomUUID } from "crypto";
|
|
|
17433
17430
|
function getContextPath(directory, contextId) {
|
|
17434
17431
|
return path5.join(directory, ".memory", `${contextId}.json`);
|
|
17435
17432
|
}
|
|
17436
|
-
function ensureMemoryDir(directory) {
|
|
17437
|
-
ensureDirectory(path5.join(directory, ".memory"));
|
|
17438
|
-
}
|
|
17439
17433
|
function createContext(directory, params) {
|
|
17440
17434
|
const now = new Date().toISOString();
|
|
17441
17435
|
const context = {
|
|
@@ -17454,7 +17448,7 @@ function createContext(directory, params) {
|
|
|
17454
17448
|
closingBalance: params.closingBalance,
|
|
17455
17449
|
account: params.account
|
|
17456
17450
|
};
|
|
17457
|
-
|
|
17451
|
+
ensureDirectory(path5.join(directory, ".memory"));
|
|
17458
17452
|
const contextPath = getContextPath(directory, context.id);
|
|
17459
17453
|
fs5.writeFileSync(contextPath, JSON.stringify(context, null, 2), "utf-8");
|
|
17460
17454
|
return context;
|
|
@@ -17515,20 +17509,6 @@ function buildSuccessResult2(classified, unrecognized, message) {
|
|
|
17515
17509
|
}
|
|
17516
17510
|
});
|
|
17517
17511
|
}
|
|
17518
|
-
function buildErrorResult2(error45, hint) {
|
|
17519
|
-
return buildToolErrorResult(error45, hint, {
|
|
17520
|
-
classified: [],
|
|
17521
|
-
unrecognized: []
|
|
17522
|
-
});
|
|
17523
|
-
}
|
|
17524
|
-
function buildCollisionError(collisions) {
|
|
17525
|
-
const error45 = `Cannot classify: ${collisions.length} file(s) would overwrite existing pending files.`;
|
|
17526
|
-
return buildToolErrorResult(error45, undefined, {
|
|
17527
|
-
collisions,
|
|
17528
|
-
classified: [],
|
|
17529
|
-
unrecognized: []
|
|
17530
|
-
});
|
|
17531
|
-
}
|
|
17532
17512
|
function planMoves(csvFiles, importsDir, pendingDir, unrecognizedDir, config2) {
|
|
17533
17513
|
const plannedMoves = [];
|
|
17534
17514
|
const collisions = [];
|
|
@@ -17629,7 +17609,10 @@ async function classifyStatements(directory, agent, configLoader = loadImportCon
|
|
|
17629
17609
|
config2 = configLoader(directory);
|
|
17630
17610
|
} catch (err) {
|
|
17631
17611
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
17632
|
-
return
|
|
17612
|
+
return buildToolErrorResult(errorMessage, undefined, {
|
|
17613
|
+
classified: [],
|
|
17614
|
+
unrecognized: []
|
|
17615
|
+
});
|
|
17633
17616
|
}
|
|
17634
17617
|
const importsDir = path6.join(directory, config2.paths.import);
|
|
17635
17618
|
const pendingDir = path6.join(directory, config2.paths.pending);
|
|
@@ -17640,7 +17623,12 @@ async function classifyStatements(directory, agent, configLoader = loadImportCon
|
|
|
17640
17623
|
}
|
|
17641
17624
|
const { plannedMoves, collisions } = planMoves(csvFiles, importsDir, pendingDir, unrecognizedDir, config2);
|
|
17642
17625
|
if (collisions.length > 0) {
|
|
17643
|
-
|
|
17626
|
+
const error45 = `Cannot classify: ${collisions.length} file(s) would overwrite existing pending files.`;
|
|
17627
|
+
return buildToolErrorResult(error45, undefined, {
|
|
17628
|
+
collisions,
|
|
17629
|
+
classified: [],
|
|
17630
|
+
unrecognized: []
|
|
17631
|
+
});
|
|
17644
17632
|
}
|
|
17645
17633
|
const { classified, unrecognized } = executeMoves(plannedMoves, config2, unrecognizedDir, directory);
|
|
17646
17634
|
return buildSuccessResult2(classified, unrecognized);
|
|
@@ -23426,7 +23414,7 @@ function findMatchingCsvRow(posting, csvRows, config2) {
|
|
|
23426
23414
|
}
|
|
23427
23415
|
|
|
23428
23416
|
// src/tools/import-statements.ts
|
|
23429
|
-
function
|
|
23417
|
+
function buildErrorResult(error45, hint) {
|
|
23430
23418
|
return buildToolErrorResult(error45, hint, {
|
|
23431
23419
|
files: [],
|
|
23432
23420
|
summary: {
|
|
@@ -23597,7 +23585,7 @@ async function importStatements(directory, agent, options, configLoader = loadIm
|
|
|
23597
23585
|
config2 = configLoader(directory);
|
|
23598
23586
|
} catch (error45) {
|
|
23599
23587
|
const errorMessage = `Failed to load configuration: ${error45 instanceof Error ? error45.message : String(error45)}`;
|
|
23600
|
-
return
|
|
23588
|
+
return buildErrorResult(errorMessage, 'Ensure config/import/providers.yaml exists with required paths including "rules"');
|
|
23601
23589
|
}
|
|
23602
23590
|
const pendingDir = path9.join(directory, config2.paths.pending);
|
|
23603
23591
|
const rulesDir = path9.join(directory, config2.paths.rules);
|
|
@@ -23606,7 +23594,7 @@ async function importStatements(directory, agent, options, configLoader = loadIm
|
|
|
23606
23594
|
const importContext = loadContext(directory, options.contextId);
|
|
23607
23595
|
const csvPath = path9.join(directory, importContext.filePath);
|
|
23608
23596
|
if (!fs10.existsSync(csvPath)) {
|
|
23609
|
-
return
|
|
23597
|
+
return buildErrorResult(`CSV file not found: ${importContext.filePath}`, "The file may have been moved or deleted");
|
|
23610
23598
|
}
|
|
23611
23599
|
const csvFiles = [csvPath];
|
|
23612
23600
|
const fileResults = [];
|
|
@@ -23758,7 +23746,7 @@ Note: This tool is typically called via import-pipeline for the full workflow.`,
|
|
|
23758
23746
|
// src/tools/reconcile-statement.ts
|
|
23759
23747
|
import * as fs11 from "fs";
|
|
23760
23748
|
import * as path10 from "path";
|
|
23761
|
-
function
|
|
23749
|
+
function buildErrorResult2(params) {
|
|
23762
23750
|
return buildToolErrorResult(params.error, params.hint, {
|
|
23763
23751
|
account: params.account ?? "",
|
|
23764
23752
|
expectedBalance: params.expectedBalance ?? "",
|
|
@@ -23775,7 +23763,7 @@ function loadConfiguration(directory, configLoader) {
|
|
|
23775
23763
|
return { config: config2 };
|
|
23776
23764
|
} catch (error45) {
|
|
23777
23765
|
return {
|
|
23778
|
-
error:
|
|
23766
|
+
error: buildErrorResult2({
|
|
23779
23767
|
error: `Failed to load configuration: ${error45 instanceof Error ? error45.message : String(error45)}`,
|
|
23780
23768
|
hint: "Ensure config/import/providers.yaml exists"
|
|
23781
23769
|
})
|
|
@@ -23786,7 +23774,7 @@ function verifyCsvExists(directory, importContext) {
|
|
|
23786
23774
|
const csvFile = path10.join(directory, importContext.filePath);
|
|
23787
23775
|
if (!fs11.existsSync(csvFile)) {
|
|
23788
23776
|
return {
|
|
23789
|
-
error:
|
|
23777
|
+
error: buildErrorResult2({
|
|
23790
23778
|
error: `CSV file not found: ${importContext.filePath}`,
|
|
23791
23779
|
hint: `The file may have been moved or deleted. Context ID: ${importContext.id}`
|
|
23792
23780
|
})
|
|
@@ -23853,7 +23841,7 @@ function determineClosingBalance(csvFile, config2, importContext, manualClosingB
|
|
|
23853
23841
|
const exampleBalance = `${currency} <amount>`;
|
|
23854
23842
|
const retryCmd = buildRetryCommand(importContext.id, exampleBalance);
|
|
23855
23843
|
return {
|
|
23856
|
-
error:
|
|
23844
|
+
error: buildErrorResult2({
|
|
23857
23845
|
csvFile: relativeCsvPath,
|
|
23858
23846
|
error: "No closing balance found in CSV metadata or data",
|
|
23859
23847
|
hint: `Provide closingBalance parameter manually. Example retry: ${retryCmd}`,
|
|
@@ -23883,7 +23871,7 @@ function determineAccount(csvFile, rulesDir, importContext, manualAccount, relat
|
|
|
23883
23871
|
if (!account) {
|
|
23884
23872
|
const rulesHint = rulesFile ? `Add 'account1 assets:bank:...' to ${rulesFile} or retry with: ${buildRetryCommand(importContext.id, undefined, "assets:bank:...")}` : `Create a rules file in ${rulesDir} with 'account1' directive or retry with: ${buildRetryCommand(importContext.id, undefined, "assets:bank:...")}`;
|
|
23885
23873
|
return {
|
|
23886
|
-
error:
|
|
23874
|
+
error: buildErrorResult2({
|
|
23887
23875
|
csvFile: relativeCsvPath,
|
|
23888
23876
|
error: "Could not determine account from rules file",
|
|
23889
23877
|
hint: rulesHint,
|
|
@@ -23966,7 +23954,7 @@ async function reconcileStatement(directory, agent, options, configLoader = load
|
|
|
23966
23954
|
try {
|
|
23967
23955
|
importContext = loadContext(directory, options.contextId);
|
|
23968
23956
|
} catch {
|
|
23969
|
-
return
|
|
23957
|
+
return buildErrorResult2({
|
|
23970
23958
|
error: `Failed to load import context: ${options.contextId}`,
|
|
23971
23959
|
hint: "Ensure the context ID is valid and the context file exists in .memory/"
|
|
23972
23960
|
});
|
|
@@ -23995,7 +23983,7 @@ async function reconcileStatement(directory, agent, options, configLoader = load
|
|
|
23995
23983
|
const { account } = accountResult;
|
|
23996
23984
|
const lastTransactionDate = await getLastTransactionDate(mainJournalPath, account, hledgerExecutor);
|
|
23997
23985
|
if (!lastTransactionDate) {
|
|
23998
|
-
return
|
|
23986
|
+
return buildErrorResult2({
|
|
23999
23987
|
csvFile: relativeCsvPath,
|
|
24000
23988
|
account,
|
|
24001
23989
|
error: "No transactions found for account",
|
|
@@ -24005,7 +23993,7 @@ async function reconcileStatement(directory, agent, options, configLoader = load
|
|
|
24005
23993
|
}
|
|
24006
23994
|
const actualBalance = await getAccountBalance(mainJournalPath, account, lastTransactionDate, hledgerExecutor);
|
|
24007
23995
|
if (actualBalance === null) {
|
|
24008
|
-
return
|
|
23996
|
+
return buildErrorResult2({
|
|
24009
23997
|
csvFile: relativeCsvPath,
|
|
24010
23998
|
account,
|
|
24011
23999
|
lastTransactionDate,
|
|
@@ -24018,7 +24006,7 @@ async function reconcileStatement(directory, agent, options, configLoader = load
|
|
|
24018
24006
|
try {
|
|
24019
24007
|
doBalancesMatch = balancesMatch(closingBalance, actualBalance);
|
|
24020
24008
|
} catch (error45) {
|
|
24021
|
-
return
|
|
24009
|
+
return buildErrorResult2({
|
|
24022
24010
|
csvFile: relativeCsvPath,
|
|
24023
24011
|
account,
|
|
24024
24012
|
lastTransactionDate,
|
|
@@ -24047,7 +24035,7 @@ async function reconcileStatement(directory, agent, options, configLoader = load
|
|
|
24047
24035
|
try {
|
|
24048
24036
|
difference = calculateDifference(closingBalance, actualBalance);
|
|
24049
24037
|
} catch (error45) {
|
|
24050
|
-
return
|
|
24038
|
+
return buildErrorResult2({
|
|
24051
24039
|
csvFile: relativeCsvPath,
|
|
24052
24040
|
account,
|
|
24053
24041
|
lastTransactionDate,
|
|
@@ -24057,7 +24045,7 @@ async function reconcileStatement(directory, agent, options, configLoader = load
|
|
|
24057
24045
|
metadata
|
|
24058
24046
|
});
|
|
24059
24047
|
}
|
|
24060
|
-
return
|
|
24048
|
+
return buildErrorResult2({
|
|
24061
24049
|
csvFile: relativeCsvPath,
|
|
24062
24050
|
account,
|
|
24063
24051
|
lastTransactionDate,
|
package/package.json
CHANGED