lmscript user guide

This reference follows lmscript 0.2.373, the published compiler used to check the examples. lmscript is in the @lmctl-ai/lmctl package and requires Node.js 24.15 or later.

Overview

A script is a UTF-8 .lms file. lmscript checks the whole file before running it, then normally performs a short dry preflight before the real run. The dry pass records planned writes, deletes and child processes; it is useful for review but it is not a security sandbox. Scripts run with the invoking user's local authority.

The diagram shows a normal run; --check stops after checking, --dry-run stops after simulation, and --no-preflight skips simulation.

A script is checked, preflighted to preview planned effects, and then run for real.

Use lmscript directly for a standalone script. Use lmctl script FILE when a script needs lmctl's installed provider configuration and agent services. Use lmctl autorun URL (or a local .lms file) to check declared provider roles, map missing providers, and run the script.

Install and first checks

After installing, download hello-vars.lms into examples/ under your working directory before running the example commands.

npm install -g @lmctl-ai/lmctl
lmscript --version
lmscript --check examples/hello-vars.lms Ada
lmscript --dry-run examples/hello-vars.lms Ada
lmctl script examples/hello-vars.lms Ada

The static-check option checks syntax, names, calls and embedded blocks without running the script. Dry-run mode executes only the simulated pass and prints its plan. A normal run checks first, performs the preflight, then executes for real. The no-preflight option skips only the dry pass. The signature-printing option prints canonical signatures for a schema v2 native host.

Values and syntax

Values are null, booleans, numbers, strings, lists and maps. Statements end in semicolons. if, for, while and function bodies use braces. Lists and maps are mutable references; use clone when you need a shallow copy. A missing map key or list index is an error; use has or get with a default when absence is expected.

for (name in ["Ada", "Lin"]) {
  println(f"Hello, {name}");
}

fn area(width, height) {
  return width * height;
}
require(area(3, 4) == 12, "area calculation failed");

Invocation values and properties

NameMeaning
ARGVList of arguments after the script name. ARGV.get(0, fallback) safely reads the first value.
DirectoryCurrent working directory for this invocation.
NonInteractiveBoolean invocation fact used to avoid opening an interactive terminal when the run is non-interactive.
PROPSRead-only view of lmctl properties loaded from init.toml and an optional --pref file. Property keys are case-insensitive; use set_property for in-memory overrides.

Directory and NonInteractive are read-only and cannot be set in init.toml. Standalone lmscript and lmctl script can both read the configured init.toml properties; use --pref FILE before the script to overlay one explicit properties file. lmctl script also connects the lmctl automation functions to provider sessions and team services.

Data and native blocks

JSON, CSV, TOML and properties blocks parse embedded data. Command and GraphQL blocks have their own checked forms. Experimental typed native blocks compile code against a host schema. They can select a release host with an install declaration; the host provides the schema, and run_lmcode runs the block through it. The schema, compiler and host must agree.

p = _lmcode_ cli="lmdraw" install="github:lmctl-ai/lmdraw@latest";
scene.canvas(480, 270, "#152438");
scene.text(32.0, 76.0, 32.0, "Hello", "#f5c16c");
scene.render_png("build/rendered/hello.png", 480, 270, 1);
end _lmcode_
r = run_lmcode(p);
require(r.ok, "lmdraw failed");

Native host install cache

A declaration using install with @latest checks for a newer release at most once every six hours per exact install string. The verified binary and the last successful release check are stored in the lmscript tool cache. A fresh check uses the cached binary when GitHub is temporarily unavailable and prints a warning. An exact release tag needs no release lookup after its binary is cached and SHA-256 verified.

Set LMSCRIPT_INSTALL_CACHE_TTL_MS to a non-negative number of milliseconds to change the @latest check interval. Set it to 0 to check on every real run. Leave it unset for the six-hour default. CI jobs with fresh runners should pin an exact release tag so every run uses a deliberate release and does not depend on the mutable latest endpoint.

Built-in lmctl functions

The following names are the lmctl automation functions listed by lmscript 0.2.460. Provider calls can create sessions or send messages; review the script before running it.

lm_batch_close(handle, status, error)
lm_batch_open(teamfile, alias, batchfile, options)
lm_batch_open(member, options)
lm_batch_turn(handle, prompt, index, total)
lm_classify_failure(text, options)
lm_error(value, ...values)
lm_exit(code)
lm_lint(teamfile)
lm_log(value, ...values)
lm_member(teamfile, alias)
lm_members(teamfile)
lm_prompt(teamfile, alias, prompt, options)
lm_ratelimit_readings(options)
lm_read_paragraphs(file)
lm_read_prompts(batchfile, single)
lm_running(options)
lm_seed(teamfile, options)
lm_session_close(member)
lm_session_delete(member, options)
lm_session_get(target)
lm_session_list(options)
lm_session_turn(member, prompt, options)
lm_terminal(teamfile, alias)
prompt_human(question)

lm_seed creates missing provider sessions in a teamfile. lm_prompt sends one turn to a named member. lm_terminal opens the provider's interactive interface. The remaining calls inspect or control sessions, batches, usage, teamfiles and recorded errors. Exact optional arguments are listed by lmscript help.

Agent functions

The agent functions talk to a model or an AI coding tool through one vocabulary, with no team file. A spec map names the provider and optionally the model, a system prompt and the tools an embedded model may use.

agent_providers(options)
agent_models(provider, options)
agent_open(spec, options)
agent_turn(agent, prompt, options)
agent_tool_result(agent, results, options)
agent_prompt(spec, prompt, options)
agent_info(agent)
agent_history(agent, options)
agent_compact(agent, options)
agent_usage(options)
agent_close(agent, status)

agent_prompt opens a session, runs one turn and closes it. agent_open keeps the session for several turns and can resume one by session_id. Every turn returns status, reply, tool_calls, usage and, for embedded models, the files their write tools created or changed. The agentic recipes use agent_prompt.

Command-line reference

FormUse
lmscript FILE [ARGS...]Run a standalone script; remaining words become ARGV.
lmscript --check FILE [ARGS...]Static check only; exit 0 or 2.
lmscript --dry-run FILE [ARGS...]Run the simulation and print its plan; exit 0 or 2.
lmscript --lmcode-signatures SCHEMAPrint canonical DSL signatures from a schema file.
lmctl script FILE [ARGS...]Run with lmctl provider configuration and automation services.
lmctl autorun URL or ./FILE.lmsFetch or load a script, check declared provider roles, map missing providers, and run it. Requires a build with autorun support; @lmctl-ai/lmctl 0.2.373 does not include this command. Use --save-only to guarantee saving without execution. Non-interactive mapping proposals are saved; when all providers are installed, the current implementation can execute.

Other useful options include --no-preflight, --plan-format text|json, --dry-loop-limit N, --dryrun-timeout MS, --pref FILE, --module SPEC=FILE, --trace FILE, --base-dir DIR and --source-name LABEL. Run lmscript --help for the installed compiler's full option list.

Common errors and fixes

Message patternFix
Undeclared variableAssign the name before a block if it is needed afterward; block-created names stay in that block.
Wrong argument count or unknown functionCheck spelling and arity with lmscript help NAME or lmscript help.
Missing map key or list indexUse has(key) or get(key, default) before reading optional data.
Check error in a native blockCompare the call and types with the host's schema summary; use its JSON schema output for compiler input and match the pinned host release.
require failed or run-time errorRead the located diagnostic, correct the input or condition, then rerun --check before the script.
Provider unavailableRun lmctl init, choose an installed provider and model, then rerun the team workflow.

Exit codes

Limits and trust

lmscript is not a sandbox. File, process and network functions use the invoking user's authority. Dry run is an effect preview and does not make untrusted code safe. Read scripts before running them, especially scripts that seed or prompt providers, write files, or launch processes.

lmscript collections are native lists and maps. In LMCode bytecode, collections are host-defined objects with methods such as len and at; the bytecode has no general list or map value type.