server

package
v0.17.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: AGPL-3.0 Imports: 57 Imported by: 0

Documentation

Overview

Package server — the Idempotency-Key dedup middleware.

A retried mutation carrying a stable `Idempotency-Key` header replays the first response instead of re-executing. This is the app's ONLY idempotency layer, POST /api/command included; do not add a body-keyed dedup beside it.

Package server — the canonical-request-path gate over the API surface.

ServeMux answers a non-canonical path with a 307, which is SUCCESS to a non-following client (`curl -sf .../api/health` would read healthy unconsulted), so the API surface refuses a non-canonical spelling itself.

Package server — security middleware: CSP headers, the ALLOWED_HOSTS anti-DNS-rebinding gate, and stdlib CSRF protection (net/http.CrossOriginProtection).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountUsageProvider

type AccountUsageProvider interface {
	AccountUsage(ctx context.Context) (*marotte.AccountUsage, error)
}

AccountUsageProvider fetches account usage (plan, credits, quota) via KAS's _kiro/account/getUsage for GET /api/account/usage. Exported for server.WithAccountUsage.

type KiroDoc

type KiroDoc struct {
	Category string `json:"category"`
	// Name is the row label: front-matter `name`, else the first H1, else the basename.
	Name string `json:"name"`
	Path string `json:"path"`
	// Group is the parent label for a nested category: a spec's feature
	// directory. Three files named requirements.md in a flat list identify
	// nothing.
	Group string `json:"group,omitempty"`

	Description string `json:"description,omitempty"`
	Inclusion   string `json:"inclusion,omitempty"`
	FileMatch   string `json:"file_match,omitempty"`
	Model       string `json:"model,omitempty"`

	// Trigger and Action carry a hook row (hooks are JSON, not markdown).
	Trigger string `json:"trigger,omitempty"`
	Action  string `json:"action,omitempty"`

	Tools            []string `json:"tools,omitempty"`
	SteeringOverride bool     `json:"steering_override,omitempty"`

	// ReadOnly says this row is not writable, so it renders without edit or delete. omitempty, so
	// read-only is only ever asserted by the server, never produced by a field failing to arrive.
	ReadOnly bool `json:"read_only,omitempty"`

	// DeleteProtected says this row renders without DELETE but keeps its edit: set for an entry
	// reached through a symlink, where the delete route would unlink the link's TARGET.
	DeleteProtected bool `json:"delete_protected,omitempty"`
}

KiroDoc is one row on the configuration browser. Fields are per-category and mostly omitempty; the client shapes each tab's columns.

type KiroDocsResponse

type KiroDocsResponse struct {
	Docs      []KiroDoc `json:"docs"`
	Truncated bool      `json:"truncated"`
}

KiroDocsResponse is GET /api/workspace/kiro-docs's reply. Truncated says a cap or a cancelled request stopped the scan before it read the whole tree, so a short list is not read as the whole inventory.

type Option

type Option func(*Server)

Option configures a Server at construction time.

func WithAccountUsage

func WithAccountUsage(p AccountUsageProvider) Option

WithAccountUsage sets the provider backing GET /api/account/usage.

func WithAgent

func WithAgent(a chatEngine) Option

WithAgent sets the agent runtime that owns the agent engine, its sessions and SSE broadcasts.

func WithAuth

func WithAuth(a routeHandler) Option

WithAuth sets the auth handler for login, logout, and whoami endpoints.

func WithAuthUnavailable

func WithAuthUnavailable(unavailable func() bool) Option

WithAuthUnavailable sets the sign-in leg /api/health reports. It must be a LATCH read, not a probe: the handler runs per request. Unset leaves readiness with no auth leg.

func WithChats

func WithChats(c routeHandler) Option

WithChats sets the chat store, whose own router owns the chat HTTP surface.

func WithConfigDir

func WithConfigDir(d string) Option

WithConfigDir sets the configuration directory path used for chat files and settings.

func WithFiles

func WithFiles(f routeHandler) Option

WithFiles sets the file handler for workspace file read/write endpoints.

func WithForges

func WithForges(r routeHandler) Option

WithForges sets the route handler for forge (GitHub/GitLab/Gitea) HTTP endpoints.

func WithGit

func WithGit(g routeHandler) Option

WithGit sets the git handler for the /api/git endpoints.

func WithGovernanceLocks added in v0.12.0

func WithGovernanceLocks(g governanceLocks) Option

WithGovernanceLocks sets the lock map a write to a locked kiro-cli setting is checked against.

func WithHostPolicy

func WithHostPolicy(p *webhttp.HostPolicy) Option

WithHostPolicy sets the exact-match Host allowlist the security middleware applies before the CSRF check — the anti-DNS-rebinding gate. A nil or inactive policy accepts any Host.

func WithKASNode added in v0.13.0

func WithKASNode(path string) Option

WithKASNode sets the node binary KAS runs on, which compiles hook matchers exactly as KAS will. Unset, a hook with a matcher cannot be created.

func WithKiroCLI

func WithKiroCLI(resolvePath func() string, resolveEnv func() []string) Option

WithKiroCLI sets the resolvers for the kiro-cli binary and its environment: resolvers because the install manager selects (and can switch) the active version after the bind.

func WithKiroDefaults added in v0.13.0

func WithKiroDefaults(k kiroDefaultsReader) Option

WithKiroDefaults sets what GET /api/settings reports an unset three-state setting resolves to.

func WithKiroReady

func WithKiroReady(ready func() (bool, pinstall.Reason)) Option

WithKiroReady sets the kiro-cli readiness verdict /api/health reports. Unset leaves the probe reflecting only that the listener is up.

func WithKiroRescan

func WithKiroRescan(rescan func(context.Context) (bool, error)) Option

WithKiroRescan sets the disk-rescan hook the loopback repair route exposes. Unset leaves the route unmounted.

func WithMCPConfig

func WithMCPConfig(r routeHandler) Option

WithMCPConfig sets the route handler for MCP server configuration endpoints.

func WithMCPRegistry

func WithMCPRegistry(r routeHandler) Option

WithMCPRegistry sets the route handler for the MCP registry proxy endpoint.

func WithMCPStatus

func WithMCPStatus(r routeHandler) Option

WithMCPStatus sets the route handler for the MCP runtime status endpoint.

func WithOnListen

func WithOnListen(fn func()) Option

WithOnListen registers a callback fired once the listener has SUCCESSFULLY bound (a bind failure never fires it). It runs on the bind goroutine ahead of serving, so it must not block.

func WithPolicy

func WithPolicy(p policyProvider) Option

WithPolicy sets the Cedar policy provider backing GET /api/permissions and POST /api/permissions/explain. The rule writer needs no provider.

func WithPolicyReload

func WithPolicyReload(p policyReloader) Option

WithPolicyReload wires what a security-profile change needs after it persisted. Optional: unwired, live sessions keep the old presets and no client is told.

func WithPreview added in v0.10.12

func WithPreview(r routeHandler) Option

WithPreview sets the sandboxed web-preview routes.

func WithPush

func WithPush(p routeHandler) Option

WithPush sets the push service used for Web Push notification delivery.

func WithSensitive added in v0.11.0

func WithSensitive(sensitive filebrowse.Sensitive) Option

WithSensitive sets the deny list the `.kiro` docs scan refuses, the same value the file browser holds.

func WithSpecApprovals

func WithSpecApprovals(st *specapproval.Store) Option

WithSpecApprovals wires the spec-phase approval record the spec GET reads. A nil store stays a nil INTERFACE (not a typed nil), so the handler's unwired branch is taken.

func WithStaticFS

func WithStaticFS(staticFS fs.FS) Option

WithStaticFS sets the embedded filesystem serving the compiled web UI.

func WithSteering

func WithSteering(g SteeringGenerator) Option

WithSteering sets the steering generator used to produce environment.md for kiro-cli.

func WithTabs

func WithTabs(st *tabs.Store) Option

WithTabs wires the open-tab set GET /api/tabs reads. A nil store stays a nil INTERFACE (not a typed nil), so the handler's unwired branch is taken.

func WithTools

func WithTools(src toolsSource) Option

WithTools sets the source of the tools engine backing the /api/tools surface.

func WithTrustedProxies

func WithTrustedProxies(trusted []netip.Prefix) Option

WithTrustedProxies sets the reverse-proxy networks trusted when resolving the access-log client_ip. Empty trusts nothing, so the socket peer is logged.

func WithWorkDir

func WithWorkDir(d string) Option

WithWorkDir sets the workspace directory served by the file handler and git endpoints.

type Server

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

Server holds shared state and registers all HTTP handlers.

func New

func New(opts ...Option) *Server

New constructs a Server with the given options applied.

func (*Server) ApplyGovernanceLocks added in v0.12.0

func (s *Server) ApplyGovernanceLocks(ctx context.Context)

ApplyGovernanceLocks writes each locked kiro-cli setting to the administrator's value, so kiro-cli's own processes follow the lock, and writes the user's held value back to each setting whose lock lifted. Best-effort: a failure warns and the next lock change retries.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe registers all routes and starts the HTTP server, blocking until SIGTERM/SIGINT.

func (*Server) SeedKiroSettings added in v0.12.9

func (s *Server) SeedKiroSettings(ctx context.Context)

SeedKiroSettings writes the Seed of each allowlisted kiro-cli setting that has one where kiro-cli holds no value, so a user's own choice survives a restart. A locked key is left to its lock, and a settings document kiro-cli cannot list seeds nothing. Call it once kiro-cli is installed.

type SteeringGenerator

type SteeringGenerator interface {
	CustomPath() string
}

SteeringGenerator generates steering files for kiro-cli. *steering.Generator satisfies it. Exported because the composition root names it in server.WithSteering.

Jump to

Keyboard shortcuts

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