Files
ryan 8f02318542 Mirror YNAB budget into Postgres with delta sync and change log
YNAB has no event feed, so keep a local copy in ynab_* tables synced via
server_knowledge delta requests: full download on first run, deltas every
YNAB_SYNC_INTERVAL seconds and on demand before each tool call, full
resync daily. Each sync diffs against the mirror and appends real edits
(transactions, assignments, renames) to ynab_changes, the edit history
YNAB doesn't keep.

Agent YNAB tools now answer from the mirror: budget summary (spending
computed from transactions, since YNAB's month activity nets in credit
card payment categories), account balances, transaction search with
splits expanded, spending reports by category/payee/account/month,
category budget, and recent changes. Adds an admin-only read-only
ynab_sql tool guarded by a sqlglot allowlist (scope-resolved tables, no
dangerous functions), a READ ONLY transaction, a timeout, and a row cap.

Replaces utils/ynab_service.py and drops the unused ynab SDK.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 17:32:38 -04:00

23 lines
462 B
Python

"""Run one YNAB sync: ``python -m blueprints.ynab [--full]``."""
import asyncio
import sys
from tortoise import Tortoise
from config.db import TORTOISE_CONFIG
from .sync import sync_ynab
async def main(full: bool) -> None:
await Tortoise.init(config=TORTOISE_CONFIG)
try:
print(await sync_ynab(full=full))
finally:
await Tortoise.close_connections()
if __name__ == "__main__":
asyncio.run(main(full="--full" in sys.argv))