@@ -203,24 +203,36 @@ func (p *Parser) Parse(input string) (*Command, error) {
203203 // Check if this is a command-line argument (first argument is the program name)
204204 args := os .Args
205205 if len (args ) > 1 && input == strings .Join (args [1 :], " " ) {
206- // Check if the input looks like a natural language query
207- // Natural language queries typically:
208- // 1. Start with a capital letter (questions, sentences)
209- // 2. Contain multiple words with spaces
210- // 3. End with a question mark (for questions)
211- // 4. Don't contain shell command special characters like |, >, <, etc.
212-
213- // If it looks like a natural language query, treat it as an AI query
214- if isNaturalLanguageQuery (input ) {
215- cmd .Type = CommandTypeAI
206+ // Split the input into words
207+ words := strings .Fields (input )
208+
209+ // Check if it's a single word that exists as an executable in PATH
210+ if len (words ) == 1 {
211+ _ , err := exec .LookPath (words [0 ])
212+ if err == nil && p .config .CommandFirstMode {
213+ // It's a single word that exists as a command and we're in command-first mode
214+ cmd .Type = CommandTypeShell
215+ cmd .Intent = input
216+ return cmd , nil
217+ }
218+ }
219+
220+ // If we're in command-first mode, check if it looks like a natural language query
221+ if p .config .CommandFirstMode {
222+ // If it looks like a natural language query, treat it as an AI query
223+ if IsNaturalLanguageQuery (input ) {
224+ cmd .Type = CommandTypeAI
225+ cmd .Intent = input
226+ return cmd , nil
227+ }
228+
229+ // Otherwise, treat it as a shell command in command-first mode
230+ cmd .Type = CommandTypeShell
216231 cmd .Intent = input
217232 return cmd , nil
218233 }
219234
220- // Otherwise, treat it as a shell command
221- cmd .Type = CommandTypeShell
222- cmd .Intent = input
223- return cmd , nil
235+ // In AI-first mode (default), we treat everything as AI query unless it's a specific exception
224236 }
225237
226238 // Check if this looks like a speed test query
@@ -230,7 +242,7 @@ func (p *Parser) Parse(input string) (*Command, error) {
230242 return cmd , nil
231243 }
232244
233- // Check if this looks like a task that should use agent mode
245+ // In AI-first mode, check if this looks like a task that should use agent mode
234246 if isAgentTask (input ) && p .config .EnableAgentMode {
235247 cmd .Type = CommandTypeAgent
236248 cmd .Intent = input
@@ -243,9 +255,9 @@ func (p *Parser) Parse(input string) (*Command, error) {
243255 return cmd , nil
244256}
245257
246- // isNaturalLanguageQuery determines if a string is likely to be a natural language query
247- // rather than a shell command
248- func isNaturalLanguageQuery (input string ) bool {
258+ // IsNaturalLanguageQuery determines if a string is likely to be a natural language query
259+ // rather than a shell command. This is exported for use in other packages.
260+ func IsNaturalLanguageQuery (input string ) bool {
249261 // Trim the input
250262 input = strings .TrimSpace (input )
251263
@@ -305,6 +317,22 @@ func isNaturalLanguageQuery(input string) bool {
305317 }
306318 }
307319
320+ // Check for common action verbs that are likely part of natural language queries
321+ // but might be confused with shell commands
322+ actionVerbs := []string {"create" , "find" , "list" , "show" , "get" , "make" , "setup" , "install" ,
323+ "configure" , "backup" , "search" , "organize" , "clean" , "delete" , "remove" , "update" , "check" , "analyze" }
324+
325+ if len (words ) > 1 {
326+ firstWord := strings .ToLower (words [0 ])
327+ for _ , verb := range actionVerbs {
328+ if firstWord == verb {
329+ // If it's an action verb followed by at least one more word, it's likely a natural language query
330+ // e.g., "create folder" is a natural language query, not a shell command
331+ return true
332+ }
333+ }
334+ }
335+
308336 // Check if the input is a single word that doesn't exist as a command
309337 // This is a heuristic to prevent treating unknown commands as shell commands
310338 if len (words ) == 1 {
0 commit comments