feat: Add source tracing metadata to cooked steps (gt-8tmz.18)
Add SourceFormula and SourceLocation fields to track where each step came from during the cooking process. This enables debugging of complex compositions with inheritance, expansion, and advice. Changes: - Added SourceFormula and SourceLocation fields to Step struct (formula/types.go) - Added same fields to Issue struct (types/types.go) - Added SetSourceInfo() to parser.go - sets source on all steps after parsing - Updated cook.go to copy source fields from Step to Issue - Updated dry-run output to display source info: [from: formula@location] - Updated advice.go to set source on advice-generated steps - Updated controlflow.go to preserve source on loop-expanded steps - Updated expand.go to preserve source on template-expanded steps The source location format is: - steps[N] - regular step at index N - steps[N].children[M] - child step - steps[N].loop.body[M] - loop body step - template[N] - expansion template step - advice - step inserted by advice transformation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -92,6 +92,10 @@ func (p *Parser) ParseFile(path string) (*Formula, error) {
|
||||
}
|
||||
|
||||
formula.Source = absPath
|
||||
|
||||
// Set source tracing info on all steps (gt-8tmz.18)
|
||||
SetSourceInfo(formula)
|
||||
|
||||
p.cache[absPath] = formula
|
||||
|
||||
// Also cache by name for extends resolution
|
||||
@@ -393,3 +397,30 @@ func ApplyDefaults(formula *Formula, values map[string]string) map[string]string
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// SetSourceInfo sets SourceFormula and SourceLocation on all steps in a formula.
|
||||
// Called after parsing to enable source tracing during cooking (gt-8tmz.18).
|
||||
func SetSourceInfo(formula *Formula) {
|
||||
setSourceInfoRecursive(formula.Steps, formula.Formula, "steps")
|
||||
// Also set source info on template steps for expansion formulas
|
||||
setSourceInfoRecursive(formula.Template, formula.Formula, "template")
|
||||
}
|
||||
|
||||
// setSourceInfoRecursive recursively sets source info on steps.
|
||||
func setSourceInfoRecursive(steps []*Step, formulaName, pathPrefix string) {
|
||||
for i, step := range steps {
|
||||
step.SourceFormula = formulaName
|
||||
step.SourceLocation = fmt.Sprintf("%s[%d]", pathPrefix, i)
|
||||
|
||||
if len(step.Children) > 0 {
|
||||
childPath := fmt.Sprintf("%s[%d].children", pathPrefix, i)
|
||||
setSourceInfoRecursive(step.Children, formulaName, childPath)
|
||||
}
|
||||
|
||||
// Handle loop body steps
|
||||
if step.Loop != nil && len(step.Loop.Body) > 0 {
|
||||
bodyPath := fmt.Sprintf("%s[%d].loop.body", pathPrefix, i)
|
||||
setSourceInfoRecursive(step.Loop.Body, formulaName, bodyPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user