/cascade

Quality L3 Production medium usage

/cascade

Overview

/cascade is a production command in the Quality category of the Prismatic Platform that executes systematic CASCADE pattern fixes for anti-pattern removal across the entire codebase. CASCADE -- an acronym representing Concentrated Anti-pattern Strike with Cascading Automated Detection and Elimination -- provides a surgical, file-by-file approach to quality debt that targets high-concentration violation hotspots for maximum production impact with zero regression risk.

Unlike traditional linting or static analysis tools that merely report violations, the /cascade command operates as a complete elimination pipeline: it detects anti-patterns, plans strike sequences, executes fixes with rollback safety, verifies compilation integrity, and generates comprehensive impact reports. The command has been battle-tested through real ARCHER SUPREME missions, where a single session eliminated 88 unsafe map access violations from 8 production-critical files with zero regressions.

This command operates under the L3 authority level and is executed by the cascade-eliminator agent. It is part of the platform's 216-command slash command registry, built on the AIAD (Autonomous Intelligence Agent Design) standard. The CASCADE system covers 13 quality domains with 40 pattern definitions stored in a structured PatternDB, enabling detection of everything from unsafe atom creation to stale TODO comments.

The CASCADE approach represents a fundamental shift from reactive quality maintenance to proactive, systematic elimination. By focusing on files with the highest concentration of violations, each strike maximizes the ratio of quality improvement per unit of developer effort, delivering measurable production stability improvements.

Architecture

The CASCADE system is built on three core components that work together to deliver zero-regression quality improvement.

PatternDB

The PatternDB contains 40 anti-pattern definitions across 13 quality domains. Each pattern includes a detection regex, severity classification, confidence score, and an automated fix template. Patterns are organized by domain for targeted scanning.

Scanner

The Scanner traverses specified scopes using git ls-tree for performance-optimized file discovery. It applies PatternDB patterns against each file, calculates violation concentrations, and ranks files by elimination priority. The scanner operates in read-only mode and never modifies source files.

Fixer

The Fixer applies automated transformations based on PatternDB fix templates. Every fix is followed by mandatory compilation verification (mix compile --warnings-as-errors), test execution, and quality gate validation. If any safety check fails, the fixer automatically rolls back using git checkout HEAD.

PatternDB (40 patterns)
    |
    v
Scanner ──> Violation Report ──> Priority Ranking
    |                                    |
    v                                    v
Fixer ──> Apply Fix ──> Safety Verify ──> Commit or Rollback

13 Quality Domains

DomainIDPatternsSeverityExample Violations
DialyzerD14High-CriticalType mismatches, conflicting specs
CredoD25Low-MediumCode style, complexity
CompilationD35Low-CriticalUnused variables, unreachable code
DateTimeD41MediumPrecision issues in timestamps
GuardsD54HighInvalid guard expressions
@implD64LowMissing @impl annotations
MemoryD72CriticalString.to_atom, unbounded atom creation
PerformanceD86Medium-HighO(n) patterns, unnecessary traversals
RegressionD91CriticalBreaking interface changes
TimingD101HighProcess.sleep in production code
TODOD111LowStale TODO/FIXME comments
TypespecD124Low-MediumMissing @spec, vague term() types
Map AccessD132Medium-HighUnsafe bracket access on maps

Usage

Basic Operations

# Scan entire codebase for quality violations
/cascade detect

# Scan with summary output only
/cascade detect --summary

# Focus on critical violations with high confidence
/cascade detect --critical --min-confidence 0.90

# Target specific pattern type
/cascade detect --pattern unsafe_map_access --scope apps/prismatic/

# Multi-pattern analysis across all domains
/cascade detect --pattern all --scope apps/ --min-concentration 3

Planning and Execution

# Generate elimination plan
/cascade plan --scope apps/ --pattern unsafe_map_access

# Preview fixes without applying (dry run)
/cascade fix --dry-run

# Execute fixes with interactive review
/cascade fix --interactive

# Automated fix for high-confidence violations
/cascade fix

# Single file strike with safety verification
/cascade strike apps/prismatic/lib/error_ledger/event.ex --pattern unsafe_map_access --verify-safety

Mix Task Interface

# Scan using mix task
mix cascade.scan

# Scan with summary
mix cascade.scan --summary

# Critical only with minimum confidence
mix cascade.scan --critical --min-confidence 0.90

# Fix with preview
mix cascade.fix --dry-run

# Install pre-commit hooks
./.githooks/install-cascade-hooks.sh

Options & Parameters

ParameterTypeDefaultDescription
scopestringapps/Target directory scope for analysis
patternstringunsafe_map_accessPattern type to target or all
operationstringdetectOperation: detect, plan, strike, eliminate, verify, report
safety_levelstringzero_toleranceSafety: standard, strict, zero_tolerance
min_concentrationinteger5Minimum violations per file for targeting
verify_safetybooleantrueEnforce zero-regression verification
--dry-runbooleanfalsePreview without applying changes
--interactivebooleanfalseInteractive fix review mode
--criticalbooleanfalseCritical severity violations only
--min-confidencefloat0.0Minimum confidence threshold for fixes

Execution Flow

The CASCADE command follows a six-phase execution pipeline, each phase gated by safety verification.

PHASE 1: DETECTION
    |-- Traverse scope using git ls-tree
    |-- Apply PatternDB patterns to each file
    |-- Calculate violation concentrations
    |-- Rank files by priority (concentration * severity)
    |
PHASE 2: PLANNING
    |-- Generate strike sequence (highest concentration first)
    |-- Estimate duration per file
    |-- Calculate total elimination potential
    |-- Present plan for approval
    |
PHASE 3: STRIKE EXECUTION
    |-- Process files in priority order
    |-- Apply fix template for each violation
    |-- Track changes with git diff
    |-- Log each transformation
    |
PHASE 4: SAFETY VERIFICATION (per file)
    |-- mix compile --warnings-as-errors --force
    |-- mix credo --strict
    |-- mix test (affected modules)
    |-- mix quality.gates
    |
PHASE 5: ROLLBACK OR COMMIT
    |-- If safety fails: git checkout HEAD -- <file>
    |-- If safety passes: stage changes
    |-- Record elimination metrics
    |
PHASE 6: REPORTING
    |-- Generate elimination report
    |-- Calculate production impact score
    |-- Emit telemetry events
    |-- Save to .claude/reports/cascade/

Integration Points

ComponentRelationshipDetails
Prismatic AgentsExecuted by cascade-eliminator agentPrimary execution agent
AIAD RegistryCommand specification and discoveryStandard AIAD command interface
Quality GatesDirect quality gate enforcementMandatory post-fix verification
TelemetryExecution metrics and event trackingReal-time progress telemetry
Pre-commit Hooks.githooks/pre-commit-cascadeAutomated cascade checks before commit
CI/CD PipelineGitLab CI integrationMerge request quality gating
ARCHER SUPREMEStrategic coordinationCan invoke CASCADE for impossible missions
Mycelial PropagationPattern distributionCASCADE patterns propagate across domains

CI/CD Integration Example

cascade_quality_check:
  stage: quality
  script:
    - mix cascade.scan --critical
    - mix cascade.scan --min-concentration 3
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'

Best Practices

  1. Start with Detection: Always run /cascade detect before attempting fixes to understand the scope and distribution of violations across the codebase.

  2. Target High-Concentration Files First: Files with 8 or more violations yield the best return on effort. Use --min-concentration 8 to focus on these hotspots.

  3. Use Dry Run Mode: Before executing fixes on production code, run /cascade fix --dry-run to preview all proposed changes without modification risk.

  4. Single Pattern Per Session: Focus on one pattern type per CASCADE session for cleaner commits and easier review. Mixing patterns in a single session increases cognitive load.

  5. Verify Between Strikes: The command automatically verifies after each file, but for critical codebases, consider running the full test suite between file groups.

  6. Document Elimination Decisions: When a fix transforms code structure significantly, add inline comments explaining the safety rationale.

Error Handling & Troubleshooting

ErrorCauseResolution
SAFETY VIOLATION - ROLLED BACKFix caused compilation warning or test failureReview the specific fix, adjust manually
LOW CONFIDENCEPattern match below thresholdIncrease confidence with --min-confidence 0.95
NO VIOLATIONS FOUNDPattern not present in scopeVerify scope path and pattern name
COMPILATION TIMEOUTLarge codebase compilation during verifyIncrease timeout or narrow scope
INSUFFICIENT CONCENTRATIONFile below min_concentration thresholdLower threshold or target different files

Advanced Usage

CASCADE Pattern Library

The five established CASCADE fix patterns cover the most common transformations:

# Pattern 1: Simple Map Access
# Before: map["key"]
# After:  Map.get(map, "key")

# Pattern 2: Default Value
# Before: map["key"] || default
# After:  Map.get(map, "key", default)

# Pattern 3: Dual Key Support
# Before: map[:key] or map["key"]
# After:  Map.get(map, :key) with fallback

# Pattern 4: Test Assertions
# Before: assert result["field"] == value
# After:  assert Map.get(result, "field") == value

# Pattern 5: Nested Access
# Before: map["a"]["b"]["c"]
# After:  get_in(map, ["a", "b", "c"])

Batch Elimination Across Domains

# Eliminate all memory-safety violations platform-wide
/cascade eliminate --pattern string_to_atom --scope apps/ --safety-level zero_tolerance

# Chain multiple pattern eliminations
/cascade eliminate --pattern unsafe_map_access --verify-safety
/cascade eliminate --pattern process_sleep --verify-safety
/cascade eliminate --pattern guard_violations --verify-safety

Historical Results

The CASCADE system has demonstrated measurable impact in production sessions. In the ARCHER SUPREME session of 2025-11-30, the command eliminated 88 violations from 8 production files with zero regressions, directly preventing 88 potential runtime crashes. Total platform quality debt was reduced from 144 to 56 violations (61% reduction) in under 20 minutes.

Performance

MetricValueNotes
Detection Speed~80ms per 1000 filesUses git ls-tree optimization
Fix Application~200ms per violationIncluding pattern matching and substitution
Safety Verification~10-30s per fileFull compile + test cycle
Total Session15-45 minutesDepends on violation count and scope
Rollback Speed<1s per fileInstant git checkout recovery

Doctrine Compliance

All CASCADE operations operate under the NO MERCY, NO DOUBTS doctrine:

  • NO MERCY: Zero tolerance for quality violations. Every detected anti-pattern is either eliminated or explicitly documented with justification for deferral. No incomplete strikes are accepted.
  • NO DOUBTS: Full investigation before action. Detection phase provides complete visibility before any fix is applied. Every fix is evidence-validated through compilation and testing.

The CASCADE system enforces the mandatory regression test protocol: every fix must pass safety verification, and any regression triggers automatic rollback with detailed failure analysis.

  • /quality-gates - Enforce quality gate checkpoints with zero-warning compilation validation
  • /quality-enforce - Mandatory progressive quality debt elimination with AIAD enforcement
  • /regression-check - Execute 25 custom Credo regression checks preventing 700+ violations
  • /code - Core coding implementation and feature development
  • /fix - Bug fix implementation with mandatory regression tests
  • /refactor - Safe refactoring with zero-regression guarantee
  • /darwinize - Natural selection operation for evolutionary fitness optimization
  • /evolve - Living AIAD ecosystem evolution with 5-phase cycle

Connect & Contribute

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