Skip to content

6.1 Shell Command Pipeline

Glen edited this page Nov 14, 2026 · 2 revisions

Shell Command Pipeline

Relevant source files

The shell command pipeline serves as the primary interactive interface for CadenzaOS users and automated subsystems. It handles reading command-line input, parsing and tokenizing arguments, enforcing policy-based safety checks, evaluating command velocity and system entropy, and dispatching execution to built-in shell functions, filesystem operations, or spawned userland tasks.

Sources: src/kernel/shell.zig:1-155(), src/kernel/config.zig:1-120()


Command Registry and Metadata

The shell relies on a static command registry defined in src/kernel/shell.zig. Each command is represented by the Command struct, which binds a string identifier to a handler function, an associated CommandID from src/kernel/config.zig, and safety requirements such as argument validation flags.


Figure 1: Bridging natural language command names to Command structs and CommandID enumerations.

Sources: src/kernel/shell.zig:115-155(), src/kernel/config.zig:93-123()

Commands are categorized into utility operations (help, keys, clear, echo, history), system administration and runtime metrics (shutdown, reboot, vitals, version, uptime, spawn), and filesystem operations (ls, touch, edit, del, stat, cat, rename, mkdir, cd, mv, df).

Sources: src/kernel/shell.zig:125-155()


Input Parsing and Argument Tokenization

Input lines arriving from the terminal subsystem are processed and tokenized into argument slices ([][]const u8) using a reusable fixed-capacity token buffer (parse_tokens) constrained by conf.MAX_ARGS.

The parsing logic splits raw input strings by whitespace, stripping quotation marks where necessary, and populates the argument array without triggering dynamic heap allocations during command invocation. This design satisfies CadenzaOS's strict bare-metal requirement to avoid unbounded allocations in the interactive shell loop. Temporary allocations are isolated to a fixed-buffer allocator (cmd_fba) backed by cmd_buf.

Sources: src/kernel/shell.zig:75-76(), src/kernel/shell.zig:105-111(), src/kernel/config.zig:85-87()


Execution Pipeline, Policy, and Safety Checks

When a user submits a command line, the shell pipeline executes a sequence of validation, behavioral telemetry tracking, and dispatch stages:


Figure 2: Data flow and execution path through the shell command pipeline.

Sources: src/kernel/shell.zig:63-64(), src/kernel/config.zig:135-151()

Policy-Based Safety Checks

Before executing commands marked with sensitive CommandID values (such as SHUTDOWN, REBOOT, or destructive file deletions), the shell inspects the active SystemPolicy preset (DEV, GAMING, or ADMIN) defined in src/kernel/config.zig. Under strict policies (e.g., ADMIN), additional confirmation prompts via src/kernel/ui/prompt.zig may be interposed before proceeding.

Sources: src/kernel/config.zig:129-152()

Entropy and Velocity Checks

The shell records timing metrics for command execution via last_command_tick and current_command_tick, computing latency and command frequency. These velocity metrics feed into behavioural intelligence subsystems like the Conductor and Composer (src/kernel/conductor.zig) to detect unusual rapid invocation patterns, potential system anomalies, or stress states.

Sources: src/kernel/shell.zig:62-111(), src/kernel/config.zig:129-152()


Spawn and Filesystem Commands

The pipeline handles process creation and persistent storage interactions via dedicated command handlers:

  • spawn: Resolves a named task from the internal task registry (task_registry) or loads embedded application binaries staged at APP_LBA_START, preparing an execution context and handing control over to the scheduler.
  • Filesystem Commands (ls, cd, touch, cat, mkdir, etc.): Interface directly with the global CodaFS instance (g_fs) and working directory tracking variables (g_cwd_lba, g_cwd_blocks) to perform metadata lookups, extent traversal, and block-level I/O.

Sources: src/kernel/shell.zig:45-54(), src/kernel/shell.zig:78-93(), src/kernel/config.zig:36-44()

Clone this wiki locally