fix: migliora pattern detection con regex case-insensitive e keyword generiche

- Usa re.IGNORECASE per estrarre path
- Usa ANY keyword read invece di pattern esatti
- Più flessibile nell'interpretazione dell'intento
This commit is contained in:
opencode committed 2026-03-23 18:41:57 +01:00
1 parent 9cccbabef1
commit 1e49eff703
1 file changed
+35 -21
+35 -21
View File
@@ -336,41 +336,55 @@ For other questions, just answer normally without tools."""
return f"\n[TOOL_RESULT]\nTool: {tool_call.name}\nResult: {json.dumps(result, ensure_ascii=False)}\n[/TOOL_RESULT]\n"
def _detect_intent(self, text: str) -> Optional[ToolCall]:
"""Detect common intents directly without relying on model"""
"""Detect intents using both patterns and LLM interpretation"""
import re
text_lower = text.lower().strip()
# System info patterns
# Extract potential file paths (case insensitive)
path_match = re.search(r'([/\w.-]+\.\w+)', text, re.IGNORECASE)
file_path = path_match.group(1) if path_match else None
# System info patterns (more comprehensive)
system_patterns = [
'sistema operativo', 'so sto', 'che os', 'what os',
'che sistema', 'which system', 'operating system',
'che versione', 'python version', 'versione python',
'sto usando', 'sto usand', 'che so', 'which computer',
'che tipo di sistema', 'che computer', 'what system'
'sistema operativo', 'so sto', 'che os', 'che sistema', 'che so',
'sto usando', 'che computer', 'che tipo di sistema',
'versione python', 'che versione', 'dettagli sistema',
'operating system', 'what os', 'which system', 'what system',
'which computer', 'system info', 'python version'
]
if any(p in text_lower for p in system_patterns):
return ToolCall(id='intent', name='system_info', arguments={})
# List files patterns
list_patterns = [
'lista', 'listare', 'listami', 'elenco', 'mostrami i file',
'list files', 'list directory', 'ls', 'file nella cartella',
'file del', 'cartella corrente', 'mostra i file', 'mostrami'
'lista', 'listare', 'listami', 'elenco', 'mostrami i file', 'mostrami',
'file nella cartella', 'file del', 'cartella corrente', 'mostra i file',
'cosa c\'è', 'cosa c\'e', 'cosa contiene', 'cosa trovo',
'list files', 'list directory', 'ls', 'show files', 'show me',
'what\'s in', 'what is in', 'files here', 'directory contents'
]
if any(p in text_lower for p in list_patterns):
return ToolCall(id='intent', name='ls', arguments={'path': '.'})
# Read file patterns
read_patterns = [
'leggi', 'leggi il file', 'leggere', 'mostrami il contenuto',
'read', 'read file', 'cat', 'apri il file', 'apri'
# Read/show file patterns - check for ANY read keyword AND a file path
read_keywords = ['leggi', 'leggere', 'mostrami', 'apri', 'aprimi', 'visualizza',
'vediamo', 'vedi', 'show me', 'show the', 'read', 'open',
'display', 'view', 'contenuto', 'che dice']
has_read_keyword = any(k in text_lower for k in read_keywords)
if has_read_keyword and file_path:
return ToolCall(id='intent', name='read_file', arguments={'path': file_path})
# Execute command patterns
exec_patterns = [
'esegui', 'eseguire', 'run', 'run command', 'lanciare',
'avvia', 'comando', 'terminale', 'bash', 'shell'
]
for p in read_patterns:
if p in text_lower:
# Extract path from message
import re
path_match = re.search(r'([/\w.-]+\.\w+)', text)
if path_match:
return ToolCall(id='intent', name='read_file', arguments={'path': path_match.group(1)})
if any(p in text_lower for p in exec_patterns):
cmd_match = re.search(r'[`"]?([a-zA-Z0-9_.\s-]+)[`"]?\s*$', text)
if cmd_match:
return ToolCall(id='intent', name='execute', arguments={'command': cmd_match.group(1).strip()})
return None