remote

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 30 Imported by: 0 modules, 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.

Documentation

Overview

Package remote connects to conch servers on other machines over the system's OpenSSH: it probes the machine, installs conch there when needed, and bridges the protocol through `conch bridge`.

Index

Constants

View Source
const (
	CloudExitConnection = 255
	CloudExitRefused    = 254
)

Exit statuses `conch cloud exec` takes for itself, as ssh takes 255: the tunnel did not connect or dropped (worth trying again), or it never will without the person (signed out, a changed key).

View Source
const CloudPrefix = "conch:"

CloudPrefix starts a cloud machine's catalog target.

View Source
const LocalID = "local"

LocalID is the machine ID of this computer.

Variables

View Source
var ErrKeyLoginUnverified = errors.New("the key was added, but logging in with it still fails")

ErrKeyLoginUnverified means the key was added but logging in with it still failed (the server may not allow keys).

Functions

func AppAsset added in v0.2.1

func AppAsset(version, arch string) (string, error)

AppAsset names Conch.app's archive in a release, as macos/release.sh makes it: Conch_0.2.1_macos_arm64.zip. Only Apple Silicon is published, since Ghostty's library is built for it alone, so another arch (runtime.GOARCH) has no asset to choose.

func Bridge

func Bridge(tr Transport, bin string) (*client.Client, error)

Bridge runs `conch bridge` on the machine and speaks the protocol through its stdin and stdout.

func BridgeCommand added in v0.1.9

func BridgeCommand(ctx context.Context, tr Transport) (*exec.Cmd, error)

BridgeCommand is the command that carries conch's protocol to the server on a machine, through its stdin and stdout — what Bridge runs, for a program that speaks the protocol itself (the Mac app) rather than through a client of this one. The machine is probed first, so a machine without conch, or with one that cannot say what it is, is said rather than bridged to; nothing is installed. The command outlives ctx, which bounds only the probe.

A conch that is merely older is bridged to: the program on the other end reads the server's capabilities from its hello and does without what is missing, saying so, as every client does (AGENTS.md, protocol compatibility). Refusing it took the machine offline in the Mac app the moment this build gained a capability — busybox, there in the TUI, shown offline in the app — until somebody upgraded it.

func CatalogPath

func CatalogPath() string

CatalogPath is the file saved machines are kept in, for watching it.

func CheckKeyCommand added in v0.2.0

func CheckKeyCommand(target string, args []string) ([]string, error)

CheckKeyCommand is an ssh that says whether target takes this computer's keys: logged in as a session would be, but in batch mode, so it never stops to ask for a password or a passphrase, and runs `true` there. It exits 0 when the key is taken. A host that is down, slow or unknown fails too; KeyLoginResult tells those apart by what ssh said.

func CheckLoginTarget added in v0.1.1

func CheckLoginTarget(target string) error

CheckLoginTarget rejects what ssh would not read as a single host: empty text, spaces, control characters, and a leading "-" that ssh could take for an option.

func CloudExecutableForTest added in v0.2.0

func CloudExecutableForTest(path string) func()

CloudExecutableForTest makes path the conch run for a cloud machine's exec and bridge, returning a func that puts it back. Tests in other packages use it; nothing else calls it.

func CloudTarget added in v0.2.0

func CloudTarget(id string) string

CloudTarget is the catalog target of cloud machine id.

func Compress added in v0.1.7

func Compress() bool

Compress reports whether conch's connections to a machine deflate what they carry. A frame is the whole screen as styled text and goes out an order of magnitude smaller for tens of microseconds of work, against milliseconds on any network — so it is on unless config.toml turns it off. It is read where the ssh config is written (sshConfig), because compression belongs to a connection and conch shares connections: a flag on one session of a master already up does nothing at all.

func Connect

func Connect(ctx context.Context, tr Transport, opts Options) (*client.Client, error)

Connect reaches the conch server on target, starting it if needed. When the server is older than this client, the connected client is returned together with an *OutdatedServerError.

func ConnectionTriesForTest added in v0.1.6

func ConnectionTriesForTest(tries int, wait time.Duration) (int, time.Duration)

ConnectionTriesForTest sets how often a connection is tried and how long between, returning what they were. Tests in other packages shorten them; nothing else calls it.

func CopyKeyCommand added in v0.1.7

func CopyKeyCommand(target string, args []string) (command []string, key string, err error)

CopyKeyCommand is a command for a terminal that sets target up for logins without a password: it appends this computer's public key to ~/.ssh/authorized_keys there (once), logging in with the password one last time. Without a key it makes ~/.ssh/id_ed25519 first. key is the public key that will be copied.

func DefaultSandboxLabel added in v0.1.5

func DefaultSandboxLabel(id string) string

DefaultSandboxLabel names a sandbox nobody named, after its ID.

func FetchApp added in v0.2.1

func FetchApp(ctx context.Context, version, arch, dir string) (string, error)

FetchApp downloads Conch.app's archive of a release into dir and checks it against the .sha256 published beside it, returning its path. A file that does not match is removed rather than left for somebody to open.

func FetchRelease

func FetchRelease(ctx context.Context, version, platform string) ([]byte, error)

FetchRelease downloads the conch binary of a release for platform and verifies it against the release checksums.

func FilesCommand added in v0.1.9

func FilesCommand(l Login) []string

FilesCommand is the ssh command that opens an sftp session to the host the login reached. It never asks anything — a host that wants a password says so and fails, since nobody is there to type it — and asks for no forwards, whatever the config says. A config that shares connections (ControlMaster) shares the terminal's, so no second login happens at all.

func ForgetCloudMachines added in v0.2.0

func ForgetCloudMachines() error

ForgetCloudMachines removes every cloud machine from the catalog: the device signed out, so none of them can be reached.

func ForwardPort added in v0.1.9

func ForwardPort(ctx context.Context, target string, port int, opts ...string) (int, error)

ForwardPort makes a port on a machine reachable from this computer through the connection conch already holds to it, and says which local port that is: the same number when it is free here, so a link written on the machine works unchanged, or another when something here holds it.

It asks the running master (ssh -O forward) rather than starting a connection of its own: the bridge keeps that master up for as long as the machine is online, so the forward lasts as long as the machine does, and asking twice for the same port is answered by the forward already there.

opts are the machine's ssh options, and they are needed to find that master at all: the control path is `%C`, a hash of the host, the port and the user, so asking without the `-p` or `-l` the master was opened with computes another path and finds no socket — which would have read as "conch is not connected", about a machine conch is connected to.

func Install

func Install(ctx context.Context, tr Transport, platform string, say func(string)) (string, error)

Install copies a conch binary for the machine's platform to ~/.local/bin/conch there, replacing any older one atomically. A server already running keeps its old binary until it restarts. For a platform other than this computer's, conch is built from source when needed.

func IsLoginCommand added in v0.1.1

func IsLoginCommand(command []string) bool

IsLoginCommand reports whether a pane's command is an ssh session.

func KeyLoginResult added in v0.2.0

func KeyLoginResult(err error, stderr string) string

KeyLoginResult reads a CheckKeyCommand's outcome: "key" when it logged in, "password" when the host refused every key it was offered (so it would ask for a password, or another way in), and "unreachable" for anything else — no route, a timeout, a host key ssh does not know — which says nothing about keys.

func LatestRelease

func LatestRelease(ctx context.Context) (string, error)

LatestRelease returns the newest published version, e.g. "0.2.0". The latest-release page redirects to its tag, so no API token is involved.

func LoginArgs added in v0.1.9

func LoginArgs(command []string) []string

LoginArgs reads a login command back: the extra ssh options it was built with, for a second session to the same host. It is the inverse of LoginCommand, so it drops what LoginCommand puts there itself — conch's config and a connection of this session's own — and keeps the rest. A login's own options can never hold -F (NormalizeLoginArgs refuses it) and ControlPath=none is asked for again anyway, so what is left is what somebody typed for this host. nil for anything that is not a login command built this way.

func LoginCommand added in v0.1.1

func LoginCommand(target string, args ...string) ([]string, error)

LoginCommand is the command for an interactive ssh session to target in a terminal: conch's ssh config (the user's own first), no remote command. The session makes its own connection, as a plain ssh would: sharing conch's master meant that once the host stopped answering, a new login sat on a blank screen until the dead master timed out, about a minute.

args are extra ssh options for this host, such as -o KexAlgorithms=… for an old server; they go before the "--", so they can only be options.

func MachineNames added in v0.1.8

func MachineNames() []string

MachineNames is what conch has, for saying so when a ref matches none.

func MachineOpts added in v0.1.9

func MachineOpts(args []string) ([]string, error)

MachineOpts is the extra ssh options a machine may be reached with. The list is first checked as any login's is (NormalizeLoginArgs), so a word that is not an option, or an option with its value missing, is refused where it can still be said. What is left is then read by ParseLogin itself, against a host of its own, and so keeps exactly the set a second session to a host keeps: where and how to log in. A machine's connections are not a terminal's session — conch runs a probe, an install and a bridge on them — so a forward, a tty, an escape character and agent forwarding are dropped rather than refused: each is a legal ssh option that means nothing here, and a second -L on a port in use would make the connection fail outright.

func NormalizeLoginArgs added in v0.1.7

func NormalizeLoginArgs(words []string) ([]string, error)

NormalizeLoginArgs checks extra ssh options for a login and returns them in the form ssh takes. A bare Key=Value word is an -o option, so "KexAlgorithms=+diffie-hellman-group1-sha1" can be written as it is in ssh_config. Anything that isn't an option is refused: a word ssh would take for the host would make the real host the remote command.

func OpenProvider added in v0.1.5

func OpenProvider(name string) (sandbox.Provider, error)

OpenProvider returns the named sandbox provider, set up from config.toml.

func ParseCloudTarget added in v0.2.0

func ParseCloudTarget(target string) (string, bool)

ParseCloudTarget is the machine id of a cloud machine's target.

func ParseSandboxTarget added in v0.1.5

func ParseSandboxTarget(target string) (provider, id string, ok bool)

ParseSandboxTarget splits a sandbox's catalog target; ok is false for an ssh target. A provider conch dropped still names a sandbox — opening it says the provider is gone — rather than an ssh host called "devin".

func RefName added in v0.2.0

func RefName(ms []Machine, id string) string

RefName is what to call machine id in front of a pane — the busybox of busybox:p3, as conch's windows show and copy a pane — so that the commands reach this machine with it: its label, when the label could be typed (no space or colon), is not "local", and is no other machine's ID or label; its ID otherwise, which LookupMachine always takes as its own. ms is every machine conch has, disabled ones too, since the commands look through all of them.

func ReleaseAsset

func ReleaseAsset(version, platform string) string

ReleaseAsset names the archive published for platform, e.g. conch_0.2.0_linux_amd64.tar.gz. scripts/release.sh and install.sh use the same scheme.

func ReleaseNotes added in v0.2.1

func ReleaseNotes(version string) string

ReleaseNotes is the page a release is described on.

func Releases added in v0.1.3

func Releases(ctx context.Context) ([]string, error)

Releases lists the published versions, in the order the feed gives them (newest first on GitHub) and once each. Callers that need them ordered sort them themselves — update.Releases does.

func RemoveMachine

func RemoveMachine(ref string) error

RemoveMachine forgets a machine by ID or label.

func ReplaceExecutable

func ReplaceExecutable(path string, bin []byte) error

ReplaceExecutable atomically swaps the file at path for bin.

func RunCommand added in v0.1.9

func RunCommand(l Login, argv []string) []string

RunCommand is the ssh command that runs argv on the host the login reached, in a terminal: the same options, and here a person is there to answer a password. Each word is single-quoted for the host's login shell, which reads it as one word in sh, bash, zsh and fish alike.

func SSHBinary added in v0.1.9

func SSHBinary() string

SSHBinary is the ssh client conch reaches machines with.

func SSHHosts

func SSHHosts() []string

SSHHosts lists concrete Host aliases from ~/.ssh/config (and files it includes directly), for suggesting machines to add.

func SandboxShell added in v0.1.6

func SandboxShell(ctx context.Context, label, target, command string, tty bool) (*exec.Cmd, error)

SandboxShell is ssh into a running sandbox for a person at a terminal: a login shell when command is empty, otherwise command run there. tty asks for a terminal for the command too, for one that draws a screen; a shell gets one whenever this side has one. The command is not tied to ctx, which only bounds asking the provider for access: a shell lasts as long as the person keeps it.

func SandboxTarget added in v0.1.5

func SandboxTarget(provider, id string) string

SandboxTarget is the catalog target of a provider's sandbox.

func SetUpKeyLogin

func SetUpKeyLogin(ctx context.Context, target, password string, opts ...string) (string, error)

SetUpKeyLogin uses password once to authorize a public key on target, then checks that key login works without it. It returns the key's path. opts are the machine's extra ssh options: the key has to go to the host as conch will reach it, not to whatever a bare target resolves to.

func SetUpSandbox added in v0.1.5

func SetUpSandbox(ctx context.Context, m Machine, say func(string)) (*client.Client, error)

SetUpSandbox installs conch in a new sandbox and connects to its server. Nothing asks first: the sandbox was made for this.

func SourceDir

func SourceDir() string

SourceDir finds conch's source tree: $CONCH_SOURCE, or a directory above the running executable or the working directory whose go.mod declares conch's module. It returns "" when there is none.

func SyncCloudMachines added in v0.2.0

func SyncCloudMachines(ms []cloud.Machine) error

SyncCloudMachines makes the catalog's cloud machines the account's: a machine new to it is added, under its name where that is free, one the account no longer has is removed, and a renamed one keeps its ID. Nothing else in the catalog is touched.

func UnsavedWork added in v0.1.5

func UnsavedWork(projects []proto.ProjectInfo) []string

UnsavedWork lists what deleting a machine would lose: branches with commits no remote has, and uncommitted changes.

func VerifyInstalled added in v0.1.9

func VerifyInstalled(ctx context.Context, tr Transport, platform string) error

VerifyInstalled asks a machine what it has after conch was installed there, and says what the new binary still lacks. Nothing else notices such an install: the binary conch had to install can itself be from an older build — a source tree that moved on, a binary somebody put in CONCH_REMOTE_BINARY — and then the server started from it lacks capabilities, which reads exactly like a server left on an old build. The advice for that is to reload the server, and no reload can help, so the install is checked rather than assumed. A probe that fails says nothing: the bridge is about to speak for itself.

func WaitReachable added in v0.1.5

func WaitReachable(ctx context.Context, tr Transport) error

WaitReachable waits until the machine answers at all. A provider says a sandbox is started before its sshd is, so the first thing conch does there would otherwise fail on a machine that was seconds from ready.

Types

type CloudAsleepError added in v0.2.0

type CloudAsleepError struct {
	Label string
	State string
}

CloudAsleepError is a cloud machine that sleeps, so nothing answers there. Waking it uses the account's hours, so it is the person's call: a background connection never does.

func (*CloudAsleepError) Error added in v0.2.0

func (e *CloudAsleepError) Error() string

type ConnectionError added in v0.1.5

type ConnectionError struct {
	Err    error
	Stderr string
}

ConnectionError is ssh failing to connect rather than a command failing: worth trying again, since a sandbox that has only just been made may not be answering yet, and a long copy can be dropped.

func (*ConnectionError) Error added in v0.1.5

func (e *ConnectionError) Error() string

func (*ConnectionError) Unwrap added in v0.1.5

func (e *ConnectionError) Unwrap() error

type InstallError

type InstallError struct {
	Platform string
	Reason   string
}

InstallError means the machine needs conch installed or upgraded before it can be used. Background connections never install on their own.

func (*InstallError) Error

func (e *InstallError) Error() string

type Login added in v0.1.9

type Login struct {
	Host string   // as typed, user@ included
	Opts []string // the options kept, each with its value
}

Login is an ssh command line read back: the host it logs in to, and the options a second session to that host needs.

func ParseLogin added in v0.1.9

func ParseLogin(argv []string) (Login, bool)

ParseLogin reads an ssh command line — the program and its arguments, as the process table has them — and says which host it logs in to. It is false for anything that is not ssh logging in somewhere: another program, ssh -V, -G, -Q or -O, or no host.

type Machine

type Machine struct {
	ID      string    `json:"id"`
	Label   string    `json:"label"`
	Target  string    `json:"target"` // ssh destination: alias, user@host or ssh://user@host:port
	Enabled bool      `json:"enabled"`
	Added   time.Time `json:"added"`
	// Opts are extra ssh options this machine is reached with, as ssh
	// takes them ("-o", "KexAlgorithms=+…"): a port is in the target, but
	// a jump host, an old key exchange or a key of its own is not. A
	// machine saved by an older build has none, and an older build
	// ignores these — it reaches the host the way it always did.
	Opts []string `json:"opts,omitempty"`
}

Machine is a saved remote machine. It holds no secrets: authentication is entirely ssh's business.

func FindMachine

func FindMachine(ref string) Machine

FindMachine resolves an ID, label or ssh target to a machine. Unknown references are treated as ad-hoc ssh targets.

func LookupMachine added in v0.1.8

func LookupMachine(ref string) (Machine, bool)

LookupMachine is FindMachine without the fallback: a machine conch has, by ID, label or target — in that order, so an ID always reaches its own machine whatever another is labelled — or ok false. A command that acts on a machine already added wants this — FindMachine would turn the name of a machine conch does not have into an ssh target and try to resolve it, so `conch machine upgrade dxb01` answered "Could not resolve hostname dxb01" for a sandbox that was simply not in the catalog.

func Machines

func Machines() ([]Machine, error)

Machines loads the saved machines.

func RenameMachine

func RenameMachine(ref, label string) (Machine, error)

RenameMachine changes the label of a machine found by ID or label. The ID stays, so saved state and pane references keep working.

func SaveMachine

func SaveMachine(m Machine) (Machine, error)

SaveMachine adds m (or updates the machine with the same target) and returns it with its ID filled in.

A label is a name to type — `conch read busybox:p3`, `-m busybox` — so no two machines share one, and none is called "local" or another machine's ID. A new machine whose label would be taken is labelled with its own ID instead: alice@devbox and bob@devbox both default to "devbox", and the second becomes "devbox-2". It is not refused, since conch is already installed there by the time it is saved. A label given again for a machine already here is a rename, and a taken one is left as it was.

func (Machine) IsCloud added in v0.2.0

func (m Machine) IsCloud() bool

IsCloud reports whether the machine is a Conch Cloud machine.

func (Machine) IsSandbox added in v0.1.5

func (m Machine) IsSandbox() bool

IsSandbox reports whether the machine is a provider's sandbox.

type Options

type Options struct {
	// Install lets Connect install or upgrade conch on the machine.
	Install bool
	// Password answers ssh's password prompt without a terminal. It is
	// handed to ssh through a short-lived askpass helper and never stored.
	Password string
	// Progress receives human-readable steps.
	Progress func(string)
}

Options control Connect.

type OutdatedServerError

type OutdatedServerError struct {
	Missing []string
}

OutdatedServerError means the machine's running server predates this client. Restarting it stops its panes, so that is the user's call.

func (*OutdatedServerError) Error

func (e *OutdatedServerError) Error() string

type Probe

type Probe struct {
	Platform string          // e.g. linux/amd64
	Bin      string          // path of an installed conch, "" if none
	Info     *buildinfo.Info // that binary's `conch version --json`
}

Probe is what a machine reported about itself.

func ProbeMachine

func ProbeMachine(ctx context.Context, tr Transport) (Probe, error)

ProbeMachine inspects a machine.

func (Probe) Missing

func (p Probe) Missing() []string

Missing lists capabilities this client needs that the probed binary lacks. A binary too old to print its version lacks everything. Those a server may withhold on its machine are not asked for (proto.OptionalCapabilities): lacking them is no sign of an older build.

type SandboxStoppedError added in v0.1.5

type SandboxStoppedError struct {
	Label string
	State sandbox.State
}

SandboxStoppedError is a sandbox that isn't running, so there is nothing to connect to. Starting it is the user's call: a running sandbox costs.

func (*SandboxStoppedError) Error added in v0.1.5

func (e *SandboxStoppedError) Error() string

type Transport added in v0.1.2

type Transport interface {
	// Command returns a command that runs script on the machine, ready for
	// its stdin, stdout and stderr to be wired up.
	Command(ctx context.Context, script string) (*exec.Cmd, error)
	// Describe names the machine in messages, e.g. "dev@gpu-box".
	Describe() string
	// contains filtered or unexported methods
}

Transport runs commands on a machine. Everything this package does to a machine — probing it, installing conch, bridging to its server — is a script run through one of these, so a machine can be reached by ssh today and by other means (a sandbox VM) later.

func CloudTransport added in v0.2.0

func CloudTransport(label, id string) (Transport, error)

CloudTransport reaches cloud machine id through this conch's `conch cloud exec` and `conch cloud bridge`, whatever its state: a machine asleep is woken by the first of them.

func Exec added in v0.1.2

func Exec(name string, argv ...string) Transport

Exec reaches a machine by running a local command, such as `container exec -i NAME sh -c SCRIPT` for a sandbox. The script is appended to argv as one argument. name is what messages call the machine.

func SSH added in v0.1.2

func SSH(target string, interactive bool, opts ...string) Transport

SSH reaches a machine over ssh. An interactive transport lets ssh prompt on the terminal; otherwise a run that needs a password fails instead of hanging. opts are the machine's extra ssh options (Machine.Opts): a jump host, an old key exchange, a key of its own.

func TransportFor added in v0.1.5

func TransportFor(ctx context.Context, label, target string, interactive bool, opts ...string) (Transport, error)

TransportFor reaches the machine saved with target: over ssh, or for a sandbox, over ssh with fresh credentials from its provider. label names it in messages, since a sandbox's ssh destination is a secret. opts are the machine's extra ssh options, which a sandbox has none of: its way in is the provider's to describe, not a host somebody typed.

Jump to

Keyboard shortcuts

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