plasalid 0.4.1 → 0.5.0

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 (65) hide show
  1. package/README.md +15 -14
  2. package/dist/ai/agent.d.ts +15 -2
  3. package/dist/ai/agent.js +21 -2
  4. package/dist/ai/memory.d.ts +2 -0
  5. package/dist/ai/memory.js +2 -2
  6. package/dist/ai/personas.d.ts +2 -1
  7. package/dist/ai/personas.js +115 -45
  8. package/dist/ai/prompt-sections.d.ts +5 -0
  9. package/dist/ai/prompt-sections.js +26 -8
  10. package/dist/ai/system-prompt.d.ts +11 -0
  11. package/dist/ai/system-prompt.js +21 -6
  12. package/dist/ai/thinking.js +1 -1
  13. package/dist/ai/tools/common.js +2 -5
  14. package/dist/ai/tools/index.js +28 -8
  15. package/dist/ai/tools/ingest.d.ts +2 -1
  16. package/dist/ai/tools/ingest.js +262 -151
  17. package/dist/ai/tools/merchants.d.ts +2 -0
  18. package/dist/ai/tools/merchants.js +117 -0
  19. package/dist/ai/tools/read.js +31 -29
  20. package/dist/ai/tools/record.d.ts +2 -0
  21. package/dist/ai/tools/record.js +188 -0
  22. package/dist/ai/tools/review.js +77 -80
  23. package/dist/ai/tools/scan.js +1 -1
  24. package/dist/ai/tools/types.d.ts +15 -6
  25. package/dist/cli/commands/accounts.js +33 -25
  26. package/dist/cli/commands/record.d.ts +4 -0
  27. package/dist/cli/commands/record.js +119 -0
  28. package/dist/cli/commands/revert.js +1 -1
  29. package/dist/cli/commands/scan.js +15 -19
  30. package/dist/cli/commands/status.js +6 -9
  31. package/dist/cli/commands/transactions.js +36 -41
  32. package/dist/cli/format.d.ts +2 -0
  33. package/dist/cli/format.js +7 -2
  34. package/dist/cli/index.js +19 -7
  35. package/dist/cli/ink/scan_dashboard.d.ts +1 -1
  36. package/dist/cli/ink/scan_dashboard.js +2 -2
  37. package/dist/cli/setup.d.ts +0 -1
  38. package/dist/cli/setup.js +2 -8
  39. package/dist/currency.d.ts +3 -0
  40. package/dist/currency.js +12 -1
  41. package/dist/db/queries/account_balance.d.ts +83 -4
  42. package/dist/db/queries/account_balance.js +239 -20
  43. package/dist/db/queries/action_log.d.ts +29 -0
  44. package/dist/db/queries/action_log.js +27 -0
  45. package/dist/db/queries/concerns.d.ts +10 -7
  46. package/dist/db/queries/concerns.js +20 -16
  47. package/dist/db/queries/journal.d.ts +1 -0
  48. package/dist/db/queries/merchants.d.ts +42 -0
  49. package/dist/db/queries/merchants.js +120 -0
  50. package/dist/db/queries/recurrences.d.ts +3 -3
  51. package/dist/db/queries/recurrences.js +32 -34
  52. package/dist/db/queries/search.d.ts +5 -4
  53. package/dist/db/queries/search.js +16 -12
  54. package/dist/db/queries/transactions.d.ts +167 -0
  55. package/dist/db/queries/transactions.js +320 -0
  56. package/dist/db/schema.js +51 -9
  57. package/dist/reviewer/pipeline.d.ts +4 -4
  58. package/dist/reviewer/pipeline.js +4 -4
  59. package/dist/reviewer/prompts.js +4 -4
  60. package/dist/scanner/buffer.d.ts +24 -21
  61. package/dist/scanner/buffer.js +18 -18
  62. package/dist/scanner/pipeline.d.ts +3 -2
  63. package/dist/scanner/pipeline.js +33 -36
  64. package/dist/scanner/prompts.js +3 -3
  65. package/package.json +2 -2
@@ -1,12 +1,15 @@
1
1
  import { config } from "../config.js";
2
2
  import { readContext } from "./context.js";
3
- import { chatPersona, SCAN_PERSONA, REVIEW_PERSONA } from "./personas.js";
3
+ import { chatPersona, SCAN_PERSONA, REVIEW_PERSONA, RECORD_PERSONA } from "./personas.js";
4
4
  import { getThaiTaxonomyHint } from "../accounts/taxonomy.js";
5
5
  import { renderChartOfAccounts, renderChatChartOrEmpty, renderMemories, renderScope, renderTodayHuman, renderTodayIso, renderUserContext, } from "./prompt-sections.js";
6
- // ── Builders ────────────────────────────────────────────────────────────────
7
- // Each builder is a list of sections in render order. No accumulation, no
8
- // inline string assembly. To edit a section, change the helper; to reorder,
9
- // shuffle the array.
6
+ /**
7
+ * Builders
8
+ *
9
+ * Each builder is a list of sections in render order. No accumulation, no
10
+ * inline string assembly. To edit a section, change the helper; to reorder,
11
+ * shuffle the array.
12
+ */
10
13
  export function buildChatSystemPrompt(db) {
11
14
  const name = config.userName;
12
15
  return joinSections([
@@ -32,6 +35,19 @@ export function buildReviewSystemPrompt(db, opts) {
32
35
  }),
33
36
  ]);
34
37
  }
38
+ export function buildRecordSystemPrompt(db, opts) {
39
+ return joinSections([
40
+ RECORD_PERSONA,
41
+ renderTodayIso(),
42
+ renderChartOfAccounts(db, { withBalance: true, emptyState: "scan" }),
43
+ `## What the user said\n> ${opts.utterance.replace(/\n/g, " ")}`,
44
+ renderMemories(db, {
45
+ header: "Rules you've already learned (apply silently)",
46
+ filterCategories: ["scanning_hint", "general", "preference"],
47
+ showCategory: false,
48
+ }),
49
+ ]);
50
+ }
35
51
  export function buildScanSystemPrompt(db, opts) {
36
52
  return joinSections([
37
53
  SCAN_PERSONA,
@@ -46,7 +62,6 @@ export function buildScanSystemPrompt(db, opts) {
46
62
  }),
47
63
  ]);
48
64
  }
49
- // ── Composition helper ─────────────────────────────────────────────────────
50
65
  /** Drop null/empty sections, join the rest with a blank line. */
51
66
  function joinSections(sections) {
52
67
  return sections.filter((s) => !!s).join("\n\n");
@@ -5,7 +5,7 @@
5
5
  */
6
6
  export const THINKING_PHRASES = [
7
7
  "Thinking...",
8
- "Looking through your journal...",
8
+ "Looking through your transactions...",
9
9
  "Checking your accounts...",
10
10
  "Crunching the numbers...",
11
11
  "Pulling up your data...",
@@ -1,12 +1,9 @@
1
1
  import { saveMemory, getMemories } from "../memory.js";
2
2
  import { getAccountBalances } from "../../db/queries/account_balance.js";
3
- import { formatCurrencyAmount } from "../../currency.js";
3
+ import { formatAmount } from "../../currency.js";
4
4
  import { sanitizeForPrompt, sanitizeForPromptCell } from "../sanitize.js";
5
5
  import { ACCOUNT_TYPE_DESCRIPTIONS } from "../../accounts/taxonomy.js";
6
6
  const ACCOUNT_TYPES = Object.keys(ACCOUNT_TYPE_DESCRIPTIONS);
7
- function formatTHB(amount) {
8
- return formatCurrencyAmount(amount, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
9
- }
10
7
  const DEFS = [
11
8
  {
12
9
  name: "list_accounts",
@@ -60,7 +57,7 @@ async function execute(db, name, input, _ctx) {
60
57
  if (a.points_balance)
61
58
  meta.push(`${a.points_balance} pts`);
62
59
  const metaStr = meta.length ? ` [${meta.join(" · ")}]` : "";
63
- return `${a.id} | ${sanitizeForPromptCell(a.name)} | ${a.type}${a.subtype ? `/${a.subtype}` : ""} | balance ${formatTHB(a.balance)}${metaStr}`;
60
+ return `${a.id} | ${sanitizeForPromptCell(a.name)} | ${a.type}${a.subtype ? `/${a.subtype}` : ""} | balance ${formatAmount(a.balance)}${metaStr}`;
64
61
  })
65
62
  .join("\n");
66
63
  }
@@ -1,27 +1,44 @@
1
1
  import { commonTools } from "./common.js";
2
2
  import { readTools } from "./read.js";
3
- import { scanIngestTools, reviewIngestTools } from "./ingest.js";
3
+ import { accountIngestTools, scanConcernTools, reviewIngestTools } from "./ingest.js";
4
4
  import { scanTools } from "./scan.js";
5
5
  import { reviewTools } from "./review.js";
6
+ import { recordTools } from "./record.js";
7
+ import { merchantTools } from "./merchants.js";
6
8
  /**
7
9
  * Profile composition. Each profile is the union of one or more tool modules;
8
10
  * the dispatcher iterates every module on each tool call so we never need a
9
11
  * central switch.
10
12
  *
11
- * `scanIngestTools` (create_account / update_account_metadata /
12
- * record_journal_entry / note_concern) ships with both scan and reviewscan
13
- * uses them to post, review uses them to fix.
13
+ * `accountIngestTools` (create_account / update_account_metadata /
14
+ * record_transaction) ships with scan, review, and recordthey're the
15
+ * shared write primitives. `scanConcernTools` (note_concern) is scan-only;
16
+ * record uses `clarify` from `recordTools` for transient prompts, review uses
17
+ * `ask_user` from `reviewIngestTools` for resolve-in-place clarifications.
18
+ * `merchantTools` ships with scan, review, and record so any write profile can
19
+ * upsert / look up / re-cache merchants alongside the posting flow.
14
20
  */
15
21
  const PROFILES = {
16
- scan: [commonTools, scanIngestTools, scanTools],
22
+ scan: [commonTools, accountIngestTools, scanConcernTools, scanTools, merchantTools],
17
23
  chat: [commonTools, readTools],
18
- review: [commonTools, readTools, scanIngestTools, reviewIngestTools, reviewTools],
24
+ review: [commonTools, readTools, accountIngestTools, reviewIngestTools, reviewTools, merchantTools],
25
+ record: [commonTools, readTools, accountIngestTools, recordTools, merchantTools],
19
26
  };
20
27
  export function getToolDefinitions(profile) {
21
28
  return PROFILES[profile].flatMap(m => m.DEFS);
22
29
  }
23
30
  export async function executeTool(db, name, input, ctx) {
24
- for (const mod of [commonTools, readTools, scanIngestTools, reviewIngestTools, scanTools, reviewTools]) {
31
+ for (const mod of [
32
+ commonTools,
33
+ readTools,
34
+ accountIngestTools,
35
+ scanConcernTools,
36
+ reviewIngestTools,
37
+ scanTools,
38
+ reviewTools,
39
+ recordTools,
40
+ merchantTools,
41
+ ]) {
25
42
  const result = await mod.execute(db, name, input, ctx);
26
43
  if (result !== undefined)
27
44
  return result;
@@ -32,8 +49,11 @@ export async function executeTool(db, name, input, ctx) {
32
49
  export const TOOL_LABELS = {
33
50
  ...commonTools.LABELS,
34
51
  ...readTools.LABELS,
35
- ...scanIngestTools.LABELS,
52
+ ...accountIngestTools.LABELS,
53
+ ...scanConcernTools.LABELS,
36
54
  ...reviewIngestTools.LABELS,
37
55
  ...scanTools.LABELS,
38
56
  ...reviewTools.LABELS,
57
+ ...recordTools.LABELS,
58
+ ...merchantTools.LABELS,
39
59
  };
@@ -1,3 +1,4 @@
1
1
  import type { ToolModule } from "./types.js";
2
- export declare const scanIngestTools: ToolModule;
2
+ export declare const accountIngestTools: ToolModule;
3
+ export declare const scanConcernTools: ToolModule;
3
4
  export declare const reviewIngestTools: ToolModule;