2"""Reject generic documentation-expansion debris anywhere in the repository Markdown corpus."""
4from __future__
import annotations
8from pathlib
import Path
11REPO_ROOT = Path(__file__).resolve().parents[2]
12CONTRACT_PATH = REPO_ROOT /
"tests" /
"tooling" /
"generic_expansion_contract.json"
17 @brief Load the forbidden-signature contract.
18 @return Parsed contract mapping.
20 return json.loads(CONTRACT_PATH.read_text(encoding=
"utf-8"))
25 @brief Yield every repository Markdown file inside the contract's scan scope.
26 @param[in] contract Parsed contract mapping.
27 @return Generator of Markdown paths.
29 excluded = set(contract[
"scan"][
"exclude_dirs"])
30 for path
in sorted(REPO_ROOT.rglob(
"*.md")):
31 if excluded.intersection(path.relative_to(REPO_ROOT).parts):
38 @brief Collapse whitespace so formatting changes cannot hide an exact template copy.
39 @param[in] text Raw file text.
40 @return Whitespace-normalized text.
42 return " ".join(text.split())
45def scan(contract: dict) -> list[str]:
47 @brief Collect every forbidden-signature hit in the Markdown corpus.
48 @param[in] contract Parsed contract mapping.
49 @return Human-readable violation lines.
52 (
"marker", contract[
"forbidden_markers"]),
53 (
"heading", contract[
"forbidden_headings"]),
54 (
"fragment", contract[
"forbidden_fragments"]),
56 violations: list[str] = []
58 text = path.read_text(encoding=
"utf-8", errors=
"replace")
60 relative = path.relative_to(REPO_ROOT)
61 for kind, patterns
in signatures:
62 for pattern
in patterns:
63 if pattern
in text
or normalize(pattern)
in collapsed:
64 violations.append(f
"{relative}: forbidden {kind}: {pattern[:72]}")
70 @brief Fail when generic expansion debris is present in the Markdown corpus.
71 @return Process status code.
74 violations =
scan(contract)
76 print(
"Generic documentation-expansion debris detected:", file=sys.stderr)
77 for violation
in violations:
78 print(f
" {violation}", file=sys.stderr)
80 "\nThese signatures mark uniform agent-generated filler. Replace them with "
81 "guidance specific to this page's subject, or remove the section.",
85 print(f
"Generic-expansion audit passed: {sum(1 for _ in iter_markdown(contract))} Markdown files clean.")
89if __name__ ==
"__main__":
90 raise SystemExit(
main())
dict load_contract()
Load the forbidden-signature contract.
int main()
Fail when generic expansion debris is present in the Markdown corpus.
str normalize(str text)
Collapse whitespace so formatting changes cannot hide an exact template copy.
iter_markdown(dict contract)
Yield every repository Markdown file inside the contract's scan scope.
list[str] scan(dict contract)
Collect every forbidden-signature hit in the Markdown corpus.