feat: Implement control flow operators (gt-8tmz.4)

Add loop, branch, and gate operators for formula step transformation:

- LoopSpec: Fixed-count loops expand body N times with chained iterations.
  Conditional loops expand once with runtime metadata labels.
- BranchRule: Fork-join patterns wire dependencies for parallel paths.
- GateRule: Adds condition labels for runtime evaluation before steps.

Types added to types.go:
- LoopSpec (count/until/max/body)
- BranchRule (from/steps/join)
- GateRule (before/condition)
- Loop field on Step
- Branch/Gate arrays on ComposeRules

New controlflow.go with ApplyLoops, ApplyBranches, ApplyGates, and
ApplyControlFlow convenience function. Wired into cook.go before
advice and expansion operators.

🤖 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 14:51:37 -08:00
parent 2ff17686d0
commit 4f065024b5
4 changed files with 852 additions and 0 deletions

View File

@@ -93,6 +93,15 @@ func runCook(cmd *cobra.Command, args []string) {
os.Exit(1)
}
// Apply control flow operators (gt-8tmz.4) - loops, branches, gates
// This must happen before advice and expansions so they can act on expanded loop steps
controlFlowSteps, err := formula.ApplyControlFlow(resolved.Steps, resolved.Compose)
if err != nil {
fmt.Fprintf(os.Stderr, "Error applying control flow: %v\n", err)
os.Exit(1)
}
resolved.Steps = controlFlowSteps
// Apply advice transformations (gt-8tmz.2)
if len(resolved.Advice) > 0 {
resolved.Steps = formula.ApplyAdvice(resolved.Steps, resolved.Advice)