-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfix_nested_rasp.py
More file actions
76 lines (57 loc) · 2.45 KB
/
fix_nested_rasp.py
File metadata and controls
76 lines (57 loc) · 2.45 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
import re
import sys
from codomyrmex.utils.cli_helpers import print_info, print_success, setup_logging
def titleize(name):
"""Convert folder name like 'git_operations' to 'Git Operations'"""
return " ".join(word.capitalize() for word in name.replace("-", "_").split("_"))
def fix_file(filepath, folder_name):
title = titleize(folder_name)
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
original = content
# 1. Replace "Codomyrmex Root" with the actual title
content = content.replace("Codomyrmex Root", title)
# 2. Ensure version string exists or replace old ones
version_string = "**Version**: v1.0.0 | **Status**: Active | **Last Updated**: February 2026\n"
# Replace any existing version string
content = re.sub(r'\*\*Version\*\*:.*?\n', '', content)
# Insert version string after the first header if it's not a PAI.md (PAI.md has its own format we already fixed mostly, but we should fix nested ones too)
lines = content.split('\n')
for i, line in enumerate(lines):
if line.startswith('# '):
lines.insert(i + 1, '\n' + version_string)
break
content = '\n'.join(lines)
# Clean up multiple newlines that might have been introduced
content = re.sub(r'\n{3,}', '\n\n', content)
if content != original:
with open(filepath, 'w', encoding='utf-8') as f:
f.write(content)
return True
return False
def main() -> int:
setup_logging()
base_dir = "src/codomyrmex"
fixed_count = 0
scanned_count = 0
print_info(f"Scanning nested RASP files in {base_dir}...")
for root, dirs, files in os.walk(base_dir):
# Skip the top-level Codomyrmex root itself, we just want subfolders
if root == base_dir:
continue
folder_name = os.path.basename(root)
if folder_name.startswith('__'):
continue
for file in files:
if file in ("README.md", "AGENTS.md", "SPEC.md", "PAI.md"):
filepath = os.path.join(root, file)
scanned_count += 1
if fix_file(filepath, folder_name):
fixed_count += 1
if scanned_count % 1000 == 0:
print_info(f"Scanned {scanned_count} files, fixed {fixed_count}...")
print_success(f"Done! Scanned {scanned_count} RASP files, fixed {fixed_count} files.")
return 0
if __name__ == "__main__":
sys.exit(main())