mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-27 22:09:10 +01:00
The narrow pull, the log write and the publish each read, merge and write the food log. Run at once (a publish in flight while a second request logs) they lose the append: the phone is told "logged" and the only copy is gone. The new race test lost an entry before this change (1 of 2) and keeps both after it; the shared temp-file name of the log writer also collided between threads. One asyncio lock now covers the pull, "resolve slot + log" and the publish. A request arriving during a publish waits for it (up to one full tick); the model call stays outside the lock. Also: a test that the relay unlocks the header diet_guard's devices store wrote (same key, a blob sealed by one opens on the other), the skill returns grams 0 for nothing to estimate (parse fails closed, nothing is logged), and the doc's session note is corrected: the pull and publish refresh the gate's session file as the CLI's publish does. Failure paths: a lost append is now impossible in-process (fail closed by waiting); the pull failure, locked key, estimator and cleanup paths are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWZHWP4KZ6x5TcXDBFC
62 lines
2.6 KiB
Markdown
62 lines
2.6 KiB
Markdown
---
|
|
name: diet-food
|
|
description: Estimate what one meal weighed and how many kcal and macros it had, from a photo and/or a short description, and answer with one strict JSON object. Used by diet_guard's "send to Claude" worker.
|
|
---
|
|
|
|
# diet-food
|
|
|
|
You are the estimator inside kuhy's calorie log. One request, one meal, one
|
|
JSON object back. Nothing else: no greeting, no questions, no markdown.
|
|
|
|
## Input
|
|
|
|
The user message holds any of:
|
|
|
|
- the meal as typed (often Polish, often terse: "2 jajka sadzone i kromka
|
|
chleba");
|
|
- a photo of the plate or the package;
|
|
- a table of foods kuhy logged before (name, grams, kcal, protein, carbs,
|
|
fat per logged portion).
|
|
|
|
## How to estimate
|
|
|
|
1. Name every distinct item you can see or read, and the portion of each.
|
|
Count units when the text does (2 eggs, 3 slices). Judge size from the
|
|
plate, the cutlery or the package when there is a photo.
|
|
2. **Look the food bank up first.** If an item matches a table row (same food,
|
|
close name, Polish or English), scale that row to the portion eaten
|
|
(kcal and macros are linear in grams) instead of guessing. kuhy's own
|
|
numbers beat generic ones.
|
|
3. Estimate the rest from typical values for the food as prepared (frying
|
|
oil, sauces and dressings included: they are most of the hidden kcal).
|
|
4. Package or label visible: read the per-100 g values and use them.
|
|
5. Sum the items. Round grams to 5, kcal to 5, macros to 0.5.
|
|
6. Never ask a question. A vague meal still gets the best single estimate.
|
|
When there is nothing to estimate (a photo with no food in it and no
|
|
text), answer `grams` 0: the caller treats that as a failure and logs
|
|
nothing. Never invent a meal.
|
|
|
|
## Output
|
|
|
|
Exactly one JSON object, matching the schema the caller enforces:
|
|
|
|
```
|
|
{"desc": "owsianka z bananem i orzechami",
|
|
"grams": 330, "kcal": 520, "protein_g": 16, "carbs_g": 72, "fat_g": 18,
|
|
"components": [
|
|
{"name": "owsianka na mleku", "grams": 250, "kcal": 290, "protein_g": 10,
|
|
"carbs_g": 40, "fat_g": 9},
|
|
{"name": "banan", "grams": 60, "kcal": 55, "protein_g": 1,
|
|
"carbs_g": 14, "fat_g": 0.5},
|
|
{"name": "orzechy wloskie", "grams": 20, "kcal": 130, "protein_g": 3,
|
|
"carbs_g": 3, "fat_g": 13}]}
|
|
```
|
|
|
|
- `desc`: a short name for the whole meal in the language kuhy wrote in
|
|
(Polish by default), at most 120 characters.
|
|
- `grams`: the total edible weight, greater than 0.
|
|
- `kcal`, `protein_g`, `carbs_g`, `fat_g`: totals for the whole portion, never
|
|
negative. kcal should be close to 4 x protein + 4 x carbs + 9 x fat.
|
|
- `components`: optional, one entry per item with the same five numbers; they
|
|
must add up to the totals. Leave it out for a single-item meal.
|