An AI agent handles a lot of my training and diet planning, and it needs good data to do that. Food Log is how I get it: a phone app where logging a day takes seconds, and a single command that hands the whole history to the agent. I use it every day. The repository is private for now, so there’s no source link here.


Getting the data to the agent
- Free text, not calorie counts. Each day is one note with breakfast, lunch and dinner headings. Logging stays quick enough to keep up, and the agent reads “chicken wrap, apple, two beers” without needing a database of foods.
- One command.
npm run pullfetches everything from the app and writes a markdown log, plus the raw rows as JSON. The log opens with the trend weight and its rate of change over 1 week, 2 weeks, 4 weeks and 3 months, then lists each day’s weight and food, newest first. - Weekly reviews. The agent reads the markdown file and adjusts the plan from what I actually ate and how my weight moved.
- Honest rates. Rates are marked as early estimates until there’s enough history, so the agent doesn’t over-read a few days of noise.
Phone
- Phone app
Cloudflare
- Worker
- D1 database
My computer
npm run pull- log.md + JSON
- AI agent
- Plan training and diet changes, back to me
npm run pull fetches the history to my computer, the agent reads it, and the plan comes back to me.Engineering
- Offline-first sync. Every device keeps its data in
localStorageand the UI never waits on the network. Changes go into an outbox and upload toPOST /api/sync, which returns the full snapshot. Each row carries anupdated_atversion and the server keeps the newest one in a single SQL upsert, so an edit queued offline can’t overwrite a newer one from another device. Deletes are soft, so they sync like any other edit. - Setup without a login. Auth is one shared key. To set up a new phone I scan a QR code that opens
/#key=.... The key sits in the URL fragment, which browsers never send to the server, so it stays out of request logs. The app saves it and strips it from the address bar.
Trend weight
I built the trend line in the style of Libra, the Android weight tracker. Libra’s own explanation says it was inspired by John Walker’s The Hacker’s Diet, which is where the method comes from: an exponentially smoothed moving average of the daily weigh-ins. Food Log can import a Libra CSV export, so an existing history carries over.
A single weigh-in can swing a kilogram on water alone, so each one pulls the trend only 10% of the way towards it. That’s the Hacker’s Diet’s 10% smoothing. Libra scales the pull by the time since the last entry, and Food Log does the same: a gap of n days applies n days of smoothing, so missed mornings don’t make the trend lag. Libra lets you change the smoothing; Food Log fixes it at 10% a day. The weekly rate is the slope of a least-squares line through the trend, and the Hacker’s Diet Online also fits a straight line to find its rate of change.
Stack
On the phone
An installable web app (PWA)
- React 19
- TypeScript
- Vite
- Service worker
- localStorage + outbox
- SVG chart
On Cloudflare
One Worker and one database
- Worker
- Static assets
- D1 (SQLite)
- 4 SQL migrations
- Wrangler
On my computer
Hands the data to the agent
- Node script
- log.md
- export.json
- QR setup link
shared TypeScript Row types are used in all three places. The trend maths is shared by the app and the pull script.
On the phone. React 19 and TypeScript, built with Vite. It installs as a web app: a service worker keeps the app shell available offline, loading the page from the network first so a new deploy shows up straight away, and the API is never cached. Entries live in localStorage until they sync, and the weight chart is hand-written SVG.
On Cloudflare. One Worker serves the built app and a small API, POST /api/sync and GET /api/export, both behind the shared key. The key is checked by comparing SHA-256 digests in constant time. D1 holds three tables, notes, weights and settings, created by four SQL migrations. npm run deploy builds the app, applies the migrations and deploys with Wrangler. In development the Cloudflare Vite plugin runs the Worker and a local D1 database next to the dev server.
On my computer. npm run pull is a Node script that fetches the export and writes data/log.md and data/export.json. It imports the same trend code as the app, so the numbers in the log match the ones on my phone. The agent reads the markdown file for the weekly review.
I built it with AI coding agents under my direction: I set the requirements and review the results, and the agents wrote most of the code.
Cloudflare and Cloudflare Workers are trademarks of Cloudflare, Inc. This project isn't affiliated with or endorsed by Cloudflare. Libra is made by Daniel Cachapa.