web

package
v1.14.9 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 11 Imported by: 0

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", "2col", or "live"
	Cols    int    `json:"cols"`
	Rows    int    `json:"rows"`
	Focused string `json:"focused"` // Pane name.
}

LayoutInfo describes the current TUI layout.

type LiveInfo added in v1.13.0

type LiveInfo struct {
	Pinned map[string]int `json:"pinned"` // Agent name -> slot index (0-based).
	Slots  []string       `json:"slots"`  // Current agent name per slot.
}

LiveInfo describes live mode state: which agents are pinned and the current slot assignments. Sent only when layout mode is "live".

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

type PaneLister interface {
	AllPanes() ([]PaneInfo, bool)
}

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"`
	Pinned   bool   `json:"pinned,omitempty"` // True if pinned in live mode.
	BeadID   string `json:"bead_id,omitempty"`
	Order    int    `json:"order"`
	Cols     int    `json:"cols"` // Terminal width in columns (from VT emulator).
	Rows     int    `json:"rows"` // Terminal height in rows (from VT emulator).
}

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 PinToggler added in v1.13.0

type PinToggler interface {
	TogglePin(paneName string) (pinned bool, ok bool)
}

PinToggler toggles the pinned state of a pane in live mode. Returns the new pinned state and true on success, or false if the pane is not found or live mode is not active.

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, pinToggler PinToggler, 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

func (s *Server) Addr() string

Addr returns the address the server is bound to. Only meaningful after Start has been called (and the listener is active).

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully stops the server.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start begins listening and serving. It blocks until the server is shut down or a fatal listen error occurs. The returned error is nil on clean shutdown (via Shutdown) and non-nil on listen failure.

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"`
	Live    *LiveInfo   `json:"live,omitempty"` // Non-nil only in live mode.
}

StateSnapshot is the JSON payload sent over /ws/state. It combines layout information with per-agent status for the web companion SPA.

Jump to

Keyboard shortcuts

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