targets

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 28 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

targets

Execution targets — where a workspace's tmux session actually runs. See design spec §1.

Defines the TargetExecutor interface (RunTmuxCommand, CapturePane, KillSession, etc.) with a plain-SSH v1 implementation for remote targets; local targets shell out directly. Designed so a future companion-daemon implementation is a second implementation of the same interface, not a redesign.

Layout

  • targets.go — the TargetExecutor interface, ErrUnreachable, and NewExecutor(t *registry.Target), which branches on t.Kind so callers never need to know whether they're talking to a local or remote executor.
  • local.go — LocalExecutor: shells out straight to the tmux binary for tmux operations, no SSH involved; FileExists/RemoveFile are plain os.Stat/os.Remove; RunOnce shells out via sh -c directly (not tmux — a genuine one-shot command, not a pane operation).
  • remote.go — RemoteExecutor: shells out to the real ssh binary per target operation, with SSH connection multiplexing (ControlMaster/ControlPersist) so repeated calls against the same target reuse one connection. Real targets are expected to resolve via the caller's own ~/.ssh/config (same convention as ssh wyzer, ssh jet01 elsewhere in this ecosystem); RemoteOptions (WithPort, WithIdentityFile, WithExtraSSHArgs, WithConnectTimeout) exist for tests to point at a non-standard target, not for production use. FileExists/RemoveFile run test -e/rm -f remotely (existence only — content was never the signal); all SSH invocations (tmux subcommands and these two, plus RunOnce) share one sshExec helper so the connection-reuse/quoting/ error-handling conventions can't drift between them.
  • poll.go — Poller (LOOM-254), an optional interface RemoteExecutor implements: Poll answers which of some files exist and which of some panes still run in one ssh operation (test -e per file, one tmux list-panes -a), so the completion package's per-second checks of every turn on a target cost one round trip. The metrics wrapper keeps a Poller one, recording op="poll".
  • RunOnce (both executors, design spec §10 axis 3, LOOM-17) runs a command once, non-interactively, and returns its combined stdout+stderr — distinct from the session methods above (NewSession/SendKeys/ CapturePane, all oriented around a long-running interactive tmux pane). Its first real consumer is router.VersionCheck (a launch-time claude --version-style check), but it's a general-purpose primitive, not version-check-specific.
  • executortest/ — shared behavioral test suite (mirrors registry/storetest's pattern): executortest.Run runs identical assertions (including RunOnce) against any TargetExecutor, proving local and remote are actually interchangeable behind the interface.
  • sshtest/ — test-only in-process SSH server used by remote_test.go to exercise the real ssh client against a loopback target, per the design spec's Testing Strategy section — no system sshd or dedicated system user required.

Run go test ./... from the repo root to run the full suite, including the SSH-backed tests.

Documentation

Overview

Package targets defines the TargetExecutor interface — the mechanism that runs tmux operations against a registry.Target, either locally or over SSH. See design spec §1.

Index

Constants

View Source
const DefaultTmuxSocket = "loomux"

DefaultTmuxSocket is the tmux server Loomux runs every session on (LOOM-93) unless an instance names its own: `tmux -L loomux`, never the user's default one, so the user's tmux config and plugins don't apply to agents, Loomux sessions don't show in their `tmux ls`, and the orphan sweep can only ever see Loomux's own sessions. Two Loomux instances driving the same target (test and production) each need their own, or each one's orphan sweep would reap the other's sessions: ExecutorOptions.TmuxSocket (LOOMUX_TMUX_SOCKET), per instance (LOOM-202), never process-wide.

View Source
const MaxPasteBytes = 32 << 10

MaxPasteBytes is the most text PasteText delivers in one go (LOOM-111): a message to an agent, with the context in front of it, is far below it; anything bigger belongs in a file the agent reads.

View Source
const RelayFlag = "-ssh-proxy-connect"

RelayFlag is the loomuxd flag ssh's ProxyCommand runs it with: loomuxd -ssh-proxy-connect PROXY HOST PORT.

View Source
const SessionPrefix = "loomux-"

SessionPrefix starts the name of every session Loomux creates.

Variables

View Source
var ErrLocalTargetsOff = errors.New("local targets are turned off on this server (LOOMUX_LOCAL_TARGETS=off): their agents would run as the server's own user, with access to its database and keys")

ErrLocalTargetsOff is what running anything on a local target returns while local targets are turned off (ExecutorOptions.LocalTargetsOff).

View Source
var ErrTextTooLarge = errors.New("targets: text too large to paste")

ErrTextTooLarge is PasteText refusing text over MaxPasteBytes.

View Source
var ErrUnreachable = errors.New("targets: target unreachable")

ErrUnreachable is returned when the target itself couldn't be reached (e.g. an SSH connection failure), as distinct from the requested tmux operation failing on an otherwise-reachable target.

Functions

func AttachCommand

func AttachCommand(socket, session string) string

AttachCommand is the command a human runs on a target to attach to a Loomux session on socket, the instance's tmux socket.

func GenerateSSHKey added in v0.3.35

func GenerateSSHKey(id, name string) (*registry.SSHKey, error)

GenerateSSHKey makes a new ed25519 key pair called name, commented "loomux-<name>" so a person can tell it apart in authorized_keys.

func ReadOnlyAttachCommand added in v0.3.159

func ReadOnlyAttachCommand(socket, session string) string

ReadOnlyAttachCommand is AttachCommand for a person who only watches (LOOM-272): tmux's -r makes the client read-only, so nothing typed reaches the pane (the keys that detach still work).

func RelaySOCKS5 added in v0.3.41

func RelaySOCKS5(proxyAddr, host, port string, in io.Reader, out io.Writer) error

RelaySOCKS5 connects to host:port through the SOCKS5 proxy at proxyAddr and relays in and out over it: loomuxd as ssh's ProxyCommand (RelayFlag), so a managed target needs neither an ssh_config nor nc.

func ScrubLocalTmuxEnv added in v0.3.40

func ScrubLocalTmuxEnv(ctx context.Context, socket string) error

ScrubLocalTmuxEnv removes every variable localEnv wouldn't pass from the global environment of a tmux server already running locally on socket, the instance's ("" is DefaultTmuxSocket). A tmux server keeps the environment of the client that started it and hands it to every new session, so one started by an older loomuxd (with its full environment) would otherwise keep leaking it. No server running is not an error.

The server can exit between listing its environment and unsetting a variable, when its last session ends (another loomuxd's, or a test's in a package running alongside). So a failed unset starts the scrub over: with the server gone, the listing fails and there's nothing to scrub; a server started meanwhile is scrubbed in turn. A listing ctx cut short is no proof the server is gone, so it's ctx's error.

func ValidSSHKeyName added in v0.3.35

func ValidSSHKeyName(name string) bool

ValidSSHKeyName reports whether name can name a managed SSH key.

func ValidTmuxSocket added in v0.1.28

func ValidTmuxSocket(name string) bool

ValidTmuxSocket reports whether name can be a socket name.

func WrapExitStatus added in v0.2.2

func WrapExitStatus(command string) string

WrapExitStatus is the pane command for command (LOOM-136): command runs in a subshell, so its own `exit` ends only that, and the pane then prints its status as a marker line and exits with it. PaneExited reads the status from that line.

The wrapping shells share the process group with command (a non-interactive shell has no job control), so a C-c typed into the pane reaches them too; dash and busybox ash would then die and take the marker, or the pane, with them. `trap :` makes them carry on. It's a handler, not an ignore: the subshell and anything it execs reset it to the default, so command's own SIGINT and SIGQUIT behaviour is unchanged.

The pane then waits for tmux to show the marker before it exits (LOOM-198). tmux 3.4 and 3.5 close a pane's pty as soon as they reap its process, dropping what they hadn't read from it yet: under load, the command's last output (why an agent CLI didn't start) and the marker with it. The pane's output is read in order, so once the marker shows, everything before it has been read. The wait asks tmux about the pane itself ($TMUX_PANE), every 100ms up to awaitMarkerTries times, and stops at once if tmux can't say: no pane, no tmux, a failed capture, or a sleep that won't take a fraction.

Types

type AgentPool added in v0.3.35

type AgentPool struct {
	// contains filtered or unexported fields
}

AgentPool serves each managed key from an agent of its own, on a unix socket in a 0700 directory: ssh is pointed at one with IdentityAgent. An agent only lists and signs with its one key; adding, removing and locking are refused.

Anything running as loomuxd's user can reach the sockets — agents on a local target included — but such a process can already read the database and the master key, so the sockets add nothing to what it could do.

func NewAgentPool added in v0.3.35

func NewAgentPool(dir string) *AgentPool

NewAgentPool serves agents from sockets in dir, which it creates.

func (*AgentPool) Close added in v0.3.35

func (p *AgentPool) Close() error

Close stops every agent.

func (*AgentPool) Drop added in v0.3.35

func (p *AgentPool) Drop(id string)

Drop stops serving key id (deleted, or rotated away from).

func (*AgentPool) Running added in v0.3.41

func (p *AgentPool) Running(id string) (string, bool)

Running returns the socket of key id's agent, if it's running.

func (*AgentPool) Socket added in v0.3.35

func (p *AgentPool) Socket(k *registry.SSHKey) (string, error)

Socket returns the socket of k's agent, starting it if it isn't running. k must carry its private key (registry GetSSHKey).

type ExecutorOptions added in v0.3.87

type ExecutorOptions struct {
	// TmuxSocket is the tmux socket the instance's sessions run on
	// (LOOMUX_TMUX_SOCKET); empty is DefaultTmuxSocket.
	TmuxSocket string
	// KnownHostsDir is where pinned targets' known_hosts files are
	// written (the data volume, beside the database); empty is
	// defaultKnownHostsDir().
	KnownHostsDir string
	// Metrics, when set, instruments every call (LOOM-103).
	Metrics *metrics.Metrics
	// Managed is how managed targets are reached (LOOM-138); nil turns
	// them off (they then fail to connect, saying so).
	Managed *ManagedSSH
	// LocalTargetsOff refuses local targets (LOOM-141). A local target's
	// agents run as loomuxd's own user on loomuxd's own machine: whatever
	// they run can read loomuxd's database (and with it the vault), its
	// SSH keys and its process environment. That's only acceptable where
	// the person running loomuxd means it, so the container image turns
	// them off (LOOMUX_LOCAL_TARGETS=off) and a bare binary leaves them on.
	LocalTargetsOff bool
}

ExecutorOptions are what one app instance's executors share (LOOM-197, LOOM-199, LOOM-202: per instance, never process-wide, so two in one process stay apart). The zero value is NewExecutor's defaults.

func (ExecutorOptions) ResolveSSHConfig added in v0.3.98

func (o ExecutorOptions) ResolveSSHConfig(ctx context.Context, t *registry.Target, keyFile string) (*SSHConfigPlan, error)

ResolveSSHConfig is the package's ResolveSSHConfig, planned against o.Managed's proxy.

func (ExecutorOptions) ScanHostKey added in v0.3.98

func (o ExecutorOptions) ScanHostKey(ctx context.Context, t *registry.Target) ([]HostKey, error)

ScanHostKey is the package's ScanHostKey, a managed target reached with o.Managed.

type HostKey added in v0.3.8

type HostKey struct {
	Line        string
	Type        string
	Fingerprint string
}

HostKey is one host key: its known_hosts line, its type ("ssh-ed25519") and its SHA256 fingerprint as ssh-keygen -l prints it.

func ParseHostKeys added in v0.3.8

func ParseHostKeys(lines string) ([]HostKey, error)

ParseHostKeys reads known_hosts lines (as pinned, or as a scan wrote them); comments and blank lines are skipped.

func ScanHostKey added in v0.3.8

func ScanHostKey(ctx context.Context, t *registry.Target) ([]HostKey, error)

ScanHostKey connects to t's host the way Loomux does (the mounted SSH config, its proxy, t's port) and returns the host key it presents, without authenticating and without trusting it: nothing is pinned until a pin names one of the fingerprints (LOOM-114, trust on first use, confirmed by a person). ssh records the key once key exchange has checked the host holds it, before authentication, which is then refused on purpose.

Loomux has one user today. If it ever has several, scanning and pinning must become admin-only: whoever pins decides which machine every later command reaches.

A managed target can't be scanned without managed SSH: an app uses its own options' ScanHostKey.

type LocalExecutor

type LocalExecutor struct {
	// contains filtered or unexported fields
}

LocalExecutor runs tmux operations directly on the local machine.

func NewLocalExecutor

func NewLocalExecutor(socket string) *LocalExecutor

NewLocalExecutor constructs a LocalExecutor on socket ("" is DefaultTmuxSocket); an app's come from NewExecutorWith, on its own. Tests name one of their own (internal/tmuxtest, LOOM-210).

func (*LocalExecutor) CapturePane

func (e *LocalExecutor) CapturePane(ctx context.Context, target string) (string, error)

func (*LocalExecutor) Close

func (e *LocalExecutor) Close() error

func (*LocalExecutor) DetachClients added in v0.3.154

func (e *LocalExecutor) DetachClients(ctx context.Context, session string) error

DetachClients runs detachClientsScript with sh, as RunOnce does.

func (*LocalExecutor) FileExists

func (e *LocalExecutor) FileExists(ctx context.Context, path string) (bool, error)

func (*LocalExecutor) HasSession

func (e *LocalExecutor) HasSession(ctx context.Context, session string) (bool, error)

func (*LocalExecutor) KillSession

func (e *LocalExecutor) KillSession(ctx context.Context, session string) error

func (*LocalExecutor) NewSession

func (e *LocalExecutor) NewSession(ctx context.Context, session, dir, command string) error

func (*LocalExecutor) PaneExited

func (e *LocalExecutor) PaneExited(ctx context.Context, target string) (*PaneExit, error)

func (*LocalExecutor) PasteText added in v0.3.2

func (e *LocalExecutor) PasteText(ctx context.Context, target, text string, enter bool) error

func (*LocalExecutor) RemoveFile

func (e *LocalExecutor) RemoveFile(ctx context.Context, path string) error

func (*LocalExecutor) RunOnce

func (e *LocalExecutor) RunOnce(ctx context.Context, command string) (string, error)

RunOnce runs command once via a local shell and returns its combined stdout+stderr — e.g. many CLIs print --version to stderr, so both streams are captured rather than just stdout.

func (*LocalExecutor) SendKey

func (e *LocalExecutor) SendKey(ctx context.Context, target, key string) error

SendKey sends one key by its tmux name to target.

func (*LocalExecutor) SendKeys

func (e *LocalExecutor) SendKeys(ctx context.Context, target, keys string, enter bool) error

func (*LocalExecutor) TmuxSocket added in v0.3.101

func (e *LocalExecutor) TmuxSocket() string

type ManagedSSH added in v0.3.41

type ManagedSSH struct {
	// Keys loads a key with its private key (registry GetSSHKey).
	Keys func(ctx context.Context, id string) (*registry.SSHKey, error)
	// Agents serves the keys to ssh.
	Agents *AgentPool
	// KeysDir holds the keys' public key files, which tell ssh which of
	// an agent's keys to offer (IdentitiesOnly).
	KeysDir string
	// Proxy is the SOCKS5 proxy, host:port, that targets reach through
	// unless they opt out (LOOMUX_SSH_PROXY); "" for none.
	Proxy string
	// Relay is the absolute path of the loomuxd binary ssh runs as the
	// ProxyCommand.
	Relay string
}

ManagedSSH is how managed targets are reached: one app instance's, passed to its executors in ExecutorOptions.Managed (LOOM-199: per instance, never process-wide).

func (*ManagedSSH) Validate added in v0.3.98

func (m *ManagedSSH) Validate() error

Validate checks m is complete and that its relay and proxy can go into a ProxyCommand. Every use checks it again (managedConfig), so a configuration never reaches ssh unvetted.

type PaneExit

type PaneExit struct {
	// Status is the process's exit status, or -1 if it has none: killed
	// by Signal, or (Signal "") tmux never recorded one.
	Status int
	// Signal is the signal that killed the process as tmux names it: a
	// number on Linux ("9"), a name on macOS and the BSDs ("kill"); ""
	// if none or unknown.
	Signal string
	// Output is the pane's contents including its scrollback — a command
	// that exits at once has its output scrolled off the visible screen
	// when tmux writes its "Pane is dead" line — with that line and
	// trailing blank lines removed. Bounded by the pane's history-limit.
	Output string
}

PaneExit describes a pane whose process has exited (LOOM-71).

func (*PaneExit) Describe added in v0.1.11

func (e *PaneExit) Describe() string

Describe says how the process ended: "exit 3", "killed by signal 9", or that tmux never recorded a status.

type PollRequest added in v0.3.141

type PollRequest struct {
	Files []string
	Panes []string
}

PollRequest is one poll of a target (LOOM-254): which of Files exist, and which of Panes' processes still run. Panes are session names, as PaneExited takes them.

type PollResult added in v0.3.141

type PollResult struct {
	// Exists[i] reports whether Files[i] exists.
	Exists []bool
	// Running[i] reports whether Panes[i]'s process is still running.
	// false covers a dead pane, a missing session and a pane tmux didn't
	// report at all: PaneExited says which, and how the process ended.
	Running []bool
}

PollResult answers a PollRequest, index for index.

type Poller added in v0.3.141

type Poller interface {
	Poll(ctx context.Context, req PollRequest) (*PollResult, error)
}

Poller is a TargetExecutor that answers a whole PollRequest in one target operation (LOOM-254): the 1 s completion polls of every turn waiting on a target cost one ssh round trip, not two per turn, so ten sessions on a slow link stay inside the target's operation budget (maxConcurrentOps). An executor without it is polled one call at a time.

type RemoteExecutor

type RemoteExecutor struct {
	// contains filtered or unexported fields
}

RemoteExecutor runs tmux operations over SSH, using connection multiplexing (ControlMaster/ControlPersist) so repeated operations against the same target reuse one connection instead of paying a fresh handshake each time. Every operation shells out to the real ssh binary per the design spec's v1 approach.

func NewRemoteExecutor

func NewRemoteExecutor(host, user string, opts ...RemoteOption) *RemoteExecutor

NewRemoteExecutor constructs a RemoteExecutor for the given host/user.

func (*RemoteExecutor) CapturePane

func (e *RemoteExecutor) CapturePane(ctx context.Context, target string) (string, error)

func (*RemoteExecutor) Close

func (e *RemoteExecutor) Close() error

Close proactively tears down the SSH ControlMaster rather than relying solely on ControlPersist's idle timeout.

func (*RemoteExecutor) ControlMasterAlive

func (e *RemoteExecutor) ControlMasterAlive(ctx context.Context) (bool, error)

ControlMasterAlive reports whether an SSH ControlMaster is currently running for this executor's ControlPath — proof that multiplexing is actually in effect rather than each call paying a fresh handshake.

func (*RemoteExecutor) DetachClients added in v0.3.154

func (e *RemoteExecutor) DetachClients(ctx context.Context, session string) error

DetachClients runs detachClientsScript in one SSH round trip. An unreachable target is ErrUnreachable, as for every other operation.

func (*RemoteExecutor) FileExists

func (e *RemoteExecutor) FileExists(ctx context.Context, path string) (bool, error)

FileExists reports whether path exists on the target's filesystem, via `test -e` (exit 0 = exists, non-zero = doesn't — a normal negative result, not a Go-level error, same convention as HasSession).

func (*RemoteExecutor) HasSession

func (e *RemoteExecutor) HasSession(ctx context.Context, session string) (bool, error)

func (*RemoteExecutor) KillSession

func (e *RemoteExecutor) KillSession(ctx context.Context, session string) error

func (*RemoteExecutor) NewSession

func (e *RemoteExecutor) NewSession(ctx context.Context, session, dir, command string) error

func (*RemoteExecutor) PaneExited

func (e *RemoteExecutor) PaneExited(ctx context.Context, target string) (*PaneExit, error)

func (*RemoteExecutor) PasteText added in v0.3.2

func (e *RemoteExecutor) PasteText(ctx context.Context, target, text string, enter bool) error

PasteText loads and pastes the buffer in one ssh round trip: the text travels inside the script as printf's quoted argument (printf is a shell builtin, so no argument-length limit applies), since the script itself is ssh's stdin.

func (*RemoteExecutor) Poll added in v0.3.141

func (e *RemoteExecutor) Poll(ctx context.Context, req PollRequest) (*PollResult, error)

Poll checks every file with test -e and lists the tmux server's panes once, in one ssh operation. A session's pane is the active pane of its active window, the one PaneExited's display-message -t session reads.

func (*RemoteExecutor) RemoveFile

func (e *RemoteExecutor) RemoveFile(ctx context.Context, path string) error

RemoveFile best-effort removes path from the target's filesystem via `rm -f`, which itself doesn't error on a missing file.

func (*RemoteExecutor) RunOnce

func (e *RemoteExecutor) RunOnce(ctx context.Context, command string) (string, error)

RunOnce runs command once, non-interactively, over SSH (via sshExec — the same connection-multiplexed primitive run() and the file-existence methods share) and returns its combined stdout+stderr — e.g. many CLIs print --version to stderr, so both streams are captured rather than just stdout.

func (*RemoteExecutor) SendKey

func (e *RemoteExecutor) SendKey(ctx context.Context, target, key string) error

SendKey sends one key by its tmux name to target.

func (*RemoteExecutor) SendKeys

func (e *RemoteExecutor) SendKeys(ctx context.Context, target, keys string, enter bool) error

func (*RemoteExecutor) TmuxSocket added in v0.3.101

func (e *RemoteExecutor) TmuxSocket() string

type RemoteOption

type RemoteOption func(*RemoteExecutor)

RemoteOption configures a RemoteExecutor. Production's NewExecutor passes none of these — they exist for tests to point at a non-standard host/port/identity (e.g. a loopback sshtest server) without needing fields on registry.Target that production connectivity doesn't need (real targets are expected to resolve via the user's own ~/.ssh/config, matching the design spec's "ssh wyzer"-style convention).

func WithConnectTimeout

func WithConnectTimeout(timeout string) RemoteOption

func WithExtraSSHArgs

func WithExtraSSHArgs(args ...string) RemoteOption

WithExtraSSHArgs appends raw arguments to every ssh invocation, inserted before the destination — an escape hatch tests use for StrictHostKeyChecking=no and a scratch UserKnownHostsFile against a freshly generated, otherwise-unknown host key.

func WithIdentityFile

func WithIdentityFile(path string) RemoteOption

func WithOpTimeout

func WithOpTimeout(d time.Duration) RemoteOption

WithOpTimeout overrides the per-operation deadline (LOOM-84) for every operation but RunOnce.

func WithPort

func WithPort(port int) RemoteOption

func WithTmuxSocket added in v0.3.101

func WithTmuxSocket(name string) RemoteOption

WithTmuxSocket runs every tmux command on the target with -L name instead of DefaultTmuxSocket (LOOM-202); empty keeps the default. NewExecutorWith passes the instance's, checked with ValidTmuxSocket.

type SSHConfigPlan added in v0.3.42

type SSHConfigPlan struct {
	Host string
	Port int
	User string
	// SSHProxy is "" (the server's LOOMUX_SSH_PROXY, which the config's
	// proxy command matches) or registry.SSHProxyNone.
	SSHProxy string
	// KeyFile is the key file the config uses; Key is it, imported (no
	// ID yet), when it could be.
	KeyFile string
	Key     *registry.SSHKey
	// HostKeys are the known_hosts lines to pin, keyed by Host:Port.
	HostKeys string
	// Problems are what keeps the target from being migrated as is,
	// worded for a person.
	Problems []string
}

SSHConfigPlan is a config-mode target as a managed one would reach it.

func ResolveSSHConfig added in v0.3.42

func ResolveSSHConfig(ctx context.Context, t *registry.Target, keyFile string) (*SSHConfigPlan, error)

ResolveSSHConfig reads what the SSH config does for t, a config-mode remote target, and plans it as a managed one. keyFile, if not "", is the file in ~/.ssh to import instead of the config's first usable one. Without managed SSH no proxy is the server's: an app uses its own options' ResolveSSHConfig.

type SSHFailure added in v0.1.13

type SSHFailure string

SSHFailure is why ssh couldn't reach a target (LOOM-85): a stable, low-cardinality class for errors, logs and metrics, so a changed host key, a dead SOCKS sidecar and a refused key don't all read as the same "unreachable".

const (
	SSHHostKeyChanged    SSHFailure = "host_key_changed"
	SSHHostKeyUnknown    SSHFailure = "host_key_unknown"
	SSHAuthFailed        SSHFailure = "auth_failed"
	SSHDNSFailed         SSHFailure = "dns_failed"
	SSHProxyUnreachable  SSHFailure = "proxy_unreachable"
	SSHConnectionRefused SSHFailure = "connection_refused"
	SSHHostUnreachable   SSHFailure = "host_unreachable"
	SSHMuxSessionRefused SSHFailure = "mux_session_refused"
	SSHTimeout           SSHFailure = "timeout"
	SSHOther             SSHFailure = "other"
)

type TargetExecutor

type TargetExecutor interface {
	// TmuxSocket is the tmux socket every operation uses: the one a raw
	// tmux command through RunOnce must name too (LOOM-202).
	TmuxSocket() string

	// NewSession creates a new detached tmux session. dir may be empty to
	// use the default working directory; command may be empty to start
	// the pane's default shell. A non-empty command is POSIX sh, run as
	// `sh -c command` whatever the target's default or login shell is. The session's pane is kept after its
	// command exits (tmux remain-on-exit, LOOM-71) so that an agent CLI
	// that dies at once still leaves its last output and exit status
	// readable — see PaneExited. Whoever owns the session is
	// responsible for killing it.
	NewSession(ctx context.Context, session, dir, command string) error

	// PaneExited reports whether target's pane process has exited: nil
	// while it is still running, otherwise its exit status and final
	// output (see PaneExit).
	PaneExited(ctx context.Context, target string) (*PaneExit, error)

	// HasSession reports whether a session with the given name currently
	// exists. A nonexistent session is a normal (false, nil) result, not
	// an error.
	HasSession(ctx context.Context, session string) (bool, error)

	// SendKeys sends keys literally to target, optionally followed by
	// Enter.
	SendKeys(ctx context.Context, target, keys string, enter bool) error

	// PasteText delivers text to target as one bracketed paste (tmux
	// load-buffer + paste-buffer -p), optionally followed by Enter
	// (LOOM-111). A multi-line message so arrives whole, as if pasted by
	// a human, instead of each newline pressing Enter in the agent's
	// input; an app that didn't ask for bracketed paste gets the plain
	// text. Text over MaxPasteBytes is refused with ErrTextTooLarge.
	PasteText(ctx context.Context, target, text string, enter bool) error

	// SendKey sends one key by its tmux name (e.g. "Escape", "C-c") to
	// target — not typed text (LOOM-117: interrupting an agent).
	SendKey(ctx context.Context, target, key string) error

	// CapturePane returns the current visible contents of target's pane.
	CapturePane(ctx context.Context, target string) (string, error)

	// KillSession terminates the named session.
	KillSession(ctx context.Context, session string) error

	// DetachClients detaches every tmux client attached to the named
	// session (tmux detach-client -s), matched by its exact name, on the
	// executor's socket (LOOM-265): what ends a person's attach once
	// their hold on the task has ended. The session keeps running. No
	// such session, no tmux server, or no client attached is nothing to
	// do, not an error.
	DetachClients(ctx context.Context, session string) error

	// Close releases any resources held by the executor (e.g. an SSH
	// connection multiplexing master).
	Close() error

	// FileExists reports whether path exists on the target's
	// filesystem — a lightweight existence check, not a content read
	// (content was never the completion-detection signal; existence
	// is — see the completion package's MarkerWatcher).
	FileExists(ctx context.Context, path string) (bool, error)

	// RemoveFile best-effort removes path from the target's
	// filesystem.
	RemoveFile(ctx context.Context, path string) error

	// RunOnce runs command once, non-interactively, as POSIX sh (whatever
	// the target's login shell is), and returns its combined
	// stdout+stderr. Distinct from NewSession/SendKeys/
	// CapturePane's long-running interactive tmux pane — this is a
	// one-shot command whose output is read straight back, e.g. a
	// version-check command like "claude --version" (design spec §10
	// axis 3, router.VersionCheck).
	RunOnce(ctx context.Context, command string) (string, error)
}

TargetExecutor runs tmux operations against a single target. session and target parameters are plain tmux target-spec strings (a session name, or "session:window.pane") — this package doesn't model window/pane semantics beyond that; that belongs to the orchestrator.

func NewExecutor

func NewExecutor(t *registry.Target) (TargetExecutor, error)

NewExecutor constructs the TargetExecutor appropriate for t.Kind, with no metrics, pins written under the default directory, local targets on, managed SSH off and the default tmux socket; an app uses NewExecutorWith.

func NewExecutorWith added in v0.3.87

func NewExecutorWith(t *registry.Target, o ExecutorOptions) (TargetExecutor, error)

NewExecutorWith constructs the TargetExecutor appropriate for t.Kind with o.

type UnreachableError added in v0.1.13

type UnreachableError struct {
	// Host is the target's ssh host (its name in the ssh config).
	Host    string
	Failure SSHFailure
	// Detail is what ssh said, its banner lines removed; or, for a
	// deadline Loomux enforced, what that deadline was.
	Detail string
	// Managed is set for a managed target (LOOM-138), which has no SSH
	// secret or config behind it: the hint mustn't point there.
	Managed bool
}

UnreachableError is the ErrUnreachable a remote operation returns: errors.Is(err, ErrUnreachable) holds, and errors.As gives the class.

func AsUnreachable added in v0.1.13

func AsUnreachable(err error) (*UnreachableError, bool)

AsUnreachable returns err's UnreachableError, if it has one.

func (*UnreachableError) Error added in v0.1.13

func (e *UnreachableError) Error() string

func (*UnreachableError) Hint added in v0.1.13

func (e *UnreachableError) Hint() string

Hint says, in plain words, what went wrong and what to do about it.

func (*UnreachableError) Is added in v0.1.13

func (e *UnreachableError) Is(target error) bool

Directories

Path Synopsis
Package executortest is the shared behavioral test suite for targets.TargetExecutor.
Package executortest is the shared behavioral test suite for targets.TargetExecutor.
Package sshtest is test-only infrastructure: a minimal in-process SSH server for exercising the real ssh client binary against a loopback target, satisfying the design spec's requirement that TargetExecutor be testable against a local/loopback SSH target.
Package sshtest is test-only infrastructure: a minimal in-process SSH server for exercising the real ssh client binary against a loopback target, satisfying the design spec's requirement that TargetExecutor be testable against a local/loopback SSH target.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL