100+ AI Agents, Agent Skills and RAG Apps - Free and Open Source.
fix(agent_skills): preserve quoted paths in commit archaeology
RaycarlLei2d8e5560d64a
diff --git a/agent_skills/commit-archaeologist/scripts/archaeologist.py b/agent_skills/commit-archaeologist/scripts/archaeologist.pyindex c96904b7..7f91d899 100644--- a/agent_skills/commit-archaeologist/scripts/archaeologist.py+++ b/agent_skills/commit-archaeologist/scripts/archaeologist.py@@ -36,23 +36,20 @@ def git(repo, args, required=True):result = subprocess.run(["git", "-C", repo, *args],capture_output=True,- text=True,- # Decode git output as UTF-8. With text=True and no encoding, Python- # uses the locale default (cp1252 on Windows), which raises- # UnicodeDecodeError on non-Latin-1 bytes in commit messages or file- # content (emoji, em-dashes, …).- encoding="utf-8",- errors="replace",timeout=30,)except FileNotFoundError as exc:raise ArchaeologistError("git is not installed or is not on PATH") from excexcept subprocess.TimeoutExpired as exc:raise ArchaeologistError("git command timed out") from exc+ # Explicit UTF-8 decoding avoids locale-dependent failures on Windows and+ # preserves carriage returns in NUL-delimited paths (text mode changes them).+ stdout = result.stdout.decode("utf-8", errors="replace")+ stderr = result.stderr.decode("utf-8", errors="replace")if result.returncode != 0 and required:- detail = result.stderr.strip() or result.stdout.strip() or "git command failed"+ detail = stderr.strip() or stdout.strip() or "git command failed"raise ArchaeologistError(detail)- return result.stdout if result.returncode == 0 else ""+ return stdout if result.returncode == 0 else ""def normalize_inputs(repo_arg, file_arg):@@ -149,20 +146,25 @@ def changed_file_details(repo, commit_hash):output = git(repo,[- "diff-tree", "--root", "--no-commit-id", "--name-status", "-r",+ "diff-tree", "--root", "--no-commit-id", "--name-status", "-z", "-r","-M", commit_hash, "--",],)paths = set()renames = []- for line in output.splitlines():- fields = line.split("\t")- if len(fields) >= 3 and fields[0].startswith("R"):- old_path, new_path = fields[1], fields[2]- paths.update((old_path, new_path))- renames.append({"from": old_path, "to": new_path})- elif len(fields) >= 2:- paths.add(fields[-1])+ fields = iter(output.split("\0"))+ for status in fields:+ if not status:+ continue+ path = next(fields)+ if status.startswith(("R", "C")):+ new_path = next(fields)+ paths.add(new_path)+ if status.startswith("R"):+ paths.add(path)+ renames.append({"from": path, "to": new_path})+ else:+ paths.add(path)return sorted(paths), renamesdiff --git a/agent_skills/evals/commit-archaeologist/test_archaeologist.py b/agent_skills/evals/commit-archaeologist/test_archaeologist.pyindex 610c0008..152e84b6 100644--- a/agent_skills/evals/commit-archaeologist/test_archaeologist.py+++ b/agent_skills/evals/commit-archaeologist/test_archaeologist.py@@ -129,6 +129,50 @@ def run(repo, *args, file_path="src/calculator.py"):)+def check_quoted_paths(root, label, old_path, new_path, companion):+ repo = os.path.join(root, label)+ os.makedirs(repo)+ git(repo, "init", "-q")+ git(repo, "config", "user.name", "Ada Archaeologist")+ git(repo, "config", "user.email", EMAIL)+ git(repo, "config", "core.quotePath", "true")+ commit(repo, "2026-01-01T10:00:00+0000", "feat: add module", {+ old_path: "value = 1\n", companion: "First notes.\n",+ })+ commit(repo, "2026-01-02T10:00:00+0000", "fix: update module", {+ old_path: "value = 2\n", companion: "Updated notes.\n",+ })+ git(repo, "mv", old_path, new_path)+ git(repo, "commit", "-m", "refactor: rename module")++ result = run(repo, "--json", file_path=new_path)+ check(label + ": report exits cleanly", result.returncode == 0, result.stderr)+ if result.returncode != 0:+ return+ report = json.loads(result.stdout)+ check(+ label + ": changed files preserve literal names",+ set(report["introduced_by"]["changed_files"]) == {old_path, companion},+ str(report["introduced_by"]["changed_files"]),+ )+ check(+ label + ": rename preserves both paths",+ report["timeline"][-1]["renames"] == [{"from": old_path, "to": new_path}],+ str(report["timeline"][-1]["renames"]),+ )+ check(+ label + ": historical aliases include the original name",+ set(report["region"]["historical_paths"]) == {old_path, new_path},+ str(report["region"]["historical_paths"]),+ )+ check(+ label + ": only the companion is a repeated co-change",+ [(item["file"], item["count"]) for item in report["co_changed"]]+ == [(companion, 2)],+ str(report["co_changed"]),+ )++def main():root = tempfile.mkdtemp(prefix="commit-archaeologist-eval-")try:@@ -233,6 +277,16 @@ def main():invalid.stderr,)+ print("quoted filenames:")+ check_quoted_paths(+ root, "unicode", "src/café.py", "src/résumé.py", "docs/使用说明.md",+ )+ if os.name != "nt":+ check_quoted_paths(+ root, "control-characters", "src/tab\tand\nnewline.py",+ 'src/quote"and\\slash\r.py', "docs/notes\tand\r\n.md",+ )+print()if all(checks):print("PASS - %d/%d checks" % (len(checks), len(checks)))