fix(sling): resolve rig path for cross-rig bead hooking

gt sling failed when hooking rig-level beads from town root because
bd update doesn't support cross-database routing like bd show does.

The fix adds a ResolveHookDir helper that:
1. Extracts the prefix from bead ID (e.g., "ap-xxx" → "ap-")
2. Looks up the rig path from routes.jsonl
3. Falls back to townRoot if prefix not found

Also removes the BEADS_DIR environment override which was preventing
routing from working correctly.

Fixes #148
This commit is contained in:
mayor
2026-01-05 08:32:42 -05:00
committed by Steve Yegge
parent 201ef3a9c8
commit 9cb14cc41a
4 changed files with 270 additions and 27 deletions
+57
View File
@@ -190,3 +190,60 @@ func FindConflictingPrefixes(beadsDir string) (map[string][]string, error) {
return conflicts, nil
}
// ExtractPrefix extracts the prefix from a bead ID.
// For example, "ap-qtsup.16" returns "ap-", "hq-cv-abc" returns "hq-".
// Returns empty string if no valid prefix found (empty input, no hyphen,
// or hyphen at position 0 which would indicate an invalid prefix).
func ExtractPrefix(beadID string) string {
if beadID == "" {
return ""
}
idx := strings.Index(beadID, "-")
if idx <= 0 {
return ""
}
return beadID[:idx+1]
}
// GetRigPathForPrefix returns the rig path for a given bead ID prefix.
// The townRoot should be the Gas Town root directory (e.g., ~/gt).
// Returns the full absolute path to the rig directory, or empty string if not found.
// For town-level beads (path="."), returns townRoot.
func GetRigPathForPrefix(townRoot, prefix string) string {
beadsDir := filepath.Join(townRoot, ".beads")
routes, err := LoadRoutes(beadsDir)
if err != nil || routes == nil {
return ""
}
for _, r := range routes {
if r.Prefix == prefix {
if r.Path == "." {
return townRoot // Town-level beads
}
return filepath.Join(townRoot, r.Path)
}
}
return ""
}
// ResolveHookDir determines the directory for running bd update on a bead.
// Since bd update doesn't support routing or redirects, we must resolve the
// actual rig directory from the bead's prefix. hookWorkDir is only used as
// a fallback if prefix resolution fails.
func ResolveHookDir(townRoot, beadID, hookWorkDir string) string {
// Always try prefix resolution first - bd update needs the actual rig dir
prefix := ExtractPrefix(beadID)
if rigPath := GetRigPathForPrefix(townRoot, prefix); rigPath != "" {
return rigPath
}
// Fallback to hookWorkDir if provided
if hookWorkDir != "" {
return hookWorkDir
}
return townRoot
}