Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.mirage.strukto.ai/llms.txt

Use this file to discover all available pages before exploring further.

The Shell is the wiring inside Mirage’s Arm, between agents, Eyes, and Hands. When an agent types cat /s3/*.csv | grep error, the Shell figures out which paths the Eyes need to look at, which Hands to use, and in what order, turning a sentence into coordinated execution. Under the hood, Mirage includes a shell execution layer that parses and runs commands using tree-sitter-bash. It handles variable expansion, control flow, pipes, and dispatches to registered command handlers.

Flow

  1. Parse - tree-sitter-bash produces an AST from the input string
  2. Walk - the executor walks AST nodes, routing each to the appropriate handler
  3. Expand - variables ($VAR, ${VAR:-default}), command substitution ($(cmd)), and arithmetic ($((expr))) are expanded
  4. Resolve - paths become PathSpec, globs are expanded
  5. Dispatch - the command registry finds the handler and executes it

Two-Layer Design

Shell layer

Handles anything that requires session state or control flow:
ResponsibilityExamples
Variable expansion$FOO, ${FOO:-default}
Path resolution./file/mirage/data/file
Glob expansion*.csva.csv b.csv
Control flow&&, `, ;, , &`
Shell builtinscd, export, echo, test

Command layer

Handles stateless data transformation:
ResponsibilityExamples
File processingcat, head, grep
Format conversionparquet → text
Data searchfind, grep -r
Commands receive fully resolved arguments - they have no concept of variables, globs, or sessions.

Shell Features

Pipes & Redirection

FeatureExample
Pipecmd1 | cmd2
Stderr pipecmd |& cmd2
Redirect stdoutcmd > file, cmd >> file
Redirect stderrcmd 2> file, cmd 2>&1
Redirect bothcmd &> file
Stdin from filecmd < file
Heredoccmd <<EOF
Herestringcmd <<< "text"
Process substitutioncmd <(other_cmd)

Control Flow

FeatureExample
AND / ORcmd1 && cmd2, cmd1 || cmd2
Sequentialcmd1 ; cmd2
If/elif/elseif cmd; then ...; elif ...; else ...; fi
For loopfor x in a b c; do ...; done
While / Untilwhile cmd; do ...; done
Casecase $x in pat) ...;; esac
Subshell(cmd1; cmd2)
Group{ cmd1; cmd2; }
Backgroundcmd &
Negate! cmd

Variable Expansion

FeatureExample
Simple$VAR, ${VAR}
Default value${VAR:-default}
Special vars$?, $#, $@, $*, $0, $1..$9
Command substitution$(cmd)
Arithmetic$((a + b))

Functions

greet() {
    local prefix=">>>"
    echo "$prefix $1"
}
greet Alice
Functions support local variables, positional parameters ($1, $@), shift, return, and a per-call call stack.

Builtins

BuiltinDescription
cdChange working directory
pwdPrint working directory
exportSet environment variable
unsetRemove environment variable
printenvPrint environment
echoPrint text
printfFormatted output
test / [ / [[Conditional expressions
readRead line from stdin into variable
localDeclare function-scoped variable
setSet positional parameters
shiftRemove first positional parameter
source / .Execute script in current session
evalEvaluate string as command
returnReturn from function
break / continueLoop control
true / falseExit with 0 / 1
sleepSleep for N seconds
pythonExecute Python code
xargsBuild and execute commands from stdin
timeoutRun command with time limit