#!/usr/bin/env python3 """Check the packaged quota instructions without querying a vendor.""" from pathlib import Path import re import json import sys # The SKILL.md frontmatter this check reads is a fixed, tiny shape: scalar keys, and # `requires` holding two lists of inline maps. Parsing it here keeps the self-test on the # standard library; a PyYAML import would make deploying this skill fail on any machine # that does not happen to have it, and nothing in the repository installs it. def parse_frontmatter(text): def scalar(raw): raw = raw.strip() if len(raw) >= 2 and raw[0] == raw[-1] and raw[0] in "\"'": return raw[1:-1] return raw def inline_map(raw): raw = raw.strip() assert raw.startswith("{") and raw.endswith("}"), f"expected an inline map: {raw}" row = {} for pair in raw[1:-1].split(","): key, _, value = pair.partition(":") assert _, f"expected key: value in {pair}" row[key.strip()] = scalar(value) return row data, section, key = {}, None, None for line in text.split("\n"): if not line.strip() or line.lstrip().startswith("#"): continue indent = len(line) - len(line.lstrip()) stripped = line.strip() if stripped.startswith("- "): assert section is not None and key is not None, f"list item outside a mapping: {line}" data[section].setdefault(key, []).append(inline_map(stripped[2:])) continue name, _, value = stripped.partition(":") assert _, f"expected key: value in {line}" if indent == 0: section, key = (name, None) if not value.strip() else (None, None) if section is None: data[name] = scalar(value) else: data[section] = {} else: assert section is not None, f"nested key outside a mapping: {line}" key = name if value.strip(): data[section][key] = scalar(value) return data root = Path(__file__).resolve().parents[2] text = (root / "SKILL.md").read_text() try: assert not ((root / "scripts/subscription-quota-check").exists() or (root / "scripts/subscription-quota-check").is_symlink()), "runtime belongs to the installed core program, not this skill" contract = json.loads((root / "references/subscription-quota-check-contract.json").read_text()) assert contract["schema_version"] == 1 and contract["program"] == "subscription-quota-check", "public contract identity" assert contract["min_version"] == "1.0", "public contract version" allowed = set(contract["flags"]) for fragment in re.finditer(r"```[^\n]*\n(.*?)```|`([^`\n]+)`", text, re.S): code = fragment[1] if fragment[1] is not None else fragment[2] for command in re.finditer(r"(?