@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
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets\!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Rafael Ferreira Carneiro
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,215 @@
1
- # Temporary Holding Version
1
+ # PATTY — Personal Agent Tracking for Treasure and Yield
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ AI-first personal finance manager. The primary interface is natural language through an **MCP server** — connect it to Claude or VS Code Copilot and talk to your finances directly. REST is a secondary surface.
4
+
5
+ **What's built:** transactions (expense/income/transfer), accounts, credit cards & bills, recurring rules, bulk import, auto-classification by merchant, sub-categories, and tags. Summaries group per currency; amounts are never converted implicitly.
6
+
7
+ **Local-first by design:** no database server, no containers, no cloud. Data lives in a single **encrypted libSQL (SQLite) file** on your machine; the encryption key is held in your OS keychain.
8
+
9
+ Stack: TypeScript · Fastify · zod · neverthrow · remeda · libSQL + Drizzle ORM.
10
+
11
+ ---
12
+
13
+ ## Try the demo
14
+
15
+ See PATTY on sample data first — no install of your own data, no login, nothing touches your real finances:
16
+
17
+ ```bash
18
+ npx @rfc0/patty@latest demo
19
+ ```
20
+
21
+ It seeds four months of sample finances (pick a data set with `--country br|us|mx|co`) and serves the dashboards on
22
+ `http://127.0.0.1:51738`. To talk to it from your AI client, run `npx @rfc0/patty@latest setup <client> --demo`
23
+ and ask for the **`tour`** prompt on the `patty-demo` server. Details in [`docs/demo.md`](docs/demo.md).
24
+
25
+ ---
26
+
27
+ ## Getting started
28
+
29
+ ### 0 — Prerequisites
30
+
31
+ Before running `npx`, make sure these tools are installed:
32
+
33
+ - **Node.js 26.x**
34
+ - **npm 11+**
35
+
36
+ Quick check:
37
+
38
+ ```bash
39
+ node -v
40
+ npm -v
41
+ ```
42
+
43
+ If needed, install from [nodejs.org](https://nodejs.org/) (recommended) or via your package manager (`nvm`, `fnm`, `asdf`, Homebrew).
44
+
45
+ ### 1 — Connect your AI client
46
+
47
+ Run the setup command for your agent — it downloads PATTY, writes the correct config, and exits. No server to start separately; the client manages that automatically from this point on.
48
+
49
+ PATTY requires a login, even on your own machine. **The first time, `setup` asks you to choose the owner's username and password** (the password twice, never echoed; 12+ characters) before it writes the config. Afterwards it just says who the owner is and carries on. Log in to the dashboard (`/ui`) with them. Upgrading from an earlier version? Run `setup` (or `auth setup`) once: it claims your existing data's owner, and nothing is copied or lost. Forgot the password: `npx @rfc0/patty@latest auth reset-password`. Scripted installs: `printf %s "$PASSWORD" | npx @rfc0/patty@latest setup claude-code --username me --password-stdin`. Details: [`docs/auth.md`](docs/auth.md#first-setup).
50
+
51
+ ```bash
52
+ npx @rfc0/patty@latest setup claude-code # Claude Code CLI
53
+ npx @rfc0/patty@latest setup claude-desktop # Claude Desktop
54
+ npx @rfc0/patty@latest setup copilot # VS Code / GitHub Copilot
55
+ npx @rfc0/patty@latest setup antigravity # Google Antigravity
56
+ npx @rfc0/patty@latest setup codex # OpenAI Codex (prints snippet)
57
+ ```
58
+
59
+ Run without a tool name to list all options and the config file each one writes:
60
+
61
+ ```bash
62
+ npx @rfc0/patty@latest setup
63
+ ```
64
+
65
+ After writing the config, `setup` offers to **sign that client in now** (a browser approval — see step 3). The setup command is safe to re-run — it skips the login step once the owner is claimed and merges idempotently, preserving any existing config keys. With no terminal and no `--password-stdin` it stops with instructions *before* writing any config.
66
+
67
+ > **Always use `@latest`.** `npx` with no version prefers an *installed* copy over the registry's, so a stale global install can run an old build. Every command here is pinned; check for a stale global copy with `npm ls -g @rfc0/patty`. An older build also refuses to run against a database a newer one has migrated, and says how to update.
68
+ If the target config file exists but is empty/invalid (or has a non-object JSON root), setup recovers automatically by replacing that root with a valid object.
69
+
70
+ ### 2 — Restart your client and start chatting
71
+
72
+ Restart the AI client (or reload the window for VS Code). **The install flow ends with a sign-in:** a stdio session acts as nobody until you approve it. If you did not sign in during `setup`, Claude's first request shows a link and a code (`PATTY: not signed in. Open …/ui/connect?code=ABCD-EFGH …`): open it, log in, check the code, choose read-only or read-and-write and how long it lasts (this session only, 24 hours, 7 days or 30 days), enter your password, and approve. From then on a restart of the client is silently signed in until it expires (24 hours, 7 days or 30 days — a "this session only" sign-in ends with the session, so the next start asks again); you can list and revoke sign-ins at `/ui/access/tokens`. From a terminal: `npx @rfc0/patty@latest login` / `logout`; for headless clients set `PATTY_TOKEN`. Details: [`docs/auth.md`](docs/auth.md#signing-in-claude-stdio). Then talk to your finances naturally. See [Sample usage](#sample-usage) below.
73
+
74
+ > **Updating:** re-run the same setup command. `npx` with `@latest` always fetches the newest published version.
75
+
76
+ ---
77
+
78
+ ## Transports
79
+
80
+ | Mode | When | How |
81
+ |---|---|---|
82
+ | **stdio** (default) | A client launches PATTY directly — no port, no conflicts. | Client config points at `npx @rfc0/patty@latest` |
83
+ | **http** (`MCP_TRANSPORT=http`) | REST API, multi-client, or debugging via the Inspector. | `http://127.0.0.1:51737` (`/mcp`, `/api`) — `:3001` if run via `npm run dev` |
84
+
85
+ ---
86
+
87
+ ## Manual config and HTTP mode
88
+
89
+ Prefer the `setup` command above. If you need to configure manually or use HTTP mode, see [`docs/mcp-clients.md`](docs/mcp-clients.md) for per-client JSON snippets, ChatGPT, Ollama, port details, and debugging.
90
+
91
+ **HTTP mode quick-start** — start the server explicitly, then connect by URL. Authentication is on: claim the owner first (`setup`/`auth setup`), log in at `/ui`, and send a [personal access token](docs/auth.md#personal-access-tokens) (`Authorization: Bearer ptk_…`) from your client — or, for development only, `PATTY_AUTH=disabled` (loopback only) turns the login off:
92
+
93
+ ```bash
94
+ MCP_TRANSPORT=http npx @rfc0/patty@latest # published package → :51737
95
+ MCP_TRANSPORT=http npm run dev # from source → :3001
96
+ ```
97
+
98
+ VS Code `.vscode/mcp.json` (HTTP, published package):
99
+
100
+ ```json
101
+ { "servers": { "patty": { "type": "http", "url": "http://127.0.0.1:51737/mcp" } } }
102
+ ```
103
+
104
+ > Use `127.0.0.1`, not `localhost` — VS Code resolves `localhost` to IPv6 `::1`. Running from source
105
+ > instead? Use port `3001` (this repo's `.vscode/mcp.json` already does).
106
+
107
+ ---
108
+
109
+ ## Docker
110
+
111
+ Run PATTY as a container instead of through npm: the dashboards (`/ui`), REST (`/api`) and the MCP endpoint (`/mcp`)
112
+ are served from one port, and your data lives in a Docker volume.
113
+
114
+ ```bash
115
+ (umask 077; openssl rand -hex 32 > patty_db_key) # the database encryption key, owner-only
116
+ sudo chown 1000 patty_db_key # Linux only: the container's unprivileged user (uid 1000) must own it; skip on Docker Desktop
117
+ docker compose up -d --build # builds from source; or drop --build to pull the published image
118
+ ```
119
+
120
+ The published image `ghcr.io/rafaelfcarneiro/patty` is public: no login is needed to pull it. `:latest` moves only
121
+ when the owner approves a release (`docs/releasing.md`); a version tag such as `:1.2.3` is available as soon as it is built.
122
+
123
+ The first start prints a one-time **setup code** to the container log. Claim the instance with it:
124
+
125
+ ```bash
126
+ docker compose logs patty # find the code: XXXX-XXXX-XXXX-XXXX-XXXX
127
+ ```
128
+
129
+ Open <http://127.0.0.1:51737/ui/setup>, enter the code, and choose a username and a password (12+ characters).
130
+ You're logged in; the code is single-use and a restart before you finish prints a fresh one.
131
+ The container requires a login for everything except `/api/health` — see [`docs/auth.md`](docs/auth.md).
132
+
133
+ Connect an MCP client or script with a **personal access token**: in the dashboard open the key icon in the sidebar
134
+ (`/ui/access/tokens`), create a token (read-only or read+write, with an expiry), copy it — it is shown once — and send it as
135
+ `Authorization: Bearer ptk_…` to `http://127.0.0.1:51737/mcp` (MCP) or `/api` (REST). Per-client setup:
136
+ [`docs/mcp-clients.md`](docs/mcp-clients.md#docker-container-http-on-12700151737); how tokens, scopes and revocation work:
137
+ [`docs/auth.md`](docs/auth.md#personal-access-tokens).
138
+
139
+ Already running PATTY through npm? Move its database and key into the container with `key export` (it asks an administrator's password and a confirmation) and `db export`:
140
+ [`docs/auth.md`](docs/auth.md#moving-an-npm-install-to-docker).
141
+
142
+ Sharing the instance with someone else? Admins invite them at `/ui/access/users` (or `npx @rfc0/patty@latest users invite <name>`): they get a one-time
143
+ link, choose their own password, and see only their own finances. See [`docs/auth.md`](docs/auth.md#users-roles-and-invitations).
144
+
145
+ - **Loopback only.** `compose.yaml` publishes `127.0.0.1:51737:51737`. The login protects the API, but the
146
+ container speaks plain HTTP — publishing as `51737:51737` would send your password and session across the network
147
+ in the clear. Keep the publish on loopback until TLS-terminating proxy support is documented.
148
+ - **One replica per volume.** SQLite and the in-process scheduler assume a single process; don't scale the service.
149
+ - **Backup = the volume *and* the key.** The database is encrypted; if you lose `patty_db_key` the data is
150
+ unrecoverable. Back both up (and keep the key somewhere other than next to the volume backup).
151
+ - The image is multi-arch (`linux/amd64`, `linux/arm64`) and hardened in compose: non-root, read-only root filesystem
152
+ (only `/data` and a `/tmp` tmpfs are writable), all capabilities dropped. The private package/image visibility is
153
+ covered in [`docs/releasing.md`](docs/releasing.md#container-image-ghcr).
154
+
155
+ ---
156
+
157
+ ## Development (from source)
158
+
159
+ ```bash
160
+ npm install
161
+ npm run dev # stdio MCP server (reads stdin)
162
+ ```
163
+
164
+ ```bash
165
+ MCP_TRANSPORT=http npm run dev # REST + MCP on http://127.0.0.1:3001
166
+ npm run mcp:inspect # MCP Inspector → http://127.0.0.1:3001/mcp
167
+ ```
168
+
169
+ Run `npx ntl` for an interactive, described list of all scripts. On first run (any mode) PATTY creates `~/.patty/patty.db` and generates the encryption key in your OS keychain.
170
+
171
+ ---
172
+
173
+ ## Sample usage
174
+
175
+ Once connected, talk to Claude naturally:
176
+
177
+ - **Log a transaction** — "Paguei 32,50 de Uber ontem"
178
+ - **Bulk import a statement** — "Here's my bank statement for May: [paste]"
179
+ - **Monthly summary** — "What did I spend in June? Break it down by category."
180
+ - **Tag and search** — "Tag last week's restaurant transactions as 'work-dinner', then show me everything tagged work-dinner this month."
181
+ - **Credit card bill** — "What's on my Itaú card bill for June? Mark it as paid."
182
+ - **Recurring rule** — "I pay R$59 for Spotify every month on the 10th. Set that up as a recurring expense."
183
+
184
+ ---
185
+
186
+ ## Testing
187
+
188
+ ```bash
189
+ npm test # unit tests (vitest)
190
+ npm run test:integration # MCP integration tests — in-process libSQL DB, no Docker required
191
+ npm run test:all # both
192
+ ```
193
+
194
+ Integration tests run against an ephemeral in-process libSQL database, exercise the full MCP tool suite, and never touch your real `<home directory>/.patty/patty.db`.
195
+
196
+ ---
197
+
198
+ ## Docs
199
+
200
+ | File | What it covers |
201
+ |---|---|
202
+ | [`docs/architecture.md`](docs/architecture.md) | System as built — relational schema, layer rules, invariants, conventions in this repo |
203
+ | [`docs/demo.md`](docs/demo.md) | The demo: what it contains, the `tour` prompt, reset and remove |
204
+ | [`docs/mcp-tools.md`](docs/mcp-tools.md) | Full MCP tool contract: inputs, outputs, error codes, examples |
205
+ | [`docs/mcp-clients.md`](docs/mcp-clients.md) | Connecting to Claude, VS Code, ChatGPT, Ollama |
206
+ | [`docs/releasing.md`](docs/releasing.md) | Publishing, installing the private package, updating, ports |
207
+ | [`docs/canonical/`](docs/canonical/) | Agnostic principles: diplomatic architecture, functional core / imperative shell, code quality, code style |
208
+ | [`docs/adr/`](docs/adr/) | Architecture Decision Records |
209
+ | [`CLAUDE.md`](CLAUDE.md) | Agent and contributor conventions |
210
+
211
+ ---
212
+
213
+ ## License
214
+
215
+ [Apache-2.0](LICENSE)
@@ -0,0 +1,7 @@
1
+ import * as persistence from '../logic/persistence.js';
2
+ import { ACCESS_TOKEN_ENTITY_TAG } from '../models/auth/entity.js';
3
+ import { AccessTokenEntitySchema } from '../models/auth/token.js';
4
+ export const dbToModel = (row) => AccessTokenEntitySchema.parse(row);
5
+ /** A versioned `AccessTokenEntity` is already row-shaped (`scopes` is a JSON column the driver (de)serializes). */
6
+ export const modelToDb = (entity) => entity;
7
+ export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(ACCESS_TOKEN_ENTITY_TAG, modelToDb);
@@ -0,0 +1,37 @@
1
+ import { ACCOUNT_ENTITY_TAG, AccountEntitySchema, AccountSchema, } from '../models/account.js';
2
+ import * as persistence from '../logic/persistence.js';
3
+ export const dbToModel = (row) => AccountSchema.parse({
4
+ id: row.id,
5
+ name: row.name,
6
+ type: row.type,
7
+ initialBalance: row.initialBalance,
8
+ currency: row.currency,
9
+ });
10
+ /** Read variant carrying `version` — for flows building an `update`/`delete` `Persistable` from a
11
+ * fresh read (`updateAccount`/`deleteAccount`, `deleteCreditCard`'s internal-account lookup).
12
+ * Never used for a plain list/read response, so `version` can't leak onto the wire. */
13
+ export const dbToEntity = (row) => AccountEntitySchema.parse({
14
+ id: row.id,
15
+ name: row.name,
16
+ type: row.type,
17
+ initialBalance: row.initialBalance,
18
+ currency: row.currency,
19
+ version: row.version,
20
+ });
21
+ /** Entity → row for the versioned unit of work (ADR-021) — the only account write path that
22
+ * needs `version` on the wire-db row. */
23
+ export const modelToDb = (entity) => ({
24
+ id: entity.id,
25
+ name: entity.name,
26
+ type: entity.type,
27
+ initialBalance: entity.initialBalance,
28
+ currency: entity.currency,
29
+ version: entity.version,
30
+ });
31
+ export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(ACCOUNT_ENTITY_TAG, modelToDb);
32
+ export const createWireInToModel = (input) => input;
33
+ export const updateWireInToModel = (input) => input;
34
+ export const addAccountMovementWireInToModel = (input) => input;
35
+ export const transferWireInToModel = (input) => input;
36
+ export const updateAccountTransactionWireInToModel = (input) => input;
37
+ export const importAccountStatementWireInToModel = (input) => input;
@@ -0,0 +1,11 @@
1
+ import * as accessTokenAdapters from './access-tokens.js';
2
+ import * as clientGrantAdapters from './client-grants.js';
3
+ import * as instanceSettingsAdapters from './instance-settings.js';
4
+ import * as inviteAdapters from './invites.js';
5
+ import * as sessionAdapters from './sessions.js';
6
+ import * as setupCodeAdapters from './setup-codes.js';
7
+ import * as userAdapters from './users.js';
8
+ /** The auth flows touch seven entities; each adapter only rewrites its own tag, so applying all seven
9
+ * in turn adapts a mixed batch (`claimOwner`: user + setup code + session; `redeemGrant`: grant + token;
10
+ * `inviteUser`: user + invite). */
11
+ export const outcomeToDb = (outcome) => instanceSettingsAdapters.outcomeToDb(inviteAdapters.outcomeToDb(clientGrantAdapters.outcomeToDb(accessTokenAdapters.outcomeToDb(sessionAdapters.outcomeToDb(setupCodeAdapters.outcomeToDb(userAdapters.outcomeToDb(outcome)))))));
@@ -0,0 +1,32 @@
1
+ import { BILL_ENTITY_TAG } from '../models/bill.js';
2
+ import { INITIAL_VERSION, PersistOp } from '@rfc0/effect-runner';
3
+ /**
4
+ * Adapts one bill `Persistable`'s model to db-row shape — hand-written rather than built from
5
+ * `logic/persistence.ts`'s `entityDbAdapter`, since `update` needs to bypass row-shaping entirely:
6
+ * `paymentTransactionId: undefined` means "leave the column unchanged" (drizzle's `.set()` drops
7
+ * undefined-valued keys); `null` means "clear it" (models/bill.ts) — a distinction a uniform
8
+ * `modelToDb` called on every update would collapse into always-clear. `insert` still bakes in
9
+ * `INITIAL_VERSION`; no-ops on any other entity's `Persistable`.
10
+ */
11
+ export const persistableToDb = (p) => {
12
+ if (p.entity !== BILL_ENTITY_TAG)
13
+ return p;
14
+ switch (p.op) {
15
+ case PersistOp.enum.insert:
16
+ return { ...p, model: { ...p.model, version: INITIAL_VERSION } };
17
+ case PersistOp.enum.update:
18
+ return p;
19
+ case PersistOp.enum.delete:
20
+ case PersistOp.enum.check:
21
+ return p;
22
+ default: {
23
+ const _exhaustive = p;
24
+ throw new Error(`billAdapters.persistableToDb: unhandled persistable op ${JSON.stringify(_exhaustive)}`);
25
+ }
26
+ }
27
+ };
28
+ /** Maps every `Persistable` in a flow's outcome through `persistableToDb` before `runEffects`. */
29
+ export const outcomeToDb = (outcome) => ({
30
+ ...outcome,
31
+ persist: outcome.persist.map(persistableToDb),
32
+ });
@@ -0,0 +1,29 @@
1
+ import { BUDGET_ENTITY_TAG, BudgetEntitySchema, BudgetSchema, } from '../models/budget.js';
2
+ import * as persistence from '../logic/persistence.js';
3
+ export const dbToModel = (row) => BudgetSchema.parse({
4
+ id: row.id,
5
+ categoryId: row.categoryId,
6
+ currency: row.currency,
7
+ limit: row.limitAmount,
8
+ period: row.period,
9
+ });
10
+ /** Read variant carrying `version` — for `updateBudget`/`deleteBudget`, which need it to build a
11
+ * version-guarded `Persistable`. */
12
+ export const dbToEntity = (row) => BudgetEntitySchema.parse({
13
+ id: row.id,
14
+ categoryId: row.categoryId,
15
+ currency: row.currency,
16
+ limit: row.limitAmount,
17
+ period: row.period,
18
+ version: row.version,
19
+ });
20
+ /** Entity → row for the versioned unit of work — the one field rename (`limit` → `limitAmount`). */
21
+ export const modelToDb = (entity) => ({
22
+ id: entity.id,
23
+ categoryId: entity.categoryId,
24
+ currency: entity.currency,
25
+ limitAmount: entity.limit,
26
+ period: entity.period,
27
+ version: entity.version,
28
+ });
29
+ export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(BUDGET_ENTITY_TAG, modelToDb);
@@ -0,0 +1,32 @@
1
+ import { CATEGORY_ENTITY_TAG, CategorySchema, LocalizedNamesSchema, SubCategorySchema, } from '../models/category.js';
2
+ import * as persistence from '../logic/persistence.js';
3
+ import { SubCategoryRowSchema } from '../wire/db/categories.js';
4
+ // Input is the schema-derived Drizzle row; CategorySchema.parse enforces domain constraints.
5
+ export const dbToModel = (row) => CategorySchema.parse({
6
+ id: row.id,
7
+ name: row.name,
8
+ kind: row.kind,
9
+ names: row.names !== null ? LocalizedNamesSchema.parse(JSON.parse(row.names)) : null,
10
+ });
11
+ export const dbToSubCategory = (record) => {
12
+ const row = SubCategoryRowSchema.parse(record);
13
+ return SubCategorySchema.parse({
14
+ id: row.id,
15
+ name: row.name,
16
+ parentId: row.parent_id,
17
+ parentName: row.parent_name,
18
+ kind: row.kind,
19
+ });
20
+ };
21
+ export const wireInToModel = (input) => input;
22
+ /** Entity → row for the versioned unit of work — shared by a top-level category and a sub-category,
23
+ * both rows in the `categories` table. */
24
+ export const modelToDb = (entity) => ({
25
+ id: entity.id,
26
+ name: entity.name,
27
+ kind: entity.kind,
28
+ parentId: entity.parentId ?? null,
29
+ names: entity.names ? JSON.stringify(entity.names) : null,
30
+ version: entity.version,
31
+ });
32
+ export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(CATEGORY_ENTITY_TAG, modelToDb);
@@ -0,0 +1,7 @@
1
+ import * as persistence from '../logic/persistence.js';
2
+ import { CLIENT_GRANT_ENTITY_TAG } from '../models/auth/entity.js';
3
+ import { ClientGrantEntitySchema } from '../models/auth/grant.js';
4
+ export const dbToModel = (row) => ClientGrantEntitySchema.parse(row);
5
+ /** A versioned `ClientGrantEntity` is already row-shaped (`scopes` is a JSON column the driver (de)serializes). */
6
+ export const modelToDb = (entity) => entity;
7
+ export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(CLIENT_GRANT_ENTITY_TAG, modelToDb);
@@ -0,0 +1,33 @@
1
+ import { CREDIT_CARD_ENTITY_TAG, CreditCardEntitySchema, } from '../models/credit-card.js';
2
+ import * as persistence from '../logic/persistence.js';
3
+ export const wireInToModel = (input) => input;
4
+ export const updateWireInToModel = (input) => input;
5
+ export const addCardPurchaseWireInToModel = (input) => input;
6
+ export const updateCardTransactionWireInToModel = (input) => input;
7
+ export const importCardStatementWireInToModel = (input) => input;
8
+ /** Read variant carrying `version` — for `deleteCreditCard`, which needs it to build a
9
+ * version-guarded `Persistable`. */
10
+ export const dbToEntity = (row) => CreditCardEntitySchema.parse({
11
+ id: row.id,
12
+ name: row.name,
13
+ currency: row.currency,
14
+ closingDay: row.closingDay,
15
+ dueDay: row.dueDay,
16
+ limit: row.limitAmount ?? undefined,
17
+ accountId: row.accountId,
18
+ paymentAccountId: row.paymentAccountId ?? undefined,
19
+ version: row.version,
20
+ });
21
+ /** Entity → row for the versioned unit of work. */
22
+ export const modelToDb = (entity) => ({
23
+ id: entity.id,
24
+ name: entity.name,
25
+ currency: entity.currency,
26
+ closingDay: entity.closingDay,
27
+ dueDay: entity.dueDay,
28
+ limitAmount: entity.limit ?? null,
29
+ accountId: entity.accountId,
30
+ paymentAccountId: entity.paymentAccountId ?? null,
31
+ version: entity.version,
32
+ });
33
+ export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(CREDIT_CARD_ENTITY_TAG, modelToDb);
@@ -0,0 +1,2 @@
1
+ import { CurrencySchema } from '../models/money.js';
2
+ export const dbToModel = (row) => CurrencySchema.parse({ code: row.code, symbol: row.symbol, name: row.name, decimals: row.decimals });
@@ -0,0 +1,18 @@
1
+ import { formatAppError } from '../common/errors.js';
2
+ import { CURRENCY_RATE_ENTITY_TAG, CurrencyRateEntitySchema, } from '../models/currency-rate.js';
3
+ import * as persistence from '../logic/persistence.js';
4
+ import { BulkSetExchangeRatesOut } from '../wire/out/currency-rates.js';
5
+ export const dbToEntity = (row) => CurrencyRateEntitySchema.parse({
6
+ id: row.id,
7
+ fromCode: row.fromCode,
8
+ toCode: row.toCode,
9
+ rate: row.rate,
10
+ asOf: row.asOf,
11
+ source: row.source,
12
+ version: row.version,
13
+ });
14
+ // Identity: a versioned CurrencyRateEntity is already row-shaped.
15
+ export const modelToDb = (entity) => entity;
16
+ export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(CURRENCY_RATE_ENTITY_TAG, modelToDb);
17
+ const bulkItemToWireOut = (item) => item.status === 'error' ? { status: 'error', from: item.from, to: item.to, error: formatAppError(item.error) } : item;
18
+ export const bulkResultToWireOut = (items) => BulkSetExchangeRatesOut.parse({ items: items.map(bulkItemToWireOut) });