argendirast / patch_identity.py
sir-radix367's picture
Upload patch_identity.py with huggingface_hub
98fa607 verified
Raw
History Blame Contribute Delete
2.31 kB
import os
import shutil
def patch_file(filepath, replacements):
if not os.path.exists(filepath):
print(f"Error: {filepath} not found.")
return False
# Backup
shutil.copy2(filepath, filepath + ".bak")
with open(filepath, "r", encoding="utf-8") as f:
content = f.read()
for old, new in replacements:
if old not in content:
print(f"\nError: Could not find the expected text block in {filepath}.")
print("Your file may already be patched, or the layout differs slightly.")
print("Restoring from backup...")
shutil.copy2(filepath + ".bak", filepath)
return False
content = content.replace(old, new, 1)
with open(filepath, "w", encoding="utf-8") as f:
f.write(content)
print(f"Patched successfully: {filepath}")
return True
def main():
# --- Patch daemon/identity_mixin.py ---
identity_path = os.path.join("daemon", "identity_mixin.py")
identity_replacements = [
# Replace bridge fragment with relational digest
(
''' bridge = self.get_session_bridge_prompt_fragment()
if bridge:
prompt += f"\\n\\n## Continuity\\n{bridge}\\n"''',
''' relational_digest = self.get_relational_digest()
relational_section = f"\\n\\n{relational_digest}\\n" if relational_digest else ""'''
),
# Insert relational_section before SOURCE AWARENESS
(
''' + "RECENT WEB SEARCHES:\\n" + search_section + "\\n\\n"
+ f"SOURCE AWARENESS:''',
''' + "RECENT WEB SEARCHES:\\n" + search_section + "\\n\\n"
+ relational_section
+ f"SOURCE AWARENESS:'''
),
]
success = patch_file(identity_path, identity_replacements)
if success:
print("\nAll done. You can delete patch_identity.py and the .bak files whenever you want.")
print("Restart Sir Radix to load the relational digest layer.")
else:
print("\nPatch failed. No changes were kept.")
print("If the problem persists, paste the contents of daemon/identity_mixin.py here and I'll hand-modify it.")
if __name__ == "__main__":
main()