@fuzzle/opencode-accountant 0.10.7-next.1 → 0.10.8-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 +59 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2739,6 +2739,19 @@ var init_agentLoader = __esm(() => {
2739
2739
  ]);
2740
2740
  });
2741
2741
 
2742
+ // src/utils/journalMatchers.ts
2743
+ function extractAccount(line, pattern) {
2744
+ const match = line.match(pattern);
2745
+ return match ? match[1].trim() : null;
2746
+ }
2747
+ var JOURNAL_ACCOUNT_DECL, RULES_ACCOUNT_DIRECTIVE, RULES_ACCOUNT2_DIRECTIVE, TX_HEADER_PATTERN;
2748
+ var init_journalMatchers = __esm(() => {
2749
+ JOURNAL_ACCOUNT_DECL = /^account\s+(.+)$/;
2750
+ RULES_ACCOUNT_DIRECTIVE = /^account\d+\s+(.+)$/;
2751
+ RULES_ACCOUNT2_DIRECTIVE = /^\s*account2\s+(.+)$/;
2752
+ TX_HEADER_PATTERN = /^(\d{4})-(\d{2}-\d{2})(\s+(.+))?$/;
2753
+ });
2754
+
2742
2755
  // node_modules/papaparse/papaparse.js
2743
2756
  var require_papaparse = __commonJS((exports, module) => {
2744
2757
  (function(root, factory) {
@@ -4258,19 +4271,6 @@ var require_brace_expansion = __commonJS((exports, module) => {
4258
4271
  }
4259
4272
  });
4260
4273
 
4261
- // src/utils/journalMatchers.ts
4262
- function extractAccount(line, pattern) {
4263
- const match2 = line.match(pattern);
4264
- return match2 ? match2[1].trim() : null;
4265
- }
4266
- var JOURNAL_ACCOUNT_DECL, RULES_ACCOUNT_DIRECTIVE, RULES_ACCOUNT2_DIRECTIVE, TX_HEADER_PATTERN;
4267
- var init_journalMatchers = __esm(() => {
4268
- JOURNAL_ACCOUNT_DECL = /^account\s+(.+)$/;
4269
- RULES_ACCOUNT_DIRECTIVE = /^account\d+\s+(.+)$/;
4270
- RULES_ACCOUNT2_DIRECTIVE = /^\s*account2\s+(.+)$/;
4271
- TX_HEADER_PATTERN = /^(\d{4})-(\d{2}-\d{2})(\s+(.+))?$/;
4272
- });
4273
-
4274
4274
  // src/utils/accountSuggester.ts
4275
4275
  var exports_accountSuggester = {};
4276
4276
  __export(exports_accountSuggester, {
@@ -17012,6 +17012,7 @@ function ensureDirectory(dirPath) {
17012
17012
  }
17013
17013
 
17014
17014
  // src/utils/journalUtils.ts
17015
+ init_journalMatchers();
17015
17016
  function extractDateFromPriceLine(line) {
17016
17017
  return line.split(" ")[1];
17017
17018
  }
@@ -17097,6 +17098,37 @@ function ensureCommodityDeclarations(commodityJournalPath, symbols, logger) {
17097
17098
  logger?.info(`Commodity declarations: added ${missing.length} (${missing.join(", ")})`);
17098
17099
  return { added: missing.sort(), updated: true };
17099
17100
  }
17101
+ function ensureInvestmentAccountDeclarations(accountJournalPath, accounts, logger) {
17102
+ const existing = new Set;
17103
+ if (fs4.existsSync(accountJournalPath)) {
17104
+ const content2 = fs4.readFileSync(accountJournalPath, "utf-8");
17105
+ for (const line of content2.split(`
17106
+ `)) {
17107
+ const match = line.trim().match(JOURNAL_ACCOUNT_DECL);
17108
+ if (match) {
17109
+ existing.add(match[1]);
17110
+ }
17111
+ }
17112
+ }
17113
+ const missing = [];
17114
+ for (const account of accounts) {
17115
+ if (!existing.has(account)) {
17116
+ missing.push(account);
17117
+ existing.add(account);
17118
+ }
17119
+ }
17120
+ if (missing.length === 0) {
17121
+ return { added: [], updated: false };
17122
+ }
17123
+ const sorted = Array.from(existing).sort((a, b) => a.localeCompare(b));
17124
+ const content = sorted.map((a) => `account ${a}`).join(`
17125
+ `) + `
17126
+ `;
17127
+ ensureDirectory(path3.dirname(accountJournalPath));
17128
+ fs4.writeFileSync(accountJournalPath, content);
17129
+ logger?.info(`Account declarations: added ${missing.length} (${missing.join(", ")})`);
17130
+ return { added: missing.sort(), updated: true };
17131
+ }
17100
17132
 
17101
17133
  // src/utils/dateUtils.ts
17102
17134
  function formatDateISO(date5) {
@@ -25830,6 +25862,20 @@ async function preprocessSwissquote(csvPath, projectDir, currency, year, lotInve
25830
25862
  if (stockSymbols.size > 0) {
25831
25863
  const commodityJournalPath = path13.join(projectDir, "ledger", "investments", "commodities.journal");
25832
25864
  ensureCommodityDeclarations(commodityJournalPath, stockSymbols, logger);
25865
+ const accountJournalPath = path13.join(projectDir, "ledger", "investments", "accounts.journal");
25866
+ const investmentAccounts = new Set;
25867
+ for (const symbol2 of stockSymbols) {
25868
+ investmentAccounts.add(`assets:investments:stocks:${symbol2}`);
25869
+ investmentAccounts.add(`income:dividends:${symbol2}`);
25870
+ }
25871
+ investmentAccounts.add(`assets:broker:swissquote:${currency.toLowerCase()}`);
25872
+ investmentAccounts.add("expenses:fees:trading:swissquote");
25873
+ investmentAccounts.add("expenses:taxes:withholding");
25874
+ investmentAccounts.add("income:capital-gains:realized");
25875
+ investmentAccounts.add("income:capital-gains:rights-distribution");
25876
+ investmentAccounts.add("expenses:losses:capital");
25877
+ investmentAccounts.add("equity:conversion");
25878
+ ensureInvestmentAccountDeclarations(accountJournalPath, investmentAccounts, logger);
25833
25879
  }
25834
25880
  logger?.logResult({
25835
25881
  totalRows: stats.totalRows,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fuzzle/opencode-accountant",
3
- "version": "0.10.7-next.1",
3
+ "version": "0.10.8-next.1",
4
4
  "description": "An OpenCode accounting agent, specialized in double-entry-bookkepping with hledger",
5
5
  "author": {
6
6
  "name": "ali bengali",