lmscript skill

For an LLM agent that writes or runs lmscript. lmscript looks like JavaScript or Python but is neither; most mistakes come from borrowing their syntax. Follow the rules below, then let lmscript --check and --dry-run prove the script before you run it. Verified against lmscript 0.2.348.

Purpose

lmscript automates local work: read and write files, transform CSV/JSON/TOML data, run other programs without a shell, and drive lmctl agent teams. A script is checked statically and simulated (dry pass) before every real run, so a correct script fails early instead of half-way.

When to use it

Install

Requires Node.js 24.15 or later.

npm install -g @lmctl-ai/lmctl
lmscript --version
lmscript 0.2.482

Commands

CommandUse
lmscript --check FILEStatic check only. Run after every edit.
lmscript --check-files FILECheck plus existence of path literals (i"…", o"…").
lmscript --dry-run FILE [ARGS]Simulate and print the plan of effects; changes nothing.
lmscript FILE [ARGS]Check statically, then run once.
lmscript -e 'CODE'Run a one-line program (quote it for the shell).
lmscript --lint FILEStops after checking, like --check.
lmscript --trace FILE.trace FILERun and write an execution trace.
lmscript --help NAMESignature, description and example of a function, built-in or topic (for example run_lmcode, lmcode_build, lmcode); lmscript --help lists all.
lmscript --lmcode-signatures SCHEMA [--without-std]List the canonical signatures of a host schema; with the standard catalog (226 signatures) unless --without-std.
lmscript --lmcode-schema SCHEMA [--json]Schema summary, or the exact schema as JSON.
lmscript install github:OWNER/REPO[@TAG]Attended one-off install of a native lmcode host.

Options go before the file; every word after the file is script data in ARGV.

Inputs and outputs

Syntax rules that differ from JavaScript and Python

Safety rules

Worked examples

Transform data with checked failures

rows = read_csv(i"orders.csv");          # fails before any effect if missing
require(len(rows) > 0, "orders.csv has no rows");
totals = {};
for (r in rows) {
  totals[r.customer] = totals.get(r.customer, 0) + r.amount;
}
write_json(o"totals.json", totals);
println(f"{len(keys(totals))} customers");

Run a tool and use its result

r = system git status --porcelain;
if (r.code != 0) {
  println(f"git failed: {trim(r.stderr)}");
  exit(1);
}
changed = [];
for (line in lines(r.stdout)) {
  if (!is_blank(line)) {
    push(changed, line);
  }
}
println(f"{len(changed)} changed file(s)");

Show the plan before deleting

lmscript --dry-run cleanup.lms
PLAN complete
1. /home/me/cleanup.lms:1:1 dummy write_file ["out/report.txt","done\n"]
2. /home/me/cleanup.lms:2:1 dummy delete_file ["out/notes.txt"]
3. /home/me/cleanup.lms:3:1 handled println ["cleaned up"]

Run a typed _lmcode_ program in a native host

An _lmcode_ block holds code in a separate, statically typed language that a native host program (for example lmhtml or lmcad) runs. The block constructs an opaque immutable program; lmscript compiles it at check time against the host schema, and only run_lmcode executes it. The earlier forms _dsl_, savedsl and dsl_cli are removed and are check errors.

check = _lmcode_ cli="lmhtml" install="github:lmctl-ai/lmhtml@latest";
let pages = html.load_dir("site");
for (i in range(0, pages.len())) {
  let page = pages.at(i);
  let links = page.links();
  for (j in range(0, links.len())) {
    let url = links.at(j);
    if (!html.link_exists(page, url)) {
      report.add("broken-link", page.path(), 0, url + " not found");
    }
  }
}
report.write_text("broken.txt");
end _lmcode_
r = run_lmcode(check);
require(r.ok, "host failed");
println(r.result);
lmscript --check links.lms
lmscript links.lms
null
cat broken.txt
broken-link site/index.html:0: missing.html not found

run_lmcode(program, options) returns the whole envelope as a map: {ok, result} for one program. Always test r.ok, because controlled host failures come back as data. Options accept args (a string list) and an optional command template containing exactly one $DSLFILE.

Several programs in one host process

load_schema(cli="HOST") or load_schema(schema="FILE") gives a reusable descriptor (the clauses must be literals). lmcode_build(host) creates a builder; builder.add(program) appends a program, and run_lmcode(builder) runs all of them in one host process and returns {ok, result: [...], parts}.

s = load_schema(cli="lmhtml");
a = _lmcode_ s;
$return = 1 + 2;
end _lmcode_
b = _lmcode_ s;
$return = "two";
end _lmcode_
builder = lmcode_build(s);
builder.add(a);
builder.add(b, fragment=["$DSLFILE"]);
r = run_lmcode(builder);
require(r.ok, "host failed");
println(r.parts);
println(r.result);
lmscript b.lms
2
[3,"two"]

lmhtml takes its program files as --lmcode FILE [FILE ...], so the second add passes only the file as its fragment; the default fragment is --lmcode $DSLFILE.

Rules inside a block: let x = expr; with inferred types, if/else, for (i in range(a, b)), for (item in collection), while with break/continue, switch, and top-level fn definitions; types int, float (write 1.0), string, bool and the schema's object types and enums; int and float never mix (float(i) converts); strings join with + and str(x). ${expr} splices an outer lmscript value as a typed literal, and $return sets the program result. Collections are host objects. The standard catalog lmcode_std_v3 (226 signatures in lmscript 0.2.482) is available in every block, including rest_config, rest_route, rest_serve, rest_stop, rest_cli, the RestExchange methods and the interfaces RestGet, RestPost, RestPut, RestDelete, RestPatch, RestHead, RestOptions, RestHandler, CliCommand and CliOption; see the guide for the tables. Hosts check the exact schema bytes, so a block is always compiled against the host that runs it.

Errors and exit codes

ExitMeaningWhat to do
0SuccessVerify the outputs (below).
1Run-time failure, failed require/assert, recorded error(), usage errorRead the error:FILE:LINE:COL line; fix the data handling or the guard.
2Check error: syntax, undeclared name, wrong arity, unknown function or method, bad data or LMCode block, missing i"…" pathNothing ran. Fix the reported position and run --check again.
Nexit(N)Script-defined.
Message (start)Fix
Expected ';' after the assignmentAdd ;.
Expected '{' after if (...)Add braces around the body.
Undeclared variable 'x'Assign x before the block, or fix the spelling.
Unexpected token '+' in expressionUsually x++ or x += 1: write x = x + 1;.
Unexpected token 'fn' in expressionNo anonymous functions; declare a top-level fn and pass its name.
Function declarations are only allowed at top levelMove the fn out of the other function.
map m has no key "k"m.has("k") or m.get("k", default).
Division by zeroGuard the divisor.
Compiler reports a method signature mismatchMatch the schema signature (--lmcode-signatures).

How to verify

  1. lmscript --check script.lms prints nothing and exits 0. Repeat after every edit.
  2. lmscript --check-files script.lms when the script uses path literals.
  3. lmscript --dry-run script.lms ARGS: the plan lists exactly the writes, deletes and program runs you intend, with the right arguments.
  4. Run it; confirm exit code 0 (or the documented code) and that the expected files or output exist, for example by reading them back with read_file/read_json or ls.
  5. For _lmcode_ blocks: --check compiles the block without starting the host; after the real run confirm r.ok is true, inspect r.result, and check the files the host program wrote.
  6. Report what you ran and what you checked; never claim success from exit code 0 alone when files were supposed to change.