feat: integrate static vps identity awareness parser in agent_executor.py

This commit is contained in:
Rui
2026-05-17 03:29:41 +02:00
parent 8d6db6edbb
commit d7a2e5fc2e
+29 -5
View File
@@ -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')