Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/jaypopat/cf_ai_duet/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The server package provides the SSH server that handles client connections and manages Bubble Tea sessions for the Duet TUI.

Types

Server

Main server struct that manages SSH connections and room state.
type Server struct {
    addr        string
    hostKeyPath string
    roomManager *room.Manager
    logger      *log.Logger
}

Functions

New

Creates a new Duet server instance.
func New(addr, hostKeyPath, workerURL string) *Server
addr
string
required
The address to listen on (e.g., “localhost:2222”)
hostKeyPath
string
required
Path to the SSH host key file
workerURL
string
Optional URL for the AI worker service. If empty, AI features will be disabled
Returns: A configured *Server instance Example:
srv := server.New("localhost:2222", ".ssh/duet_ed25519", "http://localhost:8787")

Start

Starts the SSH server and blocks until shutdown.
func (s *Server) Start() error
Returns: Error if the server fails to start or during shutdown Example:
if err := srv.Start(); err != nil {
    log.Fatal("Server error:", err)
}
Behavior:
  • Starts SSH server with Bubble Tea middleware
  • Listens for OS interrupt signals (SIGINT, SIGTERM)
  • Performs graceful shutdown with 10-second timeout
  • Logs server lifecycle events

Implementation Details

SSH Middleware

The server uses Wish middleware for SSH handling:
  • Bubble Tea Middleware: Manages TUI sessions
  • Logging Middleware: Logs connection events

Session Handling

Each SSH connection:
  1. Extracts username (defaults to “guest”)
  2. Creates a Bubble Tea renderer
  3. Detects terminal type (special handling for xterm-ghostty)
  4. Initializes a UI model with the room manager
  5. Launches in alternate screen mode

Color Profile Detection

if pty.Term == "xterm-ghostty" {
    renderer.SetColorProfile(termenv.TrueColor)
}
The server automatically enables TrueColor for Ghostty terminal.

Build docs developers (and LLMs) love