AFAdocs
CLI

afa enhance

Generate AI-powered enhancement candidates and validate them through nine quantitative gates.

afa enhance

Generate enhancement candidates for functions and validate them through all nine quantitative gates.

Usage

afa enhance <path> [options]

Arguments

ArgumentRequiredDescription
pathYesFile or directory to enhance

Options

FlagDefaultDescription
--dry-runfalseShow proposed changes without committing
--provideranthropicLLM provider
--formattableOutput format (table, json, sarif)

The enhancement loop

AFA runs a convergent loop per function:

Analyze --> Generate Candidates --> Gate Check (9 gates) --> Commit or Redesign

For each function:

  1. Analyze -- run all four analysis agents to identify improvement opportunities
  2. Generate -- create up to 3 enhancement candidates (configurable via enhancement.max_candidates)
  3. Gate check -- evaluate each candidate against all 9 quantitative gates
  4. Decide:
    • All gates pass --> commit the enhancement on an afa/ branch
    • Near miss (within 1.1x of thresholds) --> redesign and retry (up to 3 times)
    • Utility ratio < 1.0 --> skip (cost exceeds value)
    • Max retries exhausted --> skip

Dry run mode

Always start with --dry-run to see what AFA would do:

afa enhance src/ --dry-run

In dry-run mode, AFA runs the full pipeline -- analysis, generation, gate evaluation -- but does not create branches or commit changes. You see the proposed diff and gate results for every candidate.

Branch isolation

When not in dry-run mode, AFA creates changes on isolated branches using git worktrees:

  • Branch prefix: afa/ (configurable)
  • Worktree directory: temporary, cleaned up after commit
  • Your working tree is never modified directly
  • Changes never land on your main branch without a PR

What happens when gates fail

Each gate failure produces a diagnostic message:

GateFailure means
ComplexityEnhancement adds too much structural complexity (hard floor: 0.5, non-overridable)
Risk/ProfitChange doesn't measurably improve risk or profit metrics
NoveltyChange is too trivial to justify pipeline resources
QualityAggregate quality below 0.7 or a sub-score is zero
UtilityEconomic cost exceeds the value of the improvement
EntropyDiff has suspiciously low entropy (potential gaming)
Supply ChainBuild provenance verification failed
KPIEnhancement doesn't align with business KPIs

Use afa explain <enhancement-id> to get a detailed breakdown of why a specific enhancement was rejected.

Examples

# Dry-run a single file
afa enhance src/utils.py --dry-run

# Enhance a directory with Gemini
afa --provider gemini enhance src/afa/gates/

# JSON output for CI
afa --format json enhance src/ --dry-run

On this page