Spaces:
Sleeping
Sleeping
| import os | |
| from ast_validator import validate_ast | |
| from sandbox_runner import sandbox_test | |
| from gated_review import gate_reject | |
| from patch_manager import prepare_patch, apply_patch | |
| PENDING_PATCH = None | |
| PENDING_TARGET = None | |
| def divine_mutation(new_code, target_file): | |
| global PENDING_PATCH, PENDING_TARGET | |
| # Vérification AST | |
| ast_ok, ast_err = validate_ast(new_code) | |
| if not ast_ok: | |
| return f"[❌ AST ERROR]\n{ast_err}" | |
| # Sandbox | |
| sandbox_ok, sandbox_err = sandbox_test(new_code) | |
| if not sandbox_ok: | |
| return f"[❌ SANDBOX FAILURE]\n{sandbox_err}" | |
| # Rejection Gate | |
| gate_ok, gate_reason = gate_reject(ast_ok, sandbox_ok) | |
| if not gate_ok: | |
| return f"[❌ MUTATION BLOQUÉE]\n{gate_reason}" | |
| # Préparer patch | |
| PENDING_PATCH = prepare_patch(new_code) | |
| PENDING_TARGET = target_file | |
| return "[✅ PATCH PRÊT]\nEnvoie 'VALIDER' pour appliquer ou 'ANNULER' pour rejeter." | |
| def apply_pending(): | |
| global PENDING_PATCH, PENDING_TARGET | |
| if PENDING_PATCH and PENDING_TARGET: | |
| apply_patch(PENDING_TARGET, PENDING_PATCH) | |
| PENDING_PATCH = None | |
| PENDING_TARGET = None | |
| return "[✔️ PATCH APPLIQUÉ]" | |
| return "Aucun patch en attente." | |
| def cancel_pending(): | |
| global PENDING_PATCH, PENDING_TARGET | |
| PENDING_PATCH = None | |
| PENDING_TARGET = None | |
| return "[❌ PATCH ANNULÉ]" |