CLS ships two orthogonal module systems that work side-by-side. Source modules (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/elfrask/cls/llms.txt
Use this file to discover all available pages before exploring further.
.clsx files) use an export/import mechanism to share symbols across files at the source level, and are the primary tool for day-to-day development. Compiled libraries (.clslib archives) package pre-compiled WASM binaries for distribution, functioning like a .dll or .so for CLS programs. Both systems share the same ModuleResolver abstraction so the runtime stays agnostic about where code comes from.
System A — Source Modules
Exporting Symbols
Any top-level declaration can be made public by prefixing it withexport. Declarations without export remain private to the file.
function, var, const, class, enum, structure.
Importing a Full Module
import "path" as alias loads the entire module and binds all its exported symbols under a namespace alias.
import "lib" — without as — uses the bare path as the namespace name.
Named Imports (from … import)
Pull specific symbols out of a module into the local scope:
as:
Merging a Module into Local Scope (include)
include "lib" imports every exported symbol directly into the current scope without a namespace prefix:
Module Loading Sequence
When the interpreter encounters animport statement it delegates to the ModuleResolver configured by the host node. The resolution order is:
Cache check
If the module has already been loaded this session, return the cached result immediately.
Internal modules
Check whether the path matches a built-in module (
math, json, async, or node-specific modules such as fs, http, Lib).External hook
Delegate to the node’s file-system hook (reads the
.clsx file from disk relative to the working directory, or modules/<pkg>/mod.clsx for installed packages).Interpreter::load_module_source). Only symbols marked export are returned to the caller — as a record value.
Multi-Module Type Checking
clx check understands imports. When you run it on a file, the type checker resolves every import and from statement, loads the referenced modules, and passes their exported declarations as a prelude to the type verifier. This means types defined in other files are fully available for annotation:
Inline Modules
Themodule (and namespace) keywords create a named, self-contained scope directly inside a file. The body executes in an isolated environment and its exported symbols are collected into a record bound to the module name.
System B — Compiled Libraries (.clslib)
.clslib files are zip archives that bundle pre-compiled .clbin binaries (WASM). They are the distribution format for third-party or performance-sensitive libraries — equivalent to a .dll or .so for CLS.
ClsLibResolver (separate from the source ModuleResolver, independently configurable by the host node). The resolver searches:
- The current working directory
- The
$CLS_LIB_PATHenvironment variable paths - Any additional paths registered by the node
.clslib files ship alongside a .clsapp package — not embedded inside it.
WASM codegen (
.clbin) and the full .clslib build pipeline are in active development. The Lib.load API is stable but the underlying WASM execution layer is not yet production-ready.Built-in Modules
These modules are available in every CLS environment without installation.math
Mathematical constants and functions:
abs, sqrt, pow, min, max, floor, ceil, round, sin, cos, tan, log, random, range, PI, E.json
JSON serialisation and deserialisation.
async
Async/await primitives. Core module — available everywhere.
fs / http / Lib
Desktop-only modules (available in the
clx/clxr nodes). fs provides filesystem access; http provides HTTP client; Lib provides .clslib loading.Dependency Management
Packages installed viaclx install (or clx add <pkg>) land in the modules/ directory of your project:
cls.json under the "dependencies" key:
clx install to materialise the modules/ directory from the lockfile, or clx add <pkg> to add and install a new package in one step.