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:
Steve Yegge
2025-12-25 02:10:41 -08:00
parent 9c1bf7d4ea
commit cfb1196044
5 changed files with 638 additions and 0 deletions

View File

@@ -98,6 +98,16 @@ func runCook(cmd *cobra.Command, args []string) {
resolved.Steps = formula.ApplyAdvice(resolved.Steps, resolved.Advice)
}
// Apply expansion operators (gt-8tmz.3)
if resolved.Compose != nil && (len(resolved.Compose.Expand) > 0 || len(resolved.Compose.Map) > 0) {
expandedSteps, err := formula.ApplyExpansions(resolved.Steps, resolved.Compose, parser)
if err != nil {
fmt.Fprintf(os.Stderr, "Error applying expansions: %v\n", err)
os.Exit(1)
}
resolved.Steps = expandedSteps
}
// Apply prefix to proto ID if specified (bd-47qx)
protoID := resolved.Formula
if prefix != "" {