#!/usr/bin/env python3 """Check that tracked plugin source stays portable across repository imports.""" from __future__ import annotations import argparse import re import stat import subprocess import sys from pathlib import Path MAX_SOURCE_FILE_BYTES = 150_000 MAX_DEPENDENCY_LOCK_BYTES = 2_000_000 DEPENDENCY_LOCK_NAMES = { "Cargo.lock", "package-lock.json", "pnpm-lock.yaml", "requirements.txt", "uv.lock", "yarn.lock", } LIST_ITEM = re.compile(r"^\s*(?:[-*+]|\d+[.)])\s+") HTML_BLOCK = re.compile(r"^\s*]*>\s*$") NATURAL_LINE_ENDINGS = tuple(".?!:;。!?:;)]}'\"`>") def tracked_files(plugin_root: Path) -> list[Path]: result = subprocess.run( ["git", "-C", str(plugin_root), "ls-files", "-z", "--", "."], check=False, capture_output=True, ) if result.returncode != 0: detail = result.stderr.decode(errors="replace").strip() raise RuntimeError(detail or "git ls-files failed") return [Path(value.decode()) for value in sorted(result.stdout.split(b"\0")) if value] def is_markdown_structure(line: str) -> bool: stripped = line.strip() return ( not stripped or stripped.startswith(("#", ">", "|", "