import json import re import sys import os def clean_file(file_path): if not os.path.exists(file_path): print(f"❌ File not found: {file_path}") sys.exit(1) with open(file_path, 'r', encoding='utf-8') as f: data = json.load(f) chunks = data.get('chunkedPrompt', {}).get('chunks', []) turn_regex = re.compile(r'\[TURN_\d{4}\]\n?') for chunk in chunks: # 1. Nuke parts array (except thoughtSignature) if 'parts' in chunk: new_parts = [] for p in chunk['parts']: if 'thoughtSignature' in p: new_parts.append(p) if new_parts: chunk['parts'] = new_parts else: del chunk['parts'] # 2. Global wipe of [TURN_XXXX] from text if 'text' in chunk: text = chunk['text'] # Skip the hotel/foundation blocks to avoid mangling system instructions if '[CODE_CUSTODIAN_HOTEL_BEGIN]' in text or '[CODE_CUSTODIAN_FOUNDATION_BEGIN]' in text: continue # Strip all TURN tags cleaned_text = turn_regex.sub('', text).strip() chunk['text'] = cleaned_text with open(file_path, 'w', encoding='utf-8') as f: json.dump(data, f, indent=2, separators=(',', ': '), ensure_ascii=False) print(f"✅ Scorched Earth complete on: {os.path.basename(file_path)}") if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: python3 defibrillator_v2.py '/path/to/master_chat.json'") sys.exit(1) clean_file(sys.argv[1])