context

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package context provides context aggregation for LLM predictions in the gsh REPL. It collects relevant information from various sources (working directory, git status, command history, system info) to provide context for more accurate predictions.

Package context provides context aggregation for LLM predictions in the gsh REPL. It collects relevant information from various sources (working directory, git status, command history, system info) to provide context for more accurate predictions.

Index

Constants

View Source
const (
	// DefaultHistoryConciseLimit is the default number of history entries for concise context.
	DefaultHistoryConciseLimit = 30
	// DefaultHistoryVerboseLimit is the default number of history entries for verbose context.
	DefaultHistoryVerboseLimit = 30
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConciseHistoryRetriever

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

ConciseHistoryRetriever retrieves a concise command history context. It shows commands grouped by directory without detailed metadata.

func NewConciseHistoryRetriever

func NewConciseHistoryRetriever(hm *history.HistoryManager, limit int) *ConciseHistoryRetriever

NewConciseHistoryRetriever creates a new ConciseHistoryRetriever. If limit is 0 or negative, DefaultHistoryConciseLimit is used.

func (*ConciseHistoryRetriever) GetContext

func (r *ConciseHistoryRetriever) GetContext() (string, error)

GetContext returns recent command history formatted for LLM context. Commands are grouped by directory with minimal formatting.

func (*ConciseHistoryRetriever) Name

func (r *ConciseHistoryRetriever) Name() string

Name returns the retriever name.

type GitStatusRetriever

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

GitStatusRetriever retrieves git repository status context.

func NewGitStatusRetriever

func NewGitStatusRetriever(exec *executor.REPLExecutor, logger *zap.Logger) *GitStatusRetriever

NewGitStatusRetriever creates a new GitStatusRetriever.

func (*GitStatusRetriever) GetContext

func (r *GitStatusRetriever) GetContext() (string, error)

GetContext returns the git status formatted for LLM context. Returns a message indicating not in a git repository if git commands fail.

func (*GitStatusRetriever) Name

func (r *GitStatusRetriever) Name() string

Name returns the retriever name.

type Provider

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

Provider aggregates context from multiple retrievers. It coordinates the collection of context information from various sources and combines them into a single map for use by the prediction system.

func NewProvider

func NewProvider(logger *zap.Logger, retrievers ...Retriever) *Provider

NewProvider creates a new context Provider with the given logger and retrievers.

func (*Provider) AddRetriever

func (p *Provider) AddRetriever(retriever Retriever)

AddRetriever adds a retriever to the provider.

func (*Provider) GetContext

func (p *Provider) GetContext() map[string]string

GetContext collects context from all registered retrievers. Returns a map where keys are retriever names and values are their context strings. If a retriever fails, its error is logged and it is skipped.

func (*Provider) GetContextForTypes

func (p *Provider) GetContextForTypes(types []string) map[string]string

GetContextForTypes collects context only from retrievers whose names match the given types. This allows selective context gathering based on the use case (e.g., agent vs prediction).

type Retriever

type Retriever interface {
	// Name returns the unique identifier for this retriever.
	// This is used as the key in the context map returned by Provider.
	Name() string

	// GetContext returns the context string for this retriever.
	// The returned string should be formatted appropriately for LLM consumption.
	GetContext() (string, error)
}

Retriever is the interface that all context retrievers must implement. Each retriever is responsible for collecting a specific type of context information that can be used by the LLM for predictions.

type SystemInfoRetriever

type SystemInfoRetriever struct{}

SystemInfoRetriever retrieves system information context.

func NewSystemInfoRetriever

func NewSystemInfoRetriever() *SystemInfoRetriever

NewSystemInfoRetriever creates a new SystemInfoRetriever.

func (*SystemInfoRetriever) GetContext

func (r *SystemInfoRetriever) GetContext() (string, error)

GetContext returns system information formatted for LLM context.

func (*SystemInfoRetriever) Name

func (r *SystemInfoRetriever) Name() string

Name returns the retriever name.

type VerboseHistoryRetriever

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

VerboseHistoryRetriever retrieves a verbose command history context. It includes sequence numbers, exit codes, and directory information.

func NewVerboseHistoryRetriever

func NewVerboseHistoryRetriever(hm *history.HistoryManager, limit int) *VerboseHistoryRetriever

NewVerboseHistoryRetriever creates a new VerboseHistoryRetriever. If limit is 0 or negative, DefaultHistoryVerboseLimit is used.

func (*VerboseHistoryRetriever) GetContext

func (r *VerboseHistoryRetriever) GetContext() (string, error)

GetContext returns recent command history with detailed metadata. Includes sequence number, exit code, and command for each entry.

func (*VerboseHistoryRetriever) Name

func (r *VerboseHistoryRetriever) Name() string

Name returns the retriever name.

type WorkingDirectoryRetriever

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

WorkingDirectoryRetriever retrieves the current working directory context.

func NewWorkingDirectoryRetriever

func NewWorkingDirectoryRetriever(exec *executor.REPLExecutor) *WorkingDirectoryRetriever

NewWorkingDirectoryRetriever creates a new WorkingDirectoryRetriever.

func (*WorkingDirectoryRetriever) GetContext

func (r *WorkingDirectoryRetriever) GetContext() (string, error)

GetContext returns the current working directory formatted for LLM context.

func (*WorkingDirectoryRetriever) Name

Name returns the retriever name.

Jump to

Keyboard shortcuts

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