# Automate with clear results — Mercury LMS ## Structured output ```sh mg version --json mg help --json mg version --json --agent ``` --json writes one stdout envelope: ok, command, exit_code, and result on success or error on failure. Version result includes version, revision, go_version and platform. Error includes kind/message and may include id/next/details. Capture stdout without 2>&1: diagnostics may also be emitted on stderr. --agent adds a bounded prompt on stderr in text mode (AGENT_PROMPT_BEGIN/END); JSON mode puts it in agent_prompt. MG_AGENT=1 also enables guidance. Guidance does not execute or authorize next steps. Source-launcher failures can omit agent_prompt/result even when --agent was requested. ## Preserve status ```sh if mg version --json > mg-result.json; then printf 'Version captured\n' else code=$? printf 'mg exited %s\n' "$code" >&2 fi ``` This example reports the status; CI must also propagate a nonzero exit when the step fails. 0 success; 1 refusal (including generator drift); 2 usage error; 3 could not measure; 101 internal fault; 128+n signal. Read the error and apply its specific recovery. Do not mark an unavailable check as passed or rewrite generated files solely because an agent prompt mentions it. ## Check both cases `mg help --json` succeeds. `mg hlep --json` exits 2 and emits a failure envelope with diagnostic guidance. A consumer distinguishes these through status and fields, not English text. Generator-enabled builds can use `mg gen examples --check --json` for read-only drift detection. ## Navigation - [Read this page in the browser](/mg/automation) - [mg](/mg/llms.txt) - [llms.txt](/llms.txt) - [All English companions](/llms-full.txt) - [Sitemap](/sitemap.xml)