Tsitsi19 commited on
Commit
d49fca3
·
verified ·
1 Parent(s): 1c0b5e6

Create divinity_engine.py

Browse files
Files changed (1) hide show
  1. divinity_engine.py +47 -0
divinity_engine.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from ast_validator import validate_ast
3
+ from sandbox_runner import sandbox_test
4
+ from gated_review import gate_reject
5
+ from patch_manager import prepare_patch, apply_patch
6
+
7
+ PENDING_PATCH = None
8
+ PENDING_TARGET = None
9
+
10
+ def divine_mutation(new_code, target_file):
11
+ global PENDING_PATCH, PENDING_TARGET
12
+
13
+ # Vérification AST
14
+ ast_ok, ast_err = validate_ast(new_code)
15
+ if not ast_ok:
16
+ return f"[❌ AST ERROR]\n{ast_err}"
17
+
18
+ # Sandbox
19
+ sandbox_ok, sandbox_err = sandbox_test(new_code)
20
+ if not sandbox_ok:
21
+ return f"[❌ SANDBOX FAILURE]\n{sandbox_err}"
22
+
23
+ # Rejection Gate
24
+ gate_ok, gate_reason = gate_reject(ast_ok, sandbox_ok)
25
+ if not gate_ok:
26
+ return f"[❌ MUTATION BLOQUÉE]\n{gate_reason}"
27
+
28
+ # Préparer patch
29
+ PENDING_PATCH = prepare_patch(new_code)
30
+ PENDING_TARGET = target_file
31
+
32
+ return "[✅ PATCH PRÊT]\nEnvoie 'VALIDER' pour appliquer ou 'ANNULER' pour rejeter."
33
+
34
+ def apply_pending():
35
+ global PENDING_PATCH, PENDING_TARGET
36
+ if PENDING_PATCH and PENDING_TARGET:
37
+ apply_patch(PENDING_TARGET, PENDING_PATCH)
38
+ PENDING_PATCH = None
39
+ PENDING_TARGET = None
40
+ return "[✔️ PATCH APPLIQUÉ]"
41
+ return "Aucun patch en attente."
42
+
43
+ def cancel_pending():
44
+ global PENDING_PATCH, PENDING_TARGET
45
+ PENDING_PATCH = None
46
+ PENDING_TARGET = None
47
+ return "[❌ PATCH ANNULÉ]"