role: consolidate RoleContext into RoleInfo

Unified the two overlapping role detection structs:
- RoleContext (prime.go) is now a type alias for RoleInfo
- detectRole() now returns RoleInfo directly
- Added WorkDir field to RoleInfo
- GetRoleWithContext now populates WorkDir

This eliminates code duplication between prime.go and role.go while
maintaining backward compatibility through the type alias.
This commit is contained in:
Steve Yegge
2025-12-25 02:11:36 -08:00
parent 0280a6f945
commit 8f54d6c3c5
2 changed files with 11 additions and 11 deletions

View File

@@ -18,6 +18,8 @@ const (
)
// RoleInfo contains information about a role and its detection source.
// This is the canonical struct for role detection - used by both GetRole()
// and detectRole() functions.
type RoleInfo struct {
Role Role `json:"role"`
Source string `json:"source"` // "env", "cwd", or "explicit"
@@ -28,6 +30,7 @@ type RoleInfo struct {
CwdRole Role `json:"cwd_role,omitempty"` // Role detected from cwd
Mismatch bool `json:"mismatch,omitempty"` // True if env != cwd detection
TownRoot string `json:"town_root,omitempty"`
WorkDir string `json:"work_dir,omitempty"` // Current working directory
}
var roleCmd = &cobra.Command{
@@ -131,6 +134,7 @@ func GetRole() (RoleInfo, error) {
func GetRoleWithContext(cwd, townRoot string) (RoleInfo, error) {
info := RoleInfo{
TownRoot: townRoot,
WorkDir: cwd,
}
// Check environment variable first
@@ -155,7 +159,7 @@ func GetRoleWithContext(cwd, townRoot string) (RoleInfo, error) {
info.Mismatch = true
}
} else {
// Fall back to cwd detection
// Fall back to cwd detection - copy all fields from cwdCtx
info.Role = cwdCtx.Role
info.Rig = cwdCtx.Rig
info.Polecat = cwdCtx.Polecat