How Detection Works

Every keystroke in Auto mode passes through a single function: lacy_shell_classify_input(). It returns shell, agent, or neutral. All routing and visual feedback flows from this one source of truth.

The six-rule cascade

Rules are evaluated in order. The first match wins.

#ConditionRouteExample
1First word is an agent wordAgentwhat files are here
2First word is a shell reserved wordAgentdo we have auth?
3First word is a valid commandShellgit status
4Single word, not a commandShellcd.. (typo)
5Multiple words, first not a commandAgentfix the bug
6Valid command fails with NL-style argsShell → Agentkill the process on :3000

Agent words (Rule 1)

About 150 common conversational words that trigger agent routing regardless of whether they're valid shell commands. These are defined in LACY_AGENT_WORDS inlib/core/constants.sh.

Examples: what, why, how, fix, explain,help, show, list, find, yes, no,thanks, perfect, can, could, should,would, is, are, does.

Note

Agent words match even as single-word inputs. Typing thanks alone routes to agent.

Shell reserved words (Rule 2)

Shell reserved words (do, done, then, else,elif, fi, in, select, etc.) passcommand -v but are never valid as the first token of a standalone invocation.

When a user types do we have X or in the codebase where is auth?, that's natural language, not a shell command.

Post-execution reroute (Rule 6)

When a valid command receives natural-language-style arguments and fails (exit code 1–127), Lacy analyzes the error output. If it matches a known error pattern AND the input has NL markers, the command silently rerouts to the agent.

$kill the process on localhost:3000reroute
No such signal: the → caught, rerouting to AI...
$make sure the tests passreroute
No rule to make target 'sure' → caught, rerouting to AI...

Both criteria must match for reroute: an error pattern from LACY_SHELL_ERROR_PATTERNSAND an NL signal (second word in LACY_NL_MARKERS, or 5+ words with a parse/syntax error).

Only active in Auto mode. The reroute is silent — no user-facing hint.

Mode-aware behavior

The cascade only applies in Auto mode. In Shell mode, everything routes to shell. In Agent mode, everything routes to agent. The visual indicator always reflects the current routing decision.

Implementation

bash
# Single source of truth: lib/core/detection.sh
lacy_shell_classify_input "$input"
# Returns: "shell" | "agent" | "neutral"

All consumers — the real-time indicator, execute routing, and first-word syntax highlighting — call this single function. Never create parallel detection logic.