Skip to content

The metta CLI

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

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.

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.