diff --git a/internal/cmd/prime.go b/internal/cmd/prime.go index a44e39a4..f931e8ad 100644 --- a/internal/cmd/prime.go +++ b/internal/cmd/prime.go @@ -51,14 +51,9 @@ func init() { rootCmd.AddCommand(primeCmd) } -// RoleContext contains information about the detected role. -type RoleContext struct { - Role Role `json:"role"` - Rig string `json:"rig,omitempty"` - Polecat string `json:"polecat,omitempty"` - TownRoot string `json:"town_root"` - WorkDir string `json:"work_dir"` -} +// RoleContext is an alias for RoleInfo for backward compatibility. +// New code should use RoleInfo directly. +type RoleContext = RoleInfo func runPrime(cmd *cobra.Command, args []string) error { cwd, err := os.Getwd() @@ -146,11 +141,12 @@ func runPrime(cmd *cobra.Command, args []string) error { return nil } -func detectRole(cwd, townRoot string) RoleContext { - ctx := RoleContext{ +func detectRole(cwd, townRoot string) RoleInfo { + ctx := RoleInfo{ Role: RoleUnknown, TownRoot: townRoot, WorkDir: cwd, + Source: "cwd", } // Get relative path from town root diff --git a/internal/cmd/role.go b/internal/cmd/role.go index 172153e8..8cecc27f 100644 --- a/internal/cmd/role.go +++ b/internal/cmd/role.go @@ -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