Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
A comprehensive collection of Agent Skills for context engineering, multi-agent architectures, and production agent systems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
researcher/scripts/check_activation_cases.py
1#!/usr/bin/env python32"""Deterministically smoke-test skill activation boundaries."""34from __future__ import annotations56import argparse7import json8import re9import sys10from pathlib import Path11from typing import Any121314ROOT = Path(__file__).resolve().parents[2]15STOPWORDS = {16"the",17"and",18"for",19"with",20"that",21"this",22"into",23"from",24"agent",25"agents",26"skill",27"skills",28"build",29"create",30"design",31"whether",32"output",33"outputs",34"before",35"later",36"can",37"should",38}394041def tokens(text: str) -> set[str]:42raw = re.findall(r"[a-zA-Z][a-zA-Z0-9_-]{2,}", text.lower())43return {token.replace("_", "-") for token in raw if token not in STOPWORDS}444546def parse_frontmatter(text: str) -> dict[str, str]:47if not text.startswith("---\n"):48return {}49end = text.find("\n---", 4)50if end == -1:51return {}52result: dict[str, str] = {}53for line in text[4:end].splitlines():54if ":" not in line or line.startswith(" "):55continue56key, value = line.split(":", 1)57result[key.strip()] = value.strip().strip('"')58return result596061def activation_text(text: str) -> str:62frontmatter = parse_frontmatter(text)63parts = [frontmatter.get("description", "")]64match = re.search(r"## When to Activate\n(.+?)(?:\n## |\Z)", text, flags=re.DOTALL)65if match:66parts.append(match.group(1))67return "\n".join(parts)686970def load_skills(root: Path) -> dict[str, set[str]]:71skills: dict[str, set[str]] = {}72for path in sorted((root / "skills").glob("*/SKILL.md")):73skills[path.parent.name] = tokens(activation_text(path.read_text(encoding="utf-8")))74return skills757677def load_cases(path: Path) -> list[dict[str, Any]]:78cases: list[dict[str, Any]] = []79for line_number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), start=1):80if not line.strip():81continue82try:83cases.append(json.loads(line))84except json.JSONDecodeError as exc:85raise ValueError(f"{path}:{line_number} invalid JSONL: {exc}") from exc86return cases878889def rank_skills(prompt: str, skills: dict[str, set[str]]) -> list[dict[str, Any]]:90prompt_tokens = tokens(prompt)91ranked: list[dict[str, Any]] = []92for name, skill_tokens in skills.items():93shared = prompt_tokens & skill_tokens94score = len(shared) / max(len(prompt_tokens), 1)95ranked.append({"skill": name, "score": round(score, 4), "shared_terms": sorted(shared)})96ranked.sort(key=lambda item: (item["score"], item["skill"]), reverse=True)97return ranked9899100def evaluate(root: Path, cases_path: Path) -> dict[str, Any]:101skills = load_skills(root)102results: list[dict[str, Any]] = []103for case in load_cases(cases_path):104ranked = rank_skills(case["prompt"], skills)105top_three = [item["skill"] for item in ranked[:3]]106rejected_in_top_three = sorted(set(case.get("rejected_skills", [])) & set(top_three))107expected = case["expected_primary_skill"]108passed = expected in top_three and not rejected_in_top_three109results.append(110{111"case_id": case["case_id"],112"passed": passed,113"expected_primary_skill": expected,114"top_three": top_three,115"rejected_in_top_three": rejected_in_top_three,116"ranked": ranked[:5],117}118)119failures = [result for result in results if not result["passed"]]120return {121"ok": not failures,122"summary": {"cases": len(results), "failures": len(failures)},123"results": results,124}125126127def main() -> int:128parser = argparse.ArgumentParser(description="Check deterministic skill activation cases")129parser.add_argument("--root", type=Path, default=ROOT)130parser.add_argument(131"--cases",132type=Path,133default=ROOT / "researcher" / "fixtures" / "activation-cases.jsonl",134)135parser.add_argument("--json", action="store_true")136args = parser.parse_args()137138result = evaluate(args.root, args.cases)139if args.json:140print(json.dumps(result, indent=2))141else:142print(143f"Activation cases {'passed' if result['ok'] else 'failed'}: "144f"{result['summary']['cases']} cases, {result['summary']['failures']} failures"145)146for item in result["results"]:147if not item["passed"]:148print(f"- {item['case_id']}: expected {item['expected_primary_skill']} top={item['top_three']}")149return 0 if result["ok"] else 1150151152if __name__ == "__main__":153sys.exit(main())154