Skip to content

Add update_recipe tool to edit recipes in place - #81

Open
paultristanwagner wants to merge 1 commit into
rwestergren:mainfrom
paultristanwagner:edit-recipe
Open

paultristanwagner wants to merge 1 commit into
rwestergren:mainfrom
paultristanwagner:edit-recipe

Conversation

@paultristanwagner

Copy link
Copy Markdown

All code in this PR was written by an AI agent (Claude Opus 5.5) working with me; I directed it and tested the results on my own account. Feel free to take, change or drop any part of it.

Part of #73.

Adds an update_recipe tool to edit a recipe in place: rename it, change
its ingredients or amounts, resize its serving, or change its notes.
update_custom_food refuses recipes, because their nutrients come from
the ingredients.

The app edits a recipe the same way update_custom_food edits a food: it
re-sends the whole object to POST /api/v2/add_food with its id. It recalculates the per-100 g
nutrients itself before sending; the server stores what it gets. Verified
against the live API with throwaway recipes:

  • new ingredients replace the old list (they get new ingredient ids)
  • measures keep their ids
  • the translation's name follows name
  • the server refuses a save that drops the g measure
    ("Cannot remove the grams measure from a gram-based food")

Changes:

  • client: the ingredient resolution and nutrient math in
    create_recipe moved into _recipe_ingredients without changes, so both
    methods share it. update_recipe(food_id, *, name, ingredients, serving_grams, comments) edits under the per-food lock:
    • the "full recipe" measure follows the new batch weight
    • a default serving that was the whole batch stays the whole batch
    • any other serving keeps its weight unless serving_grams is given
    • saved meals are refused, because their measures are serving-based
  • server: update_recipe tool. add_recipe's ingredient parsing moved
    into _parse_ingredients, which both tools use. get_food_details now
    returns a recipe's ingredients, in the shape these tools take, so they
    can be read before editing.
  • README: tool table row.

https://claude.ai/code/session_01MCJFDo71qoSqTRtcGfkpXJ

The app edits a recipe by re-sending it whole to /api/v2/add_food with
its id, with the nutrient profile recalculated client side; the server
doesn't recalculate. update_recipe does the same, sharing the ingredient
and nutrient math with create_recipe. The "full recipe" measure follows
the new batch weight, a whole-batch serving stays whole-batch, and the g
measure is kept (the server refuses a save that drops it).
get_food_details now returns a recipe's ingredients so they can be read
before editing. Verified against the live API.

Claude-Session: https://claude.ai/code/session_01MCJFDo71qoSqTRtcGfkpXJ

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant