Skip to content
78 changes: 49 additions & 29 deletions scripts/extract_todos_structured.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,63 @@
import json
from pathlib import Path

TODO_PATTERN = re.compile(r'TODO\(priority=([^,]+), complexity=([^,]+), owner=([^)]+)\):')
TODO_OLD_PATTERN = re.compile(r'TODO\(priority=([^,]+), complexity=([^)]+)\):')

def extract_todos(root_dir):
todos = []
# Exclude directories
exclude_dirs = {'.git', 'node_modules', '.jules', 'dist', 'build', '.venv', '__pycache__'}
exclude_dirs = {'.git', 'node_modules', '.jules', '.Jules', 'dist', 'build', '.venv', '__pycache__'}
this_file = Path(__file__).resolve()

for root, dirs, files in os.walk(root_dir):
dirs[:] = [d for d in dirs if d not in exclude_dirs]

for file in files:
if file.endswith(('.py', '.tsx', '.ts', '.js', '.jsx', '.md')):
filepath = os.path.join(root, file)
try:
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
lines = f.readlines()
for i, line in enumerate(lines):
if 'TODO' in line:
# Simple parser
content = line.strip()
# Try to parse structured TODOs if they exist
# Format: TODO(priority=<Level>, complexity=<Level>):
priority = "Unknown"
complexity = "Unknown"

match = re.search(r'TODO\(priority=(.*?), complexity=(.*?)\):', content)
if match:
priority = match.group(1)
complexity = match.group(2)

todos.append({
'file': filepath,
'line': i + 1,
'content': content,
'priority': priority,
'complexity': complexity
})
except Exception as e:
print(f"Error reading {filepath}: {e}")
if not file.endswith(('.py', '.tsx', '.ts', '.js', '.jsx', '.md')):
continue

filepath = os.path.join(root, file)
if Path(filepath).resolve() == this_file:
continue

try:
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
lines = f.readlines()
for i, line in enumerate(lines):
if 'TODO' not in line:
continue

# Simple parser
content = line.strip()
# Try to parse structured TODOs if they exist
# Format: TODO(priority=<Level>, complexity=<Level>, owner=<Owner>):
priority = "Unknown"
complexity = "Unknown"
owner = "Unknown"

match = TODO_PATTERN.search(content)
if match:
priority = match.group(1)
complexity = match.group(2)
owner = match.group(3)
else:
# Fallback for old format
match_old = TODO_OLD_PATTERN.search(content)
if match_old:
priority = match_old.group(1)
complexity = match_old.group(2)

todos.append({
'file': filepath,
'line': i + 1,
'content': content,
'priority': priority,
'complexity': complexity,
'owner': owner
})
except Exception as e:
print(f"Error reading {filepath}: {e}")
return todos

if __name__ == "__main__":
Expand Down
Loading