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 flag | Description |
|---|---|
| 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-signatures | Execute compiled DSLB v6 bytecode or inspect the host schema and signatures. |
Ts context, Tree, Node, and NodeList methods (lmok.dsl.json)
| Signature | Return type | Description |
|---|---|---|
| ts.parse(s) / parse_c(s) / parse_cpp(s) / parse_python(s) / parse_bash(s) / parse_java(s) | Tree | Parse 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_java | Tree | Incrementally re-parse new source text against an edited Tree. |
| ts.changed_ranges(old: Tree, new: Tree) | string | Return 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_java | NodeList | Run a tree-sitter S-expression query with predicates over subtree n. |
| ts.match_c(n: Node, pat: string) / match_python(n: Node, pat: string) | NodeList | Match a code-shaped pattern ($VAR, ...) over a C or Python subtree. |
| ts.report(n: Node, msg: string[, rule: string, sev: string]) | void | Append 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) | void | Append a finding with an autofix replacement or extra JSON metadata. |
| ts.report_count() / ts.report_json() | int / string | Return 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) | string | Query stored files, symbols, or references from the active SQLite index as JSON. |
| Tree.sexp() / has_error() / node_count() / root() / nodes() | string / bool / int / Node / NodeList | Inspect 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) | void | Record a byte-offset edit on a tree prior to calling ts.reparse*. |
| Node.kind() / text() / is_named() / is_missing() | string / string / bool / bool | Node grammar kind, source slice, named status, and missing-token placeholder flag. |
| Node.start_row() / start_col() / end_row() / end_col() | int | Zero-based start and end row and byte column coordinates. |
| Node.child_count() / child(i: int) / has_parent() / parent() | int / Node / bool / Node | Navigate named children or walk upward to the parent Node. |
| NodeList.len() / NodeList.at(i: int) | int / Node | Length and bounds-checked element access on a NodeList. |
SAM interfaces and standard REST/CLI interfaces (lmcode_std_v3)
| Interface | Annotation | Signature | Role |
|---|---|---|---|
| Rule | @NODE_KIND | (n: Node) -> void | CST node visitor dispatched by lmok check for every matching node kind. |
| RestGet..RestOptions, RestHandler | @"/path/:param" | (exchange: RestExchange) -> void | Standard lmcode_std_v3 HTTP route handler interfaces (current main; check --lmcode-signatures on a released host). |
| CliCommand, CliOption | @"cmd" / @"--opt" | (exchange: RestExchange) -> void | Standard lmcode_std_v3 stateless CLI handler interfaces for rest_cli. |
Exit codes
| Code | Meaning |
|---|---|
| 0 | Execution succeeded (lint findings do not fail the run unless --fail-on-new is passed). |
| 1 | Project quality gate failed in lmok ci (findings met or exceeded severity_floor). |
| 2 | CLI usage error, unknown --lang, rule-pack format error, or missing SQLite DB on a read verb. |
| 3 | Input or lmcode error: unreadable file, invalid query pattern, unreadable or corrupt DB, or LOAD_UNBOUND rule kind in check. |
| 4 | Stdout write failure or new findings detected under lint --fail-on-new. |