forked from Aider-AI/aider
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclean_cache.py
41 lines (34 loc) · 1.34 KB
/
clean_cache.py
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
import json
import re
from pathlib import Path
def clean_cached_summaries():
# Get the cache directory
cache_dir = Path(".aider") / "caches" / "summaries"
if not cache_dir.exists():
print("No cache directory found!")
return
# Process each JSON file in the cache
for cache_file in cache_dir.glob("*.json"):
print(f"Processing {cache_file}")
try:
# Load the cached data
with open(cache_file, 'r', encoding='utf-8') as f:
cache_data = json.load(f)
# Get the summary content
summary = cache_data.get("summary", "")
if not summary:
continue
# Strip out <note> sections
cleaned_summary = re.sub(r'<note>.*?</note>', '', summary, flags=re.DOTALL)
if cleaned_summary != summary:
print(f"Cleaned notes from {cache_file}")
# Update the cache file with cleaned summary
cache_data["summary"] = cleaned_summary
with open(cache_file, 'w', encoding='utf-8') as f:
json.dump(cache_data, f, indent=2)
except Exception as e:
print(f"Error processing {cache_file}: {e}")
if __name__ == "__main__":
print("Starting cache cleanup...")
clean_cached_summaries()
print("Cache cleanup complete!")