Skip to content

The metta CLI

@mettascript/node installs the metta command. Use it to run MeTTa files, check them, explain reductions, render reduction GIFs, and run property tests.

bash
npm install -g @mettascript/node

Run a program

bash
metta run hello.metta
metta hello.metta

Both commands run the file and print one result list for each ! query:

metta
(= (double $x) (* $x 2))
!(double 21)
text
[42]

metta <file.metta> is shorthand for metta run <file.metta>.

The runner accepts these flags:

flagdoes
--checkrun static analysis instead of evaluation
--jsonprint checker diagnostics as JSON when --check is set
--undefined-symbolsinclude undefined-symbol diagnostics in the checker
--pyenable Python interop through pythonia
--prologenable Prolog interop through a local swipl executable
--conformanceprint every top-level directive result, not only ! queries
--max-steps=Nset the evaluation fuel
--max-stack-depth=Nset the initial interpreter stack-depth bound
--hash-consenable the experimental hash-consing mode
--flat-atomspaceenable the experimental flat atomspace mode

Host runtimes are opt-in. Without --py or --prolog, the runner does not load Python, Prolog, or their optional packages.

Check a program

bash
metta check hello.metta
metta check hello.metta --json --undefined-symbols

metta check runs the same static analyzer as metta run --check. Human diagnostics are printed to stderr. JSON diagnostics are printed to stdout.

Debug the engine

bash
metta debug --source '(= (double $x) (* $x 2))' eval '(double 21)'
metta debug --source '!(+ 1 2)' run
metta debug --file program.metta why '(main)' --llm --max-steps 1000

The debugger takes source from --file <p> or --source '<m>', then runs one command:

commanddoes
whyevaluates one call with tracing and prints the trace summary
evalevaluates one expression against the loaded source
runruns every ! query in the loaded source

--llm prints JSON. --max-steps N sets the evaluation fuel. See Debugging and traces for the trace fields.

Run property tests

bash
metta fuzz suite.metta
metta fuzz --list suite.metta
metta fuzz --seed 7 --runs 50 suite.metta
metta fuzz --exhaustive suite.metta
metta fuzz --corpus regressions suite.metta
metta reach suite.metta [id]

metta fuzz runs every (FuzzTest ...) declaration a file carries and prints one line each. metta reach does the same for (FuzzReachTest ...), optionally restricted to one id. Neither runs the file's own ! queries: reading a suite is not a way to execute whatever else the file would have done. import! and register-module! are kept, because a property defined in an imported file would be undefined without them.

optiondoes
--listprints the declarations without running them
--jsonprints the full result atoms as one JSON document on stdout
--exhaustiveenumerates each declaration's whole domain instead of sampling
--corpus <dir>replays the counterexamples stored there first, and records new ones
--no-recordreads the corpus without writing to it
--seed, --runs, --max-size, --max-discards, --max-shrinks, --case-steps, --case-depth, --max-enumeratedreplace that option in every declaration's fuzz-config
--max-depth, --max-states, --max-transitionsreplace that option in every reach-config, for metta reach

The exit code is the run's verdict, so the command works as a test gate:

codemeans
0every declaration passed, or gave a definitive answer
1a property failed
2invalid input, or corrupt stored data
3an incomplete run: gave up, bounded by depth, or cut off by a limit

Results go to stdout and diagnostics to stderr, so --json prints exactly one document however much the run has to say about its corpus. See Property testing for how to write the declarations.

Render a reduction GIF

bash
metta graph program.metta -o out.gif
metta graph program.metta --view side-by-side --width 960 --max-steps 200

metta graph renders the reduction to an animated GIF through @mettascript/grapher/node. The grapher is loaded lazily, so install the renderer packages before using this command:

bash
npm install @mettascript/grapher gifenc sharp

The graph command accepts these flags:

flagdoes
-o out.gifwrite to the given GIF path
--view blocksrender the nested blocks view
--view graphrender the node graph view
--view side-by-siderender both views together
--width Nset the GIF width in pixels
--max-steps Nbound reduction steps while building the trace

Version and help

bash
metta --version
metta --help

metta-ts remains an alias for metta run, and metta-debug remains an alias for metta debug.

The Python Hyperon package also installs a metta executable, so if both are on PATH, whichever comes first shadows the other. Use the metta-ts alias to reach this runner when that happens.

Released under the MIT License.