Documentation
¶
Index ¶
- Constants
- Variables
- func CommandFromArgv(selectedShell ShellName, argv []string) (string, error)
- func EffectiveEnv(overrides map[string]string) ([]string, error)
- func EffectiveEnvWithBase(baseEnv, overrides map[string]string) ([]string, error)
- func HostExec(ctx context.Context, args ...string) ([]byte, error)
- func HostSpawnAvailable(ctx context.Context) bool
- func IsFlatpak() bool
- func NormalizeBlockedCommand(s string) (string, error)
- func PrependHostSpawn(ctx context.Context, args []string) ([]string, bool)
- func RejectDangerousCommand(cmd, shellPath string, shellName ShellName, ...) error
- func ValidateEnvMap(m map[string]string) error
- type SelectedShell
- type SessionStore
- type ShellCommandExecResult
- type ShellName
- type ShellSession
- func (sess *ShellSession) AddToEnv(additionalEnv map[string]string) error
- func (sess *ShellSession) GetEffectiveEnv(overrides map[string]string) ([]string, error)
- func (sess *ShellSession) GetEffectiveEnvWithBase(baseEnv, overrides map[string]string) ([]string, error)
- func (sess *ShellSession) GetEffectiveWorkdir(inputWorkDir, defaultWorkDir string) (string, error)
- func (sess *ShellSession) GetID() string
- func (sess *ShellSession) SetWorkDir(workdir string)
Constants ¶
const ( HardMaxTimeout = 10 * time.Minute HardMaxOutputBytes int64 = 4 * 1024 * 1024 // per stream HardMaxCommands = 64 HardMaxCommandLength = 64 * 1024 // bytes MinOutputBytes int64 = 1024 DefaultTimeout = 60 * time.Second DefaultMaxOutputBytes int64 = 256 * 1024 DefaultMaxCommands = 64 DefaultMaxCommandLength = 64 * 1024 )
Fixed, package-wide hard limits (single source of truth).
Variables ¶
var HardBlockedCommands = func() map[string]struct{} { hard := []string{ "sudo", "su", "rm", "mkfs", "shutdown", "reboot", "halt", "poweroff", "vim", "vi", "nano", "emacs", "less", "more", "top", "htop", "curl", "wget", "nc", "netcat", "ncat", "socat", "ssh", "scp", "sftp", "ftp", "tftp", "telnet", "invoke-webrequest", "iwr", "invoke-restmethod", "irm", "diskpart", "format.com", "del", "erase", "rmdir", "rd", "remove-item", "ri", } m := make(map[string]struct{}, len(hard)) for _, c := range hard { m[c] = struct{}{} } return m }()
Functions ¶
func CommandFromArgv ¶
CommandFromArgv builds a safely-quoted command string for ShellTool (which executes via shell "-c"/"-Command").
Why this exists: ShellTool accepts command strings; without a canonical helper, wrappers duplicate quoting and can accidentally introduce injection bugs. This keeps quoting logic centralized and consistent.
Supported dialects:
- sh-like shells (bash/zsh/sh/dash/ksh/fish): POSIX single-quote strategy
- PowerShell (pwsh/powershell): single-quote strategy + "&" call operator prefix
cmd.exe quoting is intentionally not supported here (too error-prone); pass a raw command string instead.
func EffectiveEnv ¶
EffectiveEnv returns the current process environment merged with overrides. It is equivalent to session-less ShellSession.GetEffectiveEnv.
func EffectiveEnvWithBase ¶ added in v0.14.0
EffectiveEnvWithBase returns the current process environment merged with base env and overrides.
func HostExec ¶ added in v0.15.0
HostExec runs a command on the host via flatpak-spawn --host and returns its stdout. Returns an error when host spawn is unavailable or the command fails.
func HostSpawnAvailable ¶ added in v0.15.0
HostSpawnAvailable reports whether flatpak-spawn --host can be used to run commands on the host. Returns false when not inside Flatpak or the probe command fails. The result is cached after the first probe.
func IsFlatpak ¶ added in v0.15.0
func IsFlatpak() bool
IsFlatpak reports whether the current process runs inside a Flatpak sandbox. The result is cached after the first call.
func NormalizeBlockedCommand ¶
func PrependHostSpawn ¶ added in v0.15.0
PrependHostSpawn wraps args with ["flatpak-spawn","--host",...] when host spawn is available. Returns the original slice unchanged otherwise. The second return value indicates whether wrapping was applied.
func RejectDangerousCommand ¶
func ValidateEnvMap ¶
Types ¶
type SelectedShell ¶
func ResolveHostAutoShell ¶ added in v0.15.0
func ResolveHostAutoShell(ctx context.Context) (SelectedShell, bool)
ResolveHostAutoShell detects the preferred shell on the host system via flatpak-spawn --host. Falls back through $SHELL, getent, and common shell probes.
type SessionStore ¶
type SessionStore struct {
// contains filtered or unexported fields
}
func NewSessionStore ¶
func NewSessionStore() *SessionStore
func (*SessionStore) Delete ¶
func (ss *SessionStore) Delete(id string)
func (*SessionStore) Get ¶
func (ss *SessionStore) Get(id string) (*ShellSession, bool)
func (*SessionStore) NewSession ¶
func (ss *SessionStore) NewSession() *ShellSession
func (*SessionStore) SetMaxSessions ¶
func (ss *SessionStore) SetMaxSessions(maxSessions int)
func (*SessionStore) SetTTL ¶
func (ss *SessionStore) SetTTL(ttl time.Duration)
func (*SessionStore) Size ¶
func (ss *SessionStore) Size() int
type ShellCommandExecResult ¶
type ShellCommandExecResult struct {
Command string `json:"command"`
WorkDir string `json:"workDir"`
Shell ShellName `json:"shell"`
ShellPath string `json:"shellPath"`
ExitCode int `json:"exitCode"`
TimedOut bool `json:"timedOut"`
DurationMS int64 `json:"durationMS"`
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
StdoutTruncated bool `json:"stdoutTruncated"`
StderrTruncated bool `json:"stderrTruncated"`
}
func RunOneShellCommand ¶
type ShellName ¶
type ShellName string
const ( ShellNameAuto ShellName = "auto" ShellNameBash ShellName = "bash" ShellNameZsh ShellName = "zsh" ShellNameSh ShellName = "sh" ShellNameDash ShellName = "dash" ShellNameKsh ShellName = "ksh" ShellNameFish ShellName = "fish" ShellNamePwsh ShellName = "pwsh" ShellNamePowershell ShellName = "powershell" ShellNameCmd ShellName = "cmd" )
func NormalizeShellName ¶ added in v0.15.0
type ShellSession ¶
type ShellSession struct {
// contains filtered or unexported fields
}
func (*ShellSession) AddToEnv ¶
func (sess *ShellSession) AddToEnv(additionalEnv map[string]string) error
func (*ShellSession) GetEffectiveEnv ¶
func (sess *ShellSession) GetEffectiveEnv(overrides map[string]string) ([]string, error)
func (*ShellSession) GetEffectiveEnvWithBase ¶ added in v0.14.0
func (sess *ShellSession) GetEffectiveEnvWithBase(baseEnv, overrides map[string]string) ([]string, error)
func (*ShellSession) GetEffectiveWorkdir ¶
func (sess *ShellSession) GetEffectiveWorkdir(inputWorkDir, defaultWorkDir string) (string, error)
func (*ShellSession) GetID ¶
func (sess *ShellSession) GetID() string
func (*ShellSession) SetWorkDir ¶
func (sess *ShellSession) SetWorkDir(workdir string)