feat: implement Step.Condition evaluation in bd cook (bd-7zka.1)

Add compile-time step filtering based on formula variables:
- New EvaluateStepCondition function for {{var}} truthy and equality checks
- FilterStepsByCondition to exclude steps based on conditions
- Integration into pour, wisp, and mol bond commands
- Supports: {{var}}, {{var}} == value, {{var}} != value

Steps with conditions that evaluate to false are excluded from the
cooked formula, along with their children.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
beads/crew/emma
2025-12-31 00:33:11 -08:00
committed by Steve Yegge
parent 82611834df
commit ee34a74e90
7 changed files with 513 additions and 8 deletions

View File

@@ -208,12 +208,13 @@ func runMolBond(cmd *cobra.Command, args []string) {
// Resolve both operands - can be issue IDs or formula names
// Formula names are cooked inline to in-memory subgraphs
subgraphA, cookedA, err := resolveOrCookToSubgraph(ctx, store, args[0])
// Pass vars for step condition filtering (bd-7zka.1)
subgraphA, cookedA, err := resolveOrCookToSubgraph(ctx, store, args[0], vars)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
subgraphB, cookedB, err := resolveOrCookToSubgraph(ctx, store, args[1])
subgraphB, cookedB, err := resolveOrCookToSubgraph(ctx, store, args[1], vars)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
@@ -569,8 +570,9 @@ func resolveOrDescribe(ctx context.Context, s storage.Storage, operand string) (
// If it's an issue, loads the subgraph from DB. If it's a formula, cooks inline to subgraph.
// Returns the subgraph, whether it was cooked from formula, and any error.
//
// The vars parameter is used for step condition filtering (bd-7zka.1).
// This implements gt-4v1eo: formulas are cooked to in-memory subgraphs (no DB storage).
func resolveOrCookToSubgraph(ctx context.Context, s storage.Storage, operand string) (*TemplateSubgraph, bool, error) {
func resolveOrCookToSubgraph(ctx context.Context, s storage.Storage, operand string, vars map[string]string) (*TemplateSubgraph, bool, error) {
// First, try to resolve as an existing issue
id, err := utils.ResolvePartialID(ctx, s, operand)
if err == nil {
@@ -599,7 +601,8 @@ func resolveOrCookToSubgraph(ctx context.Context, s storage.Storage, operand str
}
// Try to cook formula inline to in-memory subgraph
subgraph, err := resolveAndCookFormula(operand, nil)
// Pass vars for step condition filtering (bd-7zka.1)
subgraph, err := resolveAndCookFormulaWithVars(operand, nil, vars)
if err != nil {
return nil, false, fmt.Errorf("'%s' not found as issue or formula: %w", operand, err)
}