Exit codes

The exit-code contract and structured output for scripts and agents.

MCMC.js is built to be driven by scripts and AI agents as well as humans, so it follows a small, documented exit-code contract. A caller can branch on the exit code without parsing any text.

The contract

CodeMeaning
0ok, or converged
1error: the command itself failed (bad input, missing file, toolchain problem)
2ran but a domain check failed, for example a fit that did not converge

Code 2 is the important one: it distinguishes “the tool worked, but the result did not meet the bar” from “the tool broke.” mcmc run and mcmc diagnose use it for non-convergence; the verdict line and the table are still printed.

if mcmc diagnose; then
  echo "converged"
else
  case $? in
    2) echo "ran but did not converge" ;;
    *) echo "error" ;;
  esac
fi

An interrupted run (Ctrl+C) exits 130, the conventional code for SIGINT.

Structured output

Every command supports --json, which prints a machine-readable result to stdout instead of the human-formatted view. The one exception is the interactive sandbox shell, which has no --json mode.

mcmc diagnose --json
mcmc summary --json
mcmc run model.jl --data data.csv --json

Combine --json with the exit code for fully unattended use: parse the JSON for the numbers, branch on the exit code for the verdict.

report=$(mcmc diagnose --json)
status=$?
echo "$report" | jq '.converged'
exit $status