arct_core/
command.rs

1//! Command parsing, analysis, and categorization
2
3use crate::types::{Error, Result};
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7/// Represents a parsed shell command
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Command {
10    pub raw: String,
11    pub program: String,
12    pub args: Vec<String>,
13    pub category: CommandCategory,
14    pub danger_level: DangerLevel,
15    pub flags: Vec<Flag>,
16}
17
18/// Categories of commands for educational grouping
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
20pub enum CommandCategory {
21    Navigation,
22    FileManagement,
23    TextProcessing,
24    SystemInfo,
25    ProcessManagement,
26    Networking,
27    Permissions,
28    Archiving,
29    Search,
30    Git,
31    Build,
32    Package,
33    Unknown,
34}
35
36/// Danger level assessment for commands
37#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
38pub enum DangerLevel {
39    Safe,       // Read-only, no system modifications
40    Caution,    // Modifies files but recoverable
41    Dangerous,  // Can cause data loss or system issues
42    Critical,   // Requires elevated privileges or very dangerous
43}
44
45/// Represents a command flag/option with its meaning
46#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct Flag {
48    pub raw: String,
49    pub short: Option<char>,
50    pub long: Option<String>,
51    pub description: Option<String>,
52    pub argument: Option<String>,
53}
54
55/// Command metadata for educational purposes
56#[derive(Debug, Clone)]
57pub struct CommandInfo {
58    pub name: String,
59    pub category: CommandCategory,
60    pub danger_level: DangerLevel,
61    pub summary: &'static str,
62    pub description: &'static str,
63    pub common_flags: Vec<FlagInfo>,
64    pub examples: Vec<Example>,
65    pub related_commands: Vec<&'static str>,
66}
67
68/// Information about a specific flag
69#[derive(Debug, Clone)]
70pub struct FlagInfo {
71    pub flag: &'static str,
72    pub description: &'static str,
73    pub example: Option<&'static str>,
74}
75
76/// Example usage of a command
77#[derive(Debug, Clone)]
78pub struct Example {
79    pub command: &'static str,
80    pub description: &'static str,
81    pub use_case: &'static str,
82}
83
84/// Analyzes commands and provides educational context
85pub struct CommandAnalyzer {
86    commands: HashMap<String, CommandInfo>,
87}
88
89impl CommandAnalyzer {
90    pub fn new() -> Self {
91        let mut analyzer = Self {
92            commands: HashMap::new(),
93        };
94        analyzer.register_builtins();
95        analyzer
96    }
97
98    /// Parse a raw command string into a Command
99    pub fn parse(&self, input: &str) -> Result<Command> {
100        let parts = shellwords::split(input)
101            .map_err(|e| Error::ParseError(e.to_string()))?;
102
103        if parts.is_empty() {
104            return Err(Error::ParseError("Empty command".to_string()));
105        }
106
107        let program = parts[0].clone();
108        let args: Vec<String> = parts[1..].iter().map(|s| s.to_string()).collect();
109
110        let info = self.get_command_info(&program);
111        let category = info.map(|i| i.category).unwrap_or(CommandCategory::Unknown);
112        let danger_level = info.map(|i| i.danger_level).unwrap_or(DangerLevel::Safe);
113
114        let flags = self.parse_flags(&args);
115
116        Ok(Command {
117            raw: input.to_string(),
118            program,
119            args,
120            category,
121            danger_level,
122            flags,
123        })
124    }
125
126    /// Extract and parse flags from arguments
127    fn parse_flags(&self, args: &[String]) -> Vec<Flag> {
128        let mut flags = Vec::new();
129
130        for arg in args {
131            if arg.starts_with("--") {
132                // Long flag
133                let (name, value) = if let Some(idx) = arg.find('=') {
134                    (arg[2..idx].to_string(), Some(arg[idx + 1..].to_string()))
135                } else {
136                    (arg[2..].to_string(), None)
137                };
138
139                flags.push(Flag {
140                    raw: arg.clone(),
141                    short: None,
142                    long: Some(name),
143                    description: None,
144                    argument: value,
145                });
146            } else if arg.starts_with('-') && arg.len() > 1 && !arg.chars().nth(1).unwrap().is_ascii_digit() {
147                // Short flag(s)
148                for ch in arg[1..].chars() {
149                    flags.push(Flag {
150                        raw: format!("-{}", ch),
151                        short: Some(ch),
152                        long: None,
153                        description: None,
154                        argument: None,
155                    });
156                }
157            }
158        }
159
160        flags
161    }
162
163    /// Get command information if available
164    pub fn get_command_info(&self, cmd: &str) -> Option<&CommandInfo> {
165        self.commands.get(cmd)
166    }
167
168    /// Suggest similar commands for typos
169    pub fn suggest_similar(&self, cmd: &str) -> Vec<String> {
170        let mut suggestions: Vec<(String, usize)> = self
171            .commands
172            .keys()
173            .map(|k| (k.clone(), levenshtein_distance(cmd, k)))
174            .filter(|(_, dist)| *dist <= 2)
175            .collect();
176
177        suggestions.sort_by_key(|(_, dist)| *dist);
178        suggestions.truncate(5);
179        suggestions.into_iter().map(|(cmd, _)| cmd).collect()
180    }
181
182    /// Register built-in command definitions
183    fn register_builtins(&mut self) {
184        // Navigation commands
185        self.register(CommandInfo {
186            name: "ls".to_string(),
187            category: CommandCategory::Navigation,
188            danger_level: DangerLevel::Safe,
189            summary: "List directory contents",
190            description: "Shows you what files and folders are in your current directory, like opening a folder in a file browser. By default it shows just names, but with flags like -l (long format) you can see details like file sizes, permissions, and modification dates. The -a flag shows hidden files (those starting with a dot), and -h makes file sizes human-readable (like '2.3GB' instead of '2456334342'). This is usually the first command you run when exploring a new directory.",
191            common_flags: vec![
192                FlagInfo { flag: "-l", description: "Long format: shows permissions, owner, size, and date", example: Some("ls -l") },
193                FlagInfo { flag: "-a", description: "All files: includes hidden files (starting with .)", example: Some("ls -a") },
194                FlagInfo { flag: "-h", description: "Human-readable: shows file sizes in KB, MB, GB", example: Some("ls -lh") },
195                FlagInfo { flag: "-t", description: "Sort by time: newest files first", example: None },
196                FlagInfo { flag: "-r", description: "Reverse order: reverses the sort", example: None },
197            ],
198            examples: vec![
199                Example { command: "ls -la", description: "List all files in long format", use_case: "See all files including hidden ones with details" },
200                Example { command: "ls -lh", description: "List files with human-readable sizes", use_case: "Quickly see file sizes in MB/GB" },
201            ],
202            related_commands: vec!["cd", "pwd", "tree", "find"],
203        });
204
205        self.register(CommandInfo {
206            name: "cd".to_string(),
207            category: CommandCategory::Navigation,
208            danger_level: DangerLevel::Safe,
209            summary: "Change directory",
210            description: "Moves you from one folder to another in the filesystem, like clicking folders in a file browser. Your terminal is always 'in' some folder - this command lets you move around. Use 'cd ..' to go up one level to the parent folder, 'cd ~' to go to your home folder, or 'cd /path/to/folder' to go to a specific location. Think of it as your navigation tool for moving through your file system.",
211            common_flags: vec![],
212            examples: vec![
213                Example { command: "cd /home/user", description: "Go to specific directory", use_case: "Navigate to an absolute path" },
214                Example { command: "cd ..", description: "Go up one directory", use_case: "Move to parent directory" },
215                Example { command: "cd -", description: "Go to previous directory", use_case: "Toggle between two directories" },
216            ],
217            related_commands: vec!["pwd", "ls", "pushd", "popd"],
218        });
219
220        self.register(CommandInfo {
221            name: "pwd".to_string(),
222            category: CommandCategory::Navigation,
223            danger_level: DangerLevel::Safe,
224            summary: "Print working directory",
225            description: "Displays the complete path of where you currently are in the filesystem. Like a 'You Are Here' sign in a mall - it tells you exactly where you're standing. Useful when you're lost or need to know the full path to copy to another command or share with someone. The output will be something like '/home/username/Documents' showing the complete chain from the root of the filesystem to your current location.",
226            common_flags: vec![
227                FlagInfo { flag: "-P", description: "Physical path: shows actual path resolving symlinks", example: None },
228            ],
229            examples: vec![
230                Example { command: "pwd", description: "Show current directory", use_case: "Find out where you are" },
231            ],
232            related_commands: vec!["cd", "ls"],
233        });
234
235        // File management
236        self.register(CommandInfo {
237            name: "rm".to_string(),
238            category: CommandCategory::FileManagement,
239            danger_level: DangerLevel::Dangerous,
240            summary: "Remove files or directories",
241            description: "⚠️  Permanently deletes files or directories from your system. Unlike moving files to a recycle bin in a graphical interface, this command completely removes them - there's no undo! Use 'rm file.txt' to delete a single file, or 'rm -r folder/' to delete a directory and everything inside it. The -i flag will ask for confirmation before each deletion, which is much safer for beginners. Always double-check what you're deleting because once it's gone, it's gone forever!",
242            common_flags: vec![
243                FlagInfo { flag: "-r", description: "Recursive: remove directories and their contents", example: Some("rm -r folder/") },
244                FlagInfo { flag: "-f", description: "Force: ignore warnings and nonexistent files", example: None },
245                FlagInfo { flag: "-i", description: "Interactive: prompt before each removal", example: Some("rm -i file.txt") },
246            ],
247            examples: vec![
248                Example { command: "rm file.txt", description: "Delete a single file", use_case: "Remove unwanted file" },
249                Example { command: "rm -ri folder/", description: "Safely delete directory with confirmation", use_case: "Remove directory with safety prompts" },
250            ],
251            related_commands: vec!["rmdir", "trash", "shred"],
252        });
253
254        self.register(CommandInfo {
255            name: "cp".to_string(),
256            category: CommandCategory::FileManagement,
257            danger_level: DangerLevel::Caution,
258            summary: "Copy files and directories",
259            description: "Creates a duplicate copy of files or directories, leaving the original untouched. Think of it like the copy-paste function in a file browser. Use 'cp file.txt backup.txt' to copy a file, or 'cp -r folder/ backup/' to copy an entire directory with all its contents. The -i flag will warn you before overwriting existing files, and -p preserves the original file's permissions and timestamps, which is useful for backups.",
260            common_flags: vec![
261                FlagInfo { flag: "-r", description: "Recursive: copy directories and their contents", example: Some("cp -r folder/ backup/") },
262                FlagInfo { flag: "-i", description: "Interactive: prompt before overwriting existing files", example: Some("cp -i file.txt dest/") },
263                FlagInfo { flag: "-v", description: "Verbose: show files as they are copied", example: None },
264                FlagInfo { flag: "-p", description: "Preserve: keep original permissions, timestamps, and ownership", example: None },
265            ],
266            examples: vec![
267                Example { command: "cp file.txt backup.txt", description: "Copy a file", use_case: "Create a backup of a file" },
268                Example { command: "cp -r folder/ backup/", description: "Copy a directory recursively", use_case: "Backup an entire directory" },
269            ],
270            related_commands: vec!["mv", "rsync", "dd"],
271        });
272
273        self.register(CommandInfo {
274            name: "mv".to_string(),
275            category: CommandCategory::FileManagement,
276            danger_level: DangerLevel::Caution,
277            summary: "Move or rename files and directories",
278            description: "Moves files to a different location or renames them - it's the same operation in Linux! Think of it like cut-and-paste or the rename function in a file browser. Unlike 'cp', the original file disappears after moving. Use 'mv oldname.txt newname.txt' to rename a file, or 'mv file.txt /other/folder/' to move it to a different directory. The -i flag prompts for confirmation before overwriting any existing files with the same name.",
279            common_flags: vec![
280                FlagInfo { flag: "-i", description: "Interactive: prompt before overwriting", example: Some("mv -i old.txt new.txt") },
281                FlagInfo { flag: "-v", description: "Verbose: show what is being moved", example: None },
282                FlagInfo { flag: "-n", description: "No-clobber: don't overwrite existing files", example: None },
283            ],
284            examples: vec![
285                Example { command: "mv old.txt new.txt", description: "Rename a file", use_case: "Change a filename" },
286                Example { command: "mv file.txt folder/", description: "Move to directory", use_case: "Relocate a file" },
287            ],
288            related_commands: vec!["cp", "rename"],
289        });
290
291        self.register(CommandInfo {
292            name: "mkdir".to_string(),
293            category: CommandCategory::FileManagement,
294            danger_level: DangerLevel::Safe,
295            summary: "Make directories",
296            description: "Creates new folders (directories) to organize your files, just like creating a new folder in a file browser. You can create a single folder with 'mkdir foldername' or create nested folders all at once with 'mkdir -p parent/child/grandchild'. The -p flag is especially handy because it creates all the parent folders if they don't exist, instead of giving you an error.",
297            common_flags: vec![
298                FlagInfo { flag: "-p", description: "Parents: create parent directories as needed", example: Some("mkdir -p a/b/c") },
299                FlagInfo { flag: "-v", description: "Verbose: print a message for each created directory", example: None },
300            ],
301            examples: vec![
302                Example { command: "mkdir project", description: "Create a directory", use_case: "Make a new folder" },
303                Example { command: "mkdir -p path/to/folder", description: "Create nested directories", use_case: "Create directory structure in one command" },
304            ],
305            related_commands: vec!["rmdir", "touch"],
306        });
307
308        self.register(CommandInfo {
309            name: "touch".to_string(),
310            category: CommandCategory::FileManagement,
311            danger_level: DangerLevel::Safe,
312            summary: "Create empty files or update timestamps",
313            description: "Quickly creates a new empty file or updates when an existing file was last accessed. Most commonly used to create placeholder files like 'touch newfile.txt' which creates an empty file you can edit later. If the file already exists, it just updates the timestamp without changing the content. Useful for testing scripts, creating template files, or triggering systems that watch for file changes.",
314            common_flags: vec![
315                FlagInfo { flag: "-a", description: "Access time: change only the access time", example: None },
316                FlagInfo { flag: "-m", description: "Modification time: change only the modification time", example: None },
317            ],
318            examples: vec![
319                Example { command: "touch file.txt", description: "Create an empty file", use_case: "Initialize a new file" },
320                Example { command: "touch *.txt", description: "Update timestamps of multiple files", use_case: "Refresh file modification times" },
321            ],
322            related_commands: vec!["mkdir", "echo"],
323        });
324
325        // Text processing and viewing
326        self.register(CommandInfo {
327            name: "cat".to_string(),
328            category: CommandCategory::TextProcessing,
329            danger_level: DangerLevel::Safe,
330            summary: "Concatenate and display file contents",
331            description: "Displays the entire contents of a file right in your terminal, like opening a text file to read it. The name comes from 'concatenate' because it can also combine multiple files together. Use it for quick peeks at small files or config files. For large files, use 'less' or 'head' instead since cat will dump everything at once. You can also use it to combine files like 'cat file1.txt file2.txt > combined.txt'.",
332            common_flags: vec![
333                FlagInfo { flag: "-n", description: "Number: number all output lines", example: Some("cat -n file.txt") },
334                FlagInfo { flag: "-A", description: "Show all: display non-printing characters", example: None },
335            ],
336            examples: vec![
337                Example { command: "cat file.txt", description: "Display file contents", use_case: "Read a file" },
338                Example { command: "cat file1.txt file2.txt > combined.txt", description: "Combine files", use_case: "Merge multiple files into one" },
339            ],
340            related_commands: vec!["less", "more", "head", "tail"],
341        });
342
343        self.register(CommandInfo {
344            name: "less".to_string(),
345            category: CommandCategory::TextProcessing,
346            danger_level: DangerLevel::Safe,
347            summary: "View file contents with pagination",
348            description: "Opens files in an interactive viewer where you can scroll up and down through the content, unlike 'cat' which dumps everything at once. The name means 'less is more' - it's an improved version of the older 'more' command. Use arrow keys or Page Up/Down to navigate, press '/' to search for text, and 'q' to quit. Perfect for reading log files, documentation, or any file too long to fit on one screen. You can also pipe command output into it like 'ls -la | less'.",
349            common_flags: vec![
350                FlagInfo { flag: "-N", description: "Show line numbers", example: Some("less -N file.txt") },
351                FlagInfo { flag: "-S", description: "Chop long lines instead of wrapping", example: None },
352            ],
353            examples: vec![
354                Example { command: "less largefile.log", description: "View large file", use_case: "Browse long files efficiently" },
355                Example { command: "ls -la | less", description: "Pipe output to less", use_case: "Paginate command output" },
356            ],
357            related_commands: vec!["more", "cat", "head", "tail"],
358        });
359
360        self.register(CommandInfo {
361            name: "head".to_string(),
362            category: CommandCategory::TextProcessing,
363            danger_level: DangerLevel::Safe,
364            summary: "Display first lines of a file",
365            description: "Shows just the beginning of a file, like peeking at the first page of a book. By default it displays the first 10 lines, but you can change this with the -n flag. Super useful for quickly checking what's in a file without opening the whole thing, or for seeing the header row of a CSV file. For example, 'head -n 20 file.txt' shows the first 20 lines. Often paired with 'tail' to see the end of a file.",
366            common_flags: vec![
367                FlagInfo { flag: "-n", description: "Number: specify how many lines to show", example: Some("head -n 20 file.txt") },
368            ],
369            examples: vec![
370                Example { command: "head file.txt", description: "Show first 10 lines", use_case: "Preview file contents" },
371                Example { command: "head -n 5 file.txt", description: "Show first 5 lines", use_case: "Quick peek at file start" },
372            ],
373            related_commands: vec!["tail", "cat", "less"],
374        });
375
376        self.register(CommandInfo {
377            name: "tail".to_string(),
378            category: CommandCategory::TextProcessing,
379            danger_level: DangerLevel::Safe,
380            summary: "Display last lines of a file",
381            description: "Shows just the end of a file, like reading the last page of a book. By default it displays the last 10 lines, perfect for checking recent log entries or the end of a file. The -f flag is incredibly useful - it 'follows' the file, continuously showing new lines as they're added. This is essential for watching log files in real-time as your application runs. For example, 'tail -f /var/log/app.log' lets you watch errors appear live while debugging.",
382            common_flags: vec![
383                FlagInfo { flag: "-n", description: "Number: specify how many lines to show", example: Some("tail -n 20 file.txt") },
384                FlagInfo { flag: "-f", description: "Follow: continuously show new lines as they're added", example: Some("tail -f /var/log/syslog") },
385            ],
386            examples: vec![
387                Example { command: "tail file.txt", description: "Show last 10 lines", use_case: "See end of file" },
388                Example { command: "tail -f app.log", description: "Follow log file in real-time", use_case: "Monitor live log output" },
389            ],
390            related_commands: vec!["head", "cat", "less"],
391        });
392
393        self.register(CommandInfo {
394            name: "grep".to_string(),
395            category: CommandCategory::Search,
396            danger_level: DangerLevel::Safe,
397            summary: "Search for patterns in files",
398            description: "Searches through files to find lines containing specific text, like using Ctrl+F in a document editor but much more powerful. You can search one file, multiple files, or even entire directory trees. It's case-sensitive by default, but -i makes it ignore case. The -r flag searches recursively through all files in folders. Super useful for finding where something is mentioned in your code, logs, or config files. For example, 'grep error app.log' finds all lines containing 'error' in your log file.",
399            common_flags: vec![
400                FlagInfo { flag: "-i", description: "Ignore case: make search case-insensitive", example: Some("grep -i \"error\" log.txt") },
401                FlagInfo { flag: "-r", description: "Recursive: search in all files in directories", example: Some("grep -r \"TODO\" .") },
402                FlagInfo { flag: "-n", description: "Line number: show line numbers with matches", example: Some("grep -n \"function\" code.js") },
403                FlagInfo { flag: "-v", description: "Invert: show lines that DON'T match", example: None },
404            ],
405            examples: vec![
406                Example { command: "grep \"error\" app.log", description: "Find errors in log", use_case: "Debug application issues" },
407                Example { command: "grep -r \"TODO\" src/", description: "Search all source files", use_case: "Find all TODO comments in codebase" },
408            ],
409            related_commands: vec!["find", "awk", "sed"],
410        });
411
412        self.register(CommandInfo {
413            name: "find".to_string(),
414            category: CommandCategory::Search,
415            danger_level: DangerLevel::Safe,
416            summary: "Search for files and directories",
417            description: "Searches your filesystem to locate files and folders matching specific criteria like name, size, or modification date. Unlike grep which searches inside files, find searches for the files themselves. For example, 'find . -name \"*.txt\"' finds all text files in the current directory and subdirectories. It's incredibly powerful but the syntax can be tricky at first. You can combine multiple criteria and even execute commands on the files it finds.",
418            common_flags: vec![
419                FlagInfo { flag: "-name", description: "Search by filename pattern", example: Some("find . -name \"*.txt\"") },
420                FlagInfo { flag: "-type", description: "Filter by type (f=file, d=directory)", example: Some("find . -type f") },
421                FlagInfo { flag: "-size", description: "Filter by file size", example: Some("find . -size +10M") },
422            ],
423            examples: vec![
424                Example { command: "find . -name \"*.log\"", description: "Find all log files", use_case: "Locate files by extension" },
425                Example { command: "find /home -type f -mtime -7", description: "Files modified in last 7 days", use_case: "Find recently changed files" },
426            ],
427            related_commands: vec!["locate", "grep", "which"],
428        });
429
430        // System information
431        self.register(CommandInfo {
432            name: "ps".to_string(),
433            category: CommandCategory::ProcessManagement,
434            danger_level: DangerLevel::Safe,
435            summary: "Display running processes",
436            description: "Shows a snapshot of all the programs currently running on your system, like Task Manager on Windows or Activity Monitor on Mac. Each running program is called a 'process' and has a unique process ID (PID). The most common usage is 'ps aux' which shows all processes with detailed info including who's running them and how much CPU and memory they're using. Often combined with grep like 'ps aux | grep nginx' to find a specific program and check if it's running.",
437            common_flags: vec![
438                FlagInfo { flag: "aux", description: "All processes with detailed info (common usage)", example: Some("ps aux") },
439                FlagInfo { flag: "-ef", description: "Full format listing of all processes", example: Some("ps -ef") },
440            ],
441            examples: vec![
442                Example { command: "ps aux", description: "Show all processes", use_case: "System overview" },
443                Example { command: "ps aux | grep nginx", description: "Find specific process", use_case: "Check if program is running" },
444            ],
445            related_commands: vec!["top", "htop", "kill", "pgrep"],
446        });
447
448        self.register(CommandInfo {
449            name: "top".to_string(),
450            category: CommandCategory::SystemInfo,
451            danger_level: DangerLevel::Safe,
452            summary: "Display dynamic real-time system information",
453            description: "Opens an interactive, live-updating display of your system's processes, like a continuously refreshing Task Manager. Shows which programs are using the most CPU and memory, updates every few seconds, and lets you see exactly what's happening on your system right now. Unlike 'ps' which gives you a one-time snapshot, 'top' keeps running and updating. Press 'q' to quit when you're done. Very useful for finding programs that are hogging resources or checking if your system is under heavy load.",
454            common_flags: vec![],
455            examples: vec![
456                Example { command: "top", description: "Monitor system resources", use_case: "Check CPU and memory usage in real-time" },
457            ],
458            related_commands: vec!["htop", "ps", "free"],
459        });
460
461        self.register(CommandInfo {
462            name: "df".to_string(),
463            category: CommandCategory::SystemInfo,
464            danger_level: DangerLevel::Safe,
465            summary: "Report filesystem disk space usage",
466            description: "Reports how much disk space is free and used on all your drives and partitions, like checking your computer's storage in system settings. The name stands for 'disk free'. Use 'df -h' (human-readable) to see sizes in GB/MB instead of confusing block counts. Perfect for quickly checking if you're running out of disk space or seeing which partition is getting full. Shows mounted filesystems including external drives, network shares, and your main hard drive.",
467            common_flags: vec![
468                FlagInfo { flag: "-h", description: "Human-readable: show sizes in GB, MB, KB", example: Some("df -h") },
469            ],
470            examples: vec![
471                Example { command: "df -h", description: "Show disk usage", use_case: "Check available disk space" },
472            ],
473            related_commands: vec!["du", "free"],
474        });
475
476        self.register(CommandInfo {
477            name: "du".to_string(),
478            category: CommandCategory::SystemInfo,
479            danger_level: DangerLevel::Safe,
480            summary: "Estimate file and directory space usage",
481            description: "Shows how much disk space individual files and directories are consuming, helping you find what's hogging all your storage. The name stands for 'disk usage'. While 'df' shows overall disk space, 'du' drills down to show you which folders are taking up room. Use 'du -sh *' to see the size of each item in the current directory, or 'du -h --max-depth=1' to avoid diving too deep into subdirectories. Essential for finding and cleaning up large files when you're running low on space.",
482            common_flags: vec![
483                FlagInfo { flag: "-h", description: "Human-readable sizes", example: Some("du -h folder/") },
484                FlagInfo { flag: "-s", description: "Summary: show only total for each argument", example: Some("du -sh *") },
485            ],
486            examples: vec![
487                Example { command: "du -sh *", description: "Size of each item in current directory", use_case: "Find what's taking up space" },
488                Example { command: "du -h --max-depth=1", description: "Show directory sizes one level deep", use_case: "Identify large directories" },
489            ],
490            related_commands: vec!["df", "ls"],
491        });
492
493        self.register(CommandInfo {
494            name: "chmod".to_string(),
495            category: CommandCategory::Permissions,
496            danger_level: DangerLevel::Caution,
497            summary: "Change file permissions",
498            description: "Controls who can read, write, or execute a file. Linux files have three permission levels: owner, group, and everyone else. Each can have read (r), write (w), and execute (x) permissions. You'll often see it used like 'chmod +x script.sh' to make a script executable, or 'chmod 644 file.txt' using numbers where 6=read+write, 4=read only. The three digits represent owner, group, and others. Understanding chmod is essential for security and making scripts runnable.",
499            common_flags: vec![
500                FlagInfo { flag: "-R", description: "Recursive: change permissions of directory and contents", example: Some("chmod -R 755 folder/") },
501            ],
502            examples: vec![
503                Example { command: "chmod 755 script.sh", description: "Make file executable", use_case: "Allow script to run" },
504                Example { command: "chmod u+x file", description: "Add execute permission for owner", use_case: "Grant execution rights" },
505            ],
506            related_commands: vec!["chown", "chgrp", "ls -l"],
507        });
508
509        self.register(CommandInfo {
510            name: "chown".to_string(),
511            category: CommandCategory::Permissions,
512            danger_level: DangerLevel::Dangerous,
513            summary: "Change file owner and group",
514            description: "Changes which user and group 'owns' a file or directory, controlling who has ultimate authority over it. In Linux, every file has an owner and a group, determining who can access it. This command usually requires sudo since you need admin rights to transfer ownership. Use it like 'sudo chown username file.txt' to change the owner, or 'sudo chown user:group file.txt' to set both. Common when moving files between users or fixing permission issues on servers.",
515            common_flags: vec![
516                FlagInfo { flag: "-R", description: "Recursive: change ownership recursively", example: Some("chown -R user:group folder/") },
517            ],
518            examples: vec![
519                Example { command: "chown user file.txt", description: "Change file owner", use_case: "Transfer file ownership" },
520                Example { command: "chown user:group file.txt", description: "Change owner and group", use_case: "Set both owner and group" },
521            ],
522            related_commands: vec!["chmod", "chgrp"],
523        });
524
525        // Archiving and compression
526        self.register(CommandInfo {
527            name: "tar".to_string(),
528            category: CommandCategory::Archiving,
529            danger_level: DangerLevel::Caution,
530            summary: "Archive files",
531            description: "Creates and extracts .tar archives, which bundle multiple files and folders into a single file for easier storage or transfer. Think of it as creating a ZIP file, but the standard format for Linux. The name stands for 'tape archive' from the old days of backup tapes. Usually combined with compression: 'tar -czf backup.tar.gz folder/' creates a compressed archive, and 'tar -xzf backup.tar.gz' extracts it. The -v flag shows which files are being processed, helpful for large archives.",
532            common_flags: vec![
533                FlagInfo { flag: "-c", description: "Create: create a new archive", example: Some("tar -czf archive.tar.gz folder/") },
534                FlagInfo { flag: "-x", description: "Extract: extract files from archive", example: Some("tar -xzf archive.tar.gz") },
535                FlagInfo { flag: "-z", description: "Gzip: compress/decompress with gzip", example: None },
536                FlagInfo { flag: "-v", description: "Verbose: list files being processed", example: None },
537                FlagInfo { flag: "-f", description: "File: specify archive filename", example: None },
538            ],
539            examples: vec![
540                Example { command: "tar -czf backup.tar.gz folder/", description: "Create compressed archive", use_case: "Backup directory" },
541                Example { command: "tar -xzf archive.tar.gz", description: "Extract compressed archive", use_case: "Unpack tarball" },
542            ],
543            related_commands: vec!["gzip", "zip", "unzip"],
544        });
545
546        // Networking
547        self.register(CommandInfo {
548            name: "curl".to_string(),
549            category: CommandCategory::Networking,
550            danger_level: DangerLevel::Safe,
551            summary: "Transfer data from or to a server",
552            description: "Fetches data from or sends data to web servers and other network resources, like a command-line web browser. Supports many protocols including HTTP, HTTPS, and FTP. Super useful for testing APIs, downloading files, or checking if a website is responding. For example, 'curl https://api.example.com' fetches and displays the response, while 'curl -O url' downloads a file. Developers use it constantly for debugging web services and making API requests from scripts.",
553            common_flags: vec![
554                FlagInfo { flag: "-O", description: "Output: save with remote filename", example: Some("curl -O https://example.com/file.zip") },
555                FlagInfo { flag: "-L", description: "Location: follow redirects", example: None },
556            ],
557            examples: vec![
558                Example { command: "curl https://api.example.com", description: "Fetch URL content", use_case: "Test API endpoints" },
559                Example { command: "curl -O https://example.com/file.zip", description: "Download file", use_case: "Download from URL" },
560            ],
561            related_commands: vec!["wget", "http"],
562        });
563
564        self.register(CommandInfo {
565            name: "wget".to_string(),
566            category: CommandCategory::Networking,
567            danger_level: DangerLevel::Safe,
568            summary: "Network downloader",
569            description: "Downloads files from the web directly to your computer, like a download manager for the command line. Unlike curl which can do many things, wget specializes in downloading. It's great for downloading large files because it can resume interrupted downloads with the -c flag. Use it like 'wget https://example.com/file.zip' and it saves the file to your current directory. Can also download entire websites recursively with the -r flag, making it perfect for offline viewing or backups.",
570            common_flags: vec![
571                FlagInfo { flag: "-c", description: "Continue: resume interrupted download", example: Some("wget -c https://example.com/large.iso") },
572                FlagInfo { flag: "-r", description: "Recursive: download entire website", example: None },
573            ],
574            examples: vec![
575                Example { command: "wget https://example.com/file.zip", description: "Download file", use_case: "Fetch file from web" },
576            ],
577            related_commands: vec!["curl", "aria2c"],
578        });
579
580        self.register(CommandInfo {
581            name: "ping".to_string(),
582            category: CommandCategory::Networking,
583            danger_level: DangerLevel::Safe,
584            summary: "Test network connectivity",
585            description: "Tests if another computer or website is reachable over the network by sending small test packets and measuring the response time. Like knocking on a door to see if anyone's home. The response time (latency) is shown in milliseconds - lower is better. Use 'ping google.com' to check if your internet is working, or 'ping 192.168.1.1' to test your router connection. It keeps running until you stop it with Ctrl+C, or use -c to send a specific number of packets like 'ping -c 4 google.com'.",
586            common_flags: vec![
587                FlagInfo { flag: "-c", description: "Count: number of packets to send", example: Some("ping -c 4 google.com") },
588            ],
589            examples: vec![
590                Example { command: "ping google.com", description: "Test internet connection", use_case: "Check if host is reachable" },
591                Example { command: "ping -c 4 192.168.1.1", description: "Send 4 packets", use_case: "Quick connectivity test" },
592            ],
593            related_commands: vec!["traceroute", "netstat"],
594        });
595
596        // Git commands
597        self.register(CommandInfo {
598            name: "git".to_string(),
599            category: CommandCategory::Git,
600            danger_level: DangerLevel::Caution,
601            summary: "Distributed version control system",
602            description: "The industry-standard tool for tracking changes to code and collaborating with other developers. It's like having unlimited undo for your entire project, with the ability to work on different features in parallel and merge them together. Every change you make can be saved as a 'commit' with a description of what you did. Essential for modern software development - nearly every coding project uses git. Common commands include 'git status' to see what changed, 'git add' to stage files, and 'git commit' to save your changes to history.",
603            common_flags: vec![],
604            examples: vec![
605                Example { command: "git status", description: "Check repository status", use_case: "See what's changed" },
606                Example { command: "git add .", description: "Stage all changes", use_case: "Prepare files for commit" },
607                Example { command: "git commit -m \"message\"", description: "Save changes", use_case: "Record changes to repository" },
608            ],
609            related_commands: vec!["svn", "hg"],
610        });
611
612        self.register(CommandInfo {
613            name: "echo".to_string(),
614            category: CommandCategory::TextProcessing,
615            danger_level: DangerLevel::Safe,
616            summary: "Display a line of text",
617            description: "Prints whatever you type directly to the screen, like a simple print statement. Commonly used to display messages in scripts, show the value of variables like 'echo $PATH', or write text to files using redirection like 'echo \"Hello\" > file.txt'. You can use it for debugging scripts by echoing variable values to see what's happening, or to create simple text files without opening an editor.",
618            common_flags: vec![
619                FlagInfo { flag: "-n", description: "No newline: don't output trailing newline", example: Some("echo -n \"text\"") },
620                FlagInfo { flag: "-e", description: "Enable interpretation of backslash escapes", example: None },
621            ],
622            examples: vec![
623                Example { command: "echo \"Hello World\"", description: "Print text", use_case: "Display message" },
624                Example { command: "echo \"text\" > file.txt", description: "Write to file", use_case: "Create file with content" },
625            ],
626            related_commands: vec!["printf", "cat"],
627        });
628
629        self.register(CommandInfo {
630            name: "man".to_string(),
631            category: CommandCategory::SystemInfo,
632            danger_level: DangerLevel::Safe,
633            summary: "Display manual pages",
634            description: "Opens the built-in manual (documentation) for any command, like a help system right in your terminal. Short for 'manual'. Use it whenever you want to learn what a command does and what flags it accepts. For example, 'man ls' shows you everything about the ls command. The manual opens in a pager (like less), so you can scroll through it and press 'q' to quit. Every serious Linux user keeps 'man' handy - it's how you look things up without leaving the terminal.",
635            common_flags: vec![],
636            examples: vec![
637                Example { command: "man ls", description: "Read ls documentation", use_case: "Learn about command options" },
638            ],
639            related_commands: vec!["help", "info", "whatis"],
640        });
641
642        self.register(CommandInfo {
643            name: "sudo".to_string(),
644            category: CommandCategory::SystemInfo,
645            danger_level: DangerLevel::Critical,
646            summary: "Execute command as superuser",
647            description: "⚠️  Runs commands with administrator (root) privileges, giving you full power over the system. Short for 'superuser do'. Like clicking 'Run as Administrator' on Windows - it bypasses normal security restrictions. You'll need to enter your password the first time you use it. Essential for system administration tasks like installing software, modifying system files, or changing settings. Be VERY careful what you run with sudo - you can accidentally damage your entire system since there are no safety nets!",
648            common_flags: vec![
649                FlagInfo { flag: "-u", description: "User: run as specified user instead of root", example: Some("sudo -u user command") },
650            ],
651            examples: vec![
652                Example { command: "sudo apt update", description: "Update package list", use_case: "System maintenance with root privileges" },
653            ],
654            related_commands: vec!["su", "doas"],
655        });
656
657        self.register(CommandInfo {
658            name: "whoami".to_string(),
659            category: CommandCategory::SystemInfo,
660            danger_level: DangerLevel::Safe,
661            summary: "Print current user name",
662            description: "Displays your current username - literally tells you 'who am I' in the system. Simple but useful, especially when you're working on multiple computers, have switched users with 'su', or are sshed into a remote server. If you're not sure what account you're using or need to confirm you're the right user before doing something important, just type 'whoami'. Often used in scripts to check which user is running them.",
663            common_flags: vec![],
664            examples: vec![
665                Example { command: "whoami", description: "Show current username", use_case: "Verify which user you are" },
666            ],
667            related_commands: vec!["id", "who"],
668        });
669
670        self.register(CommandInfo {
671            name: "history".to_string(),
672            category: CommandCategory::SystemInfo,
673            danger_level: DangerLevel::Safe,
674            summary: "Show command history",
675            description: "Shows a numbered list of all the commands you've recently run in your terminal, like a browser history for the command line. Super useful for finding and reusing complex commands you typed earlier without retyping them. You can re-run a command by typing '!123' where 123 is the command number. Combine with grep like 'history | grep git' to find all git commands you've used. Your shell remembers hundreds or thousands of commands between sessions.",
676            common_flags: vec![],
677            examples: vec![
678                Example { command: "history", description: "Show recent commands", use_case: "Find and reuse previous commands" },
679                Example { command: "history | grep git", description: "Search command history", use_case: "Find specific past commands" },
680            ],
681            related_commands: vec!["fc", "!!"],
682        });
683
684        self.register(CommandInfo {
685            name: "clear".to_string(),
686            category: CommandCategory::SystemInfo,
687            danger_level: DangerLevel::Safe,
688            summary: "Clear the terminal screen",
689            description: "Wipes all the text from your terminal screen, giving you a fresh clean view. Like clearing a whiteboard - everything disappears visually, but your command history is still saved and can be accessed with the up arrow or 'history' command. Useful when your terminal gets cluttered with output and you want to start fresh, or before taking a screenshot. You can also use Ctrl+L as a keyboard shortcut in most terminals.",
690            common_flags: vec![],
691            examples: vec![
692                Example { command: "clear", description: "Clean terminal screen", use_case: "Start fresh with clean view" },
693            ],
694            related_commands: vec!["reset"],
695        });
696
697        // Advanced text processing
698        self.register(CommandInfo {
699            name: "sed".to_string(),
700            category: CommandCategory::TextProcessing,
701            danger_level: DangerLevel::Caution,
702            summary: "Stream editor for filtering and transforming text",
703            description: "A powerful tool for automatically editing text, like find-and-replace on steroids. The name means 'stream editor' because it processes text line by line. Most commonly used for search-and-replace operations like 'sed 's/old/new/g' file.txt' which replaces all occurrences of 'old' with 'new'. The -i flag edits files in place, which is convenient but risky since it modifies the original file. Can also extract specific lines, delete lines, and perform complex text transformations. The syntax is cryptic but extremely powerful once you learn it.",
704            common_flags: vec![
705                FlagInfo { flag: "-i", description: "In-place: edit files in place (careful!)", example: Some("sed -i 's/old/new/g' file.txt") },
706                FlagInfo { flag: "-e", description: "Expression: add script to be executed", example: None },
707            ],
708            examples: vec![
709                Example { command: "sed 's/old/new/g' file.txt", description: "Replace text", use_case: "Find and replace in file" },
710                Example { command: "sed -n '10,20p' file.txt", description: "Print lines 10-20", use_case: "Extract specific lines" },
711            ],
712            related_commands: vec!["awk", "grep", "tr"],
713        });
714
715        self.register(CommandInfo {
716            name: "awk".to_string(),
717            category: CommandCategory::TextProcessing,
718            danger_level: DangerLevel::Safe,
719            summary: "Pattern scanning and text processing language",
720            description: "A text processing powerhouse that excels at working with columnar data like CSV files, logs, or tables. It automatically splits each line into fields (columns) and lets you manipulate them. For example, 'awk '{print $1}' file.txt' prints just the first column of each line. Great for extracting specific columns from data, doing calculations, filtering rows, and formatting output. More powerful than cut but simpler than writing a full script. The -F flag lets you specify what separates columns, like commas or colons.",
721            common_flags: vec![
722                FlagInfo { flag: "-F", description: "Field separator: specify delimiter", example: Some("awk -F':' '{print $1}' /etc/passwd") },
723            ],
724            examples: vec![
725                Example { command: "awk '{print $1}' file.txt", description: "Print first column", use_case: "Extract specific fields from text" },
726                Example { command: "awk -F':' '{print $1}' /etc/passwd", description: "List all usernames", use_case: "Parse colon-separated data" },
727            ],
728            related_commands: vec!["sed", "cut", "grep"],
729        });
730
731        self.register(CommandInfo {
732            name: "sort".to_string(),
733            category: CommandCategory::TextProcessing,
734            danger_level: DangerLevel::Safe,
735            summary: "Sort lines of text files",
736            description: "Arranges lines of text in order, either alphabetically or numerically. Like organizing a list in alphabetical order. By default it sorts alphabetically A-Z, but use -n for numeric sorting (so '10' comes after '2' instead of before). The -r flag reverses the sort order, and -u removes duplicate lines while sorting. Perfect for organizing lists, finding the top/bottom items in data, or preparing input for other commands like 'uniq' which requires sorted input to work properly.",
737            common_flags: vec![
738                FlagInfo { flag: "-n", description: "Numeric: sort by numerical value", example: Some("sort -n numbers.txt") },
739                FlagInfo { flag: "-r", description: "Reverse: sort in descending order", example: Some("sort -r file.txt") },
740                FlagInfo { flag: "-u", description: "Unique: remove duplicate lines", example: None },
741            ],
742            examples: vec![
743                Example { command: "sort file.txt", description: "Sort alphabetically", use_case: "Organize text lines" },
744                Example { command: "sort -n -r sizes.txt", description: "Sort numbers descending", use_case: "Find largest values" },
745            ],
746            related_commands: vec!["uniq", "cut"],
747        });
748
749        self.register(CommandInfo {
750            name: "uniq".to_string(),
751            category: CommandCategory::TextProcessing,
752            danger_level: DangerLevel::Safe,
753            summary: "Report or omit repeated lines",
754            description: "Removes duplicate lines from text, but only if they're adjacent (next to each other). That's why it's almost always used with 'sort' first - 'sort file.txt | uniq' gives you all unique lines. The -c flag is super useful: it counts how many times each line appears, perfect for finding the most common items in a list. For example, analyzing log files to count how many times each error occurred. Simple but powerful for data analysis tasks.",
755            common_flags: vec![
756                FlagInfo { flag: "-c", description: "Count: prefix lines with occurrence count", example: Some("sort file.txt | uniq -c") },
757                FlagInfo { flag: "-d", description: "Duplicates: only print duplicate lines", example: None },
758            ],
759            examples: vec![
760                Example { command: "sort file.txt | uniq", description: "Get unique lines", use_case: "Remove duplicates from file" },
761                Example { command: "sort file.txt | uniq -c", description: "Count occurrences", use_case: "Find most common entries" },
762            ],
763            related_commands: vec!["sort", "comm"],
764        });
765
766        self.register(CommandInfo {
767            name: "cut".to_string(),
768            category: CommandCategory::TextProcessing,
769            danger_level: DangerLevel::Safe,
770            summary: "Remove sections from lines of files",
771            description: "Extracts specific columns or character positions from each line of text, like cutting out columns from a spreadsheet. Great for working with CSV files, tab-separated data, or any structured text. Use -d to specify the delimiter (what separates columns) and -f to pick which fields you want. For example, 'cut -d',' -f1,3 data.csv' grabs just the 1st and 3rd columns from a CSV. Simpler than awk for basic column extraction but less flexible for complex tasks.",
772            common_flags: vec![
773                FlagInfo { flag: "-d", description: "Delimiter: specify field separator", example: Some("cut -d',' -f1,3 data.csv") },
774                FlagInfo { flag: "-f", description: "Fields: select specific fields", example: Some("cut -f1-3 file.txt") },
775                FlagInfo { flag: "-c", description: "Characters: select character positions", example: None },
776            ],
777            examples: vec![
778                Example { command: "cut -d',' -f1,3 data.csv", description: "Extract CSV columns", use_case: "Parse CSV files" },
779                Example { command: "cut -c1-10 file.txt", description: "First 10 characters", use_case: "Truncate lines" },
780            ],
781            related_commands: vec!["awk", "paste"],
782        });
783
784        self.register(CommandInfo {
785            name: "wc".to_string(),
786            category: CommandCategory::TextProcessing,
787            danger_level: DangerLevel::Safe,
788            summary: "Print newline, word, and byte counts",
789            description: "Counts lines, words, and characters (bytes) in files, giving you quick statistics about text. The name stands for 'word count'. By default shows all three counts, but you can use -l for just lines, -w for just words, or -c for just characters. Super useful for quickly checking how long a file is, counting entries in a list, or seeing how much code you've written. For example, 'wc -l file.txt' tells you exactly how many lines are in a file.",
790            common_flags: vec![
791                FlagInfo { flag: "-l", description: "Lines: count only lines", example: Some("wc -l file.txt") },
792                FlagInfo { flag: "-w", description: "Words: count only words", example: Some("wc -w file.txt") },
793                FlagInfo { flag: "-c", description: "Bytes: count only bytes", example: None },
794            ],
795            examples: vec![
796                Example { command: "wc file.txt", description: "Count lines, words, bytes", use_case: "Get file statistics" },
797                Example { command: "wc -l *.txt", description: "Count lines in all text files", use_case: "Compare file sizes" },
798            ],
799            related_commands: vec!["cat", "du"],
800        });
801
802        // Process management
803        self.register(CommandInfo {
804            name: "kill".to_string(),
805            category: CommandCategory::ProcessManagement,
806            danger_level: DangerLevel::Dangerous,
807            summary: "Terminate processes",
808            description: "Sends signals to running processes, usually to stop them. Despite the name, it doesn't always 'kill' - it sends different types of signals. The default signal (SIGTERM) asks a process to shut down gracefully, giving it time to clean up. Use 'kill -9' (SIGKILL) as a last resort to forcefully terminate unresponsive processes - this doesn't give them a chance to save data. You need the process ID (PID) which you can get from 'ps' or 'top'. For example, 'kill 1234' stops process 1234.",
809            common_flags: vec![
810                FlagInfo { flag: "-9", description: "SIGKILL: force kill (last resort)", example: Some("kill -9 1234") },
811                FlagInfo { flag: "-15", description: "SIGTERM: graceful termination (default)", example: None },
812            ],
813            examples: vec![
814                Example { command: "kill 1234", description: "Terminate process 1234", use_case: "Stop a running process" },
815                Example { command: "kill -9 1234", description: "Force kill process", use_case: "Stop unresponsive process" },
816            ],
817            related_commands: vec!["killall", "pkill", "ps"],
818        });
819
820        self.register(CommandInfo {
821            name: "killall".to_string(),
822            category: CommandCategory::ProcessManagement,
823            danger_level: DangerLevel::Dangerous,
824            summary: "Kill processes by name",
825            description: "⚠️  Terminates ALL processes that match a program name, which is more convenient than 'kill' when you don't know the PID but know the program name. Be careful - it will stop EVERY instance of that program! For example, 'killall firefox' closes all Firefox windows at once. Useful for cleaning up multiple stuck processes or ensuring all instances of a program are stopped. The -9 flag forces immediate termination. Double-check the name before running this - typos can stop the wrong programs!",
826            common_flags: vec![
827                FlagInfo { flag: "-9", description: "Force kill all matching processes", example: Some("killall -9 firefox") },
828            ],
829            examples: vec![
830                Example { command: "killall firefox", description: "Kill all Firefox processes", use_case: "Close all instances of a program" },
831            ],
832            related_commands: vec!["kill", "pkill"],
833        });
834
835        self.register(CommandInfo {
836            name: "pkill".to_string(),
837            category: CommandCategory::ProcessManagement,
838            danger_level: DangerLevel::Dangerous,
839            summary: "Signal processes based on name and attributes",
840            description: "A smarter version of 'killall' that can filter processes by various criteria like user, terminal, or partial name matches. For example, 'pkill -u username' kills all processes owned by that user, and 'pkill chrome' kills anything with 'chrome' in the name. More flexible than killall because you can target specific subsets of processes. The pattern matching uses regular expressions, so it's powerful but requires care. Check what you're about to kill with 'pgrep' first using the same pattern.",
841            common_flags: vec![
842                FlagInfo { flag: "-u", description: "User: kill processes owned by user", example: Some("pkill -u username") },
843            ],
844            examples: vec![
845                Example { command: "pkill chrome", description: "Kill processes matching 'chrome'", use_case: "Stop browser processes" },
846            ],
847            related_commands: vec!["kill", "killall", "pgrep"],
848        });
849
850        self.register(CommandInfo {
851            name: "bg".to_string(),
852            category: CommandCategory::ProcessManagement,
853            danger_level: DangerLevel::Safe,
854            summary: "Resume jobs in background",
855            description: "Continues running a program in the background after you've paused it with Ctrl+Z. When you press Ctrl+Z, a program suspends (freezes). The 'bg' command resumes it but lets it run in the background so you can use your terminal for other things. Useful when you realize a long-running task is blocking your terminal and you want to continue working. Pair it with 'fg' to bring jobs back to the foreground, and 'jobs' to see all background tasks.",
856            common_flags: vec![],
857            examples: vec![
858                Example { command: "bg", description: "Resume last suspended job", use_case: "Continue process in background" },
859                Example { command: "bg %1", description: "Resume job 1 in background", use_case: "Resume specific job" },
860            ],
861            related_commands: vec!["fg", "jobs", "&"],
862        });
863
864        self.register(CommandInfo {
865            name: "fg".to_string(),
866            category: CommandCategory::ProcessManagement,
867            danger_level: DangerLevel::Safe,
868            summary: "Bring jobs to foreground",
869            description: "Brings a background or paused program back to the foreground, making it the active process in your terminal again. If you have a program running in the background or you suspended it with Ctrl+Z, 'fg' returns control to it so you can interact with it. For example, if you backgrounded a text editor, 'fg' brings it back so you can type in it again. Use 'jobs' to see all available jobs and their numbers, then 'fg %2' to bring job 2 to the foreground.",
870            common_flags: vec![],
871            examples: vec![
872                Example { command: "fg", description: "Bring last job to foreground", use_case: "Return to background process" },
873                Example { command: "fg %1", description: "Bring job 1 to foreground", use_case: "Resume specific background job" },
874            ],
875            related_commands: vec!["bg", "jobs", "Ctrl+Z"],
876        });
877
878        self.register(CommandInfo {
879            name: "jobs".to_string(),
880            category: CommandCategory::ProcessManagement,
881            danger_level: DangerLevel::Safe,
882            summary: "List active jobs",
883            description: "Lists all the programs currently running or paused in your terminal session, showing their job numbers and status. Each background or suspended task gets a job number (like [1], [2]) that you can use with 'fg' or 'bg' commands. Shows whether each job is running, stopped, or done. This only shows jobs started from your current shell, not all system processes - use 'ps' for that. Essential for managing multiple tasks in one terminal window.",
884            common_flags: vec![
885                FlagInfo { flag: "-l", description: "Long format: show process IDs", example: Some("jobs -l") },
886            ],
887            examples: vec![
888                Example { command: "jobs", description: "List all jobs", use_case: "See background processes" },
889            ],
890            related_commands: vec!["bg", "fg", "ps"],
891        });
892
893        // Compression and archiving
894        self.register(CommandInfo {
895            name: "gzip".to_string(),
896            category: CommandCategory::Archiving,
897            danger_level: DangerLevel::Caution,
898            summary: "Compress files",
899            description: "Compresses files to save disk space, creating .gz files that are typically 60-70% smaller. By default it replaces the original file with the compressed version, so use -k to keep the original. Common for compressing log files, backups, or any large files you want to store. To decompress, use 'gunzip file.gz' or 'gzip -d file.gz'. Often combined with tar like 'tar -czf' to create compressed archives. Good balance of compression speed and file size reduction.",
900            common_flags: vec![
901                FlagInfo { flag: "-k", description: "Keep: keep original file", example: Some("gzip -k file.txt") },
902                FlagInfo { flag: "-d", description: "Decompress: uncompress .gz files", example: Some("gzip -d file.gz") },
903            ],
904            examples: vec![
905                Example { command: "gzip file.txt", description: "Compress file", use_case: "Reduce file size" },
906                Example { command: "gzip -k *.log", description: "Compress keeping originals", use_case: "Archive log files" },
907            ],
908            related_commands: vec!["gunzip", "tar", "bzip2"],
909        });
910
911        self.register(CommandInfo {
912            name: "gunzip".to_string(),
913            category: CommandCategory::Archiving,
914            danger_level: DangerLevel::Safe,
915            summary: "Decompress gzip files",
916            description: "Decompresses .gz files back to their original form, restoring files that were compressed with gzip. It's actually just a convenient wrapper around 'gzip -d'. By default it removes the .gz file after decompression, leaving you with the original uncompressed file. Use it like 'gunzip file.txt.gz' to get back file.txt. Safe and straightforward - just unzips compressed files so you can use them again.",
917            common_flags: vec![],
918            examples: vec![
919                Example { command: "gunzip file.gz", description: "Decompress file", use_case: "Extract compressed file" },
920            ],
921            related_commands: vec!["gzip", "tar"],
922        });
923
924        self.register(CommandInfo {
925            name: "zip".to_string(),
926            category: CommandCategory::Archiving,
927            danger_level: DangerLevel::Safe,
928            summary: "Package and compress files",
929            description: "Creates .zip archives that work across all operating systems - Windows, Mac, and Linux. While Linux prefers .tar.gz, ZIP files are perfect for sharing with Windows users or creating cross-platform archives. Use 'zip archive.zip file1 file2' to zip individual files, or 'zip -r archive.zip folder/' to zip an entire directory with -r (recursive). The original files stay untouched. Everyone knows how to open ZIP files, making this the most universal archive format.",
930            common_flags: vec![
931                FlagInfo { flag: "-r", description: "Recursive: include directories", example: Some("zip -r archive.zip folder/") },
932            ],
933            examples: vec![
934                Example { command: "zip archive.zip file1.txt file2.txt", description: "Create zip archive", use_case: "Package files for sharing" },
935                Example { command: "zip -r backup.zip project/", description: "Zip entire directory", use_case: "Archive project folder" },
936            ],
937            related_commands: vec!["unzip", "tar", "gzip"],
938        });
939
940        self.register(CommandInfo {
941            name: "unzip".to_string(),
942            category: CommandCategory::Archiving,
943            danger_level: DangerLevel::Safe,
944            summary: "Extract compressed files from ZIP archive",
945            description: "Extracts files from .zip archives, unpacking them into your current directory or a specified location. Use 'unzip archive.zip' to extract everything, or 'unzip -l archive.zip' to just list the contents without extracting (useful for previewing). The -d flag lets you extract to a specific directory like 'unzip file.zip -d /target/folder'. Works with ZIP files from any operating system. The archives stay intact after extraction so you can unzip them again later.",
946            common_flags: vec![
947                FlagInfo { flag: "-l", description: "List: show archive contents without extracting", example: Some("unzip -l archive.zip") },
948                FlagInfo { flag: "-d", description: "Directory: extract to specific directory", example: Some("unzip file.zip -d dest/") },
949            ],
950            examples: vec![
951                Example { command: "unzip archive.zip", description: "Extract zip file", use_case: "Unpack downloaded archive" },
952                Example { command: "unzip -l archive.zip", description: "List archive contents", use_case: "Preview files before extracting" },
953            ],
954            related_commands: vec!["zip", "tar"],
955        });
956
957        // Networking
958        self.register(CommandInfo {
959            name: "ssh".to_string(),
960            category: CommandCategory::Networking,
961            danger_level: DangerLevel::Caution,
962            summary: "Secure shell - remote login",
963            description: "Opens a secure, encrypted connection to another computer over the network. Think of it like remote desktop for the command line - you can control another machine as if you were sitting right in front of it. Commonly used to manage servers, run commands on remote computers, or access your work machine from home. The connection is encrypted, so passwords and data stay private even on public networks.",
964            common_flags: vec![
965                FlagInfo { flag: "-p", description: "Port: specify SSH port", example: Some("ssh -p 2222 user@host") },
966                FlagInfo { flag: "-i", description: "Identity: use specific private key", example: Some("ssh -i ~/.ssh/key user@host") },
967            ],
968            examples: vec![
969                Example { command: "ssh user@example.com", description: "Connect to remote server", use_case: "Remote server access" },
970                Example { command: "ssh -p 2222 user@host", description: "Connect on custom port", use_case: "Non-standard SSH port" },
971            ],
972            related_commands: vec!["scp", "sftp", "rsync"],
973        });
974
975        self.register(CommandInfo {
976            name: "scp".to_string(),
977            category: CommandCategory::Networking,
978            danger_level: DangerLevel::Caution,
979            summary: "Secure copy - transfer files over SSH",
980            description: "Securely copies files between your computer and remote servers using SSH encryption, like a secure version of copy-paste over the network. Use it to upload files to a server or download files from one. The syntax is 'scp source destination' where either can be remote (user@host:path). For example, 'scp file.txt user@server:~/' uploads a file, while 'scp user@server:~/file.txt .' downloads it. The -r flag copies entire directories recursively. Note: the port flag is -P (capital P), not -p like ssh!",
981            common_flags: vec![
982                FlagInfo { flag: "-r", description: "Recursive: copy directories", example: Some("scp -r folder/ user@host:~/") },
983                FlagInfo { flag: "-P", description: "Port: specify SSH port (capital P!)", example: Some("scp -P 2222 file user@host:~/") },
984            ],
985            examples: vec![
986                Example { command: "scp file.txt user@host:~/", description: "Copy file to remote", use_case: "Upload file to server" },
987                Example { command: "scp user@host:~/file.txt .", description: "Copy file from remote", use_case: "Download from server" },
988            ],
989            related_commands: vec!["ssh", "rsync", "sftp"],
990        });
991
992        self.register(CommandInfo {
993            name: "rsync".to_string(),
994            category: CommandCategory::Networking,
995            danger_level: DangerLevel::Caution,
996            summary: "Remote file synchronization",
997            description: "An incredibly efficient tool for syncing files and directories between locations, either locally or over the network. Unlike scp which copies everything, rsync is smart - it only transfers the parts of files that changed, making it much faster for updates and backups. The -a flag preserves everything (permissions, timestamps, etc.) and is almost always used. Common for keeping backup copies synchronized, deploying websites, or maintaining identical copies of directories. The --delete flag makes the destination exactly match the source by removing extra files.",
998            common_flags: vec![
999                FlagInfo { flag: "-a", description: "Archive: preserve permissions, timestamps, etc.", example: Some("rsync -a src/ dest/") },
1000                FlagInfo { flag: "-v", description: "Verbose: show files being transferred", example: None },
1001                FlagInfo { flag: "-z", description: "Compress: compress during transfer", example: None },
1002            ],
1003            examples: vec![
1004                Example { command: "rsync -avz folder/ user@host:~/backup/", description: "Sync to remote", use_case: "Backup to server" },
1005                Example { command: "rsync -av --delete src/ dest/", description: "Mirror directories", use_case: "Keep directories identical" },
1006            ],
1007            related_commands: vec!["scp", "cp", "ssh"],
1008        });
1009
1010        // Useful utilities
1011        self.register(CommandInfo {
1012            name: "ln".to_string(),
1013            category: CommandCategory::FileManagement,
1014            danger_level: DangerLevel::Caution,
1015            summary: "Create links between files",
1016            description: "Creates links to files or directories - think of them as shortcuts or aliases. The -s flag creates symbolic (soft) links, which are like shortcuts that point to another file's path. These are what you usually want. Without -s, it creates hard links which are more complex (multiple names for the same data). Common uses include creating shorter paths to frequently accessed directories, maintaining multiple versions of programs, or making files appear in multiple locations without copying them. For example, 'ln -s /long/path/to/file shortcut' creates a convenient shortcut.",
1017            common_flags: vec![
1018                FlagInfo { flag: "-s", description: "Symbolic: create symbolic link instead of hard link", example: Some("ln -s target link") },
1019            ],
1020            examples: vec![
1021                Example { command: "ln -s /path/to/file link", description: "Create symbolic link", use_case: "Create shortcut to file" },
1022                Example { command: "ln -s /usr/bin/python3 python", description: "Link python to python3", use_case: "Alias command name" },
1023            ],
1024            related_commands: vec!["cp", "mv"],
1025        });
1026
1027        self.register(CommandInfo {
1028            name: "file".to_string(),
1029            category: CommandCategory::SystemInfo,
1030            danger_level: DangerLevel::Safe,
1031            summary: "Determine file type",
1032            description: "Identifies what type of file something really is by analyzing its actual contents, not just trusting the file extension. It can tell you if something is a text file, image, executable, archive, or dozens of other types. Useful when you encounter files with no extension, wrong extensions, or you want to verify what you're dealing with. For example, 'file mystery' might tell you it's a JPEG image even if it has no .jpg extension. Smarter than just looking at filenames!",
1033            common_flags: vec![],
1034            examples: vec![
1035                Example { command: "file document.pdf", description: "Check file type", use_case: "Verify file format" },
1036                Example { command: "file *", description: "Check all files in directory", use_case: "Identify unknown files" },
1037            ],
1038            related_commands: vec!["ls", "stat"],
1039        });
1040
1041        self.register(CommandInfo {
1042            name: "which".to_string(),
1043            category: CommandCategory::SystemInfo,
1044            danger_level: DangerLevel::Safe,
1045            summary: "Locate a command",
1046            description: "Shows you exactly where a command is located on your system by searching through your PATH directories. When you type a command like 'python', the shell looks through PATH to find it - 'which' shows you which one it finds. Useful for figuring out which version of a program you're using, especially when multiple versions are installed. For example, 'which python' might show '/usr/bin/python' or '/usr/local/bin/python'. If 'which' finds nothing, the command isn't in your PATH.",
1047            common_flags: vec![],
1048            examples: vec![
1049                Example { command: "which python", description: "Find python location", use_case: "Locate command executable" },
1050                Example { command: "which -a python", description: "Show all matches in PATH", use_case: "Find all versions of command" },
1051            ],
1052            related_commands: vec!["whereis", "type", "command"],
1053        });
1054
1055        self.register(CommandInfo {
1056            name: "date".to_string(),
1057            category: CommandCategory::SystemInfo,
1058            danger_level: DangerLevel::Safe,
1059            summary: "Print or set system date and time",
1060            description: "Shows the current date and time, or formats it in custom ways for scripts and logs. Without any options, it displays the full date and time. But you can format it however you want using format codes like '+%Y-%m-%d' for year-month-day. Super useful in scripts for creating timestamped filenames, log entries, or calculating how long something took. For example, 'date +%Y%m%d' gives you '20231215' which is perfect for backup filenames. Can also set the system time, but that requires sudo.",
1061            common_flags: vec![],
1062            examples: vec![
1063                Example { command: "date", description: "Show current date/time", use_case: "Get current timestamp" },
1064                Example { command: "date '+%Y-%m-%d'", description: "Custom date format", use_case: "Format date for filenames" },
1065            ],
1066            related_commands: vec!["cal", "timedatectl"],
1067        });
1068
1069        self.register(CommandInfo {
1070            name: "alias".to_string(),
1071            category: CommandCategory::SystemInfo,
1072            danger_level: DangerLevel::Safe,
1073            summary: "Create command shortcuts",
1074            description: "Creates custom shortcuts for commands you use frequently, saving you tons of typing. Like creating your own abbreviated commands. For example, 'alias ll=\"ls -la\"' lets you type just 'll' instead of 'ls -la' every time. These shortcuts only last for your current terminal session unless you add them to your .bashrc or .zshrc file to make them permanent. Run 'alias' with no arguments to see all your current aliases. Power users create dozens of these to speed up their workflow dramatically!",
1075            common_flags: vec![],
1076            examples: vec![
1077                Example { command: "alias ll='ls -la'", description: "Create 'll' shortcut", use_case: "Quick long listing" },
1078                Example { command: "alias", description: "List all aliases", use_case: "See existing shortcuts" },
1079            ],
1080            related_commands: vec!["unalias", "function"],
1081        });
1082
1083        self.register(CommandInfo {
1084            name: "export".to_string(),
1085            category: CommandCategory::SystemInfo,
1086            danger_level: DangerLevel::Safe,
1087            summary: "Set environment variables",
1088            description: "Sets environment variables that control how programs behave and where they look for things. Environment variables are like global settings for your terminal session. The most common one is PATH, which tells your shell where to find commands. For example, 'export EDITOR=vim' sets vim as your default editor, and 'export PATH=$PATH:/new/folder' adds a new directory to your command search path. These last only for your current session unless you add them to your .bashrc or .zshrc file.",
1089            common_flags: vec![],
1090            examples: vec![
1091                Example { command: "export PATH=$PATH:/new/path", description: "Add to PATH", use_case: "Make commands available" },
1092                Example { command: "export EDITOR=vim", description: "Set default editor", use_case: "Configure environment" },
1093            ],
1094            related_commands: vec!["env", "printenv"],
1095        });
1096
1097        self.register(CommandInfo {
1098            name: "env".to_string(),
1099            category: CommandCategory::SystemInfo,
1100            danger_level: DangerLevel::Safe,
1101            summary: "Display environment variables",
1102            description: "Displays all your environment variables (the settings that control your terminal and programs) or runs a command with modified variables. Run 'env' alone to see everything - you'll see PATH, HOME, USER, and dozens of others. You can also use it to temporarily change variables for a single command like 'env DEBUG=1 myprogram' without affecting your overall environment. Useful for debugging to see what environment a program is seeing, or checking what variables are set.",
1103            common_flags: vec![],
1104            examples: vec![
1105                Example { command: "env", description: "List all environment variables", use_case: "Check environment settings" },
1106                Example { command: "env VAR=value command", description: "Run with custom environment", use_case: "Temporary environment changes" },
1107            ],
1108            related_commands: vec!["export", "printenv"],
1109        });
1110
1111        // Package managers
1112        self.register(CommandInfo {
1113            name: "apt".to_string(),
1114            category: CommandCategory::Package,
1115            danger_level: DangerLevel::Dangerous,
1116            summary: "Advanced Package Tool (Debian/Ubuntu)",
1117            description: "The package manager for Debian-based Linux systems like Ubuntu - like an app store for the command line. Use it to install, update, and remove software. 'sudo apt update' refreshes the list of available packages, 'sudo apt install program' installs software, and 'sudo apt upgrade' updates everything you have installed. Much easier than downloading and installing programs manually. Requires sudo because it modifies system software. Essential for keeping your system updated and installing new tools.",
1118            common_flags: vec![],
1119            examples: vec![
1120                Example { command: "sudo apt update", description: "Update package list", use_case: "Refresh available packages" },
1121                Example { command: "sudo apt install package", description: "Install package", use_case: "Add new software" },
1122                Example { command: "sudo apt upgrade", description: "Upgrade all packages", use_case: "Update installed software" },
1123            ],
1124            related_commands: vec!["apt-get", "dpkg", "snap"],
1125        });
1126
1127        self.register(CommandInfo {
1128            name: "yum".to_string(),
1129            category: CommandCategory::Package,
1130            danger_level: DangerLevel::Dangerous,
1131            summary: "Yellowdog Updater Modified (RedHat/CentOS)",
1132            description: "The package manager for RedHat-based Linux systems like CentOS and older Fedora versions. Does the same job as apt but for a different family of Linux distributions. Use 'sudo yum update' to update all packages, 'sudo yum install program' to install software, and 'sudo yum remove program' to uninstall. Being gradually replaced by dnf on newer systems, but still widely used on enterprise servers. Like apt, it requires root privileges to modify system packages.",
1133            common_flags: vec![],
1134            examples: vec![
1135                Example { command: "sudo yum update", description: "Update all packages", use_case: "System maintenance" },
1136                Example { command: "sudo yum install package", description: "Install package", use_case: "Add new software" },
1137            ],
1138            related_commands: vec!["dnf", "rpm"],
1139        });
1140
1141        self.register(CommandInfo {
1142            name: "dnf".to_string(),
1143            category: CommandCategory::Package,
1144            danger_level: DangerLevel::Dangerous,
1145            summary: "Dandified YUM (Modern RedHat/Fedora)",
1146            description: "The modern replacement for yum on Fedora and newer RedHat systems, offering better performance and dependency resolution. It's basically yum 2.0 - faster, more reliable, and with cleaner output. The commands are almost identical: 'sudo dnf install', 'sudo dnf update', 'sudo dnf remove'. If you're on a modern RedHat/Fedora system, use dnf instead of yum. Most yum commands work with dnf too, making the transition easy. Like its predecessor, requires sudo for most operations.",
1147            common_flags: vec![],
1148            examples: vec![
1149                Example { command: "sudo dnf install package", description: "Install package", use_case: "Add software" },
1150                Example { command: "sudo dnf update", description: "Update packages", use_case: "System updates" },
1151            ],
1152            related_commands: vec!["yum", "rpm"],
1153        });
1154
1155        self.register(CommandInfo {
1156            name: "pacman".to_string(),
1157            category: CommandCategory::Package,
1158            danger_level: DangerLevel::Dangerous,
1159            summary: "Package manager (Arch Linux)",
1160            description: "The package manager for Arch Linux and Arch-based distributions, known for being fast and powerful but with a unique syntax. Unlike apt or yum, it uses flags: -S to install (sync), -R to remove, -Syu to update everything. 'sudo pacman -Syu' is the Arch equivalent of 'apt update && apt upgrade'. The Arch package repository is huge and very up-to-date. Power and flexibility come with complexity, so read the prompts carefully before confirming - pacman is very literal about what you ask it to do!",
1161            common_flags: vec![
1162                FlagInfo { flag: "-S", description: "Sync: install packages", example: Some("sudo pacman -S package") },
1163                FlagInfo { flag: "-Syu", description: "Full system upgrade", example: Some("sudo pacman -Syu") },
1164                FlagInfo { flag: "-R", description: "Remove: uninstall packages", example: Some("sudo pacman -R package") },
1165            ],
1166            examples: vec![
1167                Example { command: "sudo pacman -Syu", description: "System upgrade", use_case: "Update entire system" },
1168                Example { command: "sudo pacman -S package", description: "Install package", use_case: "Add new software" },
1169            ],
1170            related_commands: vec!["yay", "paru"],
1171        });
1172
1173        // More networking
1174        self.register(CommandInfo {
1175            name: "netstat".to_string(),
1176            category: CommandCategory::Networking,
1177            danger_level: DangerLevel::Safe,
1178            summary: "Network statistics",
1179            description: "Displays active network connections, listening ports, and routing information - like a network traffic monitor for your system. The most useful command is 'netstat -tuln' which shows all TCP/UDP ports that programs are listening on. Great for checking if a web server is listening on port 80, seeing what's connected to your machine, or diagnosing network issues. Being gradually replaced by the newer 'ss' command, but still widely used and available. Essential for network troubleshooting and security audits.",
1180            common_flags: vec![
1181                FlagInfo { flag: "-tuln", description: "Show TCP/UDP listening ports with numbers", example: Some("netstat -tuln") },
1182                FlagInfo { flag: "-r", description: "Display routing table", example: None },
1183            ],
1184            examples: vec![
1185                Example { command: "netstat -tuln", description: "List listening ports", use_case: "See what services are running" },
1186                Example { command: "netstat -r", description: "Show routing table", use_case: "Check network routes" },
1187            ],
1188            related_commands: vec!["ss", "lsof", "ip"],
1189        });
1190
1191        self.register(CommandInfo {
1192            name: "ifconfig".to_string(),
1193            category: CommandCategory::Networking,
1194            danger_level: DangerLevel::Caution,
1195            summary: "Configure network interfaces",
1196            description: "Shows information about your network interfaces (like WiFi and Ethernet adapters) including IP addresses, network masks, and connection status. The classic way to check 'what's my IP address' on Linux. Run 'ifconfig' to see all interfaces with their IPs. While still widely used, it's being replaced by the more powerful 'ip' command on modern systems. You can also use it to configure networks, but that requires sudo and is rarely done manually anymore. Quick way to check your network configuration.",
1197            common_flags: vec![],
1198            examples: vec![
1199                Example { command: "ifconfig", description: "Show all interfaces", use_case: "Check network configuration" },
1200                Example { command: "ifconfig eth0", description: "Show specific interface", use_case: "Get interface details" },
1201            ],
1202            related_commands: vec!["ip", "iwconfig"],
1203        });
1204
1205        self.register(CommandInfo {
1206            name: "ip".to_string(),
1207            category: CommandCategory::Networking,
1208            danger_level: DangerLevel::Caution,
1209            summary: "Show/manipulate routing and network devices",
1210            description: "The modern, powerful replacement for ifconfig with more features and better consistency. Use 'ip addr show' to see IP addresses (like ifconfig), 'ip route show' for routing information, and 'ip link show' for network interfaces. The syntax is more structured and scriptable than ifconfig. Becoming the standard on all Linux systems - if you're learning networking commands, learn 'ip' instead of ifconfig. Can do everything ifconfig does and much more, from managing VLANs to setting up tunnels.",
1211            common_flags: vec![],
1212            examples: vec![
1213                Example { command: "ip addr show", description: "Show IP addresses", use_case: "View network configuration" },
1214                Example { command: "ip route show", description: "Display routing table", use_case: "Check network routes" },
1215                Example { command: "ip link show", description: "Show network interfaces", use_case: "List network devices" },
1216            ],
1217            related_commands: vec!["ifconfig", "route"],
1218        });
1219
1220        self.register(CommandInfo {
1221            name: "nc".to_string(),
1222            category: CommandCategory::Networking,
1223            danger_level: DangerLevel::Caution,
1224            summary: "Netcat - networking swiss army knife",
1225            description: "A versatile networking tool that can read and write data across network connections, often called the 'Swiss Army knife' of networking. You can use it to test if a port is open, create simple chat servers, transfer files, debug network services, or scan ports. For example, 'nc -l 8080' listens on port 8080, while 'nc example.com 80' connects to port 80. Great for testing network connectivity, debugging services, or quick file transfers. Simple but incredibly powerful for network troubleshooting.",
1226            common_flags: vec![
1227                FlagInfo { flag: "-l", description: "Listen mode: listen for incoming connections", example: Some("nc -l 8080") },
1228                FlagInfo { flag: "-v", description: "Verbose: more detailed output", example: None },
1229            ],
1230            examples: vec![
1231                Example { command: "nc -l 8080", description: "Listen on port 8080", use_case: "Test network connectivity" },
1232                Example { command: "nc example.com 80", description: "Connect to port 80", use_case: "Test HTTP connection" },
1233            ],
1234            related_commands: vec!["telnet", "curl", "socat"],
1235        });
1236
1237        self.register(CommandInfo {
1238            name: "traceroute".to_string(),
1239            category: CommandCategory::Networking,
1240            danger_level: DangerLevel::Safe,
1241            summary: "Trace route to network host",
1242            description: "Traces the complete network path from your computer to a destination, showing every router (hop) along the way. Like following breadcrumbs across the internet. Each line shows a router your data passes through, with response times. Incredibly useful for diagnosing where network problems occur - if packets get slow or lost at a specific hop, you know where the problem is. For example, 'traceroute google.com' shows you all the routers between you and Google. Network admins use this constantly for troubleshooting.",
1243            common_flags: vec![],
1244            examples: vec![
1245                Example { command: "traceroute google.com", description: "Trace route to Google", use_case: "Diagnose network problems" },
1246            ],
1247            related_commands: vec!["ping", "mtr"],
1248        });
1249
1250        self.register(CommandInfo {
1251            name: "nslookup".to_string(),
1252            category: CommandCategory::Networking,
1253            danger_level: DangerLevel::Safe,
1254            summary: "Query DNS servers",
1255            description: "Looks up domain names in DNS (Domain Name System) to find their IP addresses, or vice versa. Like looking up a phone number in a directory. Use it to check if a domain resolves correctly, find a website's IP address, or troubleshoot DNS problems. For example, 'nslookup google.com' shows you Google's IP addresses. Essential for diagnosing website connection issues - if nslookup can't find a domain, the problem is likely DNS-related. Being replaced by 'dig' on modern systems but still widely used.",
1256            common_flags: vec![],
1257            examples: vec![
1258                Example { command: "nslookup google.com", description: "Look up IP for domain", use_case: "DNS troubleshooting" },
1259            ],
1260            related_commands: vec!["dig", "host"],
1261        });
1262
1263        self.register(CommandInfo {
1264            name: "dig".to_string(),
1265            category: CommandCategory::Networking,
1266            danger_level: DangerLevel::Safe,
1267            summary: "DNS lookup utility",
1268            description: "A more powerful and detailed DNS lookup tool than nslookup, providing comprehensive information about DNS records. Network professionals prefer it for its detailed output showing query time, DNS server used, and complete record information. Use 'dig google.com' for full details, or 'dig +short google.com' to just get the IP address quickly. Can query specific record types (A, MX, TXT, etc.) and provides timing information useful for performance troubleshooting. The go-to tool for serious DNS investigation.",
1269            common_flags: vec![
1270                FlagInfo { flag: "+short", description: "Short output: just the answer", example: Some("dig +short google.com") },
1271            ],
1272            examples: vec![
1273                Example { command: "dig google.com", description: "Query DNS records", use_case: "Detailed DNS information" },
1274                Example { command: "dig +short google.com", description: "Get just the IP", use_case: "Quick DNS lookup" },
1275            ],
1276            related_commands: vec!["nslookup", "host"],
1277        });
1278
1279        // Disk utilities
1280        self.register(CommandInfo {
1281            name: "mount".to_string(),
1282            category: CommandCategory::SystemInfo,
1283            danger_level: DangerLevel::Dangerous,
1284            summary: "Mount filesystems",
1285            description: "⚠️  Attaches storage devices (like USB drives, hard disks, or network shares) to your filesystem so you can access their files. In Linux, you must 'mount' a drive before using it - it doesn't happen automatically like on Windows. Run 'mount' alone to see what's currently mounted, or 'sudo mount /dev/sdb1 /mnt' to mount a device. Always unmount with 'umount' before removing drives to prevent data corruption! Modern desktop Linux often automounts USB drives, but servers require manual mounting.",
1286            common_flags: vec![
1287                FlagInfo { flag: "-t", description: "Type: specify filesystem type", example: Some("mount -t ext4 /dev/sdb1 /mnt") },
1288            ],
1289            examples: vec![
1290                Example { command: "mount", description: "Show mounted filesystems", use_case: "See what's mounted" },
1291                Example { command: "sudo mount /dev/sdb1 /mnt", description: "Mount device", use_case: "Access external drive" },
1292            ],
1293            related_commands: vec!["umount", "df", "lsblk"],
1294        });
1295
1296        self.register(CommandInfo {
1297            name: "umount".to_string(),
1298            category: CommandCategory::SystemInfo,
1299            danger_level: DangerLevel::Dangerous,
1300            summary: "Unmount filesystems",
1301            description: "⚠️  Safely detaches mounted filesystems, ensuring all data is written before disconnecting the device. ALWAYS run this before unplugging USB drives or external drives - yanking them out while mounted can corrupt data! Use 'sudo umount /mnt' where /mnt is the mount point. If it says 'device is busy', something is still using files on that drive - close programs and try again. The safe eject button equivalent for Linux command line. Note the spelling: it's 'umount', not 'unmount'!",
1302            common_flags: vec![],
1303            examples: vec![
1304                Example { command: "sudo umount /mnt", description: "Unmount filesystem", use_case: "Safely remove external drive" },
1305            ],
1306            related_commands: vec!["mount", "eject"],
1307        });
1308
1309        self.register(CommandInfo {
1310            name: "lsblk".to_string(),
1311            category: CommandCategory::SystemInfo,
1312            danger_level: DangerLevel::Safe,
1313            summary: "List block devices",
1314            description: "Displays all storage devices (hard drives, SSDs, USB drives) in a tree structure showing their partitions and mount points. Think of it as a visual map of all your disks and how they're divided up. Use 'lsblk -f' to also see filesystem types and UUIDs, which is super useful when setting up Arch Linux or troubleshooting mount issues. Much easier to read than parsing fdisk output. Perfect for quickly seeing what drives are connected and where they're mounted.",
1315            common_flags: vec![
1316                FlagInfo { flag: "-f", description: "Filesystems: show filesystem information", example: Some("lsblk -f") },
1317            ],
1318            examples: vec![
1319                Example { command: "lsblk", description: "List all block devices", use_case: "See connected drives" },
1320                Example { command: "lsblk -f", description: "Show with filesystem details", use_case: "Check filesystem types" },
1321            ],
1322            related_commands: vec!["fdisk", "df", "mount"],
1323        });
1324
1325        self.register(CommandInfo {
1326            name: "fdisk".to_string(),
1327            category: CommandCategory::SystemInfo,
1328            danger_level: DangerLevel::Critical,
1329            summary: "Partition table manipulator",
1330            description: "⚠️ CRITICAL: A powerful but dangerous tool for creating, deleting, and modifying disk partitions. Think of it like dividing a hard drive into separate sections - but one wrong move can erase everything! Essential for setting up Arch Linux where you need to partition your disk before installation. Use 'fdisk -l' to safely LIST partitions without changing anything. When actually partitioning (just 'fdisk /dev/sda'), you work in an interactive menu - changes aren't saved until you explicitly write them with 'w'. Beginners should consider using the safer 'cfdisk' which has a friendlier interface.",
1331            common_flags: vec![
1332                FlagInfo { flag: "-l", description: "List: show partition tables (safe)", example: Some("sudo fdisk -l") },
1333            ],
1334            examples: vec![
1335                Example { command: "sudo fdisk -l", description: "List partitions (safe)", use_case: "View disk layout" },
1336            ],
1337            related_commands: vec!["parted", "gparted", "lsblk"],
1338        });
1339
1340        // More compression
1341        self.register(CommandInfo {
1342            name: "bzip2".to_string(),
1343            category: CommandCategory::Archiving,
1344            danger_level: DangerLevel::Caution,
1345            summary: "Compress files with bzip2",
1346            description: "Compresses files more effectively than gzip, typically achieving 10-15% better compression, but takes longer to run. Creates .bz2 files that are great for archiving large files you don't access frequently. Like gzip, it replaces the original file unless you use -k to keep it. Common for distributing source code (you'll see .tar.bz2 archives). Use 'bzip2 -d' to decompress, or the 'bunzip2' command. When you need maximum space savings and don't mind waiting a bit longer, bzip2 is your friend.",
1347            common_flags: vec![
1348                FlagInfo { flag: "-k", description: "Keep: keep original file", example: Some("bzip2 -k file.txt") },
1349                FlagInfo { flag: "-d", description: "Decompress: uncompress files", example: Some("bzip2 -d file.bz2") },
1350            ],
1351            examples: vec![
1352                Example { command: "bzip2 file.txt", description: "Compress file", use_case: "Better compression ratio" },
1353                Example { command: "bzip2 -d file.bz2", description: "Decompress file", use_case: "Extract bz2 file" },
1354            ],
1355            related_commands: vec!["gzip", "xz", "tar"],
1356        });
1357
1358        self.register(CommandInfo {
1359            name: "xz".to_string(),
1360            category: CommandCategory::Archiving,
1361            danger_level: DangerLevel::Caution,
1362            summary: "Compress with xz (best compression)",
1363            description: "The champion of compression - squeezes files down to the smallest possible size, but takes the longest time to do it. Creates .xz files that can be 30-50% smaller than gzip. Increasingly popular for software distribution (many Linux packages now use .tar.xz format). Great for long-term archival where you want to save maximum disk space and don't mind the slow compression. Decompression is reasonably fast. Use 'xz -d' to decompress or the 'unxz' command. When disk space is at a premium and you have time to spare, xz delivers the best results.",
1364            common_flags: vec![
1365                FlagInfo { flag: "-k", description: "Keep: keep original file", example: Some("xz -k file.txt") },
1366                FlagInfo { flag: "-d", description: "Decompress: uncompress files", example: Some("xz -d file.xz") },
1367            ],
1368            examples: vec![
1369                Example { command: "xz file.txt", description: "Compress file", use_case: "Maximum compression" },
1370                Example { command: "xz -d file.xz", description: "Decompress file", use_case: "Extract xz file" },
1371            ],
1372            related_commands: vec!["gzip", "bzip2", "tar"],
1373        });
1374
1375        // Text editors
1376        self.register(CommandInfo {
1377            name: "nano".to_string(),
1378            category: CommandCategory::TextProcessing,
1379            danger_level: DangerLevel::Safe,
1380            summary: "Simple text editor",
1381            description: "The most beginner-friendly command-line text editor - no confusing modes or cryptic commands! When you open a file, you can just start typing. All the keyboard shortcuts are helpfully displayed at the bottom of the screen (^ means Ctrl, so ^X means Ctrl+X to exit). Perfect for quick config file edits, writing scripts, or editing text without leaving the terminal. Use Ctrl+O to save (WriteOut), Ctrl+X to exit, and Ctrl+W to search. If you're new to Linux, start with nano before attempting vim or emacs!",
1382            common_flags: vec![],
1383            examples: vec![
1384                Example { command: "nano file.txt", description: "Edit file", use_case: "Simple text editing" },
1385                Example { command: "nano -w file.txt", description: "Disable line wrapping", use_case: "Edit code files" },
1386            ],
1387            related_commands: vec!["vim", "emacs", "vi"],
1388        });
1389
1390        self.register(CommandInfo {
1391            name: "vi".to_string(),
1392            category: CommandCategory::TextProcessing,
1393            danger_level: DangerLevel::Safe,
1394            summary: "Visual editor (classic)",
1395            description: "The classic Unix text editor that's guaranteed to be on every Linux system - even minimal ones. It's modal, meaning it has different modes for different tasks, which is confusing at first but powerful once learned. Starts in 'normal' mode where you can't type - press 'i' to enter 'insert' mode to actually edit text. Press ESC to go back to normal mode, then type ':wq' and press Enter to save and quit (or ':q!' to quit without saving). Learning vi basics is essential because when you SSH into servers, vi is often the only editor available.",
1396            common_flags: vec![],
1397            examples: vec![
1398                Example { command: "vi file.txt", description: "Edit file", use_case: "Universal text editor" },
1399            ],
1400            related_commands: vec!["vim", "nano", "emacs"],
1401        });
1402
1403        self.register(CommandInfo {
1404            name: "vim".to_string(),
1405            category: CommandCategory::TextProcessing,
1406            danger_level: DangerLevel::Safe,
1407            summary: "Vi IMproved - advanced text editor",
1408            description: "An enhanced version of vi with syntax highlighting, plugins, multiple undo levels, and tons of features that make it a favorite among developers. The learning curve is steep - expect to spend a week getting comfortable - but once mastered, you can edit text incredibly fast without ever touching your mouse. Has the same modal system as vi (insert mode for typing, normal mode for commands) but with way more capabilities. Power users customize it extensively with plugins and configurations. If you're serious about command-line editing and willing to invest time learning, vim will reward you with blazing speed.",
1409            common_flags: vec![],
1410            examples: vec![
1411                Example { command: "vim file.txt", description: "Edit file", use_case: "Advanced text editing" },
1412                Example { command: "vim +10 file.txt", description: "Open at line 10", use_case: "Jump to specific line" },
1413            ],
1414            related_commands: vec!["vi", "nvim", "nano"],
1415        });
1416
1417        // System services
1418        self.register(CommandInfo {
1419            name: "systemctl".to_string(),
1420            category: CommandCategory::SystemInfo,
1421            danger_level: DangerLevel::Dangerous,
1422            summary: "Control systemd services",
1423            description: "The control center for managing system services (daemons) on modern Linux systems using systemd. Like the Services panel in Windows, but more powerful. Use it to start/stop services like web servers or databases, check their status, enable them to start at boot, or view their logs. For example, 'systemctl status nginx' checks if nginx is running, 'sudo systemctl start nginx' launches it, and 'sudo systemctl enable nginx' makes it auto-start on boot. Essential for server administration and managing background services on your Linux system.",
1424            common_flags: vec![],
1425            examples: vec![
1426                Example { command: "systemctl status nginx", description: "Check service status", use_case: "See if service is running" },
1427                Example { command: "sudo systemctl start nginx", description: "Start service", use_case: "Launch a service" },
1428                Example { command: "sudo systemctl enable nginx", description: "Enable on boot", use_case: "Auto-start service" },
1429            ],
1430            related_commands: vec!["service", "journalctl"],
1431        });
1432
1433        self.register(CommandInfo {
1434            name: "service".to_string(),
1435            category: CommandCategory::SystemInfo,
1436            danger_level: DangerLevel::Dangerous,
1437            summary: "Run init script (legacy)",
1438            description: "The old-school way of managing services from before systemd became standard on most Linux distributions. Still works on modern systems and is simpler to remember for basic operations - 'sudo service nginx start/stop/restart/status'. It's actually a compatibility wrapper that calls systemctl behind the scenes on systemd systems. Some older tutorials and scripts still use it. While 'systemctl' is more powerful and the modern standard, 'service' is perfectly fine for basic start/stop operations and works on both old and new systems.",
1439            common_flags: vec![],
1440            examples: vec![
1441                Example { command: "sudo service nginx status", description: "Check service", use_case: "Service status check" },
1442                Example { command: "sudo service nginx restart", description: "Restart service", use_case: "Apply configuration changes" },
1443            ],
1444            related_commands: vec!["systemctl", "init"],
1445        });
1446
1447        self.register(CommandInfo {
1448            name: "crontab".to_string(),
1449            category: CommandCategory::SystemInfo,
1450            danger_level: DangerLevel::Caution,
1451            summary: "Schedule periodic jobs",
1452            description: "Your personal task scheduler for automating commands that need to run at specific times or intervals. Like Windows Task Scheduler but controlled through the command line. Use 'crontab -e' to edit your schedule, where each line specifies when and what to run (format: minute hour day month weekday command). Perfect for automating backups, cleanup scripts, or any repetitive tasks. For example, you could run a backup script every night at 2 AM, or check for updates every Monday. Use 'crontab -l' to view your current scheduled jobs.",
1453            common_flags: vec![
1454                FlagInfo { flag: "-e", description: "Edit: edit crontab file", example: Some("crontab -e") },
1455                FlagInfo { flag: "-l", description: "List: display crontab", example: Some("crontab -l") },
1456            ],
1457            examples: vec![
1458                Example { command: "crontab -e", description: "Edit scheduled jobs", use_case: "Add automated tasks" },
1459                Example { command: "crontab -l", description: "List cron jobs", use_case: "See scheduled tasks" },
1460            ],
1461            related_commands: vec!["at", "systemd-timer"],
1462        });
1463
1464        // File utilities
1465        self.register(CommandInfo {
1466            name: "diff".to_string(),
1467            category: CommandCategory::TextProcessing,
1468            danger_level: DangerLevel::Safe,
1469            summary: "Compare files line by line",
1470            description: "Compares two files and shows exactly what's different between them, line by line. Like Track Changes in Word but for any text files. Incredibly useful for seeing what changed between versions of a config file, comparing your edited code to the original, or reviewing changes before committing to git. The output shows lines that were added (marked with +), removed (marked with -), or changed. Use the -u flag for 'unified diff' format which is easier to read and what git uses. Essential tool for developers and system administrators.",
1471            common_flags: vec![
1472                FlagInfo { flag: "-u", description: "Unified: unified diff format (most common)", example: Some("diff -u file1 file2") },
1473                FlagInfo { flag: "-r", description: "Recursive: compare directories", example: Some("diff -r dir1/ dir2/") },
1474            ],
1475            examples: vec![
1476                Example { command: "diff file1.txt file2.txt", description: "Compare two files", use_case: "See what changed" },
1477                Example { command: "diff -u old.txt new.txt", description: "Unified diff format", use_case: "Git-style comparison" },
1478            ],
1479            related_commands: vec!["patch", "comm", "cmp"],
1480        });
1481
1482        self.register(CommandInfo {
1483            name: "patch".to_string(),
1484            category: CommandCategory::TextProcessing,
1485            danger_level: DangerLevel::Caution,
1486            summary: "Apply diff file to original",
1487            description: "Takes a patch file (created by diff) and applies those changes to the original files, automatically making all the edits for you. Like having someone tell you exactly which lines to change, add, or remove, and doing it automatically. Commonly used to apply bug fixes or updates to source code without downloading entire new files. For example, open source projects often distribute patches for security fixes. Use it like 'patch < changes.patch' to update your files. Be cautious - it modifies files directly, so keep backups when patching important code!",
1488            common_flags: vec![],
1489            examples: vec![
1490                Example { command: "patch < changes.patch", description: "Apply patch", use_case: "Update files from diff" },
1491            ],
1492            related_commands: vec!["diff", "git apply"],
1493        });
1494
1495        self.register(CommandInfo {
1496            name: "tree".to_string(),
1497            category: CommandCategory::Navigation,
1498            danger_level: DangerLevel::Safe,
1499            summary: "List directory contents in tree format",
1500            description: "Displays your directory structure as a beautiful visual tree with branches showing the hierarchy, making it easy to see how folders and files are organized at a glance. Like Windows Explorer's folder tree view, but prettier! Perfect for understanding a project's structure, documenting folder layouts, or getting a quick overview of what's in a directory and its subdirectories. Use -L to limit depth (like 'tree -L 2' for just 2 levels deep) to avoid overwhelming output in large projects. Great for README files and documentation.",
1501            common_flags: vec![
1502                FlagInfo { flag: "-L", description: "Level: limit depth of recursion", example: Some("tree -L 2") },
1503                FlagInfo { flag: "-d", description: "Directories: show only directories", example: Some("tree -d") },
1504            ],
1505            examples: vec![
1506                Example { command: "tree", description: "Show directory tree", use_case: "Visualize folder structure" },
1507                Example { command: "tree -L 2", description: "Show 2 levels deep", use_case: "Quick project overview" },
1508            ],
1509            related_commands: vec!["ls", "find"],
1510        });
1511
1512        self.register(CommandInfo {
1513            name: "xargs".to_string(),
1514            category: CommandCategory::TextProcessing,
1515            danger_level: DangerLevel::Caution,
1516            summary: "Build and execute commands from standard input",
1517            description: "Converts input from one command into arguments for another command, enabling powerful pipelines and batch operations. Think of it as a bridge that lets you use the output of one command as the input to another in creative ways. For example, 'find . -name \"*.log\" | xargs rm' finds all .log files and deletes them. The -I flag lets you control exactly where the input goes in the command. Essential for processing lists of files or performing the same operation on multiple items. Great for automation but use carefully - always test with 'echo' first!",
1518            common_flags: vec![
1519                FlagInfo { flag: "-I", description: "Replace string: specify placeholder", example: Some("find . -name '*.txt' | xargs -I {} cp {} /backup/") },
1520            ],
1521            examples: vec![
1522                Example { command: "find . -name '*.log' | xargs rm", description: "Delete all .log files", use_case: "Batch file operations" },
1523                Example { command: "ls *.txt | xargs -I {} cp {} /backup/", description: "Copy files with placeholder", use_case: "Process each file" },
1524            ],
1525            related_commands: vec!["find", "parallel"],
1526        });
1527
1528        self.register(CommandInfo {
1529            name: "tee".to_string(),
1530            category: CommandCategory::TextProcessing,
1531            danger_level: DangerLevel::Safe,
1532            summary: "Read from stdin and write to stdout and files",
1533            description: "Splits command output into two streams - showing it on your screen AND saving it to a file at the same time. Like a T-junction in a pipe (hence the name 'tee'). Super useful when you want to watch a command's output live while also keeping a permanent log. For example, 'make | tee build.log' lets you watch your code compile while saving all the output to a file for later review. The -a flag appends instead of overwriting. Perfect for logging long-running processes or build outputs.",
1534            common_flags: vec![
1535                FlagInfo { flag: "-a", description: "Append: append to file instead of overwriting", example: Some("command | tee -a log.txt") },
1536            ],
1537            examples: vec![
1538                Example { command: "ls -la | tee output.txt", description: "Save and display output", use_case: "Log command output" },
1539                Example { command: "make | tee build.log", description: "Log build output", use_case: "Save compilation output" },
1540            ],
1541            related_commands: vec!["cat", "redirect"],
1542        });
1543
1544        self.register(CommandInfo {
1545            name: "watch".to_string(),
1546            category: CommandCategory::SystemInfo,
1547            danger_level: DangerLevel::Safe,
1548            summary: "Execute a program periodically",
1549            description: "Runs a command over and over again at regular intervals (default every 2 seconds) and displays the updated output, clearing the screen each time. Like hitting refresh repeatedly on a webpage, but automated. Perfect for monitoring things that change over time - disk space usage, active processes, file modifications, or network connections. For example, 'watch df -h' shows you disk space updating in real-time. Use -n to change the interval, like 'watch -n 5 command' to run every 5 seconds. Press Ctrl+C to stop watching.",
1550            common_flags: vec![
1551                FlagInfo { flag: "-n", description: "Interval: seconds between updates", example: Some("watch -n 2 df -h") },
1552            ],
1553            examples: vec![
1554                Example { command: "watch df -h", description: "Monitor disk space", use_case: "Watch space usage in real-time" },
1555                Example { command: "watch -n 5 'ls -l'", description: "Watch directory every 5 seconds", use_case: "Monitor file changes" },
1556            ],
1557            related_commands: vec!["top", "tail -f"],
1558        });
1559
1560        self.register(CommandInfo {
1561            name: "time".to_string(),
1562            category: CommandCategory::SystemInfo,
1563            danger_level: DangerLevel::Safe,
1564            summary: "Time command execution",
1565            description: "Measures and reports how long a command takes to run, giving you three numbers: real time (total clock time), user time (CPU time in your code), and system time (CPU time in kernel/system calls). Like a stopwatch for your commands. Great for benchmarking scripts, finding performance bottlenecks, or just satisfying curiosity about how long things take. For example, 'time ls -R' shows how long it takes to recursively list all files. The output appears after the command finishes. Essential for optimization work.",
1566            common_flags: vec![],
1567            examples: vec![
1568                Example { command: "time ls -R", description: "Time a command", use_case: "Measure performance" },
1569                Example { command: "time ./script.sh", description: "Time script execution", use_case: "Benchmark script" },
1570            ],
1571            related_commands: vec!["timeout", "date"],
1572        });
1573
1574        self.register(CommandInfo {
1575            name: "sleep".to_string(),
1576            category: CommandCategory::SystemInfo,
1577            danger_level: DangerLevel::Safe,
1578            summary: "Delay for specified time",
1579            description: "Pauses for a specified amount of time before continuing - literally makes your terminal sleep! Takes a number of seconds by default, but you can use 'm' for minutes, 'h' for hours, or 'd' for days. Essential in scripts when you need to wait between operations, like pausing before retrying a failed network connection or spacing out API requests. For example, 'sleep 5' waits 5 seconds, 'sleep 2m' waits 2 minutes. Can also chain commands like 'echo Starting... && sleep 3 && echo Done!' for timed sequences.",
1580            common_flags: vec![],
1581            examples: vec![
1582                Example { command: "sleep 5", description: "Sleep for 5 seconds", use_case: "Add delay in script" },
1583                Example { command: "sleep 1m", description: "Sleep for 1 minute", use_case: "Longer delays" },
1584            ],
1585            related_commands: vec!["wait", "timeout"],
1586        });
1587
1588        // User management
1589        self.register(CommandInfo {
1590            name: "useradd".to_string(),
1591            category: CommandCategory::SystemInfo,
1592            danger_level: DangerLevel::Dangerous,
1593            summary: "Create a new user",
1594            description: "⚠️  Creates a new user account on the system, assigning them a username, user ID, and optionally a home directory and default shell. Requires sudo/root access since you're modifying system accounts. Use -m to create their home directory automatically (highly recommended). For example, 'sudo useradd -m john' creates user john with a home directory at /home/john. After creating the user, you'll want to set their password with 'sudo passwd john'. Essential for multi-user systems and servers. Note: Some systems have 'adduser' which is more interactive and beginner-friendly.",
1595            common_flags: vec![
1596                FlagInfo { flag: "-m", description: "Create home directory", example: Some("sudo useradd -m username") },
1597            ],
1598            examples: vec![
1599                Example { command: "sudo useradd -m john", description: "Create user with home dir", use_case: "Add new system user" },
1600            ],
1601            related_commands: vec!["userdel", "usermod", "adduser"],
1602        });
1603
1604        self.register(CommandInfo {
1605            name: "userdel".to_string(),
1606            category: CommandCategory::SystemInfo,
1607            danger_level: DangerLevel::Dangerous,
1608            summary: "Delete a user account",
1609            description: "⚠️  Permanently removes a user account from the system. Requires root privileges. By default it only removes the account entry, leaving their home directory and files intact. Use the -r flag to also delete their home directory and mail spool - but be careful, this deletes all their files! For example, 'sudo userdel john' removes the account but keeps /home/john, while 'sudo userdel -r john' removes everything. Always backup important data before deleting users. Used for cleaning up old accounts or removing compromised accounts on servers.",
1610            common_flags: vec![
1611                FlagInfo { flag: "-r", description: "Remove: delete home directory and mail spool", example: Some("sudo userdel -r username") },
1612            ],
1613            examples: vec![
1614                Example { command: "sudo userdel john", description: "Delete user", use_case: "Remove user account" },
1615                Example { command: "sudo userdel -r john", description: "Delete user and files", use_case: "Complete user removal" },
1616            ],
1617            related_commands: vec!["useradd", "usermod"],
1618        });
1619
1620        self.register(CommandInfo {
1621            name: "passwd".to_string(),
1622            category: CommandCategory::SystemInfo,
1623            danger_level: DangerLevel::Caution,
1624            summary: "Change user password",
1625            description: "Changes a user's password securely. When run without arguments, it changes YOUR password - the system will ask for your current password, then the new one twice for confirmation. With sudo, you can reset other users' passwords like 'sudo passwd john' without needing their old password (useful when users forget their passwords). The password you type won't be visible on screen for security. Important for maintaining account security and resetting forgotten passwords. The system enforces password complexity rules on most distributions.",
1626            common_flags: vec![],
1627            examples: vec![
1628                Example { command: "passwd", description: "Change your password", use_case: "Update your password" },
1629                Example { command: "sudo passwd john", description: "Change another user's password", use_case: "Reset user password" },
1630            ],
1631            related_commands: vec!["chpasswd", "usermod"],
1632        });
1633
1634        self.register(CommandInfo {
1635            name: "groups".to_string(),
1636            category: CommandCategory::SystemInfo,
1637            danger_level: DangerLevel::Safe,
1638            summary: "Print group memberships",
1639            description: "Lists all the groups that a user belongs to, which determines what files and resources they can access. In Linux, permissions are managed through user and group ownership. Being in the 'sudo' group gives admin privileges, 'docker' group allows Docker access, etc. Run 'groups' alone to see YOUR groups, or 'groups username' to see someone else's. If you can't access something even with the right file permissions, check if you're in the required group. After being added to a new group, you may need to log out and back in for it to take effect.",
1640            common_flags: vec![],
1641            examples: vec![
1642                Example { command: "groups", description: "Show your groups", use_case: "Check group membership" },
1643                Example { command: "groups john", description: "Show user's groups", use_case: "View another user's groups" },
1644            ],
1645            related_commands: vec!["id", "usermod"],
1646        });
1647
1648        // Build tools
1649        self.register(CommandInfo {
1650            name: "make".to_string(),
1651            category: CommandCategory::Build,
1652            danger_level: DangerLevel::Safe,
1653            summary: "Build automation tool",
1654            description: "The classic build automation tool that reads a Makefile containing instructions on how to compile your project and runs them in the correct order. It's smart - only recompiles files that changed, saving time on large projects. Standard for C/C++ projects but used for many other types of builds too. When you download source code and see a Makefile, typically you run './configure && make && sudo make install' to build and install it. The -j flag enables parallel compilation using multiple CPU cores, dramatically speeding up builds on modern machines. Essential for building software from source.",
1655            common_flags: vec![
1656                FlagInfo { flag: "-j", description: "Jobs: number of parallel jobs", example: Some("make -j4") },
1657            ],
1658            examples: vec![
1659                Example { command: "make", description: "Build project", use_case: "Compile from source" },
1660                Example { command: "make install", description: "Install built software", use_case: "System-wide installation" },
1661            ],
1662            related_commands: vec!["cmake", "gcc", "configure"],
1663        });
1664
1665        self.register(CommandInfo {
1666            name: "npm".to_string(),
1667            category: CommandCategory::Package,
1668            danger_level: DangerLevel::Caution,
1669            summary: "Node Package Manager",
1670            description: "The official package manager for Node.js and JavaScript, managing libraries and tools for your web development projects. Run 'npm install' in a project folder to download all dependencies listed in package.json. Use 'npm install package-name' to add a new package, 'npm start' to run your application, and 'npm run build' for build scripts. It's like apt for JavaScript - handles versioning, dependencies, and scripts automatically. Essential for any modern JavaScript or Node.js development. The npm registry has over a million packages available!",
1671            common_flags: vec![],
1672            examples: vec![
1673                Example { command: "npm install", description: "Install dependencies", use_case: "Set up Node.js project" },
1674                Example { command: "npm start", description: "Run start script", use_case: "Launch application" },
1675                Example { command: "npm install package", description: "Install package", use_case: "Add dependency" },
1676            ],
1677            related_commands: vec!["yarn", "pnpm", "npx"],
1678        });
1679
1680        self.register(CommandInfo {
1681            name: "pip".to_string(),
1682            category: CommandCategory::Package,
1683            danger_level: DangerLevel::Caution,
1684            summary: "Python Package Installer",
1685            description: "The standard package manager for Python, downloading and installing libraries from PyPI (Python Package Index) - a repository with hundreds of thousands of Python packages. Use 'pip install requests' to add a library, 'pip list' to see what's installed, and 'pip install -r requirements.txt' to install all dependencies for a project at once. The 'pip' command usually works with Python 2, while 'pip3' is for Python 3 (though on modern systems, pip often points to pip3). Essential for any Python development - it's how you add functionality beyond Python's standard library.",
1686            common_flags: vec![],
1687            examples: vec![
1688                Example { command: "pip install requests", description: "Install package", use_case: "Add Python library" },
1689                Example { command: "pip list", description: "List installed packages", use_case: "See what's installed" },
1690                Example { command: "pip install -r requirements.txt", description: "Install from file", use_case: "Set up project dependencies" },
1691            ],
1692            related_commands: vec!["pip3", "conda", "poetry"],
1693        });
1694
1695        self.register(CommandInfo {
1696            name: "cargo".to_string(),
1697            category: CommandCategory::Build,
1698            danger_level: DangerLevel::Safe,
1699            summary: "Rust package manager and build tool",
1700            description: "The all-in-one build tool and package manager for Rust, handling compilation, dependencies, testing, and more. It's what makes Rust development so smooth! Run 'cargo build' to compile your project, 'cargo run' to build and execute it, 'cargo test' to run tests, and 'cargo new project-name' to start a new project with all the boilerplate. Downloads dependencies from crates.io automatically. This very tool - Arc Academy Terminal - is built with cargo! If you're learning Rust, you'll use cargo constantly. It's beloved by developers for being fast, reliable, and having great error messages.",
1701            common_flags: vec![],
1702            examples: vec![
1703                Example { command: "cargo build", description: "Build project", use_case: "Compile Rust code" },
1704                Example { command: "cargo run", description: "Build and run", use_case: "Test application" },
1705                Example { command: "cargo test", description: "Run tests", use_case: "Execute test suite" },
1706            ],
1707            related_commands: vec!["rustc", "rustup"],
1708        });
1709
1710        // More system monitoring
1711        self.register(CommandInfo {
1712            name: "htop".to_string(),
1713            category: CommandCategory::SystemInfo,
1714            danger_level: DangerLevel::Safe,
1715            summary: "Interactive process viewer",
1716            description: "A beautiful, modernized version of 'top' with colors, mouse support, and a much friendlier interface. Shows CPU usage for each core, memory usage, and all running processes in a sortable, filterable list. You can click on column headers to sort, use arrow keys to navigate, press F9 to kill processes, and F6 to sort by different criteria. Way easier than memorizing 'top' keyboard shortcuts! If it's not installed by default, it's worth installing - most Linux users prefer it over top. Perfect for quickly checking what's using your CPU or memory.",
1717            common_flags: vec![],
1718            examples: vec![
1719                Example { command: "htop", description: "Launch interactive monitor", use_case: "Visual system monitoring" },
1720            ],
1721            related_commands: vec!["top", "ps", "atop"],
1722        });
1723
1724        self.register(CommandInfo {
1725            name: "free".to_string(),
1726            category: CommandCategory::SystemInfo,
1727            danger_level: DangerLevel::Safe,
1728            summary: "Display memory usage",
1729            description: "Displays how much RAM is free, used, and available on your system in a simple table format. Shows both physical memory (RAM) and swap space (disk-based virtual memory). Use the -h flag for human-readable output in GB/MB instead of confusing kilobytes. Important: Linux uses 'available' memory for caching to speed things up, so 'used' looks higher than it really is - check the 'available' column for how much is truly free for applications. Quick way to see if you're running low on memory or if a program is eating all your RAM.",
1730            common_flags: vec![
1731                FlagInfo { flag: "-h", description: "Human-readable: show in GB/MB/KB", example: Some("free -h") },
1732            ],
1733            examples: vec![
1734                Example { command: "free -h", description: "Show memory usage", use_case: "Check available RAM" },
1735            ],
1736            related_commands: vec!["top", "vmstat"],
1737        });
1738
1739        self.register(CommandInfo {
1740            name: "uptime".to_string(),
1741            category: CommandCategory::SystemInfo,
1742            danger_level: DangerLevel::Safe,
1743            summary: "Show how long system has been running",
1744            description: "Shows how long your system has been running since the last reboot, along with load averages. Great for bragging about server stability (\"my server has been up for 500 days!\") or checking if a recent reboot occurred. Also displays the current time, how many users are logged in, and the load average (how busy the CPU has been over the last 1, 5, and 15 minutes). On servers, high uptime is often a point of pride, though regular reboots for security updates are actually better practice. Simple but informative.",
1745            common_flags: vec![],
1746            examples: vec![
1747                Example { command: "uptime", description: "Show system uptime", use_case: "Check how long server has been up" },
1748            ],
1749            related_commands: vec!["w", "who"],
1750        });
1751
1752        self.register(CommandInfo {
1753            name: "uname".to_string(),
1754            category: CommandCategory::SystemInfo,
1755            danger_level: DangerLevel::Safe,
1756            summary: "Print system information",
1757            description: "Displays basic information about your system including the kernel name (Linux), kernel version, hardware architecture (x86_64, ARM, etc.), and more. Use 'uname -a' to see everything at once - useful when reporting bugs or checking system specs. The -r flag shows just the kernel version, helpful for verifying you're running the latest kernel after updates. Often the first command you run when troubleshooting to confirm what system you're dealing with, especially when SSHing into unfamiliar servers.",
1758            common_flags: vec![
1759                FlagInfo { flag: "-a", description: "All: print all information", example: Some("uname -a") },
1760                FlagInfo { flag: "-r", description: "Release: kernel release version", example: Some("uname -r") },
1761            ],
1762            examples: vec![
1763                Example { command: "uname -a", description: "Show all system info", use_case: "Get kernel and OS details" },
1764                Example { command: "uname -r", description: "Show kernel version", use_case: "Check kernel release" },
1765            ],
1766            related_commands: vec!["lsb_release", "hostnamectl"],
1767        });
1768
1769        self.register(CommandInfo {
1770            name: "hostname".to_string(),
1771            category: CommandCategory::SystemInfo,
1772            danger_level: DangerLevel::Safe,
1773            summary: "Show or set system hostname",
1774            description: "Shows your computer's hostname - the name it uses to identify itself on the network. Like a computer's name tag. Useful when you're managing multiple servers and need to quickly confirm which one you're connected to. Use 'hostname -I' (capital i) to also see your IP addresses. The hostname is often displayed in your terminal prompt, but this command gives you just the name. You can set a new hostname with sudo, though most modern systems use 'hostnamectl' for that now.",
1775            common_flags: vec![
1776                FlagInfo { flag: "-I", description: "IP addresses: show all IP addresses", example: Some("hostname -I") },
1777            ],
1778            examples: vec![
1779                Example { command: "hostname", description: "Show hostname", use_case: "Get computer name" },
1780                Example { command: "hostname -I", description: "Show IP addresses", use_case: "Get network IPs" },
1781            ],
1782            related_commands: vec!["hostnamectl", "uname"],
1783        });
1784
1785        // System control
1786        self.register(CommandInfo {
1787            name: "reboot".to_string(),
1788            category: CommandCategory::SystemInfo,
1789            danger_level: DangerLevel::Critical,
1790            summary: "Reboot the system",
1791            description: "⚠️ CRITICAL: Immediately restarts your entire computer. Everything stops - all programs close, all users are kicked off, and the system boots back up from scratch. Use this after kernel updates or when the system is misbehaving and needs a fresh start. On multi-user servers, ALWAYS warn other users first! The command requires sudo privileges. After reboot, you'll need to log back in and restart any programs you were running. On servers, this is a big deal - plan reboots carefully and ideally during maintenance windows.",
1792            common_flags: vec![],
1793            examples: vec![
1794                Example { command: "sudo reboot", description: "Restart system", use_case: "Reboot server/computer" },
1795            ],
1796            related_commands: vec!["shutdown", "systemctl reboot"],
1797        });
1798
1799        self.register(CommandInfo {
1800            name: "shutdown".to_string(),
1801            category: CommandCategory::SystemInfo,
1802            danger_level: DangerLevel::Critical,
1803            summary: "Shutdown or restart the system",
1804            description: "⚠️ CRITICAL: The controlled way to power off or restart your system, optionally scheduling it for later. Unlike just hitting the power button, this gracefully closes all programs and saves data. Use 'sudo shutdown -h now' to power off immediately, or 'sudo shutdown -r now' to reboot. You can schedule it with 'sudo shutdown -h +30' to shutdown in 30 minutes, giving users warning time. The system will broadcast messages to logged-in users about the impending shutdown. Use 'sudo shutdown -c' to cancel a scheduled shutdown. More polite and safer than 'reboot' or 'poweroff' for managed systems.",
1805            common_flags: vec![
1806                FlagInfo { flag: "-h", description: "Halt: shutdown and power off", example: Some("sudo shutdown -h now") },
1807                FlagInfo { flag: "-r", description: "Reboot: restart the system", example: Some("sudo shutdown -r now") },
1808            ],
1809            examples: vec![
1810                Example { command: "sudo shutdown -h now", description: "Shutdown immediately", use_case: "Power off system" },
1811                Example { command: "sudo shutdown -r +10", description: "Reboot in 10 minutes", use_case: "Scheduled restart" },
1812            ],
1813            related_commands: vec!["reboot", "halt", "poweroff"],
1814        });
1815
1816        self.register(CommandInfo {
1817            name: "dmesg".to_string(),
1818            category: CommandCategory::SystemInfo,
1819            danger_level: DangerLevel::Safe,
1820            summary: "Print kernel ring buffer messages",
1821            description: "Displays messages from the Linux kernel's ring buffer, including boot messages, hardware detection events, driver loading, and importantly, hardware errors. Like peeking into the kernel's diary to see what it's been up to. Super useful for troubleshooting hardware issues - if your USB device isn't working, dmesg will show if the kernel even detected it. Use 'dmesg | tail' to see recent messages, or 'dmesg | grep -i error' to find problems. The -H flag makes it more readable with timestamps. Essential diagnostic tool when hardware isn't behaving.",
1822            common_flags: vec![
1823                FlagInfo { flag: "-H", description: "Human-readable: easier to read format", example: Some("dmesg -H") },
1824                FlagInfo { flag: "-w", description: "Wait: follow new messages in real-time", example: Some("dmesg -w") },
1825            ],
1826            examples: vec![
1827                Example { command: "dmesg | tail", description: "Show recent kernel messages", use_case: "Check for hardware errors" },
1828                Example { command: "dmesg | grep -i error", description: "Find kernel errors", use_case: "Diagnose system issues" },
1829            ],
1830            related_commands: vec!["journalctl", "syslog"],
1831        });
1832
1833        self.register(CommandInfo {
1834            name: "journalctl".to_string(),
1835            category: CommandCategory::SystemInfo,
1836            danger_level: DangerLevel::Safe,
1837            summary: "Query systemd journal logs",
1838            description: "The modern, powerful log viewer for systemd-based Linux systems, replacing old scattered log files with a unified, queryable database of system events. Use it to debug services, check what happened during boot, or investigate system problems. 'journalctl -f' follows logs in real-time like 'tail -f', while 'journalctl -u nginx' shows logs only for the nginx service. You can filter by time, priority, service, or search for specific text. Logs are stored centrally and include timestamps, priorities, and metadata. The go-to tool for system troubleshooting on modern Linux.",
1839            common_flags: vec![
1840                FlagInfo { flag: "-f", description: "Follow: stream new log entries", example: Some("journalctl -f") },
1841                FlagInfo { flag: "-u", description: "Unit: show logs for specific service", example: Some("journalctl -u nginx") },
1842            ],
1843            examples: vec![
1844                Example { command: "journalctl -f", description: "Follow system logs", use_case: "Monitor live log output" },
1845                Example { command: "journalctl -u nginx", description: "Show nginx logs", use_case: "Debug service issues" },
1846            ],
1847            related_commands: vec!["dmesg", "systemctl", "tail"],
1848        });
1849
1850        // More package managers
1851        self.register(CommandInfo {
1852            name: "brew".to_string(),
1853            category: CommandCategory::Package,
1854            danger_level: DangerLevel::Caution,
1855            summary: "Homebrew package manager (macOS/Linux)",
1856            description: "The beloved package manager that started on macOS and is now available on Linux too. Known for being user-friendly with great documentation and a huge selection of packages. Use 'brew install package-name' to install software, 'brew update' to refresh package lists, and 'brew upgrade' to update everything installed. It installs packages in its own directory to avoid conflicting with system packages. macOS users swear by it, and it's growing popular on Linux as an alternative to apt/yum. Great for installing development tools and CLI utilities.",
1857            common_flags: vec![],
1858            examples: vec![
1859                Example { command: "brew install package", description: "Install package", use_case: "Add software on macOS" },
1860                Example { command: "brew update", description: "Update package list", use_case: "Get latest packages" },
1861                Example { command: "brew upgrade", description: "Upgrade all packages", use_case: "Update installed software" },
1862            ],
1863            related_commands: vec!["apt", "yum"],
1864        });
1865
1866        self.register(CommandInfo {
1867            name: "snap".to_string(),
1868            category: CommandCategory::Package,
1869            danger_level: DangerLevel::Caution,
1870            summary: "Snap package manager (Ubuntu)",
1871            description: "Canonical's universal package format that works across different Linux distributions with apps running in isolated sandboxes for security. Snap packages are self-contained with all their dependencies, so they're larger but guaranteed to work consistently. Pre-installed on Ubuntu and growing in adoption. Use 'snap install package-name' to add software, 'snap list' to see what's installed. The sandboxing provides extra security but can cause permission issues. Some users love the convenience, others prefer traditional packages - it's somewhat controversial in the Linux community but undeniably useful.",
1872            common_flags: vec![],
1873            examples: vec![
1874                Example { command: "snap install package", description: "Install snap package", use_case: "Add sandboxed app" },
1875                Example { command: "snap list", description: "List installed snaps", use_case: "See installed packages" },
1876            ],
1877            related_commands: vec!["apt", "flatpak"],
1878        });
1879
1880        // Container tools
1881        self.register(CommandInfo {
1882            name: "docker".to_string(),
1883            category: CommandCategory::SystemInfo,
1884            danger_level: DangerLevel::Caution,
1885            summary: "Container platform",
1886            description: "The industry-standard platform for containerization - packaging applications with their dependencies into isolated, portable containers that run consistently anywhere. Think of containers as lightweight virtual machines that start in seconds instead of minutes. Use 'docker ps' to see running containers, 'docker run image-name' to start one, and 'docker build' to create your own. Revolutionary for development (\"it works on my machine\" becomes irrelevant) and deployment. Learning Docker is essential for modern DevOps and cloud development. Containers are everywhere in modern tech infrastructure.",
1887            common_flags: vec![],
1888            examples: vec![
1889                Example { command: "docker ps", description: "List running containers", use_case: "See active containers" },
1890                Example { command: "docker run image", description: "Run container from image", use_case: "Start containerized app" },
1891                Example { command: "docker build -t name .", description: "Build container image", use_case: "Create custom image" },
1892            ],
1893            related_commands: vec!["docker-compose", "podman", "kubectl"],
1894        });
1895
1896        // More text utilities
1897        self.register(CommandInfo {
1898            name: "tr".to_string(),
1899            category: CommandCategory::TextProcessing,
1900            danger_level: DangerLevel::Safe,
1901            summary: "Translate or delete characters",
1902            description: "Translates (replaces) or deletes characters from text, working character-by-character rather than on whole words. Simple but incredibly useful for text transformations. For example, 'echo \"hello\" | tr 'a-z' 'A-Z'' converts to uppercase, 'tr -d ' ' removes all spaces, and 'tr '\\n' ' '' replaces newlines with spaces. Great for cleaning up text, changing case, removing unwanted characters, or swapping characters. Works with character ranges and special characters. Simpler than sed for basic character-level operations.",
1903            common_flags: vec![
1904                FlagInfo { flag: "-d", description: "Delete: remove specified characters", example: Some("echo 'text' | tr -d 't'") },
1905            ],
1906            examples: vec![
1907                Example { command: "echo 'hello' | tr 'a-z' 'A-Z'", description: "Convert to uppercase", use_case: "Change text case" },
1908                Example { command: "echo 'hello' | tr -d 'l'", description: "Remove all 'l' characters", use_case: "Delete specific chars" },
1909            ],
1910            related_commands: vec!["sed", "awk"],
1911        });
1912
1913        self.register(CommandInfo {
1914            name: "printf".to_string(),
1915            category: CommandCategory::TextProcessing,
1916            danger_level: DangerLevel::Safe,
1917            summary: "Format and print data",
1918            description: "A more powerful version of echo with precise formatting control, similar to printf in C and other programming languages. Lets you format output exactly how you want with format specifiers like %s for strings, %d for numbers, and %f for decimals. Unlike echo, printf doesn't automatically add a newline - you control everything with \\n. For example, 'printf \"Name: %s\\nAge: %d\\n\" John 25' formats output nicely. Essential for scripting when you need predictable, formatted output or when building structured data. More portable across systems than echo's varying implementations.",
1919            common_flags: vec![],
1920            examples: vec![
1921                Example { command: "printf '%s\\n' 'Hello'", description: "Print with newline", use_case: "Formatted output" },
1922                Example { command: "printf '%d\\n' 42", description: "Print number", use_case: "Format numbers" },
1923            ],
1924            related_commands: vec!["echo", "awk"],
1925        });
1926
1927        self.register(CommandInfo {
1928            name: "basename".to_string(),
1929            category: CommandCategory::TextProcessing,
1930            danger_level: DangerLevel::Safe,
1931            summary: "Strip directory from filename",
1932            description: "Strips the directory path from a full file path, leaving just the filename. For example, 'basename /home/user/documents/file.txt' returns just 'file.txt'. You can also remove file extensions: 'basename /path/to/file.txt .txt' gives you just 'file'. Super useful in shell scripts when you need to work with filenames but have full paths - extract the name, process it, then reconstruct the path. Pairs perfectly with dirname which does the opposite (keeps the directory, removes the filename). Simple but essential for path manipulation in scripts.",
1933            common_flags: vec![],
1934            examples: vec![
1935                Example { command: "basename /path/to/file.txt", description: "Get filename", use_case: "Extract filename from path" },
1936                Example { command: "basename /path/to/file.txt .txt", description: "Remove extension too", use_case: "Get name without extension" },
1937            ],
1938            related_commands: vec!["dirname", "realpath"],
1939        });
1940
1941        self.register(CommandInfo {
1942            name: "dirname".to_string(),
1943            category: CommandCategory::TextProcessing,
1944            danger_level: DangerLevel::Safe,
1945            summary: "Strip filename from path",
1946            description: "Does the opposite of basename - removes the filename and keeps the directory path. For example, 'dirname /home/user/documents/file.txt' returns '/home/user/documents'. Essential in scripts when you need to know what directory a file is in, or to build new paths relative to a file's location. For instance, if a script needs to find config files in the same directory it's running from, dirname helps extract that path. Together with basename, you can completely decompose and rebuild file paths programmatically.",
1947            common_flags: vec![],
1948            examples: vec![
1949                Example { command: "dirname /path/to/file.txt", description: "Get directory path", use_case: "Extract directory from path" },
1950            ],
1951            related_commands: vec!["basename", "realpath"],
1952        });
1953
1954        self.register(CommandInfo {
1955            name: "readlink".to_string(),
1956            category: CommandCategory::FileManagement,
1957            danger_level: DangerLevel::Safe,
1958            summary: "Print resolved symbolic links",
1959            description: "Follows a symbolic link (shortcut) and shows you where it actually points to. Symbolic links can be confusing - they look like files but are really just pointers. Use 'readlink link-name' to see the target, or better yet, 'readlink -f link-name' to get the absolute canonical path, resolving all intermediate links and relative paths. For example, '/usr/bin/python' might be a link to 'python3', which itself links to 'python3.9' - readlink -f shows you the final destination. Essential for understanding system configurations and tracking down the real location of commands.",
1960            common_flags: vec![
1961                FlagInfo { flag: "-f", description: "Canonicalize: resolve all symlinks to absolute path", example: Some("readlink -f link") },
1962            ],
1963            examples: vec![
1964                Example { command: "readlink /usr/bin/python", description: "See where link points", use_case: "Follow symbolic link" },
1965                Example { command: "readlink -f link", description: "Get absolute target path", use_case: "Resolve all symlinks" },
1966            ],
1967            related_commands: vec!["ln", "realpath"],
1968        });
1969
1970        // File search utilities
1971        self.register(CommandInfo {
1972            name: "locate".to_string(),
1973            category: CommandCategory::Search,
1974            danger_level: DangerLevel::Safe,
1975            summary: "Find files by name (fast)",
1976            description: "Blazingly fast file search that uses a pre-built database of all files on your system, making it much quicker than 'find' which searches the filesystem in real-time. Just type 'locate filename' and instantly get all matching files. The catch: the database is typically updated only once a day, so very recent files won't appear until you run 'sudo updatedb' manually. Great for finding config files, programs, or documents when you know the name but not the location. Use -i for case-insensitive search. The speed difference is dramatic on large filesystems!",
1977            common_flags: vec![
1978                FlagInfo { flag: "-i", description: "Ignore case: case-insensitive search", example: Some("locate -i filename") },
1979            ],
1980            examples: vec![
1981                Example { command: "locate filename", description: "Find file quickly", use_case: "Fast file search" },
1982                Example { command: "sudo updatedb && locate file", description: "Update DB and search", use_case: "Search with fresh index" },
1983            ],
1984            related_commands: vec!["find", "which", "updatedb"],
1985        });
1986
1987        self.register(CommandInfo {
1988            name: "whereis".to_string(),
1989            category: CommandCategory::Search,
1990            danger_level: DangerLevel::Safe,
1991            summary: "Locate binary, source, and manual pages",
1992            description: "Locates not just where a command is (like 'which'), but also its source code and documentation if available. For example, 'whereis ls' might show you the binary at /bin/ls, the source at /usr/src/coreutils/ls.c, and the man page at /usr/share/man/man1/ls.1.gz. More comprehensive than 'which' for understanding where all the pieces of a program live on your system. Useful for developers who need to find source code or when you want to see where documentation is stored. Searches standard system directories quickly.",
1993            common_flags: vec![],
1994            examples: vec![
1995                Example { command: "whereis ls", description: "Find ls locations", use_case: "Locate command and docs" },
1996            ],
1997            related_commands: vec!["which", "locate", "find"],
1998        });
1999
2000        // More utilities
2001        self.register(CommandInfo {
2002            name: "exit".to_string(),
2003            category: CommandCategory::SystemInfo,
2004            danger_level: DangerLevel::Safe,
2005            summary: "Exit the shell",
2006            description: "Closes your current terminal session or shell. Just type 'exit' and press Enter to quit. In scripts, you can specify an exit code like 'exit 0' (success) or 'exit 1' (error) to indicate how the script finished - other programs can check this code. If you're in an SSH session, exit logs you out and closes the connection. If it's your last terminal window, the window closes. You can also usually use Ctrl+D as a keyboard shortcut for exit. Simple but essential for cleanly closing shells and scripts.",
2007            common_flags: vec![],
2008            examples: vec![
2009                Example { command: "exit", description: "Close shell", use_case: "End terminal session" },
2010                Example { command: "exit 1", description: "Exit with error code", use_case: "Signal script failure" },
2011            ],
2012            related_commands: vec!["logout", "Ctrl+D"],
2013        });
2014
2015        self.register(CommandInfo {
2016            name: "source".to_string(),
2017            category: CommandCategory::SystemInfo,
2018            danger_level: DangerLevel::Caution,
2019            summary: "Execute commands from file in current shell",
2020            description: "Executes a script file in your CURRENT shell session, unlike running it normally which creates a new shell. This is crucial - any variables, functions, or environment changes the script makes will persist in your current session. Most commonly used with 'source ~/.bashrc' to reload your bash configuration after editing it, making changes take effect without logging out. The dot command '.' is a shorthand for source. Essential for applying configuration changes, loading environment variables, or running setup scripts that need to modify your current shell environment.",
2021            common_flags: vec![],
2022            examples: vec![
2023                Example { command: "source ~/.bashrc", description: "Reload bash config", use_case: "Apply config changes" },
2024                Example { command: ". ./script.sh", description: "Same as source (dot command)", use_case: "Run in current shell" },
2025            ],
2026            related_commands: vec![".", "bash"],
2027        });
2028
2029        self.register(CommandInfo {
2030            name: "id".to_string(),
2031            category: CommandCategory::SystemInfo,
2032            danger_level: DangerLevel::Safe,
2033            summary: "Print user and group IDs",
2034            description: "Displays detailed identity information including your user ID (UID), primary group ID (GID), and all groups you belong to with their numeric IDs. More comprehensive than 'whoami' or 'groups' alone. The UID and GID numbers are what Linux actually uses internally for permissions - usernames are just friendly labels. Use 'id -u' to get just your UID (useful in scripts), or 'id username' to check another user's info. Essential for understanding permissions, troubleshooting access issues, or verifying what account a process will run as.",
2035            common_flags: vec![
2036                FlagInfo { flag: "-u", description: "User ID: print only UID", example: Some("id -u") },
2037                FlagInfo { flag: "-g", description: "Group ID: print only primary GID", example: Some("id -g") },
2038            ],
2039            examples: vec![
2040                Example { command: "id", description: "Show user/group info", use_case: "Check user identity" },
2041                Example { command: "id username", description: "Show info for user", use_case: "Check another user's IDs" },
2042            ],
2043            related_commands: vec!["whoami", "groups"],
2044        });
2045
2046        self.register(CommandInfo {
2047            name: "who".to_string(),
2048            category: CommandCategory::SystemInfo,
2049            danger_level: DangerLevel::Safe,
2050            summary: "Show who is logged in",
2051            description: "Lists all users currently logged into the system, showing their username, terminal, login time, and where they logged in from (if remote). Useful on multi-user systems or servers to see who else is online. For example, you might see other administrators connected via SSH. Simple but informative - just type 'who' with no arguments. On a single-user desktop you'll usually only see yourself, but on servers it's important for coordination and security auditing. The 'w' command shows similar info plus what each user is doing.",
2052            common_flags: vec![],
2053            examples: vec![
2054                Example { command: "who", description: "List logged in users", use_case: "See active users" },
2055            ],
2056            related_commands: vec!["w", "whoami", "users"],
2057        });
2058
2059        self.register(CommandInfo {
2060            name: "w".to_string(),
2061            category: CommandCategory::SystemInfo,
2062            danger_level: DangerLevel::Safe,
2063            summary: "Show who is logged in and what they're doing",
2064            description: "An enhanced version of 'who' that shows not just who's logged in, but also what command they're currently running, how long they've been idle, and system load averages. Like looking over everyone's shoulder to see what they're doing. The first line shows uptime and load, then each user gets a line showing their login time, idle time, CPU usage, and current command. Perfect for system administrators monitoring server activity or seeing if that colleague is actually working or just has a terminal window open. More informative than 'who', less detailed than 'top'.",
2065            common_flags: vec![],
2066            examples: vec![
2067                Example { command: "w", description: "Show users and activity", use_case: "Monitor user activity" },
2068            ],
2069            related_commands: vec!["who", "uptime", "top"],
2070        });
2071
2072        self.register(CommandInfo {
2073            name: "last".to_string(),
2074            category: CommandCategory::SystemInfo,
2075            danger_level: DangerLevel::Safe,
2076            summary: "Show listing of last logged in users",
2077            description: "Shows a historical log of all user logins and logouts, plus system reboots - like a visitor log for your computer. Each line shows who logged in, from where, when they logged in, when they logged out, and how long they were connected. Essential for security auditing (was my account accessed while I was away?), troubleshooting (when did the server last reboot?), or just curiosity. Use 'last -n 10' to see just the 10 most recent entries. The data comes from /var/log/wtmp, which keeps weeks or months of history depending on your system configuration.",
2078            common_flags: vec![],
2079            examples: vec![
2080                Example { command: "last", description: "Show login history", use_case: "Audit user access" },
2081                Example { command: "last -n 10", description: "Show last 10 entries", use_case: "Recent logins" },
2082            ],
2083            related_commands: vec!["who", "w", "lastlog"],
2084        });
2085
2086        self.register(CommandInfo {
2087            name: "chgrp".to_string(),
2088            category: CommandCategory::Permissions,
2089            danger_level: DangerLevel::Caution,
2090            summary: "Change group ownership",
2091            description: "Changes which group owns a file or directory, affecting which users in that group can access it based on group permissions. Every file has both a user owner AND a group owner - chgrp changes the latter. For example, 'chgrp developers project.txt' makes the 'developers' group the owner, so anyone in that group gets the group permissions (typically read access). Use -R to change group ownership recursively for entire directories. Common when setting up shared project folders where multiple team members need access. Less drastic than chown which changes the user owner too.",
2092            common_flags: vec![
2093                FlagInfo { flag: "-R", description: "Recursive: change group recursively", example: Some("chgrp -R group folder/") },
2094            ],
2095            examples: vec![
2096                Example { command: "chgrp developers file.txt", description: "Change file group", use_case: "Set group ownership" },
2097            ],
2098            related_commands: vec!["chown", "chmod", "groups"],
2099        });
2100
2101        self.register(CommandInfo {
2102            name: "umask".to_string(),
2103            category: CommandCategory::Permissions,
2104            danger_level: DangerLevel::Safe,
2105            summary: "Set default file permissions",
2106            description: "Sets the default permissions for newly created files and directories by specifying which permissions to REMOVE (it's a mask). A bit counterintuitive - umask 022 means \"remove write permission for group and others\", resulting in files created with 644 (rw-r--r--) permissions. Run 'umask' alone to see your current setting, usually 022 or 002. Use 'umask 077' for maximum privacy (only you can read your new files). The setting only lasts for your current shell session unless you add it to your .bashrc. Important for security-conscious users who want to control default file access.",
2107            common_flags: vec![],
2108            examples: vec![
2109                Example { command: "umask", description: "Show current umask", use_case: "Check permission defaults" },
2110                Example { command: "umask 022", description: "Set umask to 022", use_case: "Set file creation defaults" },
2111            ],
2112            related_commands: vec!["chmod", "mkdir", "touch"],
2113        });
2114
2115        // Hardware detection (essential for Arch installation)
2116        self.register(CommandInfo {
2117            name: "lspci".to_string(),
2118            category: CommandCategory::SystemInfo,
2119            danger_level: DangerLevel::Safe,
2120            summary: "List all PCI devices",
2121            description: "Lists all PCI devices connected to your system - graphics cards, network cards, sound cards, USB controllers, etc. Like Device Manager on Windows but for the command line. Use 'lspci -k' to also see which kernel drivers are loaded for each device - crucial when installing Arch Linux to verify hardware is detected and has the right drivers. The -v flag gives verbose details about each device. Essential for troubleshooting hardware issues, checking if your GPU is recognized, or verifying that network hardware is present before installing drivers.",
2122            common_flags: vec![
2123                FlagInfo { flag: "-v", description: "Verbose: detailed information", example: Some("lspci -v") },
2124                FlagInfo { flag: "-k", description: "Kernel: show kernel drivers", example: Some("lspci -k") },
2125            ],
2126            examples: vec![
2127                Example { command: "lspci", description: "List PCI devices", use_case: "See hardware components" },
2128                Example { command: "lspci -k", description: "Show with kernel drivers", use_case: "Check if drivers loaded" },
2129            ],
2130            related_commands: vec!["lsusb", "lshw"],
2131        });
2132
2133        self.register(CommandInfo {
2134            name: "lsusb".to_string(),
2135            category: CommandCategory::SystemInfo,
2136            danger_level: DangerLevel::Safe,
2137            summary: "List USB devices",
2138            description: "Displays all USB devices currently connected to your computer - mice, keyboards, external drives, webcams, phones, and more. Each line shows the bus number, device number, USB ID (vendor:product), and device name. Great for troubleshooting when a USB device isn't working - if it doesn't appear in lsusb, it's a hardware/connection problem. Use -v for verbose output with detailed technical specs. Simple command that answers the question \"did my computer even detect this USB thing I just plugged in?\" Essential for debugging USB issues.",
2139            common_flags: vec![
2140                FlagInfo { flag: "-v", description: "Verbose: detailed information", example: Some("lsusb -v") },
2141            ],
2142            examples: vec![
2143                Example { command: "lsusb", description: "List USB devices", use_case: "See connected USB hardware" },
2144            ],
2145            related_commands: vec!["lspci", "dmesg"],
2146        });
2147
2148        self.register(CommandInfo {
2149            name: "lshw".to_string(),
2150            category: CommandCategory::SystemInfo,
2151            danger_level: DangerLevel::Safe,
2152            summary: "List hardware configuration",
2153            description: "A comprehensive hardware information tool that shows detailed specs for ALL your system hardware - CPU, RAM, motherboard, storage, network interfaces, graphics, and more. More thorough than lspci or lsusb alone. Use 'sudo lshw -short' for a nice summary table, or just 'sudo lshw' for the full detailed tree. The output is extensive, showing capabilities, configurations, and drivers for each component. Perfect for creating a complete hardware inventory, verifying specs before buying RAM, or diagnosing hardware issues. Requires sudo for full information.",
2154            common_flags: vec![
2155                FlagInfo { flag: "-short", description: "Brief output", example: Some("lshw -short") },
2156            ],
2157            examples: vec![
2158                Example { command: "sudo lshw -short", description: "Show hardware summary", use_case: "Quick hardware overview" },
2159            ],
2160            related_commands: vec!["lspci", "lsusb", "hwinfo"],
2161        });
2162
2163        // Filesystem tools (critical for Arch installation)
2164        self.register(CommandInfo {
2165            name: "mkfs".to_string(),
2166            category: CommandCategory::SystemInfo,
2167            danger_level: DangerLevel::Critical,
2168            summary: "Build a Linux filesystem",
2169            description: "⚠️ CRITICAL: Creates a new filesystem on a partition, PERMANENTLY ERASING ALL EXISTING DATA! Like formatting a drive in Windows but from the command line. Essential during Arch Linux installation when you need to format partitions as ext4, FAT32 (for EFI), or other filesystem types. Use 'sudo mkfs.ext4 /dev/sda1' to format partition sda1 as ext4, or 'sudo mkfs.fat -F32 /dev/sda1' for FAT32. TRIPLE-CHECK the device name before running - one typo and you could erase the wrong drive! Always unmount the partition first. This is a point of no return command.",
2170            common_flags: vec![
2171                FlagInfo { flag: "-t", description: "Type: specify filesystem type", example: Some("mkfs -t ext4 /dev/sda1") },
2172            ],
2173            examples: vec![
2174                Example { command: "sudo mkfs.ext4 /dev/sda1", description: "Create ext4 filesystem", use_case: "Format partition for Arch" },
2175                Example { command: "sudo mkfs.fat -F32 /dev/sda1", description: "Create FAT32 (for EFI)", use_case: "Format EFI partition" },
2176            ],
2177            related_commands: vec!["fdisk", "parted", "fsck"],
2178        });
2179
2180        self.register(CommandInfo {
2181            name: "fsck".to_string(),
2182            category: CommandCategory::SystemInfo,
2183            danger_level: DangerLevel::Dangerous,
2184            summary: "Check and repair filesystem",
2185            description: "⚠️  File System ChecK - scans a partition for errors and attempts to repair them, like running CHKDSK on Windows. Critically important: NEVER run fsck on a mounted (in-use) filesystem - you must unmount it first or you'll cause more damage! Usually run automatically during boot if the system wasn't shut down cleanly. Manual use is for when a partition won't mount or you suspect corruption. Use 'sudo fsck /dev/sda1' to check a partition, add -y to automatically fix errors. Essential recovery tool when filesystems get corrupted, but use carefully and always on unmounted partitions.",
2186            common_flags: vec![
2187                FlagInfo { flag: "-a", description: "Automatic: automatically repair", example: Some("fsck -a /dev/sda1") },
2188            ],
2189            examples: vec![
2190                Example { command: "sudo fsck /dev/sda1", description: "Check filesystem", use_case: "Repair corrupted partition" },
2191            ],
2192            related_commands: vec!["mkfs", "e2fsck"],
2193        });
2194
2195        self.register(CommandInfo {
2196            name: "blkid".to_string(),
2197            category: CommandCategory::SystemInfo,
2198            danger_level: DangerLevel::Safe,
2199            summary: "Locate/print block device attributes",
2200            description: "Displays critical information about block devices (hard drives and partitions) including their UUIDs (unique identifiers), filesystem types, and labels. UUIDs are super important because they never change even if you reorder drives, unlike device names (/dev/sda1 might become /dev/sdb1). Essential when setting up /etc/fstab during Arch installation - you need the UUID to tell the system which partitions to mount at boot. Just run 'blkid' to see all devices, or 'blkid /dev/sda1' for a specific partition. Copy those UUIDs when configuring your system!",
2201            common_flags: vec![],
2202            examples: vec![
2203                Example { command: "blkid", description: "Show all block device UUIDs", use_case: "Get UUIDs for fstab" },
2204                Example { command: "blkid /dev/sda1", description: "Show specific partition info", use_case: "Check partition UUID" },
2205            ],
2206            related_commands: vec!["lsblk", "fdisk"],
2207        });
2208
2209        // Arch-specific tools
2210        self.register(CommandInfo {
2211            name: "yay".to_string(),
2212            category: CommandCategory::Package,
2213            danger_level: DangerLevel::Caution,
2214            summary: "AUR helper (Arch User Repository)",
2215            description: "The most popular AUR helper for Arch Linux, making it easy to install packages from both the official Arch repositories AND the AUR (Arch User Repository) - a huge collection of community-maintained packages. Use 'yay package-name' to search and install with an interactive menu, or 'yay -Syu' to update your entire system including AUR packages. It's like pacman but friendlier and with access to way more software. Essential for Arch users who want easy access to the latest software that isn't in official repos. Note: builds packages from source, so installation can take longer.",
2216            common_flags: vec![
2217                FlagInfo { flag: "-S", description: "Sync: install package", example: Some("yay -S package") },
2218                FlagInfo { flag: "-Syu", description: "System upgrade (AUR + official)", example: Some("yay -Syu") },
2219            ],
2220            examples: vec![
2221                Example { command: "yay -Syu", description: "Full system update", use_case: "Update all packages including AUR" },
2222                Example { command: "yay package", description: "Search and install from AUR", use_case: "Install AUR package" },
2223            ],
2224            related_commands: vec!["pacman", "paru"],
2225        });
2226
2227        self.register(CommandInfo {
2228            name: "paru".to_string(),
2229            category: CommandCategory::Package,
2230            danger_level: DangerLevel::Caution,
2231            summary: "AUR helper (modern alternative to yay)",
2232            description: "A modern, feature-rich AUR helper written in Rust (making it fast and reliable), positioned as the next-generation replacement for yay. Has all of yay's functionality plus additional features like better package review, bat integration for syntax highlighting, and more efficient updating. Use the same commands as yay: 'paru -Syu' for updates, 'paru package-name' to install. Many Arch users are switching from yay to paru for its speed and extra features. If you're starting fresh with Arch, paru is probably the better choice for the future.",
2233            common_flags: vec![
2234                FlagInfo { flag: "-S", description: "Sync: install package", example: Some("paru -S package") },
2235                FlagInfo { flag: "-Syu", description: "System upgrade", example: Some("paru -Syu") },
2236            ],
2237            examples: vec![
2238                Example { command: "paru -Syu", description: "Full system update", use_case: "Update Arch system" },
2239            ],
2240            related_commands: vec!["pacman", "yay"],
2241        });
2242
2243        self.register(CommandInfo {
2244            name: "mkinitcpio".to_string(),
2245            category: CommandCategory::SystemInfo,
2246            danger_level: DangerLevel::Dangerous,
2247            summary: "Create initial ramdisk (Arch)",
2248            description: "⚠️  Generates the initramfs (initial RAM filesystem) - a crucial boot component that loads necessary drivers and prepares your system before the real root filesystem mounts. On Arch Linux, you run this after kernel updates or when changing hardware drivers in /etc/mkinitcpio.conf. Use 'sudo mkinitcpio -P' to regenerate all initramfs images for all installed kernels. If you forget to run this after a kernel update, your system might not boot! The initramfs is what makes Linux boot fast by loading only essential drivers first. Critical for Arch maintenance.",
2249            common_flags: vec![
2250                FlagInfo { flag: "-P", description: "Preset: use preset from /etc/mkinitcpio.d/", example: Some("mkinitcpio -P") },
2251                FlagInfo { flag: "-p", description: "Preset: generate for specific preset", example: Some("mkinitcpio -p linux") },
2252            ],
2253            examples: vec![
2254                Example { command: "sudo mkinitcpio -P", description: "Regenerate all initramfs", use_case: "After kernel update" },
2255                Example { command: "sudo mkinitcpio -p linux", description: "Regenerate for linux kernel", use_case: "Rebuild initramfs" },
2256            ],
2257            related_commands: vec!["pacman", "grub-mkconfig"],
2258        });
2259
2260        // Boot tools
2261        self.register(CommandInfo {
2262            name: "grub-install".to_string(),
2263            category: CommandCategory::SystemInfo,
2264            danger_level: DangerLevel::Critical,
2265            summary: "Install GRUB bootloader",
2266            description: "⚠️ CRITICAL: Installs the GRUB bootloader to your disk - the program that runs when you turn on your computer and lets you choose which operating system to boot. Essential during Arch installation! For UEFI systems use 'sudo grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB'. For BIOS systems use 'sudo grub-install --target=i386-pc /dev/sda'. Get this wrong and your computer won't boot! GRUB is what shows that menu when you start your computer. After installing, run grub-mkconfig to generate the configuration.",
2267            common_flags: vec![
2268                FlagInfo { flag: "--target", description: "Target platform (x86_64-efi, i386-pc)", example: Some("grub-install --target=x86_64-efi") },
2269                FlagInfo { flag: "--efi-directory", description: "EFI directory mount point", example: Some("grub-install --efi-directory=/boot") },
2270            ],
2271            examples: vec![
2272                Example { command: "sudo grub-install --target=x86_64-efi --efi-directory=/boot", description: "Install GRUB (UEFI)", use_case: "Set up bootloader on UEFI system" },
2273            ],
2274            related_commands: vec!["grub-mkconfig", "efibootmgr"],
2275        });
2276
2277        self.register(CommandInfo {
2278            name: "grub-mkconfig".to_string(),
2279            category: CommandCategory::SystemInfo,
2280            danger_level: DangerLevel::Caution,
2281            summary: "Generate GRUB configuration",
2282            description: "Generates the GRUB configuration file that tells GRUB which operating systems and kernels are available to boot. Scans your system, finds all installed kernels and OSes, and creates the boot menu. Run 'sudo grub-mkconfig -o /boot/grub/grub.cfg' after installing a new kernel, updating GRUB, or dual-booting with Windows. On Ubuntu/Debian, you might use 'update-grub' instead which is a wrapper for this command. This is what makes new kernels appear in your boot menu. Essential after system updates that install new kernels.",
2283            common_flags: vec![
2284                FlagInfo { flag: "-o", description: "Output: specify output file", example: Some("grub-mkconfig -o /boot/grub/grub.cfg") },
2285            ],
2286            examples: vec![
2287                Example { command: "sudo grub-mkconfig -o /boot/grub/grub.cfg", description: "Regenerate GRUB config", use_case: "Update bootloader menu" },
2288            ],
2289            related_commands: vec!["grub-install", "update-grub"],
2290        });
2291
2292        // Compiler tools (for building from source)
2293        self.register(CommandInfo {
2294            name: "gcc".to_string(),
2295            category: CommandCategory::Build,
2296            danger_level: DangerLevel::Safe,
2297            summary: "GNU C Compiler",
2298            description: "The GNU C Compiler - the standard compiler for C programming on Linux and a cornerstone of open-source development. Turns your C source code into executable programs. Use 'gcc program.c -o program' to compile program.c into an executable called 'program'. Essential for building software from source - many programs you download come as C code that needs compiling. The -O2 flag enables optimization for faster code, -Wall shows all warnings (highly recommended!). If you're learning C or building Linux from source, you'll use gcc constantly. It's been around since 1987 and powers much of the software world.",
2299            common_flags: vec![
2300                FlagInfo { flag: "-o", description: "Output: specify output filename", example: Some("gcc program.c -o program") },
2301                FlagInfo { flag: "-O2", description: "Optimize: optimization level 2", example: Some("gcc -O2 program.c") },
2302            ],
2303            examples: vec![
2304                Example { command: "gcc program.c -o program", description: "Compile C program", use_case: "Build from source" },
2305                Example { command: "gcc -Wall -O2 program.c", description: "Compile with warnings and optimization", use_case: "Production build" },
2306            ],
2307            related_commands: vec!["g++", "clang", "make"],
2308        });
2309
2310        self.register(CommandInfo {
2311            name: "g++".to_string(),
2312            category: CommandCategory::Build,
2313            danger_level: DangerLevel::Safe,
2314            summary: "GNU C++ Compiler",
2315            description: "The GNU C++ Compiler - gcc's counterpart for C++ programming. Compiles C++ code which includes object-oriented features, templates, and the STL that C doesn't have. Use 'g++ program.cpp -o program' to compile. The -std flag lets you choose the C++ standard version (c++11, c++17, c++20, c++23) - newer standards have more features. Essential for building C++ software, game engines, performance-critical applications, and much of the modern software stack. Like gcc but for when you need classes, templates, and modern C++ features.",
2316            common_flags: vec![
2317                FlagInfo { flag: "-std", description: "Standard: C++ standard (c++11, c++17, c++20)", example: Some("g++ -std=c++17 program.cpp") },
2318            ],
2319            examples: vec![
2320                Example { command: "g++ program.cpp -o program", description: "Compile C++ program", use_case: "Build C++ code" },
2321            ],
2322            related_commands: vec!["gcc", "clang++"],
2323        });
2324
2325        // Debugging and analysis tools
2326        self.register(CommandInfo {
2327            name: "strace".to_string(),
2328            category: CommandCategory::SystemInfo,
2329            danger_level: DangerLevel::Safe,
2330            summary: "Trace system calls and signals",
2331            description: "A powerful debugging tool that shows every system call (request to the kernel) a program makes - file opens, network connections, memory allocations, everything. Like x-ray vision for programs. Use 'strace command' to see what a program is doing under the hood, or 'strace -p PID' to attach to a running process. Essential for debugging when a program mysteriously fails - you can see exactly where it's trying to open files, what permissions it needs, or why it's hanging. The output is verbose but incredibly informative. Every systems programmer's secret weapon.",
2332            common_flags: vec![
2333                FlagInfo { flag: "-f", description: "Follow: trace child processes", example: Some("strace -f command") },
2334            ],
2335            examples: vec![
2336                Example { command: "strace ls", description: "Trace ls command", use_case: "See what a program does" },
2337                Example { command: "strace -p 1234", description: "Attach to running process", use_case: "Debug running program" },
2338            ],
2339            related_commands: vec!["ltrace", "gdb"],
2340        });
2341
2342        self.register(CommandInfo {
2343            name: "lsof".to_string(),
2344            category: CommandCategory::SystemInfo,
2345            danger_level: DangerLevel::Safe,
2346            summary: "List open files",
2347            description: "Lists all open files and which processes have them open - remember, in Linux \"everything is a file\" including network connections and devices! Super useful for answering questions like \"which process is using port 80?\" ('lsof -i :80'), \"why can't I unmount this drive?\" ('lsof /mnt'), or \"what files is this process accessing?\" The name means \"list open files\". Essential for troubleshooting locked files, finding processes listening on ports, or investigating what a suspicious process is accessing. One of the most versatile debugging tools in Linux.",
2348            common_flags: vec![
2349                FlagInfo { flag: "-i", description: "Internet: show network connections", example: Some("lsof -i :80") },
2350            ],
2351            examples: vec![
2352                Example { command: "lsof /var/log/syslog", description: "Who's using this file", use_case: "Find process accessing file" },
2353                Example { command: "lsof -i :80", description: "What's using port 80", use_case: "Find process on port" },
2354            ],
2355            related_commands: vec!["netstat", "ps", "fuser"],
2356        });
2357
2358        self.register(CommandInfo {
2359            name: "gdb".to_string(),
2360            category: CommandCategory::Build,
2361            danger_level: DangerLevel::Safe,
2362            summary: "GNU Debugger",
2363            description: "The GNU Debugger - an incredibly powerful interactive debugger for C/C++ programs that lets you step through code line-by-line, set breakpoints, examine variables, and figure out exactly where bugs are. Load a program with 'gdb ./program', set breakpoints with 'break main', run with 'run', and step through with 'step' or 'next'. You can examine memory, modify variables mid-execution, and get stack traces when crashes occur. Learning curve is steep but it's the gold standard for debugging compiled code. Every serious C/C++ developer needs to know gdb basics.",
2364            common_flags: vec![],
2365            examples: vec![
2366                Example { command: "gdb program", description: "Debug program", use_case: "Interactive debugging" },
2367                Example { command: "gdb -p 1234", description: "Attach to process", use_case: "Debug running program" },
2368            ],
2369            related_commands: vec!["lldb", "strace"],
2370        });
2371
2372        // Advanced networking
2373        self.register(CommandInfo {
2374            name: "ss".to_string(),
2375            category: CommandCategory::Networking,
2376            danger_level: DangerLevel::Safe,
2377            summary: "Socket statistics (modern netstat)",
2378            description: "The modern, faster replacement for the classic 'netstat' command, showing socket statistics and network connections. Use 'ss -tuln' to see all TCP/UDP listening ports (what services are waiting for connections), or 'ss -tulnp' to also show which process is listening. Much faster than netstat, especially on busy servers with thousands of connections. Essential for network troubleshooting - check what ports are open, see active connections, diagnose why something can't bind to a port. If you're learning network commands, learn 'ss' instead of the aging 'netstat'.",
2379            common_flags: vec![
2380                FlagInfo { flag: "-tuln", description: "TCP/UDP listening with numbers", example: Some("ss -tuln") },
2381                FlagInfo { flag: "-p", description: "Processes: show process using socket", example: Some("ss -tulnp") },
2382            ],
2383            examples: vec![
2384                Example { command: "ss -tuln", description: "Show listening ports", use_case: "Check open ports" },
2385                Example { command: "ss -tulnp", description: "Show with processes", use_case: "See what's listening" },
2386            ],
2387            related_commands: vec!["netstat", "lsof"],
2388        });
2389
2390        self.register(CommandInfo {
2391            name: "iptables".to_string(),
2392            category: CommandCategory::Networking,
2393            danger_level: DangerLevel::Critical,
2394            summary: "IPv4 packet filtering and NAT",
2395            description: "⚠️ CRITICAL: The low-level Linux firewall configuration tool - extremely powerful but complex and dangerous if used incorrectly. Controls which network packets are allowed in or out of your system. One wrong command can lock you out of a remote server permanently! Use 'iptables -L' to list current rules safely. Most users should use friendlier front-ends like 'ufw' (Ubuntu) or 'firewalld' (RedHat) instead of raw iptables. Only use this directly if you know what you're doing or are following exact instructions. Being replaced by 'nftables' on modern systems but still widely used.",
2396            common_flags: vec![
2397                FlagInfo { flag: "-L", description: "List: show all rules", example: Some("iptables -L") },
2398                FlagInfo { flag: "-A", description: "Append: add new rule", example: Some("iptables -A INPUT -p tcp --dport 22 -j ACCEPT") },
2399            ],
2400            examples: vec![
2401                Example { command: "sudo iptables -L", description: "List firewall rules", use_case: "See current firewall config" },
2402            ],
2403            related_commands: vec!["ufw", "firewalld", "nftables"],
2404        });
2405
2406        // Text editors we might have missed
2407        self.register(CommandInfo {
2408            name: "emacs".to_string(),
2409            category: CommandCategory::TextProcessing,
2410            danger_level: DangerLevel::Safe,
2411            summary: "Extensible text editor",
2412            description: "A legendary, incredibly powerful and extensible text editor that's also a complete computing environment - some people run email, calendars, git, terminals, and more all within Emacs! Famously rivals Vim in the \"editor wars\". Unlike modal editors, you can start typing immediately, but it uses extensive keyboard shortcuts (Ctrl+X Ctrl+S to save, Ctrl+X Ctrl+C to quit). Infinitely customizable with Emacs Lisp. The learning curve is steep and it's large/slow compared to Vim, but devotees swear by its power and consistency. More than an editor - it's a way of life for some developers!",
2413            common_flags: vec![],
2414            examples: vec![
2415                Example { command: "emacs file.txt", description: "Edit file", use_case: "Advanced text editing" },
2416            ],
2417            related_commands: vec!["vim", "nano"],
2418        });
2419
2420        // System information we might have missed
2421        self.register(CommandInfo {
2422            name: "dmidecode".to_string(),
2423            category: CommandCategory::SystemInfo,
2424            danger_level: DangerLevel::Safe,
2425            summary: "DMI table decoder (hardware info)",
2426            description: "Reads your system's DMI (Desktop Management Interface) tables from BIOS/UEFI to show detailed hardware information - motherboard model, RAM specs, CPU details, serial numbers, and more. Like reading the hardware database that your BIOS maintains. Use 'sudo dmidecode -t memory' to see RAM details (type, speed, slots), or 'sudo dmidecode -t system' for motherboard info. Great for finding out exact hardware specs without opening the case, verifying compatible RAM before upgrading, or getting serial numbers for warranty claims. Requires sudo to access the DMI tables.",
2427            common_flags: vec![
2428                FlagInfo { flag: "-t", description: "Type: show specific type", example: Some("dmidecode -t memory") },
2429            ],
2430            examples: vec![
2431                Example { command: "sudo dmidecode -t system", description: "Show system information", use_case: "Get hardware details" },
2432                Example { command: "sudo dmidecode -t memory", description: "Show RAM information", use_case: "Check memory specs" },
2433            ],
2434            related_commands: vec!["lshw", "hwinfo"],
2435        });
2436
2437        self.register(CommandInfo {
2438            name: "arch-chroot".to_string(),
2439            category: CommandCategory::SystemInfo,
2440            danger_level: DangerLevel::Dangerous,
2441            summary: "Enhanced chroot for Arch installation",
2442            description: "⚠️  An enhanced version of the 'chroot' command specifically designed for Arch Linux installation. Changes your root directory to a mounted Arch installation, automatically mounting necessary filesystems (/proc, /sys, /dev) so you can configure the new system before booting into it. During Arch installation, after running pacstrap, you use 'arch-chroot /mnt' to enter your new Arch system and configure the bootloader, set timezone, create users, etc. It's like stepping into your new OS before it's actually installed. Essential Arch installation tool - makes configuration much easier than manual chroot.",
2443            common_flags: vec![],
2444            examples: vec![
2445                Example { command: "arch-chroot /mnt", description: "Chroot into new system", use_case: "Configure Arch installation" },
2446            ],
2447            related_commands: vec!["chroot", "pacstrap"],
2448        });
2449
2450        self.register(CommandInfo {
2451            name: "pacstrap".to_string(),
2452            category: CommandCategory::Package,
2453            danger_level: DangerLevel::Caution,
2454            summary: "Install packages to new root (Arch install)",
2455            description: "Installs packages into a new Arch Linux system during installation - the command that actually puts Arch on your drive! Use it like 'pacstrap /mnt base linux linux-firmware' to install the base system, kernel, and firmware to your mounted partition. This is the first major step after partitioning and formatting during Arch installation. You specify which packages to include in your base install - minimal Arch just needs 'base', but you typically also want the kernel ('linux'), firmware, and maybe a text editor. Essential Arch installation tool that bootstraps your new system.",
2456            common_flags: vec![],
2457            examples: vec![
2458                Example { command: "pacstrap /mnt base linux linux-firmware", description: "Install base system", use_case: "Bootstrap Arch installation" },
2459            ],
2460            related_commands: vec!["arch-chroot", "pacman"],
2461        });
2462
2463        self.register(CommandInfo {
2464            name: "genfstab".to_string(),
2465            category: CommandCategory::SystemInfo,
2466            danger_level: DangerLevel::Caution,
2467            summary: "Generate /etc/fstab file",
2468            description: "Automatically generates the /etc/fstab file by detecting all currently mounted filesystems and their mount points. The fstab file tells Linux which partitions to mount at boot and where. During Arch installation, after mounting your partitions, run 'genfstab -U /mnt >> /mnt/etc/fstab' to create the fstab using UUIDs (recommended over device names). This saves you from manually writing fstab entries which is error-prone. Always verify the generated file before rebooting - a broken fstab can prevent your system from booting! Essential Arch installation step.",
2469            common_flags: vec![
2470                FlagInfo { flag: "-U", description: "UUIDs: use UUIDs instead of device names", example: Some("genfstab -U /mnt") },
2471            ],
2472            examples: vec![
2473                Example { command: "genfstab -U /mnt >> /mnt/etc/fstab", description: "Generate fstab with UUIDs", use_case: "Set up Arch filesystem table" },
2474            ],
2475            related_commands: vec!["blkid", "mount"],
2476        });
2477    }
2478
2479    fn register(&mut self, info: CommandInfo) {
2480        self.commands.insert(info.name.clone(), info);
2481    }
2482}
2483
2484impl Default for CommandAnalyzer {
2485    fn default() -> Self {
2486        Self::new()
2487    }
2488}
2489
2490/// Calculate Levenshtein distance for typo detection
2491fn levenshtein_distance(s1: &str, s2: &str) -> usize {
2492    let len1 = s1.len();
2493    let len2 = s2.len();
2494    let mut matrix = vec![vec![0; len2 + 1]; len1 + 1];
2495
2496    for i in 0..=len1 {
2497        matrix[i][0] = i;
2498    }
2499    for j in 0..=len2 {
2500        matrix[0][j] = j;
2501    }
2502
2503    for (i, c1) in s1.chars().enumerate() {
2504        for (j, c2) in s2.chars().enumerate() {
2505            let cost = if c1 == c2 { 0 } else { 1 };
2506            matrix[i + 1][j + 1] = (matrix[i][j + 1] + 1)
2507                .min(matrix[i + 1][j] + 1)
2508                .min(matrix[i][j] + cost);
2509        }
2510    }
2511
2512    matrix[len1][len2]
2513}
2514
2515#[cfg(test)]
2516mod tests {
2517    use super::*;
2518
2519    #[test]
2520    fn test_parse_simple_command() {
2521        let analyzer = CommandAnalyzer::new();
2522        let cmd = analyzer.parse("ls").unwrap();
2523        assert_eq!(cmd.program, "ls");
2524        assert_eq!(cmd.args.len(), 0);
2525    }
2526
2527    #[test]
2528    fn test_parse_command_with_flags() {
2529        let analyzer = CommandAnalyzer::new();
2530        let cmd = analyzer.parse("ls -lah /tmp").unwrap();
2531        assert_eq!(cmd.program, "ls");
2532        assert_eq!(cmd.flags.len(), 3);
2533    }
2534
2535    #[test]
2536    fn test_levenshtein_distance() {
2537        assert_eq!(levenshtein_distance("cat", "cat"), 0);
2538        assert_eq!(levenshtein_distance("cat", "bat"), 1);
2539        assert_eq!(levenshtein_distance("cat", "car"), 1);
2540    }
2541}