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.
- package/README.md +15 -14
- package/dist/ai/agent.d.ts +15 -2
- package/dist/ai/agent.js +21 -2
- package/dist/ai/memory.d.ts +2 -0
- package/dist/ai/memory.js +2 -2
- package/dist/ai/personas.d.ts +2 -1
- package/dist/ai/personas.js +115 -45
- package/dist/ai/prompt-sections.d.ts +5 -0
- package/dist/ai/prompt-sections.js +26 -8
- package/dist/ai/system-prompt.d.ts +11 -0
- package/dist/ai/system-prompt.js +21 -6
- package/dist/ai/thinking.js +1 -1
- package/dist/ai/tools/common.js +2 -5
- package/dist/ai/tools/index.js +28 -8
- package/dist/ai/tools/ingest.d.ts +2 -1
- package/dist/ai/tools/ingest.js +262 -151
- package/dist/ai/tools/merchants.d.ts +2 -0
- package/dist/ai/tools/merchants.js +117 -0
- package/dist/ai/tools/read.js +31 -29
- package/dist/ai/tools/record.d.ts +2 -0
- package/dist/ai/tools/record.js +188 -0
- package/dist/ai/tools/review.js +77 -80
- package/dist/ai/tools/scan.js +1 -1
- package/dist/ai/tools/types.d.ts +15 -6
- package/dist/cli/commands/accounts.js +33 -25
- package/dist/cli/commands/record.d.ts +4 -0
- package/dist/cli/commands/record.js +119 -0
- package/dist/cli/commands/revert.js +1 -1
- package/dist/cli/commands/scan.js +15 -19
- package/dist/cli/commands/status.js +6 -9
- package/dist/cli/commands/transactions.js +36 -41
- package/dist/cli/format.d.ts +2 -0
- package/dist/cli/format.js +7 -2
- package/dist/cli/index.js +19 -7
- package/dist/cli/ink/scan_dashboard.d.ts +1 -1
- package/dist/cli/ink/scan_dashboard.js +2 -2
- package/dist/cli/setup.d.ts +0 -1
- package/dist/cli/setup.js +2 -8
- package/dist/currency.d.ts +3 -0
- package/dist/currency.js +12 -1
- package/dist/db/queries/account_balance.d.ts +83 -4
- package/dist/db/queries/account_balance.js +239 -20
- package/dist/db/queries/action_log.d.ts +29 -0
- package/dist/db/queries/action_log.js +27 -0
- package/dist/db/queries/concerns.d.ts +10 -7
- package/dist/db/queries/concerns.js +20 -16
- package/dist/db/queries/journal.d.ts +1 -0
- package/dist/db/queries/merchants.d.ts +42 -0
- package/dist/db/queries/merchants.js +120 -0
- package/dist/db/queries/recurrences.d.ts +3 -3
- package/dist/db/queries/recurrences.js +32 -34
- package/dist/db/queries/search.d.ts +5 -4
- package/dist/db/queries/search.js +16 -12
- package/dist/db/queries/transactions.d.ts +167 -0
- package/dist/db/queries/transactions.js +320 -0
- package/dist/db/schema.js +51 -9
- package/dist/reviewer/pipeline.d.ts +4 -4
- package/dist/reviewer/pipeline.js +4 -4
- package/dist/reviewer/prompts.js +4 -4
- package/dist/scanner/buffer.d.ts +24 -21
- package/dist/scanner/buffer.js +18 -18
- package/dist/scanner/pipeline.d.ts +3 -2
- package/dist/scanner/pipeline.js +33 -36
- package/dist/scanner/prompts.js +3 -3
- package/package.json +2 -2
package/dist/ai/system-prompt.js
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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");
|
package/dist/ai/thinking.js
CHANGED
package/dist/ai/tools/common.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { saveMemory, getMemories } from "../memory.js";
|
|
2
2
|
import { getAccountBalances } from "../../db/queries/account_balance.js";
|
|
3
|
-
import {
|
|
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 ${
|
|
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
|
}
|
package/dist/ai/tools/index.js
CHANGED
|
@@ -1,27 +1,44 @@
|
|
|
1
1
|
import { commonTools } from "./common.js";
|
|
2
2
|
import { readTools } from "./read.js";
|
|
3
|
-
import {
|
|
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
|
-
* `
|
|
12
|
-
*
|
|
13
|
-
*
|
|
13
|
+
* `accountIngestTools` (create_account / update_account_metadata /
|
|
14
|
+
* record_transaction) ships with scan, review, and record — they'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,
|
|
22
|
+
scan: [commonTools, accountIngestTools, scanConcernTools, scanTools, merchantTools],
|
|
17
23
|
chat: [commonTools, readTools],
|
|
18
|
-
review: [commonTools, readTools,
|
|
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 [
|
|
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
|
-
...
|
|
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
|
};
|