Documentation
¶
Overview ¶
ABOUTME: Manages server state files so CLI commands can detect ABOUTME: a running agentsview server instance.
Index ¶
- func FindAvailablePort(host string, start int) int
- func IsServerActive(dataDir string) bool
- func IsStartupLocked(dataDir string) bool
- func RemoveStartupLock(dataDir string)
- func RemoveStateFile(dataDir string, port int)
- func WaitForStartup(dataDir string, timeout time.Duration) bool
- func WriteStartupLock(dataDir string)
- func WriteStateFile(dataDir string, host string, port int, version string) (string, error)
- type Opener
- type Option
- func WithBaseContext(ctx context.Context) Option
- func WithBasePath(path string) Option
- func WithDataDir(dir string) Option
- func WithGenerateFunc(f insight.GenerateFunc) Option
- func WithGenerateStreamFunc(f insight.GenerateStreamFunc) Option
- func WithUpdateChecker(f UpdateCheckFunc) Option
- func WithVersion(v VersionInfo) Option
- type SSEStream
- type Server
- type StateFile
- type UpdateCheckFunc
- type VersionInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindAvailablePort ¶
FindAvailablePort finds an available port starting from the given port, binding to the specified host.
func IsServerActive ¶ added in v0.15.0
IsServerActive reports whether a server process is managing the database in dataDir. Returns true if:
- a state file with a live PID exists (even if the port probe fails due to a transient issue), or
- a startup lock with a live PID exists (server is still syncing / binding its port).
This is the check CLI commands should use to decide whether to skip on-demand sync.
func IsStartupLocked ¶ added in v0.15.0
IsStartupLocked reports whether the startup lock file exists with a live PID. Callers use this to distinguish "server is starting up" from "server is running but TCP probe failed".
func RemoveStartupLock ¶ added in v0.15.0
func RemoveStartupLock(dataDir string)
RemoveStartupLock removes the startup lock file for the current process.
func RemoveStateFile ¶ added in v0.15.0
RemoveStateFile removes the state file for the given port.
func WaitForStartup ¶ added in v0.15.0
WaitForStartup polls until the startup lock clears or a running server is detected, up to the given timeout. Returns true if a server became ready, false on timeout.
func WriteStartupLock ¶ added in v0.15.0
func WriteStartupLock(dataDir string)
WriteStartupLock creates a lock file indicating a server is starting up (syncing, binding port). Each server uses a PID-specific filename so concurrent startups on different ports don't clobber each other. Written via a temp file and atomic rename to prevent partial reads.
func WriteStateFile ¶ added in v0.15.0
WriteStateFile writes a state file to dataDir for the running server. Returns the path written. StartedAt is set to the actual process creation time so it passes processStartTime validation even when startup is slow.
Types ¶
type Opener ¶ added in v0.12.0
type Opener struct {
ID string `json:"id"`
Name string `json:"name"`
Kind string `json:"kind"` // "editor", "terminal", "files", "action"
Bin string `json:"bin"`
}
Opener represents an application that can open a project directory.
type Option ¶
type Option func(*Server)
Option configures a Server.
func WithBaseContext ¶ added in v0.13.0
WithBaseContext sets the base context for all incoming HTTP requests. When this context is cancelled, request contexts are also cancelled, causing long-lived handlers (SSE) to exit and unblocking graceful shutdown.
func WithBasePath ¶ added in v0.16.0
WithBasePath sets a URL prefix for reverse-proxy deployments. The path must start with "/" and not end with "/" (e.g. "/agentsview"). When set, the server strips this prefix from incoming requests and injects a <base href> tag into the SPA.
func WithDataDir ¶ added in v0.12.0
WithDataDir sets the data directory used for update caching.
func WithGenerateFunc ¶ added in v0.4.0
func WithGenerateFunc(f insight.GenerateFunc) Option
WithGenerateFunc overrides the insight generation function, allowing tests to substitute a stub. Nil is ignored.
func WithGenerateStreamFunc ¶ added in v0.10.0
func WithGenerateStreamFunc(f insight.GenerateStreamFunc) Option
WithGenerateStreamFunc overrides the streaming insight generation function used by the SSE handler. Nil is ignored.
func WithUpdateChecker ¶ added in v0.12.0
func WithUpdateChecker(f UpdateCheckFunc) Option
WithUpdateChecker overrides the update check function, allowing tests to substitute a deterministic stub.
func WithVersion ¶
func WithVersion(v VersionInfo) Option
WithVersion sets the build-time version metadata.
type SSEStream ¶
type SSEStream struct {
// contains filtered or unexported fields
}
SSEStream manages a Server-Sent Events connection.
func NewSSEStream ¶
func NewSSEStream(w http.ResponseWriter) (*SSEStream, error)
NewSSEStream initializes an SSE connection by setting the required headers and flushing them to the client. Returns an error if the ResponseWriter does not support streaming.
func (*SSEStream) ForceWriteDeadlineNow ¶ added in v0.10.0
func (s *SSEStream) ForceWriteDeadlineNow()
ForceWriteDeadlineNow asks the underlying writer (when supported) to expire write deadlines immediately. This is used during shutdown to unblock stalled writes.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the HTTP server that serves the SPA and REST API.
func (*Server) ListenAndServe ¶
ListenAndServe starts the HTTP server.
func (*Server) SetGithubToken ¶
SetGithubToken updates the GitHub token for testing.
type StateFile ¶ added in v0.15.0
type StateFile struct {
PID int `json:"pid"`
Port int `json:"port"`
Host string `json:"host"`
Version string `json:"version"`
StartedAt string `json:"started_at"`
}
StateFile records a running server instance.
func FindRunningServer ¶ added in v0.15.0
FindRunningServer scans dataDir for server state files and returns the first one whose process is still alive and whose port is accepting connections. Stale state files are cleaned up automatically.
type UpdateCheckFunc ¶ added in v0.12.0
type UpdateCheckFunc func( currentVersion string, forceCheck bool, cacheDir string, ) (*update.UpdateInfo, error)
UpdateCheckFunc is the signature for functions that check for available updates. The default is update.CheckForUpdate.