shellmode

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package shellmode implements the ! prefix for direct shell command execution in the REPL input, bypassing the LLM entirely.

Index

Constants

View Source
const (
	// DefaultTimeout is the maximum execution time for a shell command.
	DefaultTimeout = 30 * time.Second
)

Variables

This section is empty.

Functions

func ExtractCommand

func ExtractCommand(input string) string

ExtractCommand strips the ! prefix and returns the shell command.

func IsDestructive

func IsDestructive(cmdStr string) bool

IsDestructive performs a basic heuristic check for potentially dangerous commands.

func IsShellCommand

func IsShellCommand(input string) bool

IsShellCommand checks if the input starts with ! indicating a direct shell command.

func ParsePipeline

func ParsePipeline(cmdStr string) []string

ParsePipeline splits a shell command string into individual piped commands for display purposes only (execution still uses the full string).

func RerouteCandidate

func RerouteCandidate(cmdStr string, stderr string, exitCode int) bool

RerouteCandidate checks if a failed shell command should be rerouted to the AI. Returns true if the command has NL markers AND the error matches known patterns.

Types

type Classification

type Classification int

Classification is the result of input analysis.

const (
	ClassShell   Classification = iota // execute in shell
	ClassAgent                         // route to AI agent
	ClassNeutral                       // undetermined
)

func ClassifyInput

func ClassifyInput(input string) Classification

ClassifyInput determines whether input should go to shell or AI agent. This is the single source of truth for routing decisions in auto mode.

type Mode

type Mode int

Mode represents the REPL routing mode.

const (
	ModeAuto  Mode = iota // smart routing (default)
	ModeShell             // everything to shell
	ModeAgent             // everything to AI
)

func ParseMode

func ParseMode(s string) (Mode, bool)

ParseMode converts a string to a Mode.

func (Mode) String

func (m Mode) String() string

String returns the display name of the mode.

type ModeManager

type ModeManager struct {
	// contains filtered or unexported fields
}

ModeManager handles mode state and toggling.

func NewModeManager

func NewModeManager() *ModeManager

NewModeManager creates a manager starting in auto mode.

func (*ModeManager) ClassifyWithMode

func (mm *ModeManager) ClassifyWithMode(input string) Classification

ClassifyWithMode applies mode override to classification. In shell/agent mode, the mode takes precedence over auto-detection.

func (*ModeManager) Current

func (mm *ModeManager) Current() Mode

Current returns the active mode.

func (*ModeManager) LoadPersistedMode

func (mm *ModeManager) LoadPersistedMode()

LoadPersistedMode restores mode from disk.

func (*ModeManager) Set

func (mm *ModeManager) Set(m Mode)

Set changes to a specific mode and persists it.

func (*ModeManager) Toggle

func (mm *ModeManager) Toggle() Mode

Toggle cycles through modes: auto → shell → agent → auto.

type Result

type Result struct {
	Stdout   string
	Stderr   string
	ExitCode int
	Duration time.Duration
	Command  string
}

Result holds the output of a shell command execution.

func ExecuteShell

func ExecuteShell(ctx context.Context, cmdStr string) Result

ExecuteShell runs a command directly in the user's shell.

func ExecuteShellWithTimeout

func ExecuteShellWithTimeout(ctx context.Context, cmdStr string, timeout time.Duration) Result

ExecuteShellWithTimeout runs a command with a custom timeout.

func (Result) Format

func (r Result) Format() string

Format returns a displayable string for the result.

Jump to

Keyboard shortcuts

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