fix: allow vars with formula-on-bead slings (#966)
This commit is contained in:
@@ -131,11 +131,6 @@ func runSling(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
townBeadsDir := filepath.Join(townRoot, ".beads")
|
townBeadsDir := filepath.Join(townRoot, ".beads")
|
||||||
|
|
||||||
// --var is only for standalone formula mode, not formula-on-bead mode
|
|
||||||
if slingOnTarget != "" && len(slingVars) > 0 {
|
|
||||||
return fmt.Errorf("--var cannot be used with --on (formula-on-bead mode doesn't support variables)")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Batch mode detection: multiple beads with rig target
|
// Batch mode detection: multiple beads with rig target
|
||||||
// Pattern: gt sling gt-abc gt-def gt-ghi gastown
|
// Pattern: gt sling gt-abc gt-def gt-ghi gastown
|
||||||
// When len(args) > 2 and last arg is a rig, sling each bead to its own polecat
|
// When len(args) > 2 and last arg is a rig, sling each bead to its own polecat
|
||||||
@@ -191,8 +186,8 @@ func runSling(cmd *cobra.Command, args []string) error {
|
|||||||
// Determine target agent (self or specified)
|
// Determine target agent (self or specified)
|
||||||
var targetAgent string
|
var targetAgent string
|
||||||
var targetPane string
|
var targetPane string
|
||||||
var hookWorkDir string // Working directory for running bd hook commands
|
var hookWorkDir string // Working directory for running bd hook commands
|
||||||
var hookSetAtomically bool // True if hook was set during polecat spawn (skip redundant update)
|
var hookSetAtomically bool // True if hook was set during polecat spawn (skip redundant update)
|
||||||
|
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
target := args[1]
|
target := args[1]
|
||||||
@@ -434,7 +429,7 @@ func runSling(cmd *cobra.Command, args []string) error {
|
|||||||
if formulaName != "" {
|
if formulaName != "" {
|
||||||
fmt.Printf(" Instantiating formula %s...\n", formulaName)
|
fmt.Printf(" Instantiating formula %s...\n", formulaName)
|
||||||
|
|
||||||
result, err := InstantiateFormulaOnBead(formulaName, beadID, info.Title, hookWorkDir, townRoot, false)
|
result, err := InstantiateFormulaOnBead(formulaName, beadID, info.Title, hookWorkDir, townRoot, false, slingVars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("instantiating formula %s: %w", formulaName, err)
|
return fmt.Errorf("instantiating formula %s: %w", formulaName, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,8 @@ exit /b 0
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test the helper function directly
|
// Test the helper function directly
|
||||||
result, err := InstantiateFormulaOnBead("mol-polecat-work", "gt-abc123", "Test Bug Fix", "", townRoot, false)
|
extraVars := []string{"branch=polecat/furiosa/gt-abc123"}
|
||||||
|
result, err := InstantiateFormulaOnBead("mol-polecat-work", "gt-abc123", "Test Bug Fix", "", townRoot, false, extraVars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("InstantiateFormulaOnBead failed: %v", err)
|
t.Fatalf("InstantiateFormulaOnBead failed: %v", err)
|
||||||
}
|
}
|
||||||
@@ -145,6 +146,9 @@ exit /b 0
|
|||||||
if !strings.Contains(logContent, "mol wisp mol-polecat-work") {
|
if !strings.Contains(logContent, "mol wisp mol-polecat-work") {
|
||||||
t.Errorf("mol wisp command not found in log:\n%s", logContent)
|
t.Errorf("mol wisp command not found in log:\n%s", logContent)
|
||||||
}
|
}
|
||||||
|
if !strings.Contains(logContent, "--var branch=polecat/furiosa/gt-abc123") {
|
||||||
|
t.Errorf("extra vars not passed to wisp command:\n%s", logContent)
|
||||||
|
}
|
||||||
if !strings.Contains(logContent, "mol bond") {
|
if !strings.Contains(logContent, "mol bond") {
|
||||||
t.Errorf("mol bond command not found in log:\n%s", logContent)
|
t.Errorf("mol bond command not found in log:\n%s", logContent)
|
||||||
}
|
}
|
||||||
@@ -219,7 +223,7 @@ exit /b 0
|
|||||||
_ = os.Chdir(townRoot)
|
_ = os.Chdir(townRoot)
|
||||||
|
|
||||||
// Test with skipCook=true
|
// Test with skipCook=true
|
||||||
_, err := InstantiateFormulaOnBead("mol-polecat-work", "gt-test", "Test", "", townRoot, true)
|
_, err := InstantiateFormulaOnBead("mol-polecat-work", "gt-test", "Test", "", townRoot, true, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("InstantiateFormulaOnBead failed: %v", err)
|
t.Fatalf("InstantiateFormulaOnBead failed: %v", err)
|
||||||
}
|
}
|
||||||
@@ -295,11 +299,11 @@ func TestSlingHookRawBeadFlag(t *testing.T) {
|
|||||||
// When formulaName is empty and target contains "/polecats/", mol-polecat-work should be applied.
|
// When formulaName is empty and target contains "/polecats/", mol-polecat-work should be applied.
|
||||||
func TestAutoApplyLogic(t *testing.T) {
|
func TestAutoApplyLogic(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
formulaName string
|
formulaName string
|
||||||
hookRawBead bool
|
hookRawBead bool
|
||||||
targetAgent string
|
targetAgent string
|
||||||
wantAutoApply bool
|
wantAutoApply bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "bare bead to polecat - should auto-apply",
|
name: "bare bead to polecat - should auto-apply",
|
||||||
@@ -416,7 +420,7 @@ exit /b 0
|
|||||||
t.Cleanup(func() { _ = os.Chdir(cwd) })
|
t.Cleanup(func() { _ = os.Chdir(cwd) })
|
||||||
_ = os.Chdir(townRoot)
|
_ = os.Chdir(townRoot)
|
||||||
|
|
||||||
_, err := InstantiateFormulaOnBead("mol-polecat-work", "gt-abc123", "My Cool Feature", "", townRoot, false)
|
_, err := InstantiateFormulaOnBead("mol-polecat-work", "gt-abc123", "My Cool Feature", "", townRoot, false, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("InstantiateFormulaOnBead: %v", err)
|
t.Fatalf("InstantiateFormulaOnBead: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ func runBatchSling(beadIDs []string, rigName string, townBeadsDir string) error
|
|||||||
beadToHook := beadID
|
beadToHook := beadID
|
||||||
attachedMoleculeID := ""
|
attachedMoleculeID := ""
|
||||||
if formulaCooked {
|
if formulaCooked {
|
||||||
result, err := InstantiateFormulaOnBead(formulaName, beadID, info.Title, hookWorkDir, townRoot, true)
|
result, err := InstantiateFormulaOnBead(formulaName, beadID, info.Title, hookWorkDir, townRoot, true, slingVars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf(" %s Could not apply formula: %v (hooking raw bead)\n", style.Dim.Render("Warning:"), err)
|
fmt.Printf(" %s Could not apply formula: %v (hooking raw bead)\n", style.Dim.Render("Warning:"), err)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -475,9 +475,10 @@ type FormulaOnBeadResult struct {
|
|||||||
// - hookWorkDir: working directory for bd commands (polecat's worktree)
|
// - hookWorkDir: working directory for bd commands (polecat's worktree)
|
||||||
// - townRoot: the town root directory
|
// - townRoot: the town root directory
|
||||||
// - skipCook: if true, skip cooking (for batch mode optimization where cook happens once)
|
// - skipCook: if true, skip cooking (for batch mode optimization where cook happens once)
|
||||||
|
// - extraVars: additional --var values supplied by the user
|
||||||
//
|
//
|
||||||
// Returns the wisp root ID which should be hooked.
|
// Returns the wisp root ID which should be hooked.
|
||||||
func InstantiateFormulaOnBead(formulaName, beadID, title, hookWorkDir, townRoot string, skipCook bool) (*FormulaOnBeadResult, error) {
|
func InstantiateFormulaOnBead(formulaName, beadID, title, hookWorkDir, townRoot string, skipCook bool, extraVars []string) (*FormulaOnBeadResult, error) {
|
||||||
// Route bd mutations (wisp/bond) to the correct beads context for the target bead.
|
// Route bd mutations (wisp/bond) to the correct beads context for the target bead.
|
||||||
formulaWorkDir := beads.ResolveHookDir(townRoot, beadID, hookWorkDir)
|
formulaWorkDir := beads.ResolveHookDir(townRoot, beadID, hookWorkDir)
|
||||||
|
|
||||||
@@ -494,7 +495,11 @@ func InstantiateFormulaOnBead(formulaName, beadID, title, hookWorkDir, townRoot
|
|||||||
// Step 2: Create wisp with feature and issue variables from bead
|
// Step 2: Create wisp with feature and issue variables from bead
|
||||||
featureVar := fmt.Sprintf("feature=%s", title)
|
featureVar := fmt.Sprintf("feature=%s", title)
|
||||||
issueVar := fmt.Sprintf("issue=%s", beadID)
|
issueVar := fmt.Sprintf("issue=%s", beadID)
|
||||||
wispArgs := []string{"--no-daemon", "mol", "wisp", formulaName, "--var", featureVar, "--var", issueVar, "--json"}
|
wispArgs := []string{"--no-daemon", "mol", "wisp", formulaName, "--var", featureVar, "--var", issueVar}
|
||||||
|
for _, variable := range extraVars {
|
||||||
|
wispArgs = append(wispArgs, "--var", variable)
|
||||||
|
}
|
||||||
|
wispArgs = append(wispArgs, "--json")
|
||||||
wispCmd := exec.Command("bd", wispArgs...)
|
wispCmd := exec.Command("bd", wispArgs...)
|
||||||
wispCmd.Dir = formulaWorkDir
|
wispCmd.Dir = formulaWorkDir
|
||||||
wispCmd.Env = append(os.Environ(), "GT_ROOT="+townRoot)
|
wispCmd.Env = append(os.Environ(), "GT_ROOT="+townRoot)
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ func EnsureGitignorePatterns(worktreePath string) error {
|
|||||||
".runtime/",
|
".runtime/",
|
||||||
".claude/",
|
".claude/",
|
||||||
".logs/",
|
".logs/",
|
||||||
|
".beads/",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read existing gitignore content
|
// Read existing gitignore content
|
||||||
|
|||||||
Reference in New Issue
Block a user