Skip to content

CLI Reference

kodoc is the Kōdo compiler. It compiles .ko source files to native executables and provides tools for inspecting the compilation pipeline.

Compile a Kōdo source file to a native executable.

Terminal window
kodoc build <file> [options]

Arguments:

ArgumentDescription
<file>Path to the .ko source file

Options:

FlagDescriptionDefault
-o, --output <path>Output file pathInput filename without .ko extension
--json-errorsEmit errors as JSON (for AI agent consumption)false
--contracts <mode>Contract checking mode: static, runtime, both, recoverable, noneruntime
--emit-mirPrint the MIR (Mid-level IR) to stdout before code generationfalse

Examples:

Terminal window
# Compile hello.ko to ./hello
kodoc build hello.ko -o hello
# Compile with default output name (produces ./hello from hello.ko)
kodoc build hello.ko
# Compile with JSON error output
kodoc build hello.ko --json-errors

Type-check and verify contracts without generating a binary. Useful for fast feedback during development.

Terminal window
kodoc check <file> [options]

Options:

FlagDescriptionDefault
--json-errorsEmit errors as JSONfalse
--contracts <mode>Contract checking mode: static, runtime, both, recoverable, noneruntime
--emit-certEmit a .ko.cert.json compilation certificate alongside diagnosticsfalse
--repair-planEmit repair plans as JSON for each error (for AI agent consumption)false

Example:

Terminal window
kodoc check my_program.ko
# Output: Check passed for module `my_program`

Tokenize a source file and print the token stream. Useful for debugging the lexer.

Terminal window
kodoc lex <file>

Example:

Terminal window
kodoc lex hello.ko
# Output:
# Module @ 0..6
# Identifier @ 7..12
# LeftBrace @ 13..14
# ...
# 42 token(s)

Parse a source file and print the AST (Abstract Syntax Tree). Useful for debugging the parser.

Terminal window
kodoc parse <file>

Example:

Terminal window
kodoc parse hello.ko
# Output: Debug representation of the AST

Lower a source file to MIR (Mid-level IR) and print it without generating code. Useful for inspecting the compiler’s intermediate representation.

Terminal window
kodoc mir <file> [options]

Options:

FlagDescriptionDefault
--contracts <mode>Contract checking mode: static, runtime, both, recoverable, noneruntime

Example:

Terminal window
kodoc mir hello.ko
# Output: MIR representation of the program

Explain an error code in detail with examples. Useful for understanding what caused a specific compiler error.

Terminal window
kodoc explain <code> [options]

Arguments:

ArgumentDescription
<code>The error code to explain (e.g., E0200)

Options:

FlagDescriptionDefault
--jsonOutput as JSON instead of human-readable formatfalse

Example:

Terminal window
kodoc explain E0200
# Output: Detailed explanation of the error with examples and fix suggestions
kodoc explain E0200 --json
# Output: JSON explanation for agent consumption

Inspect metadata embedded in a compiled Kōdo binary. Shows the compilation certificate stored in the binary.

Terminal window
kodoc describe <binary> [options]

Arguments:

ArgumentDescription
<binary>Path to the compiled binary

Options:

FlagDescriptionDefault
--jsonOutput as raw JSON instead of human-readable formatfalse

Example:

Terminal window
kodoc describe ./hello
# Output: Module name, purpose, version, functions, contracts, confidence scores
kodoc describe ./hello --json
# Output: JSON metadata for agent consumption

Run tests defined in a Kōdo source file. See Testing for details on writing tests.

Terminal window
kodoc test <file> [options]

Options:

FlagDescriptionDefault
--filter <pattern>Filter tests by name substring(none — run all)
--jsonOutput results as JSON for agent consumptionfalse
--contracts <mode>Contract checking mode: static, runtime, both, recoverable, noneruntime

Examples:

Terminal window
# Run all tests
kodoc test examples/testing.ko
# Run only tests matching a pattern
kodoc test examples/testing.ko --filter "add"
# JSON output for agents
kodoc test examples/testing.ko --json

Show the code generated by intent resolvers without compiling. Useful for understanding what an intent block produces.

Terminal window
kodoc intent-explain <file> [options]

Options:

FlagDescriptionDefault
--jsonOutput as JSONfalse

Example:

Terminal window
kodoc intent-explain intent_demo.ko
# Output: Shows the generated kodo_main() function from the console_app resolver

Format a Kōdo source file according to the standard style.

Terminal window
kodoc fmt <file>

Example:

Terminal window
kodoc fmt my_program.ko
# Output: Formatted output of my_program.ko

Generate a confidence report showing declared and computed confidence for each function in a module.

Terminal window
kodoc confidence-report <file> [options]

Options:

FlagDescriptionDefault
--jsonOutput as JSON instead of human-readable tablefalse
--threshold <float>Confidence threshold — functions below this value are flagged0.8

Example:

Terminal window
kodoc confidence-report agent_traceability.ko
# Output: Table of function confidences
kodoc confidence-report agent_traceability.ko --json
# Output: JSON confidence report

Automatically apply fix patches suggested by the compiler.

Terminal window
kodoc fix <file> [options]

Options:

FlagDescriptionDefault
--dry-runShow patches without applying themfalse

Example:

Terminal window
# Show what would be fixed
kodoc fix my_program.ko --dry-run
# Apply fixes
kodoc fix my_program.ko

Start an interactive Read-Eval-Print Loop. Each input is compiled and executed through the full pipeline (parse, type-check, desugar, MIR, codegen, link, run).

Terminal window
kodoc repl

Definitions (functions, structs, enums, types) persist across inputs — define a function on one line, call it on the next. Multi-line input is detected automatically when braces are unbalanced. Command history is persisted to ~/.kodo_history across sessions.

REPL commands:

CommandAliasDescription
:help:hShow available commands
:quit:q, :exitExit the REPL
:reset:clearClear all accumulated definitions
:type <expr>:t <expr>Show the type of an expression without executing it
:ast <expr>Show the AST of an expression
:mir <expr>Show the MIR of an expression

Examples:

Terminal window
kodoc repl
kōdo> println("Hello from the REPL!")
kōdo> let x: Int = 2 + 3
kōdo> fn double(n: Int) -> Int { return n * 2 }
kōdo> double(x)
kōdo> :type 42
kōdo> :reset
kōdo> :quit

Start the Kōdo Language Server Protocol server on stdin/stdout. Connect it to any LSP-compatible editor (VS Code, Neovim, etc.) or AI agent.

Terminal window
kodoc lsp

Features:

  • Real-time diagnostics (parse errors, type errors)
  • Hover information (function signatures, contracts, full annotations with args — e.g., @confidence(0.85), @authored_by(agent: "claude"))
  • Code actions from FixPatch — automatic quick-fix suggestions for type errors with machine-applicable patches
  • Completions for 31 built-in functions with signature details, user-defined functions with contract info (requires/ensures)
  • Goto definition (functions, variables, parameters, structs, enums), find references (with include_declaration support), rename, signature help, document symbols

A dedicated VSCode extension is available that connects to the Kōdo LSP server. It provides:

  • Syntax highlighting for .ko files
  • Automatic LSP connection (diagnostics, hover, completions, goto definition, find references, code actions)
  • One-click installation from the VS Code marketplace

To use it, install the extension and ensure kodoc is in your PATH. The extension automatically starts the LSP server when you open a .ko file.

Generate a consolidated audit report combining confidence scores, contract verification status, and annotations.

Terminal window
kodoc audit <file> [options]

Options:

FlagDescriptionDefault
--jsonOutput as JSONfalse
--contracts <mode>Contract checking mode: static, runtime, both, recoverable, noneruntime
--policy <criteria>Enforce a deployment policy and exit non-zero if not met(none)

The --policy flag accepts a comma-separated list of criteria:

CriterionDescription
min_confidence=<float>All functions must have effective confidence >= the given threshold
contracts=all_verifiedAll contracts must be statically verified by Z3
contracts=all_presentEvery function must have at least one contract
reviewed=allEvery function must have a @reviewed_by annotation

Example:

Terminal window
# Human-readable audit
kodoc audit my_module.ko
# JSON for agents
kodoc audit my_module.ko --json --contracts both

The audit report includes:

  • Per-function confidence scores (declared and effective after transitive propagation)
  • Contract verification summary (static verified, runtime checks, failures)
  • Deployability status (true if min confidence > 0.9 and zero contract failures)
  • All annotations per function

If you haven’t installed kodoc to your PATH, run it through Cargo:

Terminal window
cargo run -p kodoc -- build hello.ko -o hello
cargo run -p kodoc -- check hello.ko
cargo run -p kodoc -- lex hello.ko
cargo run -p kodoc -- parse hello.ko
cargo run -p kodoc -- mir hello.ko
cargo run -p kodoc -- explain E0200
cargo run -p kodoc -- describe ./hello
cargo run -p kodoc -- test examples/testing.ko
cargo run -p kodoc -- intent-explain intent_demo.ko
cargo run -p kodoc -- fmt hello.ko
cargo run -p kodoc -- repl
cargo run -p kodoc -- lsp

The -- separates Cargo’s arguments from kodoc’s arguments.

VariableDescription
KODO_RUNTIME_LIBPath to libkodo_runtime.a. If not set, kodoc searches relative to its own binary and common target/ directories.
RUST_LOGControls tracing output (e.g., RUST_LOG=info kodoc build hello.ko)
CodeMeaning
0Success
1Compilation error (parse, type, contract, codegen, or link error)