config

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package config provides configuration management for the gsh REPL. It handles loading and parsing of ~/.gsh/repl.gsh configuration files, extracting declarations (models, agents, tools, MCP servers), and maintaining backward compatibility with bash-style .gshrc files.

Package config provides configuration management for the gsh REPL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadBashRC

func LoadBashRC(ctx context.Context, executor BashExecutor, rcPath string) error

LoadBashRC loads a bash configuration file (.gshrc) by executing it through a bash interpreter. This maintains compatibility with existing bash/zsh configurations. Returns any errors encountered during execution (non-fatal).

Types

type BashExecutor

type BashExecutor interface {
	RunBashScriptFromReader(ctx context.Context, reader io.Reader, name string) error
}

BashExecutor is the interface required for loading bash configuration files.

type Config

type Config struct {

	// MCPServers holds MCP server configurations from `mcp` declarations
	MCPServers map[string]*mcp.MCPServer

	// Models holds model configurations from `model` declarations
	Models map[string]*interpreter.ModelValue

	// Agents holds agent configurations from `agent` declarations
	Agents map[string]*interpreter.AgentValue

	// Tools holds tool definitions from `tool` declarations
	Tools map[string]*interpreter.ToolValue
}

Config holds all REPL configuration extracted from declarations in ~/.gsh/repl.gsh. Configuration values like logging level, prompt, model tiers, and event handlers are now managed via the SDK (gsh.* properties and gsh.on() event handlers).

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Config with default values.

func (*Config) Clone

func (c *Config) Clone() *Config

Clone creates a deep copy of the Config.

func (*Config) GetAgent

func (c *Config) GetAgent(name string) *interpreter.AgentValue

GetAgent returns an agent by name, or nil if not found.

func (*Config) GetMCPServer

func (c *Config) GetMCPServer(name string) *mcp.MCPServer

GetMCPServer returns an MCP server by name, or nil if not found.

func (*Config) GetModel

func (c *Config) GetModel(name string) *interpreter.ModelValue

GetModel returns a model by name, or nil if not found.

func (*Config) GetTool

func (c *Config) GetTool(name string) *interpreter.ToolValue

GetTool returns a tool by name, or nil if not found.

type EmbeddedDefaults

type EmbeddedDefaults struct {
	Content  string // The content of the main default config file
	FS       fs.FS  // The embedded filesystem (optional, enables imports)
	BasePath string // The base path within the embedded FS (e.g., "defaults")
}

EmbeddedDefaults contains the embedded default configuration. If EmbedFS is provided, imports from the default config will resolve against it.

type LoadResult

type LoadResult struct {
	Config      *Config
	Interpreter *interpreter.Interpreter
	Errors      []error
}

LoadResult contains the result of loading a configuration file.

type Loader

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

Loader handles loading and parsing of ~/.gsh/repl.gsh configuration files.

func NewLoader

func NewLoader(logger *zap.Logger) *Loader

NewLoader creates a new configuration loader.

func (*Loader) ExtractConfigFromInterpreter

func (l *Loader) ExtractConfigFromInterpreter(interp *interpreter.Interpreter, result *LoadResult)

ExtractConfigFromInterpreter extracts declarations from the interpreter's environment. This extracts models, agents, tools, and MCP servers defined in the config files.

func (*Loader) LoadDefaultConfigPathInto

func (l *Loader) LoadDefaultConfigPathInto(interp *interpreter.Interpreter, defaults EmbeddedDefaults) (*LoadResult, error)

LoadDefaultConfigPathInto loads configuration from the default path (~/.gsh/repl.gsh) into an existing interpreter.

Loading order:

  1. defaults/init.gsh (system defaults) - sets up SDK properties and event handlers
  2. ~/.gsh/repl.gsh (user config) - can override SDK properties and add custom handlers

Configuration is now managed via the SDK (gsh.* properties and gsh.on() event handlers) rather than the legacy GSH_CONFIG object.

defaults contains the embedded default configuration (can have empty Content to skip).

func (*Loader) LoadFromFile

func (l *Loader) LoadFromFile(path string) (*LoadResult, error)

LoadFromFile loads configuration from a repl.gsh file. Returns the configuration and any non-fatal errors encountered. If the file doesn't exist, returns default configuration with no error.

func (*Loader) LoadFromFileContent

func (l *Loader) LoadFromFileContent(filePath string, source string) (*LoadResult, error)

LoadFromFileContent loads configuration from a gsh script string with a known file path. This sets up proper import resolution relative to the file's directory.

func (*Loader) LoadFromString

func (l *Loader) LoadFromString(source string) (*LoadResult, error)

LoadFromString loads configuration from a gsh script string. Creates a new interpreter internally. For loading into an existing interpreter, use LoadFromStringInto.

func (*Loader) LoadFromStringInto

func (l *Loader) LoadFromStringInto(interp *interpreter.Interpreter, source string) (*LoadResult, error)

LoadFromStringInto loads configuration from a gsh script string into an existing interpreter.

Jump to

Keyboard shortcuts

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