| import hashlib | |
| import importlib | |
| import os | |
| import json | |
| class TruthKernel: | |
| def __init__(self, rules_path="rules", config_path="config/manifest.json"): | |
| self.rules = [] | |
| self.audits = [] | |
| self.load_rules(rules_path, config_path) | |
| def load_rules(self, rules_path, config_path): | |
| with open(config_path, "r") as f: | |
| config = json.load(f) | |
| for rule in config.get("active_rules", []): | |
| module = importlib.import_module(f"{rules_path}.{rule}") | |
| self.rules.append((rule, module.validate)) | |
| def validate(self, text): | |
| results = {} | |
| for name, fn in self.rules: | |
| results[name] = fn(text) | |
| return results | |
| def audit(self, text): | |
| hash = hashlib.sha256(text.encode()).hexdigest() | |
| self.audits.append((text, hash)) | |
| return hash |