ui

package
v0.0.0-...-de45444 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ColorPrimary   = lipgloss.Color("#7C3AED") // purple
	ColorSecondary = lipgloss.Color("#6366F1") // indigo
	ColorAccent    = lipgloss.Color("#22D3EE") // cyan
	ColorSuccess   = lipgloss.Color("#34D399") // green
	ColorWarning   = lipgloss.Color("#FBBF24") // amber
	ColorError     = lipgloss.Color("#F87171") // red
	ColorMuted     = lipgloss.Color("#6B7280") // gray
	ColorText      = lipgloss.Color("#E5E7EB") // light gray
	ColorBg        = lipgloss.Color("#111827") // dark bg
)

Color palette.

View Source
var (
	StyleTitle = lipgloss.NewStyle().
				Bold(true).
				Foreground(ColorPrimary).
				MarginBottom(1)

	StyleSubtle = lipgloss.NewStyle().
				Foreground(ColorMuted)

	StyleAccent = lipgloss.NewStyle().
				Foreground(ColorAccent)

	StyleSuccess = lipgloss.NewStyle().
					Foreground(ColorSuccess)

	StyleError = lipgloss.NewStyle().
				Foreground(ColorError)

	StyleBorder = lipgloss.NewStyle().
				Border(lipgloss.RoundedBorder()).
				BorderForeground(ColorMuted).
				Padding(0, 1)

	StyleStatusBar = lipgloss.NewStyle().
					Foreground(ColorText).
					Background(lipgloss.Color("#1F2937")).
					Padding(0, 1)

	StyleKey = lipgloss.NewStyle().
				Foreground(ColorAccent).
				Bold(true)

	StyleKeyDesc = lipgloss.NewStyle().
					Foreground(ColorMuted)

	StyleSelected = lipgloss.NewStyle().
					Foreground(ColorPrimary).
					Bold(true)
)

Common styles.

Functions

This section is empty.

Types

type App

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

App is the root Bubble Tea model.

func NewApp

func NewApp(backend Backend, tap *uilog.Tap) App

NewApp creates the root TUI model. tap is used to surface the most recent daemon log line above the status bar; pass a discard-sink tap if there's no local daemon to log.

func (App) Init

func (a App) Init() tea.Cmd

Init starts async identity loading and event subscription.

func (App) Update

func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles all messages.

func (App) View

func (a App) View() string

View renders the current screen plus the status bar.

type Backend

type Backend interface {
	GetIdentity(ctx context.Context) (*IdentityInfo, error)
	GetStatus(ctx context.Context) (*StatusInfo, error)
	GetDebugInfo(ctx context.Context) (*DebugInfo, error)
	ListContacts(ctx context.Context) ([]*contacts.Contact, error)
	// ListPeers returns the unified peers list: saved contacts ∪ peers with
	// live/in-flight connections, one entry per address, sorted by address.
	// Inbound-only non-contacts appear unsaved (ADR-0004).
	ListPeers(ctx context.Context) ([]PeerInfo, error)
	AddContact(ctx context.Context, address, alias string, pubKey []byte) error
	RemoveContact(ctx context.Context, address string) error
	Connect(ctx context.Context, address string) (accepted bool, msg string, err error)
	// Disconnect tears down every live path to a peer (direct and/or Tor).
	// The contact entry, if any, is untouched.
	Disconnect(ctx context.Context, address string) error
	AcceptConnection(ctx context.Context, address string) error
	RejectConnection(ctx context.Context, address string) error
	SendMessage(ctx context.Context, address, text string) (messageID string, err error)
	// InvokeCommand runs a slash-command for a conversation (daemon built-in
	// and/or the active service, per the daemon's augment dispatch) and STREAMS
	// the reply legs: the instant built-in line, then the service reply (or a
	// timeout) when it lands. The channel closes when the dispatch completes.
	// Commands never go through the chat send path — they are control-plane, not
	// conversation.
	InvokeCommand(ctx context.Context, address, name, args string) (<-chan CommandLeg, error)
	// ListCommands returns the commands available in a conversation (built-ins +
	// the service's declared set, deduped) for /-autocomplete.
	ListCommands(ctx context.Context, address string) ([]CommandSpecInfo, error)
	GetMessages(ctx context.Context, address string, limit int) ([]ChatMessageInfo, error)
	DeleteMessage(ctx context.Context, address, messageID string) error
	ClearConversation(ctx context.Context, address string) error
	SendFile(ctx context.Context, address, filePath string) (<-chan FileProgress, error)
	AcceptFile(ctx context.Context, transferID, savePath string) error
	RejectFile(ctx context.Context, transferID string) error
	CancelTransfer(ctx context.Context, transferID string) error
	AddNode(ctx context.Context, onionAddr string) (peersFound int, err error)
	Subscribe(ctx context.Context) (<-chan node.Event, error)
	Close() error
}

Backend abstracts daemon access so the TUI works identically whether running in-process or attached to a remote daemon.

type ChatMessageInfo

type ChatMessageInfo struct {
	ID       string
	From     string
	To       string
	Text     string
	SentAt   time.Time
	Acked    bool
	Outgoing bool // true = sent by this node
}

ChatMessageInfo is a stored chat message surfaced to the TUI. It is the backend-agnostic shape of internal/chat.Message: DirectBackend reads it from the in-process history, GRPCBackend from the GetChatHistory RPC.

type CommandLeg

type CommandLeg struct {
	Leg   string
	Text  string
	Ok    bool
	Error string
}

CommandLeg is one streamed leg of an invoked slash-command's reply (E3): the instant daemon built-in line, the service reply when it lands, or a daemon- rendered timeout. Leg is "builtin" | "service" | "timeout". Error carries a transport/stream failure (empty on normal legs) so the UI can render it.

type CommandSpecInfo

type CommandSpecInfo struct {
	Name        string
	Description string
	Usage       string
}

CommandSpecInfo is one slash-command available in a conversation — a daemon built-in or a service-declared command, as returned by the ListServiceCommands discovery RPC. The TUI uses it to drive /-autocomplete.

type DebugConnection

type DebugConnection struct {
	Address string
	State   string
	Error   string
}

DebugConnection represents a connection state.

type DebugInfo

type DebugInfo struct {
	RTSize      int
	RTPeers     []DebugPeer
	Connections []DebugConnection
	OnionAddr   string
	// Services lists the currently-registered services on this daemon, in
	// name order. W3 #a137ce40: surfaced in `ensemble debug` so squatting
	// is one call away from being visible.
	Services []DebugService
}

DebugInfo holds diagnostic information for the Network screen and the `ensemble debug` CLI (both sourced from the GetDebugInfo RPC).

type DebugPeer

type DebugPeer struct {
	Address   string
	OnionAddr string
	LastSeen  int64 // Unix millis
}

DebugPeer represents a peer in the routing table.

type DebugService

type DebugService struct {
	Name      string
	Address   string
	OnionAddr string
}

DebugService describes one registered service for the debug surface.

type DirectBackend

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

DirectBackend wraps a node.Node for in-process TUI access (no serialization).

func NewDirectBackend

func NewDirectBackend(n directNode, history *chat.History) *DirectBackend

NewDirectBackend creates a backend that talks to the node directly. history is the daemon's chat message store (nil-safe — chat history methods degrade to empty/no-op when it's absent).

func (*DirectBackend) AcceptConnection

func (b *DirectBackend) AcceptConnection(_ context.Context, addr string) error

func (*DirectBackend) AcceptFile

func (b *DirectBackend) AcceptFile(_ context.Context, transferID, savePath string) error

func (*DirectBackend) AddContact

func (b *DirectBackend) AddContact(_ context.Context, addr, alias string, pubKey []byte) error

func (*DirectBackend) AddNode

func (b *DirectBackend) AddNode(ctx context.Context, onionAddr string) (int, error)

func (*DirectBackend) CancelTransfer

func (b *DirectBackend) CancelTransfer(_ context.Context, transferID string) error

func (*DirectBackend) ClearConversation

func (b *DirectBackend) ClearConversation(_ context.Context, addr string) error

func (*DirectBackend) Close

func (b *DirectBackend) Close() error

func (*DirectBackend) Connect

func (b *DirectBackend) Connect(ctx context.Context, addr string) (bool, string, error)

func (*DirectBackend) DeleteMessage

func (b *DirectBackend) DeleteMessage(_ context.Context, addr, messageID string) error

func (*DirectBackend) Disconnect

func (b *DirectBackend) Disconnect(_ context.Context, addr string) error

func (*DirectBackend) GetDebugInfo

func (b *DirectBackend) GetDebugInfo(_ context.Context) (*DebugInfo, error)

func (*DirectBackend) GetIdentity

func (b *DirectBackend) GetIdentity(_ context.Context) (*IdentityInfo, error)

func (*DirectBackend) GetMessages

func (b *DirectBackend) GetMessages(_ context.Context, addr string, limit int) ([]ChatMessageInfo, error)

func (*DirectBackend) GetStatus

func (b *DirectBackend) GetStatus(_ context.Context) (*StatusInfo, error)

func (*DirectBackend) InvokeCommand

func (b *DirectBackend) InvokeCommand(ctx context.Context, addr, name, args string) (<-chan CommandLeg, error)

func (*DirectBackend) ListCommands

func (b *DirectBackend) ListCommands(ctx context.Context, addr string) ([]CommandSpecInfo, error)

func (*DirectBackend) ListContacts

func (b *DirectBackend) ListContacts(_ context.Context) ([]*contacts.Contact, error)

func (*DirectBackend) ListPeers

func (b *DirectBackend) ListPeers(_ context.Context) ([]PeerInfo, error)

func (*DirectBackend) RejectConnection

func (b *DirectBackend) RejectConnection(_ context.Context, addr string) error

func (*DirectBackend) RejectFile

func (b *DirectBackend) RejectFile(_ context.Context, transferID string) error

func (*DirectBackend) RemoveContact

func (b *DirectBackend) RemoveContact(_ context.Context, addr string) error

func (*DirectBackend) SendFile

func (b *DirectBackend) SendFile(ctx context.Context, addr, filePath string) (<-chan FileProgress, error)

func (*DirectBackend) SendMessage

func (b *DirectBackend) SendMessage(ctx context.Context, addr, text string) (string, error)

func (*DirectBackend) SetCommandInvoker

func (b *DirectBackend) SetCommandInvoker(c commandInvoker)

SetCommandInvoker wires the in-process command seam (the daemon's *api.Server) so the embedded TUI can run slash-commands and list them. Optional: without it, InvokeCommand/ListCommands degrade to a clear "not available" error / the empty set. Call once after construction.

func (*DirectBackend) Subscribe

func (b *DirectBackend) Subscribe(ctx context.Context) (<-chan node.Event, error)

type FileProgress

type FileProgress struct {
	TransferID string
	Filename   string
	TotalBytes uint64
	SentBytes  uint64
	Percent    float32
	Complete   bool
	Error      string
}

FileProgress reports file transfer progress.

type GRPCBackend

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

GRPCBackend wraps a gRPC client for attach mode (TUI → remote daemon).

func NewGRPCBackend

func NewGRPCBackend(target string, privKey ed25519.PrivateKey, options ...GRPCOption) (*GRPCBackend, error)

NewGRPCBackend dials the given target and returns a gRPC-backed Backend. For a Unix socket, use "unix:///path/to/socket". privKey is optional — if non-nil, each RPC is signed with this Ed25519 key. By default the connection is plaintext h2c. Pass WithTLS() or WithTLSInsecureSkipVerify() to wrap in TLS (e.g. when going via an HTTPS ingress).

func (*GRPCBackend) AcceptConnection

func (b *GRPCBackend) AcceptConnection(ctx context.Context, address string) error

func (*GRPCBackend) AcceptFile

func (b *GRPCBackend) AcceptFile(ctx context.Context, transferID, savePath string) error

func (*GRPCBackend) AddContact

func (b *GRPCBackend) AddContact(ctx context.Context, address, alias string, pubKey []byte) error

func (*GRPCBackend) AddNode

func (b *GRPCBackend) AddNode(ctx context.Context, onionAddr string) (int, error)

func (*GRPCBackend) CancelTransfer

func (b *GRPCBackend) CancelTransfer(ctx context.Context, transferID string) error

CancelTransfer aborts an in-flight transfer (send or receive) over the attach (gRPC) backend via the CancelTransfer RPC.

func (*GRPCBackend) ClearConversation

func (b *GRPCBackend) ClearConversation(ctx context.Context, address string) error

func (*GRPCBackend) Close

func (b *GRPCBackend) Close() error

func (*GRPCBackend) Connect

func (b *GRPCBackend) Connect(ctx context.Context, address string) (bool, string, error)

func (*GRPCBackend) DeleteMessage

func (b *GRPCBackend) DeleteMessage(ctx context.Context, address, messageID string) error

func (*GRPCBackend) Disconnect

func (b *GRPCBackend) Disconnect(ctx context.Context, address string) error

func (*GRPCBackend) GetDebugInfo

func (b *GRPCBackend) GetDebugInfo(ctx context.Context) (*DebugInfo, error)

func (*GRPCBackend) GetIdentity

func (b *GRPCBackend) GetIdentity(ctx context.Context) (*IdentityInfo, error)

func (*GRPCBackend) GetMessages

func (b *GRPCBackend) GetMessages(ctx context.Context, address string, limit int) ([]ChatMessageInfo, error)

func (*GRPCBackend) GetStatus

func (b *GRPCBackend) GetStatus(ctx context.Context) (*StatusInfo, error)

func (*GRPCBackend) InvokeCommand

func (b *GRPCBackend) InvokeCommand(ctx context.Context, address, name, args string) (<-chan CommandLeg, error)

func (*GRPCBackend) ListCommands

func (b *GRPCBackend) ListCommands(ctx context.Context, address string) ([]CommandSpecInfo, error)

func (*GRPCBackend) ListContacts

func (b *GRPCBackend) ListContacts(ctx context.Context) ([]*contacts.Contact, error)

func (*GRPCBackend) ListPeers

func (b *GRPCBackend) ListPeers(ctx context.Context) ([]PeerInfo, error)

func (*GRPCBackend) RejectConnection

func (b *GRPCBackend) RejectConnection(ctx context.Context, address string) error

func (*GRPCBackend) RejectFile

func (b *GRPCBackend) RejectFile(ctx context.Context, transferID string) error

func (*GRPCBackend) RemoveContact

func (b *GRPCBackend) RemoveContact(ctx context.Context, address string) error

func (*GRPCBackend) SendFile

func (b *GRPCBackend) SendFile(ctx context.Context, address, filePath string) (<-chan FileProgress, error)

func (*GRPCBackend) SendMessage

func (b *GRPCBackend) SendMessage(ctx context.Context, address, text string) (string, error)

func (*GRPCBackend) Subscribe

func (b *GRPCBackend) Subscribe(ctx context.Context) (<-chan node.Event, error)

type GRPCOption

type GRPCOption func(*grpcOpts)

GRPCOption configures NewGRPCBackend.

func WithTLS

func WithTLS() GRPCOption

WithTLS enables TLS with system root CAs.

func WithTLSInsecureSkipVerify

func WithTLSInsecureSkipVerify() GRPCOption

WithTLSInsecureSkipVerify enables TLS but does not verify the server certificate. Useful for LAN deployments behind a private CA without distributing the CA cert.

type IdentityInfo

type IdentityInfo struct {
	Address   string
	PublicKey []byte
}

IdentityInfo holds the node's address and public key.

type KeyMap

type KeyMap struct {
	Quit       key.Binding
	Back       key.Binding
	Up         key.Binding
	Down       key.Binding
	AddContact key.Binding
	Settings   key.Binding
	Enter      key.Binding
}

KeyMap holds all key bindings for the TUI.

func DefaultKeyMap

func DefaultKeyMap() KeyMap

DefaultKeyMap returns the default key bindings.

type PeerInfo

type PeerInfo struct {
	Address string
	Alias   string // empty when unsaved
	Saved   bool   // true when in the contact store
	State   string // "none" | "connecting" | "direct" | "tor" | "failed"
	Online  bool   // a live data path exists (State direct or tor)
}

PeerInfo is one row of the unified peers list (ADR-0004): a peer that is a saved contact, has a live or in-flight connection, or both. The home screen renders these directly — badges come from Saved/State/Online.

type Screen

type Screen int

Screen identifies the current TUI screen.

const (
	ScreenSplash Screen = iota
	ScreenHome
	ScreenSettings
	ScreenAddContact
	ScreenConnPrompt
	ScreenChat
	ScreenFilePicker
	ScreenFileOffer
	ScreenTransfer
	ScreenAddNode
	ScreenNetwork
	ScreenLogs
)

type StatusInfo

type StatusInfo struct {
	TorState  string
	PeerCount int32
	OnionAddr string
	UptimeMs  int64
	RTSize    int32
}

StatusInfo holds the node's current status.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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