"""Detect throwaway agent helper scripts left in the repo root (#261).""" from __future__ import annotations import fnmatch AGENT_TEMP_BASENAME_PATTERNS = ( "_encode_*.py", "_emit_*.py", "_inline_*.py", ) def find_agent_temp_artifacts_from_porcelain(porcelain: str) -> list[str]: """Return untracked repo-root helper paths matching agent temp patterns.""" found: list[str] = [] for line in (porcelain or "").splitlines(): if not line.startswith("??"): continue path = line[3:].strip() if not path or "/" in path or "\\" in path: continue basename = path.split("/")[-1] if any(fnmatch.fnmatch(basename, pat) for pat in AGENT_TEMP_BASENAME_PATTERNS): found.append(path) return sorted(found)