lmscript

lmscript logo

lmscript is a small scripting language and CLI for file operations, structured data, subprocesses, agent workflows and typed _lmcode_ programs that native lmcode hosts execute. This page is the quick reference; scripts run with the operator's full local authority (no sandbox), so run only trusted scripts.

Install and run

lmscript ships in the @lmctl-ai/lmctl npm package, which also installs lmctl.

npm i -g @lmctl-ai/lmctl
lmscript --version
lmscript --check script.lms
lmscript --dry-run script.lms
lmscript script.lms arg1 arg2
lmscript -e 'println("hi");'
lmscript --help run_lmcode
lmscript --version
lmscript 0.2.482

CLI modes and exit codes

ModeWhat it does
lmscript FILE [ARGS]Checks statically, then runs once.
--checkStatic check only, including compiling _lmcode_ blocks; never starts a host.
--lintStops after checking, like --check.
--dry-runChecks, then evaluates statements with effects off and prints PLAN.
--trace FILEWrites an execution trace to FILE.
Exit codeMeaning
0Success.
1Ordinary runtime failure (for example a failed require).
2Static check failure; nothing ran.
otherExplicit exit(N) codes and signals keep their codes.

CLI flags

Flag or formMeaning
--check, --lintCheck only.
--dry-runPrint the plan of effects without performing them.
--plan-format text|jsonPlan format; valid only with --dry-run.
--dry-loop-limit NLoop iteration limit for the dry run.
--trace FILEExecution trace file.
--resumepoint PATHStart at a named resume point of a recover block.
--pref FILEProperties file.
--check-filesAlso verify path literals against the file system.
--base-dir dir, --source-name labelBase directory and the source label used in diagnostics.
--saveas FILEListed in the usage line of lmscript --help.
FILE, https URL of an .lms file, -, -e CODEScript source: file, URL, standard input or inline code; words after it are script arguments.
lmscript install github:OWNER/REPO[@TAG]Attended one-off install of a native host; an omitted tag means @latest. Also npm:@lmctl-ai/TOOL@VERSION|latest.
--lmcode-signatures SCHEMA [--without-std]Print the canonical signatures of a host schema, with or without the standard catalog.
--lmcode-schema SCHEMA [--without-std] [--json]Print a schema summary, or the exact schema as JSON.
--help, --help NAMEList all functions and topics, or explain one function, built-in or topic (for example lmcode).

lmcode quick reference

ConstructSignatureMeaning
_lmcode_ blockp = _lmcode_ cli="X" install="github:lmctl-ai/X@latest"; ... end _lmcode_Constructs an opaque immutable program compiled against the host schema; it does not execute.
load_schemaload_schema(cli="X") or load_schema(schema="FILE")Reusable schema descriptor; write p = _lmcode_ s; to use it.
run_lmcoderun_lmcode(program_or_builder: lmcode, options?: map): mapRuns one program or one sealed builder in a single host process. Single result {ok, result}; builder result {ok, result: [...], parts}. Options: args, command.
lmcode_buildlmcode_build(host: lmcode schema | string | string list): lmcode_builderOne-process builder; builder.add(program) then run_lmcode(builder).
Standard cataloglmcode_std_v3, 226 signaturesAvailable in every block; includes rest_config, rest_route, rest_serve, rest_stop, rest_cli and the RestExchange methods.
Standard interfacesRestGet, RestPost, RestPut, RestDelete, RestPatch, RestHead, RestOptions, RestHandler, CliCommand, CliOptionREST endpoint and stateless CLI interfaces of the standard catalog.

Minimal _lmcode_ example

A complete script: the block is compiled against the lmhtml host schema at check time, and run_lmcode executes it in the host and returns the result envelope.

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

Documentation