🚀 Auto-deploy: BotVPS atualizado em 28/03/2026 17:56:20

This commit is contained in:
2026-03-28 17:56:20 +00:00
parent 175144310f
commit 823a6ce056
4 changed files with 113 additions and 4 deletions

View File

@@ -2,6 +2,8 @@ import subprocess
import os
import psutil
import time
import re
import json
def run_bash_command(command: str) -> str:
"""Executa um comando bash na VPS e retorna a saída."""
@@ -75,6 +77,64 @@ def get_docker_stats() -> str:
"""Retorna o uso de CPU/RAM de todos os containers ativos via comando docker stats."""
return run_bash_command('docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}"')
# ============================================================
# SISTEMA CRONOS (MEMÓRIA DE LONGO PRAZO)
# ============================================================
MEMORY_ROOT = "/root/Antigravity_Memory"
def cronos_log(arg: str) -> str:
"""
Salva memórias. Formato esperado: topic="assunto", content="texto", folder="current_week"
Também aceita JSON.
"""
try:
# Tenta como JSON primeiro
try:
data = json.loads(arg)
topic = data.get("topic", "geral")
content = data.get("content", "")
folder = data.get("folder", "current_week")
except:
# Parser simples por regex para query="xxx" ou topic="xxx"
topic_m = re.search(r'topic=["\'](.*?)["\']', arg)
content_m = re.search(r'content=["\'](.*?)["\']', arg, re.S)
folder_m = re.search(r'folder=["\'](.*?)["\']', arg)
topic = topic_m.group(1) if topic_m else "geral"
content = content_m.group(1) if content_m else arg # fallback para arg bruto
folder = folder_m.group(1) if folder_m else "current_week"
if not content: return "Erro: Conteúdo vazio."
target_dir = os.path.join(MEMORY_ROOT, folder)
if not os.path.exists(target_dir):
os.makedirs(target_dir, exist_ok=True)
filename = f"{topic.lower().replace(' ', '_')}.md"
filepath = os.path.join(target_dir, filename)
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
entry = f"\n---\n### ENTRY: {timestamp}\n{content}\n"
with open(filepath, "a" if os.path.exists(filepath) else "w") as f:
f.write(entry)
return f"Sucesso: Salvo em Cronos/{folder}/{filename}"
except Exception as e:
return f"Erro ao salvar em Cronos: {e}"
def cronos_query(arg: str) -> str:
"""Busca informações. Formato: query="termo", folder="pasta" """
query_m = re.search(r'query=["\'](.*?)["\']', arg)
folder_m = re.search(r'folder=["\'](.*?)["\']', arg)
query = query_m.group(1) if query_m else arg
folder = folder_m.group(1) if folder_m else "current_week"
target_dir = os.path.join(MEMORY_ROOT, folder)
return run_bash_command(f"grep -rniI '{query}' {target_dir} | head -n 20")
# Mapeamento para o Agente entender quais tools ele possui (será usado no loop ReAct)
AVAILABLE_TOOLS = {
"run_bash_command": {
@@ -92,5 +152,13 @@ AVAILABLE_TOOLS = {
"get_docker_stats": {
"description": "Retorna uma tabela com o consumo de CPU e Memória de cada container.",
"func": get_docker_stats
},
"cronos_log": {
"description": "Salva memórias importantes (assunto, conteúdo, pasta=current_week|knowledge). Use sempre que algo for concluído.",
"func": cronos_log
},
"cronos_query": {
"description": "Busca informações no histórico da Memória Cronos.",
"func": cronos_query
}
}