Skip to content

nvs agent primer

nvs agent primer prints the one document that a coding agent reads before it writes Novis code.

The document has five parts, in this order. The first explains how to look things up with nvs agent find and nvs agent show. The second is one complete program with an explanation of each part. The third explains capabilities (the permissions a program needs, such as reading a file), with the smallest nvs.toml that allows a program to read a file. The fourth explains how nvs reload makes a running server use the code you changed. The last is a list of the chapters of the reference.

The command prints to standard output and writes no file. Each part is a whole section of the reference, copied from the nvs binary. Because of this, the primer always describes the language that this binary compiles.

Examples

A program written from the primer

<?nvs
// Shows a program that uses each syntax the worked program of `nvs agent primer` explains.
// Each comment names the syntax and says what the step prints.
// A variable has its type before its name. The type never changes.
array<string> $fields = ['12', '7', 'n/a', '30'];
// A `foreach` loop gives its variable a type too.
array<int> $quantities = [];
foreach ($fields as string $field) {
// `as ?int` converts a string to a whole number. "n/a" is not a number,
// so the result is `null` and the loop skips it.
?int $quantity = $field as ?int;
if ($quantity != null) {
$quantities[] = $quantity;
}
}
// Options are written as `{ key: value }` after the last argument.
// This prints `[30,12,7]`.
array<int> $ordered = Core\Arr::sort($quantities, { order: Core\Arr::Order::Desc });
echo Core\Json::encode($ordered), "\n";
// Every built-in function is a method of a `Core` class. This prints `49`.
echo Core\Arr::sum($quantities), "\n";
Output
[30,12,7]
49