feat: implement JIT dynamic Doutrina loading from Gitea REST API
This commit is contained in:
@@ -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_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")
|
vps_name = subprocess.getoutput("hostname")
|
||||||
|
|
||||||
# Carrega a Doutrina de Agentes
|
# Carrega a Doutrina de Agentes de forma dinâmica e em tempo real do Gitea (VPS 3)
|
||||||
doutrina_path = "/home/deploy/instrucoes/global/doutrina_agentes.md"
|
|
||||||
doutrina = ""
|
doutrina = ""
|
||||||
if os.path.exists(doutrina_path):
|
auth_str = 'ruicesar:h$tg@g5aga$ra1E3$C-yHW$-BA@DF2@Grfa!3#'
|
||||||
with open(doutrina_path, "r") as f:
|
base64_auth = base64.b64encode(auth_str.encode('ascii')).decode('ascii')
|
||||||
doutrina = f.read()
|
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
|
# Consciência Situacional Injetada
|
||||||
situational_awareness = (
|
situational_awareness = (
|
||||||
|
|||||||
Reference in New Issue
Block a user