Help us shape the future of Go! Take the 2026 Go Developer Survey

web

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package web provides an embedded web server that mirrors the rysh TUI in a browser. It connects to the same NATS bus as the TUI, polls workspace snapshots, and pushes them to WebSocket clients. Commands from the browser are published back to NATS so the actor hierarchy processes them identically.

Control-dashboard surface (WS5, design 005 — tasks DB1–DB4).

This file adds the browser control plane on top of the read-only viewer in server.go:

  • DB1 channel operations → MsgHumanoidChannelStart/Stop on humanoid.{name}.inbox (same messages ##humanoid channel start/stop send)
  • DB2 pairing operations → MsgChannelPairApprove / MsgChannelAllow / MsgChannelPairList on humanoid.{name}.pairing (same subject the terminal ##humanoid pair commands ride, WS3 / design 003 §4.4), plus a live relay of MsgChannelPairRequest/QR/Status/ListReply into the WS hub
  • DB3 humanoid operations → MsgHumanoidActivate/Deactivate on the registry inbox and MsgHumanoidSetGovernance / MsgHumanoidSetReplyMode on humanoid.{name}.inbox
  • DB4 control gating → every MUTATING endpoint/action requires control mode; read/list endpoints stay available. Control mode is enabled by the RYSH_WEB_CONTROL environment variable (1/true/yes/on) read in NewServer — chosen as the least-invasive wiring so the two existing WorkspaceActor NewServer call sites need no changes — or programmatically via SetControl (tests, future `rysh web --control`). When control is enabled the HTTP listener is forced onto 127.0.0.1.

Terminal and web drive the SAME typed messages on the SAME subjects, so the two fronts cannot diverge (design 003 §4.4 / 005 G5).

Index

Constants

View Source
const DefaultHost = "127.0.0.1"

DefaultHost is the bind address used when none is configured: loopback, so a rysh web session is reachable only from the machine running the daemon unless the operator explicitly opts into a wider bind (`--bind 0.0.0.0`, web host, RYSH_WEB_HOST). The access token is a guard, not a perimeter — binding the default surface to a LAN-visible interface is a decision the operator must make deliberately.

Variables

This section is empty.

Functions

func GenerateToken

func GenerateToken() string

GenerateToken returns a URL-safe random access token (192 bits).

Types

type Hub

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

Hub maintains the set of active WebSocket clients and broadcasts messages to all of them. Modelled after the Gorilla WebSocket chat example.

type Server

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

Server is the web UI server. It serves static assets over HTTP and maintains WebSocket connections to push real-time workspace snapshots to browsers.

func NewServer

func NewServer(port int, sessionName string, pub *msg.NATSPublisher, nc *nats.Conn, codecs *msg.CodecRegistry) *Server

NewServer creates a new web UI server.

func (*Server) AuthEnabled

func (s *Server) AuthEnabled() bool

AuthEnabled reports whether an access token is required.

func (*Server) AuthToken

func (s *Server) AuthToken() string

AuthToken returns the configured access token, or "" when auth is disabled. Used by ##rysh web status / ##rysh web token to surface the token on request.

func (*Server) ControlEnabled

func (s *Server) ControlEnabled() bool

ControlEnabled reports whether control mode is enabled.

func (*Server) Host

func (s *Server) Host() string

Host returns the configured bind IP ("" = default).

func (*Server) IsRunning

func (s *Server) IsRunning() bool

IsRunning reports whether the server is currently running.

func (*Server) Port

func (s *Server) Port() int

Port returns the configured port number.

func (*Server) SetAuthToken

func (s *Server) SetAuthToken(token string)

SetAuthToken sets the access token required to reach the web UI. When set, every request except /health must present the token — via the ?token= query on first load, after which a cookie authorizes the follow-up asset and WebSocket requests. Empty ⇒ no auth (loopback-only default). Call before Start.

func (*Server) SetClientCountListener

func (s *Server) SetClientCountListener(fn func(n int))

SetClientCountListener registers fn to receive the live WebSocket-client count on every transition. Must be called before Start.

func (*Server) SetControl

func (s *Server) SetControl(enabled bool)

SetControl enables or disables control mode. Must be called before Start: the listen address is computed at Start time and mutating endpoints consult the flag per-request under the server mutex.

func (*Server) SetFSBrowser

func (s *Server) SetFSBrowser(fn func(op, paneID, path string, offset, length int64) (any, string, string))

SetFSBrowser injects the file-browse implementation. Call before Start.

func (*Server) SetHost

func (s *Server) SetHost(host string)

SetHost pins the HTTP listener to a specific bind IP — 0.0.0.0 to expose the UI on every interface, a dedicated loopback alias like 127.0.100.1 fronted by a reverse proxy, and so on. Empty selects DefaultHost (loopback). Must be called before Start.

func (*Server) Start

func (s *Server) Start() error

Start launches the web server in background goroutines.

func (*Server) Stop

func (s *Server) Stop() error

Stop gracefully shuts down the web server.

Jump to

Keyboard shortcuts

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