Documentation
¶
Index ¶
Constants ¶
const ( // DefaultStorageFileName is the default filename for storing instances DefaultStorageFileName = "instances.json" // RuntimesSubdirectory is the subdirectory for runtime storage RuntimesSubdirectory = "runtimes" )
Variables ¶
var ( // ErrInstanceNotFound is returned when an instance is not found ErrInstanceNotFound = errors.New("instance not found") // ErrInstanceExists is returned when trying to add a duplicate instance ErrInstanceExists = errors.New("instance already exists") // ErrInvalidPath is returned when a path is invalid or empty ErrInvalidPath = errors.New("invalid path") )
Functions ¶
This section is empty.
Types ¶
type AddOptions ¶
type AddOptions struct {
// Instance is the instance to add
Instance Instance
// RuntimeType is the type of runtime to use
RuntimeType string
// WorkspaceConfig is the workspace-level configuration from .kaiden/workspace.json (optional, can be nil)
WorkspaceConfig *workspace.WorkspaceConfiguration
// Project is an optional custom project identifier to override auto-detection
Project string
// Agent is an optional agent name for loading agent-specific configuration
Agent string
// Model is an optional model ID to configure for the agent
Model string
}
AddOptions contains parameters for adding a new instance
type Instance ¶
type Instance interface {
// GetID returns the unique identifier for the instance.
GetID() string
// GetName returns the human-readable name for the instance.
GetName() string
// GetSourceDir returns the source directory.
// The path is always absolute.
GetSourceDir() string
// GetConfigDir returns the configuration directory.
// The path is always absolute.
GetConfigDir() string
// IsAccessible checks if both source and config directories are accessible
IsAccessible() bool
// GetRuntimeType returns the runtime type for this instance
GetRuntimeType() string
// GetRuntimeData returns the complete runtime data for this instance
GetRuntimeData() RuntimeData
// GetProject returns the project identifier for this instance
GetProject() string
// GetAgent returns the agent name for this instance
GetAgent() string
// GetModel returns the model ID for this instance (empty if not set)
GetModel() string
// Dump returns the serializable data of the instance
Dump() InstanceData
}
Instance represents a workspace instance with source and configuration directories. Each instance is uniquely identified by its ID and has a human-readable name. Instances must be created using NewInstance to ensure proper validation and path normalization.
func NewInstance ¶
func NewInstance(params NewInstanceParams) (Instance, error)
NewInstance creates a new Instance with validated and normalized paths. Both sourceDir and configDir are converted to absolute paths. The ID and Name (if empty) will be generated by the Manager when the instance is added to storage.
func NewInstanceFromData ¶
func NewInstanceFromData(data InstanceData) (Instance, error)
NewInstanceFromData creates a new Instance from InstanceData. The paths in InstanceData are assumed to be already validated and absolute.
type InstanceData ¶
type InstanceData struct {
// ID is the unique identifier for the instance
ID string `json:"id"`
// Name is the human-readable name for the instance
Name string `json:"name"`
// Paths contains the source and configuration directories
Paths InstancePaths `json:"paths"`
// Runtime contains runtime-specific information
Runtime RuntimeData `json:"runtime"`
// Project is the project identifier for grouping instances.
// Format depends on workspace type:
// - Git repository with remote: normalized remote repository identifier (remote URL with .git suffix
// and credentials stripped, e.g., "https://github.com/user/repo")
// - Git repository without remote: repository root directory as absolute path (e.g., "/home/user/my-local-repo")
// - Non-git directory: workspace source directory as absolute path (e.g., "/home/user/my-workspace")
// When the workspace is in a subdirectory of the repository, a relative-path suffix is appended
// (e.g., "https://github.com/user/repo/pkg/subdir" or "/home/user/my-local-repo/pkg/subdir")
Project string `json:"project"`
// Agent is the agent name for this instance (e.g., "claude", "goose").
// This is used to load agent-specific configuration and determine which agent command to run.
Agent string `json:"agent"`
// Model is the model ID configured for the agent (e.g., "claude-sonnet-4-20250514").
// Empty string means no model was explicitly specified.
Model string `json:"model,omitempty"`
}
InstanceData represents the serializable data of an instance
type InstanceFactory ¶
type InstanceFactory func(InstanceData) (Instance, error)
InstanceFactory is a function that creates an Instance from InstanceData
type InstancePaths ¶
type InstancePaths struct {
// Source is the directory containing source files (absolute path)
Source string `json:"source"`
// Configuration is the directory containing workspace configuration (absolute path)
Configuration string `json:"configuration"`
}
InstancePaths represents the paths in an instance
type Manager ¶
type Manager interface {
// Add registers a new instance with a runtime and returns the instance with its generated ID
Add(ctx context.Context, opts AddOptions) (Instance, error)
// Start starts a runtime instance by ID
Start(ctx context.Context, id string) error
// Stop stops a runtime instance by ID
Stop(ctx context.Context, id string) error
// Terminal starts an interactive terminal session in a running instance
Terminal(ctx context.Context, id string, command []string) error
// List returns all registered instances
List() ([]Instance, error)
// Get retrieves a specific instance by name or ID
Get(nameOrID string) (Instance, error)
// Delete unregisters an instance by ID
Delete(ctx context.Context, id string) error
// Reconcile removes instances with inaccessible directories
// Returns the list of removed instance IDs
Reconcile() ([]string, error)
// RegisterRuntime registers a runtime with the manager's registry
RegisterRuntime(rt runtime.Runtime) error
// RegisterAgent registers an agent with the manager's registry
RegisterAgent(name string, agent agent.Agent) error
}
Manager handles instance storage and operations
func NewManager ¶
NewManager creates a new instance manager with the given storage directory.
type NewInstanceParams ¶
type NewInstanceParams struct {
// SourceDir is the directory containing source files
SourceDir string
// ConfigDir is the directory containing workspace configuration
ConfigDir string
// Name is the human-readable name for the instance (optional, will be generated if empty)
Name string
}
NewInstanceParams contains the parameters for creating a new Instance
type RuntimeData ¶
type RuntimeData struct {
// Type is the runtime type (e.g., "fake", "podman", "docker")
Type string `json:"type"`
// InstanceID is the runtime-assigned instance identifier
InstanceID string `json:"instance_id"`
// State is the current runtime state (e.g., "running", "stopped")
State api.WorkspaceState `json:"state"`
// Info contains runtime-specific metadata
Info map[string]string `json:"info"`
}
RuntimeData represents runtime-specific information for an instance