learn_bash_from_session_data 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1593 @@
1
+ """
2
+ Comprehensive Bash Command Knowledge Base
3
+
4
+ This module provides a structured database of bash commands, operators, and concepts
5
+ for educational purposes. All content is curated for learning bash from real usage patterns.
6
+ """
7
+
8
+ from typing import Dict, Set, List, Any
9
+
10
+ # Command categories with their associated utilities
11
+ CATEGORY_MAPPINGS: Dict[str, Set[str]] = {
12
+ "File System": {
13
+ "ls", "cd", "pwd", "mkdir", "rmdir", "rm", "cp", "mv", "touch",
14
+ "cat", "less", "more", "head", "tail", "file", "stat", "ln",
15
+ "readlink", "realpath", "basename", "dirname", "tree", "du", "df",
16
+ "mount", "umount", "fdisk", "mkfs", "fsck", "lsblk", "blkid",
17
+ "find", "locate", "updatedb", "which", "whereis", "type",
18
+ },
19
+ "Text Processing": {
20
+ "grep", "egrep", "fgrep", "sed", "awk", "gawk", "cut", "paste",
21
+ "sort", "uniq", "wc", "tr", "tee", "xargs", "split", "csplit",
22
+ "join", "comm", "diff", "patch", "cmp", "od", "hexdump", "xxd",
23
+ "strings", "expand", "unexpand", "fold", "fmt", "pr", "nl",
24
+ "column", "rev", "shuf", "head", "tail", "tac",
25
+ },
26
+ "Git": {
27
+ "git", "gh", "hub", "tig", "gitk", "git-lfs",
28
+ },
29
+ "Package Management": {
30
+ "apt", "apt-get", "apt-cache", "dpkg", "snap", "flatpak",
31
+ "yum", "dnf", "rpm", "zypper", "pacman", "yay", "paru",
32
+ "brew", "port", "pkg", "apk",
33
+ "npm", "npx", "yarn", "pnpm", "bun",
34
+ "pip", "pip3", "pipx", "conda", "poetry", "uv",
35
+ "cargo", "rustup", "gem", "bundle", "composer", "go",
36
+ "nuget", "dotnet", "mvn", "gradle",
37
+ },
38
+ "Process & System": {
39
+ "ps", "top", "htop", "btop", "atop", "kill", "killall", "pkill",
40
+ "pgrep", "nice", "renice", "nohup", "bg", "fg", "jobs", "disown",
41
+ "screen", "tmux", "byobu", "systemctl", "service", "journalctl",
42
+ "dmesg", "uptime", "free", "vmstat", "iostat", "mpstat", "sar",
43
+ "lsof", "fuser", "strace", "ltrace", "perf", "time", "timeout",
44
+ "watch", "wait", "sleep", "cron", "crontab", "at", "batch",
45
+ "shutdown", "reboot", "halt", "poweroff", "init", "runlevel",
46
+ "uname", "hostname", "hostnamectl", "timedatectl", "localectl",
47
+ },
48
+ "Networking": {
49
+ "curl", "wget", "httpie", "http", "ssh", "scp", "sftp", "rsync",
50
+ "ftp", "tftp", "nc", "netcat", "ncat", "socat", "telnet",
51
+ "ping", "traceroute", "tracepath", "mtr", "dig", "nslookup", "host",
52
+ "ip", "ifconfig", "route", "netstat", "ss", "arp", "arping",
53
+ "iptables", "nft", "ufw", "firewall-cmd", "tcpdump", "wireshark",
54
+ "nmap", "masscan", "nikto", "whois", "openssl", "certbot",
55
+ },
56
+ "Permissions": {
57
+ "chmod", "chown", "chgrp", "umask", "getfacl", "setfacl",
58
+ "sudo", "su", "doas", "chroot", "newgrp", "id", "whoami",
59
+ "groups", "users", "who", "w", "last", "lastlog", "finger",
60
+ "useradd", "userdel", "usermod", "groupadd", "groupdel", "groupmod",
61
+ "passwd", "chpasswd", "pwck", "grpck", "vipw", "vigr",
62
+ },
63
+ "Compression": {
64
+ "tar", "gzip", "gunzip", "bzip2", "bunzip2", "xz", "unxz",
65
+ "zip", "unzip", "7z", "7za", "rar", "unrar", "zstd",
66
+ "compress", "uncompress", "lz4", "lzop", "zcat", "bzcat", "xzcat",
67
+ },
68
+ "Search & Navigation": {
69
+ "find", "locate", "mlocate", "plocate", "updatedb", "which",
70
+ "whereis", "type", "command", "hash", "apropos", "whatis", "man",
71
+ "info", "help", "ag", "rg", "ripgrep", "ack", "fzf", "fd",
72
+ "tree", "exa", "lsd", "broot", "ranger", "mc", "nnn", "lf",
73
+ },
74
+ "Development": {
75
+ "make", "cmake", "ninja", "meson", "autoconf", "automake",
76
+ "gcc", "g++", "clang", "clang++", "cc", "ld", "as", "ar",
77
+ "python", "python3", "python2", "node", "deno", "bun",
78
+ "ruby", "perl", "php", "java", "javac", "kotlin", "scala",
79
+ "go", "rust", "rustc", "cargo", "swift", "swiftc",
80
+ "gdb", "lldb", "valgrind", "objdump", "nm", "readelf", "ldd",
81
+ "docker", "docker-compose", "podman", "kubectl", "helm", "minikube",
82
+ "vagrant", "terraform", "ansible", "puppet", "chef",
83
+ "code", "vim", "nvim", "nano", "emacs", "ed", "ex", "vi",
84
+ "jq", "yq", "xmllint", "xsltproc", "jsonnet",
85
+ },
86
+ "Shell Builtins": {
87
+ "echo", "printf", "read", "source", ".", "exec", "eval", "set",
88
+ "unset", "export", "declare", "local", "readonly", "typeset",
89
+ "alias", "unalias", "builtin", "command", "enable", "hash",
90
+ "cd", "pwd", "pushd", "popd", "dirs", "shopt", "bind",
91
+ "history", "fc", "true", "false", "test", "[", "[[", "exit",
92
+ "return", "break", "continue", "shift", "getopts", "trap",
93
+ "ulimit", "times", "let", ":", "compgen", "complete", "compopt",
94
+ },
95
+ }
96
+
97
+ # Build reverse mapping: command -> category
98
+ COMMAND_TO_CATEGORY: Dict[str, str] = {}
99
+ for category, commands in CATEGORY_MAPPINGS.items():
100
+ for cmd in commands:
101
+ COMMAND_TO_CATEGORY[cmd] = category
102
+
103
+ # Operators and special constructs that increase complexity
104
+ PIPE_OPERATORS = {"|", "|&"}
105
+ REDIRECT_OPERATORS = {">", ">>", "<", "<<", "<<<", "2>", "2>>", "&>", "&>>", "2>&1", ">&2"}
106
+ COMPOUND_OPERATORS = {"&&", "||", ";"}
107
+ SUBSHELL_MARKERS = {"$(", "`", "(", ")"}
108
+ PROCESS_SUBSTITUTION = {"<(", ">("}
109
+
110
+ # Command patterns that indicate higher complexity
111
+ LOOP_KEYWORDS = {"for", "while", "until", "do", "done"}
112
+ CONDITIONAL_KEYWORDS = {"if", "then", "else", "elif", "fi", "case", "esac"}
113
+ FUNCTION_KEYWORDS = {"function", "()"}
114
+
115
+ # Common flag patterns by complexity contribution
116
+ SIMPLE_FLAGS = {"-h", "--help", "-v", "--version", "-q", "--quiet"}
117
+ MODERATE_FLAGS = {"-r", "-R", "--recursive", "-f", "--force", "-a", "--all"}
118
+ COMPLEX_FLAGS = {"-e", "--regex", "-P", "--perl-regexp", "-E", "--extended-regexp"}
119
+
120
+ # Categories ordered by typical learning progression
121
+ LEARNING_ORDER: List[str] = [
122
+ "Shell Builtins",
123
+ "File System",
124
+ "Search & Navigation",
125
+ "Text Processing",
126
+ "Permissions",
127
+ "Compression",
128
+ "Process & System",
129
+ "Git",
130
+ "Package Management",
131
+ "Development",
132
+ "Networking",
133
+ ]
134
+
135
+ def get_category(command: str) -> str:
136
+ """Get the category for a given base command."""
137
+ return COMMAND_TO_CATEGORY.get(command, "Unknown")
138
+
139
+ def get_all_categories() -> List[str]:
140
+ """Get all category names in learning order."""
141
+ return LEARNING_ORDER.copy()
142
+
143
+ def get_commands_in_category(category: str) -> Set[str]:
144
+ """Get all commands in a specific category."""
145
+ return CATEGORY_MAPPINGS.get(category, set()).copy()
146
+
147
+
148
+ # =============================================================================
149
+ # COMPREHENSIVE COMMAND DATABASE
150
+ # =============================================================================
151
+
152
+ COMMAND_DB: Dict[str, Dict[str, Any]] = {
153
+ "ls": {
154
+ "description": "List directory contents with various formatting and filtering options",
155
+ "man_url": "https://man7.org/linux/man-pages/man1/ls.1.html",
156
+ "flags": {
157
+ "-l": "Long format with permissions, owner, size, and modification time",
158
+ "-a": "Show all files including hidden (dotfiles)",
159
+ "-A": "Show almost all (exclude . and ..)",
160
+ "-h": "Human-readable sizes (1K, 234M, 2G)",
161
+ "-R": "Recursive listing of subdirectories",
162
+ "-t": "Sort by modification time, newest first",
163
+ "-r": "Reverse sort order",
164
+ "-S": "Sort by file size, largest first",
165
+ "-1": "One file per line",
166
+ "-d": "List directories themselves, not their contents",
167
+ },
168
+ "common_patterns": ["ls -la", "ls -lah", "ls -lt", "ls *.txt", "ls -d */"],
169
+ },
170
+ "cd": {
171
+ "description": "Change the current working directory",
172
+ "man_url": "https://man7.org/linux/man-pages/man1/cd.1p.html",
173
+ "flags": {
174
+ "-": "Change to previous directory ($OLDPWD)",
175
+ "-P": "Use physical directory structure (resolve symlinks)",
176
+ "-L": "Use logical directory structure (follow symlinks, default)",
177
+ },
178
+ "common_patterns": ["cd ~", "cd ..", "cd -", "cd /path/to/dir"],
179
+ },
180
+ "pwd": {
181
+ "description": "Print the current working directory path",
182
+ "man_url": "https://man7.org/linux/man-pages/man1/pwd.1.html",
183
+ "flags": {
184
+ "-L": "Print logical path (with symlinks)",
185
+ "-P": "Print physical path (resolved symlinks)",
186
+ },
187
+ "common_patterns": ["pwd", "echo $(pwd)"],
188
+ },
189
+ "find": {
190
+ "description": "Search for files in directory hierarchy with powerful filtering",
191
+ "man_url": "https://man7.org/linux/man-pages/man1/find.1.html",
192
+ "flags": {
193
+ "-name": "Match filename pattern (case-sensitive)",
194
+ "-iname": "Match filename pattern (case-insensitive)",
195
+ "-type": "File type: f=file, d=directory, l=symlink",
196
+ "-size": "File size (+10M = larger than 10MB)",
197
+ "-mtime": "Modified time in days (-1 = last 24h)",
198
+ "-exec": "Execute command on each match",
199
+ "-delete": "Delete matching files",
200
+ "-maxdepth": "Maximum directory depth to search",
201
+ "-empty": "Match empty files or directories",
202
+ "-print0": "Print with null delimiter (for xargs -0)",
203
+ },
204
+ "common_patterns": [
205
+ "find . -name '*.py'",
206
+ "find . -type f -name '*.log' -delete",
207
+ "find . -mtime -1",
208
+ "find . -size +100M",
209
+ "find . -name '*.txt' -exec grep -l 'pattern' {} \\;",
210
+ ],
211
+ },
212
+ "tree": {
213
+ "description": "Display directory structure as a tree",
214
+ "man_url": "https://linux.die.net/man/1/tree",
215
+ "flags": {
216
+ "-L": "Limit depth of directory tree",
217
+ "-a": "Show all files including hidden",
218
+ "-d": "List directories only",
219
+ "-h": "Print size in human-readable format",
220
+ "-I": "Exclude pattern from listing",
221
+ "--gitignore": "Filter using .gitignore rules",
222
+ },
223
+ "common_patterns": ["tree -L 2", "tree -d", "tree -a -I 'node_modules|.git'"],
224
+ },
225
+ "du": {
226
+ "description": "Estimate file and directory space usage",
227
+ "man_url": "https://man7.org/linux/man-pages/man1/du.1.html",
228
+ "flags": {
229
+ "-h": "Human-readable sizes",
230
+ "-s": "Summary only (total for each argument)",
231
+ "-a": "Show all files, not just directories",
232
+ "-c": "Produce grand total",
233
+ "--max-depth": "Maximum directory depth",
234
+ },
235
+ "common_patterns": ["du -sh *", "du -sh .", "du -h --max-depth=1", "du -sh */ | sort -h"],
236
+ },
237
+ "df": {
238
+ "description": "Report filesystem disk space usage",
239
+ "man_url": "https://man7.org/linux/man-pages/man1/df.1.html",
240
+ "flags": {
241
+ "-h": "Human-readable sizes",
242
+ "-T": "Show filesystem type",
243
+ "-i": "Show inode information instead of block usage",
244
+ },
245
+ "common_patterns": ["df -h", "df -hT", "df -h /"],
246
+ },
247
+ "mkdir": {
248
+ "description": "Create directories",
249
+ "man_url": "https://man7.org/linux/man-pages/man1/mkdir.1.html",
250
+ "flags": {
251
+ "-p": "Create parent directories as needed, no error if exists",
252
+ "-v": "Verbose, print each directory created",
253
+ "-m": "Set permission mode (like chmod)",
254
+ },
255
+ "common_patterns": ["mkdir -p src/components/ui", "mkdir -pv new/nested/dir"],
256
+ },
257
+ "rm": {
258
+ "description": "Remove files or directories",
259
+ "man_url": "https://man7.org/linux/man-pages/man1/rm.1.html",
260
+ "flags": {
261
+ "-r": "Remove directories recursively",
262
+ "-f": "Force, ignore nonexistent files, never prompt",
263
+ "-i": "Interactive, prompt before each removal",
264
+ "-v": "Verbose, explain what is being done",
265
+ },
266
+ "common_patterns": ["rm file.txt", "rm -rf directory/", "rm -i *.log"],
267
+ },
268
+ "cp": {
269
+ "description": "Copy files and directories",
270
+ "man_url": "https://man7.org/linux/man-pages/man1/cp.1.html",
271
+ "flags": {
272
+ "-r": "Copy directories recursively",
273
+ "-a": "Archive mode (preserve all: -dR --preserve=all)",
274
+ "-i": "Interactive, prompt before overwrite",
275
+ "-n": "No clobber, don't overwrite existing",
276
+ "-u": "Update, copy only when source is newer",
277
+ "-v": "Verbose, explain what is being done",
278
+ },
279
+ "common_patterns": ["cp file.txt backup.txt", "cp -r src/ dest/", "cp -a project/ backup/"],
280
+ },
281
+ "mv": {
282
+ "description": "Move or rename files and directories",
283
+ "man_url": "https://man7.org/linux/man-pages/man1/mv.1.html",
284
+ "flags": {
285
+ "-i": "Interactive, prompt before overwrite",
286
+ "-n": "No clobber, don't overwrite existing",
287
+ "-u": "Update, move only when source is newer",
288
+ "-v": "Verbose, explain what is being done",
289
+ },
290
+ "common_patterns": ["mv old.txt new.txt", "mv file.txt directory/", "mv -v *.log archive/"],
291
+ },
292
+ "touch": {
293
+ "description": "Create empty files or update file timestamps",
294
+ "man_url": "https://man7.org/linux/man-pages/man1/touch.1.html",
295
+ "flags": {
296
+ "-a": "Change only access time",
297
+ "-m": "Change only modification time",
298
+ "-c": "Don't create file if it doesn't exist",
299
+ "-d": "Parse string and use instead of current time",
300
+ },
301
+ "common_patterns": ["touch newfile.txt", "touch -c existing.txt"],
302
+ },
303
+ "ln": {
304
+ "description": "Create links between files (hard or symbolic)",
305
+ "man_url": "https://man7.org/linux/man-pages/man1/ln.1.html",
306
+ "flags": {
307
+ "-s": "Create symbolic (soft) link",
308
+ "-f": "Force, remove existing destination files",
309
+ "-r": "Create relative symbolic link",
310
+ "-v": "Verbose, print name of each linked file",
311
+ },
312
+ "common_patterns": ["ln -s /path/to/target linkname", "ln -sf target link"],
313
+ },
314
+ "cat": {
315
+ "description": "Concatenate and display file contents",
316
+ "man_url": "https://man7.org/linux/man-pages/man1/cat.1.html",
317
+ "flags": {
318
+ "-n": "Number all output lines",
319
+ "-b": "Number non-blank output lines",
320
+ "-s": "Squeeze multiple blank lines into one",
321
+ "-A": "Show all (equivalent to -vET)",
322
+ },
323
+ "common_patterns": ["cat file.txt", "cat -n script.sh", "cat file1.txt file2.txt > combined.txt"],
324
+ },
325
+ "grep": {
326
+ "description": "Search for patterns in text using regular expressions",
327
+ "man_url": "https://man7.org/linux/man-pages/man1/grep.1.html",
328
+ "flags": {
329
+ "-i": "Case-insensitive matching",
330
+ "-v": "Invert match (show non-matching lines)",
331
+ "-r": "Recursive search in directories",
332
+ "-l": "List filenames with matches only",
333
+ "-n": "Show line numbers",
334
+ "-c": "Count matching lines",
335
+ "-w": "Match whole words only",
336
+ "-E": "Extended regex (same as egrep)",
337
+ "-o": "Show only matching part of line",
338
+ "-A": "Show N lines after match",
339
+ "-B": "Show N lines before match",
340
+ "-C": "Show N lines of context (before and after)",
341
+ "--include": "Search only files matching pattern",
342
+ "--exclude": "Skip files matching pattern",
343
+ },
344
+ "common_patterns": [
345
+ "grep 'pattern' file.txt",
346
+ "grep -r 'TODO' src/",
347
+ "grep -rn 'function' --include='*.js'",
348
+ "grep -i 'error' log.txt",
349
+ "grep -v '^#' config.txt",
350
+ ],
351
+ },
352
+ "sed": {
353
+ "description": "Stream editor for filtering and transforming text",
354
+ "man_url": "https://man7.org/linux/man-pages/man1/sed.1.html",
355
+ "flags": {
356
+ "-i": "Edit files in place",
357
+ "-e": "Add script/expression to commands",
358
+ "-n": "Suppress automatic printing",
359
+ "-E": "Use extended regular expressions (portable)",
360
+ },
361
+ "common_patterns": [
362
+ "sed 's/old/new/' file.txt",
363
+ "sed 's/old/new/g' file.txt",
364
+ "sed -i 's/old/new/g' file.txt",
365
+ "sed -n '10,20p' file.txt",
366
+ "sed '/pattern/d' file.txt",
367
+ ],
368
+ },
369
+ "awk": {
370
+ "description": "Pattern scanning and text processing language",
371
+ "man_url": "https://man7.org/linux/man-pages/man1/awk.1p.html",
372
+ "flags": {
373
+ "-F": "Set field separator",
374
+ "-v": "Assign variable before execution",
375
+ "-f": "Read program from file",
376
+ },
377
+ "common_patterns": [
378
+ "awk '{print $1}' file.txt",
379
+ "awk -F',' '{print $1, $3}' data.csv",
380
+ "awk '/pattern/ {print}' file.txt",
381
+ "awk '{sum += $1} END {print sum}' numbers.txt",
382
+ ],
383
+ },
384
+ "sort": {
385
+ "description": "Sort lines of text files",
386
+ "man_url": "https://man7.org/linux/man-pages/man1/sort.1.html",
387
+ "flags": {
388
+ "-r": "Reverse sort order",
389
+ "-n": "Numeric sort",
390
+ "-h": "Human numeric sort (2K, 1G)",
391
+ "-k": "Sort by specific field/key",
392
+ "-t": "Field separator",
393
+ "-u": "Output only unique lines",
394
+ },
395
+ "common_patterns": ["sort file.txt", "sort -r file.txt", "sort -n numbers.txt", "du -sh * | sort -h"],
396
+ },
397
+ "uniq": {
398
+ "description": "Report or filter out repeated lines (requires sorted input)",
399
+ "man_url": "https://man7.org/linux/man-pages/man1/uniq.1.html",
400
+ "flags": {
401
+ "-c": "Prefix lines by count of occurrences",
402
+ "-d": "Only print duplicate lines",
403
+ "-u": "Only print unique lines",
404
+ "-i": "Case-insensitive comparison",
405
+ },
406
+ "common_patterns": ["sort file.txt | uniq", "sort file.txt | uniq -c", "sort file.txt | uniq -c | sort -rn"],
407
+ },
408
+ "wc": {
409
+ "description": "Print line, word, and byte counts",
410
+ "man_url": "https://man7.org/linux/man-pages/man1/wc.1.html",
411
+ "flags": {
412
+ "-l": "Print line count only",
413
+ "-w": "Print word count only",
414
+ "-c": "Print byte count only",
415
+ "-m": "Print character count only",
416
+ },
417
+ "common_patterns": ["wc file.txt", "wc -l file.txt", "wc -l *.py"],
418
+ },
419
+ "head": {
420
+ "description": "Output the first part of files",
421
+ "man_url": "https://man7.org/linux/man-pages/man1/head.1.html",
422
+ "flags": {
423
+ "-n": "Print first N lines (or -N for all but last N)",
424
+ "-c": "Print first N bytes",
425
+ },
426
+ "common_patterns": ["head file.txt", "head -n 20 file.txt"],
427
+ },
428
+ "tail": {
429
+ "description": "Output the last part of files",
430
+ "man_url": "https://man7.org/linux/man-pages/man1/tail.1.html",
431
+ "flags": {
432
+ "-n": "Print last N lines (or +N for lines from N onward)",
433
+ "-f": "Follow file as it grows",
434
+ "-F": "Follow with retry (handles log rotation)",
435
+ },
436
+ "common_patterns": ["tail file.txt", "tail -n 50 file.txt", "tail -f logfile.log"],
437
+ },
438
+ "cut": {
439
+ "description": "Remove sections from each line of files",
440
+ "man_url": "https://man7.org/linux/man-pages/man1/cut.1.html",
441
+ "flags": {
442
+ "-d": "Use delimiter instead of TAB",
443
+ "-f": "Select fields (1,3 or 1-3)",
444
+ "-c": "Select characters",
445
+ },
446
+ "common_patterns": ["cut -d',' -f1,3 data.csv", "cut -d':' -f1 /etc/passwd"],
447
+ },
448
+ "tr": {
449
+ "description": "Translate or delete characters",
450
+ "man_url": "https://man7.org/linux/man-pages/man1/tr.1.html",
451
+ "flags": {
452
+ "-d": "Delete characters in SET1",
453
+ "-s": "Squeeze repeated characters",
454
+ "-c": "Use complement of SET1",
455
+ },
456
+ "common_patterns": ["tr 'a-z' 'A-Z'", "tr -d '\\n'", "tr -s ' '"],
457
+ },
458
+ "diff": {
459
+ "description": "Compare files line by line",
460
+ "man_url": "https://man7.org/linux/man-pages/man1/diff.1.html",
461
+ "flags": {
462
+ "-u": "Unified format (most common)",
463
+ "-r": "Recursive directory comparison",
464
+ "-q": "Report only when files differ",
465
+ "-i": "Ignore case differences",
466
+ "--color": "Colorize output",
467
+ },
468
+ "common_patterns": ["diff file1.txt file2.txt", "diff -u original.txt modified.txt"],
469
+ },
470
+ "jq": {
471
+ "description": "Command-line JSON processor",
472
+ "man_url": "https://stedolan.github.io/jq/manual/",
473
+ "flags": {
474
+ "-r": "Raw output (no quotes for strings)",
475
+ "-c": "Compact output (one line)",
476
+ "-s": "Slurp mode (read entire input as array)",
477
+ "-S": "Sort object keys",
478
+ "--arg": "Set variable to string value",
479
+ },
480
+ "common_patterns": [
481
+ "jq '.' file.json",
482
+ "jq '.name' file.json",
483
+ "jq -r '.items[]' file.json",
484
+ "curl -s url | jq '.'",
485
+ ],
486
+ },
487
+ "tee": {
488
+ "description": "Read from stdin and write to stdout and files simultaneously",
489
+ "man_url": "https://man7.org/linux/man-pages/man1/tee.1.html",
490
+ "flags": {
491
+ "-a": "Append to files instead of overwriting",
492
+ },
493
+ "common_patterns": ["echo 'text' | tee file.txt", "command | tee output.log"],
494
+ },
495
+ "xargs": {
496
+ "description": "Build and execute commands from standard input",
497
+ "man_url": "https://man7.org/linux/man-pages/man1/xargs.1.html",
498
+ "flags": {
499
+ "-0": "Input items terminated by null (for find -print0)",
500
+ "-n": "Use at most N arguments per command",
501
+ "-I": "Replace string in command with input",
502
+ "-P": "Run N processes in parallel",
503
+ },
504
+ "common_patterns": [
505
+ "find . -name '*.log' | xargs rm",
506
+ "find . -name '*.txt' -print0 | xargs -0 grep 'pattern'",
507
+ "echo 'a b c' | xargs -n 1 echo",
508
+ ],
509
+ },
510
+ "git": {
511
+ "description": "Distributed version control system",
512
+ "man_url": "https://git-scm.com/docs",
513
+ "flags": {
514
+ "--version": "Print git version",
515
+ "-C": "Run as if started in specified directory",
516
+ },
517
+ "subcommands": {
518
+ "init": "Create empty repository",
519
+ "clone": "Clone repository",
520
+ "add": "Add file contents to staging",
521
+ "commit": "Record changes",
522
+ "status": "Show working tree status",
523
+ "diff": "Show changes",
524
+ "log": "Show commit logs",
525
+ "branch": "Manage branches",
526
+ "checkout": "Switch branches",
527
+ "merge": "Join histories",
528
+ "pull": "Fetch and integrate",
529
+ "push": "Update remote",
530
+ "stash": "Stash changes",
531
+ },
532
+ "common_patterns": [
533
+ "git init",
534
+ "git clone url",
535
+ "git add .",
536
+ "git commit -m 'message'",
537
+ "git status",
538
+ "git log --oneline",
539
+ "git branch -a",
540
+ "git checkout -b new-branch",
541
+ "git pull origin main",
542
+ "git push origin main",
543
+ ],
544
+ },
545
+ "npm": {
546
+ "description": "Node.js package manager",
547
+ "man_url": "https://docs.npmjs.com/cli",
548
+ "flags": {
549
+ "-g": "Install globally",
550
+ "--save-dev": "Save to devDependencies",
551
+ "-D": "Save to devDependencies (shorthand)",
552
+ "-y": "Accept defaults for init",
553
+ },
554
+ "subcommands": {
555
+ "init": "Create package.json",
556
+ "install": "Install dependencies",
557
+ "run": "Run scripts",
558
+ "test": "Run test script",
559
+ "build": "Run build script",
560
+ },
561
+ "common_patterns": [
562
+ "npm init -y",
563
+ "npm install",
564
+ "npm install package-name",
565
+ "npm install -D typescript",
566
+ "npm run build",
567
+ ],
568
+ },
569
+ "npx": {
570
+ "description": "Execute npm package binaries",
571
+ "man_url": "https://docs.npmjs.com/cli/commands/npx",
572
+ "flags": {
573
+ "-y": "Auto-confirm package installation",
574
+ "--no-install": "Error if package not installed",
575
+ },
576
+ "common_patterns": ["npx create-react-app my-app", "npx typescript --init", "npx eslint ."],
577
+ },
578
+ "pip": {
579
+ "description": "Python package installer",
580
+ "man_url": "https://pip.pypa.io/en/stable/",
581
+ "flags": {
582
+ "-r": "Install from requirements file",
583
+ "-e": "Install in editable/development mode",
584
+ "--upgrade": "Upgrade packages",
585
+ "-U": "Upgrade packages (shorthand)",
586
+ },
587
+ "common_patterns": [
588
+ "pip install package-name",
589
+ "pip install -r requirements.txt",
590
+ "pip freeze > requirements.txt",
591
+ "pip list",
592
+ ],
593
+ },
594
+ "apt": {
595
+ "description": "Debian/Ubuntu package manager",
596
+ "man_url": "https://manpages.ubuntu.com/manpages/man8/apt.8.html",
597
+ "flags": {
598
+ "-y": "Automatic yes to prompts",
599
+ "-q": "Quiet output",
600
+ },
601
+ "common_patterns": ["apt update", "apt upgrade -y", "apt install package-name"],
602
+ },
603
+ "brew": {
604
+ "description": "macOS/Linux package manager (Homebrew)",
605
+ "man_url": "https://docs.brew.sh/Manpage",
606
+ "flags": {
607
+ "--cask": "Operate on cask (macOS apps)",
608
+ },
609
+ "common_patterns": ["brew install package-name", "brew update", "brew upgrade"],
610
+ },
611
+ "cargo": {
612
+ "description": "Rust package manager and build tool",
613
+ "man_url": "https://doc.rust-lang.org/cargo/",
614
+ "flags": {
615
+ "--release": "Build in release mode with optimizations",
616
+ },
617
+ "common_patterns": ["cargo new project-name", "cargo build", "cargo run", "cargo test"],
618
+ },
619
+ "ps": {
620
+ "description": "Report process status",
621
+ "man_url": "https://man7.org/linux/man-pages/man1/ps.1.html",
622
+ "flags": {
623
+ "-e": "Select all processes",
624
+ "-f": "Full-format listing",
625
+ "-u": "Select by effective user",
626
+ "aux": "BSD-style all users, detailed",
627
+ },
628
+ "common_patterns": ["ps aux", "ps -ef", "ps aux | grep process-name"],
629
+ },
630
+ "kill": {
631
+ "description": "Send signals to processes",
632
+ "man_url": "https://man7.org/linux/man-pages/man1/kill.1.html",
633
+ "flags": {
634
+ "-9": "SIGKILL - force kill",
635
+ "-15": "SIGTERM - terminate (default)",
636
+ "-l": "List signal names",
637
+ },
638
+ "common_patterns": ["kill PID", "kill -9 PID"],
639
+ },
640
+ "top": {
641
+ "description": "Display and update sorted process information",
642
+ "man_url": "https://man7.org/linux/man-pages/man1/top.1.html",
643
+ "flags": {
644
+ "-b": "Batch mode (for piping output)",
645
+ "-n": "Number of iterations",
646
+ "-u": "Filter by user",
647
+ },
648
+ "common_patterns": ["top", "top -u username"],
649
+ },
650
+ "env": {
651
+ "description": "Display, set, or remove environment variables",
652
+ "man_url": "https://man7.org/linux/man-pages/man1/env.1.html",
653
+ "flags": {
654
+ "-i": "Start with empty environment",
655
+ "-u": "Remove variable from environment",
656
+ },
657
+ "common_patterns": ["env", "env | grep PATH", "env VAR=value command"],
658
+ },
659
+ "export": {
660
+ "description": "Set environment variables for child processes",
661
+ "man_url": "https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html",
662
+ "flags": {
663
+ "-p": "Display all exported variables",
664
+ "-n": "Remove export property",
665
+ },
666
+ "common_patterns": ["export PATH=$PATH:/new/path", "export NODE_ENV=production"],
667
+ },
668
+ "which": {
669
+ "description": "Locate command executable in PATH",
670
+ "man_url": "https://man7.org/linux/man-pages/man1/which.1.html",
671
+ "flags": {
672
+ "-a": "Print all matches in PATH",
673
+ },
674
+ "common_patterns": ["which python", "which -a python"],
675
+ },
676
+ "curl": {
677
+ "description": "Transfer data with URLs",
678
+ "man_url": "https://curl.se/docs/manpage.html",
679
+ "flags": {
680
+ "-X": "Request method (GET, POST, PUT, DELETE)",
681
+ "-H": "Add header",
682
+ "-d": "Send data in request body",
683
+ "-o": "Write output to file",
684
+ "-O": "Write to file named like remote",
685
+ "-L": "Follow redirects",
686
+ "-s": "Silent mode",
687
+ "-v": "Verbose output",
688
+ "-i": "Include response headers",
689
+ "-I": "Fetch headers only (HEAD request)",
690
+ },
691
+ "common_patterns": [
692
+ "curl https://api.example.com",
693
+ "curl -s https://api.example.com | jq '.'",
694
+ "curl -X POST -H 'Content-Type: application/json' -d '{\"key\":\"value\"}' url",
695
+ "curl -o output.html https://example.com",
696
+ "curl -L https://shortened.url",
697
+ ],
698
+ },
699
+ "wget": {
700
+ "description": "Non-interactive network file downloader",
701
+ "man_url": "https://www.gnu.org/software/wget/manual/wget.html",
702
+ "flags": {
703
+ "-O": "Write to specified file",
704
+ "-q": "Quiet mode",
705
+ "-c": "Continue interrupted download",
706
+ "-r": "Recursive download",
707
+ },
708
+ "common_patterns": ["wget https://example.com/file.zip", "wget -O output.zip url"],
709
+ },
710
+ "ssh": {
711
+ "description": "OpenSSH remote login client",
712
+ "man_url": "https://man.openbsd.org/ssh",
713
+ "flags": {
714
+ "-p": "Port to connect to",
715
+ "-i": "Identity file (private key)",
716
+ "-v": "Verbose mode",
717
+ "-L": "Local port forwarding",
718
+ "-D": "Dynamic port forwarding (SOCKS proxy)",
719
+ },
720
+ "common_patterns": ["ssh user@host", "ssh -p 2222 user@host", "ssh -i ~/.ssh/key.pem user@host"],
721
+ },
722
+ "scp": {
723
+ "description": "Secure copy over SSH",
724
+ "man_url": "https://man.openbsd.org/scp",
725
+ "flags": {
726
+ "-r": "Recursive copy directories",
727
+ "-P": "Port to connect to",
728
+ "-i": "Identity file",
729
+ },
730
+ "common_patterns": ["scp file.txt user@host:/path/", "scp -r directory/ user@host:/path/"],
731
+ },
732
+ "rsync": {
733
+ "description": "Fast, versatile file copying tool for synchronization",
734
+ "man_url": "https://rsync.samba.org/documentation.html",
735
+ "flags": {
736
+ "-a": "Archive mode (preserves everything)",
737
+ "-v": "Verbose output",
738
+ "-z": "Compress during transfer",
739
+ "-n": "Dry run",
740
+ "--delete": "Delete extraneous files from destination",
741
+ "-P": "Show progress and allow resume",
742
+ },
743
+ "common_patterns": ["rsync -av source/ destination/", "rsync -avz source/ user@host:/destination/"],
744
+ },
745
+ "chmod": {
746
+ "description": "Change file mode/permissions",
747
+ "man_url": "https://man7.org/linux/man-pages/man1/chmod.1.html",
748
+ "flags": {
749
+ "-R": "Recursive change",
750
+ "-v": "Verbose, show changes",
751
+ },
752
+ "common_patterns": ["chmod 755 script.sh", "chmod +x script.sh", "chmod -R 644 directory/"],
753
+ },
754
+ "chown": {
755
+ "description": "Change file owner and group",
756
+ "man_url": "https://man7.org/linux/man-pages/man1/chown.1.html",
757
+ "flags": {
758
+ "-R": "Recursive change",
759
+ "-v": "Verbose, show changes",
760
+ },
761
+ "common_patterns": ["chown user file.txt", "chown user:group file.txt", "chown -R user:group directory/"],
762
+ },
763
+ "tar": {
764
+ "description": "Archive files (tape archive)",
765
+ "man_url": "https://man7.org/linux/man-pages/man1/tar.1.html",
766
+ "flags": {
767
+ "-c": "Create archive",
768
+ "-x": "Extract archive",
769
+ "-t": "List archive contents",
770
+ "-f": "Archive filename",
771
+ "-v": "Verbose output",
772
+ "-z": "Filter through gzip",
773
+ "-j": "Filter through bzip2",
774
+ "-C": "Change to directory before operation",
775
+ },
776
+ "common_patterns": [
777
+ "tar -cvf archive.tar directory/",
778
+ "tar -xvf archive.tar",
779
+ "tar -czvf archive.tar.gz directory/",
780
+ "tar -xzvf archive.tar.gz",
781
+ ],
782
+ },
783
+ "gzip": {
784
+ "description": "Compress files with LZ77 algorithm",
785
+ "man_url": "https://man7.org/linux/man-pages/man1/gzip.1.html",
786
+ "flags": {
787
+ "-d": "Decompress",
788
+ "-k": "Keep original file",
789
+ "-v": "Verbose output",
790
+ "-9": "Best compression",
791
+ },
792
+ "common_patterns": ["gzip file.txt", "gzip -d file.txt.gz", "gunzip file.txt.gz"],
793
+ },
794
+ "zip": {
795
+ "description": "Package and compress files",
796
+ "man_url": "https://linux.die.net/man/1/zip",
797
+ "flags": {
798
+ "-r": "Recursive, include directories",
799
+ "-e": "Encrypt with password",
800
+ "-9": "Best compression",
801
+ },
802
+ "common_patterns": ["zip archive.zip file1 file2", "zip -r archive.zip directory/"],
803
+ },
804
+ "unzip": {
805
+ "description": "Extract compressed files from zip archive",
806
+ "man_url": "https://linux.die.net/man/1/unzip",
807
+ "flags": {
808
+ "-l": "List archive contents",
809
+ "-d": "Extract to directory",
810
+ "-o": "Overwrite without prompting",
811
+ },
812
+ "common_patterns": ["unzip archive.zip", "unzip archive.zip -d destination/"],
813
+ },
814
+ "node": {
815
+ "description": "JavaScript runtime built on V8",
816
+ "man_url": "https://nodejs.org/docs/latest/api/cli.html",
817
+ "flags": {
818
+ "-v": "Print Node.js version",
819
+ "-e": "Evaluate script",
820
+ "--inspect": "Enable inspector agent",
821
+ },
822
+ "common_patterns": ["node script.js", "node -e 'console.log(process.version)'"],
823
+ },
824
+ "python": {
825
+ "description": "Python interpreter",
826
+ "man_url": "https://docs.python.org/3/using/cmdline.html",
827
+ "flags": {
828
+ "-V": "Print Python version",
829
+ "-c": "Execute command string",
830
+ "-m": "Run module as script",
831
+ },
832
+ "common_patterns": ["python script.py", "python -m http.server 8000", "python -m venv venv"],
833
+ },
834
+ "docker": {
835
+ "description": "Container management platform",
836
+ "man_url": "https://docs.docker.com/engine/reference/commandline/docker/",
837
+ "flags": {
838
+ "-v": "Bind mount a volume",
839
+ "-p": "Publish port",
840
+ "-d": "Detached mode",
841
+ "-it": "Interactive with TTY",
842
+ "-e": "Set environment variable",
843
+ "--name": "Assign name to container",
844
+ "--rm": "Remove container when stopped",
845
+ },
846
+ "common_patterns": [
847
+ "docker run -it ubuntu bash",
848
+ "docker run -d -p 8080:80 nginx",
849
+ "docker ps",
850
+ "docker images",
851
+ "docker build -t myapp .",
852
+ ],
853
+ },
854
+ "echo": {
855
+ "description": "Display text or variables",
856
+ "man_url": "https://man7.org/linux/man-pages/man1/echo.1.html",
857
+ "flags": {
858
+ "-n": "Don't output trailing newline",
859
+ "-e": "Enable interpretation of backslash escapes",
860
+ },
861
+ "common_patterns": ["echo 'Hello World'", "echo $PATH", "echo -n 'no newline'"],
862
+ },
863
+ "date": {
864
+ "description": "Display or set system date and time",
865
+ "man_url": "https://man7.org/linux/man-pages/man1/date.1.html",
866
+ "flags": {
867
+ "-u": "UTC time",
868
+ "-d": "Display specified date",
869
+ "-I": "ISO 8601 format",
870
+ },
871
+ "common_patterns": ["date", "date +%Y-%m-%d", "date '+%Y-%m-%d %H:%M:%S'"],
872
+ },
873
+ "sleep": {
874
+ "description": "Delay for specified time",
875
+ "man_url": "https://man7.org/linux/man-pages/man1/sleep.1.html",
876
+ "flags": {},
877
+ "common_patterns": ["sleep 5", "sleep 0.5", "sleep 1m"],
878
+ },
879
+ "time": {
880
+ "description": "Measure command execution time",
881
+ "man_url": "https://man7.org/linux/man-pages/man1/time.1.html",
882
+ "flags": {},
883
+ "common_patterns": ["time command", "time ./script.sh"],
884
+ },
885
+ "watch": {
886
+ "description": "Execute command repeatedly and display output",
887
+ "man_url": "https://man7.org/linux/man-pages/man1/watch.1.html",
888
+ "flags": {
889
+ "-n": "Interval in seconds",
890
+ "-d": "Highlight differences",
891
+ },
892
+ "common_patterns": ["watch -n 1 'date'", "watch df -h"],
893
+ },
894
+ "history": {
895
+ "description": "Display command history",
896
+ "man_url": "https://www.gnu.org/software/bash/manual/html_node/Bash-History-Builtins.html",
897
+ "flags": {
898
+ "-c": "Clear history list",
899
+ },
900
+ "common_patterns": ["history", "history | grep pattern"],
901
+ },
902
+ "alias": {
903
+ "description": "Create command aliases",
904
+ "man_url": "https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html",
905
+ "flags": {},
906
+ "common_patterns": ["alias", "alias ll='ls -la'", "alias gs='git status'"],
907
+ },
908
+ "test": {
909
+ "description": "Evaluate conditional expression",
910
+ "man_url": "https://man7.org/linux/man-pages/man1/test.1.html",
911
+ "flags": {
912
+ "-e": "File exists",
913
+ "-f": "Is regular file",
914
+ "-d": "Is directory",
915
+ "-r": "Is readable",
916
+ "-w": "Is writable",
917
+ "-x": "Is executable",
918
+ "-z": "String is empty",
919
+ "-n": "String is non-empty",
920
+ },
921
+ "common_patterns": ["test -f file.txt && echo 'exists'", "[ -d dir ] && cd dir"],
922
+ },
923
+ "read": {
924
+ "description": "Read line from stdin into variable",
925
+ "man_url": "https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html",
926
+ "flags": {
927
+ "-p": "Prompt string",
928
+ "-r": "Raw input (no backslash escaping)",
929
+ "-s": "Silent mode (for passwords)",
930
+ "-t": "Timeout in seconds",
931
+ },
932
+ "common_patterns": ["read -p 'Enter name: ' name", "read -s -p 'Password: ' pass"],
933
+ },
934
+ "basename": {
935
+ "description": "Strip directory and suffix from filename",
936
+ "man_url": "https://man7.org/linux/man-pages/man1/basename.1.html",
937
+ "flags": {
938
+ "-s": "Remove suffix",
939
+ },
940
+ "common_patterns": ["basename /path/to/file.txt", "basename /path/to/file.txt .txt"],
941
+ },
942
+ "dirname": {
943
+ "description": "Strip last component from filename",
944
+ "man_url": "https://man7.org/linux/man-pages/man1/dirname.1.html",
945
+ "flags": {},
946
+ "common_patterns": ["dirname /path/to/file.txt", "cd $(dirname $0)"],
947
+ },
948
+ "realpath": {
949
+ "description": "Print resolved absolute pathname",
950
+ "man_url": "https://man7.org/linux/man-pages/man1/realpath.1.html",
951
+ "flags": {
952
+ "-e": "All components must exist",
953
+ "-s": "Don't expand symlinks",
954
+ },
955
+ "common_patterns": ["realpath file.txt", "realpath ."],
956
+ },
957
+ "seq": {
958
+ "description": "Print sequence of numbers",
959
+ "man_url": "https://man7.org/linux/man-pages/man1/seq.1.html",
960
+ "flags": {
961
+ "-s": "Separator string",
962
+ "-w": "Equalize width with leading zeros",
963
+ },
964
+ "common_patterns": ["seq 10", "seq 1 10", "seq -w 01 10"],
965
+ },
966
+ "stat": {
967
+ "description": "Display detailed file or filesystem status",
968
+ "man_url": "https://man7.org/linux/man-pages/man1/stat.1.html",
969
+ "flags": {
970
+ "-c": "Use specified FORMAT",
971
+ },
972
+ "common_patterns": ["stat file.txt", "stat -c '%a %n' *"],
973
+ },
974
+ "file": {
975
+ "description": "Determine file type by examining content",
976
+ "man_url": "https://man7.org/linux/man-pages/man1/file.1.html",
977
+ "flags": {
978
+ "-b": "Brief mode (don't print filename)",
979
+ "-i": "Output MIME type strings",
980
+ },
981
+ "common_patterns": ["file *", "file -i document.pdf"],
982
+ },
983
+ "less": {
984
+ "description": "View file contents with scrolling and search",
985
+ "man_url": "https://man7.org/linux/man-pages/man1/less.1.html",
986
+ "flags": {
987
+ "-N": "Show line numbers",
988
+ "-S": "Chop long lines",
989
+ "-R": "Show raw control characters (for colors)",
990
+ },
991
+ "common_patterns": ["less file.txt", "command | less"],
992
+ },
993
+ "more": {
994
+ "description": "View file contents one screen at a time",
995
+ "man_url": "https://man7.org/linux/man-pages/man1/more.1.html",
996
+ "flags": {},
997
+ "common_patterns": ["more file.txt"],
998
+ },
999
+ "clear": {
1000
+ "description": "Clear terminal screen",
1001
+ "man_url": "https://man7.org/linux/man-pages/man1/clear.1.html",
1002
+ "flags": {},
1003
+ "common_patterns": ["clear"],
1004
+ },
1005
+ "man": {
1006
+ "description": "Display manual pages for commands",
1007
+ "man_url": "https://man7.org/linux/man-pages/man1/man.1.html",
1008
+ "flags": {
1009
+ "-k": "Search manual page names and descriptions",
1010
+ },
1011
+ "common_patterns": ["man ls", "man -k keyword"],
1012
+ },
1013
+ "ping": {
1014
+ "description": "Send ICMP ECHO_REQUEST packets to network hosts",
1015
+ "man_url": "https://man7.org/linux/man-pages/man8/ping.8.html",
1016
+ "flags": {
1017
+ "-c": "Stop after N packets",
1018
+ "-i": "Interval between packets (seconds)",
1019
+ },
1020
+ "common_patterns": ["ping google.com", "ping -c 4 google.com"],
1021
+ },
1022
+ "netstat": {
1023
+ "description": "Network statistics and connections",
1024
+ "man_url": "https://man7.org/linux/man-pages/man8/netstat.8.html",
1025
+ "flags": {
1026
+ "-t": "TCP connections",
1027
+ "-u": "UDP connections",
1028
+ "-l": "Listening sockets only",
1029
+ "-p": "Show PID/program name",
1030
+ "-n": "Numeric addresses (no DNS)",
1031
+ },
1032
+ "common_patterns": ["netstat -tlnp", "netstat -an | grep LISTEN"],
1033
+ },
1034
+ "ss": {
1035
+ "description": "Socket statistics (modern netstat replacement)",
1036
+ "man_url": "https://man7.org/linux/man-pages/man8/ss.8.html",
1037
+ "flags": {
1038
+ "-t": "TCP sockets",
1039
+ "-u": "UDP sockets",
1040
+ "-l": "Listening sockets",
1041
+ "-n": "Numeric (no resolve)",
1042
+ "-p": "Show processes",
1043
+ },
1044
+ "common_patterns": ["ss -tlnp", "ss -tulnp"],
1045
+ },
1046
+ "make": {
1047
+ "description": "Build automation tool",
1048
+ "man_url": "https://www.gnu.org/software/make/manual/make.html",
1049
+ "flags": {
1050
+ "-f": "Use specified Makefile",
1051
+ "-j": "Parallel jobs",
1052
+ "-n": "Dry run",
1053
+ },
1054
+ "common_patterns": ["make", "make target", "make -j4", "make clean"],
1055
+ },
1056
+ "tsc": {
1057
+ "description": "TypeScript compiler",
1058
+ "man_url": "https://www.typescriptlang.org/docs/handbook/compiler-options.html",
1059
+ "flags": {
1060
+ "-w": "Watch mode",
1061
+ "--init": "Create tsconfig.json",
1062
+ "--noEmit": "Check without emitting",
1063
+ },
1064
+ "common_patterns": ["tsc", "tsc --init", "tsc -w"],
1065
+ },
1066
+ "eslint": {
1067
+ "description": "JavaScript/TypeScript linter",
1068
+ "man_url": "https://eslint.org/docs/user-guide/command-line-interface",
1069
+ "flags": {
1070
+ "--fix": "Automatically fix problems",
1071
+ "--ext": "File extensions to lint",
1072
+ },
1073
+ "common_patterns": ["eslint .", "eslint --fix ."],
1074
+ },
1075
+ "prettier": {
1076
+ "description": "Code formatter",
1077
+ "man_url": "https://prettier.io/docs/en/cli.html",
1078
+ "flags": {
1079
+ "--write": "Write changes to file",
1080
+ "--check": "Check if files are formatted",
1081
+ },
1082
+ "common_patterns": ["prettier --write .", "prettier --check ."],
1083
+ },
1084
+ "pytest": {
1085
+ "description": "Python testing framework",
1086
+ "man_url": "https://docs.pytest.org/en/stable/reference/reference.html",
1087
+ "flags": {
1088
+ "-v": "Verbose output",
1089
+ "-x": "Stop on first failure",
1090
+ "-k": "Filter tests by expression",
1091
+ "--cov": "Coverage report",
1092
+ },
1093
+ "common_patterns": ["pytest", "pytest -v", "pytest --cov=src"],
1094
+ },
1095
+ "jest": {
1096
+ "description": "JavaScript testing framework",
1097
+ "man_url": "https://jestjs.io/docs/cli",
1098
+ "flags": {
1099
+ "--watch": "Watch mode",
1100
+ "--coverage": "Collect coverage",
1101
+ },
1102
+ "common_patterns": ["jest", "jest --watch", "jest --coverage"],
1103
+ },
1104
+ "killall": {
1105
+ "description": "Kill processes by name",
1106
+ "man_url": "https://man7.org/linux/man-pages/man1/killall.1.html",
1107
+ "flags": {
1108
+ "-9": "SIGKILL - force kill",
1109
+ "-i": "Interactive, ask before killing",
1110
+ },
1111
+ "common_patterns": ["killall process-name", "killall -9 hung-process"],
1112
+ },
1113
+ "pkill": {
1114
+ "description": "Signal processes based on pattern matching",
1115
+ "man_url": "https://man7.org/linux/man-pages/man1/pkill.1.html",
1116
+ "flags": {
1117
+ "-f": "Match against full command line",
1118
+ "-9": "Send SIGKILL",
1119
+ },
1120
+ "common_patterns": ["pkill -f 'node server'", "pkill -9 hung-process"],
1121
+ },
1122
+ "pgrep": {
1123
+ "description": "Find processes based on pattern matching",
1124
+ "man_url": "https://man7.org/linux/man-pages/man1/pgrep.1.html",
1125
+ "flags": {
1126
+ "-f": "Match against full command line",
1127
+ "-l": "List process name and ID",
1128
+ },
1129
+ "common_patterns": ["pgrep -f 'node'", "pgrep -l python"],
1130
+ },
1131
+ "htop": {
1132
+ "description": "Interactive process viewer (improved top)",
1133
+ "man_url": "https://htop.dev/",
1134
+ "flags": {
1135
+ "-u": "Show only processes for specified user",
1136
+ "-t": "Tree view",
1137
+ },
1138
+ "common_patterns": ["htop", "htop -u username"],
1139
+ },
1140
+ "whereis": {
1141
+ "description": "Locate binary, source, and manual pages for command",
1142
+ "man_url": "https://man7.org/linux/man-pages/man1/whereis.1.html",
1143
+ "flags": {
1144
+ "-b": "Search for binaries only",
1145
+ "-m": "Search for manual pages only",
1146
+ },
1147
+ "common_patterns": ["whereis python", "whereis -b node"],
1148
+ },
1149
+ "type": {
1150
+ "description": "Describe how command name would be interpreted",
1151
+ "man_url": "https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html",
1152
+ "flags": {
1153
+ "-a": "Display all locations",
1154
+ "-t": "Print single word (alias, keyword, function, builtin, file)",
1155
+ },
1156
+ "common_patterns": ["type ls", "type -a python"],
1157
+ },
1158
+ "printf": {
1159
+ "description": "Format and print data",
1160
+ "man_url": "https://man7.org/linux/man-pages/man1/printf.1.html",
1161
+ "flags": {},
1162
+ "common_patterns": ["printf '%s\\n' 'Hello'", "printf '%d\\n' 42"],
1163
+ },
1164
+ "true": {
1165
+ "description": "Return exit status 0 (success)",
1166
+ "man_url": "https://man7.org/linux/man-pages/man1/true.1.html",
1167
+ "flags": {},
1168
+ "common_patterns": ["while true; do command; sleep 1; done"],
1169
+ },
1170
+ "false": {
1171
+ "description": "Return exit status 1 (failure)",
1172
+ "man_url": "https://man7.org/linux/man-pages/man1/false.1.html",
1173
+ "flags": {},
1174
+ "common_patterns": ["false || echo 'command failed'"],
1175
+ },
1176
+ "umask": {
1177
+ "description": "Set default file creation permissions mask",
1178
+ "man_url": "https://man7.org/linux/man-pages/man2/umask.2.html",
1179
+ "flags": {
1180
+ "-S": "Display mask in symbolic form",
1181
+ },
1182
+ "common_patterns": ["umask", "umask 022", "umask -S"],
1183
+ },
1184
+ "chgrp": {
1185
+ "description": "Change group ownership",
1186
+ "man_url": "https://man7.org/linux/man-pages/man1/chgrp.1.html",
1187
+ "flags": {
1188
+ "-R": "Recursive change",
1189
+ },
1190
+ "common_patterns": ["chgrp group file.txt", "chgrp -R group directory/"],
1191
+ },
1192
+ "bzip2": {
1193
+ "description": "Block-sorting file compressor",
1194
+ "man_url": "https://man7.org/linux/man-pages/man1/bzip2.1.html",
1195
+ "flags": {
1196
+ "-d": "Decompress",
1197
+ "-k": "Keep original file",
1198
+ "-9": "Best compression",
1199
+ },
1200
+ "common_patterns": ["bzip2 file.txt", "bzip2 -d file.txt.bz2"],
1201
+ },
1202
+ "xz": {
1203
+ "description": "High-ratio file compressor using LZMA2",
1204
+ "man_url": "https://man7.org/linux/man-pages/man1/xz.1.html",
1205
+ "flags": {
1206
+ "-d": "Decompress",
1207
+ "-k": "Keep original file",
1208
+ "-9": "Best compression",
1209
+ },
1210
+ "common_patterns": ["xz file.txt", "xz -d file.txt.xz"],
1211
+ },
1212
+ "cal": {
1213
+ "description": "Display calendar",
1214
+ "man_url": "https://man7.org/linux/man-pages/man1/cal.1.html",
1215
+ "flags": {
1216
+ "-y": "Display whole year",
1217
+ "-3": "Display previous, current, and next month",
1218
+ },
1219
+ "common_patterns": ["cal", "cal -y", "cal 12 2024"],
1220
+ },
1221
+ "yes": {
1222
+ "description": "Output string repeatedly until killed",
1223
+ "man_url": "https://man7.org/linux/man-pages/man1/yes.1.html",
1224
+ "flags": {},
1225
+ "common_patterns": ["yes | command", "yes n | rm -i *"],
1226
+ },
1227
+ "shuf": {
1228
+ "description": "Shuffle lines randomly",
1229
+ "man_url": "https://man7.org/linux/man-pages/man1/shuf.1.html",
1230
+ "flags": {
1231
+ "-n": "Output at most N lines",
1232
+ "-e": "Treat arguments as input lines",
1233
+ },
1234
+ "common_patterns": ["shuf file.txt", "shuf -n 1 file.txt"],
1235
+ },
1236
+ "rev": {
1237
+ "description": "Reverse lines character by character",
1238
+ "man_url": "https://man7.org/linux/man-pages/man1/rev.1.html",
1239
+ "flags": {},
1240
+ "common_patterns": ["echo 'hello' | rev", "rev file.txt"],
1241
+ },
1242
+ "tac": {
1243
+ "description": "Concatenate and print files in reverse",
1244
+ "man_url": "https://man7.org/linux/man-pages/man1/tac.1.html",
1245
+ "flags": {},
1246
+ "common_patterns": ["tac file.txt"],
1247
+ },
1248
+ "nl": {
1249
+ "description": "Number lines of files",
1250
+ "man_url": "https://man7.org/linux/man-pages/man1/nl.1.html",
1251
+ "flags": {
1252
+ "-b": "Body numbering style (a=all, t=non-empty)",
1253
+ },
1254
+ "common_patterns": ["nl file.txt", "nl -ba file.txt"],
1255
+ },
1256
+ "paste": {
1257
+ "description": "Merge lines of files",
1258
+ "man_url": "https://man7.org/linux/man-pages/man1/paste.1.html",
1259
+ "flags": {
1260
+ "-d": "Delimiter characters",
1261
+ "-s": "Paste one file at a time",
1262
+ },
1263
+ "common_patterns": ["paste file1.txt file2.txt", "paste -d',' file1.txt file2.txt"],
1264
+ },
1265
+ "join": {
1266
+ "description": "Join lines of two files on common field",
1267
+ "man_url": "https://man7.org/linux/man-pages/man1/join.1.html",
1268
+ "flags": {
1269
+ "-t": "Field separator",
1270
+ },
1271
+ "common_patterns": ["join file1.txt file2.txt"],
1272
+ },
1273
+ "comm": {
1274
+ "description": "Compare two sorted files line by line",
1275
+ "man_url": "https://man7.org/linux/man-pages/man1/comm.1.html",
1276
+ "flags": {
1277
+ "-1": "Suppress column 1 (lines unique to file1)",
1278
+ "-2": "Suppress column 2 (lines unique to file2)",
1279
+ "-3": "Suppress column 3 (lines common to both)",
1280
+ },
1281
+ "common_patterns": ["comm file1.txt file2.txt", "comm -12 file1.txt file2.txt"],
1282
+ },
1283
+ "split": {
1284
+ "description": "Split file into pieces",
1285
+ "man_url": "https://man7.org/linux/man-pages/man1/split.1.html",
1286
+ "flags": {
1287
+ "-l": "Lines per output file",
1288
+ "-b": "Bytes per output file",
1289
+ "-d": "Use numeric suffixes",
1290
+ },
1291
+ "common_patterns": ["split -l 1000 file.txt", "split -b 10M file.bin"],
1292
+ },
1293
+ "column": {
1294
+ "description": "Format output into columns",
1295
+ "man_url": "https://man7.org/linux/man-pages/man1/column.1.html",
1296
+ "flags": {
1297
+ "-t": "Create table",
1298
+ "-s": "Separator characters",
1299
+ },
1300
+ "common_patterns": ["column -t file.txt", "mount | column -t"],
1301
+ },
1302
+ }
1303
+
1304
+
1305
+ # =============================================================================
1306
+ # OPERATORS DATABASE
1307
+ # =============================================================================
1308
+
1309
+ OPERATORS: Dict[str, Dict[str, str]] = {
1310
+ "|": {
1311
+ "name": "Pipe",
1312
+ "description": "Send stdout of left command to stdin of right command",
1313
+ "example": "ls -la | grep '.txt'",
1314
+ "use_case": "Chain commands together, filtering or transforming output",
1315
+ },
1316
+ ">": {
1317
+ "name": "Redirect stdout (overwrite)",
1318
+ "description": "Redirect stdout to file, overwriting existing content",
1319
+ "example": "echo 'hello' > file.txt",
1320
+ "use_case": "Save command output to file, replacing previous content",
1321
+ },
1322
+ ">>": {
1323
+ "name": "Redirect stdout (append)",
1324
+ "description": "Redirect stdout to file, appending to existing content",
1325
+ "example": "echo 'new line' >> file.txt",
1326
+ "use_case": "Add command output to end of file without losing existing data",
1327
+ },
1328
+ "2>": {
1329
+ "name": "Redirect stderr",
1330
+ "description": "Redirect stderr to file",
1331
+ "example": "command 2> errors.log",
1332
+ "use_case": "Capture error messages separately from normal output",
1333
+ },
1334
+ "2>&1": {
1335
+ "name": "Redirect stderr to stdout",
1336
+ "description": "Send stderr to the same destination as stdout",
1337
+ "example": "command > output.log 2>&1",
1338
+ "use_case": "Capture both normal output and errors in same file/stream",
1339
+ },
1340
+ "&>": {
1341
+ "name": "Redirect both stdout and stderr",
1342
+ "description": "Redirect both stdout and stderr to file (bash shorthand)",
1343
+ "example": "command &> all_output.log",
1344
+ "use_case": "Capture all output in one file (bash 4+ only)",
1345
+ },
1346
+ "&&": {
1347
+ "name": "AND operator",
1348
+ "description": "Execute right command only if left command succeeds (exit code 0)",
1349
+ "example": "mkdir dir && cd dir",
1350
+ "use_case": "Chain dependent commands; second runs only if first succeeds",
1351
+ },
1352
+ "||": {
1353
+ "name": "OR operator",
1354
+ "description": "Execute right command only if left command fails (non-zero exit)",
1355
+ "example": "git pull || echo 'Pull failed'",
1356
+ "use_case": "Provide fallback action when command fails",
1357
+ },
1358
+ ";": {
1359
+ "name": "Command separator",
1360
+ "description": "Execute commands sequentially regardless of exit status",
1361
+ "example": "cd /tmp; ls; cd -",
1362
+ "use_case": "Run multiple commands in sequence, ignoring failures",
1363
+ },
1364
+ "&": {
1365
+ "name": "Background operator",
1366
+ "description": "Run command in background, returning control to shell",
1367
+ "example": "long_running_command &",
1368
+ "use_case": "Start process without waiting for it to complete",
1369
+ },
1370
+ "$()": {
1371
+ "name": "Command substitution",
1372
+ "description": "Execute command and substitute its output in place",
1373
+ "example": "echo \"Today is $(date)\"",
1374
+ "use_case": "Use command output as argument or in string",
1375
+ },
1376
+ "``": {
1377
+ "name": "Command substitution (legacy)",
1378
+ "description": "Legacy syntax for command substitution (prefer $())",
1379
+ "example": "echo \"Today is `date`\"",
1380
+ "use_case": "Same as $() but less readable; avoid in new scripts",
1381
+ },
1382
+ "<": {
1383
+ "name": "Input redirect",
1384
+ "description": "Use file as stdin for command",
1385
+ "example": "sort < unsorted.txt",
1386
+ "use_case": "Feed file content as input to command",
1387
+ },
1388
+ "<<": {
1389
+ "name": "Here document",
1390
+ "description": "Multi-line input until delimiter is encountered",
1391
+ "example": "cat << EOF\\nline 1\\nline 2\\nEOF",
1392
+ "use_case": "Embed multi-line text or create config files in scripts",
1393
+ },
1394
+ "<<<": {
1395
+ "name": "Here string",
1396
+ "description": "Pass string as stdin to command",
1397
+ "example": "grep 'pattern' <<< 'search in this text'",
1398
+ "use_case": "Pass string to command expecting stdin without echo pipe",
1399
+ },
1400
+ "|&": {
1401
+ "name": "Pipe stdout and stderr",
1402
+ "description": "Pipe both stdout and stderr to next command",
1403
+ "example": "command |& tee output.log",
1404
+ "use_case": "Process both output streams together",
1405
+ },
1406
+ }
1407
+
1408
+
1409
+ # =============================================================================
1410
+ # BASH CONCEPTS
1411
+ # =============================================================================
1412
+
1413
+ CONCEPTS: Dict[str, Dict[str, Any]] = {
1414
+ "pipes": {
1415
+ "title": "Pipes and Pipelines",
1416
+ "description": "Pipes connect the output of one command to the input of another, allowing you to chain commands together into powerful data processing pipelines.",
1417
+ "key_points": [
1418
+ "Pipes connect stdout to stdin",
1419
+ "Data flows left to right through the pipeline",
1420
+ "Each command in the pipeline runs in its own process",
1421
+ "Exit status is typically that of the last command",
1422
+ ],
1423
+ "examples": [
1424
+ {"code": "cat file.txt | grep 'pattern' | sort | uniq -c", "explanation": "Read file, filter lines, sort, count unique"},
1425
+ {"code": "ps aux | grep python | awk '{print $2}'", "explanation": "List processes, filter for python, extract PID"},
1426
+ ],
1427
+ },
1428
+ "redirects": {
1429
+ "title": "I/O Redirection",
1430
+ "description": "Redirection allows you to control where command input comes from and where output goes.",
1431
+ "key_points": [
1432
+ "File descriptors: 0=stdin, 1=stdout, 2=stderr",
1433
+ "> overwrites file, >> appends to file",
1434
+ "< reads from file as stdin",
1435
+ "2>&1 redirects stderr to stdout destination",
1436
+ ],
1437
+ "examples": [
1438
+ {"code": "command > output.txt 2>&1", "explanation": "Send both stdout and stderr to output.txt"},
1439
+ {"code": "command 2>/dev/null", "explanation": "Discard error messages"},
1440
+ ],
1441
+ },
1442
+ "exit_codes": {
1443
+ "title": "Exit Codes and Status",
1444
+ "description": "Every command returns an exit status (0-255). By convention, 0 means success and non-zero indicates failure.",
1445
+ "key_points": [
1446
+ "Exit 0 = success, non-zero = failure",
1447
+ "$? contains the exit status of the last command",
1448
+ "&& executes next command only if previous succeeded",
1449
+ "|| executes next command only if previous failed",
1450
+ ],
1451
+ "common_codes": {
1452
+ 0: "Success",
1453
+ 1: "General error",
1454
+ 2: "Misuse of shell builtin",
1455
+ 126: "Command invoked cannot execute",
1456
+ 127: "Command not found",
1457
+ 130: "Terminated by Ctrl+C (128+2)",
1458
+ },
1459
+ },
1460
+ "globbing": {
1461
+ "title": "Glob Patterns (Wildcards)",
1462
+ "description": "Glob patterns allow matching multiple files using wildcards. The shell expands globs before passing arguments to commands.",
1463
+ "key_points": [
1464
+ "* matches any characters (except leading dot)",
1465
+ "? matches exactly one character",
1466
+ "[abc] matches any character in brackets",
1467
+ "[a-z] matches any character in range",
1468
+ "** matches directories recursively (with globstar)",
1469
+ ],
1470
+ "examples": [
1471
+ {"code": "ls *.txt", "explanation": "List all .txt files"},
1472
+ {"code": "rm file?.log", "explanation": "Remove file1.log, file2.log, etc."},
1473
+ ],
1474
+ },
1475
+ "quoting": {
1476
+ "title": "Quoting and Escaping",
1477
+ "description": "Quoting controls how the shell interprets special characters.",
1478
+ "key_points": [
1479
+ "Single quotes: everything is literal (no expansion)",
1480
+ "Double quotes: variables and commands expand, spaces preserved",
1481
+ "Backslash: escape single character",
1482
+ "Always quote variables: \"$var\" not $var",
1483
+ ],
1484
+ "examples": [
1485
+ {"code": "echo '$HOME'", "explanation": "Prints literal $HOME"},
1486
+ {"code": "echo \"$HOME\"", "explanation": "Prints the value of HOME variable"},
1487
+ ],
1488
+ },
1489
+ "variable_expansion": {
1490
+ "title": "Variable and Parameter Expansion",
1491
+ "description": "Variables store values that can be expanded in commands. Bash provides powerful parameter expansion features.",
1492
+ "key_points": [
1493
+ "Set: VAR=value (no spaces around =)",
1494
+ "Use: $VAR or ${VAR}",
1495
+ "Export for child processes: export VAR",
1496
+ "Special variables: $?, $#, $@, $*, $$, $!",
1497
+ ],
1498
+ "expansions": {
1499
+ "${VAR:-default}": "Use default if VAR is unset or null",
1500
+ "${VAR:=default}": "Set and use default if VAR is unset or null",
1501
+ "${#VAR}": "Length of variable value",
1502
+ "${VAR%pattern}": "Remove shortest suffix match",
1503
+ "${VAR##pattern}": "Remove longest prefix match",
1504
+ },
1505
+ },
1506
+ }
1507
+
1508
+
1509
+ # =============================================================================
1510
+ # CATEGORY DESCRIPTIONS
1511
+ # =============================================================================
1512
+
1513
+ CATEGORY_DESCRIPTIONS: Dict[str, str] = {
1514
+ "File System": "Commands for navigating, viewing, creating, and managing files and directories",
1515
+ "Text Processing": "Commands for viewing, searching, filtering, and transforming text content",
1516
+ "Git": "Version control system commands for tracking changes and collaboration",
1517
+ "Package Management": "Package managers for installing, updating, and managing software dependencies",
1518
+ "Process & System": "Commands for monitoring, managing, and controlling running processes",
1519
+ "Networking": "Commands for network operations, file transfers, and remote access",
1520
+ "Permissions": "Commands for managing file ownership and access permissions",
1521
+ "Compression": "Commands for compressing, archiving, and extracting files",
1522
+ "Development": "Development tools for building, testing, and running code",
1523
+ "Shell Builtins": "Built-in shell commands for scripting and interactive use",
1524
+ "Search & Navigation": "Commands for finding files and navigating the filesystem",
1525
+ }
1526
+
1527
+
1528
+ # =============================================================================
1529
+ # HELPER FUNCTIONS
1530
+ # =============================================================================
1531
+
1532
+ def get_command_info(name: str) -> Dict[str, Any] | None:
1533
+ """Get comprehensive command information by name."""
1534
+ return COMMAND_DB.get(name)
1535
+
1536
+
1537
+ def get_operator(symbol: str) -> Dict[str, str] | None:
1538
+ """Get operator information by symbol."""
1539
+ return OPERATORS.get(symbol)
1540
+
1541
+
1542
+ def get_concept(name: str) -> Dict[str, Any] | None:
1543
+ """Get concept explanation by name."""
1544
+ return CONCEPTS.get(name)
1545
+
1546
+
1547
+ def get_flags_for_command(command: str) -> Dict[str, str]:
1548
+ """Get all flags for a command."""
1549
+ cmd = COMMAND_DB.get(command, {})
1550
+ return cmd.get("flags", {})
1551
+
1552
+
1553
+ def get_common_patterns(command: str) -> List[str]:
1554
+ """Get common usage patterns for a command."""
1555
+ cmd = COMMAND_DB.get(command, {})
1556
+ return cmd.get("common_patterns", [])
1557
+
1558
+
1559
+ def search_commands(query: str) -> List[str]:
1560
+ """Search commands by name or description."""
1561
+ query_lower = query.lower()
1562
+ results = []
1563
+ for name, info in COMMAND_DB.items():
1564
+ if query_lower in name.lower():
1565
+ results.append(name)
1566
+ elif query_lower in info.get("description", "").lower():
1567
+ results.append(name)
1568
+ return results
1569
+
1570
+
1571
+ def get_stats() -> Dict[str, int]:
1572
+ """Get statistics about the knowledge base."""
1573
+ total_flags = sum(len(cmd.get("flags", {})) for cmd in COMMAND_DB.values())
1574
+ total_patterns = sum(len(cmd.get("common_patterns", [])) for cmd in COMMAND_DB.values())
1575
+ return {
1576
+ "total_commands": len(COMMAND_DB),
1577
+ "total_operators": len(OPERATORS),
1578
+ "total_concepts": len(CONCEPTS),
1579
+ "total_categories": len(set(CATEGORY_MAPPINGS.keys())),
1580
+ "total_flags": total_flags,
1581
+ "total_patterns": total_patterns,
1582
+ }
1583
+
1584
+
1585
+ if __name__ == "__main__":
1586
+ stats = get_stats()
1587
+ print("Knowledge Base Statistics:")
1588
+ print(f" Commands in COMMAND_DB: {stats['total_commands']}")
1589
+ print(f" Operators: {stats['total_operators']}")
1590
+ print(f" Concepts: {stats['total_concepts']}")
1591
+ print(f" Categories: {stats['total_categories']}")
1592
+ print(f" Total flags documented: {stats['total_flags']}")
1593
+ print(f" Total patterns: {stats['total_patterns']}")