core

package
v0.6.76 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0, Apache-2.0, MIT Imports: 35 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package core is the devbox gateway proper (sections 4.6 to 4.6b): it serves devbox.v1.Gateway through the KAS tunnel, drives instance lifecycles on Substrate, forwards daemon events to console, proxies history reads to the box that holds the transcript, executes suspends and backstops, and resolves actors for the egress package.

Index

Constants

This section is empty.

Variables

View Source
var Capabilities = []string{"acp-v2", "claude-oauth", "egress-pr-observation", "snapshots"}

Capabilities are reported on registration.

View Source
var ErrRunnerNotReady = errors.New("devbox runner has no ready revision")

ErrRunnerNotReady means the runner has no ready revision to start instances from.

Functions

func ActorName

func ActorName(instanceID string) string

ActorName is the Substrate actor name of an instance: a DNS label derived from the instance ID.

func AutonomyOf

AutonomyOf converts a CRD autonomy level.

func Registered

func Registered() bool

Registered reports whether this process has registered with console at least once since it started.

func SnapshotTagName

func SnapshotTagName(snapshotID string) string

SnapshotTagName is the Substrate tag of a snapshot.

Types

type Config

type Config struct {
	GatewayID        string
	Version          string
	SubstrateVersion string
	// ClusterID is the console cluster, used until RegisterGateway reports it.
	ClusterID string
	// CredentialProviderRegistered and EgressAuthzRegistered are reported on registration.
	CredentialProviderRegistered bool
	EgressAuthzRegistered        bool

	// Harness endpoints handed to daemons in Initialize.
	ConsoleURL string
	AIProxyURL string
	// WorkbenchMCPURL is the base of console's workbench MCP; each instance gets <base>/<workbench-id>.
	WorkbenchMCPURL string
	// GatewayURL is where sandboxes reach the gateway's devbox MCP (GatewayURL + /mcp) and SandboxCredentials
	// (GatewayURL), through egress which injects the actor JWT.
	GatewayURL string
	// RequestTokenJWKS is passed to daemons to validate devbox-request-token. Empty disables validation.
	RequestTokenJWKS []byte

	HeartbeatInterval   time.Duration
	ReadyTimeout        time.Duration
	PrepareTimeout      time.Duration
	DrainTimeout        time.Duration
	SnapshotTimeout     time.Duration
	FlushInterval       time.Duration
	MaxBatch            int
	DeltaInterval       time.Duration
	MaxDeltaBatch       int
	BackstopInterval    time.Duration
	EvictionInterval    time.Duration
	UnresponsiveAfter   time.Duration
	StreamTokenTTL      time.Duration
	RegistrationBackoff time.Duration
}

Config tunes the core. Zero values take the defaults below.

type CredentialService

type CredentialService interface {
	VerifyActorJWT(ctx context.Context, raw string) (*egress.Caller, error)
	InstanceCredential(ctx context.Context, instanceID string, sel *devboxv1.CredentialSelector) (*devboxv1.InstanceCredential, error)
}

CredentialService verifies sandbox callers and serves cached OIDC credentials (egress.Service).

type Deps

type Deps struct {
	Ingest  devboxv1.IngestClient
	Actors  *actors.Client
	Router  Router
	Records Records
	Runners Runners
	// Egress is optional; when set, instance changes invalidate its caches.
	Egress Egress
	// Credentials is optional; SandboxCredentials needs it.
	Credentials CredentialService
	Log         logr.Logger
	Now         func() time.Time
}

Deps are the core's collaborators.

type Egress

type Egress interface {
	Invalidate(instanceID string)
}

Egress is what the core needs from the egress package.

type Gateway

type Gateway struct {
	devboxv1.UnimplementedGatewayServer
	// contains filtered or unexported fields
}

Gateway is the core.

func New

func New(cfg Config, deps Deps) (*Gateway, error)

New builds a Gateway. Call Run to start its background loops.

func (*Gateway) AddRepository

func (*Gateway) CancelPrompt

func (*Gateway) CloseThread

func (*Gateway) CountByStatus

func (g *Gateway) CountByStatus(st devboxv1.InstanceStatus) int

CountByStatus counts managed instances in a status (metrics).

func (*Gateway) CreateThread

func (*Gateway) DeleteThread

func (*Gateway) ForkThread

func (*Gateway) GetBranchDiffStat

func (*Gateway) GetChanges

func (*Gateway) GetSessions

func (*Gateway) GetTimeline

func (*Gateway) ImportThread

func (*Gateway) ListCommands

func (*Gateway) ListFiles

func (*Gateway) ListThreads

func (*Gateway) OpenStream

OpenStream prepares a terminal, VNC or preview target and registers it under a fresh stream ID (DBX-33).

func (*Gateway) Prompt

func (*Gateway) ProxyStream

func (g *Gateway) ProxyStream(stream devboxv1.Gateway_ProxyStreamServer) error

ProxyStream carries one browser WebSocket (or preview HTTP request) to the daemon through atenet-router, as HTTP-over-gRPC: header, data*, trailer, then upgrade data both ways after a 101.

func (*Gateway) ReadFile

func (*Gateway) Register

func (g *Gateway) Register(s grpc.ServiceRegistrar)

Register adds the Gateway service to a gRPC server (the tunnel's in-process server).

func (*Gateway) RegisterSandboxCredentials

func (g *Gateway) RegisterSandboxCredentials(s grpc.ServiceRegistrar)

RegisterSandboxCredentials adds SandboxCredentials to a server.

func (*Gateway) ResolveActor

func (g *Gateway) ResolveActor(ctx context.Context, actorID string) (*egress.InstanceInfo, error)

ResolveActor implements egress.ActorResolver: it maps "<atespace>/<actor>" to the instance's egress view.

func (*Gateway) ResumeThread

func (*Gateway) Run

func (g *Gateway) Run(ctx context.Context) error

Run runs registration, heartbeats, backstops and eviction polling until ctx is done, then stops event forwarders and waits for background operations.

func (*Gateway) Shutdown

func (g *Gateway) Shutdown()

Shutdown stops forwarders and background operations. Instances keep running on Substrate.

func (*Gateway) SuspendInstance

func (*Gateway) UseEgress

func (g *Gateway) UseEgress(e Egress, c CredentialService)

UseEgress wires the egress service, which itself needs the Gateway as its actor resolver. Call it before Run.

func (*Gateway) WriteFile

type Instance

type Instance struct {
	ID string
	// contains filtered or unexported fields
}

Instance is one devbox instance managed by this gateway.

func (*Instance) ActorID

func (i *Instance) ActorID() string

type KubeRecords

type KubeRecords struct {
	Client    client.Client
	Namespace string
}

KubeRecords keeps one ConfigMap per instance in the gateway's namespace. Records hold no credentials.

func (*KubeRecords) Delete

func (k *KubeRecords) Delete(ctx context.Context, id string) error

func (*KubeRecords) Get

func (k *KubeRecords) Get(ctx context.Context, id string) (*Record, error)

func (*KubeRecords) List

func (k *KubeRecords) List(ctx context.Context) ([]*Record, error)

func (*KubeRecords) Put

func (k *KubeRecords) Put(ctx context.Context, rec *Record) error

type KubeRunners

type KubeRunners struct {
	Client client.Reader
	// Namespace holds v1alpha1.DevboxRunnerEnvSecret; empty disables secret env.
	Namespace string
	TTL       time.Duration
	// contains filtered or unexported fields
}

KubeRunners reads DevboxRunners (cluster-scoped) with a short cache.

func (*KubeRunners) Get

func (k *KubeRunners) Get(ctx context.Context, name string) (*Runner, error)

func (*KubeRunners) Invalidate

func (k *KubeRunners) Invalidate(name string)

Invalidate drops a cached runner.

type MemoryRecords

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

MemoryRecords keeps records in memory (tests and local development).

func (*MemoryRecords) Delete

func (m *MemoryRecords) Delete(_ context.Context, id string) error

func (*MemoryRecords) Get

func (m *MemoryRecords) Get(_ context.Context, id string) (*Record, error)

func (*MemoryRecords) List

func (m *MemoryRecords) List(ctx context.Context) ([]*Record, error)

func (*MemoryRecords) Put

func (m *MemoryRecords) Put(_ context.Context, rec *Record) error

type Record

type Record struct {
	InstanceID  string `json:"instanceId"`
	DevboxID    string `json:"devboxId"`
	WorkbenchID string `json:"workbenchId,omitempty"`
	OwnerID     string `json:"ownerId,omitempty"`
	Runner      string `json:"runner"`

	Atespace         string `json:"atespace"`
	Actor            string `json:"actor"`
	Template         string `json:"template,omitempty"`
	TemplateRevision int64  `json:"templateRevision,omitempty"`
	ImageDigest      string `json:"imageDigest,omitempty"`

	Status          string    `json:"status"`
	SuspendReason   string    `json:"suspendReason,omitempty"`
	Message         string    `json:"message,omitempty"`
	RestoredFrom    string    `json:"restoredFrom,omitempty"`
	RestoreFidelity string    `json:"restoreFidelity,omitempty"`
	CreatedAt       time.Time `json:"createdAt"`
	UpdatedAt       time.Time `json:"updatedAt"`
	SuspendedAt     time.Time `json:"suspendedAt,omitempty"`

	// Request is the protojson CreateInstanceRequest, kept current with allowlist and billing changes.
	Request json.RawMessage `json:"request"`
}

Record is the durable state of an instance (see Records), so a restarted gateway can reconcile with console's RegisterGateway summaries.

func (*Record) ActorID

func (r *Record) ActorID() string

ActorID is "<atespace>/<actor>".

type Records

type Records interface {
	Put(ctx context.Context, rec *Record) error
	Get(ctx context.Context, id string) (*Record, error)
	List(ctx context.Context) ([]*Record, error)
	Delete(ctx context.Context, id string) error
}

Records persists instance records so a restarted gateway can reconcile with console's RegisterGateway summaries. Get returns nil, nil for an unknown instance.

type Router

type Router interface {
	Daemon(actor string) devboxv1.DaemonClient
	NewRequest(ctx context.Context, actor, method, pathAndQuery string) (*http.Request, error)
	RoundTrip(req *http.Request) (*http.Response, error)
}

Router reaches daemons through atenet-router (see package router).

type Runner

type Runner struct {
	Name     string
	Atespace string
	// Template, Revision and GoldenTag describe the revision new instances start from.
	Template    string
	Revision    int64
	GoldenTag   string
	ImageDigest string
	// Revisions maps every revision that still exists to its template and golden tag.
	Revisions map[int64]RunnerRevision

	AllowedRepositories []string
	HTTPAllowlist       []egress.AllowEntry
	CloudIdentities     []*devboxv1.CloudIdentity
	CloudIdentityHosts  []string
	IdlePolicy          *devboxv1.IdlePolicy
	Autonomy            *devboxv1.AutonomyPolicy
	// Env is the runner's resolved secret env vars, sent with every Initialize.
	Env map[string]string
}

Runner is what the gateway needs from a DevboxRunner.

func RunnerFromCRD

func RunnerFromCRD(obj *v1alpha1.DevboxRunner) *Runner

RunnerFromCRD converts a DevboxRunner.

type RunnerRevision

type RunnerRevision struct {
	Template  string
	GoldenTag string
}

type Runners

type Runners interface {
	Get(ctx context.Context, name string) (*Runner, error)
}

Runners looks up DevboxRunners by name.

type StaticRunners

type StaticRunners map[string]*Runner

StaticRunners serves fixed runners (tests and local development).

func (StaticRunners) Get

func (s StaticRunners) Get(_ context.Context, name string) (*Runner, error)

Jump to

Keyboard shortcuts

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