# Check and edit model files

Validate, format, diff, merge and test model files, and export them as code.

## naga schema

```text
usage: naga schema [-h] [--out OUT]

Print the JSON Schema (draft 2020-12) of the model file format.

options:
  -h, --help  show this help message and exit
  --out OUT   write the schema here instead of printing it
```

## naga validate

```text
usage: naga validate [-h] [--json] model

Validate a model file and report structured problems (code, severity, path,
hint).

positional arguments:
  model       path to the model JSON, or a bundled model's name (naga
              examples)

options:
  -h, --help  show this help message and exit
  --json      emit the problems as a JSON array instead of one line each
```

## naga fmt

```text
usage: naga fmt [-h] [--check] files [files ...]

Rewrite model files in their shortest canonical form: every value the engine
fills in anyway left out, keys in one order, "$schema" first. The model, and
every run of it, stays the same.

positional arguments:
  files       model JSON files, rewritten in place

options:
  -h, --help  show this help message and exit
  --check     change nothing; name each file not in that form and exit 1
```

## naga export

```text
usage: naga export [-h] --python [-o OUT] model

Write a model as code that builds it again (nagasim.build). Running the code
gives the model in the form `naga fmt` writes.

positional arguments:
  model              path to the model JSON, or a bundled model's name (naga
                     examples)

options:
  -h, --help         show this help message and exit
  --python           Python code using nagasim.build (the one format so far)
  -o OUT, --out OUT  write the code here instead of printing it
```

## naga diff

```text
usage: naga diff [-h] [--json] [--all] [--textconv] files [files ...]

Semantic diff between two model files, matched by record identity rather than
list position.

positional arguments:
  files       two model files, or one with --textconv

options:
  -h, --help  show this help message and exit
  --json      emit the changes as a JSON array
  --all       also report canvas-only 'moved' changes (hidden by default)
  --textconv  print one file's canonical text form (a git textconv driver)
```

## naga merge

```text
usage: naga merge [-h] [-o OUTPUT] [--json] base ours theirs

Three-way merge of model files by record identity; usable as a git merge
driver (naga merge %%O %%A %%B).

positional arguments:
  base                  the common ancestor (git %O)
  ours                  our version (git %A); overwritten unless -o is given
  theirs                their version (git %B)

options:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        write the merged model here instead of over OURS
  --json                also print the conflicts as a JSON array on stdout
```

## naga check

```text
usage: naga check [-h] [--junit JUNIT] [--workers WORKERS] [--strict] [--json]
                  models [models ...]

positional arguments:
  models             model file(s) to check

options:
  -h, --help         show this help message and exit
  --junit JUNIT      write a JUnit XML report here
  --workers WORKERS
  --strict           treat an inconclusive assertion (its CI straddles the
                     bound) as a failure too (exit 1)
  --json             print {problems, laws, results} as JSON (one model)
```

## naga verify

```text
usage: naga verify [-h] [--quick] [--blocks K] [--json] [--html PATH]

Check the engine against textbook queueing theory.

options:
  -h, --help   show this help message and exit
  --quick      8 replications instead of 20
  --blocks K   K independent seed blocks; reports how many intervals hold the
               theory
  --json       print the rows as JSON
  --html PATH  also write an HTML report here
```

## naga facts

```text
usage: naga facts [-h] [--seed SEED] [--run-length RUN_LENGTH] [--json] model

Run one replication and list what happened in it that nothing else reports:
blocks never entered, resources never seized, resources idle while entities
waited for them, entities left at the end. Facts, not verdicts: exit 0
whenever the run happened.

positional arguments:
  model                 path to the model JSON, or a bundled model's name
                        (naga examples)

options:
  -h, --help            show this help message and exit
  --seed SEED
  --run-length RUN_LENGTH
                        default: the model's own 'simulation.time_limit'; 0 =
                        run until the queue drains
  --json                print the facts as JSON
```

## naga ci-template

```text
usage: naga ci-template [-h] [--path PATH] [--install INSTALL]

options:
  -h, --help         show this help message and exit
  --path PATH        directory of *.json models to check (default models/)
  --install INSTALL  the install step (default "pip install .": the product
                     package from the repository checkout)
```
