VanyaJ's picture
Release BADA Terminal v2.1.0 (Enterprise Ontology, NVIDIA auto-ontology, Release Preflight)
d739b1b verified
Raw History Blame Contribute Delete
5.18 kB
#!/usr/bin/env python3
"""
BADA & Knot LLMWiki ์ง€์‹ ๋ฌด๊ฒฐ์„ฑ Linter
์‚ฌ์šฉ: python3 scripts/lint.py [wiki_path] (๊ธฐ๋ณธ๊ฐ’: ./wiki)
๊ทœ์•ฝ ์œ„๋ฐ˜ ์‹œ exit 1์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
"""
import os
import re
import sys
from pathlib import Path
TYPES = {"source", "entity", "concept", "note"}
REQUIRED_FIELDS = ["type", "created", "updated", "sources"]
DATE_RE = re.compile(r"^\d{4}-\d{2}-\d{2}$")
LINK_RE = re.compile(r"\[\[([^\]|#\n]+?)(?:\|[^\]]*)?\]\]")
errors = []
warnings = []
def parse_frontmatter(text):
"""YAML Frontmatter๋ฅผ ํŒŒ์‹ฑํ•˜์—ฌ dict๋กœ ๋ฐ˜ํ™˜. ํ˜•์‹ ์˜ค๋ฅ˜ ์‹œ None."""
lines = text.split("\n")
if not lines or lines[0].strip() != "---":
return None
fm = {}
key = None
for line in lines[1:]:
if line.strip() == "---":
return fm
if ":" in line:
k, _, v = line.partition(":")
k = k.strip()
v = v.split("#")[0].strip()
key = k
# ๋ฐฐ์—ด ์ฒ˜๋ฆฌ [a, b]
if v.startswith("[") and v.endswith("]"):
fm[k] = [x.strip().strip("'\"") for x in v[1:-1].split(",") if x.strip()]
else:
fm[k] = v.strip("'\"")
elif key and line.strip().startswith("- "):
if not isinstance(fm[key], list):
fm[key] = []
fm[key].append(line.strip()[2:].strip().strip("'\""))
return None # ๋‹ซ๋Š” ---๊ฐ€ ์—†์Œ
def main():
wiki_path = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("./wiki")
if not wiki_path.is_dir():
print(f"๐Ÿšจ ERROR: wiki ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค: {wiki_path}")
return 1
print(f"๐Ÿ” Starting LLMWiki Lint check on: {wiki_path.resolve()}")
# 1. wiki/ ๋‚ด์˜ ๋ชจ๋“  ๋งˆํฌ๋‹ค์šด ํŒŒ์ผ ํƒ์ƒ‰ (Flat ๊ตฌ์กฐ ๊ฒ€์ฆ)
pages = sorted(wiki_path.glob("*.md"))
slugs = {p.stem for p in pages}
inbound_links = {s: [] for s in slugs}
# 2. ๊ฐœ๋ณ„ ํŒŒ์ผ ๋ถ„์„ ๋ฐ ์ •ํ•ฉ์„ฑ ๊ฒ€์‚ฌ
for p in pages:
if p.name.lower() in ("schema.md", "index.md", "ontology-index.md", "claude.md", "architecture.md", "readme.md"):
continue
filename = f"wiki/{p.name}"
try:
text = p.read_text(encoding="utf-8")
except Exception as e:
errors.append(f"{filename}: ํŒŒ์ผ ์ฝ๊ธฐ ์‹คํŒจ - {str(e)}")
continue
# Frontmatter ํŒŒ์‹ฑ
fm = parse_frontmatter(text)
if fm is None:
errors.append(f"{filename}: Frontmatter๊ฐ€ ๋ˆ„๋ฝ๋˜์—ˆ๊ฑฐ๋‚˜ ํ˜•์‹์ด ๋ถˆ๋Ÿ‰ํ•ฉ๋‹ˆ๋‹ค.")
continue
# ํ•„์ˆ˜ ํ•„๋“œ ์ฒดํฌ
for field in REQUIRED_FIELDS:
if field not in fm:
errors.append(f"{filename}: ํ•„์ˆ˜ ํ•„๋“œ '{field}'๊ฐ€ Frontmatter์— ์—†์Šต๋‹ˆ๋‹ค.")
# ํƒ€์ž… ๊ฒ€์‚ฌ
if "type" in fm and fm["type"] not in TYPES:
errors.append(f"{filename}: ํ—ˆ์šฉ๋˜์ง€ ์•Š์€ type '{fm['type']}' (ํ—ˆ์šฉ: {list(TYPES)})")
# ๋‚ ์งœ ํฌ๋งท ๊ฒ€์‚ฌ
for date_field in ("created", "updated"):
if date_field in fm and not DATE_RE.match(str(fm[date_field])):
errors.append(f"{filename}: '{date_field}' ๋‚ ์งœ ํฌ๋งท์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค (YYYY-MM-DD ๊ถŒ์žฅ).")
# ๋ณธ๋ฌธ ๋งํฌ ๊ฒ€์‚ฌ
lines = text.split("\n")
for line_num, line in enumerate(lines, 1):
for match in LINK_RE.finditer(line):
target_slug = match.group(1).strip()
# ์•ต์ปค ๋งํฌ(#) ์ œ๊ฑฐ ํ›„ ํŒŒ์ผ๋ช… ์Šฌ๋Ÿฌ๊ทธ ์ถ”์ถœ
clean_slug = target_slug.split("#")[0].strip()
# notes/ ๋Ÿฐ ์ด๋ ฅ ๋“ฑ ์™ธ๋ถ€ ํด๋” ์ฐธ์กฐ ๋งํฌ ์˜ˆ์™ธ ํ†ต๊ณผ
if "/" in clean_slug or clean_slug.startswith(".."):
continue
# wiki ๋‚ด๋ถ€ ์Šฌ๋Ÿฌ๊ทธ ๊ฒ€์‚ฌ
if clean_slug not in slugs:
# stub ์ฃผ์„ ์ฒ˜๋ฆฌ๋˜์–ด ์žˆ์œผ๋ฉด ํ†ต๊ณผ
if "<!-- stub -->" in line:
continue
errors.append(f"{filename}:{line_num}: ๊นจ์ง„ ๋งํฌ [[{target_slug}]] ๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค (์กด์žฌํ•˜์ง€ ์•Š๋Š” ์Šฌ๋Ÿฌ๊ทธ).")
else:
inbound_links[clean_slug].append(p.stem)
# 3. ๊ณ ์•„ ๋…ธ๋“œ(Orphan Node) ํƒ์ƒ‰ (index.md ๋ฐ ontology-index.md ์ œ์™ธ)
for slug, links in inbound_links.items():
if slug in ("index", "ontology-index", "schema"):
continue
if not links:
warnings.append(f"wiki/{slug}.md: ํ”ผ๋งํฌ๊ฐ€ ์—†๋Š” ๊ณ ์•„(Orphan) ์ง€์‹ ๋…ธ๋“œ์ž…๋‹ˆ๋‹ค.")
# 4. ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ ์ถœ๋ ฅ
print("\n=== Lint Summary ===")
print(f"Total processed files: {len(pages)}")
print(f"Errors found: {len(errors)}")
print(f"Warnings found: {len(warnings)}")
if warnings:
print("\nโš ๏ธ WARNINGS:")
for w in warnings:
print(f" - {w}")
if errors:
print("\n๐Ÿšจ ERRORS (Lint Failed):")
for e in errors:
print(f" - {e}")
return 1
print("\nโœ… LLMWiki Lint PASSED successfully!")
return 0
if __name__ == "__main__":
sys.exit(main())