Skip to content

Quality check

quality_check

Quality-check hook for protocol pre-hook injection.

Injects a ready-to-read markdown summary of failed audit checks so the dev-ticket verify phase can act without re-running audit. The hook reuses the text field each rule already populates (one formatted line per violation with file:line and code), grouped by rule.

QualityCheckHook

Run audit categories and emit a text-only summary of failures.

Source code in packages/axm-audit/src/axm_audit/hooks/quality_check.py
Python
class QualityCheckHook:
    """Run audit categories and emit a text-only summary of failures."""

    def execute(
        self,
        context: dict[str, object],
        **params: object,
    ) -> HookResult:
        """Run audit on a project directory.

        Args:
            context: Hook context with ``working_dir``.
            **params: Optional ``categories`` list.

        Returns:
            HookResult with ``has_violations`` and ``summary`` metadata,
            plus a markdown ``text`` block containing each failed rule
            with its pre-formatted per-violation lines (file:line, code,
            message) ready for direct LLM consumption.
        """
        working_dir_param = params.get("working_dir") or context.get("working_dir", ".")
        working_dir = working_dir_param if isinstance(working_dir_param, str) else "."
        project_path = Path(working_dir)

        if not project_path.is_dir():
            return _clean_result()

        categories_param = params.get("categories", _DEFAULT_CATEGORIES)
        categories: list[str] = (
            [c for c in categories_param if isinstance(c, str)]
            if isinstance(categories_param, list)
            else _DEFAULT_CATEGORIES
        )
        failed_checks = _failed_checks_from(_run_audits(project_path, categories))

        if not failed_checks:
            return _clean_result()

        return _violations_result(failed_checks)
execute(context, **params)

Run audit on a project directory.

Parameters:

Name Type Description Default
context dict[str, object]

Hook context with working_dir.

required
**params object

Optional categories list.

{}

Returns:

Type Description
HookResult

HookResult with has_violations and summary metadata,

HookResult

plus a markdown text block containing each failed rule

HookResult

with its pre-formatted per-violation lines (file:line, code,

HookResult

message) ready for direct LLM consumption.

Source code in packages/axm-audit/src/axm_audit/hooks/quality_check.py
Python
def execute(
    self,
    context: dict[str, object],
    **params: object,
) -> HookResult:
    """Run audit on a project directory.

    Args:
        context: Hook context with ``working_dir``.
        **params: Optional ``categories`` list.

    Returns:
        HookResult with ``has_violations`` and ``summary`` metadata,
        plus a markdown ``text`` block containing each failed rule
        with its pre-formatted per-violation lines (file:line, code,
        message) ready for direct LLM consumption.
    """
    working_dir_param = params.get("working_dir") or context.get("working_dir", ".")
    working_dir = working_dir_param if isinstance(working_dir_param, str) else "."
    project_path = Path(working_dir)

    if not project_path.is_dir():
        return _clean_result()

    categories_param = params.get("categories", _DEFAULT_CATEGORIES)
    categories: list[str] = (
        [c for c in categories_param if isinstance(c, str)]
        if isinstance(categories_param, list)
        else _DEFAULT_CATEGORIES
    )
    failed_checks = _failed_checks_from(_run_audits(project_path, categories))

    if not failed_checks:
        return _clean_result()

    return _violations_result(failed_checks)