import os import re import json lanes_dir = "/home/donghyeon/Documents/LLM Wiki/docs/superpowers/specs/2026-05-27-branch-notes-audit/lanes" lane_files = sorted(os.listdir(lanes_dir)) all_extracted = [] for lf in lane_files: if not lf.endswith(".md"): continue path = os.path.join(lanes_dir, lf) with open(path, "r", encoding="utf-8") as f: content = f.read() print(f"Parsing {lf}...") # We want to find each Finding section in the file. # A finding section typically starts with a header like: # "### L1-F01: ..." or "#### Finding 4.1.1: ..." # Let's search for headers or blocks that contain "Severity:" or "심각도:" # and "Source file:", "Source quote:", etc. # Let's split the file by headers to isolate findings. sections = re.split(r"\n(###+ [^\n]+)\n", content) current_header = None for i, part in enumerate(sections): if i == 0: continue if i % 2 == 1: current_header = part else: section_content = part if "Severity" in section_content or "심각도" in section_content: # This is a finding! severity = "Medium" for sev in ["Critical", "High", "Medium", "Low"]: if re.search(r"(?:Severity|심각도)\s*:\s*" + sev, section_content, re.IGNORECASE): severity = sev break source_file = "Unknown" sf_match = re.search(r"(?:Source file|Source|소스 파일)\s*:\s*`?([^`\n\r]+)`?", section_content) if sf_match: source_file = sf_match.group(1).strip() finding_id = "Unknown" id_match = re.search(r"(L\d+-F\d+|Finding\s+\d+\.\d+\.\d+|F-\d+)", current_header) if id_match: finding_id = id_match.group(1).strip() else: id_match_in_body = re.search(r"(L\d+-F\d+)", section_content) if id_match_in_body: finding_id = id_match_in_body.group(1).strip() title = current_header.replace("#", "").strip() # Clean up title title = re.sub(r"^(L\d+-F\d+|Finding\s+\d+\.\d+\.\d+):\s*", "", title) all_extracted.append({ "lane_file": lf, "finding_id": finding_id, "title": title, "severity": severity, "source_file": source_file, "header": current_header }) print(f"\nExtracted {len(all_extracted)} findings in detail!") with open("extracted_findings.json", "w", encoding="utf-8") as out_j: json.dump(all_extracted, out_j, indent=2, ensure_ascii=False) print("Saved to extracted_findings.json")