fix(beads): restore graceful degradation for mayor/rig fallback
When rig/.beads doesn't exist, fall back to mayor/rig/.beads (tracked beads architecture) with a warning suggesting 'bd doctor' to fix. This restores behavior that was inadvertently removed in #290, which simplified SetupRedirect but removed the fallback path. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Steve Yegge
parent
1da3e18e60
commit
34cb28e0b9
@@ -191,9 +191,19 @@ func SetupRedirect(townRoot, worktreePath string) error {
|
|||||||
|
|
||||||
rigRoot := filepath.Join(townRoot, parts[0])
|
rigRoot := filepath.Join(townRoot, parts[0])
|
||||||
rigBeadsPath := filepath.Join(rigRoot, ".beads")
|
rigBeadsPath := filepath.Join(rigRoot, ".beads")
|
||||||
|
mayorBeadsPath := filepath.Join(rigRoot, "mayor", "rig", ".beads")
|
||||||
|
|
||||||
|
// Check rig-level .beads first, fall back to mayor/rig/.beads (tracked beads architecture)
|
||||||
|
usesMayorFallback := false
|
||||||
if _, err := os.Stat(rigBeadsPath); os.IsNotExist(err) {
|
if _, err := os.Stat(rigBeadsPath); os.IsNotExist(err) {
|
||||||
return fmt.Errorf("no rig .beads found at %s", rigBeadsPath)
|
// No rig/.beads - check for mayor/rig/.beads (tracked beads architecture)
|
||||||
|
if _, err := os.Stat(mayorBeadsPath); os.IsNotExist(err) {
|
||||||
|
return fmt.Errorf("no beads found at %s or %s", rigBeadsPath, mayorBeadsPath)
|
||||||
|
}
|
||||||
|
// Using mayor fallback - warn user to run bd doctor
|
||||||
|
fmt.Fprintf(os.Stderr, "Warning: rig .beads not found at %s, using %s\n", rigBeadsPath, mayorBeadsPath)
|
||||||
|
fmt.Fprintf(os.Stderr, " Run 'bd doctor' to fix rig beads configuration\n")
|
||||||
|
usesMayorFallback = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up runtime files in .beads/ but preserve tracked files (formulas/, README.md, etc.)
|
// Clean up runtime files in .beads/ but preserve tracked files (formulas/, README.md, etc.)
|
||||||
@@ -211,18 +221,26 @@ func SetupRedirect(townRoot, worktreePath string) error {
|
|||||||
// e.g., crew/<name> (depth 2) -> ../../.beads
|
// e.g., crew/<name> (depth 2) -> ../../.beads
|
||||||
// refinery/rig (depth 2) -> ../../.beads
|
// refinery/rig (depth 2) -> ../../.beads
|
||||||
depth := len(parts) - 1 // subtract 1 for rig name itself
|
depth := len(parts) - 1 // subtract 1 for rig name itself
|
||||||
redirectPath := strings.Repeat("../", depth) + ".beads"
|
upPath := strings.Repeat("../", depth)
|
||||||
|
|
||||||
// Check if rig-level beads has a redirect (tracked beads case).
|
var redirectPath string
|
||||||
// If so, redirect directly to the final destination to avoid chains.
|
if usesMayorFallback {
|
||||||
// The bd CLI doesn't support redirect chains, so we must skip intermediate hops.
|
// Direct redirect to mayor/rig/.beads since rig/.beads doesn't exist
|
||||||
rigRedirectPath := filepath.Join(rigBeadsPath, "redirect")
|
redirectPath = upPath + "mayor/rig/.beads"
|
||||||
if data, err := os.ReadFile(rigRedirectPath); err == nil {
|
} else {
|
||||||
rigRedirectTarget := strings.TrimSpace(string(data))
|
redirectPath = upPath + ".beads"
|
||||||
if rigRedirectTarget != "" {
|
|
||||||
// Rig has redirect (e.g., "mayor/rig/.beads" for tracked beads).
|
// Check if rig-level beads has a redirect (tracked beads case).
|
||||||
// Redirect worktree directly to the final destination.
|
// If so, redirect directly to the final destination to avoid chains.
|
||||||
redirectPath = strings.Repeat("../", depth) + rigRedirectTarget
|
// The bd CLI doesn't support redirect chains, so we must skip intermediate hops.
|
||||||
|
rigRedirectPath := filepath.Join(rigBeadsPath, "redirect")
|
||||||
|
if data, err := os.ReadFile(rigRedirectPath); err == nil {
|
||||||
|
rigRedirectTarget := strings.TrimSpace(string(data))
|
||||||
|
if rigRedirectTarget != "" {
|
||||||
|
// Rig has redirect (e.g., "mayor/rig/.beads" for tracked beads).
|
||||||
|
// Redirect worktree directly to the final destination.
|
||||||
|
redirectPath = upPath + rigRedirectTarget
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user