GodModeAI2025/SkillSafeWerkstatt / maintain-llm-wiki
maintain-llm-wiki
UnverifiedCreate, maintain, inventory, migrate, recover, quality-review, optionally clean, release, or export an evidence-linked SkillSafeWerkstatt Markdown wiki. Use whenever the user wants to initialize or extend this wiki, ingest documents as Markdown, curate claims, clusters or concepts, clean metadata, restore files, record who reviewed which pages, resolve a OneDrive or SharePoint conflict copy, publish a release, or export a frozen read-only knowledge skill or an Open Knowledge Format bundle in Claude Code, Claude Cowork, or Codex.
scripts/validate_extraction.py
View on GitHub#!/usr/bin/env python3
"""Assess a staged Markdown extraction before it enters a wiki."""
from __future__ import annotations
import argparse
import json
import re
import sys
from pathlib import Path
from typing import Any
# Siblings are imported from this folder even where the interpreter leaves it
# off sys.path: python -I, python -P, PYTHONSAFEPATH=1.
_SCRIPT_DIR = str(Path(__file__).resolve().parent)
if _SCRIPT_DIR not in sys.path:
sys.path.insert(0, _SCRIPT_DIR)
import secret_screen
import source_coverage
SUSPICIOUS_HEADING = re.compile(r"^#{1,6}\s+#+(?:\s+#+)*\s*$")
CONTROL = re.compile(r"[\x00-\x08\x0b\x0c\x0e-\x1f]")
def assess(path: Path, source_type: str = "unknown") -> dict[str, Any]:
errors: list[str] = []
warnings: list[str] = []
try:
text = path.read_text(encoding="utf-8")
except UnicodeError as exc:
return {"state": "rejected", "errors": [f"extraction is not valid UTF-8: {exc}"], "warnings": []}
except OSError as exc:
return {"state": "rejected", "errors": [f"extraction is unavailable: {exc}"], "warnings": []}
if not text.strip():
errors.append("extraction is empty")
if CONTROL.search(text):
errors.append("extraction contains control characters")
if "\ufffd" in text:
errors.append("extraction contains Unicode replacement characters")
# A faithful extraction is still not allowed to carry a live credential in.
errors.extend(secret_screen.describe("extraction line", secret_screen.scan_text(text)))
lines = text.splitlines()
longest = max((len(line) for line in lines), default=0)
extreme_lines = [index for index, line in enumerate(lines, 1) if len(line) > 20000]
long_lines = [index for index, line in enumerate(lines, 1) if 2000 < len(line) <= 20000]
if extreme_lines:
errors.append(f"extraction contains extremely long flattened lines: {extreme_lines[:10]}")
if long_lines:
warnings.append(f"extraction contains unusually long lines: {long_lines[:10]}")
suspicious = [index for index, line in enumerate(lines, 1) if SUSPICIOUS_HEADING.fullmatch(line.strip())]
if suspicious:
warnings.append(f"extraction contains suspicious heading artifacts: {suspicious[:10]}")
fences = sum(1 for line in lines if line.strip().startswith("```"))
if fences % 2:
errors.append("extraction contains an unclosed fenced code block")
# Lint, coverage and the reading views read a marker only on a line of its
# own, so an inline marker would pass here and later resolve no locator.
# Fences follow the scan's rule (``` or ~~~), as coverage does.
markers = 0
inline_markers: list[int] = []
fenced = False
for index, line in enumerate(lines, 1):
stripped = line.strip()
if source_coverage.FENCE.match(line):
fenced = not fenced
continue
if fenced or "<!--" not in stripped:
continue
if source_coverage.PAGE_MARKER.match(stripped):
markers += 1
elif source_coverage.ANY_MARKER.search(stripped):
inline_markers.append(index)
if inline_markers:
warnings.append(
"page or slide markers must stand on a line of their own: lines "
+ ", ".join(str(number) for number in inline_markers[:10])
)
if source_type.casefold() in {"pdf", "presentation", "slides"} and markers == 0:
warnings.append("page or slide markers are missing from a paged source extraction")
table_dividers = sum(1 for line in lines if re.fullmatch(r"\s*\|?(?:\s*:?-{3,}:?\s*\|)+\s*", line))
table_rows = sum(1 for line in lines if line.count("|") >= 2)
if table_rows >= 4 and table_dividers == 0:
warnings.append("table-like rows exist without a recognizable Markdown table divider")
state = "rejected" if errors else "attention-needed" if warnings else "acceptable"
return {
"state": state,
"recommended_status": "partial" if warnings or errors else "active",
"errors": errors,
"warnings": warnings,
"stats": {
"bytes": len(text.encode("utf-8")),
"lines": len(lines),
"longest_line": longest,
"page_or_slide_markers": markers,
"inline_page_or_slide_markers": len(inline_markers),
"table_like_rows": table_rows,
},
}
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--markdown-file", required=True)
parser.add_argument("--source-type", default="unknown")
args = parser.parse_args()
report = assess(Path(args.markdown_file), args.source_type)
print(json.dumps(report, ensure_ascii=False, indent=2))
return 4 if report["state"] == "rejected" else 2 if report["state"] == "attention-needed" else 0
if __name__ == "__main__":
# Windows pipes default to the ANSI code page; output is UTF-8 everywhere.
for _stream in (sys.stdout, sys.stderr):
if hasattr(_stream, "reconfigure"):
_stream.reconfigure(encoding="utf-8", errors=_stream.errors)
raise SystemExit(main())
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |