Skip to content

Running Commands ​

loomtty run runs one command on this machine or on other machines you have saved as [[remote.hosts]], waits for it to end and prints its output and exit status. It is meant for builds and tests on other machines, started by a person or by a coding agent, without wrapping commands in ssh '...'.

bash
# on this machine
loomtty run -- cargo test -p mycrate

# on two build machines at once, with this checkout's uncommitted changes
loomtty run --on build,mac --tree -- cargo test -p mycrate

The model ​

  • An argument list, not a shell string. Everything after -- reaches the program exactly as typed: no shell runs in between, so there is no second round of quoting. When you want a pipeline, && or a glob, say which shell: loomtty run -- sh -c 'make && make test' or loomtty run --on build -- pwsh -c 'Get-ChildItem | Measure-Object'. On Windows, .cmd and .bat files are run as cmd /c build.cmd.

  • A real pane. The command runs in a pane of the server's jobs session (an internal session that is never saved and that plain loomtty never attaches to by itself). You can watch it, or take over, with loomtty attach jobs on that machine while a run is active.

  • The output comes back at the end. While the command runs you see one line, [build] started k3f9a2b8c1d0. When every host is done, loomtty prints one block per host: a header with the result, the last 200 lines of output (--tail N or --all for more), and an end line. The log is the text the pane showed, and it stays on that machine for 7 days.

  • The run belongs to the server, not to you. Ctrl+C, a dropped network or a closed laptop only end the waiting. The command keeps going, and loomtty prints the two commands that pick it up again:

    bash
    loomtty runs log build:k3f9a2b8c1d0    # its output (so far)
    loomtty runs stop build:k3f9a2b8c1d0   # stop it and everything it started

    loomtty runs ls build lists the recent runs on a machine.

  • Waiting later. loomtty runs wait build:k3f9a2b8c1d0 waits for a run that is already going (one started with --no-wait, or one whose wait was cut off) and prints the same block and exit status run would have. A run that has already ended is answered at once. Ctrl+C again only stops the waiting.

    bash
    addr=$(loomtty run --on build --no-wait -- cargo build --release)
    # ... other work ...
    loomtty runs wait "$addr"
  • The exit status is the command's. With several hosts it is 0 if all succeeded, else the first failure in --on order. loomtty's own failures have fixed codes: 124 timed out (--timeout), 125 loomtty could not do its part, 126 the program could not start.

Sending your working tree (--tree) ​

With --tree, loomtty sends the code you have here, uncommitted changes included, before running the command:

  1. It turns the working tree (tracked changes and new files that are not ignored) into a commit on top of HEAD. Your index, branch and files are not touched, and you do not need to commit anything.
  2. It pushes that commit to each host's copy of the repository with git push over ssh.
  3. The host checks it out into a build directory of its own, one per tree name (by default your branch name), and runs the command there.

Each host needs to know where the repository and the build directories are, in this machine's config:

toml
[[remote.hosts]]
name = "build"
host = "build.example.com"

[remote.hosts.repos.myproject]      # the local repository's directory name
repo = "C:/src/myproject"           # any clone of it on that host
builds = "D:/builds/myproject"      # one subdirectory per tree name

Good to know:

  • Build directories are disposable. The next --tree run with the same tree name overwrites changes to tracked files there, so never edit inside them; edit here and run again. loomtty only reuses build directories it created itself: a worktree of yours that happens to sit at that path is refused, untouched.
  • repo and builds are absolute paths on the host (/srv/proj, D:/proj); ~ and relative paths are refused.
  • Files the command changed in the build directory are listed after its output; they are not copied back.
  • Submodules and Git LFS files are not sent.
  • Untracked files over 50 MiB are refused unless you pass --allow-large.
  • A build cache shared between tree names (for example one CARGO_TARGET_DIR in the host's env) is fine for Cargo, which locks it, but not for tools that do not.

Directories synced with Mutagen ​

If you keep a copy of a project in sync with another machine through Mutagen, run from inside your local copy and leave out --cwd:

bash
cd ~/dev/myproject/crates/app
loomtty run --on build -- cargo test
# [build] mutagen myproject synced; running in D:/work/myproject/crates/app

Before a run on another host without --tree, loomtty asks Mutagen for its sync sessions (mutagen sync list):

  • Working directory. Without --cwd, if the current directory is inside the local end of a session whose other end is on that host, the command runs in the matching directory there. With several matches the session with the longest root wins. A session whose remote path is relative to the home directory is not used for this.
  • Sync first. When the directory the command runs in (derived, or given with --cwd) is inside such a session's remote root, loomtty runs mutagen sync flush on it first, so the host has your latest edits. If the flush fails (session paused, host unreachable, over 120 s) the run does not start and loomtty exits with 125. A session with conflicts after the flush gets a warning, and the run goes ahead.
  • Matching the host. Mutagen names an ssh host; it is the same machine as a [[remote.hosts]] entry when it equals the entry's name, its host without user@, or when ssh -G resolves both to the same host name and port.
  • --no-sync skips all of this. Without a mutagen program, a running Mutagen daemon (loomtty does not start it) or a matching session, run behaves as it would without Mutagen.

Output for programs (--pipe) ​

The pane's log suits people and agents reading build output, not parsing: stdout and stderr are mixed, long lines are wrapped at 200 columns, and on Windows the console redraws it. With --pipe the command runs without a terminal, and its output comes back exactly as it was written:

bash
head=$(loomtty run --pipe --on mac -- git rev-parse HEAD)   # only those 41 bytes
loomtty run --pipe --on build -- cargo metadata --format-version 1 > meta.json 2> err.txt
  • The command's stdin is empty; its stdout and stderr go, byte for byte and apart, to files on that machine (up to 64 MiB each; past that the rest is dropped). Once it has ended, loomtty writes them to its own stdout and stderr. Nothing is converted: a Windows program may write its console code page, not UTF-8.
  • No result block, no started line and no Mutagen synced line. stderr carries only the command's stderr and loomtty's own messages, every line of which starts with loomtty: . The exit status is as without --pipe.
  • One host per run, and not with --json, --tail, --all or --session (each of these is a usage error, exit status 2). --tree, --cwd, --env, --timeout and --no-wait work as usual.
  • runs wait ADDR prints a --pipe run's output the same way (without --json, --tail or --all), and runs log ADDR writes all of its stdout and stderr (no --tail). runs ls shows pipe in the LINES column.
  • A process the command started and left running keeps its output open. loomtty waits 3 seconds for it after the command exits, then keeps what it has and says so. That process is not stopped.
  • The output comes back after the run, not while it runs. There is no pane, so a program that behaves differently without a terminal (colours, progress bars) does so here.

Connection pool ​

Opening an ssh connection takes a few seconds, most of the fixed cost of a run on another host. loomtty run, runs and peer exit after one command, so they leave the connection to the loomtty-server on this machine, which keeps it open for the next command:

  • A command asks the local server for a connection to the host and sends its requests through it; the local server passes them on unchanged. The first command to a host opens a new ssh connection as before; later ones within 10 minutes reuse it.
  • A connection serves one command at a time (a run being waited for keeps it); up to 8 per host. Before reuse it is checked with a ping (up to 3 seconds), so one left dead by sleep or a network change is replaced; the host's other unused connections are closed with it.
  • A command interrupted with Ctrl+C or killed does not give its connection back: the local server closes it.
  • An unused connection closes after 10 minutes. While it is open, the remote server counts it as a connected client, which can delay that server's idle shutdown by up to 10 minutes.
  • When the local server is not running (it is not started for this), is older than 0.5.0, does not answer within 2 seconds, or cannot provide a connection within 25 seconds, the command opens its own ssh connection as before, and any ssh error comes from that one.
  • The pooled ssh is started by the local server: with the ssh on its PATH and its environment (for example its SSH_AUTH_SOCK), not your shell's. When it cannot connect, the command tries again with its own ssh, so a host that is down takes about twice as long to report (two ssh timeouts), and if only the server's ssh cannot log in, every command pays that failed try first. If commands to a host got slower, look for relay: lines in the local server's log, or turn the pool off.
  • Only the local server needs 0.5.0; the remote server may be older.
  • [run] pool = false in your config turns this off. No port is opened for the pool: it uses the same ssh -W connections, held by your own local server.

Limits ​

  • The command's environment comes from the server. The command inherits the environment of the loomtty-server on that machine, plus the host's env and --env. On Windows its PATH is the one in the registry (what a new terminal gets), not the server's own. On macOS a server started from an ssh shell does not read the login environment, so PATH is whatever that shell had; if a tool is not found, check how the server was started.
  • Stopping on macOS and Linux. --timeout and runs stop end the command's process group. A process that leaves the group (setsid, some daemons) keeps running. On Windows the whole process tree is ended.
  • The log is the rendered terminal text, not the raw byte stream:
    • clear (or anything that erases the screen) drops the lines still on the screen at that moment; lines that had already scrolled off are kept.
    • Progress bars that redraw a line with \r leave only their final text.
    • The output of a full-screen program (alternate screen) is not logged.
    • Lines wider than the pane are joined back only as far as the terminal recorded the wrap.
    • Someone attached to jobs with a different window size can make the pane resize; around a resize a line can be logged twice or go missing.
    • If the server crashes (rather than shuts down), up to one screen of the latest output is lost.
    • runs log on a run that is still going can miss the lines that scrolled off the screen a moment ago; the next call shows them.
  • Scripts from Windows. A new, untracked script created on Windows arrives without its execute bit on macOS or Linux (Windows has none to send): run it as sh script.sh, or commit it with git update-index --chmod=+x.
  • Git Bash paths. Git Bash rewrites an argument like /Users/me/repo into C:/Program Files/Git/Users/me/repo before loomtty starts, /tmp into the Windows temp directory, and /c into C:/ (so cmd /c reaches the host as cmd C:/, which waits at a prompt). For a run on another host loomtty prints a note when it sees such an argument (in --cwd or after --), but leaves it as it is: on a Windows host it may be what you meant. /c/x becomes C:/x, which looks like any Windows path, so it gets no note. Set MSYS_NO_PATHCONV=1, or run from PowerShell, to pass POSIX paths through unchanged.
  • Size. --tail N returns at most 512 KiB; use runs log ID --all for the whole log.
  • Clients older than 0.4.0 connected to a 0.4.0 server do not see the jobs session in their session lists.

Requirements ​

  • loomtty 0.4.0 or newer on both ends; runs wait and --pipe need 0.5.0 on the host that runs the command, the connection pool 0.5.0 on this machine. A 0.4 loomtty runs lists --pipe runs but cannot print their output.
  • On each remote host, [remote] enabled = true and a running loomtty-server, reachable over ssh without a password prompt (keys or an agent), as for remote attach.
  • For --tree: git on both machines, and the host's repository reachable as git push <host>:<repo>.

See the CLI reference for every flag, the output format, --json and the exit codes.

Released under the AGPL-3.0-only License.