feat: auto-resolve cross-rig IDs in bd dep add (bd-lfiu)
When `bd dep add` fails to resolve the dependency ID locally, it now checks routes.jsonl for a matching prefix and auto-converts to an external reference format (external:<project>:<id>). This allows simpler syntax like: bd dep add gt-xyz bd-abc Instead of the verbose: bd dep add gt-xyz external:beads:bd-abc New functions in routing package: - ExtractProjectFromPath: Gets project name from route path - ResolveToExternalRef: Converts foreign ID to external ref using routes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,9 +5,11 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/routing"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/storage/sqlite"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
@@ -15,6 +17,14 @@ import (
|
||||
"github.com/steveyegge/beads/internal/utils"
|
||||
)
|
||||
|
||||
// getBeadsDir returns the .beads directory path, derived from the global dbPath.
|
||||
func getBeadsDir() string {
|
||||
if dbPath != "" {
|
||||
return filepath.Dir(dbPath)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// isChildOf returns true if childID is a hierarchical child of parentID.
|
||||
// For example, "bd-abc.1" is a child of "bd-abc", and "bd-abc.1.2" is a child of "bd-abc.1".
|
||||
func isChildOf(childID, parentID string) bool {
|
||||
@@ -88,9 +98,15 @@ Examples:
|
||||
resolveArgs = &rpc.ResolveIDArgs{ID: args[1]}
|
||||
resp, err = daemonClient.ResolveID(resolveArgs)
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving dependency ID %s: %v", args[1], err)
|
||||
}
|
||||
if err := json.Unmarshal(resp.Data, &toID); err != nil {
|
||||
// Resolution failed - try auto-converting to external ref (bd-lfiu)
|
||||
beadsDir := getBeadsDir()
|
||||
if extRef := routing.ResolveToExternalRef(args[1], beadsDir); extRef != "" {
|
||||
toID = extRef
|
||||
isExternalRef = true
|
||||
} else {
|
||||
FatalErrorRespectJSON("resolving dependency ID %s: %v", args[1], err)
|
||||
}
|
||||
} else if err := json.Unmarshal(resp.Data, &toID); err != nil {
|
||||
FatalErrorRespectJSON("unmarshaling resolved ID: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -111,7 +127,14 @@ Examples:
|
||||
} else {
|
||||
toID, err = utils.ResolvePartialID(ctx, store, args[1])
|
||||
if err != nil {
|
||||
FatalErrorRespectJSON("resolving dependency ID %s: %v", args[1], err)
|
||||
// Resolution failed - try auto-converting to external ref (bd-lfiu)
|
||||
beadsDir := getBeadsDir()
|
||||
if extRef := routing.ResolveToExternalRef(args[1], beadsDir); extRef != "" {
|
||||
toID = extRef
|
||||
isExternalRef = true
|
||||
} else {
|
||||
FatalErrorRespectJSON("resolving dependency ID %s: %v", args[1], err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user