Skip to content

fix(shopping-list): expand recipe references at every depth - #145

Merged
dubadub merged 1 commit into
mainfrom
fix/shopping-list-nested-refs
Sep 24, 2026
Merged

dubadub merged 1 commit into
mainfrom
fix/shopping-list-nested-refs

Conversation

@dubadub

@dubadub dubadub commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Problem

Same bug as cooklang/cookcli#509, one level worse. RecipeReferenceResolver.resolve() only read the references in the file it was given, and the native generate_shopping_list calls add_recipe(.., false), which skips reference ingredients. So:

  • Add recipe: its direct references were included; anything below them was silently dropped.
  • Add menu: the menu's recipes were included, but none of their references (addMenu supported grandchildren via includedRefs, but nothing ever filled it). A menu → dinner → sauce → prep chain lost both the sauce and the prep.

Fix

  • resolve() recurses and returns a tree (children on ResolvedRecipeReference, omitted when empty so existing callers/tests are unchanged). Nested paths resolve against the workspace root, like CookCLI. A reference back to a recipe already being expanded is skipped with a warning (so a cycle can't count twice); depth is capped at 100 (CookCLI's MAX_REFERENCE_DEPTH).
  • Each nested {N%servings} resolves against its own recipe's servings, relative to its parent; flattenReferences() multiplies scales down the chain.
  • addRecipe / addMenu persist the full tree (the .shopping-list format and flattenForGeneration were already recursive).
  • The AI generateShoppingList tool's preview uses flattenReferences for recipes and menus.

Tests

New: 4-level chain, nested %servings, cycle, flattenReferences, service nesting for addRecipe/addMenu, tool preview for nested recipe + menu. packages/cooklang: 538 passing; tsc -b and eslint clean.

Not tested in the running app yet.

RecipeReferenceResolver only read the references in one file, and the
native generator skips reference ingredients, so a shopping list lost
everything more than one reference deep: a menu -> dinner -> sauce ->
prep chain dropped the sauce and the prep (cooklang/cookcli#509, and a
level shallower than the CLI ever was).

resolve() now recurses into each referenced recipe (paths against the
workspace root, as in CookCLI), skipping a reference back to a recipe
already being expanded and stopping at 100 levels. addRecipe/addMenu
persist the full tree, and the AI tool's preview flattens it with
multipliers applied down the chain.
@dubadub
dubadub merged commit 8ea79d2 into main Sep 24, 2026
2 checks passed
@dubadub
dubadub deleted the fix/shopping-list-nested-refs branch September 24, 2026 17:58
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