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
- Variables
- func LocalName() string
- func MarkWords(m agent.Mark) string
- func Rules(bin string) agent.Rules
- type Activity
- type AgentState
- type App
- func (a *App) Activities() ([]Activity, error)
- func (a *App) Apply(ctx context.Context, p *move.Plan, in move.Input, progress func(string)) (*move.Result, error)
- func (a *App) Connect(ctx context.Context, h config.Host) (*host.Machine, error)
- func (a *App) DefaultOptions() move.Options
- func (a *App) InstallSkill(ctx context.Context, files map[string][]byte, version, bin string, ...) (SkillReport, error)
- func (a *App) Journals() ([]*journal.Journal, error)
- func (a *App) LocalRoots() []string
- func (a *App) Module(id agent.ID) (agent.Module, bool)
- func (a *App) Modules() []agent.Module
- func (a *App) OwedMarks() ([]lineage.Pending, error)
- func (a *App) Plan(ctx context.Context, inv *Inventory, e Entry, target agent.ID, ...) (*move.Plan, move.Input, error)
- func (a *App) RemoveSkill(ctx context.Context, files map[string][]byte, bin string, force bool) error
- func (a *App) Resume(inv *Inventory, e Entry, o agent.ResumeOptions) (agent.Command, error)
- func (a *App) ResumeShell(inv *Inventory, e Entry) (string, error)
- func (a *App) Scan(ctx context.Context, o ScanOptions) *Inventory
- func (a *App) Serve(ctx context.Context, r io.Reader, w io.Writer) error
- func (a *App) SetupKeyLogin(ctx context.Context, h config.Host, createKey bool) (*KeyLogin, error)
- func (a *App) Skill(ctx context.Context, files map[string][]byte, bin string) SkillReport
- func (a *App) Specs() []agent.Spec
- func (a *App) StartPush(ctx context.Context, inv *Inventory, e Entry, to config.Host, target agent.ID, ...) (*Push, error)
- func (a *App) Undo(ctx context.Context, match string, force bool) (*journal.Journal, error)
- type Copy
- type Entry
- type Group
- type Inventory
- type Item
- type KeyLogin
- type Machine
- type PeerConn
- type Push
- type PushResult
- type Ref
- type RuleState
- type ScanOptions
- type SkillCopy
- type SkillReport
Constants ¶
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 ¶
var ErrAmbiguous = errors.New("several sessions match")
ErrAmbiguous means a reference matches several sessions.
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.
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 (*App) Activities ¶
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) DefaultOptions ¶
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) LocalRoots ¶
LocalRoots are folders searched for checkouts on this machine.
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 ¶
Resume is the command that continues a session that is already on this machine.
func (*App) ResumeShell ¶
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 ¶
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 ¶
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 ¶
Skill reports the skill copies and rules against files (this build's rendering).
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.
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"`
GitError string `json:"gitError,omitempty"` // the checkout could not be read
Lineage *lineage.Manifest `json:"lineage,omitempty"`
}
Entry is one session on one machine.
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 ¶
Inventory is the result of a scan.
func (*Inventory) Close ¶
func (inv *Inventory) Close()
Close ends every connection the scan opened.
func (*Inventory) Find ¶
Find returns the session a reference names. Without a machine, the newest copy of the session is chosen.
func (*Inventory) Groups ¶
Groups arranges sessions by repository; sessions outside git are in a group with no identity. localRoots are searched for checkouts on this machine.
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.
type PeerConn ¶
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 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.