Implement expansion operators for formula composition (gt-8tmz.3)
Add expand and map operators that apply macro-style template expansion:
- expand(target, template) - replace a single step with expanded template
- map(select, template) - replace all matching steps with expanded template
The expansion formula type (e.g., rule-of-five) uses a template field with
{target} and {target.description} placeholders that are substituted when
applied to target steps.
Changes:
- Add Template field to Formula struct for expansion formulas
- Add ExpandRule and MapRule types to ComposeRules
- Implement ApplyExpansions in new expand.go
- Add LoadByName method to Parser for loading expansion formulas
- Integrate expansion into bd cook command
- Add comprehensive tests
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -209,6 +209,12 @@ func (p *Parser) loadFormula(name string) (*Formula, error) {
|
||||
return nil, fmt.Errorf("formula %q not found in search paths", name)
|
||||
}
|
||||
|
||||
// LoadByName loads a formula by name from search paths.
|
||||
// This is the public API for loading formulas used by expansion operators.
|
||||
func (p *Parser) LoadByName(name string) (*Formula, error) {
|
||||
return p.loadFormula(name)
|
||||
}
|
||||
|
||||
// mergeComposeRules merges two compose rule sets.
|
||||
func mergeComposeRules(base, overlay *ComposeRules) *ComposeRules {
|
||||
if overlay == nil {
|
||||
@@ -221,6 +227,8 @@ func mergeComposeRules(base, overlay *ComposeRules) *ComposeRules {
|
||||
result := &ComposeRules{
|
||||
BondPoints: append([]*BondPoint{}, base.BondPoints...),
|
||||
Hooks: append([]*Hook{}, base.Hooks...),
|
||||
Expand: append([]*ExpandRule{}, base.Expand...),
|
||||
Map: append([]*MapRule{}, base.Map...),
|
||||
}
|
||||
|
||||
// Add overlay bond points (override by ID)
|
||||
@@ -239,6 +247,12 @@ func mergeComposeRules(base, overlay *ComposeRules) *ComposeRules {
|
||||
// Add overlay hooks (append, no override)
|
||||
result.Hooks = append(result.Hooks, overlay.Hooks...)
|
||||
|
||||
// Add overlay expand rules (append, no override)
|
||||
result.Expand = append(result.Expand, overlay.Expand...)
|
||||
|
||||
// Add overlay map rules (append, no override)
|
||||
result.Map = append(result.Map, overlay.Map...)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user