CLI
npm install -g @katnip-org/compilerkatnip helpFrom a source checkout, substitute node packages/compiler/build/cli.js for katnip.
Commands
Section titled “Commands”katnip build <source> [output]Compiles a .knip to a .sb3. Output defaults to the source path with the extension
swapped.
katnip build game.knip # writes game.sb3katnip build game.knip dist/g.sb3katnip build game.knip --compression 1 # faster build, larger file--compression is the zip deflate level, 0 to 9, and defaults to 6.
Imports, costumes, sounds and import() data files are resolved relative to the source
file, and declared assets are packed into the .sb3. Runs the whole pipeline, so it type-checks too. On any error it prints the diagnostics and
exits non-zero without writing a file — a build either produces a project that loads, or
produces nothing.
katnip check <source> [logger]Lex, parse, and analyze. Prints No semantic errors found. or the diagnostics. Faster than
build because it skips IR and codegen.
katnip lower <source> [output]Lowers to IR and prints it as JSON, to stdout unless you give a path. The fastest way to answer “what did the compiler actually do with that loop”.
katnip parse <source> <output>Writes the AST as JSON. Aborts if the lexer or parser reported errors.
tokenize
Section titled “tokenize”katnip tokenize <source> <output>Writes the token stream as JSON, each token with its line and column.
decompile
Section titled “decompile”katnip decompile <source> [output]Turns a .sb3 into .knip source. Output defaults to the source path with a .knip
extension. Stage variables become top-level globals, the stage’s scripts land in a
stage { } block, and each sprite becomes a sprite block.
The result is a starting point, not a perfect round trip:
- Costumes and sounds are not extracted or declared, so add your own
costumeandsoundlines before rebuilding. - Types come back as
any, and names Katnip cannot use are rewritten, somy varbecomesmy_var. - Anything compiled from Katnip decompiles to what it became. A returning procedure comes
back as a
voidone writing to aname_retvariable, plus the compiler’s helper lists. - A block with no Katnip form is left out of the code and marked with a
# unsupported: <opcode>comment, so search for that marker before rebuilding.
katnip helpThe logger flag
Section titled “The logger flag”tokenize, parse and check take an optional trailing logger positional. Pass true
to write a verbose per-character, per-state trace:
katnip check game.knip trueThe log goes to examples/log.txt relative to your current working directory — so run
it from a directory that has an examples/ folder, or the write fails. This is a compiler
debugging aid, not a user-facing feature.
Errors
Section titled “Errors”Diagnostics carry a source span with line and column, and are printed with the offending line and a caret:
Semantic Error: No overload of 'looks.say' matches these arguments at line 3, column 9 | 3 | looks.say("Hello from Katnip!", "two"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Multiple errors are reported per run. The parser recovers into error nodes, so semantic errors surface alongside syntax errors rather than hiding behind the first one — you get the whole list.
Each diagnostic is followed by an internal stack trace into the compiler. That is for compiler development; the first few lines are the part meant for you.
Exit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
| 0 | success |
| 1 | the build failed — diagnostics printed |
Suitable for CI:
katnip check src/game.knip || exit 1