diff --git a/app.py b/app.py index ec21443..cfa9d8f 100644 --- a/app.py +++ b/app.py @@ -214,32 +214,50 @@ def normalize_components(raw_components: list) -> list: # getrennt von SkillSpectors eigenem Scan, nur um der KI echten Kontext für # den "Wofür ist das?"-Absatz zu geben statt nur der Sicherheitsfunde. # --------------------------------------------------------------------------- # -def extract_skill_context(target: str, is_zip: bool, work_dir: str) -> str: - context_dir = Path(work_dir) / "context_extract" - try: - context_dir.mkdir(exist_ok=True) - if is_zip: - with zipfile.ZipFile(target) as zf: - zf.extractall(context_dir) - else: +def extract_skill_context(target: str, work_dir: str) -> str: + if target.startswith("http://") or target.startswith("https://"): + context_dir = Path(work_dir) / "context_extract" + try: + context_dir.mkdir(exist_ok=True) subprocess.run( ["git", "clone", "--depth", "1", target, str(context_dir / "repo")], timeout=60, capture_output=True, text=True, ) - candidates = ( - list(context_dir.rglob("SKILL.md")) - or list(context_dir.rglob("skill.md")) - or list(context_dir.rglob("README.md")) - ) - if not candidates: + candidates = ( + list(context_dir.rglob("SKILL.md")) + or list(context_dir.rglob("skill.md")) + or list(context_dir.rglob("README.md")) + ) + return candidates[0].read_text(errors="ignore")[:3000] if candidates else "" + except Exception: return "" - return candidates[0].read_text(errors="ignore")[:3000] + finally: + shutil.rmtree(context_dir, ignore_errors=True) + + if target.lower().endswith(".zip"): + context_dir = Path(work_dir) / "context_extract" + try: + context_dir.mkdir(exist_ok=True) + with zipfile.ZipFile(target) as zf: + zf.extractall(context_dir) + candidates = ( + list(context_dir.rglob("SKILL.md")) + or list(context_dir.rglob("skill.md")) + or list(context_dir.rglob("README.md")) + ) + return candidates[0].read_text(errors="ignore")[:3000] if candidates else "" + except Exception: + return "" + finally: + shutil.rmtree(context_dir, ignore_errors=True) + + # Einzeln hochgeladene Datei (z. B. eine reine SKILL.md ohne ZIP) + try: + return Path(target).read_text(errors="ignore")[:3000] except Exception: return "" - finally: - shutil.rmtree(context_dir, ignore_errors=True) # --------------------------------------------------------------------------- # @@ -437,8 +455,8 @@ a{color:var(--orange)}