Command history tracking and utility functions