server

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureLogging

func ConfigureLogging()

ConfigureLogging sets the log package to use RFC3339 UTC timestamps, matching the format used by RequestLogger.

func GetStaticHandler

func GetStaticHandler() http.Handler

GetStaticHandler returns an http.Handler for the embedded static files.

func RequestLogger

func RequestLogger(next http.Handler) http.Handler

RequestLogger wraps an http.Handler and logs each request as a comma-separated line:

timestamp,method,path,status,duration_ms,client

Types

type ArtifactResponse

type ArtifactResponse struct {
	ArtifactType string    `json:"artifact_type"`
	Filename     string    `json:"filename"`
	UpdatedAt    time.Time `json:"updated_at"`
	UpdatedBy    string    `json:"updated_by"`
}

type CommentResponse

type CommentResponse struct {
	ID        string    `json:"id"`
	Text      string    `json:"text"`
	CreatedBy string    `json:"created_by"`
	CreatedAt time.Time `json:"created_at"`
}

type DependencyResponse

type DependencyResponse struct {
	SourceID string `json:"source_id"`
	TargetID string `json:"target_id"`
	Kind     string `json:"kind"`
}

type IssueResponse

type IssueResponse struct {
	ID               string               `json:"id"`
	Title            string               `json:"title"`
	Description      string               `json:"description"`
	Status           string               `json:"status"`
	IsInferred       bool                 `json:"is_inferred,omitempty"`
	ParentID         string               `json:"parent_id,omitempty"`
	Estimate         int                  `json:"estimate"`
	Priority         int                  `json:"priority"`
	SortOrder        string               `json:"sort_order"`
	Assignee         string               `json:"assignee,omitempty"`
	CycleID          string               `json:"cycle_id,omitempty"`
	EffectiveCycleID string               `json:"effective_cycle_id,omitempty"`
	BranchStats      *model.BranchStats   `json:"branch_stats,omitempty"`
	Labels           []string             `json:"labels,omitempty"`
	Dependencies     []DependencyResponse `json:"dependencies,omitempty"`
	Artifacts        []ArtifactResponse   `json:"artifacts,omitempty"`
	Comments         []CommentResponse    `json:"comments,omitempty"`
	CreatedAt        time.Time            `json:"created_at"`
	CreatedBy        string               `json:"created_by"`
	UpdatedAt        time.Time            `json:"updated_at"`
	IsPending        bool                 `json:"is_pending"`
}

type PendingEventEntry

type PendingEventEntry struct {
	IssueID   string      `json:"issue_id"`
	Type      string      `json:"type"`
	Payload   interface{} `json:"payload,omitempty"`
	CreatedAt time.Time   `json:"created_at"`
}

type PendingResponse

type PendingResponse struct {
	HasPending bool                `json:"has_pending"`
	Events     []PendingEventEntry `json:"events"`
	IssueIDs   []string            `json:"issue_ids"`
}

type SSEEvent

type SSEEvent struct {
	Type    string `json:"type"`
	IssueID string `json:"issue_id"`
}

SSEEvent is a lightweight notification sent to connected clients.

type SSEHub

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

SSEHub manages connected SSE clients and broadcasts events.

func NewSSEHub

func NewSSEHub() *SSEHub

NewSSEHub creates a new hub.

func (*SSEHub) Broadcast

func (h *SSEHub) Broadcast(evt SSEEvent)

Broadcast sends an event to all connected clients.

func (*SSEHub) ClientCount

func (h *SSEHub) ClientCount() int

ClientCount returns the number of connected clients.

type Server

type Server struct {
	Config   *config.Config
	Port     int
	DevMode  bool
	DevPort  int
	Headless bool

	// Auth fields — nil when auth is disabled (local board mode).
	NonceStore     *auth.NonceStore
	AuthorizedKeys *auth.AuthorizedKeys
	SigningKey     ed25519.PrivateKey
	VerifyKey      ed25519.PublicKey

	// MCP handler — set externally for xpo serve mode.
	MCPHandler http.Handler

	// Proxy mode — when set, /api/* routes are reverse-proxied to
	// the remote server with the bearer token injected.
	ProxyURL   string
	ProxyToken string

	// SSE hub for real-time event notifications.
	SSEHub *SSEHub
	// contains filtered or unexported fields
}

Server holds the state for the xpo web server.

func NewServer

func NewServer(cfg *config.Config, port int, devMode bool, devPort int) *Server

NewServer creates a new Server instance.

func (*Server) AddPendingEvent

func (s *Server) AddPendingEvent(evt model.Event)

AddPendingEvent adds an event to the pending buffer.

func (*Server) Bind

func (s *Server) Bind() (net.Listener, error)

Bind acquires a TCP listener on s.Port, falling back to the next free port if that one is taken. The actual port bound is written back to s.Port.

func (*Server) BroadcastEvent

func (s *Server) BroadcastEvent(eventType, issueID string)

BroadcastEvent is the exported form of broadcastEvent for use by external callers (e.g. MCP tool handlers that need to push SSE notifications).

func (*Server) DiscardPending

func (s *Server) DiscardPending()

DiscardPending clears all pending events.

func (*Server) GetAllEvents

func (s *Server) GetAllEvents() ([]model.Event, error)

GetAllEvents returns all persisted events plus pending events. The persisted events are cached and only re-read when the database file has changed on disk.

func (*Server) GetPendingCount

func (s *Server) GetPendingCount() int

GetPendingCount returns the number of pending (unsaved) events.

func (*Server) GetProjectedIssues

func (s *Server) GetProjectedIssues() (map[string]*model.Issue, error)

GetProjectedIssues returns all issues with pending events applied. Results are cached and recomputed only when the on-disk database or the pending-events buffer has changed.

func (*Server) SaveAndSync

func (s *Server) SaveAndSync(commitMessage string) error

SaveAndSync persists pending events to storage and optionally commits to git.

func (*Server) ServeOn

func (s *Server) ServeOn(l net.Listener) error

ServeOn serves HTTP on the provided listener. Use after Bind.

func (*Server) SetupRoutes

func (s *Server) SetupRoutes() *http.ServeMux

setupRoutes configures the HTTP routes for the server.

func (*Server) Start

func (s *Server) Start() error

Start binds and serves in one step. Equivalent to Bind followed by ServeOn.

func (*Server) WatchDB

func (s *Server) WatchDB()

WatchDB watches issues.db for external modifications and broadcasts an SSE event so the GUI refreshes immediately.

func (*Server) WatchGitRefs

func (s *Server) WatchGitRefs()

WatchGitRefs watches .git/refs/heads/ (recursively) and .git/packed-refs for changes. When git refs change (new commit, new/deleted branch, gc), the cached issues are invalidated and an SSE update is broadcast so the GUI refreshes branch stats immediately.

Jump to

Keyboard shortcuts

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