@rfc0/patty 0.0.0-stage → 1.0.2

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 (465) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +214 -2
  3. package/dist/adapters/access-tokens.js +7 -0
  4. package/dist/adapters/accounts.js +37 -0
  5. package/dist/adapters/auth.js +11 -0
  6. package/dist/adapters/bills.js +32 -0
  7. package/dist/adapters/budgets.js +29 -0
  8. package/dist/adapters/categories.js +32 -0
  9. package/dist/adapters/client-grants.js +7 -0
  10. package/dist/adapters/credit-cards.js +33 -0
  11. package/dist/adapters/currencies.js +2 -0
  12. package/dist/adapters/currency-rates.js +18 -0
  13. package/dist/adapters/dashboards.js +43 -0
  14. package/dist/adapters/demo.js +13 -0
  15. package/dist/adapters/instance-settings.js +7 -0
  16. package/dist/adapters/invites.js +7 -0
  17. package/dist/adapters/recurring.js +55 -0
  18. package/dist/adapters/sessions.js +7 -0
  19. package/dist/adapters/settings.js +4 -0
  20. package/dist/adapters/setup-codes.js +7 -0
  21. package/dist/adapters/tags.js +9 -0
  22. package/dist/adapters/transactions.js +95 -0
  23. package/dist/adapters/users.js +7 -0
  24. package/dist/common/build-version.js +5 -0
  25. package/dist/common/errors.js +118 -0
  26. package/dist/common/net.js +71 -0
  27. package/dist/common/result.js +7 -0
  28. package/dist/composition/auth.js +106 -0
  29. package/dist/composition/boot.js +27 -0
  30. package/dist/composition/cli.js +86 -0
  31. package/dist/composition/demo/seed.js +92 -0
  32. package/dist/composition/demo/shell.js +107 -0
  33. package/dist/composition/export.js +89 -0
  34. package/dist/composition/http.js +110 -0
  35. package/dist/composition/import.js +55 -0
  36. package/dist/composition/lazy-modules.js +2 -0
  37. package/dist/composition/runtime.js +115 -0
  38. package/dist/composition/sign-in/interpreter.js +154 -0
  39. package/dist/composition/sign-in/server.js +36 -0
  40. package/dist/composition/sign-in/wiring.js +23 -0
  41. package/dist/composition/stdio.js +69 -0
  42. package/dist/config.js +136 -0
  43. package/dist/controllers/account/account.js +88 -0
  44. package/dist/controllers/account/transaction.js +119 -0
  45. package/dist/controllers/account/transfer.js +34 -0
  46. package/dist/controllers/aggregate.js +40 -0
  47. package/dist/controllers/auth/access-tokens.js +61 -0
  48. package/dist/controllers/auth/grants.js +136 -0
  49. package/dist/controllers/auth/key-export.js +20 -0
  50. package/dist/controllers/auth/owner.js +80 -0
  51. package/dist/controllers/auth/password.js +35 -0
  52. package/dist/controllers/auth/session.js +50 -0
  53. package/dist/controllers/auth/step-up.js +8 -0
  54. package/dist/controllers/auth/users.js +183 -0
  55. package/dist/controllers/budgets.js +87 -0
  56. package/dist/controllers/categories.js +67 -0
  57. package/dist/controllers/correlations.js +112 -0
  58. package/dist/controllers/credit-card/bill.js +105 -0
  59. package/dist/controllers/credit-card/credit-card.js +129 -0
  60. package/dist/controllers/credit-card/transaction.js +181 -0
  61. package/dist/controllers/currencies.js +1 -0
  62. package/dist/controllers/currency-rates.js +40 -0
  63. package/dist/controllers/dashboards.js +68 -0
  64. package/dist/controllers/demo/seed.js +31 -0
  65. package/dist/controllers/demo/tour.js +12 -0
  66. package/dist/controllers/deps.js +6 -0
  67. package/dist/controllers/instance.js +6 -0
  68. package/dist/controllers/merchants.js +12 -0
  69. package/dist/controllers/recurring.js +70 -0
  70. package/dist/controllers/resolve.js +37 -0
  71. package/dist/controllers/settings.js +47 -0
  72. package/dist/controllers/status.js +19 -0
  73. package/dist/controllers/summary.js +21 -0
  74. package/dist/controllers/tags.js +19 -0
  75. package/dist/controllers/transaction/bulk.js +6 -0
  76. package/dist/controllers/transaction/core.js +49 -0
  77. package/dist/controllers/transaction/read.js +28 -0
  78. package/dist/diplomat/auth/credentials.js +58 -0
  79. package/dist/diplomat/auth/sign-in-store.js +18 -0
  80. package/dist/diplomat/cli/commands/auth.js +100 -0
  81. package/dist/diplomat/cli/commands/db.js +72 -0
  82. package/dist/diplomat/cli/commands/demo.js +68 -0
  83. package/dist/diplomat/cli/commands/key.js +119 -0
  84. package/dist/diplomat/cli/commands/login.js +151 -0
  85. package/dist/diplomat/cli/commands/setup.js +132 -0
  86. package/dist/diplomat/cli/commands/users.js +123 -0
  87. package/dist/diplomat/cli/commands.js +61 -0
  88. package/dist/diplomat/cli/export-file.js +37 -0
  89. package/dist/diplomat/cli/import-file.js +44 -0
  90. package/dist/diplomat/cli/io.js +61 -0
  91. package/dist/diplomat/cli/key-export-approval.js +37 -0
  92. package/dist/diplomat/cli/messages.js +96 -0
  93. package/dist/diplomat/cli/prompt.js +74 -0
  94. package/dist/diplomat/cli/terminal.js +81 -0
  95. package/dist/diplomat/client-config/clients.js +150 -0
  96. package/dist/diplomat/client-config/merge.js +41 -0
  97. package/dist/diplomat/db/bootstrap.js +98 -0
  98. package/dist/diplomat/db/database-files.js +147 -0
  99. package/dist/diplomat/db/driver.js +167 -0
  100. package/dist/diplomat/db/effects.js +101 -0
  101. package/dist/diplomat/db/engine.js +9 -0
  102. package/dist/diplomat/db/export.js +22 -0
  103. package/dist/diplomat/db/file-lock.js +82 -0
  104. package/dist/diplomat/db/key-lock.js +14 -0
  105. package/dist/diplomat/db/locale-cache.js +23 -0
  106. package/dist/diplomat/db/migration-barrier.js +57 -0
  107. package/dist/diplomat/db/migration-journal.js +18 -0
  108. package/dist/diplomat/db/migration-lock.js +15 -0
  109. package/dist/diplomat/db/migrations.js +11 -0
  110. package/dist/diplomat/db/present.js +17 -0
  111. package/dist/diplomat/db/queries/aggregate-whitelist.js +35 -0
  112. package/dist/diplomat/db/queries/filters.js +59 -0
  113. package/dist/diplomat/db/queries/fts.js +18 -0
  114. package/dist/diplomat/db/queries/scope.js +8 -0
  115. package/dist/diplomat/db/queries/transaction-select.js +26 -0
  116. package/dist/diplomat/db/queries/tx-predicates.js +13 -0
  117. package/dist/diplomat/db/repos/access-tokens.js +27 -0
  118. package/dist/diplomat/db/repos/accounts.js +91 -0
  119. package/dist/diplomat/db/repos/bills.js +93 -0
  120. package/dist/diplomat/db/repos/budgets.js +72 -0
  121. package/dist/diplomat/db/repos/categories.js +53 -0
  122. package/dist/diplomat/db/repos/client-grants.js +67 -0
  123. package/dist/diplomat/db/repos/correlations.js +66 -0
  124. package/dist/diplomat/db/repos/credit-cards.js +67 -0
  125. package/dist/diplomat/db/repos/currencies.js +8 -0
  126. package/dist/diplomat/db/repos/currency-rates.js +40 -0
  127. package/dist/diplomat/db/repos/dashboards.js +123 -0
  128. package/dist/diplomat/db/repos/health.js +12 -0
  129. package/dist/diplomat/db/repos/instance-settings.js +14 -0
  130. package/dist/diplomat/db/repos/instance.js +58 -0
  131. package/dist/diplomat/db/repos/invites.js +43 -0
  132. package/dist/diplomat/db/repos/merchants.js +121 -0
  133. package/dist/diplomat/db/repos/recurring.js +29 -0
  134. package/dist/diplomat/db/repos/sessions.js +19 -0
  135. package/dist/diplomat/db/repos/settings.js +41 -0
  136. package/dist/diplomat/db/repos/setup-codes.js +28 -0
  137. package/dist/diplomat/db/repos/sub-categories.js +67 -0
  138. package/dist/diplomat/db/repos/tags.js +51 -0
  139. package/dist/diplomat/db/repos/transaction-tags.js +57 -0
  140. package/dist/diplomat/db/repos/transactions.js +163 -0
  141. package/dist/diplomat/db/repos/users.js +47 -0
  142. package/dist/diplomat/db/safety-copy.js +87 -0
  143. package/dist/diplomat/db/schema.js +348 -0
  144. package/dist/diplomat/db/seed/categories.js +112 -0
  145. package/dist/diplomat/db/seed/currencies.js +9 -0
  146. package/dist/diplomat/db/seed/demo/br.js +98 -0
  147. package/dist/diplomat/db/seed/demo/co.js +89 -0
  148. package/dist/diplomat/db/seed/demo/index.js +12 -0
  149. package/dist/diplomat/db/seed/demo/mx.js +90 -0
  150. package/dist/diplomat/db/seed/demo/shared.js +39 -0
  151. package/dist/diplomat/db/seed/demo/us.js +90 -0
  152. package/dist/diplomat/db/seed/merchant-rules.js +188 -0
  153. package/dist/diplomat/db/sqlite-errors.js +40 -0
  154. package/dist/diplomat/db/tenancy-integrity.js +45 -0
  155. package/dist/diplomat/db/version-guard.js +16 -0
  156. package/dist/diplomat/http/auth-pages.js +41 -0
  157. package/dist/diplomat/http/auth-paths.js +46 -0
  158. package/dist/diplomat/http/bearer.js +15 -0
  159. package/dist/diplomat/http/connect-pages.js +51 -0
  160. package/dist/diplomat/http/context.js +17 -0
  161. package/dist/diplomat/http/cookies.js +27 -0
  162. package/dist/diplomat/http/form-pages.js +38 -0
  163. package/dist/diplomat/http/hooks/auth.js +106 -0
  164. package/dist/diplomat/http/hooks/demo-marker.js +59 -0
  165. package/dist/diplomat/http/openapi.js +73 -0
  166. package/dist/diplomat/http/principal.js +1 -0
  167. package/dist/diplomat/http/rate-limiter.js +78 -0
  168. package/dist/diplomat/http/remedy.js +26 -0
  169. package/dist/diplomat/http/respond.js +50 -0
  170. package/dist/diplomat/http/routes/account.js +226 -0
  171. package/dist/diplomat/http/routes/aggregate.js +28 -0
  172. package/dist/diplomat/http/routes/auth.js +105 -0
  173. package/dist/diplomat/http/routes/budget.js +34 -0
  174. package/dist/diplomat/http/routes/category.js +109 -0
  175. package/dist/diplomat/http/routes/connect.js +124 -0
  176. package/dist/diplomat/http/routes/credit-card.js +263 -0
  177. package/dist/diplomat/http/routes/currency-rates.js +60 -0
  178. package/dist/diplomat/http/routes/currency.js +16 -0
  179. package/dist/diplomat/http/routes/dashboard.js +93 -0
  180. package/dist/diplomat/http/routes/invite.js +63 -0
  181. package/dist/diplomat/http/routes/recurring.js +65 -0
  182. package/dist/diplomat/http/routes/settings.js +38 -0
  183. package/dist/diplomat/http/routes/summary.js +23 -0
  184. package/dist/diplomat/http/routes/system.js +29 -0
  185. package/dist/diplomat/http/routes/tag.js +51 -0
  186. package/dist/diplomat/http/routes/tokens.js +72 -0
  187. package/dist/diplomat/http/routes/transaction.js +55 -0
  188. package/dist/diplomat/http/routes/transfer.js +35 -0
  189. package/dist/diplomat/http/routes/ui.js +110 -0
  190. package/dist/diplomat/http/routes/users.js +156 -0
  191. package/dist/diplomat/http/routes/well-known.js +26 -0
  192. package/dist/diplomat/http/routes.js +85 -0
  193. package/dist/diplomat/http/session.js +34 -0
  194. package/dist/diplomat/http/token-pages.js +75 -0
  195. package/dist/diplomat/http/ui-files.js +21 -0
  196. package/dist/diplomat/http/user-pages.js +93 -0
  197. package/dist/diplomat/mcp/annotations.js +8 -0
  198. package/dist/diplomat/mcp/auth-info.js +20 -0
  199. package/dist/diplomat/mcp/context.js +14 -0
  200. package/dist/diplomat/mcp/definition.js +3 -0
  201. package/dist/diplomat/mcp/gate.js +15 -0
  202. package/dist/diplomat/mcp/instructions.js +19 -0
  203. package/dist/diplomat/mcp/prompts.js +125 -0
  204. package/dist/diplomat/mcp/register.js +12 -0
  205. package/dist/diplomat/mcp/remedy.js +17 -0
  206. package/dist/diplomat/mcp/resources.js +93 -0
  207. package/dist/diplomat/mcp/respond.js +20 -0
  208. package/dist/diplomat/mcp/route.js +62 -0
  209. package/dist/diplomat/mcp/scopes.js +53 -0
  210. package/dist/diplomat/mcp/server.js +26 -0
  211. package/dist/diplomat/mcp/shared.js +5 -0
  212. package/dist/diplomat/mcp/stdio-session.js +94 -0
  213. package/dist/diplomat/mcp/stdio.js +23 -0
  214. package/dist/diplomat/mcp/tool-name.js +59 -0
  215. package/dist/diplomat/mcp/tools/account.js +218 -0
  216. package/dist/diplomat/mcp/tools/aggregate.js +32 -0
  217. package/dist/diplomat/mcp/tools/budget.js +99 -0
  218. package/dist/diplomat/mcp/tools/category.js +103 -0
  219. package/dist/diplomat/mcp/tools/correlations.js +70 -0
  220. package/dist/diplomat/mcp/tools/credit-card.js +239 -0
  221. package/dist/diplomat/mcp/tools/currency-rates.js +62 -0
  222. package/dist/diplomat/mcp/tools/dashboard.js +75 -0
  223. package/dist/diplomat/mcp/tools/index.js +31 -0
  224. package/dist/diplomat/mcp/tools/recurring.js +62 -0
  225. package/dist/diplomat/mcp/tools/summary.js +30 -0
  226. package/dist/diplomat/mcp/tools/system.js +83 -0
  227. package/dist/diplomat/mcp/tools/tag.js +48 -0
  228. package/dist/diplomat/mcp/tools/transaction.js +53 -0
  229. package/dist/diplomat/mcp/tools/transfer.js +28 -0
  230. package/dist/diplomat/mcp/tour.js +87 -0
  231. package/dist/logic/account.js +79 -0
  232. package/dist/logic/aggregate.js +37 -0
  233. package/dist/logic/auth/bearer.js +35 -0
  234. package/dist/logic/auth/grant.js +126 -0
  235. package/dist/logic/auth/key-export.js +10 -0
  236. package/dist/logic/auth/keychain.js +3 -0
  237. package/dist/logic/auth/message.js +22 -0
  238. package/dist/logic/auth/origin.js +57 -0
  239. package/dist/logic/auth/owner.js +22 -0
  240. package/dist/logic/auth/password.js +3 -0
  241. package/dist/logic/auth/redact.js +25 -0
  242. package/dist/logic/auth/revoke.js +28 -0
  243. package/dist/logic/auth/scope.js +17 -0
  244. package/dist/logic/auth/session.js +30 -0
  245. package/dist/logic/auth/sign-in-flow.js +305 -0
  246. package/dist/logic/auth/time.js +2 -0
  247. package/dist/logic/auth/token.js +74 -0
  248. package/dist/logic/auth/user-plans.js +84 -0
  249. package/dist/logic/auth/users.js +78 -0
  250. package/dist/logic/balance.js +2 -0
  251. package/dist/logic/bill.js +74 -0
  252. package/dist/logic/budget.js +78 -0
  253. package/dist/logic/category.js +37 -0
  254. package/dist/logic/classify.js +21 -0
  255. package/dist/logic/correlations.js +147 -0
  256. package/dist/logic/credit-card.js +2 -0
  257. package/dist/logic/currency-rate.js +69 -0
  258. package/dist/logic/dashboard.js +40 -0
  259. package/dist/logic/demo/database.js +30 -0
  260. package/dist/logic/demo/plan.js +308 -0
  261. package/dist/logic/demo/tour.js +33 -0
  262. package/dist/logic/export-destination.js +12 -0
  263. package/dist/logic/key-import.js +15 -0
  264. package/dist/logic/locale.js +5 -0
  265. package/dist/logic/localize.js +12 -0
  266. package/dist/logic/merchant.js +31 -0
  267. package/dist/logic/migration.js +1 -0
  268. package/dist/logic/money.js +12 -0
  269. package/dist/logic/period.js +45 -0
  270. package/dist/logic/persistence.js +48 -0
  271. package/dist/logic/recurring.js +51 -0
  272. package/dist/logic/resolve.js +44 -0
  273. package/dist/logic/summary.js +29 -0
  274. package/dist/logic/tag.js +13 -0
  275. package/dist/logic/transaction.js +197 -0
  276. package/dist/main.js +42 -0
  277. package/dist/models/account.js +197 -0
  278. package/dist/models/aggregate.js +61 -0
  279. package/dist/models/auth/bearer.js +11 -0
  280. package/dist/models/auth/entity.js +17 -0
  281. package/dist/models/auth/errors.js +42 -0
  282. package/dist/models/auth/grant.js +58 -0
  283. package/dist/models/auth/key-export.js +11 -0
  284. package/dist/models/auth/message.js +50 -0
  285. package/dist/models/auth/mode.js +7 -0
  286. package/dist/models/auth/origin.js +16 -0
  287. package/dist/models/auth/owner.js +36 -0
  288. package/dist/models/auth/password.js +24 -0
  289. package/dist/models/auth/principal.js +26 -0
  290. package/dist/models/auth/redact.js +4 -0
  291. package/dist/models/auth/scope.js +9 -0
  292. package/dist/models/auth/session.js +19 -0
  293. package/dist/models/auth/sign-in-flow.js +102 -0
  294. package/dist/models/auth/sign-in.js +41 -0
  295. package/dist/models/auth/time.js +5 -0
  296. package/dist/models/auth/token.js +50 -0
  297. package/dist/models/auth/users.js +52 -0
  298. package/dist/models/bill.js +55 -0
  299. package/dist/models/budget.js +106 -0
  300. package/dist/models/category.js +52 -0
  301. package/dist/models/client-config.js +18 -0
  302. package/dist/models/correlations.js +215 -0
  303. package/dist/models/credit-card.js +156 -0
  304. package/dist/models/currency-rate.js +83 -0
  305. package/dist/models/dashboard.js +54 -0
  306. package/dist/models/database.js +16 -0
  307. package/dist/models/date.js +8 -0
  308. package/dist/models/demo/core.js +58 -0
  309. package/dist/models/demo/tour.js +41 -0
  310. package/dist/models/encryption-key.js +2 -0
  311. package/dist/models/error.js +13 -0
  312. package/dist/models/export.js +9 -0
  313. package/dist/models/id.js +2 -0
  314. package/dist/models/instance.js +7 -0
  315. package/dist/models/key-import.js +6 -0
  316. package/dist/models/locale.js +25 -0
  317. package/dist/models/merchant.js +12 -0
  318. package/dist/models/money.js +14 -0
  319. package/dist/models/package.js +12 -0
  320. package/dist/models/page.js +56 -0
  321. package/dist/models/persistence.js +1 -0
  322. package/dist/models/prompts.js +5 -0
  323. package/dist/models/recurring.js +54 -0
  324. package/dist/models/remedy.js +17 -0
  325. package/dist/models/resolution.js +1 -0
  326. package/dist/models/startup.js +7 -0
  327. package/dist/models/summary.js +24 -0
  328. package/dist/models/tag.js +14 -0
  329. package/dist/models/tenancy.js +10 -0
  330. package/dist/models/transaction-tag.js +6 -0
  331. package/dist/models/transaction.js +275 -0
  332. package/dist/wire/db/access-tokens.js +1 -0
  333. package/dist/wire/db/accounts.js +7 -0
  334. package/dist/wire/db/aggregate.js +16 -0
  335. package/dist/wire/db/bills.js +14 -0
  336. package/dist/wire/db/budgets.js +33 -0
  337. package/dist/wire/db/categories.js +14 -0
  338. package/dist/wire/db/client-grants.js +1 -0
  339. package/dist/wire/db/correlations.js +49 -0
  340. package/dist/wire/db/credit-cards.js +1 -0
  341. package/dist/wire/db/currencies.js +1 -0
  342. package/dist/wire/db/currency-rates.js +1 -0
  343. package/dist/wire/db/dashboards.js +1 -0
  344. package/dist/wire/db/instance-settings.js +1 -0
  345. package/dist/wire/db/invites.js +1 -0
  346. package/dist/wire/db/merchants.js +18 -0
  347. package/dist/wire/db/recurring.js +19 -0
  348. package/dist/wire/db/sessions.js +1 -0
  349. package/dist/wire/db/settings.js +1 -0
  350. package/dist/wire/db/setup-codes.js +1 -0
  351. package/dist/wire/db/tags.js +1 -0
  352. package/dist/wire/db/tenancy.js +1 -0
  353. package/dist/wire/db/transactions.js +89 -0
  354. package/dist/wire/db/users.js +1 -0
  355. package/dist/wire/in/accounts.js +26 -0
  356. package/dist/wire/in/aggregate.js +10 -0
  357. package/dist/wire/in/auth.js +107 -0
  358. package/dist/wire/in/bills.js +11 -0
  359. package/dist/wire/in/budgets.js +11 -0
  360. package/dist/wire/in/categories.js +9 -0
  361. package/dist/wire/in/cli.js +106 -0
  362. package/dist/wire/in/coerce.js +6 -0
  363. package/dist/wire/in/common.js +17 -0
  364. package/dist/wire/in/credit-cards.js +16 -0
  365. package/dist/wire/in/currency-rates.js +8 -0
  366. package/dist/wire/in/period.js +7 -0
  367. package/dist/wire/in/recurring.js +6 -0
  368. package/dist/wire/in/settings.js +5 -0
  369. package/dist/wire/in/summary.js +5 -0
  370. package/dist/wire/in/tags.js +2 -0
  371. package/dist/wire/in/transactions.js +31 -0
  372. package/dist/wire/out/bills.js +9 -0
  373. package/dist/wire/out/budgets.js +10 -0
  374. package/dist/wire/out/client-config.js +2 -0
  375. package/dist/wire/out/common.js +4 -0
  376. package/dist/wire/out/credit-cards.js +15 -0
  377. package/dist/wire/out/currency-rates.js +11 -0
  378. package/dist/wire/out/errors.js +58 -0
  379. package/dist/wire/out/recurring.js +6 -0
  380. package/dist/wire/out/status.js +10 -0
  381. package/dist/wire/out/summary.js +9 -0
  382. package/dist/wire/out/transactions.js +52 -0
  383. package/drizzle/0000_futuristic_umar.sql +124 -0
  384. package/drizzle/0001_fts5_search.sql +23 -0
  385. package/drizzle/0002_rename_graph_to_history.sql +7 -0
  386. package/drizzle/0003_lyrical_hairball.sql +2 -0
  387. package/drizzle/0004_misty_ikaris.sql +7 -0
  388. package/drizzle/0005_credit-liability-accounts.sql +14 -0
  389. package/drizzle/0006_smart_aqueduct.sql +1 -0
  390. package/drizzle/0007_add_dashboards.sql +5 -0
  391. package/drizzle/0008_yummy_madripoor.sql +1 -0
  392. package/drizzle/0009_version_groundwork.sql +9 -0
  393. package/drizzle/0010_category_merchant_association_cascade.sql +16 -0
  394. package/drizzle/0011_dashboard_id_normalization.sql +16 -0
  395. package/drizzle/0012_hot_the_spike.sql +12 -0
  396. package/drizzle/0013_recurring_rules_merchant.sql +1 -0
  397. package/drizzle/0014_dashboard_source_discriminator.sql +17 -0
  398. package/drizzle/0015_currencies_decimals.sql +1 -0
  399. package/drizzle/0016_unusual_zaran.sql +13 -0
  400. package/drizzle/0017_premium_blur.sql +1 -0
  401. package/drizzle/0018_auth_identity.sql +39 -0
  402. package/drizzle/0019_access_tokens.sql +16 -0
  403. package/drizzle/0020_stdio_sign_in.sql +27 -0
  404. package/drizzle/0021_tenancy_data.sql +289 -0
  405. package/drizzle/0022_user_management.sql +17 -0
  406. package/drizzle/0023_instance_settings_row.sql +2 -0
  407. package/drizzle/0024_credentials_changed_at.sql +2 -0
  408. package/drizzle/0025_instance_kind.sql +2 -0
  409. package/drizzle/0026_demo_seeded_at.sql +2 -0
  410. package/drizzle/0027_demo_country.sql +2 -0
  411. package/drizzle/0028_reset_sign_ins.sql +2 -0
  412. package/drizzle/meta/0000_snapshot.json +894 -0
  413. package/drizzle/meta/0003_snapshot.json +910 -0
  414. package/drizzle/meta/0004_snapshot.json +951 -0
  415. package/drizzle/meta/0005_snapshot.json +991 -0
  416. package/drizzle/meta/0006_snapshot.json +998 -0
  417. package/drizzle/meta/0007_snapshot.json +1029 -0
  418. package/drizzle/meta/0008_snapshot.json +1049 -0
  419. package/drizzle/meta/0009_snapshot.json +1121 -0
  420. package/drizzle/meta/0010_snapshot.json +1121 -0
  421. package/drizzle/meta/0011_snapshot.json +1136 -0
  422. package/drizzle/meta/0012_snapshot.json +1227 -0
  423. package/drizzle/meta/0013_snapshot.json +1247 -0
  424. package/drizzle/meta/0014_snapshot.json +1267 -0
  425. package/drizzle/meta/0015_snapshot.json +1275 -0
  426. package/drizzle/meta/0016_snapshot.json +1371 -0
  427. package/drizzle/meta/0017_snapshot.json +1392 -0
  428. package/drizzle/meta/0018_snapshot.json +1603 -0
  429. package/drizzle/meta/0019_snapshot.json +1713 -0
  430. package/drizzle/meta/0020_snapshot.json +1904 -0
  431. package/drizzle/meta/0021_snapshot.json +2186 -0
  432. package/drizzle/meta/0022_snapshot.json +2311 -0
  433. package/drizzle/meta/0023_snapshot.json +2311 -0
  434. package/drizzle/meta/0024_snapshot.json +2318 -0
  435. package/drizzle/meta/0025_snapshot.json +2326 -0
  436. package/drizzle/meta/0026_snapshot.json +2333 -0
  437. package/drizzle/meta/0027_snapshot.json +2340 -0
  438. package/drizzle/meta/0028_snapshot.json +2340 -0
  439. package/drizzle/meta/_journal.json +209 -0
  440. package/package.json +106 -4
  441. package/skills/dashboard-building/SKILL.md +201 -0
  442. package/skills/patty-tour/SKILL.md +34 -0
  443. package/ui/app.css +758 -0
  444. package/ui/app.js +543 -0
  445. package/ui/connect-result.html +16 -0
  446. package/ui/connect.html +53 -0
  447. package/ui/dashboards/accounts.html +3189 -0
  448. package/ui/dashboards/budget.html +1734 -0
  449. package/ui/dashboards/cards.html +4032 -0
  450. package/ui/dashboards/categories.html +4694 -0
  451. package/ui/dashboards/comparative.html +2475 -0
  452. package/ui/dashboards/dashboards.html +839 -0
  453. package/ui/dashboards/overview.html +2405 -0
  454. package/ui/dashboards/pending.html +2973 -0
  455. package/ui/dashboards/projections.html +2528 -0
  456. package/ui/dashboards/tags.html +1365 -0
  457. package/ui/invite.html +44 -0
  458. package/ui/login.html +26 -0
  459. package/ui/money.js +175 -0
  460. package/ui/setup.html +29 -0
  461. package/ui/shell.html +96 -0
  462. package/ui/token-created.html +24 -0
  463. package/ui/tokens.html +58 -0
  464. package/ui/user-invited.html +27 -0
  465. package/ui/users.html +60 -0
@@ -0,0 +1,53 @@
1
+ import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
2
+ import { formatAppError } from '../../common/errors.js';
3
+ import { hasScope, scopeOfTool } from '../../logic/auth/scope.js';
4
+ import { authErrors } from '../../models/auth/errors.js';
5
+ import { READ_SCOPE } from '../../models/auth/scope.js';
6
+ import { GateKind } from './gate.js';
7
+ import { jsonError, textError } from './respond.js';
8
+ import { LOG_PREFIX } from '../../models/package.js';
9
+ const toolScopesByServer = new WeakMap();
10
+ /** The scope each registered tool needs, by tool name. */
11
+ export const toolScopesOf = (server) => toolScopesByServer.get(server) ?? new Map();
12
+ /** `null` = proceed; otherwise what to answer instead of running the callback. */
13
+ const refusalOf = (outcome, required) => {
14
+ if (outcome.kind !== GateKind.enum.granted)
15
+ return outcome;
16
+ return hasScope(outcome.principal.scopes, required)
17
+ ? null
18
+ : { kind: GateKind.enum.refused, error: authErrors.insufficientScope(required) };
19
+ };
20
+ const refusalText = (refusal) => refusal.kind === GateKind.enum.not_signed_in ? refusal.message : formatAppError(refusal.error);
21
+ /** The request context is the callback's last argument; once granted it carries the caller's principal. */
22
+ const gated = (callback, required, options, refuse) => async (...args) => {
23
+ const extra = args.at(-1);
24
+ const outcome = await options.gate(extra);
25
+ const refusal = refusalOf(outcome, required);
26
+ if (refusal !== null || outcome.kind !== GateKind.enum.granted) {
27
+ return refuse(refusal ?? { kind: GateKind.enum.refused, error: authErrors.unauthenticated });
28
+ }
29
+ const caller = { principal: outcome.principal };
30
+ return callback(...args.slice(0, -1), { ...extra, ...caller });
31
+ };
32
+ const toolRefusal = (refusal) => refusal.kind === GateKind.enum.refused ? jsonError(refusal.error) : textError(refusal.message);
33
+ const throwRefusal = (refusal) => {
34
+ throw new McpError(ErrorCode.InvalidRequest, refusalText(refusal));
35
+ };
36
+ const withGatedLastArgument = (register, wrap) => (...args) => register(...args.slice(0, -1), wrap(args.at(-1)));
37
+ export const guardScopes = (server, options) => {
38
+ const scopes = new Map();
39
+ toolScopesByServer.set(server, scopes);
40
+ const registerTool = server.registerTool.bind(server);
41
+ server.registerTool = ((name, config, callback) => {
42
+ const readOnlyHint = config.annotations?.readOnlyHint;
43
+ if (typeof readOnlyHint !== 'boolean') {
44
+ throw new Error(`${LOG_PREFIX} MCP tool "${name}" must declare annotations.readOnlyHint (its scope derives from it)`);
45
+ }
46
+ const required = scopeOfTool(readOnlyHint);
47
+ scopes.set(name, required);
48
+ return registerTool(name, config, gated(callback, required, options, toolRefusal));
49
+ });
50
+ const readOnly = (callback) => gated(callback, READ_SCOPE, options, throwRefusal);
51
+ server.registerResource = withGatedLastArgument(server.registerResource.bind(server), readOnly);
52
+ server.registerPrompt = withGatedLastArgument(server.registerPrompt.bind(server), readOnly);
53
+ };
@@ -0,0 +1,26 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { DEFAULT_INSTANCE } from '../../models/instance.js';
3
+ import { documentationContext } from '../http/context.js';
4
+ import { buildOpenApiDocument } from '../http/openapi.js';
5
+ import { buildRouteDefinitions } from '../http/routes.js';
6
+ import { createMcpContext } from './context.js';
7
+ import { MCP_SERVER_NAME, serverInstructions } from './instructions.js';
8
+ import { promptDefinitions } from './prompts.js';
9
+ import { registerDefinitions } from './register.js';
10
+ import { resourceDefinitions } from './resources.js';
11
+ import { guardScopes } from './scopes.js';
12
+ import { toolDefinitions } from './tools/index.js';
13
+ /** Thin diplomat: MCP tools delegate to the same controllers as HTTP. Aggregation only (ADR-025) — each domain
14
+ * module exports its definitions, and the one generic registrar (`register.ts`) registers them. */
15
+ export const buildMcpServer = (tenancy, version, scopeGuard, instance = DEFAULT_INSTANCE) => {
16
+ const server = new McpServer({ name: MCP_SERVER_NAME, version }, { instructions: serverInstructions(instance) });
17
+ guardScopes(server, scopeGuard);
18
+ const ctx = createMcpContext(tenancy, version);
19
+ const openApiDocument = buildOpenApiDocument(buildRouteDefinitions(documentationContext(version)), version);
20
+ registerDefinitions(server, ctx, {
21
+ prompts: promptDefinitions,
22
+ resources: resourceDefinitions(openApiDocument),
23
+ tools: toolDefinitions,
24
+ });
25
+ return server;
26
+ };
@@ -0,0 +1,5 @@
1
+ /** Shared by import_card_statement/import_account_statement — the per-item
2
+ * classification/idempotency/result-status contract is identical for both single-source importers. */
3
+ export const STATEMENT_IMPORT_RESULT_DESCRIPTION = 'Each item is auto-classified and idempotent (key derived from date+description+amount when absent — ' +
4
+ 're-importing is safe). Returns a per-item status: created, needs_review (low confidence — confirm ' +
5
+ 'categories with the user), duplicate, or error.';
@@ -0,0 +1,94 @@
1
+ import { notSignedInMessage } from '../../logic/auth/message.js';
2
+ import { pendingOf } from '../../logic/auth/sign-in-flow.js';
3
+ import { GrantChannel } from '../../models/auth/grant.js';
4
+ import { STDIO_MESSAGES } from '../../models/auth/message.js';
5
+ import { GRANT_POLL_INTERVAL_MS } from '../../models/auth/sign-in.js';
6
+ import { IDLE, ObservationKind, PresentationKind, } from '../../models/auth/sign-in-flow.js';
7
+ import { clientInfoOf } from '../../wire/in/auth.js';
8
+ import { GateKind } from './gate.js';
9
+ const O = ObservationKind.enum;
10
+ const P = PresentationKind.enum;
11
+ const notSignedIn = (message) => ({ kind: GateKind.enum.not_signed_in, message });
12
+ /** The words a stdio client reads for what the protocol said. Nothing else is ever said to a stdio client. */
13
+ const outcomeOf = (presentation) => {
14
+ switch (presentation?.kind) {
15
+ case P.granted:
16
+ return { kind: GateKind.enum.granted, principal: presentation.principal };
17
+ case P.invalid_env_token:
18
+ return notSignedIn(STDIO_MESSAGES.invalidEnvToken);
19
+ case P.instructions:
20
+ return notSignedIn(notSignedInMessage({
21
+ origin: presentation.origin,
22
+ userCode: presentation.userCode,
23
+ ownerUnclaimed: presentation.ownerUnclaimed,
24
+ }));
25
+ // Everything else — including nothing at all — is "could not check"; only terminal lines say more.
26
+ default:
27
+ return notSignedIn(STDIO_MESSAGES.cannotVerify);
28
+ }
29
+ };
30
+ // Requests and the poll timer share the sign-in state, and a device code is single-use: one at a time.
31
+ const createSerialQueue = () => {
32
+ const queue = { tail: Promise.resolve() };
33
+ return (work) => {
34
+ const next = queue.tail.then(work);
35
+ queue.tail = next.catch(() => undefined);
36
+ return next;
37
+ };
38
+ };
39
+ /** The timer runs exactly while a request is open. */
40
+ const createPoller = (onTick) => {
41
+ const poller = { timer: null };
42
+ const stop = () => {
43
+ if (poller.timer !== null)
44
+ clearInterval(poller.timer);
45
+ poller.timer = null;
46
+ };
47
+ const start = () => {
48
+ if (poller.timer !== null)
49
+ return;
50
+ poller.timer = setInterval(onTick, GRANT_POLL_INTERVAL_MS);
51
+ poller.timer.unref();
52
+ };
53
+ return { stop, sync: (isPending) => (isPending ? start() : stop()) };
54
+ };
55
+ const signInConfig = (options) => ({
56
+ channel: GrantChannel.enum.stdio,
57
+ profile: options.profile,
58
+ client: clientInfoOf(options.clientInfo()),
59
+ authRequired: true,
60
+ envToken: options.envToken,
61
+ });
62
+ export const createStdioSession = (options) => {
63
+ const flow = { state: IDLE };
64
+ const serially = createSerialQueue();
65
+ const poller = createPoller(() => void serially(() => feed({ kind: O.ticked })).catch(() => undefined));
66
+ const syncPolling = () => poller.sync(pendingOf(flow.state) !== null);
67
+ /** Feed one observation; the last thing the protocol said (if anything) comes back. */
68
+ const feed = async (observation) => {
69
+ const said = { last: undefined };
70
+ try {
71
+ await options.signIn.drive(flow.state, observation, signInConfig(options), {
72
+ present: (presentation) => void (said.last = presentation),
73
+ // The timer paces a stdio session; there is nothing to wait for inline.
74
+ wait: async () => undefined,
75
+ progress: (next) => {
76
+ flow.state = next;
77
+ syncPolling();
78
+ },
79
+ });
80
+ }
81
+ finally {
82
+ syncPolling();
83
+ }
84
+ return said.last;
85
+ };
86
+ return {
87
+ // An unexpected failure (the database is busy, the keychain misbehaves) is "could not check", never a sign-out.
88
+ resolve: () => serially(async () => outcomeOf(await feed({ kind: O.requested }).catch(() => feed({ kind: O.errored })))).catch(() => outcomeOf(undefined)),
89
+ close: () => serially(async () => {
90
+ poller.stop();
91
+ await feed({ kind: O.closed });
92
+ }).catch(() => undefined),
93
+ };
94
+ };
@@ -0,0 +1,23 @@
1
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
2
+ import { instanceFactsOf } from '../../controllers/instance.js';
3
+ import { AuthMode } from '../../models/auth/mode.js';
4
+ import { ownerGate } from './gate.js';
5
+ import { buildMcpServer } from './server.js';
6
+ import { createStdioSession } from './stdio-session.js';
7
+ /** Thin diplomat: connects the transport-agnostic MCP server to a stdio transport, gated by the channel's identity —
8
+ * a `StdioSession` that asks the connected client who it is, or the owner. */
9
+ export const connectStdio = async (tenancy, version, auth) => {
10
+ // The connected server reports who spawned it (`initialize`'s clientInfo); the session asks only when it needs to.
11
+ const session = auth.mode === AuthMode.enum.required
12
+ ? createStdioSession({
13
+ signIn: auth.signIn(auth.profile),
14
+ profile: auth.profile,
15
+ envToken: auth.envToken,
16
+ clientInfo: () => server.server.getClientVersion(),
17
+ })
18
+ : undefined;
19
+ const gate = session ? () => session.resolve() : ownerGate;
20
+ const server = buildMcpServer(tenancy, version, { gate }, await instanceFactsOf(tenancy));
21
+ await server.connect(new StdioServerTransport());
22
+ return { server, session };
23
+ };
@@ -0,0 +1,59 @@
1
+ import { z } from 'zod';
2
+ /** Every MCP tool the server registers — the one source of tool names (definitions, tests, docs check, hints). */
3
+ export const ToolName = z.enum([
4
+ 'add_account_expense',
5
+ 'add_account_income',
6
+ 'add_card_purchase',
7
+ 'aggregate_spending',
8
+ 'apply_due_recurring',
9
+ 'confirm_transaction',
10
+ 'create_account',
11
+ 'create_budget',
12
+ 'create_category',
13
+ 'create_credit_card',
14
+ 'create_recurring',
15
+ 'create_sub_category',
16
+ 'create_tag',
17
+ 'create_transfer',
18
+ 'delete_account',
19
+ 'delete_account_transaction',
20
+ 'delete_budget',
21
+ 'delete_card_transaction',
22
+ 'delete_category',
23
+ 'delete_credit_card',
24
+ 'delete_dashboard',
25
+ 'delete_sub_category',
26
+ 'delete_tag',
27
+ 'find_correlations',
28
+ 'get_account_balances',
29
+ 'get_bill',
30
+ 'get_budget_status',
31
+ 'get_preferences',
32
+ 'get_spending_summary',
33
+ 'get_status',
34
+ 'import_account_statement',
35
+ 'import_card_statement',
36
+ 'list_accounts',
37
+ 'list_budgets',
38
+ 'list_categories',
39
+ 'list_credit_cards',
40
+ 'list_dashboards',
41
+ 'list_exchange_rates',
42
+ 'list_recurring',
43
+ 'list_sub_categories',
44
+ 'list_tags',
45
+ 'pay_bill',
46
+ 'rename_dashboard',
47
+ 'revert_bill_payment',
48
+ 'save_dashboard',
49
+ 'search_transactions',
50
+ 'set_base_currency',
51
+ 'set_exchange_rate',
52
+ 'set_exchange_rates',
53
+ 'set_locale',
54
+ 'update_account',
55
+ 'update_account_transaction',
56
+ 'update_budget',
57
+ 'update_card_transaction',
58
+ 'update_credit_card',
59
+ ]);
@@ -0,0 +1,218 @@
1
+ import { ToolName } from '../tool-name.js';
2
+ import { z } from 'zod';
3
+ import { createAccount, deleteAccount, getAccountBalances, listAccounts, updateAccount, } from '../../../controllers/account/account.js';
4
+ import { addAccountExpense, addAccountIncome, deleteAccountTransaction, importAccountStatement, updateAccountTransaction, } from '../../../controllers/account/transaction.js';
5
+ import { AccountType } from '../../../models/account.js';
6
+ import { DeleteTransactionSchema, TransactionSource } from '../../../models/transaction.js';
7
+ import { AddAccountMovementSchema, CreateAccountSchema, ImportAccountStatementSchema, UpdateAccountSchema, UpdateAccountTransactionSchema, } from '../../../wire/in/accounts.js';
8
+ import * as accountAdapters from '../../../adapters/accounts.js';
9
+ import { bulkResultToWireOut, createResultToWireOut, deleteResultToWireOut, outcomeToDb, } from '../../../adapters/transactions.js';
10
+ import { buildBulkResult } from '../../../controllers/transaction/bulk.js';
11
+ import { defineTool } from '../definition.js';
12
+ import { fromResult, json } from '../respond.js';
13
+ import { STATEMENT_IMPORT_RESULT_DESCRIPTION } from '../shared.js';
14
+ import { MUTATING, READ_ONLY } from '../annotations.js';
15
+ /** Shared by add_account_expense/add_account_income — identical aside from which movement kind
16
+ * is being recorded. */
17
+ const addAccountMovementDescription = (movement) => `Record ${movement === 'expense' ? 'an expense from' : 'income into'} a bank account / wallet — the ` +
18
+ "account aggregate's movement entry point (ADR-016). Resolves the account and category by name; " +
19
+ 'when category is omitted, classifies via learned merchant→category associations and returns method + ' +
20
+ 'confidence (confirm with the user when confidence < 0.6). Idempotent automatically — a repeat call with ' +
21
+ 'the same account/description/date/amount/currency is deduped; pass discriminator to record a genuinely ' +
22
+ 'separate transaction that would otherwise look identical. Currency comes from the account, or the ' +
23
+ `currency field (default USD). Omitting account records an unattached ${movement === 'expense' ? '(e.g. cash) expense' : 'income'}.`;
24
+ const addAccountExpenseTool = defineTool({
25
+ name: ToolName.enum.add_account_expense,
26
+ config: {
27
+ annotations: MUTATING,
28
+ title: 'Add account expense',
29
+ description: addAccountMovementDescription('expense'),
30
+ inputSchema: AddAccountMovementSchema.shape,
31
+ },
32
+ handle: async (args, { deps, runEffects }) => {
33
+ const model = accountAdapters.addAccountMovementWireInToModel(args);
34
+ const flow = () => addAccountExpense(deps, model, TransactionSource.enum.mcp).map(outcomeToDb);
35
+ return fromResult((await runEffects(flow)).map(createResultToWireOut));
36
+ },
37
+ });
38
+ const addAccountIncomeTool = defineTool({
39
+ name: ToolName.enum.add_account_income,
40
+ config: {
41
+ annotations: MUTATING,
42
+ title: 'Add account income',
43
+ description: addAccountMovementDescription('income'),
44
+ inputSchema: AddAccountMovementSchema.shape,
45
+ },
46
+ handle: async (args, { deps, runEffects }) => {
47
+ const model = accountAdapters.addAccountMovementWireInToModel(args);
48
+ const flow = () => addAccountIncome(deps, model, TransactionSource.enum.mcp).map(outcomeToDb);
49
+ return fromResult((await runEffects(flow)).map(createResultToWireOut));
50
+ },
51
+ });
52
+ const importAccountStatementDescription = 'Import a bank/wallet statement (pasted text, CSV lines) — every item is an expense or income ' +
53
+ "(per item's `type`) on the ONE account named at the top level (omit to record unattached, e.g. " +
54
+ "cash, movements) — the account aggregate's bulk entry point (ADR-017) — use import_card_statement " +
55
+ `instead for a credit-card statement. ${STATEMENT_IMPORT_RESULT_DESCRIPTION}`;
56
+ const importAccountStatementTool = defineTool({
57
+ name: ToolName.enum.import_account_statement,
58
+ config: {
59
+ annotations: MUTATING,
60
+ title: 'Import an account statement',
61
+ description: importAccountStatementDescription,
62
+ inputSchema: ImportAccountStatementSchema.shape,
63
+ },
64
+ // Orchestration (plan → run each item → bulk result) that belongs in a controller; kept as one named step here.
65
+ handle: async (args, { deps, runEffectsSequence }) => {
66
+ const model = accountAdapters.importAccountStatementWireInToModel(args);
67
+ const plan = await importAccountStatement(deps, model, TransactionSource.enum.import);
68
+ const outcomes = await runEffectsSequence(plan.lines, (line) => () => plan.flowFor(line)().map(outcomeToDb));
69
+ return json(bulkResultToWireOut(buildBulkResult(outcomes, plan.lines)));
70
+ },
71
+ });
72
+ const updateAccountTransactionDescription = "Update an account transaction by id (from search_transactions) — the account aggregate's update " +
73
+ 'entry point (ADR-017/ADR-020). Owns transactions that involve no credit account: account ' +
74
+ 'expenses/income and ordinary transfers. Absent cardId/billId (returned by search_transactions/ ' +
75
+ 'TransactionView) is a reliable proxy for picking this tool, but TransactionView does not expose ' +
76
+ 'account types and the authoritative check is the leg account type; if unsure (e.g. an ordinary ' +
77
+ "transfer's toAccountId), call the tool and follow the wrong-tool redirect. Calling this on a " +
78
+ 'transaction that involves a credit account is rejected with a validation error redirecting to ' +
79
+ `${ToolName.enum.update_card_transaction}. Only provided fields change. Setting category is a ` +
80
+ 'user correction (confidence 1, strengthens the merchant→category association). Changing account ' +
81
+ 'also updates currency to match it. Transfer transactions cannot have their type changed and ' +
82
+ 'cannot receive a category/subCategory (both rejected with a validation error).';
83
+ const updateAccountTransactionTool = defineTool({
84
+ name: ToolName.enum.update_account_transaction,
85
+ config: {
86
+ annotations: MUTATING,
87
+ title: 'Update account transaction',
88
+ description: updateAccountTransactionDescription,
89
+ inputSchema: UpdateAccountTransactionSchema.shape,
90
+ },
91
+ handle: async (args, { deps, runEffects }) => {
92
+ const flow = () => updateAccountTransaction(deps, accountAdapters.updateAccountTransactionWireInToModel(args)).map(outcomeToDb);
93
+ return fromResult(await runEffects(flow));
94
+ },
95
+ });
96
+ const deleteAccountTransactionDescription = "Delete an account transaction by id — the account aggregate's delete entry point " +
97
+ '(ADR-017/ADR-020). Owns transactions that involve no credit account (account expenses/income, ' +
98
+ 'ordinary transfers); calling this on a transaction that involves a credit account is rejected ' +
99
+ `with a validation error redirecting to ${ToolName.enum.delete_card_transaction}. Without ` +
100
+ 'confirm:true it is a DRY RUN returning what would be deleted — show it to the user and call ' +
101
+ 'again with confirm: true.';
102
+ const deleteAccountTransactionTool = defineTool({
103
+ name: ToolName.enum.delete_account_transaction,
104
+ config: {
105
+ annotations: MUTATING,
106
+ title: 'Delete account transaction',
107
+ description: deleteAccountTransactionDescription,
108
+ inputSchema: DeleteTransactionSchema.shape,
109
+ },
110
+ handle: async (args, { deps, runEffects }) => {
111
+ const flow = () => deleteAccountTransaction(deps, args).map(outcomeToDb);
112
+ return fromResult((await runEffects(flow)).map(deleteResultToWireOut));
113
+ },
114
+ });
115
+ const createAccountDescription = 'Create a bank account / wallet. Type defaults to checking, currency to USD. ' +
116
+ 'Note: credit accounts are created automatically with a credit card (create_credit_card).';
117
+ const createAccountTool = defineTool({
118
+ name: ToolName.enum.create_account,
119
+ config: {
120
+ annotations: MUTATING,
121
+ title: 'Create account',
122
+ description: createAccountDescription,
123
+ inputSchema: CreateAccountSchema.shape,
124
+ },
125
+ handle: async (args, { deps, runEffects }) => {
126
+ const flow = () => createAccount(deps, accountAdapters.createWireInToModel(args)).map(accountAdapters.outcomeToDb);
127
+ return fromResult(await runEffects(flow));
128
+ },
129
+ });
130
+ const getAccountBalancesDescription = 'Returns { balances, consolidatedNetWorth }. Each balance is derived: initialBalance + income − expenses ' +
131
+ '+ transfers in − transfers out, plus an optional converted block (read-time valuation against the base ' +
132
+ 'currency, with rate/asOf/stale — absent when no exchange rate is on file). consolidatedNetWorth sums ' +
133
+ 'every convertible balance in the base currency; accounts with no rate are listed in its excluded array. ' +
134
+ 'Optionally filter by account name or type.';
135
+ const getAccountBalancesTool = defineTool({
136
+ name: ToolName.enum.get_account_balances,
137
+ config: {
138
+ annotations: READ_ONLY,
139
+ title: 'Get account balances',
140
+ description: getAccountBalancesDescription,
141
+ inputSchema: {
142
+ account: z.string().optional().describe('Single account by name'),
143
+ type: AccountType.optional(),
144
+ projectedAsOf: z
145
+ .string()
146
+ .regex(/^\d{4}-\d{2}-\d{2}$/)
147
+ .optional()
148
+ .describe('YYYY-MM-DD. When provided, also returns projectedBalance = effective balance + pending ' +
149
+ 'transactions dated on/before this date. The effective balance is always included.'),
150
+ },
151
+ },
152
+ handle: async (args, { deps }) => {
153
+ return fromResult(await getAccountBalances(deps, args));
154
+ },
155
+ });
156
+ const listAccountsTool = defineTool({
157
+ name: ToolName.enum.list_accounts,
158
+ config: {
159
+ annotations: READ_ONLY,
160
+ title: 'List accounts',
161
+ description: 'List accounts with their currencies, optionally filtered by type (checking = conta corrente).',
162
+ inputSchema: {
163
+ type: AccountType.optional(),
164
+ },
165
+ },
166
+ handle: async (args, { deps }) => {
167
+ return json(await listAccounts(deps, args.type));
168
+ },
169
+ });
170
+ const updateAccountDescription = 'Update a bank account. name (via newName) and initialBalance are always editable. ' +
171
+ 'type is only editable when the account has no transactions/transfers (and cannot be set to credit). ' +
172
+ 'currency is only editable when the account has no transactions/transfers, ' +
173
+ 'no recurring rules, and is not a credit card payment account. ' +
174
+ 'Credit accounts (card-managed) are rejected — use the card flow.';
175
+ const updateAccountTool = defineTool({
176
+ name: ToolName.enum.update_account,
177
+ config: {
178
+ annotations: MUTATING,
179
+ title: 'Update account',
180
+ description: updateAccountDescription,
181
+ inputSchema: UpdateAccountSchema.shape,
182
+ },
183
+ handle: async (args, { deps, runEffects }) => {
184
+ const flow = () => updateAccount(deps, accountAdapters.updateWireInToModel(args)).map(accountAdapters.outcomeToDb);
185
+ return fromResult(await runEffects(flow));
186
+ },
187
+ });
188
+ const deleteAccountDescription = 'Delete a bank account by name. Blocked if any transactions, transfers, recurring rules, or credit cards ' +
189
+ 'reference it — returns an in_use error with reference counts ' +
190
+ 'so you can guide the user to clear them first. ' +
191
+ 'Credit accounts (card-managed) are rejected — use delete_credit_card instead.';
192
+ const deleteAccountTool = defineTool({
193
+ name: ToolName.enum.delete_account,
194
+ config: {
195
+ annotations: MUTATING,
196
+ title: 'Delete account',
197
+ description: deleteAccountDescription,
198
+ inputSchema: {
199
+ name: z.string().min(1).describe('Account name'),
200
+ },
201
+ },
202
+ handle: async (args, { deps, runEffects }) => {
203
+ const flow = () => deleteAccount(deps, args.name).map(accountAdapters.outcomeToDb);
204
+ return fromResult(await runEffects(flow));
205
+ },
206
+ });
207
+ export const accountTools = [
208
+ addAccountExpenseTool,
209
+ addAccountIncomeTool,
210
+ importAccountStatementTool,
211
+ updateAccountTransactionTool,
212
+ deleteAccountTransactionTool,
213
+ createAccountTool,
214
+ getAccountBalancesTool,
215
+ listAccountsTool,
216
+ updateAccountTool,
217
+ deleteAccountTool,
218
+ ];
@@ -0,0 +1,32 @@
1
+ import { ToolName } from '../tool-name.js';
2
+ import { aggregateSpending } from '../../../controllers/aggregate.js';
3
+ import { AggregateMetric, AggregateSort, AggregateSpendingSchema, } from '../../../models/aggregate.js';
4
+ import { defineTool } from '../definition.js';
5
+ import { fromResult } from '../respond.js';
6
+ import { READ_ONLY } from '../annotations.js';
7
+ const aggregateSpendingDescription = 'Flexible spending aggregation: group transactions by category, account, tag, month, or merchant, ' +
8
+ 'measured as sum, count, or avg. Results are per-currency blocks with totals and percentages. ' +
9
+ 'Only effective, non-transfer transactions are counted. Provide a period via month+year or from/to date range. ' +
10
+ 'Optional displayCurrency adds a top-level converted block: a read-time grand total of the per-currency ' +
11
+ 'block totals, converted against currency_rates (as_of-stamped, stale-flagged; a currency with no rate to ' +
12
+ 'displayCurrency is listed in converted.excluded and left out of the total, never fabricated). Only attached ' +
13
+ 'when metric is sum — count/avg are not coherent cross-currency money totals. Per-currency lines are ' +
14
+ 'unaffected either way.';
15
+ const aggregateSpendingTool = defineTool({
16
+ name: ToolName.enum.aggregate_spending,
17
+ config: {
18
+ annotations: READ_ONLY,
19
+ title: 'Aggregate spending',
20
+ description: aggregateSpendingDescription,
21
+ inputSchema: {
22
+ ...AggregateSpendingSchema.shape,
23
+ metric: AggregateSpendingSchema.shape.metric.default(AggregateMetric.enum.sum),
24
+ sort: AggregateSpendingSchema.shape.sort.default(AggregateSort.enum.desc),
25
+ limit: AggregateSpendingSchema.shape.limit.default(50),
26
+ },
27
+ },
28
+ handle: async (args, { deps }) => {
29
+ return fromResult(await aggregateSpending(deps, args));
30
+ },
31
+ });
32
+ export const aggregateTools = [aggregateSpendingTool];
@@ -0,0 +1,99 @@
1
+ import { ToolName } from '../tool-name.js';
2
+ import { z } from 'zod';
3
+ import { createBudget, deleteBudget, getBudgetStatus, listBudgets, updateBudget, } from '../../../controllers/budgets.js';
4
+ import { PeriodSchema } from '../../../models/date.js';
5
+ import { CurrencyCode } from '../../../models/money.js';
6
+ import { CreateBudgetSchema, UpdateBudgetSchema } from '../../../wire/in/budgets.js';
7
+ import * as budgetAdapters from '../../../adapters/budgets.js';
8
+ import { defineTool } from '../definition.js';
9
+ import { fromResult, json } from '../respond.js';
10
+ import { MUTATING, READ_ONLY } from '../annotations.js';
11
+ const createBudgetDescription = 'Create a recurring monthly spending limit on a category or sub-category, in one currency ' +
12
+ '(Feature Design 015). Provide exactly one of category/subCategory — a category budget rolls up its ' +
13
+ "sub-categories' spend (the envelope behavior); a sub-category budget measures only its own spend, " +
14
+ "and also counts toward its parent's budget if one exists. Rejected for an income-kind category " +
15
+ '(a budget caps spending). Rejected as a duplicate if this exact (target, currency, period) already ' +
16
+ 'has a budget — use update_budget instead. Use get_budget_status to see spend-vs-limit.';
17
+ const createBudgetTool = defineTool({
18
+ name: ToolName.enum.create_budget,
19
+ config: {
20
+ annotations: MUTATING,
21
+ title: 'Create budget',
22
+ description: createBudgetDescription,
23
+ inputSchema: CreateBudgetSchema.shape,
24
+ },
25
+ handle: async (args, { deps, runEffects }) => {
26
+ const flow = () => createBudget(deps, args).map(budgetAdapters.outcomeToDb);
27
+ return fromResult(await runEffects(flow));
28
+ },
29
+ });
30
+ const updateBudgetTool = defineTool({
31
+ name: ToolName.enum.update_budget,
32
+ config: {
33
+ annotations: MUTATING,
34
+ title: 'Update budget',
35
+ description: "Update a budget's limit and/or period, identified by its id (from create_budget/list_budgets).",
36
+ inputSchema: UpdateBudgetSchema.shape,
37
+ },
38
+ handle: async (args, { deps, runEffects }) => {
39
+ const flow = () => updateBudget(deps, args).map(budgetAdapters.outcomeToDb);
40
+ return fromResult(await runEffects(flow));
41
+ },
42
+ });
43
+ const deleteBudgetTool = defineTool({
44
+ name: ToolName.enum.delete_budget,
45
+ config: {
46
+ annotations: MUTATING,
47
+ title: 'Delete budget',
48
+ description: 'Delete a budget by id. Idempotent — deleting an already-absent id is not an error.',
49
+ inputSchema: { id: z.string().min(1).describe('Budget id') },
50
+ },
51
+ handle: async (args, { deps, runEffects }) => {
52
+ const flow = () => deleteBudget(deps, args.id).map(budgetAdapters.outcomeToDb);
53
+ return fromResult(await runEffects(flow));
54
+ },
55
+ });
56
+ const listBudgetsTool = defineTool({
57
+ name: ToolName.enum.list_budgets,
58
+ config: {
59
+ annotations: READ_ONLY,
60
+ title: 'List budgets',
61
+ description: 'List all budgets (the limits themselves, no spend) — use get_budget_status for spend-vs-limit.',
62
+ inputSchema: {},
63
+ },
64
+ handle: async (_args, { deps }) => {
65
+ return json(await listBudgets(deps));
66
+ },
67
+ });
68
+ const getBudgetStatusDescription = 'Spend-vs-limit for every budget in a month (Feature Design 015 phase 2, measurement revised by ' +
69
+ "Feature Design 020) — grouped by top-level category so a category's own budget and each of its " +
70
+ "sub-categories' own budgets read as one coherent unit; no cross-currency total on the per-currency " +
71
+ 'lines themselves (BRL and USD never mixed there). Reports two measures against each limit: ' +
72
+ '`effective` (cleared spend only) and `committed` (effective + pending — the earmark-aware view of ' +
73
+ "what's already spoken for); `pending` (committed - effective) is derived for convenience. Each " +
74
+ 'measure carries `amount` and `pct` (amount / limit); both sums are expense-only, same-currency ' +
75
+ '(income and transfers never count, even on a both-kind category); a category budget rolls up its ' +
76
+ "sub-categories' spend, a sub-category budget measures only its own (and also counts toward its " +
77
+ "parent's, if the parent has a budget too). `remaining` (limit - committed.amount) can go negative " +
78
+ 'when over budget — over-budget is reported, never an error. Optional displayCurrency adds a ' +
79
+ 'top-level converted block: a read-time grand total of committed spend across every budgeted ' +
80
+ "category's currency, converted against currency_rates (as_of-stamped, stale-flagged; a currency " +
81
+ 'with no rate to displayCurrency is listed in converted.excluded and left out of the total, never ' +
82
+ 'fabricated). A spend row counted toward both a sub-category budget and its rolled-up parent budget ' +
83
+ 'contributes to this total once, not twice. Per-currency/per-category lines are unaffected either way.';
84
+ const getBudgetStatusTool = defineTool({
85
+ name: ToolName.enum.get_budget_status,
86
+ config: {
87
+ annotations: READ_ONLY,
88
+ title: 'Get budget status',
89
+ description: getBudgetStatusDescription,
90
+ inputSchema: {
91
+ ...PeriodSchema.shape,
92
+ displayCurrency: CurrencyCode.optional().describe('Also return a converted grand total of committed spend in this currency'),
93
+ },
94
+ },
95
+ handle: async (args, { deps }) => {
96
+ return json(await getBudgetStatus(deps, args, args.displayCurrency));
97
+ },
98
+ });
99
+ export const budgetTools = [createBudgetTool, updateBudgetTool, deleteBudgetTool, listBudgetsTool, getBudgetStatusTool];