Repository navigation
fix(shopping-list): expand recipe references at every depth - #145
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Same bug as cooklang/cookcli#509, one level worse.
RecipeReferenceResolver.resolve()only read the references in the file it was given, and the nativegenerate_shopping_listcallsadd_recipe(.., false), which skips reference ingredients. So:addMenusupported grandchildren viaincludedRefs, 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 (childrenonResolvedRecipeReference, 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'sMAX_REFERENCE_DEPTH).{N%servings}resolves against its own recipe'sservings, relative to its parent;flattenReferences()multiplies scales down the chain.addRecipe/addMenupersist the full tree (the.shopping-listformat andflattenForGenerationwere already recursive).generateShoppingListtool's preview usesflattenReferencesfor recipes and menus.Tests
New: 4-level chain, nested
%servings, cycle,flattenReferences, service nesting foraddRecipe/addMenu, tool preview for nested recipe + menu.packages/cooklang: 538 passing;tsc -band eslint clean.Not tested in the running app yet.