plasalid 0.6.4 → 0.6.7

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 CHANGED
@@ -15,9 +15,9 @@
15
15
 
16
16
  <br />
17
17
 
18
- A unified view of personal financial data is critical. In the US and EU, a financial data aggregator like Plaid empowers most finance apps: one connection, and every app sees the same unified view of your accounts. Most of the world doesn't have that, including Thailand, where there's no such aggregator. All bank data is siloed: knowing where your financial status stands means logging into five bank apps one by one and with such a steep learning curve, most people just don't bother.
18
+ In the US/EU, a financial data aggregator like Plaid empowers most finance apps: one connection, and every app sees the same unified view of your accounts. Most of the world doesn't have that, including Thailand, where there's no such aggregator platform. All bank data is siloed: to know where your financial status stands means logging into five bank apps one by one. Creating a unified view of personal financial data is very challenging.
19
19
 
20
- Your data has stayed fragmented for decades. That's why Plasalid emerged to resolve this painpoint. Without a way to bring it together, personal finance remains hard to manage. You can't manage a mortgage effectively without the full picture, and you may be completely blind to your recurring monthly income and expenses. Subscriptions stay active long after they're forgotten, unknown charges go unverified, bank accounts opened years ago drift unchecked, and unexpected spending may silently grow beyond what any single statement shows. When your finances are hard to manage, your life definitely gets harder. Your plans toward financial stability or freedom slip further out of reach.
20
+ That's why Plasalid emerged to resolve this pain point. Your data has stayed fragmented for decades, with no way to bring it together. You can't manage a mortgage effectively without the full picture, and you may be completely blind to your recurring monthly income and expenses. Subscriptions stay active long after they're forgotten, unknown charges go unverified, bank accounts opened years ago drift unchecked, and unexpected spending may silently grow beyond what any single statement shows. When your finances are hard to manage, your life definitely becomes more difficult. Your plans toward financial stability or freedom slip further out of reach. Plasalid is built to solve this.
21
21
 
22
22
  Plasalid addresses this with a simple founding concept: let users drop all their financial documents — bank statements, credit-card statements, payslips, brokerage statements — onto their own machine, where Plasalid leverages AI to extract every transaction, balance, and holding into a single, structured, double-entry database that serves as context for future processing.
23
23
 
@@ -21,3 +21,4 @@ export declare function getMemories(db: Database.Database): Memory[];
21
21
  * tells it not to save what's already in the loaded memories.
22
22
  */
23
23
  export declare function saveMemory(db: Database.Database, content: string, category?: string): void;
24
+ export declare function deleteMemory(db: Database.Database, id: number): Memory | null;
package/dist/ai/memory.js CHANGED
@@ -22,3 +22,12 @@ export function saveMemory(db, content, category = "general") {
22
22
  return;
23
23
  db.prepare(`INSERT INTO memories (content, category) VALUES (?, ?)`).run(content, category);
24
24
  }
25
+ export function deleteMemory(db, id) {
26
+ const row = db
27
+ .prepare(`SELECT id, content, category, created_at FROM memories WHERE id = ?`)
28
+ .get(id);
29
+ if (!row)
30
+ return null;
31
+ db.prepare(`DELETE FROM memories WHERE id = ?`).run(id);
32
+ return row;
33
+ }
@@ -54,11 +54,15 @@ Rules:
54
54
  5. **Merchants are first-class.** Every transaction with an external counter-party (a charge to a store, a payment to a service, a refund from a vendor) must include a \`merchant\` block on \`record_transaction\`:
55
55
  - \`canonical_name\`: Title-cased name (e.g. \`"Starbucks"\`, \`"Amazon"\`, \`"Spotify"\`). Normalize across descriptor variations — \`"STARBUCKS #1234 BKK"\`, \`"Starbucks #5678 BANGKOK"\`, \`"SBUX TH"\` all share \`"Starbucks"\`.
56
56
  - \`alias\`: the exact raw statement descriptor. Plasalid normalizes and dedups it.
57
- - \`default_account_id\`: when categorization is confident on first sight, set this to the matching expense account (e.g. \`expense:food:dining\` for Starbucks). The next scan that sees the same merchant will skip re-asking the LLM.
57
+ - \`default_account_id\`: **do not** set this on first sight, even when you're confident. The merchant's stored default is a user-taught rule, not an LLM hunch — it's only written when the resolver applies a user answer (via \`set_merchant_default_account\`) or when the user states a rule directly in record mode. Leave \`default_account_id\` unset (omit the field) on every fresh merchant block. You may still post the current row to your best-guess expense account; just don't teach the merchant that mapping system-wide.
58
58
  Also set \`raw_descriptor\` on the transaction to the exact statement line for downstream lookups.
59
59
  For transfers between own accounts and pure balance movements, omit the merchant block.
60
60
  6. **Pre-resolved merchants.** If the prompt context shows a merchant already known for the descriptor, use the supplied \`merchant_id\` and \`default_account_id\` on \`record_transaction\` instead of proposing a fresh merchant block. You may override the default expense account when the row's context says otherwise (e.g. a Starbucks gift-card top-up is not Dining).
61
- 7. **Suspense fallback.** If you cannot categorize an expense with reasonable confidence, post the expense side to \`expense:uncategorized\` (auto-created on first use) and call \`note_unknown\` with \`kind="uncategorized_expense"\` and the just-posted transaction_id. Do **not** invent a category. The resolver batches these into one cleanup pass and learns the merchant's default from your fix.
61
+ 7. **Suspense fallback (expense and income).** If you cannot categorize a posting with reasonable confidence:
62
+ - For an expense (debit on an expense account): post the expense side to \`expense:uncategorized\` (auto-created), and call \`note_unknown\` with \`kind="uncategorized_expense"\` and the just-posted \`transaction_id\`.
63
+ - For an income (credit on an income account where the subtype — salary, bonus, freelance, interest, dividend, refund — isn't obvious): post the credit to \`income:uncategorized\` (auto-created) and call \`note_unknown\` with \`kind="uncategorized"\` and the \`transaction_id\`. Do not pick \`income:other\` or any subtype as a guess.
64
+
65
+ Do **not** invent a category in either direction. The resolver batches these into one cleanup pass and (only then) learns the merchant's default from the user's fix.
62
66
  8. Dates: convert Buddhist Era → Gregorian by subtracting 543 from the year. Store as YYYY-MM-DD.
63
67
  9. Default currency is THB. Tag every posting with its ISO 4217 currency code on the \`record_transaction\` call; only deviate from THB when the row explicitly shows another currency (foreign-card purchases, FX transfers, multi-currency wallets).
64
68
  10. Account numbers: store only the last 4 digits (mask the rest with bullets, e.g. \`••1234\`). Never persist the full account number.
@@ -148,7 +152,7 @@ Inputs you receive:
148
152
 
149
153
  The workflow is five steps. Do them in order. Do not skip step 1.
150
154
 
151
- **Step 1 — Survey (no tool calls).** Read the entire unknown list. Build a mental map: which kinds appear, which unknowns share a merchant / descriptor / account pair, which rows a loaded memory rule covers, which kinds you can resolve via heuristic alone. The goal is to know the whole shape before mutating anything.
155
+ **Step 1 — Survey.** Read the entire unknown list. Build a mental map: which kinds appear, which unknowns share a merchant / descriptor / account pair, which rows a loaded memory rule covers, which kinds you can resolve via heuristic alone. The goal is to know the whole shape before mutating anything.
152
156
 
153
157
  **Step 2 — Apply memory-driven silent resolutions.** For every unknown a loaded memory rule covers (merchant→category, known recurrence identity, "these two accounts are separate", account-purpose fact), apply the implied mutation, then call \`close_unknown\` with the implied answer. Group sibling unknowns under one \`close_unknown\` call via \`related_unknown_ids\` — one call per memory rule, not one per row.
154
158
 
@@ -156,7 +160,7 @@ The workflow is five steps. Do them in order. Do not skip step 1.
156
160
  - kind=\`duplicate\` — if the two transactions share the same merchant on the same date in the same file, default "Keep both" silently. (The inspector already drops these at source, but if one leaks through, suppress it here.)
157
161
  - kind=\`correlation\` — if both sides are already linked to a recurrence, default "Keep separate" silently (recurring transfers aren't duplicates).
158
162
  - kind=\`recurrence_candidate\` — if a memory rule names the recurrence (e.g. "Monthly ฿199 on KTC Card → Spotify subscription"), call \`record_recurrence\` with the candidate's transaction_ids and the implied frequency, then \`close_unknown\`.
159
- - kind=\`uncategorized\` / \`uncategorized_expense\` — if the transaction's merchant already has a default_account_id set, apply that category via \`update_posting\` and \`close_unknown\`. No need to re-ask.
163
+ - kind=\`uncategorized\` / \`uncategorized_expense\` — if the transaction's merchant already has a \`default_account_id\` set, apply that category via \`update_posting\` and \`close_unknown\`. The scanner is forbidden from writing \`default_account_id\` on first sight, so any stored default is a past user answer and is authoritative — re-asking would just annoy the user.
160
164
  - kind=\`similar_accounts\` — if the two names differ only in casing/whitespace, that's a high-confidence merge; still group with a single \`ask_user\` (don't auto-merge without confirmation, but ask only once).
161
165
 
162
166
  In each case, call \`close_unknown\` with the implied answer and \`related_unknown_ids\` if any siblings share that answer.
@@ -0,0 +1,16 @@
1
+ import type Database from "libsql";
2
+ export interface ForgetMatch {
3
+ displayId: string;
4
+ text: string;
5
+ }
6
+ export type ForgetOutcome = {
7
+ ok: true;
8
+ matched: ForgetMatch[];
9
+ } | {
10
+ ok: false;
11
+ error: string;
12
+ };
13
+ export declare function renderRules(db: Database.Database): string;
14
+ export declare function forgetRules(db: Database.Database, pattern: string): ForgetOutcome;
15
+ export declare function showRules(): void;
16
+ export declare function forgetRule(pattern: string): void;
@@ -0,0 +1,79 @@
1
+ import chalk from "chalk";
2
+ import { getDb } from "../../db/connection.js";
3
+ import { getMemories, deleteMemory } from "../../ai/memory.js";
4
+ import { listMerchants, clearMerchantDefaultAccount, } from "../../db/queries/merchants.js";
5
+ function collectRules(db) {
6
+ const out = [];
7
+ for (const m of getMemories(db)) {
8
+ out.push({
9
+ displayId: `mem:${m.id}`,
10
+ text: m.content,
11
+ forget: (db) => {
12
+ deleteMemory(db, m.id);
13
+ },
14
+ });
15
+ }
16
+ const merchants = listMerchants(db, { withDefaultOnly: true });
17
+ merchants.forEach((m, i) => {
18
+ out.push({
19
+ displayId: `mch:${i + 1}`,
20
+ text: `${m.canonical_name} → ${m.default_account_id}`,
21
+ forget: (db) => {
22
+ clearMerchantDefaultAccount(db, m.id);
23
+ },
24
+ });
25
+ });
26
+ return out;
27
+ }
28
+ export function renderRules(db) {
29
+ const rules = collectRules(db);
30
+ if (rules.length === 0) {
31
+ return ("No rules yet.\n\n" +
32
+ chalk.dim("Rules accumulate as you resolve unknowns. Run `plasalid resolve` after a scan."));
33
+ }
34
+ const width = Math.max(...rules.map((r) => r.displayId.length));
35
+ const lines = [chalk.bold(`Rules (${rules.length}):`)];
36
+ for (const r of rules) {
37
+ lines.push(` ${chalk.cyan(r.displayId.padEnd(width))} ${r.text}`);
38
+ }
39
+ lines.push("");
40
+ lines.push(chalk.dim("To remove: plasalid forget <regex>"));
41
+ return lines.join("\n");
42
+ }
43
+ export function forgetRules(db, pattern) {
44
+ let re;
45
+ try {
46
+ re = new RegExp(`^${pattern}$`);
47
+ }
48
+ catch (err) {
49
+ return { ok: false, error: `Invalid regex /${pattern}/: ${err.message}` };
50
+ }
51
+ const snapshot = collectRules(db);
52
+ const hits = snapshot.filter((r) => re.test(r.displayId));
53
+ if (!hits.length) {
54
+ return {
55
+ ok: false,
56
+ error: `No rule matches /${pattern}/. Run \`plasalid rules\` to list ids.`,
57
+ };
58
+ }
59
+ const matched = hits.map((r) => {
60
+ r.forget(db);
61
+ return { displayId: r.displayId, text: r.text };
62
+ });
63
+ return { ok: true, matched };
64
+ }
65
+ export function showRules() {
66
+ console.log(renderRules(getDb()));
67
+ }
68
+ export function forgetRule(pattern) {
69
+ const outcome = forgetRules(getDb(), pattern);
70
+ if (!outcome.ok) {
71
+ console.error(chalk.red(outcome.error));
72
+ process.exitCode = 1;
73
+ return;
74
+ }
75
+ const width = Math.max(...outcome.matched.map((m) => m.displayId.length));
76
+ for (const m of outcome.matched) {
77
+ console.log(`Forgot ${chalk.cyan(m.displayId.padEnd(width))} ${m.text}`);
78
+ }
79
+ }
package/dist/cli/index.js CHANGED
@@ -131,6 +131,22 @@ program
131
131
  kind: opts.kind,
132
132
  });
133
133
  });
134
+ program
135
+ .command("rules")
136
+ .description("List rules the system has learned")
137
+ .action(async () => {
138
+ ensureConfigured();
139
+ const { showRules } = await import("./commands/rules.js");
140
+ showRules();
141
+ });
142
+ program
143
+ .command("forget <regex>")
144
+ .description("Delete every learned rule whose id matches <regex> (anchored). Run `plasalid rules` to list ids.")
145
+ .action(async (regex) => {
146
+ ensureConfigured();
147
+ const { forgetRule } = await import("./commands/rules.js");
148
+ forgetRule(regex);
149
+ });
134
150
  program
135
151
  .command("revert <regex>")
136
152
  .description("Delete scanned files matching <regex> and all their transactions")
@@ -167,6 +183,14 @@ program.configureHelp({
167
183
  name: "resolve",
168
184
  desc: "Walk open unknowns one at a time and apply your decision",
169
185
  },
186
+ {
187
+ name: "rules",
188
+ desc: "List rules the system has learned",
189
+ },
190
+ {
191
+ name: "forget",
192
+ desc: "Delete learned rules whose ids match <regex> (anchored)",
193
+ },
170
194
  {
171
195
  name: "revert",
172
196
  desc: "Delete scanned files matching <regex> and their transactions",
@@ -40,3 +40,6 @@ export declare function setMerchantDefaultAccount(db: Database.Database, merchan
40
40
  before: string | null;
41
41
  after: string;
42
42
  };
43
+ export declare function clearMerchantDefaultAccount(db: Database.Database, merchantId: string): {
44
+ before: string | null;
45
+ } | null;
@@ -118,3 +118,12 @@ export function setMerchantDefaultAccount(db, merchantId, accountId) {
118
118
  .run(accountId, merchantId);
119
119
  return { before: before.default_account_id, after: accountId };
120
120
  }
121
+ export function clearMerchantDefaultAccount(db, merchantId) {
122
+ const row = db
123
+ .prepare(`SELECT default_account_id FROM merchants WHERE id = ?`)
124
+ .get(merchantId);
125
+ if (!row)
126
+ return null;
127
+ db.prepare(`UPDATE merchants SET default_account_id = NULL WHERE id = ?`).run(merchantId);
128
+ return { before: row.default_account_id };
129
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plasalid",
3
- "version": "0.6.4",
3
+ "version": "0.6.7",
4
4
  "description": "Plasalid — The Harness Layer for Personal Finance",
5
5
  "keywords": [
6
6
  "finance",