AI Diagnosis
Mozhi can attach a free AI explanation under the local error diagnostics — the feature is named exactly AI Diagnosis. It requires no API key, no account, no registration and no payment: the default service is an anonymous, keyless HTTPS endpoint that was verified reachable before this release.
How it works
- The interpreter first prints its local diagnosis (codes, spans, suggested fixes) — that part is deterministic and authoritative.
- When errors occurred and output is interactive, it collects a minimal context: up to 4 error entries (code, message, reason, position) plus at most ~1.2 KB of the offending source lines. The whole project is never uploaded; no other files are read.
- The context is sent over HTTPS with a bounded timeout (20 s by default) and the reply is size-capped and validated before display.
- The suggestion is shown in an
AI Diagnosisblock with a disclaimer: AI-generated suggestion — may be wrong; the local diagnosis above is authoritative. Suggestions are never executed and never modify files.
When it is off
AI Diagnosis is off for non-interactive runs (piped output, CI) unless
you pass --ai or set MOZHI_AI=1, and always off
with --no-ai or MOZHI_NO_AI=1. If the service is unreachable,
rate-limited, slow, or returns garbage, you see one line
(AI Diagnosis unavailable: …) with a link to the error index — the exit code
and the local diagnosis are completely unaffected.
Privacy
- Only the minimal context above leaves the machine — never the project tree.
- Anything that looks like a credential (
sk-…,ghp_…,npm_…, AWS keys,Bearer …) is scrubbed to[REDACTED]before sending. - Transport is HTTPS; plain HTTP is only accepted for loopback endpoints (tests).
- No API key exists, so nothing can leak a key.
- The response is advisory text; it is never executed or written to disk.
Configuration
$ mozhi run app.mz # interactive: AI Diagnosis attaches automatically
$ mozhi --no-ai run app.mz # skip it entirely
$ MOZHI_NO_AI=1 mozhi run app.mz # same via environment
$ mozhi --ai --json run app.mz # force in scripts; emits {"ai": ...} on stderr| Variable | Meaning | Default |
|---|---|---|
MOZHI_NO_AI=1 | disable AI Diagnosis | unset (enabled) |
MOZHI_AI=1 | force-enable, also in scripts/JSON mode | unset |
MOZHI_AI_TIMEOUT_MS | request timeout (500–60000) | 20000 |
MOZHI_AI_ENDPOINT | replace the service (maintenance/testing) | built-in default |
MOZHI_AI_MODEL | override the model id sent to the service | built-in default |
MOZHI_AI_MAX_CONTEXT | max source-context bytes (200–8000) | 1200 |
Honest limits
- The default free service was verified keyless and anonymous on 2026-10-26 (repeated back-to-back requests, no throttling observed), but it is still a courtesy service: if it is unreachable, rate-limited, slow, or returns garbage, you get the one-line notice instead of a suggestion.
- Suggestions can be wrong — the block always says so. Verified local facts (codes, spans, fixes) always come first.
- Binaries built without TLS support (some release targets) report
AI Diagnosis unavailableand fall back to local diagnosis.