Documentation
¶
Overview ¶
Package runtime provides interfaces and types for managing AI agent workspace runtimes. A runtime is an execution environment (e.g., container, process) that hosts a workspace instance.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRuntimeNotFound is returned when a requested runtime type is not registered. ErrRuntimeNotFound = errors.New("runtime not found") // ErrInstanceNotFound is returned when a requested runtime instance does not exist. ErrInstanceNotFound = errors.New("runtime instance not found") // (e.g., podman binary not found, docker daemon not running). ErrRuntimeUnavailable = errors.New("runtime unavailable") // ErrInvalidParams is returned when create parameters are invalid or incomplete. ErrInvalidParams = errors.New("invalid runtime parameters") )
Functions ¶
func ValidateState ¶
func ValidateState(state api.WorkspaceState) error
ValidateState validates that a runtime state is one of the valid WorkspaceState values. Valid states are: "running", "stopped", "error", "unknown". Returns an error if the state is not valid.
Types ¶
type AgentLister ¶
type AgentLister interface {
// ListAgents returns the names of all agents supported by this runtime.
// Returns an empty slice if no agents are configured.
ListAgents() ([]string, error)
}
AgentLister is an optional interface for runtimes that can report which agents they support. Runtimes implementing this interface enable discovery of available agents without requiring direct knowledge of the runtime's internal configuration.
Example implementation:
type myRuntime struct {
configDir string
}
func (r *myRuntime) ListAgents() ([]string, error) {
// Scan configuration directory for agent definitions
return []string{"claude", "goose"}, nil
}
type CreateParams ¶
type CreateParams struct {
// Name is the human-readable name for the instance.
Name string
// SourcePath is the absolute path to the workspace source directory.
SourcePath string
// WorkspaceConfig is the workspace configuration (optional, can be nil if no configuration exists).
WorkspaceConfig *workspace.WorkspaceConfiguration
// Agent is the agent name for loading agent-specific configuration (required, cannot be empty).
Agent string
// AgentSettings contains the agent settings files to embed into the agent user's
// home directory in the workspace image. Keys are relative file paths using
// forward slashes (e.g., ".claude/settings.json"), values are file contents.
// This map can be nil or empty if no default settings are configured.
AgentSettings map[string][]byte
}
CreateParams contains parameters for creating a new runtime instance.
type Registry ¶
type Registry interface {
// Register adds a runtime to the registry.
// Returns an error if a runtime with the same type is already registered.
Register(runtime Runtime) error
// Get retrieves a runtime by type.
// Returns ErrRuntimeNotFound if the runtime type is not registered.
Get(runtimeType string) (Runtime, error)
// List returns all registered runtime types.
List() []string
}
Registry manages available runtime implementations.
func NewRegistry ¶
NewRegistry creates a new runtime registry with the specified storage directory. The storage directory is used to create runtime-specific subdirectories at REGISTRY_STORAGE/runtimeType.
type Runtime ¶
type Runtime interface {
// Type returns the runtime type identifier (e.g., "podman", "docker", "process", "fake").
Type() string
// WorkspaceSourcesPath returns the path where sources will be mounted inside the workspace.
// This is a constant for each runtime type and doesn't require an instance to exist.
WorkspaceSourcesPath() string
// Create creates a new runtime instance without starting it.
// Returns RuntimeInfo with the assigned instance ID and initial state.
Create(ctx context.Context, params CreateParams) (RuntimeInfo, error)
// Start starts a previously created runtime instance.
// Returns updated RuntimeInfo with running state.
Start(ctx context.Context, id string) (RuntimeInfo, error)
// Stop stops a running runtime instance without removing it.
// The instance can be started again later.
Stop(ctx context.Context, id string) error
// Remove removes a runtime instance and cleans up all associated resources.
// The instance must be stopped before removal.
Remove(ctx context.Context, id string) error
// Info retrieves current information about a runtime instance.
Info(ctx context.Context, id string) (RuntimeInfo, error)
}
Runtime manages the lifecycle of workspace instances in a specific execution environment. Implementations might use containers (podman, docker), processes, or other isolation mechanisms.
type RuntimeInfo ¶
type RuntimeInfo struct {
// ID is the runtime-assigned instance identifier.
ID string
// State is the current runtime state.
State api.WorkspaceState
// Info contains runtime-specific metadata as key-value pairs.
// Examples: container_id, pid, created_at, network addresses.
Info map[string]string
}
RuntimeInfo contains information about a runtime instance.
type StorageAware ¶
type StorageAware interface {
// Initialize is called during registration with the runtime's private storage directory.
// The directory is created before this method is called and is guaranteed to exist.
// The path will be: REGISTRY_STORAGE/runtimeType
//
// Runtimes should store the directory path and use it for persisting private data.
// This method is called exactly once during registration, before the runtime is available for use.
Initialize(storageDir string) error
}
StorageAware is an optional interface that runtimes can implement to receive a dedicated storage directory during registration.
When a runtime implements this interface, the Registry will:
- Create a directory at REGISTRY_STORAGE/runtimeType
- Call Initialize with the absolute path to this directory
- The runtime can use this directory to persist private data
Example implementation:
type myRuntime struct {
storageDir string
}
func (r *myRuntime) Initialize(storageDir string) error {
r.storageDir = storageDir
// Optional: create subdirectories, load state, etc.
return os.MkdirAll(filepath.Join(storageDir, "instances"), 0755)
}
func (r *myRuntime) Create(ctx context.Context, params CreateParams) (RuntimeInfo, error) {
// Use r.storageDir to persist instance data
instanceFile := filepath.Join(r.storageDir, "instances", id+".json")
return os.WriteFile(instanceFile, data, 0644)
}
type Terminal ¶
type Terminal interface {
// Terminal starts an interactive terminal session inside a running instance.
// The command is executed with stdin/stdout/stderr connected directly to the user's terminal.
// Returns an error if the instance is not running or command execution fails.
//
// Parameters:
// - ctx: Context for cancellation and timeout
// - instanceID: The runtime instance identifier
// - agent: The agent name for loading agent-specific configuration
// - command: The command to execute (e.g., ["bash"], ["claude-code", "--debug"]).
// If empty, the runtime will use the agent's configured terminal command.
Terminal(ctx context.Context, instanceID string, agent string, command []string) error
}
Terminal is an optional interface for runtimes that support interactive terminal sessions. Runtimes implementing this interface enable the terminal command for connecting to running instances.
When a runtime implements this interface, users can:
- Connect to running instances with an interactive terminal
- Execute commands directly inside the instance environment
- Interact with agents or shells running in the instance
Example implementation:
type myRuntime struct {
// ... other fields
}
func (r *myRuntime) Terminal(ctx context.Context, instanceID string, agent string, command []string) error {
// Execute command interactively (stdin/stdout/stderr connected)
return r.exec.RunInteractive(ctx, "exec", "-it", instanceID, command...)
}
Directories
¶
| Path | Synopsis |
|---|---|
|
Package fake provides a fake runtime implementation for testing.
|
Package fake provides a fake runtime implementation for testing. |
|
Package podman provides a Podman runtime implementation for container-based workspaces.
|
Package podman provides a Podman runtime implementation for container-based workspaces. |
|
exec
Package exec provides an abstraction for executing podman commands.
|
Package exec provides an abstraction for executing podman commands. |