Documentation
¶
Overview ¶
Package server provides the HTTP router serving the API and embedded frontend.
Index ¶
- type AgentConfig
- type AuthConfig
- type CacheSizeStore
- type Config
- type DebugConfig
- type Dependencies
- type DirsConfig
- type FakeCIHook
- type GitHubConfig
- type GitLabConfig
- type GoogleConfig
- type HarnessModels
- type IPGeoConfig
- type ImageRefresh
- func (r *ImageRefresh) Run(ctx context.Context) error
- func (r *ImageRefresh) RunScheduled(ctx context.Context, interval time.Duration) error
- func (r *ImageRefresh) Start(ctx context.Context, userID, runtime string) (v1.ImageRefreshStatus, error)
- func (r *ImageRefresh) Status(userID, runtime string) (v1.ImageRefreshStatus, error)
- type ImageWarmer
- type LLMConfig
- type Router
- type RuntimeConfig
- type VoiceConfig
- type VoiceGatewayConfig
- type VoiceGatewayMode
- type VoiceTokenMode
- type WarningStore
- func (w *WarningStore) ResolveCI(ownerID string, category ci.WarningCategory) error
- func (w *WarningStore) Since(ownerID string, seq uint64) []serverWarning
- func (w *WarningStore) UpdateCI(ownerID string, category ci.WarningCategory, message string, ...) error
- func (w *WarningStore) UpdateRuntimeRestore(failure *taskmgr.ImportError)
- type WebhookHandlers
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentConfig ¶ added in v0.9.2
type AgentConfig struct {
HarnessEnv map[string][]string // per-harness KEY=VALUE env vars for runtime instances
CoreEnv map[string]string // server-level KEY=VALUE env vars from [core.env]
Backends agent.Backends // optional agent backend override for smoke/e2e tests
}
AgentConfig configures coding-agent process environments.
type AuthConfig ¶ added in v0.9.2
type AuthConfig struct {
// ExternalURL is the public base URL (e.g. https://caic.example.com).
// "auto" locks the hostname from the first FQDN request.
ExternalURL string
// TrustedProxies contains direct reverse-proxy address prefixes whose
// Forwarded and X-Forwarded-* origin and client-IP headers may be accepted.
TrustedProxies []string
}
AuthConfig configures public URL state used by OAuth and webhook flows.
func (*AuthConfig) TrustedProxyPrefixes ¶ added in v0.12.0
func (c *AuthConfig) TrustedProxyPrefixes() ([]netip.Prefix, error)
TrustedProxyPrefixes parses the configured trusted reverse-proxy prefixes.
func (*AuthConfig) Validate ¶ added in v0.9.2
func (c *AuthConfig) Validate() error
Validate returns an error if the auth configuration is invalid.
type CacheSizeStore ¶ added in v0.10.1
type CacheSizeStore struct {
// contains filtered or unexported fields
}
CacheSizeStore holds periodic well-known cache size snapshots. It is constructed and refreshed by internal/app; HTTP handlers only read snapshots.
func NewCacheSizeStore ¶ added in v0.10.1
func NewCacheSizeStore(log *slog.Logger) *CacheSizeStore
NewCacheSizeStore creates an empty cache size store.
func (*CacheSizeStore) Refresh ¶ added in v0.10.1
func (c *CacheSizeStore) Refresh(ctx context.Context)
Refresh recomputes the well-known cache size snapshot once.
func (*CacheSizeStore) RefreshLoop ¶ added in v0.10.1
func (c *CacheSizeStore) RefreshLoop(ctx context.Context)
RefreshLoop refreshes well-known cache sizes until ctx is cancelled. It is owned by internal/app, which starts it as a background maintenance loop.
func (*CacheSizeStore) Snapshot ¶ added in v0.10.1
func (c *CacheSizeStore) Snapshot() []v1.CacheSize
Snapshot returns the current well-known cache sizes, sorted by name.
type Config ¶
type Config struct {
Dirs DirsConfig
Runtime RuntimeConfig
Agent AgentConfig
LLM LLMConfig
GitHub GitHubConfig
GitLab GitLabConfig
Google GoogleConfig
Auth AuthConfig
Voice VoiceConfig
Debug DebugConfig
IPGeo IPGeoConfig
FakeCI FakeCIHook // optional fake CI simulation hook for smoke/e2e tests
// UsageFetchers replaces auto-detected provider usage fetchers.
// When non-nil, provider auto-detection is skipped entirely.
// App owns these fetchers and closes those that implement io.Closer.
UsageFetchers []usage.ProviderFetcher
}
Config bundles values read once at startup from config.toml, environment variables, and CLI flags, then threaded into the server.
type DebugConfig ¶ added in v0.9.2
type DebugConfig struct {
Pprof bool // expose /debug/pprof/* endpoints
}
DebugConfig configures optional server diagnostics.
type Dependencies ¶ added in v0.9.2
type Dependencies struct {
// PushCacheDir is the configured application cache root for cloned checkouts.
PushCacheDir string
Checkouts *repo.Registry
CheckoutRoot string
RepoStatus *ci.RepoStatusStore
Tailscale bool
Preferences *preferences.Store
AuthStore *auth.Store
SessionSecret []byte
OAuthPrivateKeyPEM []byte
OAuthKeyID string
OAuthIssuer string
OAuthRefreshTokenStorePath string
AuditLogPath string
GitHubOAuth *oauthclient.ProviderConfig
GitLabOAuth *oauthclient.ProviderConfig
GoogleOAuth *oauthclient.ProviderConfig
HostState *auth.HostState
UsageFetchers []usage.ProviderFetcher
UsageRollup *usagedb.Store
VoiceBridge *voicertc.Bridge
VoiceGateway VoiceGatewayConfig
ForgeMgr *forgemgr.Manager
CICache *forgecache.Cache
Runtimes *runtime.Router
TaskMgr *taskmgr.Manager
Provider genai.Provider
IPGeoChecker *ipgeo.Checker
TrustedProxies []netip.Prefix
// App-owned automation services, routed to by HTTP handlers and webhooks.
Bot *bot.Bot
CIService *ci.Service
TaskClient taskCreator // creates tasks for manual CI repair
Warnings *WarningStore
CacheSizes *CacheSizeStore
// Metrics aggregates operation duration observations.
Metrics *metrics.Store
// HarnessModels refreshes coding-agent model inventories.
HarnessModels *HarnessModels
ImageRefresh *ImageRefresh
FakeCI FakeCIHook // optional fake CI simulation hook for smoke/e2e tests
GitHubAllowedUsers []string
GitLabAllowedUsers []string
GoogleAllowedUsers []string
GitHubWebhookSecret []byte
GitLabWebhookSecret []byte
GitHubAppAllowedOwners []string
Pprof bool
}
Dependencies contains already-constructed server dependencies. The caller (internal/app) owns the lifetime of the long-lived automation services (Bot, CIService, and their adapters); the router only routes requests to them.
type DirsConfig ¶ added in v0.9.2
type DirsConfig struct {
ConfigDir string // persistent server state, e.g. ~/.config/caic
CacheDir string // logs and cache files, e.g. ~/.cache/caic
}
DirsConfig contains filesystem paths for persistent server state.
type GitHubConfig ¶ added in v0.9.2
type GitHubConfig struct {
Token string // PAT for GitHub API access
OAuthClientID string // OAuth app client ID
OAuthClientSecret string
OAuthAllowedUsers []string // if set, restricts login to these users; empty allows any
WebhookSecret []byte // HMAC secret; enables POST /webhooks/github
AppID int64 // GitHub App ID; used with AppPrivateKeyPEM
AppPrivateKeyPEM []byte // RSA private key PEM
AppAllowedOwners []string // if set, reject installs from other owners
}
GitHubConfig configures GitHub API, OAuth, webhooks, and App integration.
func (*GitHubConfig) Validate ¶ added in v0.9.2
func (c *GitHubConfig) Validate() error
Validate returns an error if the GitHub configuration is invalid.
type GitLabConfig ¶ added in v0.9.2
type GitLabConfig struct {
Token string // PAT; mutually exclusive with OAuthClientID
OAuthClientID string // OAuth app client ID; mutually exclusive with Token
OAuthClientSecret string
OAuthAllowedUsers []string // if set, restricts login to these users; empty allows any
URL string // default "https://gitlab.com"
WebhookSecret []byte // X-Gitlab-Token secret; enables POST /webhooks/gitlab
}
GitLabConfig configures GitLab API, OAuth, and webhooks.
func (*GitLabConfig) Validate ¶ added in v0.9.2
func (c *GitLabConfig) Validate() error
Validate returns an error if the GitLab configuration is invalid.
type GoogleConfig ¶ added in v0.10.2
type GoogleConfig struct {
OAuthClientID string // OAuth client ID
OAuthClientSecret string // OAuth client secret
OAuthAllowedUsers []string // if set, restricts login to these emails; empty allows any
}
GoogleConfig configures Google Sign-In, an identity-only login provider with no forge backing.
func (*GoogleConfig) Validate ¶ added in v0.10.2
func (c *GoogleConfig) Validate() error
Validate returns an error if the Google configuration is invalid.
type HarnessModels ¶ added in v0.12.0
type HarnessModels struct {
// Log records model refresh progress.
Log *slog.Logger
// CacheDir stores the harness model inventory cache.
CacheDir string
// Router creates temporary runtimes for model discovery.
Router *runtime.Router
// TaskManager owns the configured harness backends.
TaskManager *taskmgr.Manager
// HarnessEnv supplies environment variables to each harness refresh.
HarnessEnv map[string][]string
// contains filtered or unexported fields
}
HarnessModels serializes model-inventory refreshes from startup, cache deletion, and user-triggered refreshes.
func (*HarnessModels) Refresh ¶ added in v0.12.0
Refresh bypasses the cache and updates one harness model inventory.
func (*HarnessModels) RefreshAll ¶ added in v0.12.0
func (r *HarnessModels) RefreshAll(ctx context.Context, force bool)
RefreshAll updates harness model inventories. force bypasses the 24-hour cache.
type IPGeoConfig ¶ added in v0.9.2
type IPGeoConfig struct {
// DB is the path to a MaxMind MMDB file (e.g. GeoLite2-Country.mmdb).
DB string
// Allowlist is a comma-separated list of permitted country codes, CIDRs, and
// named origins: "local", "tailscale", "anthropic", "github", and "openai".
// When set, requests from IPs that do not resolve to an allowed value are
// rejected with 403. Requires DB for country-code tokens.
Allowlist string
}
IPGeoConfig configures optional request geolocation allowlisting.
type ImageRefresh ¶ added in v0.14.0
type ImageRefresh struct {
Log *slog.Logger
Clients map[string]ImageWarmer
Prefs *preferences.Store
// contains filtered or unexported fields
}
ImageRefresh tracks user-requested specialized image rebuilds per runtime.
func (*ImageRefresh) Run ¶ added in v0.14.4
func (r *ImageRefresh) Run(ctx context.Context) error
Run owns requested refreshes until the application stops.
func (*ImageRefresh) RunScheduled ¶ added in v0.14.0
RunScheduled checks configured images at startup and at each interval for every available runtime. Each runtime runs independently and shares the same build coordination as user-requested refreshes.
func (*ImageRefresh) Start ¶ added in v0.14.0
func (r *ImageRefresh) Start(ctx context.Context, userID, runtime string) (v1.ImageRefreshStatus, error)
Start begins a refresh using a snapshot of the user's image preferences. The server context keeps the build alive after the HTTP request completes.
func (*ImageRefresh) Status ¶ added in v0.14.0
func (r *ImageRefresh) Status(userID, runtime string) (v1.ImageRefreshStatus, error)
Status returns the current or most recent refresh result for one runtime.
type ImageWarmer ¶ added in v0.14.0
type ImageWarmer interface {
Warmup(ctx context.Context, stdout, stderr io.Writer, opts *md.WarmupOpts) (bool, error)
}
ImageWarmer builds a specialized image without launching a container.
type LLMConfig ¶ added in v0.9.2
LLMConfig configures title generation and commit-description LLM calls.
type Router ¶ added in v0.10.1
type Router struct {
// Immutable.
TaskMCPScoper taskmgr.TaskMCPScoper // Scopes the normal MCP registry for task agents.
// contains filtered or unexported fields
}
Router is the HTTP router for the caic web UI. It owns HTTP routing, middleware, and route handler concerns only. Application services and long-lived automation (tasks, runtime, forge, bot/CI) are owned by internal/app and reached through the handler concerns below.
func New ¶
New creates a new HTTP router from already-assembled dependencies. It wires the injected services into HTTP handler concerns and the webhook endpoint; it does not construct or own application services.
func (*Router) Close ¶ added in v0.14.4
func (r *Router) Close()
Close cancels and waits for router-owned background work. Serve calls Close when it returns; callers must also close a router that is never served.
type RuntimeConfig ¶ added in v0.9.2
type RuntimeConfig struct {
TailscaleAPIKey string // required for Tailscale networking inside runtime instances
ImagePruneSchedule *autoupdate.Schedule // nil disables unused md image pruning
RepoRepackSchedule *autoupdate.Schedule // nil disables nightly large-repository repacking
System runtime.System // optional runtime override for smoke/e2e tests
Metadata runtime.Metadata // optional runtime metadata added to every created instance
// SkipWarmup skips base-image warmup at startup. Used by e2e fake mode to
// avoid pulling Docker images that aren't needed for testing.
SkipWarmup bool
}
RuntimeConfig selects and configures task runtime provisioning.
type VoiceConfig ¶ added in v0.9.2
type VoiceConfig struct {
Gateway VoiceGatewayConfig
}
VoiceConfig configures the WebRTC voice bridge.
func (*VoiceConfig) Validate ¶ added in v0.10.0
func (c *VoiceConfig) Validate() error
Validate returns an error if the voice configuration is invalid.
type VoiceGatewayConfig ¶ added in v0.10.0
type VoiceGatewayConfig struct {
Mode VoiceGatewayMode
URL string
Issuer string
InstanceID string
TokenMode VoiceTokenMode
SigningKey ed25519.PrivateKey
Config voicegateway.Config
}
VoiceGatewayConfig is caic's effective reference to a voice gateway.
func (*VoiceGatewayConfig) Validate ¶ added in v0.10.0
func (c *VoiceGatewayConfig) Validate() error
Validate returns an error if the voice gateway configuration is invalid.
type VoiceGatewayMode ¶ added in v0.10.0
type VoiceGatewayMode string
VoiceGatewayMode describes how caic exposes voice gateway support.
const ( VoiceGatewayModeDisabled VoiceGatewayMode = "disabled" VoiceGatewayModeEmbedded VoiceGatewayMode = "embedded" VoiceGatewayModeExternal VoiceGatewayMode = "external" )
Voice gateway support modes.
type VoiceTokenMode ¶ added in v0.13.1
type VoiceTokenMode string
VoiceTokenMode selects the token form caic issues for an external gateway.
const ( // VoiceTokenModeScoped issues the transitional scoped Ed25519 token. VoiceTokenModeScoped VoiceTokenMode = "scoped" // VoiceTokenModeOAuth issues a narrow OAuth 2.0 access token through caic's // authorization server so the gateway can verify it with discovery and JWKS. VoiceTokenModeOAuth VoiceTokenMode = "oauth" )
External voice gateway token modes.
type WarningStore ¶ added in v0.10.1
type WarningStore struct {
// contains filtered or unexported fields
}
WarningStore retains account-scoped warnings by owner and category, and public warnings by category. Recovery removes an episode, so a later failure receives a new ID. Diagnostic updates keep the ID.
func NewWarningStore ¶ added in v0.10.1
func NewWarningStore(taskMgr *taskmgr.Manager) *WarningStore
NewWarningStore creates a warning store that wakes task-list subscribers.
func (*WarningStore) ResolveCI ¶ added in v0.14.0
func (w *WarningStore) ResolveCI(ownerID string, category ci.WarningCategory) error
ResolveCI translates a CI recovery and removes its account's active alert.
func (*WarningStore) Since ¶ added in v0.10.1
func (w *WarningStore) Since(ownerID string, seq uint64) []serverWarning
Since returns active account and public server warnings newer than the revision cursor. A zero cursor replays active warnings on reconnect, retaining their IDs.
func (*WarningStore) UpdateCI ¶ added in v0.14.0
func (w *WarningStore) UpdateCI(ownerID string, category ci.WarningCategory, message string, details []ci.WarningDetail) error
UpdateCI translates a CI warning and coalesces its account's failure episode. Details are copied so callers cannot mutate a published warning.
func (*WarningStore) UpdateRuntimeRestore ¶ added in v0.14.0
func (w *WarningStore) UpdateRuntimeRestore(failure *taskmgr.ImportError)
UpdateRuntimeRestore translates a runtime import failure into a public alert. It covers tasks with existing runtime instances, including idle or stopped instances, rather than purged history. Private diagnostics belong in logs.
type WebhookHandlers ¶ added in v0.10.0
type WebhookHandlers struct {
// contains filtered or unexported fields
}
WebhookHandlers serves forge webhook delivery routes for GitHub and GitLab.
It verifies delivery authenticity, then dispatches events to the bot, the CI service, and the task manager. It owns the forge webhook secrets and the GitHub App owner allowlist; the bot and CI service it dispatches to are app-owned automation services injected at construction.
func (*WebhookHandlers) HandleGitHub ¶ added in v0.10.0
func (h *WebhookHandlers) HandleGitHub(w http.ResponseWriter, r *http.Request)
HandleGitHub handles POST /webhooks/github. It verifies the HMAC signature and dispatches on X-GitHub-Event.
func (*WebhookHandlers) HandleGitLab ¶ added in v0.10.0
func (h *WebhookHandlers) HandleGitLab(w http.ResponseWriter, r *http.Request)
HandleGitLab verifies the X-Gitlab-Token header and dispatches Pipeline Hook and Merge Request Hook events.
Source Files
¶
- attachment_handlers.go
- audit.go
- auth_handlers.go
- cache_sizes.go
- ci_handlers.go
- client_ip.go
- config.go
- device_login_host.go
- gomode.go
- http_wrappers.go
- image_refresh.go
- mcp_handlers.go
- mcp_notifications.go
- mcp_projection.go
- mcp_registry.go
- mcp_resources.go
- mcp_service_items.go
- mcp_skills.go
- mcp_tools.go
- middleware.go
- model_refresh.go
- oauth_handlers.go
- prompt_handlers.go
- purge_delay.go
- ratelimit.go
- router.go
- runtime_processes.go
- server_handlers.go
- static.go
- system_stats.go
- task_access.go
- task_handlers.go
- task_history.go
- task_history_http.go
- task_service.go
- usage_handlers.go
- voice_handlers.go
- warnings_store.go
- webfetch_handlers.go
- webhook_handlers.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package api provides shared API infrastructure (errors, validation interface) used across all API versions.
|
Package api provides shared API infrastructure (errors, validation interface) used across all API versions. |
|
v1
Package v1 defines SSE event types and API data transfer objects for the caic API.
|
Package v1 defines SSE event types and API data transfer objects for the caic API. |
|
Package apiconv converts backend domain values to API DTOs at the server boundary.
|
Package apiconv converts backend domain values to API DTOs at the server boundary. |
|
data
|
|
|
audit
Package audit defines the persisted OAuth and MCP audit event schema.
|
Package audit defines the persisted OAuth and MCP audit event schema. |
|
Package history incrementally projects raw task records into immutable bodies, section summaries, and pricing observations.
|
Package history incrementally projects raw task records into immutable bodies, section summaries, and pricing observations. |
|
data
Package data defines the private, rebuildable history pricing journal schema.
|
Package data defines the private, rebuildable history pricing journal schema. |
|
Package ipgeo provides IP origin and country allowlist enforcement.
|
Package ipgeo provides IP origin and country allowlist enforcement. |
|
data
Package data defines the on-disk named IP-origin cache.
|
Package data defines the on-disk named IP-origin cache. |