NyaScript terminal automation
NyaScript runs interactive tasks using NyaTerm connections, terminals and credentials. Open Quick commands → Terminal macros → New script, edit the source, then choose Check or Run.
Editing and running
Scripts share the macro library, categories, import/export, backup and cloud sync. You can save unfinished source as a draft; execution requires a successful check. Diagnostics identify the source line and column. Editing after a run starts does not change that run.
The editor provides NyaScript highlighting, keyword and builtin completion, and function documentation on hover. It checks the source after 500 ms without edits; Check checks immediately. Click a diagnostic to locate its source. Warnings allow execution.
Checks validate literal regular expressions, key names, wait patterns and timeouts before execution. Parameter errors that a try/catch in the same task can handle produce warnings and retain their runtime behavior. Resource-limit errors still prevent execution. Variables and computed arguments remain validated at runtime.
Before execution, bind script aliases to saved connections, open sessions and credentials. Bindings apply to that run, so passwords need not appear in source. Existing step macros keep their recording and replay behavior. Older NyaTerm versions preserve script documents but display them as unsupported.
Newly recorded step macros send text literally, so {{...}} in Docker commands is not automatically treated as a variable. Enable Expand variables on a text step to use placeholders; extracting a variable enables this option automatically. Existing macros and manually added steps retain their original variable rules. Older NyaTerm versions preserve new macros containing literal steps but cannot execute them.
Macro and script exports include only their referenced categories and ancestors. Import creates document copies and reuses uniquely matching category paths; ambiguous paths or conflicting extension metadata reject the entire import. Imports and exports both have a 16 MiB limit. Export documents individually when the combined archive exceeds it.
Connections and interaction
connect("alias") opens a saved SSH terminal, Telnet, Serial or local connection. attach("alias") uses the selected open terminal. Targets are fixed for the run; changing tabs does not redirect input.
A connection opened by a script gives terminal login interaction to the script: Telnet auto-login, post-login commands and credential autofill are suspended for that launch. Saved settings remain intact. SSH protocol authentication, host verification and proxies use the existing connection flow. Resolve serial parameters before running.
Attaching an existing Telnet session also stops any unfinished auto-login for that session so it cannot compete with script input.
For this SSH example, bind router to a saved connection and adjust the prompt for the device:
let s = connect("router");
wait_regex(s, r"(?m)^router[>#]\s*$", 30000);
discard_pending(s);
sendln(s, "show version");
wait_regex(s, r"(?m)^router[>#]\s*$", 30000);
log("Inspection completed");
For Telnet login, bind device_password to a specific credential account:
let s = connect("telnet_device");
wait(s, "Username:");
sendln(s, "admin");
wait(s, "Password:");
sendln(s, secret("device_password"));
wait_regex(s, r"(?m)^device[>#]\s*$");
For an open serial terminal, use attach("console"). If the prompt is already displayed, send Enter to request another prompt; attach does not search previous screen history.
Waiting and control flow
wait matches literal text, wait_regex uses Rust regular expressions, and wait_any returns a matching candidate. The default timeout is 30 seconds; the optional final argument specifies milliseconds. Handle timeouts with try / catch; unhandled errors terminate the run.
let s = attach("target");
discard_pending(s);
sendln(s, "show version");
let result = wait_any(s, [
regex(r"(?m)^device[>#]\s*$"),
text("Invalid command")
], 30000);
if result.index == 1 {
fail("The device does not support this command");
}
log("The command returned");
Results expose zero-based index, matched text, and a groups list. groups[0] is the first capturing group; the full match is not included, and unmatched optional groups are empty strings. Regular expressions match currently received text; they do not wait for a potentially longer future match. Each evaluation chooses the leftmost match, breaking ties by candidate order. Empty matches, backreferences and look-around are unsupported.
Waits continue from unconsumed output and retain text following a match. Two consecutive waits can therefore consume prompts from the same output chunk. Sending does not clear the receive buffer; use discard_pending(s) to explicitly discard preceding pending output. Timeouts do not consume data.
Matching uses a normalized text event stream, retaining CR, LF and Tab while filtering ANSI/OSC sequences and other controls, including backspace. It is not a screen snapshot and does not reconstruct the final screen after cursor movement or backspace. For example, receiving AB, backspace, then C produces ABC in the matching stream. Include device names or line boundaries in prompt patterns instead of matching a bare # in ordinary output.
The language supports strings, integers, booleans, lists, let, assignment, if / else, while, for over lists, break, continue, return, and try / catch. Connection, session and secret aliases must be source string literals of at most 256 bytes. sleep(1000) waits one second. All loops have an execution budget.
Builtin functions
| Call | Behavior |
|---|---|
connect("alias"), attach("alias") | Return an exclusively owned session handle from a saved connection or existing session. |
send(s, value), sendln(s, value) | Send text or a secret reference; sendln appends Enter. |
send_key(s, "key") | Encode a special key using the current terminal mode. |
wait(s, value[, timeout]), wait_regex(s, value[, timeout]) | Wait for literal text or a regex and return the match. |
wait_any(s, patterns[, timeout]) | Wait for a list containing text(value) and regex(value) patterns. |
discard_pending(s) | Discard unconsumed output preceding the call's boundary. |
disconnect(s) | Close the session. |
secret("alias") | Return the secret reference bound for this run. |
sleep(milliseconds) | Delay; all delays and timeouts accept 0–86400000 milliseconds. |
log(message), fail(message) | Record a string or report failure with that string. |
join(task), cancel(task) | Wait for a child and its return value, or request its cancellation. |
send_key accepts enter, tab, escape, backspace, delete, up, down, left, right, home, end, ctrl+c, and ctrl+d. Square brackets in the table indicate optional arguments, not call syntax. End statements with semicolons and enclose blocks in braces.
Concurrency and batches
spawn creates a child task and join waits for completion. Children receive snapshots of ordinary variables and cannot share session handles; connect or attach to separate sessions inside each child.
let a = spawn {
let s = connect("edge_a");
wait(s, "edge-a#");
log("edge_a is ready");
};
let b = spawn {
let s = connect("edge_b");
wait(s, "edge-b#");
log("edge_b is ready");
};
join(a);
join(b);
Leaving the block that creates a child implicitly joins any children not already joined. Children cannot outlive their parent. Neither session nor task handles can be captured by a child or returned from one. An unhandled child error cancels the root run and its other children. Handle tolerated errors inside the child. cancel(task) requests child cancellation.
Scripts using connect("target") or attach("target") can enable Run for multiple targets in the binding dialog. Choose targets for target; concurrency defaults to 4 and accepts 1–16, with at most 256 selected targets. Each target runs independently, so one failure does not cancel the others. Stop all also clears the pending queue.
Stopping, secrets and logs
Typing or pasting in an owned terminal cancels its script before delivering your input. Stopping prevents subsequent sends; it cannot retract commands already received by the device and does not send Ctrl+C automatically. Terminals remain open after execution unless the script calls disconnect(s).
Pausing freezes script waits and delays while continuing to receive output. Disconnect, reconnect, transfer to another window, screen lock or output loss terminates execution. Configuration commands are not automatically replayed. Full-screen TUI automation is unsupported.
secret("alias") returns a secret reference usable only for sending, not logging or concatenation. The selected account is resolved at send time; account groups are not tried in sequence.
The run view shows status, duration, targets, tasks, source locations and explicit log messages, with filtering by task. Clicking a log or error location opens the source snapshot used by that run, even if the original script has since changed.
Export log retains the message-only text format. Export run report adds timestamps, targets, status, errors and task locations without automatically including full source, terminal output or credentials. Each run retains at most 2000 entries and 1 MiB of explicit logs; a truncation marker replaces further messages while execution continues. In-memory history retains at most 512 runs and applies a combined 64 MiB source/log budget, evicting the oldest completed records first. Results are not automatically stored in the database or cloud sync and do not enter application diagnostic logs. Do not hardcode passwords in source.
Unconsumed output is limited to 1 MiB per session and 8 MiB per run; exceeding the limit fails explicitly. A run allows up to 32 live tasks including the root, 16 sessions and one million interpreter instructions. Source is limited to 1 MiB; expressions, blocks and lists allow up to 64 nesting levels, and runtime values have an 8 MiB memory budget. A wait accepts at most 32 patterns of up to 4 KiB each; matched text and capturing groups have a combined 64 KiB limit. Scripts have no arbitrary file, network, process or module import APIs.