Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompanionOpts ¶
type CompanionOpts struct {
// Name is a short name for this companion instance. When using the Docker
// backend, the container name is prefixed with "codefly-" (e.g. codefly-lsp-go-123).
Name string
// SourceDir is the host directory to mount as /workspace (or work in).
SourceDir string
// Image is the Docker image (required for Docker backend, ignored otherwise).
Image *resources.DockerImage
// PreferredBackend forces a specific backend. If empty, auto-detect.
PreferredBackend Backend
}
CompanionOpts configures companion runner creation.
type CompanionRunner ¶
type CompanionRunner interface {
// WithMount makes a host directory visible inside the companion.
// Docker: bind mount. Nix/Local: no-op (already on host).
WithMount(hostPath, targetPath string)
// WithPortMapping maps a companion port to a host port.
// Docker: Docker port mapping. Nix/Local: no-op (same network).
WithPortMapping(ctx context.Context, hostPort, companionPort uint16)
// WithWorkDir sets the working directory for all processes.
WithWorkDir(dir string)
// WithPause keeps the environment alive after Init.
// Docker: runs `sleep infinity`. Nix/Local: no-op.
WithPause()
// Init starts the environment.
Init(ctx context.Context) error
// NewProcess creates a process inside the companion.
NewProcess(bin string, args ...string) (base.Proc, error)
// Shutdown stops and cleans up all resources.
// Safe to call multiple times.
Shutdown(ctx context.Context) error
// RunnerEnv returns the underlying RunnerEnvironment for callers that need
// WithEnvironmentVariables, WithBinary, etc. Same lifecycle as this companion.
RunnerEnv() base.RunnerEnvironment
// Backend returns which backend is in use (e.g. for path or port decisions).
Backend() Backend
}
CompanionRunner is the golden wrapper for running companions.
It provides a unified interface that works across Docker, Nix, and local runners. Consumers (LSP, code generation, etc.) program against this interface and never care which backend is running underneath.
- Docker: full isolation, mounts, port mapping
- Nix: reproducible env via flake.nix, no isolation overhead
- Local: direct host execution, zero overhead
Use NewCompanionRunner to create one -- it picks the best available backend.
func NewCompanionRunner ¶
func NewCompanionRunner(ctx context.Context, opts CompanionOpts) (CompanionRunner, error)
NewCompanionRunner creates a companion runner using the best available backend.
Selection order (unless PreferredBackend is set):
- Docker -- if Docker is running and Image is provided
- Nix -- if flake.nix exists in SourceDir (future)
- Local -- always available as fallback
Click to show internal directories.
Click to hide internal directories.