workspace

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: AGPL-3.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BotLabelKey                 = "memoh.bot_id"
	WorkspaceLabelKey           = "memoh.workspace"
	WorkspaceLabelValue         = "v3"
	WorkspaceCDIDevicesLabelKey = "memoh.workspace.cdi_devices"
	ContainerPrefix             = "workspace-"
	LegacyContainerPrefix       = "mcp-"
	DisplayRFBSocketName        = "display.rfb.sock"
	ToolsProxyHTTPURL           = bridge.ToolsProxyHTTPURL

	// WorkspaceInitPath and WorkspaceBridgePath are the container start
	// parameters used by buildWorkspaceContainerSpec: the image's init and the
	// mount point of the Server-supplied bridge binary. A container missing
	// either never starts, so WaitForWorkspaceReady surfaces that on its own.
	WorkspaceInitPath   = "/usr/bin/tini"
	WorkspaceBridgePath = "/opt/memoh/bridge"
)
View Source
const (
	WorkspaceTargetNative = "native"
	WorkspaceTargetRemote = "remote"

	WorkspaceTargetStatusOnline               = "online"
	WorkspaceTargetStatusOffline              = "offline"
	WorkspaceTargetStatusRevoked              = "revoked"
	WorkspaceTargetStatusOwnerMismatch        = "owner_mismatch"
	WorkspaceTargetStatusClientUpdateRequired = "client_update_required"
)
View Source
const (
	WorkspaceResourceCPUMillicoresLabelKey = "memoh.workspace.resource.cpu_millicores"
	WorkspaceResourceMemoryBytesLabelKey   = "memoh.workspace.resource.memory_bytes"

	ResourceLimitStatusApplied         = "applied"
	ResourceLimitStatusNotCreated      = "not_created"
	ResourceLimitStatusPendingRecreate = "pending_recreate"
	ResourceLimitStatusUnsupported     = "unsupported"
)
View Source
const (
	SnapshotSourceManual   = "manual"
	SnapshotSourcePreExec  = "pre_exec"
	SnapshotSourceRollback = "rollback"
)

Variables

View Source
var (
	ErrWorkspaceTargetNotFound          = errors.New("workspace target not found")
	ErrRemoteWorkspaceNotBound          = errors.New("remote workspace is not bound")
	ErrRemoteRuntimeNotUsable           = errors.New("remote runtime not found, revoked, or owned by another user")
	ErrRemoteRuntimeOffline             = errors.New("remote runtime is offline")
	ErrRemoteRuntimeRevoked             = errors.New("remote runtime has been revoked")
	ErrRemoteRuntimeOwnerMismatch       = errors.New("remote runtime no longer belongs to the bot owner")
	ErrRemoteRuntimeClientUpdateNeeded  = errors.New("remote runtime client must be updated")
	ErrInvalidWorkspaceToolApprovalMode = errors.New("invalid workspace tool approval mode")
)
View Source
var ErrContainerNotFound = errors.New("workspace not found for bot")

ErrContainerNotFound is returned when no container exists for a bot.

View Source
var ErrWorkspaceTemplateBootstrapFailed = errors.New("workspace template bootstrap failed")

ErrWorkspaceTemplateBootstrapFailed identifies a workspace that started but could not receive the built-in workspace files. The wrapped cause is private diagnostic data and must be translated at the transport boundary.

Functions

func BotIDFromContainerID

func BotIDFromContainerID(containerID string) (string, bool)

BotIDFromContainerID infers a bot ID from a known container naming scheme. This is only used as a fallback for legacy containers when labels are missing.

func BotIDFromContainerInfo

func BotIDFromContainerInfo(info ctr.ContainerInfo) (string, bool)

BotIDFromContainerInfo resolves the bot ID from container metadata. It prefers the current label and only falls back to name inference.

func BridgeTLSOptionsFromConfig

func BridgeTLSOptionsFromConfig(cfg config.Config) (*bridge.TLSOptions, error)

BridgeTLSOptionsFromConfig 把 server 配置翻译成 bridge dial 的 mTLS options。 disabled → (nil, nil)。strict 但材料/instance-id 不全 → error:strict 不允许 静默回退明文,配置残缺必须在启动期暴露。

func DefaultRemoteToolApprovalConfig

func DefaultRemoteToolApprovalConfig() settings.ToolApprovalConfig

The remote default is allow-everything: mounting a computer is already the explicit trust decision, so per-call asks would just be friction. Bypass and force-review lists stay empty — nothing is inherited from native.

func SkillDiscoveryRootsFromMetadata

func SkillDiscoveryRootsFromMetadata(metadata map[string]any) []string

func WithWorkspaceTarget

func WithWorkspaceTarget(ctx context.Context, targetID string) context.Context

WithWorkspaceTarget returns a child context whose workspace operations default to targetID. The override is request-scoped; it never mutates the Bot's persisted Primary target or Manager state.

func WorkspaceTargetFromContext

func WorkspaceTargetFromContext(ctx context.Context) string

WorkspaceTargetFromContext returns the request-scoped workspace target override, or an empty string when the Bot's persisted Primary should apply.

Types

type BotSnapshotData

type BotSnapshotData struct {
	ContainerID      string
	Info             ctr.ContainerInfo
	Snapshotter      string
	RuntimeSnapshots []ctr.SnapshotInfo
	ManagedMeta      map[string]ManagedSnapshotMeta
}

type BridgeTLSRuntimeOptions

type BridgeTLSRuntimeOptions struct {
	Client            *bridge.TLSOptions
	BridgeMaterialDir string
	ExpectedClientURI string
}

func BridgeTLSRuntimeOptionsFromConfig

func BridgeTLSRuntimeOptionsFromConfig(cfg config.Config) (*BridgeTLSRuntimeOptions, error)

type ContainerMetricsResult

type ContainerMetricsResult struct {
	Supported         bool
	UnsupportedReason string
	Status            ContainerMetricsStatus
	SampledAt         time.Time
	CPU               *ctr.CPUMetrics
	Memory            *ctr.MemoryMetrics
	Storage           *ContainerStorageMetrics
}

type ContainerMetricsStatus

type ContainerMetricsStatus struct {
	Exists      bool `json:"exists"`
	TaskRunning bool `json:"task_running"`
}

type ContainerSetupEvent

type ContainerSetupEvent struct {
	Type             string
	Image            string
	Message          string
	Layers           []ctr.LayerStatus
	ContainerID      string
	WorkspaceBackend string
	RuntimeBackend   string
	ContainerPath    string
	CDIDevices       []string
	Started          bool
	DataRestored     bool
	HasPreservedData bool
}

type ContainerSetupProgress

type ContainerSetupProgress func(ContainerSetupEvent)

type ContainerStatus

type ContainerStatus struct {
	ContainerID      string    `json:"container_id"`
	WorkspaceBackend string    `json:"workspace_backend"`
	RuntimeBackend   string    `json:"runtime_backend,omitempty"`
	Image            string    `json:"image"`
	Status           string    `json:"status"`
	Namespace        string    `json:"namespace"`
	ContainerPath    string    `json:"container_path"`
	CDIDevices       []string  `json:"cdi_devices,omitempty"`
	TaskRunning      bool      `json:"task_running"`
	HasPreservedData bool      `json:"has_preserved_data"`
	Legacy           bool      `json:"legacy"`
	CreatedAt        time.Time `json:"created_at"`
	UpdatedAt        time.Time `json:"updated_at"`
}

ContainerStatus combines DB records with live containerd state.

type ContainerStorageMetrics

type ContainerStorageMetrics struct {
	Path      string `json:"path"`
	UsedBytes uint64 `json:"used_bytes"`
}

type ImagePrepareMode

type ImagePrepareMode string
const (
	ImagePreparePulled    ImagePrepareMode = "pulled"
	ImagePrepareSkipped   ImagePrepareMode = "skipped"
	ImagePrepareDelegated ImagePrepareMode = "delegated"
)

type ImagePrepareResult

type ImagePrepareResult struct {
	Mode     ImagePrepareMode
	ImageRef string
	Image    ctr.ImageInfo
	Message  string
}

type ManagedSnapshotMeta

type ManagedSnapshotMeta struct {
	Source                    string
	Version                   *int
	DisplayName               string
	ParentRuntimeSnapshotName string
	Snapshotter               string
	CreatedAt                 time.Time
}

type Manager

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

func NewManager

func NewManager(log *slog.Logger, service runtimeService, networkController netctl.Controller, cfg config.WorkspaceConfig, namespace string, conn *pgxpool.Pool, queryOverride ...dbstore.Queries) *Manager

func (*Manager) BotDisplayEnabled

func (m *Manager) BotDisplayEnabled(ctx context.Context, botID string) bool

func (*Manager) CleanupBotContainer

func (m *Manager) CleanupBotContainer(ctx context.Context, botID string, preserveData bool) error

CleanupBotContainer removes the container and DB record for a bot. When preserveData is true, /data is exported to a backup archive before deletion.

func (*Manager) ClearLegacyIP

func (m *Manager) ClearLegacyIP(botID string)

ClearLegacyIP removes a cached legacy IP (e.g. when the container is deleted).

func (*Manager) ClearWorkspaceGPUPreference

func (m *Manager) ClearWorkspaceGPUPreference(ctx context.Context, botID string) error

func (*Manager) ClearWorkspaceImagePreference

func (m *Manager) ClearWorkspaceImagePreference(ctx context.Context, botID string) error

func (*Manager) ContainerID

func (m *Manager) ContainerID(ctx context.Context, botID string) (string, error)

ContainerID resolves the containerd container ID for a bot. Resolution order: DB lookup → label search → full container scan.

func (*Manager) CountData

func (m *Manager) CountData(ctx context.Context, botID string) (int, error)

CountData returns the number of regular files under the container's /data directory, read live over the gRPC bridge so it never stops the container. It is best-effort context for the export dialog; callers should treat an error (e.g. a stopped or unreachable container) as "unknown".

func (*Manager) CreateSnapshot

func (m *Manager) CreateSnapshot(ctx context.Context, botID, snapshotName, source string) (*SnapshotCreateInfo, error)

func (*Manager) CreateVersion

func (m *Manager) CreateVersion(ctx context.Context, botID string) (*VersionInfo, error)

func (*Manager) CurrentWorkspaceTargetID

func (m *Manager) CurrentWorkspaceTargetID(ctx context.Context, botID string) (string, error)

CurrentWorkspaceTargetID resolves only the request or persisted target ID. It intentionally avoids connecting to a runtime or loading target settings.

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, botID string, preserveData bool) error

func (*Manager) DisplayDialContext

func (m *Manager) DisplayDialContext(ctx context.Context, botID, network, address string) (net.Conn, error)

func (*Manager) DisplaySocketPath

func (m *Manager) DisplaySocketPath(botID string) string

DisplaySocketPath returns the host-side path to the workspace display RFB Unix socket. The directory is mounted into the container at /run/memoh.

func (*Manager) EnsureBot

func (m *Manager) EnsureBot(ctx context.Context, botID, imageOverride string) error

EnsureBot creates the workspace container for a bot if it does not exist. Bot data lives in the container's writable layer (snapshot), not bind mounts. Only the bridge binary is injected as a read-only file mount; the workspace image owns its toolkit and runtime scripts. If imageOverride is non-empty, it is used instead of the configured default.

func (*Manager) EnsureNativeRunning

func (m *Manager) EnsureNativeRunning(ctx context.Context, botID string) error

EnsureNativeRunning manages only the server-owned container workspace, regardless of which target is currently Primary.

func (*Manager) EnsureRunning

func (m *Manager) EnsureRunning(ctx context.Context, botID string) error

EnsureRunning verifies the container exists and its task is running. If the container is missing, it rebuilds via SetupBotContainer. If the task is stopped, it restarts and sets up networking.

func (*Manager) ExportData

func (m *Manager) ExportData(ctx context.Context, botID string) (io.ReadCloser, error)

ExportData streams a tar.gz archive of the container's /data directory. The container is stopped during export and restarted afterwards. Caller must consume the returned reader before the context is cancelled.

func (*Manager) GetContainerInfo

func (m *Manager) GetContainerInfo(ctx context.Context, botID string) (*ContainerStatus, error)

GetContainerInfo returns current container status for a bot, combining DB records with live containerd state.

func (*Manager) GetContainerMetrics

func (m *Manager) GetContainerMetrics(ctx context.Context, botID string) (*ContainerMetricsResult, error)

func (*Manager) GetResourceLimits

func (m *Manager) GetResourceLimits(ctx context.Context, botID string) (*ResourceLimitsResult, error)

func (*Manager) HasPreservedData

func (m *Manager) HasPreservedData(botID string) bool

HasPreservedData checks whether a backup tar.gz exists for a bot.

func (*Manager) ImportData

func (m *Manager) ImportData(ctx context.Context, botID string, r io.Reader) error

ImportData extracts a tar.gz archive into the container's /data directory. The container is stopped during import and restarted afterwards.

func (*Manager) Init

func (m *Manager) Init(ctx context.Context) error

func (*Manager) InitializeNativeWorkspace

func (m *Manager) InitializeNativeWorkspace(ctx context.Context, botID string) error

InitializeNativeWorkspace applies server-owned bootstrap content after the native workspace bridge is reachable. Remote Runtime targets intentionally do not pass through this method.

func (*Manager) IsLegacyContainer

func (*Manager) IsLegacyContainer(_ context.Context, containerID string) bool

IsLegacyContainer returns true if the container was created before the bridge process architecture (uses the legacy "mcp-" prefix). Legacy containers are functional but unreachable from the server (they use TCP gRPC instead of UDS). Users should delete and recreate them.

func (*Manager) ListBotSnapshotData

func (m *Manager) ListBotSnapshotData(ctx context.Context, botID string) (*BotSnapshotData, error)

ListBotSnapshotData returns the raw snapshot data for a bot under the per-container lock, so callers never observe transient state during snapshot/version operations.

func (*Manager) ListBots

func (m *Manager) ListBots(ctx context.Context) ([]string, error)

ListBots returns the bot IDs that have workspace containers.

func (*Manager) ListVersions

func (m *Manager) ListVersions(ctx context.Context, botID string) ([]VersionInfo, error)

func (*Manager) ListWorkspaceTargets

func (m *Manager) ListWorkspaceTargets(ctx context.Context, botID string) ([]WorkspaceTarget, error)

func (*Manager) MCPClient

func (m *Manager) MCPClient(ctx context.Context, botID string) (*bridge.Client, error)

MCPClient implements bridge.Provider and resolves the request-scoped target override before falling back to the Bot's persisted Primary target.

func (*Manager) NativeMCPClient

func (m *Manager) NativeMCPClient(ctx context.Context, botID string) (*bridge.Client, error)

func (*Manager) OnBridgeReset added in v0.20.0

func (m *Manager) OnBridgeReset(fn func(botID string))

OnBridgeReset registers fn to run each time the bridge connection for a bot is evicted from the pool — after a container restart, rebuild, snapshot replace, or a failed readiness probe. The callback receives the bot ID and runs synchronously on the resetting goroutine, so it must be cheap and must not call back into the Manager's bridge path. Use it to invalidate per-bot state derived from the workspace container process. A nil fn is ignored.

func (*Manager) PrepareImageForCreate

func (m *Manager) PrepareImageForCreate(ctx context.Context, image string, opts *ctr.PullImageOptions) (ImagePrepareResult, error)

func (*Manager) PreserveData

func (m *Manager) PreserveData(ctx context.Context, botID string) error

PreserveData exports /data to a backup tar.gz on the host. Used before deleting a container when the user chooses to preserve data. For snapshot-mount backends the caller must stop the task first so the mounted snapshot is consistent; the Apple fallback uses gRPC and does not require a stop.

func (*Manager) ReconcileContainers

func (m *Manager) ReconcileContainers(ctx context.Context)

ReconcileContainers compares the DB containers table against actual containerd state on startup. For each auto_start container in DB it verifies the container and task exist; if missing they are rebuilt.

func (*Manager) RecordContainerRunning

func (m *Manager) RecordContainerRunning(ctx context.Context, botID, containerID, image string)

RecordContainerRunning upserts a DB record marking the resolved container as running. This is exported for the HTTP handler's SSE-based creation flow, where the pull + start happen in the handler but the DB write belongs to Manager.

func (*Manager) RememberWorkspaceGPU

func (m *Manager) RememberWorkspaceGPU(ctx context.Context, botID string, gpu WorkspaceGPUConfig) error

func (*Manager) RememberWorkspaceImage

func (m *Manager) RememberWorkspaceImage(ctx context.Context, botID, image string) error

func (*Manager) ResolveWorkspaceGPU

func (m *Manager) ResolveWorkspaceGPU(ctx context.Context, botID string) (WorkspaceGPUConfig, error)

func (*Manager) ResolveWorkspaceImage

func (m *Manager) ResolveWorkspaceImage(ctx context.Context, botID string) (string, error)

func (*Manager) ResolveWorkspaceSkillDiscoveryRoots

func (m *Manager) ResolveWorkspaceSkillDiscoveryRoots(ctx context.Context, botID string) ([]string, error)

func (*Manager) ResolveWorkspaceTarget

func (m *Manager) ResolveWorkspaceTarget(ctx context.Context, botID, targetID string) (ResolvedWorkspaceTarget, error)

func (*Manager) RestorePreservedData

func (m *Manager) RestorePreservedData(ctx context.Context, botID string) error

RestorePreservedData imports preserved data (backup tar.gz) into a running container's /data.

func (*Manager) RollbackVersion

func (m *Manager) RollbackVersion(ctx context.Context, botID string, version int) error

func (*Manager) SetBridgeTLS

func (m *Manager) SetBridgeTLS(opts *BridgeTLSRuntimeOptions)

SetBridgeTLS enables strict mTLS on TCP bridge dials and injects bridge-side TLS material into new workspace containers. UDS bridge targets keep using the local filesystem trust model.

func (*Manager) SetHookService

func (m *Manager) SetHookService(h *hooks.Service)

func (*Manager) SetLegacyIP

func (m *Manager) SetLegacyIP(botID, ip string)

SetLegacyIP records the IP address of a legacy (pre-bridge) container so the gRPC pool can reach it via TCP.

func (*Manager) SetRemoteWorkspaceService

func (m *Manager) SetRemoteWorkspaceService(service *RemoteWorkspaceService)

func (*Manager) SetResourceLimits

func (m *Manager) SetResourceLimits(ctx context.Context, botID string, limits container.ResourceLimits) (*ResourceLimitsResult, error)

func (*Manager) SetSetupDiagnostics

func (m *Manager) SetSetupDiagnostics(diagnostics WorkspaceSetupDiagnostics)

func (*Manager) SetupBotContainer

func (m *Manager) SetupBotContainer(ctx context.Context, botID string) error

SetupBotContainer creates/starts the container and upserts the DB record.

func (*Manager) SetupBotContainerWithProgress

func (m *Manager) SetupBotContainerWithProgress(ctx context.Context, botID string, progress ContainerSetupProgress) error

func (*Manager) Start

func (m *Manager) Start(ctx context.Context, botID string) error

func (*Manager) StartWithImage

func (m *Manager) StartWithImage(ctx context.Context, botID, imageOverride string) error

StartWithImage creates and starts the MCP container for a bot. If imageOverride is non-empty, it is used as the base image instead of the configured default. The override only applies when creating a new container.

func (*Manager) StartWithResolvedConfig

func (m *Manager) StartWithResolvedConfig(ctx context.Context, botID, image string, gpu WorkspaceGPUConfig) error

func (*Manager) StartWithResolvedImage

func (m *Manager) StartWithResolvedImage(ctx context.Context, botID, image string) error

StartWithResolvedImage creates and starts the workspace container for a bot using an explicit image reference.

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context, botID string, timeout time.Duration) error

func (*Manager) StopBot

func (m *Manager) StopBot(ctx context.Context, botID string) error

StopBot stops the container task for a bot and marks it stopped in DB.

func (*Manager) VersionSnapshotName

func (m *Manager) VersionSnapshotName(ctx context.Context, botID string, version int) (string, error)

func (*Manager) WaitForWorkspaceReady

func (m *Manager) WaitForWorkspaceReady(ctx context.Context, botID string) error

func (*Manager) WorkspaceInfo

func (m *Manager) WorkspaceInfo(ctx context.Context, botID string) (bridge.WorkspaceInfo, error)

type RemoteWorkspaceService

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

RemoteWorkspaceService owns persistent remote mounts. Live runtime connections remain owned by userruntime.Service.

func (*RemoteWorkspaceService) DeleteMount

func (s *RemoteWorkspaceService) DeleteMount(ctx context.Context, botID, targetID string) error

func (*RemoteWorkspaceService) EnsurePrimaryReady

func (s *RemoteWorkspaceService) EnsurePrimaryReady(ctx context.Context, botID string) (bool, error)

func (*RemoteWorkspaceService) GetMount

func (s *RemoteWorkspaceService) GetMount(ctx context.Context, botID, targetID string) (WorkspaceTarget, error)

func (*RemoteWorkspaceService) GetPrimaryMount

func (s *RemoteWorkspaceService) GetPrimaryMount(ctx context.Context, botID string) (WorkspaceTarget, error)

func (*RemoteWorkspaceService) ListAccountGrants

func (s *RemoteWorkspaceService) ListAccountGrants(ctx context.Context, ownerUserID string) ([]WorkspaceTargetGrant, error)

ListAccountGrants is the reverse lookup behind the account Computers page: every live mount held by the owner's bots, across all of their runtimes.

func (*RemoteWorkspaceService) ListMounts

func (s *RemoteWorkspaceService) ListMounts(ctx context.Context, botID string) ([]WorkspaceTarget, error)

func (*RemoteWorkspaceService) Mount

func (s *RemoteWorkspaceService) Mount(ctx context.Context, botID, runtimeID string) (WorkspaceTarget, error)

func (*RemoteWorkspaceService) ResolveMount

func (s *RemoteWorkspaceService) ResolveMount(ctx context.Context, botID, targetID string) (ResolvedWorkspaceTarget, error)

func (*RemoteWorkspaceService) ResolvePrimary

func (*RemoteWorkspaceService) SetPrimary

func (s *RemoteWorkspaceService) SetPrimary(ctx context.Context, botID, targetID string) error

func (*RemoteWorkspaceService) UpdateToolApproval

func (s *RemoteWorkspaceService) UpdateToolApproval(ctx context.Context, botID, targetID string, modes WorkspaceTargetToolApproval) error

func (*RemoteWorkspaceService) UpdateToolApprovalConfig

func (s *RemoteWorkspaceService) UpdateToolApprovalConfig(ctx context.Context, botID, targetID string, config settings.ToolApprovalConfig) error

type ResolvedWorkspaceTarget

type ResolvedWorkspaceTarget struct {
	TargetID string
	Kind     string
	Name     string
	Primary  bool
	Client   *bridge.Client
	Info     bridge.WorkspaceInfo
	Approval settings.ToolApprovalConfig
}

type ResourceLimitCapabilities

type ResourceLimitCapabilities struct {
	CPU     ResourceLimitCapability
	Memory  ResourceLimitCapability
	Storage ResourceLimitCapability
}

func ResourceLimitCapabilitiesFor

func ResourceLimitCapabilitiesFor(workspaceBackend, runtimeBackend string) ResourceLimitCapabilities

type ResourceLimitCapability

type ResourceLimitCapability struct {
	HardLimitSupported bool
	SoftLimitSupported bool
}

type ResourceLimitObserved

type ResourceLimitObserved struct {
	CPUUsagePercent      float64
	MemoryUsageBytes     uint64
	MemoryLimitBytes     uint64
	StorageUsedBytes     uint64
	StorageOverSoftLimit bool
}

type ResourceLimitsResult

type ResourceLimitsResult struct {
	Desired          container.ResourceLimits
	Applied          container.ResourceLimits
	Capabilities     ResourceLimitCapabilities
	Observed         ResourceLimitObserved
	Status           string
	RequiresRecreate bool
	WorkspaceBackend string
	RuntimeBackend   string
}

type SetPrimaryWorkspaceTargetRequest

type SetPrimaryWorkspaceTargetRequest struct {
	TargetID string `json:"target_id" validate:"required"`
}

type SnapshotCreateInfo

type SnapshotCreateInfo struct {
	ContainerID         string
	SnapshotName        string
	RuntimeSnapshotName string
	DisplayName         string
	Snapshotter         string
	Version             int
	CreatedAt           time.Time
}

type TemplateBootstrapper

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

TemplateBootstrapper copies the canonical embedded template tree into one provider-owned workspace filesystem.

func NewTemplateBootstrapper

func NewTemplateBootstrapper(source fs.FS) *TemplateBootstrapper

func (*TemplateBootstrapper) Bootstrap

func (b *TemplateBootstrapper) Bootstrap(ctx context.Context, target WorkspaceFileSystem, root string) error

Bootstrap applies the built-in workspace template under root. User-owned files are create-only, while files belonging to built-in skills are managed and refreshed on every reconciliation. Extra user skills are never removed.

type UpdateWorkspaceTargetToolApprovalRequest

type UpdateWorkspaceTargetToolApprovalRequest struct {
	Enabled            *bool                        `json:"enabled,omitempty"`
	Read               settings.ToolApprovalMode    `json:"read,omitempty"`
	Write              settings.ToolApprovalMode    `json:"write,omitempty"`
	Exec               settings.ToolApprovalMode    `json:"exec,omitempty"`
	ToolApprovalConfig *settings.ToolApprovalConfig `json:"tool_approval_config,omitempty"`
}

type VersionInfo

type VersionInfo struct {
	ID                  string
	Version             int
	SnapshotName        string
	RuntimeSnapshotName string
	DisplayName         string
	CreatedAt           time.Time
}

type WorkspaceFileInfo

type WorkspaceFileInfo struct {
	IsDir bool
}

WorkspaceFileInfo is the provider-neutral subset of file metadata needed by the workspace bootstrapper.

type WorkspaceFileSystem

type WorkspaceFileSystem interface {
	Stat(ctx context.Context, filePath string) (WorkspaceFileInfo, error)
	Mkdir(ctx context.Context, dirPath string) error
	WriteFile(ctx context.Context, filePath string, content []byte) error
	Rename(ctx context.Context, oldPath, newPath string) error
}

WorkspaceFileSystem is the minimal filesystem contract needed to seed a workspace. Container workspaces adapt bridge.Client; future providers such as E2B can implement this contract directly without running the Memoh bridge. Implementations must return an error matching fs.ErrNotExist for a missing path and make Mkdir recursive.

type WorkspaceGPUConfig

type WorkspaceGPUConfig struct {
	Devices []string `json:"devices,omitempty"`
}

type WorkspaceSetupDiagnostics

type WorkspaceSetupDiagnostics interface {
	RecordContainerSetupFailure(ctx context.Context, botID, phase string, setupErr error) error
	ClearContainerSetupFailure(ctx context.Context, botID string) error
}

WorkspaceSetupDiagnostics records sanitized setup failures for Bot health checks without coupling the workspace package to the bots package.

type WorkspaceTarget

type WorkspaceTarget struct {
	TargetID           string                      `json:"target_id"`
	Kind               string                      `json:"kind"`
	RuntimeID          string                      `json:"runtime_id,omitempty"`
	Name               string                      `json:"name"`
	Primary            bool                        `json:"primary"`
	Online             bool                        `json:"online"`
	Status             string                      `json:"status"`
	ToolApproval       WorkspaceTargetToolApproval `json:"tool_approval"`
	ToolApprovalConfig settings.ToolApprovalConfig `json:"tool_approval_config"`
}

WorkspaceTarget is the aggregate shape consumed by clients. Callers address mounts by TargetID; RuntimeID identifies the backing remote Runtime and is empty for the Native target.

type WorkspaceTargetGrant

type WorkspaceTargetGrant struct {
	TargetID  string `json:"target_id"`
	BotID     string `json:"bot_id"`
	RuntimeID string `json:"runtime_id"`
	Primary   bool   `json:"primary"`
}

WorkspaceTargetGrant is one entry of the account-level ACL view: bot BotID may use the owner's runtime RuntimeID, addressable as mount TargetID.

type WorkspaceTargetGrantsResponse

type WorkspaceTargetGrantsResponse struct {
	Grants []WorkspaceTargetGrant `json:"grants"`
}

type WorkspaceTargetToolApproval

type WorkspaceTargetToolApproval struct {
	Read  settings.ToolApprovalMode `json:"read"`
	Write settings.ToolApprovalMode `json:"write"`
	Exec  settings.ToolApprovalMode `json:"exec"`
}

type WorkspaceTargetsResponse

type WorkspaceTargetsResponse struct {
	Targets []WorkspaceTarget `json:"targets"`
}

Directories

Path Synopsis
Package bridge provides a gRPC client for the workspace container bridge service.
Package bridge provides a gRPC client for the workspace container bridge service.
Package vpath resolves user-supplied paths under a virtual workspace root without consulting the host filesystem.
Package vpath resolves user-supplied paths under a virtual workspace root without consulting the host filesystem.

Jump to

Keyboard shortcuts

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