plugin

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(src, dst string, perm os.FileMode) error

CopyFile copies a single file from src to dst with the given permissions. Shared by plugins that stage host files into workspace state directories.

func InferOwner

func InferOwner(user string) string

InferOwner returns the container user for chown operations. Empty user maps to "root", otherwise returns the user as-is.

func InferRemoteHome

func InferRemoteHome(user string) string

InferRemoteHome returns the home directory path for the given user inside the container. Root or empty user maps to /root, others to /home/{user}. Used by plugins that need to place files in the container user's home before the container exists.

func ShellQuote added in v0.7.1

func ShellQuote(s string) string

ShellQuote escapes single quotes in s for safe embedding in single-quoted shell strings. The result is the inner content, not the outer quotes.

func ShellQuoteJoin added in v0.7.1

func ShellQuoteJoin(args []string) string

ShellQuoteJoin single-quotes each argument and joins them with spaces, producing a shell-safe command string. Arguments with spaces, single quotes, or metacharacters are preserved as single tokens.

Types

type BasePlugin added in v0.8.0

type BasePlugin struct{}

BasePlugin provides no-op implementations of optional Plugin methods. Embed it in plugin structs to satisfy the interface without boilerplate.

func (BasePlugin) PostContainerCreate added in v0.8.0

PostContainerCreate is a no-op. Override in plugins that need post-creation logic.

func (BasePlugin) PreContainerRun added in v0.8.0

PreContainerRun is a no-op. Override in plugins that need pre-run logic.

type ExecFunc added in v0.8.0

type ExecFunc func(ctx context.Context, cmd []string, user string, workDir string) ([]byte, error)

ExecFunc runs a command inside the container. Returns combined output and error.

type FileCopy

type FileCopy struct {
	Source      string // path on host
	Target      string // path inside container
	Mode        string // chmod mode (e.g. "0600"), empty for default
	User        string // chown user inside container (e.g. "vscode"), empty for default
	IfNotExists bool   // skip copy if the target file already exists in the container
}

FileCopy describes a file to copy into the container after creation.

type Manager

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

Manager holds registered plugins and dispatches events to them.

func NewManager

func NewManager(logger *slog.Logger) *Manager

NewManager creates a Manager with the given logger.

func (*Manager) Register

func (m *Manager) Register(p Plugin)

Register adds a plugin to the manager.

func (*Manager) RunPostContainerCreate added in v0.8.0

func (m *Manager) RunPostContainerCreate(ctx context.Context, req *PostContainerCreateRequest)

RunPostContainerCreate dispatches the post-container-create event to all registered plugins. Called between create-time hooks (postCreateCommand) and start-time hooks (postStartCommand). Errors are logged and skipped (fail-open).

func (*Manager) RunPreContainerRun

func (m *Manager) RunPreContainerRun(ctx context.Context, req *PreContainerRunRequest) (*PreContainerRunResponse, error)

RunPreContainerRun dispatches the pre-container-run event to all registered plugins and merges their responses. Mounts and RunArgs are appended in plugin order. Env vars are merged with last-plugin-wins on conflicts. Plugin errors are logged and skipped (fail-open).

func (*Manager) SetProgress added in v0.5.0

func (m *Manager) SetProgress(fn func(string))

SetProgress sets a callback for user-facing progress messages (e.g. "Running plugin: foo").

type Plugin

type Plugin interface {
	Name() string
	PreContainerRun(ctx context.Context, req *PreContainerRunRequest) (*PreContainerRunResponse, error)
	PostContainerCreate(ctx context.Context, req *PostContainerCreateRequest) (*PostContainerCreateResponse, error)
}

Plugin is the interface all plugins implement.

type PostContainerCreateRequest added in v0.8.0

type PostContainerCreateRequest struct {
	WorkspaceID     string
	WorkspaceDir    string
	ContainerID     string
	RemoteUser      string
	WorkspaceFolder string
	Exec            ExecFunc
	StreamExec      StreamExecFunc
}

PostContainerCreateRequest provides context for post-creation hooks. Plugins that need to run commands inside the container (e.g. dotfiles installation) use the Exec callback (captured) or StreamExec (streamed).

type PostContainerCreateResponse added in v0.8.0

type PostContainerCreateResponse struct{}

PostContainerCreateResponse carries results from post-creation hooks. Empty for now, keeps the interface consistent with PreContainerRun.

type PreContainerRunRequest

type PreContainerRunRequest struct {
	WorkspaceID     string         // unique workspace identifier
	WorkspaceDir    string         // ~/.crib/workspaces/{id}/
	SourceDir       string         // project root on host
	Runtime         string         // "docker" or "podman"
	ImageName       string         // resolved image name
	RemoteUser      string         // user inside the container
	WorkspaceFolder string         // path inside container
	ContainerName   string         // crib-{workspace-id}
	Customizations  map[string]any // customizations.crib from devcontainer.json
}

PreContainerRunRequest carries context about the workspace and container that is about to be created. Plugins use this to decide what mounts, env vars, or extra args to inject.

type PreContainerRunResponse

type PreContainerRunResponse struct {
	Mounts      []config.Mount
	Env         map[string]string
	RunArgs     []string
	Copies      []FileCopy
	PathPrepend []string // absolute paths to prepend to PATH in remoteEnv
}

PreContainerRunResponse carries additions that the plugin wants injected into the container run command. Nil means no-op.

type StreamExecFunc added in v0.8.0

type StreamExecFunc func(ctx context.Context, cmd []string, user string, workDir string, stdout, stderr io.Writer) error

StreamExecFunc runs a command inside the container, streaming stdout and stderr to the provided writers instead of capturing them.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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