Skip to content

hashgraph-online/awesome-codex-plugins / plugins/aklofas/kicad-happy/skills/datasheets

datasheets

Verified

Extract structured specifications from electronic component datasheet PDFs — pinouts, electrical characteristics, peripherals, topology, and features. Cache extractions per project for consumption by schematic and PCB analyzers. Primary consumer infrastructure for `kicad`, `emc`, `spice`, and `thermal` analyzers. Use this skill whenever the user asks to extract, verify, or read specs from a component datasheet; when analyzers need verified IC knowledge (EN pin thresholds, PG presence, USB peripheral speed); or when a review mentions datasheet coverage, extraction quality, or per-MPN specifications. Also triggers on "extract this datasheet", "what are the specs for MPN X", "verify datasheet extraction", or "check pin functions for part Y".

FileKindSize
SKILL.mdskill md11.2 KB
datasheet_types/__init__.pyscript1.9 KB
datasheet_types/base_block.pyscript6.5 KB
datasheet_types/cache_reader.pyscript12.3 KB
datasheet_types/codec.pyscript6.3 KB
datasheet_types/extraction.pyscript8.0 KB
datasheet_types/pinout.pyscript5.2 KB
datasheet_types/regulator.pyscript5.3 KB
datasheet_types/spec_value.pyscript2.4 KB
datasheet_types/trust_gating.pyscript5.0 KB
distributor_core/__init__.pyscript0 B
distributor_core/cli.pyscript2.9 KB
distributor_core/download.pyscript36.7 KB
distributor_core/inputs.pyscript9.0 KB
distributor_core/manifest.pyscript5.7 KB
distributor_core/sync.pyscript21.0 KB
distributor_core/verify.pyscript12.1 KB
examples/abm8g-106-12.000mhz-t.jsonconfig9.4 KB
examples/irlml6344.jsonconfig16.0 KB
examples/lm2596-adj.jsonconfig14.3 KB
examples/lm358.jsonconfig15.6 KB
examples/mbrs540t3g.jsonconfig12.3 KB
examples/stm32f103c8t6.jsonconfig51.1 KB
prompts/base.mdmarkdown4.5 KB
prompts/crystal.mdmarkdown8.8 KB
prompts/diode.mdmarkdown8.3 KB
prompts/mcu.mdmarkdown9.6 KB
prompts/opamp.mdmarkdown10.7 KB
prompts/pinout.mdmarkdown4.7 KB
prompts/regulator.mdmarkdown4.4 KB
prompts/scout.mdmarkdown3.5 KB
prompts/transistor.mdmarkdown12.5 KB
references/cache-layout.mdmarkdown8.4 KB
references/consumer-api.mdmarkdown10.8 KB
references/dispatch-claude-code.mdmarkdown9.4 KB
references/dispatcher-contract.mdmarkdown8.2 KB
references/extraction-pipeline.mdmarkdown1.7 KB
references/extraction-schema.mdmarkdown18.0 KB
references/field-extraction-guide.mdmarkdown14.9 KB
references/quality-scoring.mdmarkdown8.4 KB
schemas/CHANGELOG.mdmarkdown16.0 KB
schemas/base.schema.jsonconfig9.3 KB
schemas/crystal.schema.jsonconfig7.2 KB
schemas/diode.schema.jsonconfig7.9 KB
schemas/extraction.schema.jsonconfig3.7 KB
schemas/fixtures/lm2596-adj.example.jsonconfig14.3 KB
schemas/fixtures/manifest.example.jsonconfig1000 B
schemas/fixtures/minimal.example.jsonconfig2.1 KB
schemas/manifest.schema.jsonconfig3.0 KB
schemas/mcu.schema.jsonconfig12.4 KB
schemas/opamp.schema.jsonconfig9.2 KB
schemas/pinout.schema.jsonconfig5.9 KB
schemas/plan.schema.jsonconfig4.6 KB
schemas/regulator.schema.jsonconfig8.4 KB
schemas/scout.schema.jsonconfig2.9 KB
schemas/spec_value.schema.jsonconfig3.0 KB
schemas/transistor.schema.jsonconfig12.0 KB
scripts/_smoke_v14_roundtrip.pyscript8.9 KB
scripts/datasheet_extract_cache.pyscript21.2 KB
scripts/datasheet_features.pyscript17.1 KB
scripts/datasheet_page_selector.pyscript16.7 KB
scripts/datasheet_score.pyscript15.5 KB
scripts/datasheet_verify.pyscript45.6 KB
scripts/extraction_schema.pyscript1.8 KB
scripts/merge_results.pyscript13.0 KB
scripts/plan_extraction.pyscript9.5 KB
scripts/validate_extraction_result.pyscript4.0 KB
scripts/validate_sanity_vector.pyscript6.4 KB

scripts/validate_sanity_vector.py

View on GitHub
#!/usr/bin/env python3
"""Diff a harness sanity vector against an extraction JSON.

Used by the harness 4-check acceptance gate (check #4). Pure function: no
LLM, no state, no network. Loads YAML vector, walks per-field expected
values, resolves dotted paths against extraction JSON, compares within
declared tolerance.
"""

from __future__ import annotations

import argparse
import json
import sys
from pathlib import Path


DEFAULT_TOLERANCE_PCT = 5.0


def _resolve_path(extraction: dict, dotted: str):
    """Resolve a dotted path. Each segment is a dict key.

    Lists at the terminal position are unwrapped via `_spec_value_pick`;
    intermediate list indices are NOT supported (e.g., 'regulator.vin_range[0].max').
    Only single-condition SpecValue lists are supported; multi-condition
    indexing is not.
    """
    cur = extraction
    for part in dotted.split("."):
        if not isinstance(cur, dict) or part not in cur:
            return None
        cur = cur[part]
    return cur


def _spec_value_pick(value, key: str):
    """SpecValue lists carry [{min, typ, max, unit, ...}]. Scalars are used as-is.

    For list values, we pick the first element's `key` (single-condition lists only).
    For scalar values (int/float/bool/str), only the `typ` key has meaning — the
    scalar IS the typical value, with no min/max/unit. This lets sanity vectors
    write `expected: {typ: 5}` for plain scalar fields like `package.pin_count`.
    """
    if isinstance(value, list) and value:
        return value[0].get(key) if isinstance(value[0], dict) else None
    if isinstance(value, dict):
        return value.get(key)
    if isinstance(value, (int, float, bool, str)):
        return value if key == "typ" else None
    return None


def _within_tolerance(actual: float, expected: float, tol_pct: float) -> bool:
    if expected == 0:
        return abs(actual) <= tol_pct / 100.0
    return abs((actual - expected) / expected) * 100.0 <= tol_pct


def _check_numeric_spec(actual_value, expected: dict, tol_pct: float) -> tuple[bool, str | None, dict]:
    """`expected` like {min: 4.5, typ: null, max: 40, unit: 'V'}.
    Each populated key (min/typ/max) must match within tolerance.
    Unit must match exactly (string compare).
    Returns (pass, reason, debug_dict).
    """
    debug = {"checked": [], "actual": {}}
    if actual_value is None:
        return False, "missing in extraction", debug

    if "unit" in expected:
        actual_unit = _spec_value_pick(actual_value, "unit")
        debug["actual"]["unit"] = actual_unit
        if actual_unit != expected["unit"]:
            return False, f"unit mismatch: expected {expected['unit']!r}, got {actual_unit!r}", debug

    for key in ("min", "typ", "max"):
        if key not in expected or expected[key] is None:
            continue
        actual_n = _spec_value_pick(actual_value, key)
        debug["actual"][key] = actual_n
        if actual_n is None:
            return False, f"{key} missing", debug
        try:
            actual_f = float(actual_n)
            exp_f = float(expected[key])
        except (TypeError, ValueError):
            return False, f"{key} not numeric (actual={actual_n!r}, expected={expected[key]!r})", debug
        if not _within_tolerance(actual_f, exp_f, tol_pct):
            return False, f"{key}={actual_f} outside ±{tol_pct}% of {exp_f}", debug
        debug["checked"].append(key)
    return True, None, debug


def _check_enum(actual_value, expected_enum) -> tuple[bool, str | None]:
    """`expected_enum` is either a scalar string or a list of strings."""
    allowed = expected_enum if isinstance(expected_enum, list) else [expected_enum]
    if actual_value in allowed:
        return True, None
    return False, f"expected one of {allowed}, got {actual_value!r}"


def diff(vector: dict, extraction: dict) -> dict:
    fields_out = []
    for f in vector.get("fields", []):
        path = f["path"]
        actual = _resolve_path(extraction, path)
        entry = {"path": path, "expected": None, "actual": None, "pass": False, "reason": None}
        if "expected_enum" in f:
            entry["expected"] = f["expected_enum"]
            entry["actual"] = actual if not isinstance(actual, dict) else _spec_value_pick(actual, "value")
            if actual is None:
                entry["pass"] = False
                entry["reason"] = "missing in extraction"
            else:
                ok, why = _check_enum(actual, f["expected_enum"])
                entry["pass"] = ok
                entry["reason"] = why
        elif "expected" in f:
            tol = float(f.get("tolerance_pct", DEFAULT_TOLERANCE_PCT))
            entry["expected"] = f["expected"]
            ok, why, dbg = _check_numeric_spec(actual, f["expected"], tol)
            entry["pass"] = ok
            entry["reason"] = why
            entry["actual"] = dbg["actual"]
            entry["tolerance_pct"] = tol
        else:
            entry["reason"] = "vector field has neither expected nor expected_enum"
        if "page" in f:
            entry["expected_page"] = f["page"]
        fields_out.append(entry)
    passed = sum(1 for x in fields_out if x["pass"])
    failed = len(fields_out) - passed
    return {
        "schema_version": "1.0",
        "mpn": vector.get("mpn"),
        "fields": fields_out,
        "summary": {"total": len(fields_out), "passed": passed, "failed": failed},
    }


def main(argv: list[str] | None = None) -> int:
    ap = argparse.ArgumentParser(description="Diff a sanity vector against an extraction JSON.")
    ap.add_argument("vector_path", type=Path)
    ap.add_argument("extraction_path", type=Path)
    args = ap.parse_args(argv)

    import yaml
    vector = yaml.safe_load(args.vector_path.read_text(encoding="utf-8"))
    try:
        extraction = json.loads(args.extraction_path.read_text(encoding="utf-8"))
    except (json.JSONDecodeError, RecursionError) as exc:
        print(f"error: extraction file is not valid JSON: {exc}", file=sys.stderr)
        return 1
    report = diff(vector, extraction)
    print(json.dumps(report, indent=2, default=str))
    return 0 if report["summary"]["failed"] == 0 else 1


if __name__ == "__main__":
    for _stream in (sys.stdout, sys.stderr):  # UTF-8 on a cp1252 pipe (Windows)
        if hasattr(_stream, "reconfigure"):
            _kw = {"newline": "\n"}
            if (getattr(_stream, "encoding", "") or "").lower().replace("-", "") != "utf8":
                _kw.update(encoding="utf-8", errors="backslashreplace")
            _stream.reconfigure(**_kw)
    sys.exit(main())
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 319kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 319kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 319kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 196kUpdated Claude CodeCodexVerifiedInstall