app

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 28 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 app is what hopsesh does, for every front end (command line, terminal UI, desktop app, the agents' skill): scan machines for sessions of every agent, plan and carry out moves and continuations, undo them, and keep the agents' integration current.

Index

Constants

View Source
const (
	StatusOK          = "ok"
	StatusUnreachable = "unreachable"
	StatusAuth        = "auth"
	StatusHostKey     = "host-key"
	StatusKeyChanged  = "host-key-changed"
	StatusTSCheck     = "tailscale-check"
	StatusLocalNet    = "local-network" // macOS local network privacy blocked it
	StatusError       = "error"
)

Machine statuses.

Variables

View Source
var ErrAmbiguous = errors.New("several sessions match")

ErrAmbiguous means a reference matches several sessions.

View Source
var ErrNoLocalKey = errors.New("this machine has no SSH key that ssh would use for it")

ErrNoLocalKey means this machine has no SSH key that ssh would offer to the machine; SetupKeyLogin can create one (createKey).

Functions

func LocalName

func LocalName() string

LocalName is this machine's name in marks and lineage: $HOPSESH_MACHINE, else its short host name.

func MarkWords

func MarkWords(m agent.Mark) string

MarkWords is a mark in words ("moved to studio", "continued in Codex on studio").

func Rules

func Rules(bin string) agent.Rules

Rules are the hopsesh commands agents may run without asking (read-only) and the ones that always ask.

Types

type Activity

type Activity struct {
	Journal *journal.Journal `json:"journal"`
	CanUndo bool             `json:"canUndo"`
	Why     string           `json:"why,omitempty"` // why not: undone, or what changed since
}

Activity is one operation hopsesh carried out, and whether it can be undone now.

type AgentState

type AgentState struct {
	Agent   agent.ID      `json:"agent"`
	Name    string        `json:"name"`
	Install agent.Install `json:"install"`
	Error   string        `json:"error,omitempty"`
}

AgentState is an agent as found on a machine.

type App

type App struct {
	Cfg      config.Config
	Reg      *registry.Registry // every compiled-in module
	StateDir string
	Audit    *audit.Log
	Log      *slog.Logger
	// Passwords answers ssh password questions for machines that log in with one (nil:
	// such machines are reported, not scanned).
	Passwords func(h config.Host) transport.PasswordFunc
	// PeerDial reaches hopsesh on a configured machine (nil: over SSH).
	PeerDial func(ctx context.Context, h config.Host) (*PeerConn, error)
}

App holds what every use case needs.

func New

func New(cfg config.Config, reg *registry.Registry, stateDir string, log *audit.Log) *App

New returns an App for the modules and configuration.

func (*App) Activities

func (a *App) Activities() ([]Activity, error)

Activities lists what hopsesh did, newest first. Whether each can still be undone is checked on this machine's files only (other machines are checked when undoing).

func (*App) Apply

func (a *App) Apply(ctx context.Context, p *move.Plan, in move.Input, progress func(string)) (*move.Result, error)

Apply carries out a plan.

func (*App) Connect

func (a *App) Connect(ctx context.Context, h config.Host) (*host.Machine, error)

Connect reaches a configured machine and probes it (one round trip).

func (*App) DefaultOptions

func (a *App) DefaultOptions() move.Options

DefaultOptions are move options from the configuration.

func (*App) InstallSkill

func (a *App) InstallSkill(ctx context.Context, files map[string][]byte, version, bin string, force, rules bool) (SkillReport, error)

InstallSkill writes the same files into every agent's skills folder in one go (and, with rules, each agent's approval rules). A copy the user edited stops the install unless force.

func (*App) Journals

func (a *App) Journals() ([]*journal.Journal, error)

Journals lists what can be undone, newest first.

func (*App) LocalRoots

func (a *App) LocalRoots() []string

LocalRoots are folders searched for checkouts on this machine.

func (*App) Module

func (a *App) Module(id agent.ID) (agent.Module, bool)

Module returns an enabled module by id.

func (*App) Modules

func (a *App) Modules() []agent.Module

Modules returns the enabled modules.

func (*App) OwedMarks

func (a *App) OwedMarks() ([]lineage.Pending, error)

OwedMarks are the marks waiting for a copy left behind to end.

func (*App) Plan

func (a *App) Plan(ctx context.Context, inv *Inventory, e Entry, target agent.ID, opt move.Options) (*move.Plan, move.Input, error)

Plan works out how a session comes here, in the same agent or (target set) another.

func (*App) RemoveSkill

func (a *App) RemoveSkill(ctx context.Context, files map[string][]byte, bin string, force bool) error

RemoveSkill removes every copy hopsesh owns, and the approval rules.

func (*App) Resume

func (a *App) Resume(inv *Inventory, e Entry, o agent.ResumeOptions) (agent.Command, error)

Resume is the command that continues a session that is already on this machine.

func (*App) ResumeShell

func (a *App) ResumeShell(inv *Inventory, e Entry) (string, error)

ResumeShell is Resume as a line for this machine's shell.

func (*App) Scan

func (a *App) Scan(ctx context.Context, o ScanOptions) *Inventory

Scan reads this machine and the allowed machines in parallel. A machine that cannot be read is returned with a status and a hint, not an error.

func (*App) Serve

func (a *App) Serve(ctx context.Context, r io.Reader, w io.Writer) error

Serve answers another machine's hopsesh on r and w until r ends (hopsesh peer --stdio). It receives sessions only when this machine opted in (peer receive = true).

func (*App) SetupKeyLogin

func (a *App) SetupKeyLogin(ctx context.Context, h config.Host, createKey bool) (*KeyLogin, error)

SetupKeyLogin moves a password machine to key login: it logs in once with the password, adds this machine's public key to the account's authorized_keys, and checks that a login without a password now works. It does not change the configuration; the caller switches the machine to key login when this succeeds.

func (*App) Skill

func (a *App) Skill(ctx context.Context, files map[string][]byte, bin string) SkillReport

Skill reports the skill copies and rules against files (this build's rendering).

func (*App) Specs

func (a *App) Specs() []agent.Spec

Specs returns the enabled modules' Specs.

func (*App) StartPush

func (a *App) StartPush(ctx context.Context, inv *Inventory, e Entry, to config.Host, target agent.ID, opt move.Options) (*Push, error)

StartPush connects to hopsesh on another machine and has it plan receiving a session from this machine, in its own agent or (target) another. Nothing changes until Commit.

func (*App) Undo

func (a *App) Undo(ctx context.Context, match string, force bool) (*journal.Journal, error)

Undo reverses a journal: by id, by a session id it concerns, or the newest when match is "". Writes on other machines are undone over SSH. Unless force, it refuses when a file the operation wrote changed since (that later work would be lost).

type Copy

type Copy struct {
	Machine    string           `json:"machine"`
	Agent      agent.ID         `json:"agent"`
	AgentName  string           `json:"agentName"`
	Key        agent.SessionKey `json:"key"`
	Local      bool             `json:"local,omitempty"`
	LastActive time.Time        `json:"lastActive"`
	Mark       *agent.Mark      `json:"mark,omitempty"`
	Live       bool             `json:"live,omitempty"`
	Newest     bool             `json:"newest,omitempty"`
}

Copy is one copy of a session that exists in several places or agents.

type Entry

type Entry struct {
	Machine   string            `json:"machine"`
	Agent     agent.ID          `json:"agent"`
	AgentName string            `json:"agentName"`
	Session   agent.Summary     `json:"session"`
	Live      agent.LiveInfo    `json:"live"`
	Git       *repos.GitState   `json:"git,omitempty"`
	Lineage   *lineage.Manifest `json:"lineage,omitempty"`
}

Entry is one session on one machine.

func (Entry) Status

func (e Entry) Status() string

Status is a session's state in words: "live …", where it went ("moved to studio"), or "ended".

type Group

type Group struct {
	Identity string `json:"identity"`
	Name     string `json:"name"`
	Remote   string `json:"remote,omitempty"`
	Local    string `json:"localCheckout,omitempty"` // a checkout on this machine
	Items    []Item `json:"items"`
}

Group is sessions of one repository.

type Inventory

type Inventory struct {
	Machines []*Machine `json:"machines"`
	Entries  []Entry    `json:"entries"`
}

Inventory is the result of a scan.

func (*Inventory) Close

func (inv *Inventory) Close()

Close ends every connection the scan opened.

func (*Inventory) Find

func (inv *Inventory) Find(r Ref) (Entry, error)

Find returns the session a reference names. Without a machine, the newest copy of the session is chosen.

func (*Inventory) Groups

func (inv *Inventory) Groups(localRoots []string) []Group

Groups arranges sessions by repository; sessions outside git are in a group with no identity. localRoots are searched for checkouts on this machine.

func (*Inventory) Items

func (inv *Inventory) Items() []Item

Items merges copies of the same session: by lineage (across agents and places) or by key (one agent, several places).

func (*Inventory) Local

func (inv *Inventory) Local() *Machine

Local returns this machine.

func (*Inventory) Machine

func (inv *Inventory) Machine(name string) *Machine

Machine returns a scanned machine by name.

type Item

type Item struct {
	Entry  Entry  `json:"entry"`
	Copies []Copy `json:"copies,omitempty"`
}

Item is one session, shown as its newest copy, with every copy when there are several.

type KeyLogin

type KeyLogin struct {
	PublicKey string `json:"publicKey"` // the local key file whose public half was installed
	Created   bool   `json:"created"`   // the key was made for this
	Added     bool   `json:"added"`     // false: the machine already had it
}

KeyLogin is what SetupKeyLogin did.

type Machine

type Machine struct {
	Name        string       `json:"name"`
	Destination string       `json:"destination,omitempty"`
	Local       bool         `json:"local"`
	Status      string       `json:"status"`
	Error       string       `json:"error,omitempty"`
	Hint        string       `json:"hint,omitempty"`
	OS          string       `json:"os,omitempty"`
	Agents      []AgentState `json:"agents"`
	// Hopsesh is the version of hopsesh installed there ("" when none was found).
	Hopsesh string `json:"hopsesh,omitempty"`
	// contains filtered or unexported fields
}

Machine is a scanned machine.

func (*Machine) Host

func (m *Machine) Host() *host.Machine

Host returns the machine's connection (nil when it was not reached).

func (*Machine) Install

func (m *Machine) Install(id agent.ID) (agent.Install, bool)

Install returns an agent's install there.

type PeerConn

type PeerConn struct {
	Out    io.Reader
	In     io.Writer
	Close  func()
	Stderr func() string
}

PeerConn is a connection to hopsesh on another machine: its output, its input, and how to end it (stderr is what it reported, for errors).

type Push

type Push struct {
	Plan   *move.Plan
	Peer   peer.HelloReply
	Pushed string // the branch was pushed first ("" when not)
	// contains filtered or unexported fields
}

Push is a session on this machine on its way to another machine's hopsesh: planned there, not yet carried out.

func (*Push) Close

func (p *Push) Close()

Close ends the connection (an uncommitted push changes nothing).

func (*Push) Commit

func (p *Push) Commit(ctx context.Context) (*PushResult, error)

Commit carries out the push: the other machine installs or converts the session, then this machine records, in its own journal, what changes for its copy (the mark and the lineage), and keeps a mark owed while the copy here is still open.

type PushResult

type PushResult struct {
	Result  *move.Result `json:"result"`
	Journal string       `json:"journal"` // undo here undoes both machines
	Machine string       `json:"machine"`
	Pushed  string       `json:"pushed,omitempty"`
}

PushResult is a finished push.

type Ref

type Ref struct {
	Machine string
	Agent   agent.ID
	Query   string
}

Ref names a session: [machine:][agent/]<id, id prefix or title>.

func ParseRef

func ParseRef(s string) Ref

ParseRef reads a session reference.

type RuleState

type RuleState struct {
	Agent   string `json:"agent"`
	Path    string `json:"path"`
	Present bool   `json:"present"`
}

RuleState is one agent's approval rules.

type ScanOptions

type ScanOptions struct {
	Hosts   []string // only these machines ("" or none: every allowed one)
	NoLocal bool     // leave this machine out
	SkipGit bool     // no git state (faster)
}

ScanOptions narrow a scan.

type SkillCopy

type SkillCopy struct {
	Dir    string                `json:"dir"`
	Agents []string              `json:"agents"` // display names
	Status integrate.SkillStatus `json:"status"`
}

SkillCopy is one place the skill goes, shared by every agent that reads that folder.

type SkillReport

type SkillReport struct {
	Copies []SkillCopy `json:"copies"`
	Rules  []RuleState `json:"rules"`
	InSync bool        `json:"inSync"` // every copy is current
	State  string      `json:"state"`  // the worst copy's state
}

SkillReport is the skill and rules across every agent installed here.

Jump to

Keyboard shortcuts

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