lmok reference

CLI verbs, flags, Ts/Tree/Node host schema methods, SAM interfaces, standard REST and CLI interfaces, and exit codes for lmok.

CLI subcommands and flags

Verb or flagDescription
parse [--lang L] FILE|-Print the concrete syntax tree as a single-line S-expression.
query [--lang L] [--pattern] Q FILE...Run a tree-sitter S-expression query or code-shaped --pattern and print 0-based capture ranges.
lint PACK.json FILE|DIR... [OPTIONS]Run a JSON rule pack (--db, --new-since, --baseline, --changed[=REV], --fail-on-new, --sarif, --no-suppress).
check [--lang L] RULES.dslb FILE|DIR...Validate @NODE_KIND annotations against grammar L and dispatch compiled Rule callbacks over files.
ci [--config FILE] [--sarif FILE] [ROOT]Run project rules from .lmok/config.json and exit 1 if findings meet severity_floor.
rules PACK.json... / test PACK.json FIXTURE...List pack rule metadata as JSONL or verify annotated rule test fixtures.
facts [--lang L] FILE|DIR...Extract definitions, references, and edges as JSONL without a database.
index FILE|DIR... [--db PATH]Index file facts and FTS5 trigram source text into SQLite, skipping unchanged files.
symbols PAT / refs NAME / find PAT [--fts]Query stored SQLite symbols (LIKE), references (exact), or source text (literal or FTS5).
findings [--rule ID] [--file P] / status [--init]Read live recorded findings or inspect/initialize the SQLite database status.
outline FILE|DIR... [--budget N] [--db PATH]Print live symbol definitions, optionally ranked by stored reference counts.
metrics FILE... / dup [--tokens N] FILE...Report lines, functions, and max_nesting, or detect duplicate normalized token windows.
serve [--preset NAME] / remote ...Run the caching local REST API server or dispatch commands to LMOK_SERVER.
--lmcode FILE / --lmcode-schema [--json] / --lmcode-signaturesExecute compiled DSLB v6 bytecode or inspect the host schema and signatures.

Ts context, Tree, Node, and NodeList methods (lmok.dsl.json)

SignatureReturn typeDescription
ts.parse(s) / parse_c(s) / parse_cpp(s) / parse_python(s) / parse_bash(s) / parse_java(s)TreeParse UTF-8 source text with the JSON, C, C++, Python, Bash, or Java grammar.
ts.reparse(old, s) / reparse_c / reparse_cpp / reparse_python / reparse_bash / reparse_javaTreeIncrementally re-parse new source text against an edited Tree.
ts.changed_ranges(old: Tree, new: Tree)stringReturn changed byte and point ranges between two trees as a JSON array string.
ts.query(n, q) / query_c / query_cpp / query_python / query_bash / query_javaNodeListRun a tree-sitter S-expression query with predicates over subtree n.
ts.match_c(n: Node, pat: string) / match_python(n: Node, pat: string)NodeListMatch a code-shaped pattern ($VAR, ...) over a C or Python subtree.
ts.report(n: Node, msg: string[, rule: string, sev: string])voidAppend a finding to the per-run findings sink (capped at 65536 per run).
ts.report_fix(n, msg, rule, sev, fix) / ts.report_meta(n, msg, rule, sev, meta)voidAppend a finding with an autofix replacement or extra JSON metadata.
ts.report_count() / ts.report_json()int / stringReturn the number of recorded findings or serialize them as a JSON array string.
ts.db_files(pat: string) / ts.db_symbols(pat: string) / ts.db_refs(name: string)stringQuery stored files, symbols, or references from the active SQLite index as JSON.
Tree.sexp() / has_error() / node_count() / root() / nodes()string / bool / int / Node / NodeListInspect S-expression, syntax error flag, total nodes, root Node, or pre-order named NodeList.
Tree.edit(start_byte: int, old_end_byte: int, new_end_byte: int)voidRecord a byte-offset edit on a tree prior to calling ts.reparse*.
Node.kind() / text() / is_named() / is_missing()string / string / bool / boolNode grammar kind, source slice, named status, and missing-token placeholder flag.
Node.start_row() / start_col() / end_row() / end_col()intZero-based start and end row and byte column coordinates.
Node.child_count() / child(i: int) / has_parent() / parent()int / Node / bool / NodeNavigate named children or walk upward to the parent Node.
NodeList.len() / NodeList.at(i: int)int / NodeLength and bounds-checked element access on a NodeList.

SAM interfaces and standard REST/CLI interfaces (lmcode_std_v3)

InterfaceAnnotationSignatureRole
Rule@NODE_KIND(n: Node) -> voidCST node visitor dispatched by lmok check for every matching node kind.
RestGet..RestOptions, RestHandler@"/path/:param"(exchange: RestExchange) -> voidStandard lmcode_std_v3 HTTP route handler interfaces (current main; check --lmcode-signatures on a released host).
CliCommand, CliOption@"cmd" / @"--opt"(exchange: RestExchange) -> voidStandard lmcode_std_v3 stateless CLI handler interfaces for rest_cli.

Exit codes

CodeMeaning
0Execution succeeded (lint findings do not fail the run unless --fail-on-new is passed).
1Project quality gate failed in lmok ci (findings met or exceeded severity_floor).
2CLI usage error, unknown --lang, rule-pack format error, or missing SQLite DB on a read verb.
3Input or lmcode error: unreadable file, invalid query pattern, unreadable or corrupt DB, or LOAD_UNBOUND rule kind in check.
4Stdout write failure or new findings detected under lint --fail-on-new.