from pathlib import Path
import json

# Import the SWE-smith profile registry and all profiles
from swesmith.profiles.base import global_registry
import swesmith.profiles.python  # or import all relevant profiles

read_path = Path("tool_gen/filtered_swe_smith.jsonl")
write_path = Path("tool_gen/filtered_swe_smith_with_base_commit.jsonl")
lines = read_path.read_text().splitlines()

with write_path.open("w") as f:
    for line in lines:
        entry = json.loads(line)
        try:
            # Use the registry to get the profile for this instance
            profile = global_registry.get_from_inst(entry)
            entry["base_commit"] = profile.commit
        except Exception as e:
            entry["base_commit"] = ""
            print(f"Warning: Could not get profile for {entry.get('instance_id', '')}: {e}")
        f.write(json.dumps(entry) + "\n") 