lmclean guide
Rule execution lifecycle, File domain methods, interactive --serve REST mode, and standard lmcode_std_v3 interfaces for lmclean.
Overview
lmclean combines a deterministic native Rust filesystem walker with the lmcode bytecode virtual machine. Instead of hard-coding file-matching heuristics or shelling out to du and git, lmclean exposes a rich File object and three SAM callback interfaces (Ignore, Filter, and Report) that run inside verified DSLB v6 bytecode.
Walker pipeline and SAM interfaces
For each entry visited under the search roots, the walker runs a three-stage callback pipeline:
- Pruning (@ignore, implements Ignore): Every @ignore entry runs first. If any returns true, the candidate is skipped completely and, if it is a directory, its subtree is never traversed. lmclean has no implicit .gitignore rules; pruning is controlled explicitly by @ignore callbacks, --hidden, and --max-depth.
- Selection (@select, implements Filter): Every @select entry runs next. Multiple @select entries are combined with logical OR. When a directory matches, its recursive byte size (rsize) is computed once and the walker does not descend into its children.
- Auditing (@report, implements Report): When a candidate matches, each @report entry runs once with the matched File handle so rules can emit custom audit notes to stderr via print().
Deterministic recursive sizes and Git inspection
The File type distinguishes own metadata length (size()) from recursive content bytes (rsize()). Recursive size sums only non-directory entries inside a directory subtree, excluding filesystem-dependent directory inode sizes, counting symlinks by link length without following them, and skipping unreadable subtrees without aborting.
For workspace cleanup rules, File also provides recursive subtree timestamps (rmodified() and raccessed(), scanning non-.git descendants) and Git repository inspection methods: is_git_repo(), is_git_clean() (clean working tree, index, and stash), is_git_pushed() (all local branches pushed to a remote), and git_status() (returning not-git, dirty, no-remote, unpushed, or clean-pushed).
Interactive REST server mode (--serve)
Launching lmclean with --serve wraps the rule engine in a single-connection HTTP/1.1 JSON server so clients can scan once, slice the cached matches with view filters (min_size, max_size, ext, kind, name, path, older_than_days, newer_than_days, exclude, sort, order, limit, offset), preview summaries by extension or root, and execute guarded deletes with expect_matched and expect_bytes.
curl -sX POST http://127.0.0.1:PORT/scan?view=summary
curl -s "http://127.0.0.1:PORT/results?ext=log,tmp&min_size=1048576&sort=size&limit=20"
curl -sX PUT http://127.0.0.1:PORT/settings -d '{"params":{"stale_days":3}}'
curl -sX POST http://127.0.0.1:PORT/clean -d '{"filter":{"ext":"log"},"dry_run":true}'
curl -sX POST http://127.0.0.1:PORT/clean -d '{"filter":{"ext":"log"},"expect_matched":12,"expect_bytes":3489192}'
curl -sX POST http://127.0.0.1:PORT/shutdown
Standard REST and stateless CLI interfaces
In addition to --serve mode, lmclean embeds the 226-signature lmcode_std_v3 standard catalog, supporting RestGet..RestOptions, RestHandler, CliCommand, CliOption, :param and {param} route templates, rest_config, rest_route, rest_serve, rest_stop, and rest_cli inside _lmcode_ programs.
program = _lmcode_ cli="lmclean" install="github:lmctl-ai/lmclean@latest";
@"--exts"
fn opt_exts(x: RestExchange) -> void implements CliOption {
x.set("exts", x.query("exts"));
}
@"policy"
fn cmd_policy(x: RestExchange) -> void implements CliCommand {
let days = param_int("stale_days", 7);
x.send("policy:exts=" + x.get("exts") + ":days=" + str(days));
}
@"/policy/:profile"
fn get_policy(x: RestExchange) -> void implements RestGet {
x.json("{\"profile\":\"" + x.param("profile") + "\",\"exts\":\"" + x.get("exts") + "\"}");
}
rest_config("session", "global");
print(rest_cli(str_split("--exts=tmp,log policy", " ")));
print(rest_cli(str_split("--exts=tmp,log /policy/default", " ")));
end _lmcode_