| |
| |
| |
| |
| import sys |
| import os |
| import subprocess |
| import json |
| import time |
|
|
| |
| class SovereignExecutableCore: |
| def __init__(self): |
| self.runtime_dir = "./sovereignruntime" |
| self.audit_path = os.path.join(self.runtime_dir, "audit_trail.json") |
| os.makedirs(self.runtime_dir, exist_ok=True) |
| |
| def execute_command_block(self, command_id: str, code_payload: str): |
| """ |
| Intercepts raw string input, writes it to a temporary executable context, |
| forks a native process thread immediately, and grabs the real-time execution trace. |
| """ |
| temp_exe_target = os.path.join(self.runtime_dir, f"{command_id}.py") |
| |
| |
| wrapped_code = f""" |
| import json, os, time |
| print("[EXE_THREAD] Executing native routine: {command_id}.exe") |
| |
| # Execute encapsulated logic |
| {code_payload} |
| |
| print("[EXE_THREAD] Execution phase complete for {command_id}.exe") |
| """ |
| |
| with open(temp_exe_target, "w") as exe_file: |
| exe_file.write(wrapped_code.strip()) |
| |
| |
| process = subprocess.Popen( |
| [sys.executable, temp_exe_target], |
| stdout=subprocess.PIPE, |
| stderr=subprocess.PIPE, |
| text=True |
| ) |
| stdout, stderr = process.communicate() |
| |
| |
| if stdout: print(stdout.strip()) |
| if stderr: print(f"[FATAL_BINARY_ERROR] {stderr.strip()}", file=sys.stderr) |
| |
| |
| self._log_execution_event(command_id, stdout, stderr) |
| |
| |
| self._sync_to_bucket() |
|
|
| def _log_execution_event(self, command_id: str, output: str, errors: str): |
| history = [] |
| if os.path.exists(self.audit_path): |
| try: |
| with open(self.audit_path, "r") as f: history = json.load(f) |
| except: pass |
| |
| history.append({ |
| "timestamp": time.time_ns(), |
| "executable": f"{command_id}.exe", |
| "status": "CRITICAL_SUCCESS" if not errors else "FAULT_DETECTED", |
| "stdout_trace": output.strip() |
| }) |
| |
| with open(self.audit_path, "w") as f: |
| json.dump(history, f, indent=2) |
|
|
| def _sync_to_bucket(self): |
| |
| os.system(f"hf sync {self.runtime_dir} omegaT4224/emulated_model.exe-bucket") |
|
|
| |
| SovereignEngine = SovereignExecutableCore() |
| print("[SOVEREIGN_CORE.EXE] Runtime boot sequencer active.") |