> ## Documentation Index
> Fetch the complete documentation index at: https://warden-re.io/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI reference

> Every warden command, its arguments, and what it does.

The `warden` command is a thin shell over the library. Every command takes `--db <path>` to
select the project database (default `warden.db`, or the `WARDEN_DB` environment variable).

<Note>
  Run `warden --help`, or `warden <command> --help`, for the authoritative, version-specific
  flag list. This page documents the commands as of the current release.
</Note>

## Project lifecycle

<AccordionGroup>
  <Accordion title="warden version" icon="hash">
    Print the installed WARDEN version.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden version
    ```
  </Accordion>

  <Accordion title="warden init" icon="folder-plus">
    Create a project: a `.warden/` directory with the knowledge base inside it
    (`.warden/warden.db`). Every command run from anywhere in that directory tree then finds and
    uses that database automatically, so you never pass `--db`.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden init [--dir <path>]
    ```
  </Accordion>

  <Accordion title="warden config" icon="settings">
    Manage settings without juggling environment variables. There are two layers: a global file at
    `~/.config/warden/config.json` (your defaults) and a per-project file at
    `<project>/.warden/config.json` (overrides for one project). Resolution is project over global,
    and the resolved keys and models are applied for you, so the backends just work.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden config set openrouter_api_key sk-or-...            # global default
    warden config set openrouter_model xiaomi/mimo-v2.5-pro   # global default
    warden config set --project openrouter_model moonshotai/kimi-k2.6   # this project only
    warden config get openrouter_model                        # value + which file it came from
    warden config list                                        # every setting, value, and source
    warden config path                                        # config file and database locations
    ```

    Known keys: `openrouter_api_key`, `openai_api_key`, `anthropic_api_key`, `openrouter_model`,
    `openai_model`, `agent_model`. API key values are masked in `get` and `list`.
  </Accordion>

  <Accordion title="warden demo" icon="play">
    Run the entire pipeline end-to-end on generated sample modules. No network or toolchain needed.
    The fastest way to see what WARDEN does.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden demo [--dir warden-demo]
    ```
  </Accordion>
</AccordionGroup>

## Ingest and inspect

<AccordionGroup>
  <Accordion title="warden ingest" icon="download">
    Parse, fingerprint, and load a module version into the KB. Seeds names from the name section,
    exports, and imports.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden ingest <wasm> [--glue <js>] [--label <name>] [--notes <text>] [--db <path>]
    ```

    * `<wasm>`: path to the `.wasm` file (required).
    * `--glue, -g`: optional Emscripten `.js` glue (recovers version, dynCall sigs, pthread shape).
    * `--label, -l`: version label (defaults to the filename stem).
  </Accordion>

  <Accordion title="warden versions" icon="layers">
    List all ingested module versions.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden versions [--db <path>]
    ```
  </Accordion>

  <Accordion title="warden coverage" icon="gauge">
    Show symbol-coverage statistics for a version (named / by oracle / by human / by agent).

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden coverage <label> [--db <path>]
    ```
  </Accordion>

  <Accordion title="warden funcs" icon="list">
    List functions for a version with their current names and provenance.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden funcs <label> [--unnamed] [--limit 50] [--db <path>]
    ```

    * `--unnamed`: show only functions that still have no name.
  </Accordion>

  <Accordion title="warden show" icon="search">
    Show everything known about a single function: type, stable id, calls, provenance, and evidence.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden show <label> <index> [--db <path>]
    ```
  </Accordion>

  <Accordion title="warden set-name" icon="user-check">
    Set a human-verified name for a function. Human names are sovereign and locked against agent
    overwrite by default.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden set-name <label> <index> <name> [--summary <text>] [--lock/--no-lock] [--db <path>]
    ```
  </Accordion>
</AccordionGroup>

## The Oracle

<AccordionGroup>
  <Accordion title="warden oracle build" icon="hammer">
    Build (or extend) an Oracle signature store from labeled modules (modules that still carry a
    name section).

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden oracle build <wasm...> --out <store.json> [--library musl] [--emver <ver>] [--opt <flag>]
    ```

    * `<wasm...>`: one or more labeled `.wasm` files.
    * `--out, -o`: signature store path (default `oracle.json`).
    * `--emver`: the Emscripten version these were built with (recorded on each signature).
    * `--opt`: the opt level, e.g. `-O2`.
  </Accordion>

  <Accordion title="warden oracle identify" icon="telescope">
    Identify runtime/libc functions in a version against a signature store, and infer the
    Emscripten version from the distribution of matches.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden oracle identify <label> --store <store.json> [--threshold 0.82] [--indexed] [--db <path>]
    ```

    * `--indexed`: build a MinHash-LSH index over the store before matching, giving sublinear
      candidate lookup for large signature stores. Produces the same results as the default linear
      scan at any threshold above 0.82, but is significantly faster when the store exceeds a few
      thousand signatures.
  </Accordion>
</AccordionGroup>

## Decompile and execute

<AccordionGroup>
  <Accordion title="warden lift" icon="code">
    Decompile a single function (or every function in a module) to readable pseudo-C using the
    built-in pure-Python stack-machine lifter.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden lift <label> [--index N] [--out <file>] [--db <path>]
    ```

    * `<label>`: the version to lift (required).
    * `--index, -i`: lift only function at index `N`. Omit to lift the entire module.
    * `--out, -o`: write output to a file instead of stdout.

    The same lifter backs `warden export --format pseudo`; that command now emits real pseudo-C
    rather than a mnemonic dump.

    **Example output** for `parse_token`:

    ```c theme={"theme":{"light":"github-light","dark":"github-dark"}}
    i32 parse_token(i32 p0, i32 p1) {
        return ((p0 + p1) * 7);
    }
    ```
  </Accordion>

  <Accordion title="warden exec" icon="play">
    Execute a single function in the built-in mini interpreter and print the return values.
    Covers the integer instruction subset; no external toolchain is required.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden exec <label> <index> [args...] [--db <path>]
    ```

    * `<label>`: the version containing the function (required).
    * `<index>`: function index (required).
    * `[args...]`: zero or more integer arguments passed to the function.

    Raises `UnsupportedExecution` when an instruction outside the supported subset is encountered.
    For behavioral comparison across versions use `warden diff` or call
    `warden.interp.differential_execute` from the Python API directly.
  </Accordion>

  <Accordion title="warden analyze" icon="microscope">
    Run the concurrency and struct-layout analyzers over a version and persist their findings as
    KB facts. This populates the `thread_model` and `structs` tables that were previously empty.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden analyze <label> [--db <path>]
    ```

    The command runs both analyzers in sequence:

    * **Concurrency analyzer**: detects shared-memory access patterns, atomic sites, and pthread
      markers; writes facts via `kb.add_thread_fact`.
    * **Struct analyzer**: recovers struct layouts (name, field offsets, sizes, and inferred
      types) from access patterns; writes records via `kb.upsert_struct`.

    Results are visible in `warden show` and in the HTML report produced by `warden report`.
  </Accordion>

  <Accordion title="warden report" icon="file-chart-column">
    Generate a self-contained HTML reverse-engineering report for a version. The file has inline
    CSS and requires no server to view.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden report <label> [--out <file>] [--db <path>]
    ```

    * `--out, -o`: output path (default `<label>-report.html`).

    The report includes:

    * A coverage summary (named / oracle / human / agent / unnamed).
    * A confidence heatmap: every function colored by provenance and confidence score.
    * A thread and memory model section (populated after `warden analyze`).
    * The diff changelog from all prior `warden diff` runs against this version.
  </Accordion>
</AccordionGroup>

## Agents, diff, verify, export

<AccordionGroup>
  <Accordion title="warden agent" icon="bot">
    Run one propose → verify → write-back sweep over unnamed functions. Auto-selects cheapest-first:
    OpenRouter (Kimi K2.6) when `OPENROUTER_API_KEY` is set, then OpenAI, then Anthropic, otherwise
    the deterministic offline backend.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden agent <label> [--strategy call-graph|flat] [--backend offline|openrouter|kimi|openai|codex|oai|anthropic] [--rounds N] [--db <path>]
    ```

    **`--strategy`** controls how functions are ordered and processed (default: `call-graph`).

    `call-graph` (default): walks the call graph bottom-up.

    1. Builds the intra-module call graph. Direct calls are exact. Indirect calls (`call_indirect` / `dynCall`) are over-approximated to table targets of the matching type, so the graph is a static skeleton.
    2. Condenses strongly-connected components (mutual recursion) and sorts them into bottom-up layers. Every function in a layer has all of its defined callees in earlier layers.
    3. Runs the concurrency and struct analyzers first and routes their findings into per-function notes (atomic sites, struct layouts).
    4. Processes layers bottom-up. Each function is named with its callees' recovered names already in view, carried in `FunctionFacts.callee_names` and `FunctionFacts.notes`. This is the main quality win over a flat pass.
    5. Functions in the same layer are independent and are proposed concurrently via asyncio (blocking LLM backends run in worker threads, capped by `--concurrency`, default 8). Writes still go through the provenance and confidence economy, so concurrent branches that share a callee cannot clobber each other.

    `flat`: the original single-pass, leaves-first ordering. Available for comparison or when call-graph analysis is not needed.
  </Accordion>

  <Accordion title="warden deep" icon="microscope">
    The per-function deep engine: one agent per function, walked bottom-up over the call graph (leaves first). Each
    function's agent is fed its disassembly facts, its decompiled C, and the recovered understanding
    of the functions it calls (read from the knowledge base, not the callees' raw bytes). It returns
    a name, a one-paragraph understanding, a variable rename map, the cleaned C, and whether the
    function is now closed.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden deep <label> [--backend offline|openrouter|kimi|...] [--parent-model <model>] [--watch/--no-watch] [--db <path>]
    ```

    * Closed functions are reused, not re-analyzed, and identical functions (same stable identity)
      are analyzed once. This is what makes a module with thousands of functions tractable.
    * Results go to the `function_analysis` table and the symbol economy; every rename is logged for
      reversibility; progress is written to `agent_events` and, with `--watch`, streamed to the terminal.
    * Tier the models: a cheap `--backend kimi` for the many leaf functions and a stronger
      `--parent-model` for the harder, high-fan-in parents.
    * Runs on the deterministic offline backend with no API key (a dry run of the whole flow). Set
      `OPENROUTER_API_KEY` and `--backend kimi` to make the agents real. Browse the inferred C with
      `warden serve`.
  </Accordion>

  <Accordion title="warden agent-backends" icon="list-checks">
    List agent backends, availability, required credentials, and default models. Use this before
    a provider-backed run to confirm what auto-selection will see.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden agent-backends
    ```
  </Accordion>

  <Accordion title="warden diff" icon="git-compare-arrows">
    Diff two versions, carry annotations forward, and print the semantic changelog.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden diff <from_label> <to_label> [--no-carry] [--db <path>]
    ```

    * `--no-carry`: classify only; do not port annotations forward.
  </Accordion>

  <Accordion title="warden export" icon="file-output">
    Export a deliverable. All formats are deterministic so they diff cleanly in git.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden export <label> --format headers|pseudo|kb-text|ghidra|csv|json [--out <file>] [--db <path>]
    ```

    | Format    | Output                                                                                                                                 |
    | --------- | -------------------------------------------------------------------------------------------------------------------------------------- |
    | `headers` | A C header of recovered function prototypes.                                                                                           |
    | `pseudo`  | Readable per-function listings with names and summaries.                                                                               |
    | `kb-text` | A stable, git-diffable dump of every symbol.                                                                                           |
    | `ghidra`  | A Python script that renames functions in the Ghidra WASM plugin.                                                                      |
    | `csv`     | A neutral CSV of all annotated symbols, suitable for editing in Ghidra, IDA, or a spreadsheet, then re-importing with `warden import`. |
    | `json`    | The same data as `csv` but as a JSON array, one object per symbol.                                                                     |

    The `csv` and `json` formats complete the round-trip: export, edit externally, then import back with `warden import`.
  </Accordion>

  <Accordion title="warden import" icon="file-input">
    Import annotations from a previously exported CSV or JSON file and merge them into the KB.
    This is the return leg of the round-trip that begins with `warden export --format csv|json`.

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden import <label> <file> [--format csv|json] [--provenance <tag>] [--lock] [--db <path>]
    ```

    * `<label>`: the version to import into (required).
    * `<file>`: the CSV or JSON file produced by `warden export` or edited by hand (required).
    * `--format`: `csv` (default) or `json`. Inferred from the file extension when omitted.
    * `--provenance`: override the provenance tag for every imported row (e.g. `human`). By default the provenance stored in the file is preserved.
    * `--lock`: mark each imported symbol as locked, preventing future agent overwrites.

    **How matching works.** The importer keys on the stable function identity first. A name recovered against one build lands on the same logical function in another build, even when the function index shifts between releases. The function index is used as a fallback when no stable identity match exists.

    **Provenance economy.** Every imported row passes through the same provenance and confidence economy as all other writes. An import never clobbers a higher-authority annotation (for example, a `human`-locked name). The returned result reports `matched`, `written`, `rejected_by_economy`, `skipped`, and `unmatched` counts so you can audit what changed.

    **Example: editing in Ghidra and importing back.**

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    # Export current annotations to CSV.
    warden export v1 --format csv --out v1-symbols.csv

    # Edit v1-symbols.csv in Ghidra, IDA, or a text editor, then:
    warden import v1 v1-symbols.csv --provenance human --lock
    ```
  </Accordion>

  <Accordion title="warden verify" icon="shield-check">
    Verify ingestion determinism and report differential-equivalence readiness (whether a
    wasm2c/w2c2 + C toolchain is present).

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden verify <wasm>
    ```
  </Accordion>

  <Accordion title="warden mcp" icon="plug">
    Serve the knowledge base over the Model Context Protocol (stdio). Requires
    `pip install -e '.[mcp]'`. See the [MCP reference](/reference/mcp).

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    warden mcp [--db <path>]
    ```
  </Accordion>
</AccordionGroup>

## A full session

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
warden init
warden ingest app_v1.wasm --glue app_v1.js -l v1
warden oracle build runtime_debug.wasm -o oracle.json --emver 3.1.55 --opt -O2
warden oracle identify v1 --store oracle.json --indexed
warden agent v1
warden set-name v1 7 verify_license
warden analyze v1
warden lift v1 --index 7          # inspect the decompiled pseudo-C for a single function
warden export v1 --format pseudo --out v1.pseudo.txt
warden report v1 --out v1_report.html

# next release:
warden ingest app_v2.wasm -l v2
warden diff v1 v2
warden report v2 --out v2_report.html
```
