Documentation
¶
Overview ¶
Package web provides an embedded HTTP server for the initech web companion. It serves a single-page application from embedded static files and exposes a JSON API for pane information.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentEventInfo ¶ added in v1.7.0
type AgentEventInfo struct {
Kind string `json:"kind"`
Pane string `json:"pane"`
BeadID string `json:"bead_id,omitempty"`
Detail string `json:"detail"`
Time string `json:"time"` // RFC 3339
}
AgentEventInfo is a serializable agent event for the web companion.
type EventProvider ¶ added in v1.7.0
type EventProvider interface {
SubscribeEvents(id string) chan AgentEventInfo
UnsubscribeEvents(id string)
}
EventProvider provides event subscription for the /ws/state stream. Subscribe returns a channel that receives agent events. Unsubscribe removes the subscription and closes the channel.
type LayoutInfo ¶ added in v1.6.0
type LayoutInfo struct {
Mode string `json:"mode"` // "focus", "grid", or "2col"
Cols int `json:"cols"`
Rows int `json:"rows"`
Focused string `json:"focused"` // Pane name.
}
LayoutInfo describes the current TUI layout.
type PaneInfo ¶
type PaneInfo struct {
Name string `json:"name"`
Host string `json:"host,omitempty"`
Activity string `json:"activity"`
Alive bool `json:"alive"`
Visible bool `json:"visible"`
}
PaneInfo describes a single managed pane. Mirrors tui.PaneInfo so the web package does not import tui directly.
type PaneLister ¶
PaneLister returns the current set of panes. The bool is false if the underlying system is shutting down and the data is unavailable.
type PaneState ¶ added in v1.6.0
type PaneState struct {
Name string `json:"name"`
Activity string `json:"activity"`
Alive bool `json:"alive"`
Visible bool `json:"visible"`
BeadID string `json:"bead_id,omitempty"`
Order int `json:"order"`
}
PaneState describes one agent's state for the web companion.
type PaneSubscriber ¶
type PaneSubscriber interface {
// SubscribePane registers a subscriber for the named pane's PTY output.
// Returns a channel of byte slices and true if the pane exists, or
// nil and false if the pane is not found.
SubscribePane(paneName, subscriberID string) (chan []byte, bool)
// UnsubscribePane removes a subscriber. Safe to call if the pane or
// subscriber does not exist.
UnsubscribePane(paneName, subscriberID string)
}
PaneSubscriber provides fan-out subscription to a pane's PTY byte stream. The returned channel receives copies of all bytes read from the pane's PTY. Callers must call UnsubscribePane when done.
type PaneWriter ¶ added in v1.7.0
type PaneWriter interface {
// WriteToPTY writes data to the named pane's PTY master. Returns an error
// if the pane is not found or dead. Safe for concurrent use.
WriteToPTY(paneName string, data []byte) error
}
PaneWriter writes raw bytes to a pane's PTY input. Used by the WebSocket handler to relay keyboard input from the browser to the agent terminal. Implementations must serialize writes with other PTY writers (e.g. IPC send).
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an HTTP server that serves the SPA and pane API.
func NewServer ¶
func NewServer(port int, lister PaneLister, subscriber PaneSubscriber, stateProvider StateProvider, eventProvider EventProvider, paneWriter PaneWriter, logger *slog.Logger) *Server
NewServer creates a Server bound to 0.0.0.0 on the given port, accessible from other machines on the network. The operator explicitly enables this with --web-port, so we bind all interfaces by default. If port is 0, the OS assigns a free port. The subscriber parameter is optional; if nil, the /ws/pane/{name} endpoint returns 501.
func (*Server) Addr ¶
Addr returns the address the server is bound to. Only meaningful after Start has been called (and the listener is active).
type StateProvider ¶ added in v1.6.0
type StateProvider interface {
CurrentState() (StateSnapshot, bool)
}
StateProvider returns the current TUI state snapshot. Called on a timer by the state broadcaster.
type StateSnapshot ¶ added in v1.6.0
type StateSnapshot struct {
Project string `json:"project,omitempty"`
Layout LayoutInfo `json:"layout"`
Panes []PaneState `json:"panes"`
}
StateSnapshot is the JSON payload sent over /ws/state. It combines layout information with per-agent status for the web companion SPA.