File size: 2,312 Bytes
98fa607
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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()