"""Deterministic CLI for catching academic LLM clichés and numeric drift.""" from __future__ import annotations import argparse import re import sys from collections import Counter from pathlib import Path PATTERNS = [ (r"\bdelve(?:s|d|ing)?\s+into\b", "Replace 'delve into' with 'examine' or 'test'."), (r"\bintricate\s+tapestry\b|\btapestry\b|\bparadigm\s+shift\b", "Replace vague metaphor with concrete mechanism."), (r"\bever-evolving\s+landscape\b|\brealm\s+of\b", "Name the exact subfield or system directly."), (r"\btestament\s+to\b|\bunderscores?\s+the\s+(?:importance|significance)\b", "Delete empty emphasis; cite observed magnitude."), (r"\bpivotal\b|\bparamount\b|\bmultifaceted\b|\bgroundbreaking\b|\bunprecedented\b", "Trim promotional adjective."), (r"\bpaving\s+the\s+way\s+for\b|\bbridges?\s+the\s+gap\s+between\b", "State the concrete downstream experiment."), (r"\bit\s+is\s+worth\s+noting\s+that\b|\bin\s+conclusion,\s+our\s+study\b", "Cut throat-clearing transition."), (r"\bmeticulous(?:ly)?\b|\bseamless(?:ly)?\b|\brobust\s+framework\b|\bmyriad\b", "Replace vague praise with validation criteria."), (r"\b(?:TODO|TBD|FIXME|XXX)\b|\[(?:insert|citation\s+needed|placeholder)[^\]]*\]", "Resolve placeholder before submission."), ] NUMBER_RE = re.compile(r"\b\d+(?:\.\d+)?%?(?:\s*[±×x]\s*\d+(?:\.\d+)?)?") def extract_numbers(text: str) -> Counter[str]: return Counter(NUMBER_RE.findall(text)) def scan_text(text: str) -> list[tuple[int, str, str]]: hits: list[tuple[int, str, str]] = [] for i, line in enumerate(text.splitlines(), start=1): for pat, msg in PATTERNS: for m in re.finditer(pat, line, flags=re.IGNORECASE): hits.append((i, m.group(0), msg)) return hits def main(argv: list[str] | None = None) -> int: parser = argparse.ArgumentParser(prog="alcyone-lint", description="Lint academic Markdown/LaTeX drafts.") parser.add_argument("file", help="Path to draft file (.md, .tex, .txt)") parser.add_argument("--baseline", default="", help="Optional original file to enforce numeric token conservation") parser.add_argument("--strict", action="store_true", help="Exit 1 if any clichés, placeholders, or numeric diffs found") args = parser.parse_args(argv) target = Path(args.file) if not target.is_file(): print(f"File not found: {target}", file=sys.stderr) return 2 text = target.read_text(encoding="utf-8", errors="replace") hits = scan_text(text) print(f"Scanned {target.name}: {len(hits)} flagged phrase(s)") for ln, matched, msg in hits: print(f" L{ln}: '{matched}' -> {msg}") drift = False if args.baseline: base_path = Path(args.baseline) if not base_path.is_file(): print(f"Baseline not found: {base_path}", file=sys.stderr) return 2 c_base = extract_numbers(base_path.read_text(encoding="utf-8", errors="replace")) c_new = extract_numbers(text) if c_base != c_new: drift = True print(f"NUMERIC DRIFT DETECTED: removed={dict(c_base - c_new)}, added={dict(c_new - c_base)}") else: print(f"Numeric guard PASS: {sum(c_new.values())} numeric token(s) preserved.") if args.strict and (hits or drift): return 1 return 0 if __name__ == "__main__": raise SystemExit(main())