shell

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEditorCanceled = errors.New("editor canceled")

ErrEditorCanceled is returned when the editor is canceled (Ctrl+C).

View Source
var ErrEditorEOF = errors.New("editor EOF")

ErrEditorEOF is returned when the editor receives EOF (Ctrl+D).

Functions

This section is empty.

Types

type AgentHandler

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

AgentHandler handles agent requests.

func NewAgentHandler

func NewAgentHandler(client *agent.Client) *AgentHandler

NewAgentHandler creates a new agent handler.

func (*AgentHandler) HandleRequest

func (h *AgentHandler) HandleRequest(ctx context.Context, parsed parser.ParseResult) (agent.Response, error)

HandleRequest processes a parsed agent request and returns the response.

func (*AgentHandler) SetClipboard

func (h *AgentHandler) SetClipboard(buf *clipboard.Buffer)

SetClipboard sets the clipboard buffer for context.

func (*AgentHandler) SetSelectedContext

func (h *AgentHandler) SetSelectedContext(ctx *hashcontext.Collection)

SetSelectedContext sets the user-selected context.

func (*AgentHandler) StreamRequest

func (h *AgentHandler) StreamRequest(ctx context.Context, parsed parser.ParseResult) (<-chan string, <-chan error)

StreamRequest processes a parsed agent request and returns streaming channels. Text chunks arrive on the text channel, errors on the error channel.

type AgentState

type AgentState int

AgentState represents the current state of an agent request.

const (
	AgentStateConnecting AgentState = iota
	AgentStateSending
	AgentStateThinking
	AgentStateReceiving
)

func (AgentState) String

func (s AgentState) String() string

type ClipboardBuffer

type ClipboardBuffer = clipboard.Buffer

ClipboardBuffer is a type alias for easier external access.

type CommandSuggestor

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

CommandSuggestor finds similar commands for typos.

func NewCommandSuggestor

func NewCommandSuggestor(historyStore *history.Store) *CommandSuggestor

NewCommandSuggestor creates a new suggestor and starts PATH caching in background.

func (*CommandSuggestor) InstallHint

func (s *CommandSuggestor) InstallHint(cmd string) string

InstallHint returns install instructions if known, empty otherwise.

func (*CommandSuggestor) Suggest

func (s *CommandSuggestor) Suggest(cmd string) []string

Suggest returns up to 3 similar command names.

type ConfirmAction

type ConfirmAction int

ConfirmAction represents the user's response to a command suggestion.

const (
	ConfirmRun    ConfirmAction = iota // User pressed Enter - run the command
	ConfirmEdit                        // User pressed Tab - edit the command
	ConfirmCancel                      // User pressed Esc - cancel
)

type ConfirmationType

type ConfirmationType int

ConfirmationType determines which confirmation options to show.

const (
	ConfirmTypeCommand     ConfirmationType = iota // [Enter: run] [Tab: edit] [Esc: cancel]
	ConfirmTypeExplanation                         // [Enter: ok] [Tab: copy] [Esc: cancel]
	ConfirmTypeError                               // [Enter: retry] [Esc: cancel]
)

type ErrorHandler

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

ErrorHandler manages error detection and fix suggestions.

func NewErrorHandler

func NewErrorHandler(store *learning.FixStore) *ErrorHandler

NewErrorHandler creates a new error handler.

func (*ErrorHandler) FormatErrorPrompt

func (h *ErrorHandler) FormatErrorPrompt(exitCode int, stderr string) string

FormatErrorPrompt formats an error prompt string.

func (*ErrorHandler) GetSuggestion

func (h *ErrorHandler) GetSuggestion(command, stderr string, exitCode int) string

GetSuggestion returns a fix suggestion for the given error, or empty string.

func (*ErrorHandler) HandleCommandNotFound

func (h *ErrorHandler) HandleCommandNotFound(cmd string, suggestions []string, installHint string)

HandleCommandNotFound displays a command-not-found error with suggestions.

func (*ErrorHandler) HandleError

func (h *ErrorHandler) HandleError(command, stderr string, exitCode int)

HandleError processes a command error and suggests fixes.

func (*ErrorHandler) RecordFixAttempt

func (h *ErrorHandler) RecordFixAttempt(command, stderr string, exitCode int, fix string, success bool)

RecordFixAttempt records whether a suggested fix worked.

type Mode

type Mode struct {
	Login       bool // Login shell (sources profile files)
	Interactive bool // Interactive shell (has TTY)
}

Mode represents the shell's startup mode.

type ResponseUI

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

ResponseUI handles displaying agent responses.

func NewResponseUI

func NewResponseUI(out io.Writer) *ResponseUI

NewResponseUI creates a new response UI.

func (*ResponseUI) ClearLine

func (u *ResponseUI) ClearLine()

ClearLine clears the current line (for replacing thinking with response).

func (*ResponseUI) ClearLines

func (u *ResponseUI) ClearLines(n int)

ClearLines moves cursor up n lines and clears each one. Used to remove streamed response when user cancels.

func (*ResponseUI) ClearThinking

func (u *ResponseUI) ClearThinking()

ClearThinking clears the thinking indicator.

func (*ResponseUI) ShowAgentHint

func (u *ResponseUI) ShowAgentHint(transport, command, url string)

ShowAgentHint displays troubleshooting hints for agent connection failures.

func (*ResponseUI) ShowConfirmation

func (u *ResponseUI) ShowConfirmation(ct ConfirmationType)

ShowConfirmation displays the compact confirmation UI below the response.

func (*ResponseUI) ShowError

func (u *ResponseUI) ShowError(errMsg string)

ShowError displays an error message in the response area.

func (*ResponseUI) ShowResponse

func (u *ResponseUI) ShowResponse(resp agent.Response)

ShowResponse displays an agent response.

func (*ResponseUI) ShowState

func (u *ResponseUI) ShowState(state AgentState)

ShowState displays the current agent state with animated spinner. If a spinner is already running, it updates the text. If no spinner is running, it starts one.

func (*ResponseUI) ShowStateWithSize

func (u *ResponseUI) ShowStateWithSize(state AgentState, sizeBytes int)

ShowStateWithSize displays state with context size info.

func (*ResponseUI) ShowStreamedResponse

func (u *ResponseUI) ShowStreamedResponse(text string, isCommand bool)

ShowStreamedResponse displays a streamed response with dim styling. The response appears tentative until confirmed.

func (*ResponseUI) ShowThinking deprecated

func (u *ResponseUI) ShowThinking(model string)

ShowThinking displays a thinking indicator with optional model name.

Deprecated: Use ShowState(AgentStateThinking) instead for consistent styling.

func (*ResponseUI) ShowThinkingInline deprecated

func (u *ResponseUI) ShowThinkingInline(model string)

ShowThinkingInline displays thinking indicator (for streaming modes).

Deprecated: Use ShowState(AgentStateThinking) instead for consistent styling.

func (*ResponseUI) StartProgress

func (u *ResponseUI) StartProgress()

StartProgress starts the OSC 9;4 progress bar without showing text.

func (*ResponseUI) StopProgress

func (u *ResponseUI) StopProgress()

StopProgress stops the OSC 9;4 progress bar.

func (*ResponseUI) StopSpinner

func (u *ResponseUI) StopSpinner()

StopSpinner stops the animated spinner if running and waits for it to exit.

func (*ResponseUI) WaitForConfirmation

func (u *ResponseUI) WaitForConfirmation() ConfirmAction

WaitForConfirmation waits for user to press Enter, Tab, or Esc.

func (*ResponseUI) WaitForConfirmationByType

func (u *ResponseUI) WaitForConfirmationByType(ct ConfirmationType) ConfirmAction

WaitForConfirmationByType waits for confirmation based on response type. Returns ConfirmAction appropriate for the confirmation type.

type Shell

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

Shell is the main Hash shell instance.

func New

func New(cfg *config.Config) (*Shell, error)

New creates a new Shell instance.

func NewWithMode

func NewWithMode(cfg *config.Config, mode Mode) (*Shell, error)

NewWithMode creates a new Shell instance with explicit mode.

func (*Shell) Close

func (s *Shell) Close() error

Close releases shell resources.

func (*Shell) History

func (s *Shell) History() *history.Store

History returns the history store for use by builtins.

func (*Shell) Learning

func (s *Shell) Learning() *learning.FixStore

Learning returns the learning store for use by builtins.

func (*Shell) Mode

func (s *Shell) Mode() Mode

Mode returns the shell's current mode.

func (*Shell) Run

func (s *Shell) Run(ctx context.Context) error

Run starts the shell REPL.

type SystemStatus

type SystemStatus struct {
	Version string

	// Prompt
	PromptMode string
	PromptOK   bool
	PromptErr  string

	// History
	HistoryPath  string
	HistoryOK    bool
	HistoryErr   string
	HistoryCount int64

	// Learning
	LearningOK   bool
	LearningErr  string
	PatternCount int64

	// Agent
	AgentName string
	AgentOK   bool
	AgentErr  string

	// PTY
	PTYOK  bool
	PTYErr string

	// Clipboard
	ClipboardOK  bool
	ClipboardErr string
}

SystemStatus holds the current status of all shell subsystems.

func (*SystemStatus) Format

func (s *SystemStatus) Format() string

Format returns a formatted status display.

type Welcome

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

Welcome handles first-run welcome message.

func NewWelcome

func NewWelcome(configDir string) *Welcome

NewWelcome creates a new Welcome handler.

func (*Welcome) MarkShown

func (w *Welcome) MarkShown() error

MarkShown marks the welcome as shown (creates flag file).

func (*Welcome) Message

func (w *Welcome) Message() string

Message returns the welcome message.

func (*Welcome) ShouldShow

func (w *Welcome) ShouldShow() bool

ShouldShow returns true if welcome message should be displayed.

Directories

Path Synopsis
Package integration provides terminal integration escape sequences.
Package integration provides terminal integration escape sequences.

Jump to

Keyboard shortcuts

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