Autocomplete()

is an advanced Netscript function.
In this function, data is an object with the following properties:
{
 servers: list of all servers in the game.
 txts: list of all text files on the current server.
 scripts: list of all scripts on the current server.
 flags: the same flags function as passed with ns. Calling this function adds all the flags as autocomplete arguments
}
This function is special as it must be declared as a top level function like main.
Example:
export function autocomplete(data, args) {
 return [...data.servers]; // This script autocompletes the list of servers.
 return [...data.servers, ...data.scripts]; // Autocomplete servers and scripts
 return ["low", "medium", "high"]; // Autocomplete 3 specific strings.
}
Terminal:
$ run demo.js mega\t
// results in
$ run demo.js megacorp