Skip to content

A worked session

An example of how a coding agent finds the right method with the nvs agent commands.

The agent has to print the length of a name. It knows the PHP function strlen, so it runs nvs agent find strlen. The command prints nothing, because Novis has nothing with that name. The agent then runs nvs agent find length and gets the functions Core\Str::length and Core\Bytes::length, and also the enum Novis\Intl\DateFormat::Length. nvs agent show 'Core\Str::length' prints the description, which says that this method counts characters and not bytes. The agent uses it, and nvs check accepts the program. For the name "Zoë" the program prints 3.

nvs check gives the same help. A program that calls strlen does not compile, and the error names Core\Str::length as the replacement.

A keyword is found the same way. nvs agent find autoload returns a heading of the reference, and nvs agent show with that heading prints the section.

Examples

A name that must fit

<?nvs
// Shows a program that was written after three lookups with `nvs agent`.
// It checks that a name has at most 20 characters and at most 32 bytes.
// `nvs agent find length` lists the functions `Core\Str::length` and `Core\Bytes::length`.
// `nvs agent show 'Core\Str::length'` prints that this function counts characters.
array<string> $names = ['Zoë', 'Björk Guðmundsdóttir', '👩‍👩‍👧‍👦 The Family Account Of Us'];
foreach ($names as string $name) {
uint $characters = Core\Str::length($name);
// `nvs agent show 'Core\Bytes::length'` prints that this function counts bytes.
// `as bytes` converts the text to its bytes. "Zoë" has 3 characters and 4 bytes.
uint $size = Core\Bytes::length($name as bytes);
string $verdict = $characters <= 20 && $size <= 32 ? 'fits' : 'too long';
echo $name, ': ', $characters, ' characters, ', $size, ' bytes, ', $verdict, "\n";
}
// The last name has 26 characters, so its line ends with `too long`.
// `nvs check 01-a-name-that-must-fit.nvs` prints `no errors` for this file.
Output
Zoë: 3 characters, 4 bytes, fits
Björk Guðmundsdóttir: 20 characters, 23 bytes, fits
👩‍👩‍👧‍👦 The Family Account Of Us: 26 characters, 50 bytes, too long