From d7a2e5fc2e61f0a47431b8e59b88e3f020a4d6ac Mon Sep 17 00:00:00 2001 From: Rui Date: Sun, 17 May 2026 03:29:41 +0200 Subject: [PATCH] feat: integrate static vps identity awareness parser in agent_executor.py --- templates/agent_executor.py | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/templates/agent_executor.py b/templates/agent_executor.py index 1bc21c4..7b42477 100644 --- a/templates/agent_executor.py +++ b/templates/agent_executor.py @@ -152,11 +152,29 @@ class SwarmAgent: def execute(self): self.setup_workspace() - # Identificação de Localização Automática - ips = subprocess.getoutput("hostname -I").split() - vps_ip = next((ip for ip in ips if ip.startswith("10.99.")), ips[0] if ips else "127.0.0.1") - vps_name = subprocess.getoutput("hostname") + # Identificação de Localização Automática via .vps_identity + identity_path = "/home/deploy/.vps_identity" + vps_name = "VPS-DESCONHECIDA" + vps_ip = "127.0.0.1" + vps_role = "Desconhecido" + danger_level = "Desconhecido" + if os.path.exists(identity_path): + try: + with open(identity_path, "r") as f: + identity = json.load(f) + vps_name = identity.get("vps_name", vps_name) + vps_ip = identity.get("ip_vpn", vps_ip) + vps_role = identity.get("role", vps_role) + danger_level = identity.get("danger_level", danger_level) + except Exception as e_id: + print(f" [!] Erro ao ler .vps_identity: {e_id}") + else: + # Fallback dinâmico caso o arquivo não exista + ips = subprocess.getoutput("hostname -I").split() + vps_ip = next((ip for ip in ips if ip.startswith("10.99.")), ips[0] if ips else "127.0.0.1") + vps_name = subprocess.getoutput("hostname") + # Carrega a Doutrina de Agentes doutrina_path = "/home/deploy/instrucoes/global/doutrina_agentes.md" doutrina = "" @@ -165,7 +183,13 @@ class SwarmAgent: doutrina = f.read() # Consciência Situacional Injetada - situational_awareness = f"\n\n[CONSCIÊNCIA SITUACIONAL]: Você está rodando na VPS: {vps_name} (IP: {vps_ip})\n" + situational_awareness = ( + f"\n\n[CONSCIÊNCIA SITUACIONAL]:\n" + f"- Servidor Atual: {vps_name}\n" + f"- IP VPN Local: {vps_ip}\n" + f"- Função da VPS: {vps_role}\n" + f"- Nível de Perigo: {danger_level}\n" + ) system_instruction = doutrina + situational_awareness task = self.data.get('data', {}).get('issue', {}).get('body', 'Corrigir projeto')