Tsitsi19 commited on
Commit
6b26721
·
verified ·
1 Parent(s): 036401c

Create divinity_engine.py

Browse files
Files changed (1) hide show
  1. divinity_engine.py +53 -0
divinity_engine.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import ast
3
+ import subprocess
4
+ from ast_validator import validate_ast
5
+ from sandbox_runner import sandbox_test
6
+ from gated_review import gate_reject
7
+ from patch_manager import prepare_patch, apply_patch
8
+
9
+ PENDING_PATCH = None # Stocke un patch en attente de validation humaine
10
+ PENDING_TARGET = None # Le fichier visé
11
+
12
+ def divine_mutation(new_code, target_file):
13
+ global PENDING_PATCH, PENDING_TARGET
14
+
15
+ # 1 — Vérification AST
16
+ ast_ok, ast_err = validate_ast(new_code)
17
+ if not ast_ok:
18
+ return f"[❌ AST ERROR]\n{ast_err}"
19
+
20
+ # 2 — Shadow Testing
21
+ sandbox_ok, sandbox_err = sandbox_test(new_code)
22
+ if not sandbox_ok:
23
+ return f"[❌ SANDBOX FAILURE]\n{sandbox_err}"
24
+
25
+ # 3 — Rejection Gate
26
+ gate_ok, gate_reason = gate_reject(ast_ok, sandbox_ok)
27
+ if not gate_ok:
28
+ return f"[❌ MUTATION BLOQUÉE]\n{gate_reason}"
29
+
30
+ # Si tout passe → on prépare le patch mais on ne l'applique PAS
31
+ PENDING_PATCH = prepare_patch(new_code)
32
+ PENDING_TARGET = target_file
33
+
34
+ return (
35
+ "[✅ PATCH PRÊT]\n"
36
+ "La mutation a réussi toutes les vérifications.\n"
37
+ "Envoie 'VALIDER' pour appliquer, ou 'ANNULER' pour rejeter."
38
+ )
39
+
40
+ def apply_pending():
41
+ global PENDING_PATCH, PENDING_TARGET
42
+ if PENDING_PATCH and PENDING_TARGET:
43
+ result = apply_patch(PENDING_TARGET, PENDING_PATCH)
44
+ PENDING_PATCH = None
45
+ PENDING_TARGET = None
46
+ return f"[✔️ PATCH APPLIQUÉ]\nLe fichier {PENDING_TARGET} a été mis à jour."
47
+ return "Aucun patch en attente."
48
+
49
+ def cancel_pending():
50
+ global PENDING_PATCH, PENDING_TARGET
51
+ PENDING_PATCH = None
52
+ PENDING_TARGET = None
53
+ return "[❌ PATCH ANNULÉ]"