Smart Rerouting
When a valid shell command receives natural-language-style arguments and fails, Lacy silently catches it and rerouts to the agent. No user-facing hint — just a second chance.
How it works
Layer 2 post-execution detection runs after a shell command exits with a non-zero code (1–127). Both criteria must match for a reroute:
- Error pattern — output contains a known shell error string from
LACY_SHELL_ERROR_PATTERNS - NL signal — the second word is in
LACY_NL_MARKERS(likethe,a,my,this), OR 5+ words with a parse/syntax error
Minimum 2 words required. Only active in Auto mode.
Examples
$kill the process on localhost:3000reroute
No such signal: the → caught, rerouting to AI...
$go ahead and fix the testsreroute
unknown command: ahead → caught, rerouting to AI...
$make sure the tests passreroute
No rule to make target 'sure' → caught, rerouting to AI...
Non-rerouting examples
$kill -9 my-processshell only
Only 2 bare words — below threshold
$echo the quick brown foxshell only
Succeeds — no reroute needed
Implementation
bash
# lib/core/detection.sh
lacy_shell_detect_natural_language "$input" "$output" "$exit_code"
# Returns 0 (NL detected) or 1 (not NL)The function takes the original input, the command output, and the exit code. It checks both the error pattern and NL signal criteria.
Note
Rerouting only triggers on exit codes 1–127. Exit codes ≥ 128 (signals like SIGKILL) are not rerouted — they indicate something more serious.