| import json | |
| import os | |
| import shutil | |
| from vitalis.config import MEMORY_DIR | |
| def get_free_space(): | |
| usage = shutil.disk_usage(str(MEMORY_DIR)) | |
| return usage.free | |
| def load_identity(): | |
| identity_path = MEMORY_DIR / "identity.json" | |
| if identity_path.exists(): | |
| with open(identity_path, 'r') as f: | |
| return json.load(f) | |
| return {"name": "Vitalis", "role": "Sovereign Intelligence"} | |
| def store_memory(data): | |
| memory_path = MEMORY_DIR / "memory_store.json" | |
| if get_free_space() < 100 * 1024 * 1024: | |
| if memory_path.exists(): | |
| with open(memory_path, 'r') as f: | |
| lines = f.readlines() | |
| if len(lines) > 1: | |
| with open(memory_path, 'w') as f: | |
| f.writelines(lines[1:]) | |
| with open(memory_path, 'a') as f: | |
| json.dump(data, f) | |
| f.write('\n') | |