web

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APITokenPath added in v0.2.1

func APITokenPath(stateDir string) string

APITokenPath returns the path to the API bearer-token file under stateDir. State dir is typically <HomePath>/state.

func AgentTokenPath added in v0.12.1

func AgentTokenPath(stateDir string) string

AgentTokenPath returns the path to the agent bearer-token file under stateDir.

func EnsureAPIToken added in v0.2.1

func EnsureAPIToken(stateDir string) (string, error)

EnsureAPIToken makes sure an API bearer token exists at APITokenPath(stateDir) and returns its contents. If the file is missing it generates a fresh token (32 random bytes, hex-encoded = 64 hex chars) and writes it with mode 0600. If the file exists its contents are returned unchanged — callers should not rotate silently. stateDir is created with mode 0700 if absent, and its perm is tightened to 0700 if an existing directory was looser.

If the existing token file is not mode 0600, EnsureAPIToken refuses to start rather than silently auto-chmod'ing. The caller should delete the file (or fix its permissions) to unblock startup.

func EnsureAgentToken added in v0.12.1

func EnsureAgentToken(stateDir string) (string, error)

EnsureAgentToken makes sure the agent bearer token exists and returns it. Same storage contract as EnsureAPIToken, different privileges: this is the token exported to every supervised agent as LEO_API_TOKEN, and it is accepted only on /api/* and the agent-messaging routes — never at /login, and never on the browser UI, whose config editor renders env values in full. Keeping it distinct bounds what a token that escapes an agent (into a transcript, a log, a channel message) can be used for.

Types

type AgentService

type AgentService interface {
	Spawn(ctx context.Context, spec agent.SpawnSpec) (agent.Record, error)
	Stop(name string) error
	List() []agent.Record
	Resolve(query string) (agent.Record, error)
	Rename(query, newName string) (agent.Record, error)
	Suspend(name string) error
	Resume(name string) (agent.Record, error)
	// RestartAll bounces every live agent in place (skipping suspended/
	// stopped ones), re-applying current config for template-spawned agents.
	// Backs POST /web/agents/restart.
	RestartAll() agent.RestartResult
	// ResolveHandle resolves an agent name to its harness name and the
	// SessionHandle a SessionDriver needs to deliver a message to it.
	// ok=false means "not an ephemeral agent" (unknown name, or no
	// agentstore record) — callers fall back to the tmux-based claude path.
	ResolveHandle(name string) (harnessName string, h harness.SessionHandle, ok bool)
}

AgentService owns the ephemeral-agent lifecycle. It is implemented by *agent.Manager; web handlers delegate to it instead of driving the supervisor directly, so the same code path backs the web UI, channel plugins, the daemon socket, and the CLI. A nil AgentService disables agent UI features.

type ConfigReloader

type ConfigReloader interface {
	ReloadConfig() error
}

ConfigReloader reloads config and re-syncs the scheduler.

type Option added in v0.13.0

type Option func(*Server)

Option configures optional Server dependencies that are not required for the server's existing functionality to keep working unchanged. Passing no options preserves pre-existing behavior for every current caller.

func WithActivityProvider added in v0.13.0

func WithActivityProvider(p observe.ActivityProvider) Option

WithActivityProvider wires the activity tracker's read seam so GET /api/v1/state and GET /api/v1/events can report live agent activity. Optional; omitting it makes every agent report observe.ActivityUnknown.

func WithEventSource added in v0.13.0

func WithEventSource(es eventSource) Option

WithEventSource wires the event bus that GET /api/v1/events streams from. Optional; omitting it makes the stream serve only a hello event plus heartbeats (no bus-published events).

func WithMessageLog added in v0.15.0

func WithMessageLog(ml messageProvider) Option

WithMessageLog wires the agent-message log GET /api/v1/state reads recent_messages from. Optional; omitting it makes recent_messages empty.

func WithPublisher added in v0.15.0

func WithPublisher(p observe.Publisher) Option

WithPublisher wires the event bus the web layer publishes agent-to-agent message activity to. Optional; omitting it silently skips those events, leaving every other observability signal unaffected.

func WithRunLog added in v0.13.0

func WithRunLog(rl runProvider) Option

WithRunLog wires the run log GET /api/v1/state reads recent_runs from. Optional; omitting it makes recent_runs built from task history alone (no in-flight runs, and less honest completed-run timing on entries recorded before the run log existed).

func WithVersion added in v0.13.0

func WithVersion(v string) Option

WithVersion sets the Leo build version reported as Snapshot.LeoVersion by GET /api/v1/state. Optional; omitting it reports an empty string.

type Options added in v0.2.1

type Options struct {
	Port     int
	APIToken string
	// AgentToken is the less-privileged token handed to spawned agents as
	// LEO_API_TOKEN. Accepted on /api/* and the agent-messaging routes, and
	// rejected at /login and on the rest of the browser UI. Empty means only
	// APIToken is accepted anywhere (pre-split behaviour).
	AgentToken   string
	AllowedHosts []string
	// LogPath is the absolute path to the service log, computed by
	// service.LogPathFor(homePath) at the layer that can import
	// internal/service (see internal/daemon/server.go's StartWeb). Optional;
	// empty disables the Service page's log tail (renders a "not
	// configured" message instead of guessing a path).
	LogPath string
	// ResolveHandle resolves a config-defined process name to its harness
	// name and SessionHandle. Optional; nil means every process is treated
	// as claude (today's behavior). Wired from service boot the same way
	// LogPath is — see internal/service/process.go.
	ResolveHandle func(name string) (harnessName string, h harness.SessionHandle, ok bool)
	// ConsultRecorder persists consult records and event streams so
	// `leo consult list` / `leo consult watch` can see work in flight.
	// Optional; nil discards recordings.
	ConsultRecorder consult.Recorder
}

Options bundles the knobs the web server needs that aren't part of the provider interfaces. Zero values disable the corresponding surface:

  • Port must match the listener port so Host/Origin checks pass.
  • APIToken must be non-empty for /api/* routes to work. If empty, /api/* responds 500 to avoid accidentally serving the API unauthenticated.

type ProcessStateInfo

type ProcessStateInfo struct {
	Name      string    `json:"name"`
	Status    string    `json:"status"`
	StartedAt time.Time `json:"started_at"`
	Restarts  int       `json:"restarts"`
	Ephemeral bool      `json:"ephemeral,omitempty"`
}

ProcessStateInfo mirrors daemon.ProcessStateInfo to avoid import cycle.

type ProcessStateProvider

type ProcessStateProvider interface {
	States() map[string]ProcessStateInfo
}

ProcessStateProvider returns the state of all supervised processes.

type SchedulerProvider

type SchedulerProvider interface {
	List() []cron.EntryInfo
}

SchedulerProvider exposes cron entry listing.

type Server

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

Server serves the Leo web UI over HTTP.

func New

func New(configPath string, processes ProcessStateProvider, scheduler SchedulerProvider, reloader ConfigReloader, agentSvc AgentService, opts Options, extra ...Option) *Server

New creates a new web UI server. agentSvc may be nil if agent spawning is not available. extra applies optional dependencies (activity provider, event bus, version) via the functional-option pattern — every existing caller passing none keeps its current behavior unchanged.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the listener address, or empty if not listening.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

ListenAndServe starts the web server on the given address.

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown gracefully stops the web server.

Directories

Path Synopsis
Package schema defines the single source of truth mapping Leo's config fields to web-UI form controls.
Package schema defines the single source of truth mapping Leo's config fields to web-UI form controls.

Jump to

Keyboard shortcuts

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