janua

v0.6.3
@nathwn12/janua Checked 6 hours ago Published 1 day ago

Persistent interactive terminals for agents: spawn once, then write and read across calls.

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

pty_spawn Spawn interactive terminal

Start a program in a persistent pseudo-terminal and return {sessionId, pid, title, name, reused}. The program keeps running until pty_kill or its own exit; nothing is run through a shell, so command and args are passed exactly as given. On Windows a bare name is resolved through PATH and PATHEXT, and a .cmd/.bat shim (npm, npx, pnpm, yarn, tsc) runs through cmd /c with its arguments quoted. Give a name to address the session by name later; a live name returns that same session with reused: true unless reuse is false, which is invalid_args. Use this for anything you need to talk to (dev servers…

ParameterTypeDescription
command *stringExecutable to run: a name resolved on PATH, or an absolute path. No shell string.
argsarrayArguments for command, one array entry each.
colsintegerTerminal columns (default 80).
cwdstringWorking directory for the program. Must exist. Defaults to the server process cwd.
descriptionstringWhat this session is for, in 5-10 words, so a later read of pty_list makes sense on its own. Optional (defaults to the title) and at most 200 characters.
envobjectExtra environment variables, merged over the server environment.
namestringOptional stable name (1-64 characters: letter or digit first, then letters, digits, ".", "_" or "-"). Every sessionId input accepts it too.
reusebooleanWhen name is already used by a live session, return that session instead of spawning (default true). false makes it invalid_args with name_taken.
rowsintegerTerminal rows (default 24).
titlestringShort label for this session, shown by pty_list. Defaults to the command name.

pty_write Write to terminal

Send keystrokes to a running session. newline (default true) appends a line ending: a carriage return to a PTY session, which is what a shell or prompt is waiting for, or a newline to a pipe session from run, because a pipe has no terminal translation. Returns {ok}. Give waitMs (and optionally match, with the same semantics as pty_read) to read the answer in the same call: the response then also carries {data, cursor, exited, exitCode, dropped, matched, incomplete, truncated}. Without waitMs nothing is read, so a caller that expects output must either pass waitMs here or call pty_read next.

ParameterTypeDescription
data *stringText to send. Escape sequences such as \u0003 (Ctrl+C) are sent literally.
sessionId *stringSession id or name: the id pty_spawn or run returned, or the name given at spawn.
cursorintegerByte offset to read from after writing. Omit to read from the start of the buffer.
matchstringRegular expression (at most 200 characters) to wait for after writing; needs waitMs > 0.
maxBytesintegerMaximum bytes to return after writing (default 8000).
newlinebooleanAppend a carriage return after data (default true).
stripAnsibooleanRemove ANSI escape sequences from the reply (default true). The cursor still counts raw bytes.
waitMsintegerAfter writing, wait up to this many milliseconds for a reply and return it (default 0: write only).

pty_read Read terminal output

Read output from a session, starting at cursor, and return {data, cursor, exited, exitCode, dropped, matched, incomplete, truncated}. Pass the cursor from the previous read to get only new output; omit it to read from the oldest byte still buffered. maxBytes bounds the returned data. A read may exceed it to finish the one UTF-8 character or escape sequence that straddles the end, and it stops widening at maxBytes + 65536 bytes: if an escape sequence is still unfinished there, the whole 65536-byte overage is returned as literal text and the cursor advances. The overage is never more than 65536…

ParameterTypeDescription
sessionId *stringSession id or name: the id pty_spawn or run returned, or the name given at spawn.
cursorintegerByte offset from the previous read. Omit to read from the start of the buffer.
matchstringRegular expression (at most 200 characters) the text from cursor must match before the read returns; with stripAnsi false it matches the raw text.
maxBytesintegerMaximum bytes to return (default 8000).
stripAnsibooleanRemove ANSI escape sequences from data (default true). The cursor still counts raw bytes.
waitMsintegerWait up to this many milliseconds for new output (default 0).

pty_resize Resize terminal

Change the size of a running session's terminal, so a full-screen program stops being pinned to the geometry it was spawned with. cols and rows are integers 1..1000; give both, or give one and the other keeps the size in force. The program is told at once: on POSIX it receives SIGWINCH, on Windows the ConPTY itself is resized, so a TUI redraws at the new size instead of staying at the old one. Returns {ok, cols, rows} for the size now in force, which pty_list also reports. A call naming neither dimension is invalid_args; resizing a session whose program has already exited is pty_resize_failed,…

ParameterTypeDescription
sessionId *stringSession id or name: the id pty_spawn or run returned, or the name given at spawn.
colsintegerTerminal columns to apply. Omit to keep the current columns; at least one of cols and rows is required.
rowsintegerTerminal rows to apply. Omit to keep the current rows; at least one of cols and rows is required.

pty_kill Kill terminal

Terminate a session's program and confirm it is gone: returns {ok, exited, exitCode, pid}. exited is the state observed after the kill, not the request, so ok:false with an error naming the pid means the process survived and the message carries the fallback. Idempotent: killing an already-exited session returns ok:true, exited:true. The session stays listed with its exit code so its last output can still be read.

ParameterTypeDescription
sessionId *stringSession id or name: the id pty_spawn or run returned, or the name given at spawn.
signalstringPOSIX signal name (default SIGTERM). Ignored on Windows, where the process tree is terminated.

pty_list List terminals

List sessions this server knows about, newest last, one page at a time: sessionId, name, pid, title, command, args, cwd, description, cols, rows, pipe, exited, exitCode, bytes emitted, and createdAt. name is the name given at spawn (or null). cols and rows are the size in force now, so a session resized with pty_resize reports the new geometry here; pipe is true for a run session with no terminal, and its cols and rows are 0. Returns {sessions, total, nextOffset}: total counts every session known, and nextOffset is null on the last page. Use it to recover a session id or name you lost, or to r…

ParameterTypeDescription
limitintegerSessions to return (default 50, max 200).
offsetintegerSessions to skip from the oldest (default 0).