From 6a7f4e23951e4af380ecb4f61e7ade35ae090404 Mon Sep 17 00:00:00 2001 From: Rui Date: Sun, 17 May 2026 08:57:37 +0200 Subject: [PATCH] feat: implement JIT dynamic Doutrina loading from Gitea REST API --- templates/agent_executor.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/templates/agent_executor.py b/templates/agent_executor.py index 7b42477..7a02325 100644 --- a/templates/agent_executor.py +++ b/templates/agent_executor.py @@ -175,12 +175,32 @@ class SwarmAgent: 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" + # Carrega a Doutrina de Agentes de forma dinâmica e em tempo real do Gitea (VPS 3) doutrina = "" - if os.path.exists(doutrina_path): - with open(doutrina_path, "r") as f: - doutrina = f.read() + auth_str = 'ruicesar:h$tg@g5aga$ra1E3$C-yHW$-BA@DF2@Grfa!3#' + base64_auth = base64.b64encode(auth_str.encode('ascii')).decode('ascii') + url = "http://10.99.0.3:3000/api/v1/repos/ruicesar/instrucoes_gerais/contents/global/doutrina_agentes.md" + + req = urllib.request.Request(url, method='GET') + req.add_header('Authorization', f'Basic {base64_auth}') + + try: + with urllib.request.urlopen(req) as response: + if response.status == 200: + res_data = json.loads(response.read().decode('utf-8')) + encoded_content = res_data.get('content', '') + # Gitea returns content in base64, usually with newlines + doutrina = base64.b64decode(encoded_content.replace('\n', '')).decode('utf-8') + print(" [✓] Doutrina carregada dinamicamente via API Gitea (JIT).") + except Exception as e: + print(f" [!] Falha ao carregar Doutrina via API Gitea, tentando ler do backup local... {e}") + # Fallback seguro para o backup local caso o Gitea esteja fora do ar + for fallback_path in ["/home/deploy/stack/instrucoes/global/doutrina_agentes.md", "/home/deploy/instrucoes/global/doutrina_agentes.md"]: + if os.path.exists(fallback_path): + with open(fallback_path, "r") as f: + doutrina = f.read() + print(f" [✓] Doutrina carregada do backup local: {fallback_path}") + break # Consciência Situacional Injetada situational_awareness = (