Documentation
¶
Overview ¶
Package process provides process wrapping and lifecycle management.
SECURITY MODEL: All processes are executed via shell -c to enable full shell features (cd, &&, ||, pipes, redirections, variable expansion, etc.). This means shell metacharacters and command substitution will be interpreted.
This is a local development tool. All commands come from sources the developer controls:
- CLI flags they type themselves
- Config files on their local filesystem
- Docker Compose files they created
If an attacker can modify these sources, they already have full access to the system. There is no security boundary to defend - the user is intentionally running arbitrary commands.
NOTE: Currently only supports Unix-like systems (macOS, Linux). Default shell: /bin/sh.
Index ¶
- type LineHandler
- type Manager
- func (m *Manager) ExitCodes() map[string]int
- func (m *Manager) GetProcess(name string) (*ProcessInfo, error)
- func (m *Manager) ListProcesses() []ProcessInfo
- func (m *Manager) ProcessNames() []string
- func (m *Manager) Restart(processName string) error
- func (m *Manager) Start() error
- func (m *Manager) Stop() error
- func (m *Manager) Wait() error
- type ProcessConfig
- type ProcessInfo
- type ProcessWrapper
- func (w *ProcessWrapper) CommandString() string
- func (w *ProcessWrapper) ExitCode() int
- func (w *ProcessWrapper) GetStatus() string
- func (w *ProcessWrapper) IsRunning() bool
- func (w *ProcessWrapper) PID() int
- func (w *ProcessWrapper) Start() error
- func (w *ProcessWrapper) StartTime() time.Time
- func (w *ProcessWrapper) Stop() error
- func (w *ProcessWrapper) Wait() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LineHandler ¶
LineHandler is called for each line of output
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages multiple ProcessWrappers
func NewManager ¶
func NewManager(configs []ProcessConfig, handler LineHandler) *Manager
NewManager creates a new Manager for multiple processes
func NewManagerWithOTEL ¶
func NewManagerWithOTEL(configs []ProcessConfig, handler LineHandler, otelEndpoint string, otelPort int, otelEnabled bool, silent bool) *Manager
NewManagerWithOTEL creates a new Manager with OpenTelemetry support If silent is true, process wrappers won't print to stdout/stderr (for TUI mode)
func (*Manager) GetProcess ¶
func (m *Manager) GetProcess(name string) (*ProcessInfo, error)
GetProcess returns information about a specific process
func (*Manager) ListProcesses ¶
func (m *Manager) ListProcesses() []ProcessInfo
ListProcesses returns information about all managed processes
func (*Manager) ProcessNames ¶
ProcessNames returns a list of all managed process names. This is more efficient than ListProcesses when only names are needed. This method is safe to call concurrently.
type ProcessConfig ¶
type ProcessConfig struct {
Name string
Command string
Args []string
Shell string // Shell to use (default: /bin/sh)
RestartOnCrash bool // Whether to restart process on crash (default: false)
}
ProcessConfig represents a process configuration
type ProcessInfo ¶
type ProcessInfo struct {
Name string `json:"name"`
Command string `json:"command"`
PID int `json:"pid"` // -1 if not started
Status string `json:"status"` // "running", "stopped", "failed"
ExitCode int `json:"exit_code"` // -1 for running processes
StartTime time.Time `json:"start_time"`
}
ProcessInfo contains runtime information about a process
type ProcessWrapper ¶
type ProcessWrapper struct {
// contains filtered or unexported fields
}
ProcessWrapper wraps a child process and captures its output
func New ¶
func New(name string, command string, args []string, shell string, handler LineHandler) *ProcessWrapper
New creates a new ProcessWrapper for the given command.
Commands are executed via shell -c to enable shell features like cd, &&, pipes, etc. The command and args are joined with spaces to form the full shell command string. If shell is empty, defaults to /bin/sh.
Example:
New("frontend", "cd", []string{"frontend", "&&", "npm", "start"}, "/bin/bash", handler)
Executes: /bin/bash -c "cd frontend && npm start"
Or more simply:
New("frontend", "cd frontend && npm start", []string{}, "/bin/bash", handler)
Executes: /bin/bash -c "cd frontend && npm start"
func NewWithOTEL ¶
func NewWithOTEL(name string, command string, args []string, shell string, handler LineHandler, otelEndpoint string, otelPort int, otelEnabled bool, silent bool) *ProcessWrapper
NewWithOTEL creates a new ProcessWrapper with OpenTelemetry environment variable injection. If otelEndpoint is not empty and otelEnabled is true, OTEL environment variables will be injected. If silent is true, the wrapper will not print to stdout/stderr (for TUI mode).
func (*ProcessWrapper) CommandString ¶
func (w *ProcessWrapper) CommandString() string
CommandString returns the full command string including arguments. Returns just the command if no arguments were provided.
func (*ProcessWrapper) ExitCode ¶
func (w *ProcessWrapper) ExitCode() int
ExitCode returns the exit code of the process, or -1 if still running
func (*ProcessWrapper) GetStatus ¶
func (w *ProcessWrapper) GetStatus() string
GetStatus returns the process status: "running", "stopped", or "failed". A process that exited with code 0 is "stopped", non-zero is "failed". This method is safe to call concurrently.
func (*ProcessWrapper) IsRunning ¶
func (w *ProcessWrapper) IsRunning() bool
IsRunning returns true if the process is still running. Returns true for processes that haven't been started yet. This method is safe to call concurrently.
func (*ProcessWrapper) PID ¶
func (w *ProcessWrapper) PID() int
PID returns the process ID, or -1 if not started. This method is safe to call concurrently.
func (*ProcessWrapper) Start ¶
func (w *ProcessWrapper) Start() error
Start starts the wrapped process and begins capturing output
func (*ProcessWrapper) StartTime ¶
func (w *ProcessWrapper) StartTime() time.Time
StartTime returns when the process was started. Returns zero time if the process hasn't been started yet.
func (*ProcessWrapper) Stop ¶
func (w *ProcessWrapper) Stop() error
Stop gracefully stops the process and all its children
func (*ProcessWrapper) Wait ¶
func (w *ProcessWrapper) Wait() error
Wait waits for the process to complete and all output to be captured