server

package
v0.36.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 58 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PostHogAPIKey  = "phc_CGzEmfPURHyNWrG49yNJA7wY5io8URFu3sazRYTAXw6Z"
	PostHogAPIHost = "https://app.posthog.com"
)

Hardcoded PostHog project credentials. These are baked into the binary — users have no control over analytics configuration.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options added in v0.36.0

type Options struct {
	// NoBrowser suppresses opening the operator's browser on start. The worker
	// spawns one server per worktree; none of them should open a tab.
	NoBrowser bool
	// Loopback binds the listener to 127.0.0.1 instead of all interfaces. The
	// worker's tunnel is the only remote path to a hosted server, so a hosted
	// server must not also be reachable on the machine's LAN address.
	Loopback bool
	// OnListen, when set, is called once with the ACTUAL bound port right after
	// the listener is established — which can differ from the requested port when
	// that one was busy and the bind loop walked past it. The CLI uses it to
	// record a project's port; leave nil to skip (worker-spawned servers do).
	OnListen func(port int)
}

Options tunes a server's runtime behavior without changing what it serves. The zero value reproduces the interactive `ogcode serve` behavior.

type PostHogClient added in v0.14.0

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

PostHogClient captures server-side analytics events to a PostHog project. Events are sent via the /capture REST endpoint — no SDK dependency required. All calls are fire-and-forget with a bounded worker goroutine so they never block request handlers.

func NewPostHogClient added in v0.14.0

func NewPostHogClient(apiKey, host string) *PostHogClient

NewPostHogClient returns an active client that starts a background worker. Returns nil if apiKey is empty.

func (*PostHogClient) Capture added in v0.14.0

func (c *PostHogClient) Capture(event, distinctID string, props map[string]any)

Capture enqueues an event. Properties are merged with the default server-side properties (os, arch, version). The call is non-blocking — if the queue is full the event is dropped silently.

func (*PostHogClient) Stop added in v0.14.0

func (c *PostHogClient) Stop()

Stop drains the queue and shuts down the worker.

type Server

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

func New

func New(port int, dir string, mode ServerMode) *Server

func NewWithOptions added in v0.36.0

func NewWithOptions(port int, dir string, mode ServerMode, opts Options) *Server

func (*Server) Guidance added in v0.36.0

func (s *Server) Guidance(id session.SessionID, content string, cancelTool bool) error

Guidance injects mid-loop guidance into a running loop: the text is queued on the loop's control and, when cancelTool is set, the in-flight LLM stream and tool execution are cancelled so the loop advances to the next iteration and drains the queue. PushGuidance runs before CancelStream/CancelTool — ordering matters, see handleGuidance.

It returns an error when no loop is running for the session.

func (*Server) HostSession added in v0.36.0

func (s *Server) HostSession(id session.SessionID, dir, prompt, agentName string, viewportWidth, viewportHeight int) (stop func(), existed bool, err error)

HostSession hosts an agent loop for a session the master minted, writing the session, message and part rows this server's store needs to run it.

It is the in-process equivalent of what a worker used to do by hand (createSessionRows + RunLoop under LoopControl + permission gating) and of what the UI does over HTTP (create session + prompt). One path, not three: the loop it starts is the same startSessionLoop the prompt and resume handlers use, so hosted sessions are gated, cancellable and guided exactly like sessions driven from a browser.

The returned stop func cancels the loop (abort semantics — it does not sweep orphaned assistant messages or tool parts; the old worker cancel did not either). existed reports whether the session row was already present, which makes re-delivery of the same StartAgent command idempotent.

func (*Server) Port added in v0.36.0

func (s *Server) Port() int

Port reports the port the server actually bound. Meaningful only after Serve has bound the listener (the caller's Serve goroutine is running); callers that passed port 0 read the kernel-assigned value here to dial the tunnel.

func (*Server) ReplyPermission added in v0.36.0

func (s *Server) ReplyPermission(id session.SessionID, permID, response string) bool

ReplyPermission delivers a permission reply to the waiting agent loop. It reports false when the request is unknown (already answered, cancelled, or expired).

func (*Server) Serve added in v0.36.0

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

Serve runs the HTTP server until ctx is cancelled, a SIGINT/SIGTERM arrives, or Stop is called — then shuts down gracefully (in-flight requests drained within the 10s shutdown timeout, MCP torn down, DBs closed) and returns. The signal path keeps standalone `ogcode serve` behavior unchanged; a ctx-driven caller (the worker hosting one server per worktree) cancels its ctx per worktree and never has signals racing across N servers. Serve must be called once per Server.

func (*Server) SessionPort added in v0.36.0

func (s *Server) SessionPort() int

SessionPort returns the loopback port the server answers on, or 0 before the listener has bound.

func (*Server) SessionRow added in v0.36.0

func (s *Server) SessionRow(id session.SessionID) (*session.Session, error)

SessionRow returns the session row from this server's own store, or nil when absent. It exists so the worker (and tests) can verify a hosted session landed in the worktree server's DB without reaching into unexported fields.

func (*Server) Stop added in v0.36.0

func (s *Server) Stop()

Stop asks a Serve loop to begin graceful shutdown; Serve then returns once shutdown completes. Safe to call from another goroutine; a no-op when Serve has not started (or has already finished).

func (*Server) SubscribeEvents added in v0.36.0

func (s *Server) SubscribeEvents() (<-chan bus.Event, func())

SubscribeEvents exposes the server's event bus to the worker, which relays hosted-session events to the master. The returned func unsubscribes.

type ServerMode

type ServerMode string

ServerMode determines the operational mode of the server.

const (
	ModeBuild ServerMode = "build"
	ModePlan  ServerMode = "plan"
)

type Theme

type Theme struct {
	Directory    string `json:"directory"`
	PrimaryColor string `json:"primaryColor"` // hex input from user, e.g. "#6366f1"
	Accent       string `json:"accent"`       // --accent
	AccentHover  string `json:"accentHover"`  // --accent-hover
	AccentSoft   string `json:"accentSoft"`   // --accent-soft (rgba)
	AccentRing   string `json:"accentRing"`   // --accent-ring (rgba)
	OnPrimary    string `json:"onPrimary"`    // text color on accent bg
	Glow         string `json:"glow"`         // --glow (rgba, for background accents)
	Tint         string `json:"tint"`         // --tint (rgba, ~5% for sidebar/header)
}

Theme holds a per-directory color palette derived from a user-chosen primary color.

Jump to

Keyboard shortcuts

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