daemonclient

package
v0.71.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package daemonclient implements sessionapi.API against a hive daemon.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGitStatusUnsupported is a daemon whose hive predates GitStatuses.
	ErrGitStatusUnsupported = errors.New("the server's hive is too old to report git status; install the same hive version on both machines")
	// ErrFileContextUnsupported is a daemon whose hive predates FileContext.
	ErrFileContextUnsupported = errors.New("the daemon's hive is too old to show the unchanged lines of a diff; update hive and restart its daemon")
	// ErrStartTmuxUnsupported is a daemon whose hive predates StartTmux.
	ErrStartTmuxUnsupported = errors.New("the server's hive is too old to start a terminal; install the same hive version on both machines")
)

Functions

func Spawn

func Spawn(ctx context.Context, binary, dataDir string, env []string) error

Spawn starts `<binary> daemon run` detached from the caller (its own session, stdio to <dataDir>/logs/hived.out) and waits up to 5s for /healthz. HIVE_DATA_DIR is set to dataDir and HIVE_CONFIG is made absolute, since the daemon outlives the caller's working directory. A daemon another client started first also counts as ready.

Types

type AgentCheck added in v0.69.0

type AgentCheck struct {
	Profile string
	Command string
	Path    string
}

AgentCheck is where the daemon finds an agent profile's command. Path is empty when the command is not on the daemon's PATH.

type Client

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

func New

func New(opts Options) *Client

func (*Client) CheckSessionRisk

func (c *Client) CheckSessionRisk(ctx context.Context, id string) (sessionsvc.Risk, error)

func (*Client) CreateFromRequest

func (c *Client) CreateFromRequest(ctx context.Context, req sessionsvc.LaunchRequest) (session.Session, error)

func (*Client) CreateSession

func (c *Client) CreateSession(ctx context.Context, opts sessionsvc.CreateOptions) (*session.Session, error)

func (*Client) CreateSessionWithWindows

func (c *Client) CreateSessionWithWindows(ctx context.Context, req sessionsvc.NewSessionRequest, windows []multiplexer.WindowSpec) (*session.Session, error)

func (*Client) DeleteSession

func (c *Client) DeleteSession(ctx context.Context, id string) error

func (*Client) Dial

func (c *Client) Dial(ctx context.Context) (net.Conn, error)

Dial opens a raw connection to the daemon, starting one when AutoStart is set and none answers. `hive daemon dial-stdio` bridges it to ssh.

func (*Client) EditSessionTags

func (c *Client) EditSessionTags(ctx context.Context, id string, add, remove []string) (session.Session, error)

func (*Client) FetchBatch

func (c *Client) FetchBatch(ctx context.Context, sessions []*session.Session, roots []status.RootRepoTarget) map[string]status.TerminalStatus

FetchBatch logs a failure and returns no statuses, the same as an unavailable status service in-process.

func (*Client) GetSession

func (c *Client) GetSession(ctx context.Context, id string) (session.Session, error)

func (*Client) GitStatuses added in v0.69.0

func (c *Client) GitStatuses(ctx context.Context, ids []string) (map[string]gitstatus.Status, error)

GitStatuses reports a daemon that predates the RPC as such, so a user knows to upgrade the server rather than look for a fault.

func (*Client) HTTPClient

func (c *Client) HTTPClient() *http.Client

HTTPClient reaches the daemon's plain HTTP endpoints, such as /healthz.

func (*Client) Health

func (c *Client) Health(ctx context.Context) (Health, error)

func (*Client) Hello

func (c *Client) Hello(ctx context.Context) (Info, error)

Hello also refreshes the cached answer StatusAvailable gives.

func (*Client) ListSessions

func (c *Client) ListSessions(ctx context.Context) ([]session.Session, error)

func (*Client) Metrics

func (c *Client) Metrics(ctx context.Context) ([]byte, error)

Metrics returns the daemon's /metrics page in the Prometheus text format.

func (*Client) Prune

func (c *Client) Prune(ctx context.Context, all bool) (int, error)

func (*Client) RecycleSession

func (c *Client) RecycleSession(ctx context.Context, id string, w io.Writer) error

func (*Client) Reload

func (c *Client) Reload(ctx context.Context) error

func (*Client) RenameSession

func (c *Client) RenameSession(ctx context.Context, id, name string) error

func (*Client) SessionBranches added in v0.69.0

func (c *Client) SessionBranches(ctx context.Context, id string) ([]string, error)

func (*Client) SessionChanges added in v0.69.0

func (c *Client) SessionChanges(ctx context.Context, id string, target gitstatus.DiffTarget) (gitstatus.Changes, error)

func (*Client) SessionFileContext added in v0.70.0

func (c *Client) SessionFileContext(ctx context.Context, id string, target gitstatus.DiffTarget, path string) (gitstatus.FileDiff, error)

func (*Client) SessionFileDiffs added in v0.69.0

func (c *Client) SessionFileDiffs(ctx context.Context, id string, target gitstatus.DiffTarget, paths []string) ([]gitstatus.FileDiff, error)

func (*Client) SessionLaunchOptions

func (c *Client) SessionLaunchOptions(ctx context.Context) (sessionsvc.LaunchOptions, error)

func (*Client) SetSessionGroup

func (c *Client) SetSessionGroup(ctx context.Context, id, group string) error

func (*Client) SetSessionTags

func (c *Client) SetSessionTags(ctx context.Context, id string, tags []string) (session.Session, error)

func (*Client) StartTmuxSession added in v0.69.0

func (c *Client) StartTmuxSession(ctx context.Context, id string) (multiplexer.LaunchResult, error)

StartTmuxSession is not retried: a second start after a lost answer could spawn the agent twice.

func (*Client) StatusAvailable

func (c *Client) StatusAvailable() bool

StatusAvailable answers from the last Hello. Until a Hello reports status available, a call starts one in the background (at most one at a time, and one per helloRetry) and answers false, so the TUI's Update never waits on the socket.

func (*Client) Stop

func (c *Client) Stop(ctx context.Context) error

type Dialer

type Dialer func(ctx context.Context) (net.Conn, error)

Dialer opens one connection to a daemon.

func LocalDialer

func LocalDialer(dataDir string) Dialer

LocalDialer reaches the daemon that serves dataDir on this machine.

func UnixDialer

func UnixDialer(path string) Dialer

type Health

type Health struct {
	Supervised      bool
	Agents          []AgentCheck
	DBOK            bool
	DBError         string
	TmuxOK          bool
	StatusLoop      StatusLoopHealth
	SessionsByState map[string]int
	Uptime          time.Duration
}

type Info

type Info struct {
	Version         string
	ProtocolVersion int
	PID             int
	DataDir         string
	StartedAt       time.Time
	StatusAvailable bool
}

type Options

type Options struct {
	Dialer Dialer
	Logger zerolog.Logger
	// AutoStart starts a daemon when a dial finds none. nil never starts one,
	// as for a remote daemon or `hive daemon status --no-start`.
	AutoStart func(ctx context.Context) error
	// ReadTimeout bounds each read-only call, so a slow remote daemon cannot
	// block a caller. A call that changes sessions first asks the daemon for
	// Hello under this bound, so a stuck daemon fails it before any change.
	// Zero sets no bound and sends no Hello.
	ReadTimeout time.Duration
	// ConnectTimeout replaces ReadTimeout for a read while the client has no
	// connection, since setting one up can take many round trips on a slow link.
	ConnectTimeout time.Duration
	// RiskTimeout replaces ReadTimeout for a risk check, which runs git and takes
	// as long as the repository needs.
	RiskTimeout time.Duration
	// DeleteTimeout bounds a delete. The service finishes a delete it has
	// started, so a cut-off delete cannot leave a half-deleted session. Other
	// calls that change sessions have no bound: a clone can take any time, and
	// a rename cut off midway leaves tmux and the store apart.
	DeleteTimeout time.Duration
	// Name is the server this client reaches, for its errors. Empty means the
	// daemon on this machine.
	Name string
	// FailureDetail adds the transport's reason to an error, such as the last
	// line ssh printed.
	FailureDetail func() string
	// CheckProtocol refuses every call to a daemon whose protocol this
	// client does not support, with an error that names ClientVersion and
	// the daemon's version. A remote daemon can be any version, and so can a
	// local one that outlived an update.
	CheckProtocol bool
	ClientVersion string
	// ReplaceOlder, for a local client with AutoStart and CheckProtocol, stops
	// a daemon that is an older release than ClientVersion and starts this
	// client's binary in its place, once per client. A local daemon is not
	// always the binary that spawned it: it outlives updates. A dev or
	// unparseable version on either side never triggers it.
	ReplaceOlder bool
	// DataDir lets a restart wait for the old daemon's lock. Empty skips that.
	DataDir string
}

type StatusLoopHealth

type StatusLoopHealth struct {
	LastTick     time.Time
	LastDuration time.Duration
	Errors       int64
	Paused       bool
}

Jump to

Keyboard shortcuts

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