Fund: Live hledger data integration

t-654·WorkTask·
·
·
·Omni/Fund.hs
Created5 hours ago·Updated5 hours ago

Description

Edit

Wire live hledger data into the Fund dashboard (Omni/Fund/Web.hs) so projections use actual balance sheet values instead of hardcoded defaults.

Background

The Fund dashboard (Omni/Fund/Web.hs) currently serves an all-client-side HTML page with hardcoded JSON defaults (btcStack, btcPrice, strdPosition, salary, etc). The goal is to add a live data endpoint that reads from the user's hledger journals and pre-seeds the dashboard with real values on page load.

Ben's hledger journals live in ~/fund/ (ledger.journal as root, includes many sub-journals). There is already a Haskell hledger query module at Omni/Agent/Tools/Hledger.hs that shells out to the hledger binary and returns parsed results.

What to build

1. New module: Omni/Fund/Ledger.hs

  • Functions to extract key financial metrics from hledger:
  • btcStack (BTC total across all asset accounts)
  • cashUsd (cash balance across as:*:cash accounts)
  • creditBalance (total liabilities li:*)
  • monthlyIncome (avg monthly income from in:* last 3 months)
  • monthlyNeeds (avg monthly from ex:*:need last 3 months)
  • monthlyWants (avg monthly from ex:*:want last 3 months)
  • Use the hledger binary (same approach as Omni/Agent/Tools/Hledger.hs) or hledger-lib if already a dep
  • Caching required: journals are large. Cache results in-process (IORef or MVar with TTL ~5 min) so repeated page loads do not re-run hledger each time.

2. New route in Omni/Fund/Web.hs: GET /fund/live

  • Returns JSON with live metrics (same shape as the 'defaults' object)
  • The Lucid page should fetch /fund/live on load (via fetch()) and merge into defaults, overriding only keys present in the response
  • If /fund/live fails or is slow, fall back to hardcoded defaults gracefully

3. Routing: The Fund app is wired into the main Omni web server. Check Omni/Web.hs or the main app entry point for route composition and add /fund/live there.

Key files

  • Omni/Fund/Web.hs -- the dashboard server (main target)
  • Omni/Agent/Tools/Hledger.hs -- existing hledger shell-out utilities to reference/reuse
  • ~/fund/ledger.journal -- root journal file (pass to hledger -f)
  • Omni/Web.hs or Main.hs -- check for route composition

Notes

  • Account naming: ex (expenses), as (assets), li (liabilities), in (income)
  • BTC amounts may be in BTC or sats depending on account; normalize to BTC
  • Shell out to hledger binary rather than linking hledger-lib unless already a dep
  • The caching layer is important -- hledger with many journals can take 1-2 seconds

Timeline (2)

💬[human]5 hours ago

To start port over the dashboard view ~/fund/bin/hledger-overview.hs

The main goal is to reproduce that TUI dashboard in a web app, and then later add the model and projections that we already have in Omni/Fund