VAR

How it works

Pipeline overview

When you run vary var, the command executes these stages in order:

Discovery -> Check -> Test -> Prove -> Mutation -> Review -> Classification

Each stage either runs, is skipped (not needed), or is blocked (a prerequisite failed). The decision policy makes this determination before each stage begins.

Stage 1: Discovery

Detects what changed. In a git repository, VAR runs git diff and git status against a base ref (defaulting to HEAD, configurable with --since-ref). Each changed file is classified:

CategoryExamples
Source.vary files in src/, lib/, main directories
Test.vary files in tests/, files matching test_*.vary
Configvary.toml, .vary/, configuration files
Docs.md, .txt, documentation directories
BuildMakefile, build.gradle, CI configuration
OtherEverything else

Each file also gets a code area label (PURE_LOGIC, EFFECTS, BOUNDARIES) that the decision policy uses for significance scoring.

In non-git environments (extracted tarballs, CI scratch spaces), VAR falls back to filesystem scanning with modification-time detection.

In a git repository Discovery also compares each changed .vary file with its base by AST and lists the changed functions: whether the body, the signature or the contract changed (a contract clause is added or removed, and an out clause is strengthened or weakened), and which test files name the function. Comments, blank lines, formatting and docstrings are not changes. A change to anything that is not a function (a type, a constant) is reported as one <declarations> entry. Where there is no git base the file is judged as a whole.

Discovery also computes a change fingerprint: a SHA-256 hash of the sorted file paths and their modification times. This fingerprint is compared to the previous session to detect working-tree drift.

Stage 2: Check

Scoped static analysis. VAR runs the same checks as vary check, but only on changed files (source and test, excluding deleted). The result is a count of errors and warnings with per-file detail.

A changed file that vary fmt would rewrite is a blocking finding (VF001, "not Varyonic: unformatted"); the fix is vary fmt <file>, and VAR does not rewrite files itself. A mechanical finding (one that has a fix) blocks only inside a changed function or a function in the same file that calls one, so an existing project is not asked to rewrite code the change did not touch.

If check finds errors, the pipeline records them as blockers. Downstream stages may still run depending on the decision policy, but the terminal state will be BLOCKED.

Stage 3: Test

Targeted test execution. VAR discovers test files covering the changed modules using path-based heuristics:

HeuristicHow it works
Adjacencytest_<module>.vary next to the source file
Directory scantests/ directory entries matching the module name

When the changed functions are known, tests that name one of them (or a function that calls one) are preferred; if none does, the whole selection runs. Only the relevant tests run, not the full suite. The result is passed/failed/skipped counts with per-file detail.

Stage 4: Prove

After the tests pass, VAR runs vary prove on each changed function that carries a contract (in, out or post). A refuted, vacuous or replay-mismatch result blocks the pipeline and holds back mutation, because a contract that is wrong or empty is not worth mutating. An unknown or unsupported result is advice with its reason. Proofs are cached per function, so a re-run costs little. --no-prove skips the stage.

Prove:    1 proven, 1 refuted
Blocking: scale is refuted (out r >= 0); vary prove calc.vary --function scale

Stage 5: Mutation

Source-level mutation testing on changed source files (test files and non-.vary files are excluded). It runs at the default cost for a change the decision policy rates significant, and --no-mutation skips it.

Mutation is limited to the changed functions and the functions in the same file that call them, with fast mode and incremental inference on, so a one-function change mutates a handful of mutants rather than the file.

The mutation engine applies small code changes (replacing operators, flipping conditions, removing statements) and runs the targeted tests against each mutant. The result is a per-file and aggregate mutation score. The quality gate defaults to a 70% kill rate.

Stage 6: Review

Generates a review closeout packet. Only runs when you pass --include-review-packet. The packet covers what changed, what the checks and tests found, mutation scores if available, and a confidence level.

Validation regressions

Alongside the stages, VAR compares each changed file with its git base for changes that make the validation weaker. Each one blocks until a person accepts it:

RegressionWhat counts
Test removedA test block or def test_* that was in the base is gone
Assertion weakenedAn observe or assert that became an inequality or a constant, or one removed from a surviving test
Contract weakenedAn in clause added to a public function, or an out, post or invariant clause removed
New suppressionA # vary-ignore-next-line, a rule turned off or lowered in [check.rules], or a [format] key added to vary.toml
Threshold loweredA min_* number under [mutation], a lower max_cost, or a shrunk prove baseline
New !!A !! added to a function in library code (not tests, not main)

Each regression has a stable id, derived from what it is, so accepting one does not accept the next:

Regression R-352a463c (assertion weakened): test "arith" asserts 1 fewer thing(s); needs a person: vary var accept R-352a463c --reason "..."

A person accepts one with vary var accept <id> --reason "why". The acceptance is recorded in .vary/var/accepted-regressions.jsonl and listed in the review packet beside the regression. An acceptance recorded from inside an agent session (Claude Code, or any process with VARY_AGENT_SESSION set) is kept on file but does not count: only a person can accept a weakening.

Tasks and the next command

The JSON output has a tasks array in the order to do them: take back a weakening (undo_regression), format (run_fmt), apply a fix (apply_fix), fix a check finding (fix_check), fix a failing test (fix_test), fix a refuted contract (fix_refutation), kill a surviving mutant (kill_survivor, or strengthen_test when a function has three), add a missing test (add_test). Each task carries command (what to run to do it, when a command does it), verify (what shows it is done), the proposed edit from a check rule, and an example (a surviving mutant as a diff). nextCommand is the first task's command or verify command, never a bare rerun of vary var.

vary var --next prints only the first task, for an agent that loses focus on long lists.

When the same task is first for three runs in a row, VAR cuts the list down to that one task and says to do exactly that. After five runs it returns needs_human with what was tried instead of letting the loop go on.

Done means done

A run is complete only when all of these hold: every changed file is in vary fmt form, there are no blocking tasks, every validation regression has been accepted by a person, every changed function is named by a test, and every changed contract is proven or unknown with a stated reason. The last two can be switched off in vary.toml; the others cannot, and there is no switch for the Varyonic requirement.

[var]
require_tests = true               # every changed function is named by a test
require_contracts_resolved = true  # every changed contract is proven, or unknown with a reason

The Stop hook

vary var --hook stop is for an agent's Stop hook. It prints nothing and exits 0 when the run is complete (or there is nothing to review). When it is not, it prints the first task on stderr and exits 2, which Claude Code reads as "do not stop yet" and feeds back to the agent. A task that needs a person exits 0 with the message, so the hook never traps an agent in a loop it cannot leave. vary new --agent claude installs it in .claude/settings.json; remove it there if you do not want it. Other agents can run the same command where they support hooks.

Stage 7: Classification

The final stage maps accumulated results and blockers into a terminal state:

StateCondition
CompleteAll executed stages passed
BlockedOne or more stages have hard failures
PartialSome stages ran, others were skipped by budget or scope
AdvisoryInformational run (e.g., discovery-only) with no blocking findings

The classification also includes a recommendation (the next command to run) and a confidence level: high, medium, or low.

Resumption

On the next invocation, the pipeline loads the previous session. If the change fingerprint matches (no new edits), it resumes from the first incomplete stage. If the fingerprint changed, it resets to discovery.

The workflow is: run vary var, fix what it reports, run vary var again. Each cycle narrows the remaining work until the terminal state is COMPLETE.

← Overview
CLI reference →