diff --git a/tools.py b/tools.py index e5a223a..75f34f0 100644 --- a/tools.py +++ b/tools.py @@ -14,13 +14,14 @@ def run_bash_command(command: str) -> str: text=True, timeout=120 # Aumentado para comandos mais pesados ) + output = result.stdout.strip() error = result.stderr.strip() if result.returncode != 0: - return f"ERRO ({result.returncode}):\n{error}" + return f"ERRO ({result.returncode}): {error if error else 'Nada no stderr'}" - return output if output else "Comando executado com sucesso (sem saída)." + return output if output else "Sucesso (vazio)" except subprocess.TimeoutExpired: return "ERRO: O comando demorou muito e foi cancelado (timeout)." except Exception as e: @@ -44,9 +45,13 @@ def get_system_health() -> str: def read_vps_file(filepath: str) -> str: """Lê um arquivo do sistema de arquivos da VPS através do mapeamento /host_root.""" host_path = f"/host_root{filepath}" if not filepath.startswith("/host_root") else filepath + # Se ainda assim não começar com /host_root e não for absoluto para o container, tentamos prefixar + if not host_path.startswith("/host_root") and filepath.startswith("/"): + host_path = "/host_root" + filepath + try: if not os.path.exists(host_path): - return f"Erro: Arquivo {filepath} não encontrado no host." + return f"Erro: Arquivo {filepath} não encontrado no host (Caminho tentado: {host_path})." with open(host_path, 'r') as f: return f.read(2000) # Limite para não estourar o contexto except Exception as e: