host

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 29 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 host gives the core and its agent modules access to a machine: this one, or another over SSH. A Machine is probed once (one round trip, generated from every module's Spec); For returns the agent.Host a module sees, confined to its Spec and with every write journaled.

Index

Constants

View Source
const LoginSessionEnv = "HOPSESH_LOGIN_SESSION"

LoginSessionEnv is set for hopsesh started in the user's login session (hopsesh serve and what it runs), where a Mac's Keychain is readable even when it was reached by SSH.

Variables

View Source
var Hopsesh = agent.Binary{
	Name: "hopsesh",
	Candidates: map[string][]string{
		"*":       {"~/.hopsesh/bin/hopsesh", "~/.local/bin/hopsesh", "/opt/homebrew/bin/hopsesh", "/usr/local/bin/hopsesh", "/Applications/hopsesh.app/Contents/Resources/bin/hopsesh"},
		"windows": {"~/.hopsesh/bin/hopsesh.exe", "~/AppData/Local/Programs/hopsesh/hopsesh.exe"},
	},
	VersionArgs: []string{"version"},
}

Hopsesh is hopsesh itself on a machine: the probe reports whether it is there (to work with it as a peer) and its version.

Functions

func SpecEnv

func SpecEnv(s agent.Spec) []string

SpecEnv lists the variables a Spec reads (roots and login environment).

func Unsetting added in v0.4.0

func Unsetting(h agent.Host, unset []string) agent.Host

Unsetting is h with every program it runs started without the variables in unset: the environment a cloud's driver must not inherit (agent.Cloud.Unset).

func Without added in v0.4.0

func Without(env, unset []string) []string

Without is an environment (KEY=value pairs) without the named variables.

Types

type FS

type FS interface {
	agent.FS
	Remove(p string) error // a file or an empty folder
	Truncate(p string, size int64) error
	Chtimes(p string, t time.Time) error
	MkdirAll(p string) error
}

FS is the core's filesystem: the module FS plus what the journal and the installer need.

func LocalFS

func LocalFS() FS

LocalFS is this machine's filesystem.

type Facts

type Facts struct {
	DesktopProtocols map[string]bool             `json:"desktopProtocols,omitempty"`
	Endpoint         string                      `json:"endpoint"`
	OS               string                      `json:"os"`
	Arch             string                      `json:"arch"`
	Home             string                      `json:"home"`
	Env              map[string]string           `json:"env"`
	Binaries         map[string]agent.BinaryFact `json:"binaries"`
	HasGit           bool                        `json:"hasGit"`
	// LoginSession: the answers come from hopsesh running in the user's login session
	// there, which sees what an SSH login cannot (a Mac's Keychain, its desktop apps).
	LoginSession bool `json:"loginSession,omitempty"`
}

Facts is what one probe learned about a machine.

func ProbeLocal

func ProbeLocal(ctx context.Context, specs []agent.Spec) Facts

ProbeLocal learns this machine's facts for the given modules.

func ProbeLocalFast added in v0.4.1

func ProbeLocalFast(ctx context.Context, specs []agent.Spec) Facts

ProbeLocalFast resolves roots and executable paths without launching agents or checking desktop protocols. Browsing can start before version enrichment.

func ProbeRemote

func ProbeRemote(ctx context.Context, c *transport.Conn, specs []agent.Spec) (Facts, error)

ProbeRemote learns a machine's facts in one round trip, with a script generated from the modules' Specs (no module code runs on the remote machine).

type Keeper added in v0.5.0

type Keeper interface {
	Kept() (string, error) // "" when none was kept
	// Keep records id, unless another one is kept already (an error then).
	Keep(id string) error
}

Keeper remembers, on this machine, the identity of a machine hopsesh is not installed on (Machine.HopseshThere), so that reaching it over SSH writes nothing there.

type Machine

type Machine struct {
	Name  string
	Local bool
	Conn  *transport.Conn // nil for this machine
	Facts Facts
	Log   *slog.Logger
	// Keeper keeps the identity of a machine without hopsesh (see HopseshThere).
	Keeper Keeper
	// contains filtered or unexported fields
}

Machine is a place sessions live: this machine, one reached over SSH, or a snapshot another machine's hopsesh sent.

func NewSnapshot

func NewSnapshot(name string, facts Facts, files []SnapshotFile) *Machine

NewSnapshot is another machine seen only through files its hopsesh sent (a push): the session's files, nothing else. Nothing runs there and no process is alive; writes are recorded for the sender (Writes).

func (*Machine) Close

func (m *Machine) Close()

Close ends the machine's SFTP session and shared SSH connection.

func (*Machine) CommitIdentity added in v0.4.0

func (m *Machine) CommitIdentity(ctx context.Context) error

func (*Machine) Exec

func (m *Machine) Exec() agent.Exec

Exec runs programs on the machine.

func (*Machine) FS

func (m *Machine) FS(ctx context.Context) (FS, error)

FS returns the machine's filesystem (opening SFTP on first use for a remote machine).

func (*Machine) For

func (m *Machine) For(ctx context.Context, s agent.Spec, in agent.Install, w Writes) (agent.Host, error)

For returns the Host a module sees on this machine: facts limited to what its Spec declares, writes through w (the journal, or nil for read-only work), confined to the install's roots and away from its secrets.

func (*Machine) GitProbe

func (m *Machine) GitProbe(ctx context.Context, dirs, excl []string) ([]repos.GitState, error)

GitProbe returns the git state of folders on the machine. excl are agent-managed worktree folders.

func (*Machine) HopseshThere added in v0.5.0

func (m *Machine) HopseshThere() bool

HopseshThere reports whether hopsesh runs on the machine, so its own files may be written there: this machine, a sender's snapshot, or a probe that found hopsesh.

func (*Machine) IsSnapshot

func (m *Machine) IsSnapshot() bool

IsSnapshot reports whether the machine is a snapshot.

func (*Machine) Locks

func (m *Machine) Locks() agent.Locks

Locks probes lock files on the machine.

func (*Machine) Path

func (m *Machine) Path() agent.Path

Path is the machine's path form.

func (*Machine) PrepareIdentity added in v0.4.0

func (m *Machine) PrepareIdentity(ctx context.Context) (string, error)

PrepareIdentity reserves a persistent endpoint identifier, independent of SSH aliases and display names. A plan reserves a new identifier in memory; only Apply persists it.

func (*Machine) Procs

func (m *Machine) Procs() agent.Procs

Procs checks and stops processes on the machine.

func (*Machine) ReadIdentity added in v0.4.0

func (m *Machine) ReadIdentity(ctx context.Context) (string, error)

ReadIdentity reads an already initialized endpoint without reserving or writing one.

func (*Machine) RemoteFS added in v0.5.0

func (m *Machine) RemoteFS() (*transport.RemoteFS, bool)

RemoteFS is the SFTP side of a machine reached over SSH (for uploads).

func (*Machine) ShortNames

func (m *Machine) ShortNames(ctx context.Context, paths []string) map[string]string

ShortNames returns the 8.3 short form of each path on a Windows machine ("C:\Users\LIHUA~1\proj"), for the paths that have one that differs. A session can name the same folder either way; moves rewrite both. Other systems, snapshots, and drives with short names turned off give none.

func (*Machine) SignInsHidden added in v0.5.0

func (m *Machine) SignInsHidden() bool

SignInsHidden reports that the machine's sign-ins may be invisible to hopsesh here, so a signed-out answer proves nothing. On a Mac they live in the Keychain, which a process started over SSH cannot read; hopsesh running in the user's login session there (Facts.LoginSession) sees them.

func (*Machine) Writes

func (m *Machine) Writes() []SnapshotWrite

Writes returns the writes made to a snapshot machine, in order.

type SnapshotFile

type SnapshotFile struct {
	Path    string      `json:"path"`
	Data    []byte      `json:"data"`
	Mode    fs.FileMode `json:"mode"`
	ModTime time.Time   `json:"modTime"`
}

SnapshotFile is one file of a snapshot: its path on the machine it came from.

type SnapshotWrite

type SnapshotWrite struct {
	Op     string      `json:"op"` // write | append | rename
	Path   string      `json:"path"`
	From   string      `json:"from,omitempty"` // rename
	Data   []byte      `json:"data,omitempty"`
	Perm   fs.FileMode `json:"perm,omitempty"`
	Append agent.AppendOptions
}

SnapshotWrite is a write made to a snapshot. It is not applied anywhere: the machine the snapshot came from replays it (journaled there).

type Writes

type Writes interface {
	WriteFile(fsys FS, machine, p string, b []byte, perm fs.FileMode) error
	Append(fsys FS, machine, p string, b []byte, o agent.AppendOptions) error
	Rename(fsys FS, machine, from, to string) error
}

Writes is where module writes go: the journal records how to undo each before it happens.

Jump to

Keyboard shortcuts

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