Skip to content

Protocols

protocols

check_author_grammar(project)

Validate import-time forms through syntax and resolved imports.

Source code in packages/axm-init/src/axm_init/checks/protocols.py
Python
def check_author_grammar(project: Path) -> CheckResult:
    """Validate import-time forms through syntax and resolved imports."""
    context = _protocol_package(project)
    details = [] if context is None else _author_findings(project, context[2])
    return _content_result("author_grammar", details, applicable=context is not None)

check_protocol_assembly(project)

Validate assembly factories and graph identities statically.

Source code in packages/axm-init/src/axm_init/checks/protocols.py
Python
def check_protocol_assembly(project: Path) -> CheckResult:
    """Validate assembly factories and graph identities statically."""
    context = _protocol_package(project)
    details = (
        []
        if context is None
        else _assembly_findings(project, context[0], context[1], context[2])
    )
    return _content_result("protocol_assembly", details, applicable=context is not None)

check_protocol_components(project)

Validate principal components without importing inspected code.

Source code in packages/axm-init/src/axm_init/checks/protocols.py
Python
def check_protocol_components(project: Path) -> CheckResult:
    """Validate principal components without importing inspected code."""
    context = _protocol_package(project)
    details = [] if context is None else _component_findings(project, context[2])
    return _content_result(
        "protocol_components", details, applicable=context is not None
    )

check_protocols_profile(project)

Validate a declared protocol profile without importing inspected code.

Source code in packages/axm-init/src/axm_init/checks/protocols.py
Python
def check_protocols_profile(project: Path) -> CheckResult:
    """Validate a declared protocol profile without importing inspected code."""
    metadata = project / "pyproject.toml"
    try:
        text = metadata.read_text(encoding="utf-8")
        data = cast("dict[str, object]", tomllib.loads(text))
    except (OSError, tomllib.TOMLDecodeError) as exc:
        return CheckResult(
            name="protocols.profile",
            category=_CATEGORY,
            passed=False,
            weight=4,
            message="Protocol metadata is unreadable",
            details=[f"pyproject.toml:1: {exc}. Correction: fix the TOML metadata"],
            fix="Fix pyproject.toml before validating the protocol profile.",
        )

    profile = _nested(data, "tool", "axm-init", "protocols")
    if profile is None:
        workspace_result = _workspace_protocol_result(project)
        if workspace_result is not None:
            return workspace_result
        return CheckResult(
            name="protocols.profile",
            category=_CATEGORY,
            passed=True,
            weight=0,
            message="Protocol profile not declared",
            details=[],
            fix="",
        )

    details: list[str] = []
    schema_version = profile.get("schema_version")
    if schema_version != _SCHEMA_VERSION:
        details.append(
            _finding(
                text,
                "schema_version",
                f"unsupported schema_version {schema_version!r}",
                f"set schema_version = {_SCHEMA_VERSION}",
            )
        )

    domain = _validate_identity(data, profile, text, details)
    units = _validate_units(text, profile, details)
    if domain is not None:
        _validate_wheel_inclusion(data, text, domain, details)
        _validate_protocol_tree(project, text, domain, units, details)

    passed = not details
    return CheckResult(
        name="protocols.profile",
        category=_CATEGORY,
        passed=passed,
        weight=4,
        message=(
            "Protocol profile is statically coherent"
            if passed
            else f"Protocol profile has {len(details)} finding(s)"
        ),
        details=details,
        fix="" if passed else "Apply every correction listed in the findings.",
    )

check_protocols_resources(project)

Validate declared prompt files and their distribution configuration.

Source code in packages/axm-init/src/axm_init/checks/protocols.py
Python
def check_protocols_resources(project: Path) -> CheckResult:
    """Validate declared prompt files and their distribution configuration."""
    metadata = project / "pyproject.toml"
    try:
        text = metadata.read_text(encoding="utf-8")
        data = cast("dict[str, object]", tomllib.loads(text))
    except (OSError, tomllib.TOMLDecodeError):
        return CheckResult(
            name="protocols.protocols_resources",
            category=_CATEGORY,
            passed=True,
            weight=0,
            message="Protocol prompt resources are not applicable",
            details=[],
            fix="",
        )

    profile = _nested(data, "tool", "axm-init", "protocols")
    if profile is None:
        workspace_result = _workspace_protocol_resources_result(project)
        if workspace_result is not None:
            return workspace_result
        return CheckResult(
            name="protocols.protocols_resources",
            category=_CATEGORY,
            passed=True,
            weight=0,
            message="Protocol profile not declared",
            details=[],
            fix="",
        )

    prompt_paths = _declared_prompt_paths(project, profile)
    details = _missing_prompt_findings(project, text, prompt_paths)
    details.extend(
        _excluded_prompt_findings(project, text, data, profile, prompt_paths)
    )

    passed = not details
    return CheckResult(
        name="protocols.protocols_resources",
        category=_CATEGORY,
        passed=passed,
        weight=2,
        message=(
            "Protocol prompt resources are present and distributable"
            if passed
            else f"Protocol prompt resources have {len(details)} finding(s)"
        ),
        details=details,
        fix="" if passed else "Apply every correction listed in the findings.",
    )