Docs
中文 EN

CLI Flags, Exec & Bridge Contracts & Env Vars

CONTENTS

The mizar binary exposes five entrypoints sharing the same config resolution, routing logic, and Cordis plugin spine.

CLI Entrypoints

Command FormPurposePrompt Input / Args
mizar [OPTIONS]Launch interactive TUI workbench; passing -p / --prompt / --prompt-file enters headless execInteractive input or -p / --prompt-file
mizar exec [OPTIONS] [<prompt>]Headless single-turn execution for CI, benchmarks, and shell scriptsPositional <prompt>, -p, --prompt-file, or piped stdin
mizar bridge [OPTIONS]Long-lived stdio NDJSON JSON-RPC 2.0 bridge (protocol v1.0) for external host runtimesstdin/stdout NDJSON frames (internal logs routed to stderr)
mizar update [FLAGS]Verify SHA-256 and update binary from GitHub Releases-v/--version <ver>, -f/--force, --check, -h/--help
mizar install-tools [--force] [rg|fd ...]Install or locate managed rg & fd binaries in $MIZAR_HOME/binInstalls both by default; --force reinstalls, with ghfast.top mirror fallback

Complete CLI Flags (mizar and mizar exec)

FlagValue / DefaultScopeDescription
-C, --workspace <dir>Path (default .)GlobalOverride workspace root directory (fallback: WORKSPACE env var)
-p, --prompt <text>StringGlobal / execProvide a single prompt and run headlessly
--prompt-file <path>File pathGlobal / execRead prompt from file and run headlessly (conflicts with --prompt/<prompt>)
--provider <name>Provider IDGlobalOverride provider (openai, openai-responses, anthropic, deepseek, mock, or models.json key)
--model <id>Model IDGlobalOverride active model ID
--protocol, --api-format <kind>completions | responses | messagesGlobalSelect protocol adapter (accepts openai-completions, openai-responses, anthropic-messages)
--base-url <url>URL stringGlobalOverride API endpoint URL
--reasoning-effort <level>off | minimal | low | medium | high | xhigh | maxGlobalOverride reasoning effort
--max-steps <n>Positive integer (unlimited)GlobalMaximum tool steps allowed per turn; triggers code=max_steps on overflow
--max-tokens <n>Positive integerGlobalOverride max output tokens per LLM response
--context-window <tokens>Positive integer (>= 1)Global (TUI / exec)Override model context window (takes precedence over MIZAR_CONTEXT_WINDOW and catalog)
--timeout <secs>SecondsexecWhole-turn execution timeout; exits with code 124 on expiry
--output-format <fmt>text (default) | json | ndjsonexecOutput format; json & ndjson emit line-flushed NDJSON events ending with result
--jsonBoolean flagexecShorthand alias for --output-format ndjson
--trace-out <path>File pathexecAtomically write structured TrajectoryExport JSON on exit (overrides MIZAR_TRACE_OUT)
--isolatedBoolean flagGlobalSkip loading global and workspace disk configs; run cleanly in memory
--minimalBoolean flagGlobalSelect default MinimalCoding preset (read, bash, edit, write only)
--read-onlyBoolean flagGlobalSelect ReadOnly preset (read, grep, find only)
-t, --tools <csv>Comma-separated namesGlobalExplicitly enable/constrain active tools
-xt, --exclude-tools <csv>Comma-separated globsGlobalAdd tool exclusions (Hidden in both schemas and codemode)
--inlineBoolean flagTUIStart directly in Inline scrollback viewport
--approveBoolean flagTUIRequire interactive approval for non-read-only tools (ui.approvalMode: "ask")
-c, --continueBoolean flagTUI / execResume the most recent session for the current workspace
-r, --resume [id]Optional session IDTUI / execOpen session picker in TUI when id is omitted, or resume matching ID
--no-persistBoolean flagGlobalDisable JSONL session persistence (in-memory session only)
--no-instructionsBoolean flagGlobalSkip startup AGENTS.md / CLAUDE.md discovery and injection
--theme <name>Theme name (auto)TUIInitial theme: auto | mist-dark | mist-light | sakura-dark | system | ansi16
-h, --help—GlobalPrint CLI help text
-V, --version—GlobalPrint binary version and exit

mizar exec Automation Contract

NDJSON Stream Schema (--json / --output-format ndjson / --output-format json)

Each line is a flushed JSON object carrying type and ts_ms: session, step_start, tool_call (redacted arguments_preview of at most 512 chars), tool_result (individual duration_ms and images), retry (plus [W retry] on stderr), compaction, step_end (6-field usage), ending with a single result after the persistence barrier (or a single invalid_request line on input/validation errors):

stdout (--json / --output-format ndjson final result example)
{
  "type": "result",
  "ts_ms": 1764250000000,
  "session_id": "019...",
  "resumed": false,
  "reason": "completed",
  "exit_code": 0,
  "steps": 4,
  "duration_ms": 3820,
  "llm_ms": 2910,
  "ttft_ms": 340,
  "tool_ms": 880,
  "tool_calls": 6,
  "tool_errors": 0,
  "retries": 0,
  "compactions": 0,
  "session_turns": 1,
  "session_steps": 4,
  "usage": { "input_tokens": 1200, "output_tokens": 350, "total_tokens": 1550, "cache_read_tokens": 0, "cache_write_tokens": 0, "reasoning_tokens": 0 },
  "session_usage": { "input_tokens": 1200, "output_tokens": 350, "total_tokens": 1550, "cache_read_tokens": 0, "cache_write_tokens": 0, "reasoning_tokens": 0 },
  "text": "Finished analyzing Cargo.toml..."
}

Exit Codes

Exit CodeMeaningstderr Diagnostic Pattern
0Completed turn cleanly—
1Generic error, storage failure, max steps, truncation, or cancellationContains code=storage, code=max_steps, code=max_tokens, code=cancelled, invalid_request, or secret-redacted error text
124--timeout deadline exceededexecution timed out after <secs>s (code=timeout)
130 / 143Interrupted by signal (SIGINT / SIGTERM)execution interrupted by signal (code=cancelled)
Secret Redaction & Trace Resolution

Diagnostics printed to stderr or triggered by —trace-out write errors are automatically scrubbed against loaded API keys. When both —trace-out and MIZAR_TRACE_OUT are set, the CLI flag wins.

mizar bridge Long-Lived Protocol (v1.0)

mizar bridge (backed by mizar-bridge) allows external TypeScript or polyglot hosts to drive Mizar over strictly \n-delimited NDJSON JSON-RPC 2.0 on stdin/stdout (all internal logs go to stderr).

mizar bridge Flags

FlagValue / DefaultDescription
-C, --workspace <dir>Path (default .)Workspace root directory
--sessions-dir <dir|none>MIZAR_SESSIONS_DIR / ~/.mizar/sessionsJSONL sessions directory, or none / off / memory to disable (disabled by default when --isolated)
--isolatedBoolean flagSkip user ~/.mizar global config, MCP, skills, and sessions
--mockBoolean flagForce offline mock LLM route
--identity <text>StringOverride system identity prompt (defaults to DEFAULT_IDENTITY)
--identity-file <path>File pathRead system identity prompt from file
--personality <text>StringOptional system personality prompt section
--protocol-version—Print supported bridge protocol version (1.0) to stdout and exit
-V, --version—Print binary version and exit
-h, --help—Print mizar bridge help and exit

Protocol Contract & Lifecycle

  • Ready Handshake: Emits a bridge.ready notification once initialized, reporting protocolVersion: "1.0", bridgeVersion, workspace, isolated, mockMode, activeProvider, and activeModel.
  • 19 Forward RPCs: Covers lifecycle & routing (runtime.info, runtime.shutdown, router.reload), sessions (session.create, session.list, session.history, session.fork, session.compact), dynamic prompts (prompt.set_section, prompt.remove_section), dynamic tools (tools.register, tools.unregister, tools.list, tools.set_session_active, tool.emit_update), MCP management (mcp.reload, mcp.status), and turn control (turn.run, turn.cancel).
  • 14 Push Notifications & Reverse tool.invoke: Streams bridge.ready, turn.completed, compaction.end, and 11 agent.* events; when a dynamically registered host tool is called, Mizar sends a reverse tool.invoke RPC request over the same stdio pipe and awaits the host result (propagating timeouts and cancellation).
  • Graceful Shutdown: Exits cleanly with code 0 on runtime.shutdown RPC (flushing {"ok": true} first), stdin EOF, or SIGTERM / SIGINT, cancelling active runs and disposing MCP/Cordis resources.

Official TypeScript SDK (@mizar/sdk)

Each GitHub Release also publishes the zero-runtime-dependency @mizar/sdk tarball (mizar-sdk-<tag>.tgz, source in sdk/ts/), providing a strict \n-delimited NDJSON parser, typed methods for all 19 RPCs and 14 events, reverse tool.invoke callbacks, onUnexpectedExit, and SHA-256 verified binary resolution (mizar-sdk install / ensureMizarBinary):

Install and provision @mizar/sdk
pnpm add https://github.com/Mieluoxxx/Mizar/releases/download/v0.2.9/mizar-sdk-v0.2.9.tgz
pnpm exec mizar-sdk install   # Download and SHA-256 verify matching mizar binary
Drive a long-lived session with MizarClient
import { MizarClient, ensureMizarBinary } from "@mizar/sdk";

await ensureMizarBinary();
const client = new MizarClient({
  workspace: process.cwd(),
  onUnexpectedExit: ({ code, signal }) => {
    console.error(`mizar bridge exited: code=${code} signal=${signal}`);
  },
});

await client.start();
const { sessionId } = await client.createSession({ title: "sdk-demo" });
const off = client.on("agent.text_delta", (ev) => process.stdout.write(ev.text));
await client.runTurnAndWait({ sessionId, input: "Summarize README.md" });
off();
await client.stop();

Environment Variables Reference

1. LLM Routing & Credentials

VariableDescription
API_KEYHighest-precedence generic credential overriding provider-specific env keys
OPENAI_API_KEYDefault key for openai / openai-responses
ANTHROPIC_API_KEYDefault key for anthropic
DEEPSEEK_API_KEYDefault key for deepseek
OPENROUTER_API_KEYOpenRouter credential env var available to router overrides
PROTOCOLOverride wire protocol (completions / responses / messages)
BASE_URLOverride API base URL
MODELOverride active model ID

2. Paths & Runtime Diagnostics

VariableDefault / Behavior
WORKSPACEOverride workspace root (lower priority than -C/--workspace)
MIZAR_HOMEGlobal config directory, default ~/.mizar (settings.json, models.json, mcp.json, sessions/, bin/)
MIZAR_AGENTS_HOMEGlobal agent directory, default ~/.agents (AGENTS.md, skills)
MIZAR_SESSIONS_DIROverride JSONL sessions directory (default ~/.mizar/sessions); set to none, off, memory, or empty to disable
MIZAR_CONTEXT_WINDOWOverride context window size (lower priority than --context-window, higher than model catalog)
MIZAR_CACHE_RETENTION / PI_CACHE_RETENTIONOverride default cache retention policy (none / short / long)
MIZAR_LLM_IDLE_TIMEOUT_SECSOverride HTTP / SSE idle progress timeout in seconds
MIZAR_BUNDLED_SKILL_DIROverride bundled skills directory (lower priority than skills.bundledDir)
MIZAR_TRACE_OUTDefault output path for mizar exec TrajectoryExport JSON
CORDIS_LOGControl Cordis microkernel log verbosity (e.g. debug / warn)

3. Corporate Proxies & Custom TLS CA Roots

mizar-llm-http and mizar-mcp check standard ecosystem CA bundle env vars in order — any one suffices:

VariableDescription
SSL_CERT_FILEOpenSSL / standard PEM CA root bundle file
CURL_CA_BUNDLEcurl-compatible CA bundle file
REQUESTS_CA_BUNDLEPython requests-compatible CA bundle file
NODE_EXTRA_CA_CERTSNode.js extra trusted root certificates file

4. Self-Update, Offline & Tool Installer Controls

VariableDescription
MIZAR_OFFLINE / PI_OFFLINEWhen 1/true/yes/on, disables startup update checks and mizar install-tools downloads
MIZAR_SKIP_VERSION_CHECKWhen 1/true/yes/on, skips startup async release check
MIZAR_RELEASE_BASE_URLOverride mizar update download base URL (default https://github.com/Mieluoxxx/Mizar)
MIZAR_GITHUB_BASE_URLOverride mizar install-tools / TUI download base URL (default https://github.com)
MIZAR_GITHUB_MIRRORFallback mirror prefix ({mirror}/{original_url}, default https://ghfast.top; set off/none/empty to disable)
MIZAR_BIN_WARMUP_MS / MIZAR_BIN_SLOW_BPSWarmup window in ms (default 5000) and slow-speed fallback threshold in bytes/s (default 65536)
MIZAR_BIN_STALL_MSContinuous stall timeout in ms before switching to mirror (default 8000)

5. Terminal, TUI Emphasis & Editor Integration

VariableDescription
COLORTERMSet to truecolor or 24bit for full Oklab 24-bit rendering
TERM / COLORFGBGUsed for capability probing and auto dark/light detection
SHELLFallback shell for bash tool when /bin/bash, /usr/bin/bash, and /bin/sh are absent
VISUAL / EDITORExternal editor binary
MIZAR_TUI_EMPHASISSet 0/false/off to disable pi-emphasis visual rendering
MIZAR_TUI_ROUND_CAPS / PI_EMPHASIS_ROUND_CAPSSet 0/false/off to turn off rounded pill caps
MIZAR_TUI_PILL_ICONS / PI_EMPHASIS_PILL_ICONSSet 0/false/off to hide Nerd Font pill icons
MIZAR_TUI_EMPHASIS_GUIDANCE / PI_EMPHASIS_GUIDANCESet 0/false/off to omit emphasis prompt guidance
MIZAR_TUI_PROGRAM_STATUSControls terminal window/progress status reporting

Search Mizar Docs