02 Command line
| Command | Does |
|---|---|
stardust convert INPUT OUTPUT [--from FORMAT] [--to FORMAT] [--no-sort] [--schema PATH] |
Converts between formats or formats a document |
stardust convert --from FILES --to FILES [--no-sort] [--schema PATH] |
Converts every file a path or glob names |
stardust fmt [PATH...] [--write] [--check] [--from FORMAT \vert FILES] [--include GLOB] [--exclude GLOB] [--schema PATH] |
Formats DUST and RON files, keeping their key order |
stardust eval FILE [--quiet] [--config FILE] [-- ARG...] |
Evaluates FILE form by form and writes each result as canonical DUST, stopping at the first error; --quiet writes only the program's own output (Script runner) |
stardust run FILE [--config FILE] [-- ARG...] |
Runs a script: stardust eval --quiet |
stardust repl [--config FILE] |
Starts the REPL |
stardust nrepl [options] |
Serves editor clients over TCP |
stardust namespace save PATH FILE --config FILE |
Validates and saves one namespace source file |
stardust namespace read PATH --config FILE |
Prints saved source as canonical DUST |
stardust namespace list [PREFIX] --config FILE |
Lists saved namespace paths and revisions |
stardust namespace delete PATH --expected-revision TX --config FILE |
Deletes a namespace at the expected revision |
stardust namespace apply FILE --config FILE |
Publishes one atomic batch of namespace changes |
Use stardust eval --config app.dust query.dust to read a database from DUST.
The configuration file app.dust names the database, for example
{plugins {stdlib true database {path "app.db"}}} (Configuration files).
The command preserves top-level locals between forms.
Each form reads a fresh database snapshot. The database file persists after evaluation.
See defquery for executable query examples.
An import in the file names a .dust file beside it, or a saved namespace of
the database. When both exist, the newer one is used
(Files).
convert supports .json, .edn, .tron, .ron, and .dust. The
input and output extensions select the formats. Using the same extension for
both files writes a normalized representation. The output file is written only
after the input has been parsed and converted successfully.
Use - for standard input or standard output. Specify standard input's format
with --from FORMAT and standard output's format with --to FORMAT. The
format names are json, edn, tron, ron, and dust. These options can
also override a file extension.
Comments go through every format. DUST, RON and EDN write each comment as
; lines above its value. JSON and TRON keep all comments of a document in
one $comment member, the first member of the root object. Its value is a
JSON string. The string holds an object from the RFC 6901 pointer of each
commented value to the text of its comment:
{"$comment":"{\"\":\"Spice math.\",\"/reserve\":\"reserve percent\"}","rates":{"arrakis":10,"caladan":15},"reserve":10}
- When the root is not an object, or is an object whose only key is
$value, the writer puts it in a wrapper:{"$comment": "…", "$value": root}. - A pointer has one step for each value. The step is the index of a list
item, an invocation argument or a pointer segment; the key of a map member;
or the name of a tag such as
#quoteor#link, which goes into its payload. For example, the1in{rule `(+ x 1)}is/rule/#quote/2. The""pointer is the root. - A
$commentmember below the root is ordinary data. - A root
$commentthat is not such an object, or that has a pointer to no value, is anInvalid_Commenterror. - A root object that has its own
$commentkey cannot go to JSON or TRON: the write fails withReserved_Key. DUST, RON and EDN write the key as data.
DUST, RON and EDN read only ; lines as comments, and use the same comment
rules. In DUST and RON, a $comment key is ordinary data.
A comment inside a template's payload is refused as Invalid_Comment: a
; line, in a template written as a tag or in a fenced template's embedded
form, or a root $comment pointer into the payload.
stardust convert input.dust output.json
stardust convert input.dust - --to json
cat input.edn | stardust convert - output.dust --from edn
cat input.dust | stardust convert - - --from dust --to json
stardust convert input.dust - --to dust --schema schema.dust
--from and --to also take files. --from is then a path or a glob, and
--to a path, or a directory followed by *.EXT or **/*.EXT. Each matching
file is converted to the path it maps to: the --to directory, then, with
**, the file's directories below the --from directory, then its name with
the --to extension. Formats come from the extensions. Missing directories are
created, an output that would not change is not rewritten, and two inputs that
map to one output are an error before anything is written. A single --from
file with a --to format name goes to standard output.
stardust convert --from order.ron --to order.dust
stardust convert --from 'data/**/*.json' --to 'out/**/*.dust' # data/x/b.json -> out/x/b.dust
stardust convert --from 'data/*.json' --to 'out/*.ron' # top level of data only
In a glob, *, ?, and [...] match within one name and a ** name matches
any number of names, none included. ** does not enter hidden directories,
and hidden files match only a name pattern that starts with ..
Run stardust convert -h for command help and examples.
DUST and RON output sorts map keys and the tags in a tag group, which gives
the canonical form. --no-sort keeps both in source order instead. Either way
a map's tag group comes first. A source that does not parse gives a
#err diagnostic with its line and column on standard error and exit status 1.
--schema PATH reads a declarative schema snapshot and uses its shape order
for DUST and RON output. --no-sort keeps source order and ignores the schema.
fmt also keeps source order, so it reads the snapshot but does not apply
its presentation. Parsing a schema snapshot never evaluates a DUST program.
fmt is convert from each file to its own format, dust or ron, with
--no-sort, and its output ends with a newline, as editors save files: DUST
output already does, and fmt adds one to RON output, which convert writes
without one. A PATH is a file, a directory, or - for standard input (with
--from dust or --from ron); with no PATH and no --from files, it is the
current directory. A directory is searched recursively for files that match an
--include glob (default *.dust and *.ron) and no --exclude glob.
Hidden files and directories, build, and vendor are always skipped, and an
excluded directory is not entered. A glob without / matches a name at any
depth; one with / matches the path below the directory. --from also takes
files, as for convert.
One file prints its result. --write (-w) rewrites each file whose result
differs: it writes a temporary file in the same directory, gives it the file's
permissions, and renames it over the file, so the file is never half written.
Through a symbolic link it rewrites the target and keeps the link. --check
writes nothing; it names each file formatting would change on standard error.
Several files need --write or --check. A file that does not parse gives
its path and a #err diagnostic on standard error, and the other files are
still formatted. The exit status is 1 when any file failed or would change, and
2 for an invalid combination of options.
stardust fmt order.dust
stardust fmt --write order.dust
stardust fmt --check # the current directory
stardust fmt --write src --exclude fixtures
stardust fmt --check . --include '*.dust'
stardust fmt --write --from 'src/**/*.dust'
cat order.dust | stardust fmt - --from dust
For example, with tags and keys out of order, and with a root list:
| Input | stardust fmt |
stardust convert ... --to dust |
|---|---|---|
{b 1 a 2 <z x>} |
{<z x> / = b 1= / = a 2}= |
{<x z> / = a 2= / = b 1}= |
[1 2 7] |
1, 2, 7 on three lines |
the same |
EDN lists and sets become arrays, while keywords, symbols, and characters become
text. Map keys become strings. Numeric ratios and decimal values become floating
point numbers; integers outside the supported range are rejected. EDN #inst
values are represented by #utc, and #uuid values become native UUIDs. Other EDN
tags retain their tag and value as DUST tagged elements. DUST tags are written
as EDN tagged elements when their names can be read as EDN tags; otherwise they
are represented as maps. These mappings do not preserve all original EDN types.
Only the first EDN form is read; an empty input reads as nil.
TRON encodes JSON-compatible values as a binary document. Floating-point
values retain their numeric kind, including integral floats such as 1.0.
This can differ from encoders that normalize integral floats to integers. A
Bytes value, #b64 in text formats, is written as binary data and read
back as Bytes.
Each REPL session can use 1 GiB of memory. stardust eval can use 256 MiB.
An nREPL session, and a REPL or eval with database storage, can use the
memory limit of its database. Exceeding the budget produces an error. Sessions retain top-level
locals and namespaces between evaluations. !reset starts a fresh session.
2.1. Selecting plugins
eval, run, repl, nrepl, test, request and namespace take their
plugins, capabilities and database from one configuration file: --config
FILE (Configuration files). There are no separate options for plugins or a
database.
Without --config, the CLI selects every plugin except backups: stdlib,
io, database, planner, sdks, skills, retention, blackholes,
objects and lsp. It grants the capabilities
that io uses: filesystem, secure random, processes, streams, network and terminal.
The database plugin has no storage settings, so evaluation works and each
database operation fails with no_database. When a command opens a database,
lsp listens on
port 1980, or the next free port, and writes its warning to standard error
(Editor integration).
The sdks plugin generates nothing without a configured language, and
skills writes nothing without dir;
retention removes no history without configured fields. The objects
plugin requires database, and its operations use database ABI requests. The
backups plugin requires database and cannot be selected with retention;
select it in a configuration file. On Windows, a file backup target refuses
the open with backups: the file target is not supported on Windows
(Backups).
A configuration file selects only the plugins that its plugins map names and
grants only the capabilities that it lists. stdlib adds library functions,
including seeded random, lexical paths and pure cryptography. io adds
host-backed operations and requires stdlib. The database plugin provides
named queries and mutations. planner adds query planning and requires
database. The plugin reference lists the members and dependencies from the
registered plugin catalog. With an empty plugins map, core expressions,
unqualified collection operations and native values remain available.
defquery and defmutation require database. The sdks development plugin
takes its settings in the configuration.
Unknown names and missing requirements are errors before evaluation begins.
{plugins <stdlib>}
stardust eval --config stdlib.dust text.dust
stardust eval arithmetic.dust
For example, (+ 20 22) works with an empty plugins map, while
(strings/case "upper" "arrakis") requires stdlib and returns "ARRAKIS".
Calling a function of a plugin that is not selected reports
#err <name unbound>. Selection also applies to loaded files,
interactive sessions and database evaluations. A smaller selection does not
reduce the size of the installed executable.
2.2. Configuration files
A configuration file contains the map that stardust_open takes
(Configuration and codecs). Its keys are workers, requests,
sessions, batch-size, limits, plugins, capabilities,
scheduled-reactors and imports. Its extension
selects the notation: .dust, .json, .edn, .ron or .tron. An unknown
or incorrect setting stops the command.
The settings of the database plugin give the storage. {path FILE} opens a
database file. {temporary true} opens a temporary database, which the
command deletes when it stops. Without these settings, there is no storage:
evaluation works, and each database operation fails with no_database. A
top-level path is refused.
imports {roots [DIRECTORY ...]} adds import roots. An import reads only
.dust files under a root (Files). For
eval and run, the first root is the directory of the program's file. For
repl and nrepl, it is the working directory. This setting adds the other
roots. A
relative directory is relative to the directory of the configuration file. A
directory that does not exist stops the command. The database does not use
this setting.
{plugins <io stdlib> capabilities {filesystem true} imports {roots [".."]}}
The repository's scripts in tools/ import lib/ with
tools/stardust.dust, whose root is the repository:
stardust run --config tools/stardust.dust tools/check-fmt.dust.
The namespace commands refuse a configuration without path. eval,
run and repl evaluate against the database when the configuration has storage, and
without a database otherwise. nrepl, request and test open the database
of the configuration, with or without storage.
{sessions 8 plugins {<stdlib io> database {path "arrakis.db"}} capabilities {filesystem true}}
stardust namespace list arrakis --config arrakis.dust
stardust nrepl --config arrakis.dust --port 7888
2.3. Script runner
stardust eval FILE -- ARG... runs a DUST program as a script. It writes the
result of each form, as eval always does. With --quiet, it writes only the
output that the program writes itself, for example with io/stdout/println.
stardust run FILE -- ARG... is stardust eval --quiet FILE -- ARG.... A
script can start with a shebang line such as #!/usr/bin/env -S stardust run.
stardust run report.dust -- --count 10 dune.dust
stardust eval --quiet --config tools/stardust.dust tools/client.dust -- 7888
stardust eval --config app.dust seed.dust
Without --config, the program has every plugin except backups and the filesystem, process,
stream, network and terminal grants. A configuration file gives only the
plugins and grants that it lists (Selecting plugins).
These script features work with and without a database:
cli/argsreturns the arguments afterFILE. Put--before the first argument that starts with-.scripts/pathreturns the absolute path ofFILE.- The first line can be a shebang line.
- The hooks that
processes/on-exitregisters run when the program stops. - INT, TERM, HUP or QUIT stops the program. The process groups of its child
processes receive the signal, the hooks run, and the command restores its
signal handlers and ends by that signal. The command waits for each child
to exit; a child that has not exited 2 seconds after the signal receives
SIGKILL.
A program uses a library file with import. The
path is relative to the program's file, not to the working directory. In
tools/client.dust, (import {nrepl "../lib/nrepl"}) names lib/nrepl.dust,
and only its exports are visible. The directory of the program's file is its
import root. This import thus needs a configuration whose imports roots
include the parent of lib/, as tools/stardust.dust does
(Configuration files). With database storage, the newer of
the file and a saved namespace of the path is used
(Files).
The program keeps its top-level locals between forms. It stops at the first
failure or returned #err, which it reports as eval does
(Errors and positions). An assertion failure gives status
1; processes/exit selects a status from 0 to 255.
When the --config file has database storage, the program runs in one
session of that database, through the requests of the ABI
(Scripts in sessions). sessions/open gets the
arguments and the path. Each form is one eval
request. A signal sends cancel with the signal for the running request, and
sessions/close runs the hooks. The memory and CPU limits of the database
apply to each request. Without storage, the program runs in the stardust
process.
A configuration file must select io and grant its capabilities to use these
services in eval, run, repl and nrepl. See DUST's
process, stream and utility contracts. Process, stream, TCP and terminal operations currently support Linux.
2.4. Generated function tests
stardust test FILE selects top-level function definitions and expressions in a
DUST file and runs the shared check operation. Non-function definitions remain
available during preparation. Preparation uses a read-only database session with
no filesystem, network, or process grants, whatever the configuration grants.
A configuration with path supplies namespace imports from that database and
reads it at a fixed snapshot, so the tests cannot write it. Without storage, a
write fails with no_database.
stardust test functions.dust --seed 42 --cases 1000 --size 256
stardust test functions.dust --replay 'BLOB'
The defaults are seed 0, 1,000 cases, and size 8,192. Each check retains the
existing database request limits, including five seconds of CPU. Large runs can
reach that limit; reduce --cases to fit the available budget. An incomplete run
exits 3. Hosts can configure their request limits when opening the database.
Replay cannot be combined
with generation flags. For one selected function the command prints its complete
native report. For several functions it prints a named report for each, followed
by a summary. Replay selects the first function whose definition and schema
snapshot match the blob. A file with no functions is unsupported.
| Exit | Meaning |
|---|---|
| 0 | All selected checks passed |
| 1 | A generated case failed |
| 2 | A selected function is unsupported |
| 3 | Invalid input, snapshot mismatch, or an interrupted/incomplete operation |
Reports retain minimized inputs, modeled effects, before/after state, shared schema diagnostics, and replay blobs. See check for supported contracts, isolation, resource limits, and replay rules. The command does not grant tested functions access to real host effects.
2.5. nREPL server
Start a server for an editor client:
stardust nrepl --config arrakis.dust
stardust nrepl --config arrakis.dust --port 7888
stardust nrepl --config arrakis.dust --bind 127.0.0.1 --port-file /tmp/stardust.port
All sessions of the server use the database that --config describes
(Configuration files). Because each session is a database session,
queries, mutations, saved namespaces and exported queries are available when
the configuration has storage. Without storage, sessions evaluate code. A
query or a mutation then returns #err <database no>, and save and
subscribe report no database in ex. With {plugins {database {temporary true}}}, the
server uses a temporary database and deletes it when it stops. The
sessions setting limits the number of open
sessions. An evaluation without a session uses a new session for that
request only. A different program that uses the same database file sees what
the sessions write and save. The editor connection of the lsp plugin is an
example.
The default address is 127.0.0.1 and the default port is 0, which asks
the operating system to choose a port. The server writes that port to
.nrepl-port in the current directory, or to the path given by --port-file.
On shutdown it removes the file only if it still contains this server's port.
The protocol has no authentication; choose the bind address accordingly.
Messages use bencode. These examples show their contents as maps:
client -> {op "clone", id "1"}
server <- {id "1", new-session "s-1", status ["done"]}
client -> {op "eval", id "2", session "s-1", code "(+ 1 2)\n(+ 3 4)"}
server <- {id "2", session "s-1", value "3"}
server <- {id "2", session "s-1", value "7"}
server <- {id "2", session "s-1", status ["done"]}
An import in eval names a file relative to the directory of the request's
file. Without file, it names a file relative to the working directory of
the server. When the database also has a saved namespace of the path, the
newer one is used (Files). The server reads
imported files from its own disk, and only under its import roots: its
working directory and the imports roots of its configuration. The root does
not follow file or file-path: a client cannot read a file outside the
roots, whatever grants the configuration gives.
load-file evaluates file, the full text of a file, as the session's code,
as the nREPL specification defines the operation. Each form returns its value
as in eval. An editor can send an unsaved buffer. The imports of the text
name files relative to the directory of file-path, and file-path names the
source in error responses. In this example, app/lib/shapes.dust exports
square:
client -> {op "load-file", id "3", session "s-1", file "(def unit 7)\n(* unit 2)", file-path "app/main.dust", file-name "main.dust"}
server <- {id "3", session "s-1", value "unit"}
server <- {id "3", session "s-1", value "14"}
server <- {id "3", session "s-1", status ["done"]}
client -> {op "eval", id "4", session "s-1", file "app/main.dust", code "(import {s \"lib/shapes\"})\n(s/square 3)"}
server <- {id "4", session "s-1", value "null"}
server <- {id "4", session "s-1", value "9"}
server <- {id "4", session "s-1", status ["done"]}
A failure in an imported file comes in ex, with file, line and column
in that file. lookup reports the name and type of a symbol from the session
or the core libraries:
client -> {op "lookup", id "5", session "s-1", sym "math/abs"}
server <- {id "5", session "s-1", info {name "math/abs", type "function"}, status ["done"]}
If the name is unknown, the response omits info.
describe maps each operation name to a descriptor. The descriptors are
empty unless the request has verbose?, which adds each operation's doc
and, for eval, its requires, optional, and returns fields:
client -> {op "describe", id "6"}
server <- {id "6", ops {clone {}, close {}, describe {}, eval {}, interrupt {}, load-file {}, lookup {}, save {}, stdin {}, subscribe {}}, status ["done"]}
subscribe sends the result of a query immediately and after each commit that
changes it, as queries/subscribe does (Database requests). To name an exported
query, give ns, query and optional args, a DUST list. Or give a query
map in code. Each event is a value with its tx. An interrupt with the
ID of the request, or close of the session, ends the subscription. Its last
message has status ["interrupted" "done"]:
client -> {op "subscribe", id "7", session "s-1", ns "dune/people", query "older", args "[18]"}
server <- {id "7", session "s-1", tx "4", value "[]"}
server <- {id "7", session "s-1", tx "8", value "[[\"Leto\"]]"}
client -> {op "interrupt", id "8", session "s-1", interrupt-id "7"}
server <- {id "8", session "s-1", status ["interrupted" "done"]}
server <- {id "7", session "s-1", status ["interrupted" "done"]}
save publishes the DUST source in file as the namespace ns, as
namespaces/save does (Namespace files). Add revision to require the
current revision of the namespace. The revision 0 requires that the
namespace does not exist. The value is the result of the save. A failure
comes in ex, with its position in file:
client -> {op "save", id "9", ns "dune/people", file "(defquery older [minimum] {find [?n] <tuples> where [[?e name ?n] [?e age ?a] (> ?a minimum)] order-by [?n]})\n(export older)"}
server <- {id "9", value "{namespaces [{<!deleted> entity #link 1 path \"dune/people\" revision 4}] tx 4}"}
server <- {id "9", status ["done"]}
eval with ns evaluates the code in the scope of the namespace of a file
that the session imported. ns is the path of the file, relative to the
working directory of the server, with or without .dust, such as
ns "app/lib/shapes". The private definitions of the namespace are then
visible (eval namespace in Namespace files). The
server ignores an ns that names no imported file.
clone starts a fresh session; copying a session is unsupported. eval
returns each top-level form's result separately, as one DUST form: a list
keeps its brackets, so [1 2 (+ 3 4)] returns [1 2 7] and [] returns
[], and map keys are in canonical order. A session keeps the
top-level locals that its evaluations define. A returned #err is a DUST value: it
arrives in value, with file, line, and column for its source. Parse,
compilation, and evaluation failures arrive in ex. interrupt stops an evaluation
at a checkpoint and leaves the session usable. Completed mutations are not
rolled back. Run stardust nrepl -h for the options and examples.
eval writes each form's result to standard output and exits with 0. It stops
at the first form that fails or returns an #err value, writes the error to
standard error as a #err element, and exits with 1. Results written before
that form stay on standard output. A returned #err gets the line and
column of its top-level form, unless it has its own line or column. A
parse or compile failure gives the position of the source that failed; other
failures, such as an exceeded memory limit, have no position. With database
storage in --config, each failure after parsing arrives as an #err value
and gets the position of its top-level form. run reports errors in the same
way:
$ echo '(/ 1 0)' > zero.dust
$ stardust eval zero.dust
#err {<division integer zero>
column 1
line 1
message "division by zero"}
The tag group classifies the failure; the other members are diagnostics. See error tags for every tag set.