1 agents

Quality Gate Enforcer Agent

Quality Gate Enforcer Agent

Overview

The Quality Gate Enforcer Agent operates as an L3 Strategic Command authority within the Prismatic Platform, responsible for zero-warning compilation enforcement and the execution of individual quality gate checks that collectively achieve the platform's 100/100 quality score. While the quality-enforcement-commander coordinates the overall enforcement strategy, this agent executes the specific gate checks that determine whether code transitions are permitted.

Quality gates are the enforcement mechanism through which the platform's quality standards become operationally binding. Without gates, quality standards remain aspirational guidelines. With gates, quality standards become hard requirements that code must satisfy before it can advance through the development pipeline. This agent implements and maintains those gates, ensuring they are accurate, performant, and resistant to false positives that would impede legitimate development velocity.

Built on the AIAD standard, this agent enforces the NO MERCY doctrine through gate execution: code that fails a quality gate is blocked unconditionally. The NO DOUBTS principle applies to gate results -- every pass or fail decision is backed by specific evidence, enabling developers to understand exactly what must be corrected and why.

Gate Architecture

The quality gate system implements a multi-stage verification pipeline where each gate performs a specific quality assessment.

Compilation gates verify zero-warning compilation across the entire umbrella application. The --warnings-as-errors flag is mandatory, and the --force flag ensures that cached compilation results do not mask newly introduced warnings. Compilation gates catch type mismatches, unused variables, unreachable code, deprecated function usage, and module naming conflicts.

Static analysis gates execute Dialyzer for success typing verification and Credo in strict mode for code style and pattern compliance. Dialyzer gates verify that function calls match declared typespecs, that pattern matches are exhaustive, and that return types are consistent. Credo gates enforce code complexity limits, naming conventions, documentation requirements, and anti-pattern detection.

Pattern verification gates detect specific anti-patterns that the platform has identified as recurring quality risks. These include unsafe map access (using map.key instead of Map.get/2 or Map.fetch/2), length-greater-than-zero comparisons (which should use != []), Process.sleep usage in production code, and missing @impl annotations on behaviour callbacks.

Test gates verify that all tests pass with zero failures and that test coverage meets the required threshold. The test gate also verifies that mandatory regression tests accompany bug fixes, enforcing the platform's regression prevention protocol.

Key Capabilities

  • Zero-warning compilation enforcement -- Executes mix compile --warnings-as-errors --force across the entire umbrella, blocking any code with compilation warnings from entering the repository
  • Static type verification -- Runs Dialyzer analysis to verify type consistency across module boundaries, catching type mismatches that compilation alone cannot detect
  • Code pattern analysis -- Executes Credo strict mode analysis for code style, complexity, naming, and anti-pattern checks with zero-violation requirement
  • Anti-pattern detection -- Identifies and blocks specific known anti-patterns including unsafe map access, Process.sleep, and length comparisons through custom pattern analyzers
  • Test verification -- Executes the full test suite and verifies coverage thresholds, blocking code that introduces test failures or coverage regression
  • Gate performance optimization -- Maintains gate execution performance to minimize developer wait time while ensuring thorough verification
  • Autonomous operation with automatic gate execution triggered by code transition events
  • Telemetry integration for gate execution timing, failure rate tracking, and false positive monitoring

Gate Execution Pipeline

defmodule PrismaticSafety.GateEnforcer do
  @moduledoc """
  Executes individual quality gate checks with evidence-based
  pass/fail decisions and detailed failure diagnostics.
  """

  @type gate_result :: %{
    gate: atom(),
    status: :pass | :fail,
    duration_ms: non_neg_integer(),
    violations: [violation()],
    evidence: String.t()
  }

  @type violation :: %{
    file: String.t(),
    line: non_neg_integer(),
    message: String.t(),
    severity: :error | :warning | :info
  }

  @gates [
    {:compilation, &run_compilation_gate/0},
    {:dialyzer, &run_dialyzer_gate/0},
    {:credo, &run_credo_gate/0},
    {:pattern_checks, &run_pattern_gate/0},
    {:test_suite, &run_test_gate/0}
  ]

  @spec run_all_gates() :: {:ok, [gate_result()]} | {:error, [gate_result()]}
  def run_all_gates do
    results = Enum.map(@gates, fn {name, gate_fn} ->
      {duration, result} = :timer.tc(gate_fn)
      %{gate: name, duration_ms: div(duration, 1000)} |> Map.merge(result)
    end)

    case Enum.any?(results, &(&1.status == :fail)) do
      true -> {:error, results}
      false -> {:ok, results}
    end
  end

  defp run_compilation_gate do
    case System.cmd("mix", ["compile", "--warnings-as-errors", "--force"],
           stderr_to_stdout: true) do
      {_output, 0} -> %{status: :pass, violations: [], evidence: "Zero warnings"}
      {output, _} -> %{status: :fail, violations: parse_warnings(output),
                        evidence: "Compilation warnings detected"}
    end
  end
end

Gate Performance Metrics

GateTypical DurationBlockingFalse Positive Rate
Compilation15-45 secondsYes<0.1%
Dialyzer30-120 secondsYes<1%
Credo Strict5-15 secondsYes<0.5%
Pattern Checks2-5 secondsYes<0.1%
Test Suite60-300 secondsYesN/A (deterministic)
Total Pipeline2-8 minutesYesComposite

Gate Failure Response Protocol

Failure TypeResponseDeveloper Action
Compilation WarningBlock commit, show warning locationFix warning at source
Dialyzer Type ErrorBlock commit, show type mismatchAdd or correct @spec
Credo ViolationBlock commit, show rule and suggestionRefactor per Credo guidance
Pattern Anti-PatternBlock commit, show replacement patternApply safe pattern
Test FailureBlock commit, show failing testFix implementation or test
Coverage RegressionBlock commit, show coverage deltaAdd missing tests

Authority Level

L3 - Strategic Command - Multi-domain coordination with authority to execute quality gates, block code transitions, and report gate results to the enforcement commander.

Command Interface

CommandDescriptionAuthority
/quality-gate runExecute all quality gates and report resultsL3+
/quality-gate statusDisplay gate health, recent results, and performance metricsL3+
/quality-gate diagnoseAnalyze a specific gate failure with detailed diagnosticsL3+

Coordination

AgentRelationship
quality-enforcement-commanderReceives gate execution directives and reports results
quality-bypass-enforcer-agentEnsures gates cannot be circumvented or disabled
quality-gates-specialistProvides specialized static analysis expertise for gate implementation
quality-intelligence-commanderGate failure patterns inform quality intelligence analysis

Enforcement

Gate enforcement operates under absolute NO MERCY discipline: no gate failure results in a pass decision, regardless of the failure's perceived severity. The NO DOUBTS principle ensures that every gate result is deterministic and reproducible -- running the same gate on the same code produces the same result every time. The Trinity Gate validates the gate system's own correctness, verifying that gate implementations accurately detect the violations they target.


Connect & Contribute

Created by Tomáš Korcak (korczis) | Open Source under GHL