DOCUMENTATION / V1.0.0 LTS

Console.rs Code Structure Visual Map

File Organization Overview

src/console.rs (~3,700 lines)
│
├── IMPORTS & CONSTANTS (Lines 1-100)
│   ├── use statements
│   ├── const CMD_BUF_SIZE = 64
│   ├── const HISTORY_SIZE = 8
│   ├── const PENDING_COMMANDS = 4
│   └── const PAGING_POOL_HIGH_USAGE_PERCENT = 90
│
├── STRUCT DEFINITIONS (Lines 101-160)
│   ├── ConsoleState - shell input state
│   ├── WorkingDirectoryState - current working directory
│   └── PendingCommandQueue - command queue
│
├── STATIC STATE VARIABLES (Lines 161-200)
│   ├── CONSOLE: Mutex<ConsoleState>
│   ├── WORKING_DIR: Mutex<WorkingDirectoryState>
│   └── COMMAND_QUEUE: Mutex<PendingCommandQueue>
│
├── KEYBOARD/LINE-EDITING FUNCTIONS (Lines 200-590)
│   ├── on_printable() - handle character input
│   ├── on_backspace() - handle backspace
│   ├── on_enter() - handle command entry
│   ├── on_arrow_up/down() - history navigation
│   ├── on_tab() - tab completion (partial)
│   ├── on_home/end() - cursor movement
│   └── Other line-editing helpers
│
├── EXECUTE_COMMAND FUNCTION (Lines 586-2204) ⭐ MAIN TARGET
│   │
│   ├─→ HELP SECTION (Lines 595-677) [95 lines]
│   │   ├── help command (595-631) [37 lines]
│   │   ├── commands command (633-642) [10 lines]
│   │   └── logs command (643-677) [35 lines]
│   │
│   ├─→ OUTPUT/SYSTEM SECTION (Lines 678-1026) [349 lines]
│   │   ├── outputs (678-749) [72 lines]
│   │   ├── prompt (750-785) [36 lines]
│   │   ├── cpu (786-811) [26 lines]
│   │   ├── memory (812-868) [57 lines] ⚠️ COMPLEX
│   │   ├── selftest (869-889) [21 lines]
│   │   ├── about (890-899) [10 lines]
│   │   ├── sysinfo (900-914) [15 lines]
│   │   ├── banner (915-924) [10 lines]
│   │   ├── version (925-934) [10 lines]
│   │   ├── info (935-1005) [71 lines]
│   │   └── bootlog (1006-1026) [21 lines]
│   │
│   ├─→ PAGING/DIAGNOSTICS (Lines 1027-1514) [488 lines]
│   │   ├── paging (1027-1404) [378 lines] ⚠️⚠️ VERY LARGE
│   │   ├── diagnose (1405-1425) [21 lines]
│   │   ├── ticks (1426-1435) [10 lines]
│   │   ├── uptime (1436-1448) [13 lines]
│   │   ├── status (1449-1473) [25 lines]
│   │   └── health (1474-1514) [41 lines]
│   │
│   ├─→ SYSTEM MONITORING (Lines 1515-1723) [209 lines]
│   │   ├── net (1515-1535) [21 lines]
│   │   ├── proc (1536-1556) [21 lines]
│   │   ├── resources (1557-1577) [21 lines]
│   │   ├── top (1578-1598) [21 lines]
│   │   ├── tasks/ps (1599-1647) [49 lines]
│   │   ├── faults (1648-1668) [21 lines]
│   │   └── keyboard (1669-1723) [55 lines]
│   │
│   ├─→ SHELL DISPLAY COMMANDS (Lines 1724-1793) [70 lines]
│   │   ├── uname (1724-1742) [19 lines]
│   │   ├── history (1743-1763) [21 lines]
│   │   ├── aliases (1764-1773) [10 lines]
│   │   ├── clear (1774-1783) [10 lines]
│   │   └── echo (1784-1793) [10 lines]
│   │
│   ├─→ STORAGE/FILESYSTEM (Lines 1794-2125) [332 lines]
│   │   ├── cd (1794-1825) [32 lines]
│   │   ├── wai (1826-1841) [16 lines]
│   │   ├── ls (1842-1872) [31 lines]
│   │   ├── cat (1873-1895) [23 lines]
│   │   ├── mount (1896-1913) [18 lines]
│   │   ├── stat (1914-1949) [36 lines]
│   │   ├── tree (1950-1976) [27 lines]
│   │   ├── mkdir (1977-1999) [23 lines]
│   │   ├── touch (2000-2022) [23 lines]
│   │   ├── write (2023-2052) [30 lines]
│   │   ├── rm (2053-2102) [50 lines]
│   │   └── rmdir (2103-2125) [23 lines]
│   │
│   ├─→ POWER COMMANDS (Lines 2126-2203) [78 lines]
│   │   ├── power (2126-2160) [35 lines]
│   │   ├── reboot (2161-2182) [22 lines]
│   │   └── shutdown (2183-2203) [21 lines]
│   │
│   └─→ DEFAULT (Line 2204)
│       └── unknown command error
│
├── HELPER DATA (Lines 2205-2280)
│   └── COMMANDS: [&[u8]; 48] - command name list for help
│
├── HELP/REFERENCE FUNCTIONS (Lines 2280-2510)
│   ├── print_help_general() - overview
│   ├── print_help_tips() - usage tips
│   ├── print_help_shell() - shell commands help
│   ├── print_help_system() - system commands help
│   ├── print_help_commands() - list all commands
│   ├── print_bootlog_text() - format boot log
│   ├── print_bootlog_json() - format boot log as JSON
│   └── print_aliases() - show alias mappings
│
├── CPU INFORMATION FUNCTIONS (Lines 2850-2920)
│   ├── print_cpu_summary() - compact CPU info
│   ├── print_cpu_features() - CPU feature flags
│   └── print_cpu_json() - CPU info as JSON
│
├── MEMORY/HEAP FUNCTIONS (Lines 2945-2960)
│   ├── print_memory_summary() - heap usage
│   └── print_memory_json() - heap info as JSON
│
├── SELF-TEST FUNCTIONS (Lines 2965-3020)
│   ├── print_selftest_text() - test results
│   └── print_selftest_json() - test results as JSON
│
├── FAULT/STATUS FUNCTIONS (Lines 2720-2740)
│   ├── print_faults_text() - page fault info
│   └── print_faults_json() - page fault info as JSON
│
├── SYSTEM MONITORING OUTPUT (Lines 2750-2890)
│   ├── print_net_text/json() - network info
│   ├── print_proc_text/json() - process info
│   ├── print_resources_text/json() - resource usage
│   └── print_top_text/json() - live operations summary
│
├── SYSTEM INFO FUNCTIONS (Lines 3078-3135)
│   ├── print_about() - system identity
│   ├── print_banner() - decorative banner
│   ├── print_sysinfo_text() - system snapshot
│   └── print_sysinfo_json() - system snapshot as JSON
│
├── DIAGNOSTICS FUNCTIONS (Lines 3140-3310)
│   ├── print_diagnose(verbose) - comprehensive health check
│   └── print_diagnose_json() - health check as JSON
│
├── HEALTH STATE FUNCTIONS (Lines 3345-3435)
│   ├── HealthState struct - health metrics
│   ├── collect_health_state() - gather health data
│   ├── print_status_json/text() - status summary
│   └── print_health_*() - health status variants
│
├── HISTORY/LISTING FUNCTIONS (Lines 3520-3620)
│   ├── print_history() - command history
│   ├── print_history_json() - history as JSON
│   ├── print_tree_recursive() - recursive tree printing
│   └── print_wai_tree_to_cwd() - where am I tree
│
└── UTILITY FUNCTIONS (Lines 3437-3686)
    ├── parse_usize_arg() - parse hex/decimal numbers
    ├── current_working_dir() - get cwd
    ├── set_current_working_dir() - change cwd
    ├── resolve_shell_path() - resolve relative paths
    ├── resolve_path_from_cwd() - path resolution helper
    ├── trim_spaces() - whitespace removal
    ├── copy_trimmed() - copy and trim
    ├── ascii_bytes_to_str() - byte to string conversion
    ├── eq_ignore_ascii_case() - case-insensitive comparison
    ├── starts_with_ignore_ascii_case() - prefix matching
    ├── nth_recent_index() - history indexing
    ├── redraw_input() - terminal redraw
    ├── redraw_line() - terminal line redraw
    └── redraw_from_state() - terminal state redraw

Extraction Strategy Visualization

CURRENT STATE:
console.rs (3,700 lines)
  ├── Line editing & keyboard handling
  ├── Command execution dispatcher ← MAIN EXTRACTION TARGET
  ├── 62+ helper/print functions
  ├── Working directory state
  ├── Shell history state
  └── Command queue state

TARGET STATE:
console.rs (500 lines)
  ├── Line editing & keyboard handling ✓ KEEP
  ├── Command dispatcher
  │   └── Router to commands/mod.rs ✓ NEW
  └── State management ✓ KEEP

commands/mod.rs (NEW)
  ├── pub fn dispatch_command()
  └── mod help;
  └── mod storage;
  └── mod system;
  └── mod memory;

commands/help.rs (95 lines) ← EXTRACTED
  ├── help command
  ├── commands command
  ├── logs command
  └── print_help_* functions

commands/storage.rs (250 lines) ← EXTRACTED
  ├── cd command
  ├── ls command
  ├── cat command
  ├── mount command
  ├── stat command
  ├── tree command
  ├── mkdir command
  ├── touch command
  ├── write command
  ├── rm command
  ├── rmdir command
  ├── wai command
  └── print_tree_recursive()

commands/system.rs (1,700 lines) ← EXTRACTED
  ├── outputs command
  ├── prompt command
  ├── cpu command
  ├── selftest command
  ├── about command
  ├── sysinfo command
  ├── banner command
  ├── version command
  ├── info command
  ├── bootlog command
  ├── power command
  ├── reboot command
  ├── shutdown command
  ├── uname command
  ├── history command
  ├── aliases command
  ├── clear command
  ├── echo command
  ├── net command
  ├── proc command
  ├── resources command
  ├── top command
  ├── tasks/ps command
  ├── faults command
  ├── keyboard command
  └── 40+ print_* functions

commands/memory.rs (680 lines) ← EXTRACTED
  ├── memory command
  ├── paging command (378 lines) ← CONSIDER SPLIT
  ├── diagnose command
  ├── ticks command
  ├── uptime command
  ├── status command
  ├── health command
  ├── HealthState struct
  ├── collect_health_state()
  └── print_* functions

OR optionally:

commands/memory.rs (100 lines)
  └── memory command only

commands/paging.rs (380 lines)
  └── paging command + helpers

commands/health.rs (100 lines)
  ├── status command
  ├── health command
  ├── diagnose command
  └── health-related helpers

Command Distribution by Category

HELP (3 commands)
├── help
├── commands
└── logs

SYSTEM INFO (10 commands)
├── about
├── sysinfo
├── banner
├── version
├── info
├── bootlog
├── uname
├── cpu
├── history
└── aliases

OUTPUT CONTROL (2 commands)
├── outputs
└── prompt

SHELL UTILITIES (3 commands)
├── clear
├── echo
└── wai

FILESYSTEM (11 commands)
├── cd
├── ls
├── cat
├── mount
├── stat
├── tree
├── mkdir
├── touch
├── write
├── rm
└── rmdir

MEMORY & PAGING (2 commands)
├── memory
└── paging

SYSTEM MONITORING (6 commands)
├── net
├── proc
├── resources
├── top
├── tasks (= ps)
└── faults

SYSTEM STATUS (5 commands)
├── ticks
├── uptime
├── status
├── health
└── keyboard

DIAGNOSTICS (1 command)
└── diagnose

POWER MANAGEMENT (3 commands)
├── power
├── reboot
└── shutdown

KERNEL SELF-TEST (1 command)
└── selftest

═══════════════════════════
TOTAL: 49 commands

Code Density Analysis

Lines per Command (average):

execute_command dispatcher:
  - Total: 2,204 lines (including command bodies)
  - 49 commands
  - Average: 45 lines per command

But distribution is highly skewed:

Large (>100 lines):
  - paging (378 lines) ⚠️ OUTLIER
  
Medium (30-99 lines):
  - info (71 lines)
  - keyboard (55 lines)
  - rm (50 lines)
  - tasks (49 lines)
  - bootlog (21 + helpers)
  
Small (<30 lines):
  - Most other commands

Helper Functions:
  - 62+ helper functions
  - Most are <50 lines
  - Some are 100+ lines (diagnose functions)

Dependency Complexity Graph

                    MEMORY.RS
                    (HIGH)
                      ↑
         ┌────────────┼────────────┐
         │            │            │
      PAGING      DIAGNOSE    HEALTH
      (378 L)     (100 L)     (100 L)
         │            │            │
         ↓            ↓            ↓
      crate::paging  ALL MODULES  PAGING+MEMORY
         │
    SYSTEM.RS ←──────────────┐
    (MEDIUM)                 │
         │                   │
    20+ commands          Many print_*
    40+ helpers           functions
         │
    ┌────┼────┬──────────────┐
    │    │    │              │
  CPU   INFO  NET  PROC  RESOURCES
  BOOT  TASKS TOP  FAULTS

    STORAGE.RS ←─────────────┐
    (LOW)                    │
        │                    │
    11 commands         FS operations
    Isolated            Path resolution
        │
    ┌───┴───────────────────┐
    │                       │
   FS                    PATHING
 COMMANDS             RESOLUTION

    HELP.RS
    (LOWEST)
        │
    3 commands
    Isolated

PHASE 1: FOUNDATION (1-2 hours)
├── Extract help.rs (95 lines) ✓ Low risk
│   └── Dependencies: serial_println only
│
└── Extract storage.rs (250 lines) ✓ Low risk
    └── Dependencies: fs, pathing, isolated

PHASE 2: SYSTEM (3-4 hours)
└── Extract system.rs (1,700 lines) ✓ Medium risk
    └── Dependencies: many crates but all read-only

PHASE 3: COMPLEX CORE (3-4 hours)
└── Extract memory.rs (680 lines) ⚠️ HIGH RISK
    └── Option A: Single module
        └── Dependencies: paging (large), memory, interrupts
    
    └── Option B: Split into 3:
        ├── memory_commands.rs (90 lines) ✓
        ├── paging_commands.rs (380 lines) ⚠️
        └── health_commands.rs (100 lines) ✓

PHASE 4: INTEGRATION (1-2 hours)
├── Create commands/mod.rs dispatcher
├── Update console.rs dispatcher call
├── Testing & validation
└── Cleanup & documentation

Total Estimated Time: 8-13 hours (depending on split strategy)


This visual map helps understand:

  1. ✅ What to extract (execute_command + helpers)
  2. ✅ What to keep (line editing + state)
  3. ✅ Extraction order (help → storage → system → memory)
  4. ✅ Risk levels (low → high)
  5. ✅ Complexity distribution (paging is the outlier)