Documentation
¶
Index ¶
- Constants
- func CheckForRuntimes(ctx context.Context, requirements []*agentv0.Runtime) error
- func CheckNixInstalled() bool
- func CheckPythonPath() (string, error)
- func ContainerName(name string) string
- func DockerEngineRunning(ctx context.Context) bool
- func FindFreePort() (int, error)
- func Forward(ctx context.Context, reader io.Reader, writer io.Writer)
- func GetImageID(im *resources.DockerImage) (string, error)
- func GetImageIfNotPresent(ctx context.Context, c *client.Client, imag *resources.DockerImage, ...) error
- func ImageExists(ctx context.Context, c *client.Client, imag *resources.DockerImage) (bool, error)
- func IsFreePort(port int) bool
- func IsNixSupported() bool
- func NixInstallCommand() string
- func PrintDownloadPercentage(reader io.ReadCloser, out io.Writer)
- func ReapStaleContainers(ctx context.Context) error
- func ReapStaleProcessGroups(ctx context.Context) error
- func RemovePgidFile(pgid int) error
- func WaitForPortUnbound(ctx context.Context, port int) error
- func WritePgidFile(pgid int, cwd string, argv []string) error
- type Backend
- type CPU
- type CompanionOpts
- type CompanionRunner
- type DockerContainerInstance
- type DockerEnvironment
- func (docker *DockerEnvironment) ContainerDeleted() (bool, error)
- func (docker *DockerEnvironment) ContainerID() (string, error)
- func (docker *DockerEnvironment) GetContainer(ctx context.Context) error
- func (docker *DockerEnvironment) GetImageIfNotPresent(ctx context.Context, imag *resources.DockerImage) error
- func (docker *DockerEnvironment) GetLogs(ctx context.Context) error
- func (docker *DockerEnvironment) ImageExists(ctx context.Context, imag *resources.DockerImage) (bool, error)
- func (docker *DockerEnvironment) Init(ctx context.Context) error
- func (docker *DockerEnvironment) IsContainerPresent(ctx context.Context) (bool, error)
- func (docker *DockerEnvironment) NewProcess(bin string, args ...string) (Proc, error)
- func (docker *DockerEnvironment) PortMappings() []*DockerPortMapping
- func (docker *DockerEnvironment) Shutdown(ctx context.Context) error
- func (docker *DockerEnvironment) Stop(ctx context.Context) error
- func (docker *DockerEnvironment) WithBinary(bin string) error
- func (docker *DockerEnvironment) WithCommand(cmd ...string)
- func (docker *DockerEnvironment) WithDir(dir string)
- func (docker *DockerEnvironment) WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
- func (docker *DockerEnvironment) WithMount(sourceDir string, targetDir string)
- func (docker *DockerEnvironment) WithOutput(w io.Writer)
- func (docker *DockerEnvironment) WithPause()
- func (docker *DockerEnvironment) WithPort(ctx context.Context, port uint16)
- func (docker *DockerEnvironment) WithPortMapping(ctx context.Context, local uint16, container uint16)
- func (docker *DockerEnvironment) WithWorkDir(dir string)
- type DockerPortMapping
- type DockerProc
- func (proc *DockerProc) FindPid(ctx context.Context) (int, error)
- func (proc *DockerProc) IsRunning(ctx context.Context) (bool, error)
- func (proc *DockerProc) Match(cmd []string) bool
- func (proc *DockerProc) Run(ctx context.Context) error
- func (proc *DockerProc) Start(ctx context.Context) error
- func (proc *DockerProc) StdinPipe() (io.WriteCloser, error)
- func (proc *DockerProc) StdoutPipe() (io.ReadCloser, error)
- func (proc *DockerProc) Stop(ctx context.Context) error
- func (proc *DockerProc) Wait(ctx context.Context) error
- func (proc *DockerProc) WaitOn(bin string)
- func (proc *DockerProc) WithDir(dir string)
- func (proc *DockerProc) WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
- func (proc *DockerProc) WithEnvironmentVariablesAppend(ctx context.Context, added *resources.EnvironmentVariable, sep string)
- func (proc *DockerProc) WithOutput(output io.Writer)
- type DockerPullResponse
- type Event
- type Memory
- type NativeEnvironment
- func (native *NativeEnvironment) Init(ctx context.Context) error
- func (native *NativeEnvironment) NewProcess(bin string, args ...string) (Proc, error)
- func (native *NativeEnvironment) Shutdown(context.Context) error
- func (native *NativeEnvironment) Stop(context.Context) error
- func (native *NativeEnvironment) WithBinary(bin string) error
- func (native *NativeEnvironment) WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
- type NativeProc
- func (proc *NativeProc) Forward(_ context.Context, r io.Reader)
- func (proc *NativeProc) IsRunning(ctx context.Context) (bool, error)
- func (proc *NativeProc) Run(ctx context.Context) error
- func (proc *NativeProc) Start(ctx context.Context) error
- func (proc *NativeProc) StdinPipe() (io.WriteCloser, error)
- func (proc *NativeProc) StdoutPipe() (io.ReadCloser, error)
- func (proc *NativeProc) Stop(ctx context.Context) error
- func (proc *NativeProc) Wait(ctx context.Context) error
- func (proc *NativeProc) WaitOn(bin string)
- func (proc *NativeProc) WithDir(dir string)
- func (proc *NativeProc) WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
- func (proc *NativeProc) WithEnvironmentVariablesAppend(ctx context.Context, added *resources.EnvironmentVariable, sep string)
- func (proc *NativeProc) WithOutput(output io.Writer)
- func (proc *NativeProc) WithRunningCmd(_ string)
- type NixEnvironment
- func (nix *NixEnvironment) Init(ctx context.Context) error
- func (nix *NixEnvironment) NewProcess(bin string, args ...string) (Proc, error)
- func (nix *NixEnvironment) Shutdown(context.Context) error
- func (nix *NixEnvironment) Stop(context.Context) error
- func (nix *NixEnvironment) WithBinary(_ string) error
- func (nix *NixEnvironment) WithCacheDir(dir string)
- func (nix *NixEnvironment) WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
- type NixProc
- func (proc *NixProc) IsRunning(ctx context.Context) (bool, error)
- func (proc *NixProc) Run(ctx context.Context) error
- func (proc *NixProc) Start(ctx context.Context) error
- func (proc *NixProc) StdinPipe() (io.WriteCloser, error)
- func (proc *NixProc) StdoutPipe() (io.ReadCloser, error)
- func (proc *NixProc) Stop(ctx context.Context) error
- func (proc *NixProc) Wait(ctx context.Context) error
- func (proc *NixProc) WaitOn(bin string)
- func (proc *NixProc) WithDir(dir string)
- func (proc *NixProc) WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
- func (proc *NixProc) WithEnvironmentVariablesAppend(_ context.Context, added *resources.EnvironmentVariable, sep string)
- func (proc *NixProc) WithOutput(output io.Writer)
- func (proc *NixProc) WithRunningCmd(_ string)
- type Proc
- type ProcessState
- type ProgressDetail
- type RunnerEnvironment
- type Tracked
- type TrackedProcess
Constants ¶
const ( LabelCodeflyOwner = "codefly.owner" // always "true" LabelCodeflySession = "codefly.session" // PID of the spawning CLI LabelCodeflyName = "codefly.name" // container's logical name )
Container labels used by the startup sweep to identify codefly-owned containers and their spawning CLI. These are set on every container created via DockerEnvironment and consumed by ReapStaleContainers.
Variables ¶
This section is empty.
Functions ¶
func CheckForRuntimes ¶
func CheckNixInstalled ¶ added in v0.1.155
func CheckNixInstalled() bool
CheckNixInstalled checks if Nix is available in PATH
func CheckPythonPath ¶
func ContainerName ¶
func DockerEngineRunning ¶
func FindFreePort ¶ added in v0.1.155
FindFreePort asks the OS to assign a free TCP port and returns it.
func GetImageID ¶ added in v0.1.121
func GetImageID(im *resources.DockerImage) (string, error)
func GetImageIfNotPresent ¶ added in v0.1.124
func ImageExists ¶ added in v0.1.124
func IsFreePort ¶
func IsNixSupported ¶ added in v0.1.155
func IsNixSupported() bool
IsNixSupported returns true if the current OS supports Nix
func NixInstallCommand ¶ added in v0.1.155
func NixInstallCommand() string
NixInstallCommand returns the command to install Nix based on OS
func PrintDownloadPercentage ¶
func PrintDownloadPercentage(reader io.ReadCloser, out io.Writer)
func ReapStaleContainers ¶ added in v0.1.155
ReapStaleContainers lists all containers carrying LabelCodeflyOwner and removes the ones whose LabelCodeflySession PID is no longer alive. Best-effort: a single failed remove is logged and the sweep continues. Safe to call when Docker isn't running — returns nil (just no sweep).
func ReapStaleProcessGroups ¶ added in v0.1.155
ReapStaleProcessGroups scans ~/.codefly/runs/*.pgid and tree-kills any process group that is still alive — these are orphans left behind by a prior ungraceful CLI exit (SIGKILL of the parent, terminal force-closed, etc). The pgid file is removed either way. Best-effort: a single failed reap does not short-circuit the sweep.
Call this once at the top of `codefly run service`, before any new children are spawned. Idempotent and safe when no files exist.
Convergence: when a parent agent and its NativeProc grandchild both have files, directory order can cause the grandchild to be visited while its parent is still live (so we skip it), then the parent gets reaped a few iterations later. We loop up to maxSweepPasses so a single call resolves the whole orphan tree without relying on a subsequent `codefly run`.
func RemovePgidFile ¶ added in v0.1.155
RemovePgidFile drops the tracking file for a pgid after graceful stop.
func WaitForPortUnbound ¶
WaitForPortUnbound waits for the portMappings to be unbound
func WritePgidFile ¶ added in v0.1.155
WritePgidFile is the exported entry point used by spawners outside this package (agent manager, MCP mutation tools) that use Setpgid:true and need their groups reaped on ungraceful parent death. NativeProc calls the unexported wrapper.
Types ¶
type Backend ¶ added in v0.1.155
type Backend string
Backend identifies which runner backend is in use.
type CompanionOpts ¶ added in v0.1.155
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 ¶ added in v0.1.155
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) (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() 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 ¶ added in v0.1.155
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
type DockerContainerInstance ¶
type DockerContainerInstance struct {
ID string
}
type DockerEnvironment ¶
type DockerEnvironment struct {
// contains filtered or unexported fields
}
func NewDockerEnvironment ¶
func NewDockerEnvironment(ctx context.Context, image *resources.DockerImage, dir, name string) (*DockerEnvironment, error)
NewDockerEnvironment creates a new docker environment.
If GetImageIfNotPresent fails, the docker client is closed before returning the error so the caller doesn't have to know about the half-constructed env (and isn't expected to call Shutdown on a nil return). Same defensive close in NewDockerHeadlessEnvironment.
func NewDockerHeadlessEnvironment ¶
func NewDockerHeadlessEnvironment(ctx context.Context, image *resources.DockerImage, name string) (*DockerEnvironment, error)
NewDockerHeadlessEnvironment creates a new docker runner
func (*DockerEnvironment) ContainerDeleted ¶ added in v0.1.89
func (docker *DockerEnvironment) ContainerDeleted() (bool, error)
ContainerDeleted checks if the container with ID is gone
func (*DockerEnvironment) ContainerID ¶
func (docker *DockerEnvironment) ContainerID() (string, error)
func (*DockerEnvironment) GetContainer ¶
func (docker *DockerEnvironment) GetContainer(ctx context.Context) error
func (*DockerEnvironment) GetImageIfNotPresent ¶ added in v0.1.87
func (docker *DockerEnvironment) GetImageIfNotPresent(ctx context.Context, imag *resources.DockerImage) error
func (*DockerEnvironment) GetLogs ¶ added in v0.1.89
func (docker *DockerEnvironment) GetLogs(ctx context.Context) error
func (*DockerEnvironment) ImageExists ¶
func (docker *DockerEnvironment) ImageExists(ctx context.Context, imag *resources.DockerImage) (bool, error)
func (*DockerEnvironment) IsContainerPresent ¶
func (docker *DockerEnvironment) IsContainerPresent(ctx context.Context) (bool, error)
func (*DockerEnvironment) NewProcess ¶
func (docker *DockerEnvironment) NewProcess(bin string, args ...string) (Proc, error)
func (*DockerEnvironment) PortMappings ¶ added in v0.1.155
func (docker *DockerEnvironment) PortMappings() []*DockerPortMapping
func (*DockerEnvironment) Shutdown ¶
func (docker *DockerEnvironment) Shutdown(ctx context.Context) error
func (*DockerEnvironment) WithBinary ¶ added in v0.1.91
func (docker *DockerEnvironment) WithBinary(bin string) error
func (*DockerEnvironment) WithCommand ¶
func (docker *DockerEnvironment) WithCommand(cmd ...string)
func (*DockerEnvironment) WithDir ¶
func (docker *DockerEnvironment) WithDir(dir string)
func (*DockerEnvironment) WithEnvironmentVariables ¶
func (docker *DockerEnvironment) WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
func (*DockerEnvironment) WithMount ¶
func (docker *DockerEnvironment) WithMount(sourceDir string, targetDir string)
func (*DockerEnvironment) WithOutput ¶
func (docker *DockerEnvironment) WithOutput(w io.Writer)
func (*DockerEnvironment) WithPause ¶
func (docker *DockerEnvironment) WithPause()
func (*DockerEnvironment) WithPort ¶
func (docker *DockerEnvironment) WithPort(ctx context.Context, port uint16)
func (*DockerEnvironment) WithPortMapping ¶
func (docker *DockerEnvironment) WithPortMapping(ctx context.Context, local uint16, container uint16)
func (*DockerEnvironment) WithWorkDir ¶
func (docker *DockerEnvironment) WithWorkDir(dir string)
type DockerPortMapping ¶
type DockerProc ¶
type DockerProc struct {
ID string
// contains filtered or unexported fields
}
func (*DockerProc) FindPid ¶ added in v0.1.88
func (proc *DockerProc) FindPid(ctx context.Context) (int, error)
FindPid locates the PID of the matching child process inside the container by scanning /proc. /proc is guaranteed on every Linux container; `ps` is not (debian-slim images ship without procps, Alpine busybox has a different flag set). Output format is one line per PID:
<pid>\t<cmdline-space-separated>
where cmdline is the full argv reconstructed from /proc/<pid>/cmdline (NUL-separated in the kernel — we convert NUL→space for splitting).
func (*DockerProc) IsRunning ¶ added in v0.1.109
func (proc *DockerProc) IsRunning(ctx context.Context) (bool, error)
func (*DockerProc) Match ¶ added in v0.1.89
func (proc *DockerProc) Match(cmd []string) bool
func (*DockerProc) StdinPipe ¶ added in v0.1.155
func (proc *DockerProc) StdinPipe() (io.WriteCloser, error)
func (*DockerProc) StdoutPipe ¶ added in v0.1.155
func (proc *DockerProc) StdoutPipe() (io.ReadCloser, error)
func (*DockerProc) Wait ¶ added in v0.1.155
func (proc *DockerProc) Wait(ctx context.Context) error
Wait blocks until the container process exits or ctx is cancelled. Polls IsRunning since Docker doesn't expose a clean blocking-wait here.
func (*DockerProc) WaitOn ¶ added in v0.1.107
func (proc *DockerProc) WaitOn(bin string)
func (*DockerProc) WithDir ¶ added in v0.1.103
func (proc *DockerProc) WithDir(dir string)
func (*DockerProc) WithEnvironmentVariables ¶
func (proc *DockerProc) WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
func (*DockerProc) WithEnvironmentVariablesAppend ¶ added in v0.1.144
func (proc *DockerProc) WithEnvironmentVariablesAppend(ctx context.Context, added *resources.EnvironmentVariable, sep string)
func (*DockerProc) WithOutput ¶
func (proc *DockerProc) WithOutput(output io.Writer)
type DockerPullResponse ¶
type DockerPullResponse struct {
ID string `json:"id"`
Status string `json:"status"`
ProgressDetail ProgressDetail `json:"progressDetail"`
}
type Event ¶
type Event struct {
// Err is the state of error of the service
Err error
// Status is the state of the service
ProcessState
// CPU
*observabilityv0.CPU
// Memory
*observabilityv0.Memory
}
Event represents data of a **running** service Generic so most fields will be nil
type NativeEnvironment ¶ added in v0.1.89
type NativeEnvironment struct {
// contains filtered or unexported fields
}
func NewNativeEnvironment ¶ added in v0.1.89
func NewNativeEnvironment(ctx context.Context, dir string) (*NativeEnvironment, error)
NewNativeEnvironment creates a new native runner. It runs processes directly on the host using whatever is in PATH.
func (*NativeEnvironment) Init ¶ added in v0.1.89
func (native *NativeEnvironment) Init(ctx context.Context) error
func (*NativeEnvironment) NewProcess ¶ added in v0.1.89
func (native *NativeEnvironment) NewProcess(bin string, args ...string) (Proc, error)
func (*NativeEnvironment) Shutdown ¶ added in v0.1.89
func (native *NativeEnvironment) Shutdown(context.Context) error
func (*NativeEnvironment) Stop ¶ added in v0.1.89
func (native *NativeEnvironment) Stop(context.Context) error
func (*NativeEnvironment) WithBinary ¶ added in v0.1.91
func (native *NativeEnvironment) WithBinary(bin string) error
func (*NativeEnvironment) WithEnvironmentVariables ¶ added in v0.1.89
func (native *NativeEnvironment) WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
type NativeProc ¶ added in v0.1.89
type NativeProc struct {
// contains filtered or unexported fields
}
func (*NativeProc) Forward ¶ added in v0.1.89
func (proc *NativeProc) Forward(_ context.Context, r io.Reader)
Forward streams r → proc.output one line at a time with newlines intact. The previous implementation used strings.TrimSpace which dropped the trailing newline between lines, so JSON-lines events merged and the log prefix was re-applied per Write call against zero-byte separators. Plain io.Copy fixed the newline loss but collapsed all output into a single prefix block — worse for interactive tailing. forwardLines strikes the middle: scanner gives per-line Write boundaries (so log prefixes apply correctly), newline is re-appended so downstream parsers see the real separator, and the scanner buffer is sized for 1MiB lines so large structured-log events don't silently truncate.
func (*NativeProc) IsRunning ¶ added in v0.1.109
func (proc *NativeProc) IsRunning(ctx context.Context) (bool, error)
IsRunning checks if the exec is still running
func (*NativeProc) Start ¶ added in v0.1.89
func (proc *NativeProc) Start(ctx context.Context) error
func (*NativeProc) StdinPipe ¶ added in v0.1.155
func (proc *NativeProc) StdinPipe() (io.WriteCloser, error)
func (*NativeProc) StdoutPipe ¶ added in v0.1.155
func (proc *NativeProc) StdoutPipe() (io.ReadCloser, error)
func (*NativeProc) Wait ¶ added in v0.1.155
func (proc *NativeProc) Wait(ctx context.Context) error
Wait blocks until the process exits or ctx is cancelled. Returns the process's exit error (nil on clean exit). Safe to call multiple times.
func (*NativeProc) WaitOn ¶ added in v0.1.107
func (proc *NativeProc) WaitOn(bin string)
func (*NativeProc) WithDir ¶ added in v0.1.103
func (proc *NativeProc) WithDir(dir string)
func (*NativeProc) WithEnvironmentVariables ¶ added in v0.1.89
func (proc *NativeProc) WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
func (*NativeProc) WithEnvironmentVariablesAppend ¶ added in v0.1.144
func (proc *NativeProc) WithEnvironmentVariablesAppend(ctx context.Context, added *resources.EnvironmentVariable, sep string)
func (*NativeProc) WithOutput ¶ added in v0.1.89
func (proc *NativeProc) WithOutput(output io.Writer)
func (*NativeProc) WithRunningCmd ¶ added in v0.1.89
func (proc *NativeProc) WithRunningCmd(_ string)
type NixEnvironment ¶ added in v0.1.155
type NixEnvironment struct {
// contains filtered or unexported fields
}
NixEnvironment runs processes inside a Nix development shell.
Two modes:
- Wrapped (default before Init): each NewProcess wraps the command in `nix develop <dir> --command <bin> <args...>`. Re-evaluates the flake every call — expensive.
- Materialized (after Init): `nix print-dev-env --json <dir>` is run once to capture the devShell's exported variables. Later NewProcess calls exec `bin` directly with that env, skipping `nix develop` entirely on the hot path. This is what makes Test calls fast once the agent has been through Init.
Binaries come from the flake.nix, so WithBinary is a no-op.
func NewNixEnvironment ¶ added in v0.1.155
func NewNixEnvironment(ctx context.Context, dir string) (*NixEnvironment, error)
NewNixEnvironment creates a new Nix runner. It verifies that nix is installed and that a flake.nix exists in dir.
func (*NixEnvironment) Init ¶ added in v0.1.155
func (nix *NixEnvironment) Init(ctx context.Context) error
func (*NixEnvironment) NewProcess ¶ added in v0.1.155
func (nix *NixEnvironment) NewProcess(bin string, args ...string) (Proc, error)
NewProcess creates a process that runs under the Nix devShell.
If the devShell env has been materialized (see Init), the binary is executed directly with that env injected — no `nix develop` wrapper, no flake re-evaluation. Otherwise falls back to wrapping the command in `nix develop <dir> --command <bin> <args...>`.
func (*NixEnvironment) Shutdown ¶ added in v0.1.155
func (nix *NixEnvironment) Shutdown(context.Context) error
func (*NixEnvironment) Stop ¶ added in v0.1.155
func (nix *NixEnvironment) Stop(context.Context) error
func (*NixEnvironment) WithBinary ¶ added in v0.1.155
func (nix *NixEnvironment) WithBinary(_ string) error
WithBinary is a no-op for Nix -- all binaries come from the flake.
func (*NixEnvironment) WithCacheDir ¶ added in v0.1.155
func (nix *NixEnvironment) WithCacheDir(dir string)
WithCacheDir enables persistent materialization caching. Typically set to the agent's cacheLocation so the env survives agent restarts. Safe to call before or after Init — but before is the only useful order (the cache is consulted during Init).
func (*NixEnvironment) WithEnvironmentVariables ¶ added in v0.1.155
func (nix *NixEnvironment) WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
type NixProc ¶ added in v0.1.155
type NixProc struct {
// contains filtered or unexported fields
}
NixProc is a process that runs inside a Nix development shell.
func (*NixProc) StdinPipe ¶ added in v0.1.155
func (proc *NixProc) StdinPipe() (io.WriteCloser, error)
func (*NixProc) StdoutPipe ¶ added in v0.1.155
func (proc *NixProc) StdoutPipe() (io.ReadCloser, error)
func (*NixProc) Wait ¶ added in v0.1.155
Wait blocks until the nix process exits or ctx is cancelled. Polls IsRunning at 1s intervals — Nix wraps the binary in `nix develop`, so we don't have direct access to the leaf process's cmd.Wait, and the existing forwarder goroutines already hold the cmd.Wait result.
func (*NixProc) WithEnvironmentVariables ¶ added in v0.1.155
func (proc *NixProc) WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
func (*NixProc) WithEnvironmentVariablesAppend ¶ added in v0.1.155
func (*NixProc) WithOutput ¶ added in v0.1.155
func (*NixProc) WithRunningCmd ¶ added in v0.1.155
type Proc ¶
type Proc interface {
Start(ctx context.Context) error
Run(ctx context.Context) error
Stop(ctx context.Context) error
// Wait blocks until the process exits or ctx is cancelled. Returns the
// process's exit error (nil for clean exit, *exec.ExitError for non-zero).
// Must be safe to call after Start. Multiple callers may share the result
// via an internal channel — implementations should make Wait idempotent.
// Used by supervisors to detect when a fire-and-forget Start'd process
// dies so they can propagate the failure (instead of leaking the parent).
Wait(ctx context.Context) error
IsRunning(ctx context.Context) (bool, error)
// WaitOn For Run, optional, we can wait on another process
WaitOn(s string)
// WithDir overrides the location where the Proc runs
WithDir(local string)
// WithOutput output to send the logs
WithOutput(w io.Writer)
// WithEnvironmentVariables adds environment variables
WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
// WithEnvironmentVariablesAppend appends environment variables
WithEnvironmentVariablesAppend(ctx context.Context, env *resources.EnvironmentVariable, sep string)
// StdinPipe returns a writer connected to the process's stdin.
// Must be called before Start/Run.
StdinPipe() (io.WriteCloser, error)
// StdoutPipe returns a reader connected to the process's stdout (raw bytes).
// Must be called before Start/Run. When used, WithOutput is bypassed for
// stdout; stderr still goes to the writer set via WithOutput.
StdoutPipe() (io.ReadCloser, error)
}
Proc is a generic process interface Implementations: - LocalEnvironment process: obtained from a local environment - Docker process: obtained by running in a Docker environment
type ProcessState ¶
type ProcessState int
const ( Unknown ProcessState = iota NotFound ProcessState = iota Running InterruptibleSleep UninterruptibleSleep Stopped Zombie Dead TracingStop Idle Parked Waking )
func (ProcessState) String ¶
func (ps ProcessState) String() string
type ProgressDetail ¶
type RunnerEnvironment ¶
type RunnerEnvironment interface {
// Init setup the environment
Init(ctx context.Context) error
// NewProcess creates a new process for the environment
NewProcess(bin string, args ...string) (Proc, error)
// Stop the environment: can potentially be restarted
Stop(ctx context.Context) error
// Shutdown the environment: stop and remove all resources
Shutdown(ctx context.Context) error
// WithBinary ensures a binary is visible in the environment
WithBinary(bin string) error
// WithEnvironmentVariables sets the environment variables
WithEnvironmentVariables(ctx context.Context, envs ...*resources.EnvironmentVariable)
}
A RunnerEnvironment controls running processes. Implementations: - local - docker - kubernetes (future)
func ResolveStandaloneEnvironment ¶ added in v0.1.155
func ResolveStandaloneEnvironment(ctx context.Context, dir string, runtimeCtx *basev0.RuntimeContext) RunnerEnvironment
ResolveStandaloneEnvironment returns a RunnerEnvironment that honors the plugin's declared RuntimeContext when possible, for callers that need a runner but are not plumbed through Runtime.CreateRunnerEnvironment.
Used by Code / Tooling when their shared Service.ActiveEnv is nil — typically when a Code RPC is served before Runtime.Init has run. The fallback chain:
- `ctx.Kind == Nix` AND nix is installed AND flake.nix is in dir → NixEnvironment.
- `ctx.Kind == Container` → **native fallback with caveat**. Code at the generic layer does not know the plugin's RuntimeImage (that's declared per-plugin in main.go), so we can't spin a Docker env here. Formatters and AST tools operate on host files and produce deterministic output — running them natively is acceptable. Use ActiveEnv (set by Init) when you need full mode consistency.
- Anything else → NativeEnvironment.
Never returns nil. Errors creating Nix fall through to native.
type TrackedProcess ¶
func (*TrackedProcess) GetMemory ¶
func (p *TrackedProcess) GetMemory(ctx context.Context) (*Memory, error)
func (*TrackedProcess) GetState ¶
func (p *TrackedProcess) GetState(ctx context.Context) (ProcessState, error)