From f9def3e3895d833c32e76f79ab6395946d2e4050 Mon Sep 17 00:00:00 2001 From: opencode Date: Mon, 23 Mar 2026 19:12:42 +0100 Subject: [PATCH] Execute: check comandi shell PRIMA di list_patterns (ls, git, cat, etc.) --- ollama_agent.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/ollama_agent.py b/ollama_agent.py index c91f6e4..d42c0f5 100644 --- a/ollama_agent.py +++ b/ollama_agent.py @@ -341,6 +341,14 @@ For other questions, just answer normally without tools.""" path_match = re.search(r'([/\w.-]+\.\w+)', text, re.IGNORECASE) file_path = path_match.group(1) if path_match else None + # Execute command patterns - check FIRST for shell commands with flags + # Shell commands like "ls -lha", "git status" should use execute + if ('ls' in text_lower or 'git' in text_lower or 'cat' in text_lower or + 'grep' in text_lower or 'find' in text_lower or 'pwd' in text_lower or + 'cd ' in text_lower or 'mkdir' in text_lower or 'rm ' in text_lower or + 'cp ' in text_lower or 'mv ' in text_lower or 'chmod' in text_lower) and ' ' in text: + return ToolCall(id='intent', name='execute', arguments={'command': text.strip()}) + # System info patterns (more comprehensive) system_patterns = [ 'sistema operativo', 'so sto', 'che os', 'che sistema', 'che so', @@ -406,15 +414,6 @@ For other questions, just answer normally without tools.""" return ToolCall(id='intent', name='write_file', arguments={'path': file_path, 'content': content}) - # Execute command patterns - check FIRST for shell commands - # Shell commands typically have spaces and flags like -, -- - if 'ls' in text_lower and ('-' in text or len(text.split()) > 1): - # Looks like a shell command with args - cmd = text_lower.split()[0] if text_lower.split() else text_lower - args = ' '.join(text.split()[1:]) if len(text.split()) > 1 else '' - full_cmd = f"{cmd} {args}".strip() if args else cmd - return ToolCall(id='intent', name='execute', arguments={'command': full_cmd}) - exec_patterns = [ 'esegui', 'eseguire', 'run', 'run command', 'lanciare', 'avvia', 'comando', 'terminale', 'bash', 'shell'