process

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LineHandler

type LineHandler func(source string, line string, timestamp time.Time, isStderr bool)

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) ExitCodes

func (m *Manager) ExitCodes() map[string]int

ExitCodes returns a map of process names to their exit codes

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

func (m *Manager) ProcessNames() []string

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.

func (*Manager) Restart

func (m *Manager) Restart(processName string) error

Restart stops and restarts a specific process by name

func (*Manager) Start

func (m *Manager) Start() error

Start starts all managed processes

func (*Manager) Stop

func (m *Manager) Stop() error

Stop stops all managed processes

func (*Manager) Wait

func (m *Manager) Wait() error

Wait waits for all processes to complete Returns an error if any process exits with an error Automatically restarts crashed processes if restart_on_crash is enabled

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

Jump to

Keyboard shortcuts

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