base

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RCFileName      = ".aishrc"
	HistoryFileName = ".aish_history"
)
View Source
const (
	ColorReset  = "\033[0m"
	ColorRed    = "\033[31m"
	ColorGreen  = "\033[32m"
	ColorYellow = "\033[33m"
	ColorBlue   = "\033[34m"
	ColorPurple = "\033[35m"
	ColorCyan   = "\033[36m"
	ColorWhite  = "\033[37m"
	ColorGray   = "\033[90m"

	// BG colors
	BgBlue   = "\033[44m"
	BgGreen  = "\033[42m"
	BgRed    = "\033[41m"
	BgYellow = "\033[43m"

	// 样式
	Bold      = "\033[1m"
	Italic    = "\033[3m"
	Underline = "\033[4m"
)

ANSI color code

View Source
const DefaultFileName = "aish"

Variables

View Source
var ErrPanic = errors.New("panic")

Functions

func AddDefinedSystemPrompt

func AddDefinedSystemPrompt(prompt string)

func AddDefinedTool

func AddDefinedTool(usage string, entrypoint string) error

func ClearDefinedSystemPrompts

func ClearDefinedSystemPrompts()

func ClearDefinedTools

func ClearDefinedTools()

func CombineFields

func CombineFields(fields []string) (string, error)

func FindExecutableNames

func FindExecutableNames(PATH string, wd string) ([]string, error)

func GetAllConfig

func GetAllConfig() map[ConfigName]string

func GetConfig

func GetConfig(name ConfigName) string

func GetDefinedSystemPrompts

func GetDefinedSystemPrompts() string

func GetDefinedTools

func GetDefinedTools() map[string]*DefinedTool

func GetIntConfig

func GetIntConfig(name ConfigName) (value int, ok bool)

func IsInteractive

func IsInteractive(writer io.Writer) bool

func LookPath

func LookPath(file string, wd string, PATH string) (string, error)

func NewCapturedStdIO

func NewCapturedStdIO(shell *Shell, writer io.Writer) (*os.File, error)

func ReaderDescriptor

func ReaderDescriptor(reader io.Reader) (*os.File, error)

func SetConfig

func SetConfig(name ConfigName, value string)

func WriterDescriptor

func WriterDescriptor(writer io.Writer) (*os.File, error)

Types

type AIAssistantAnswer

type AIAssistantAnswer struct {
	Text     string                                `json:"text"`
	ToolCall *openai.ChatCompletionMessageToolCall `json:"tool_call"`
}

type AIExecution

type AIExecution struct {
	UnderToolCall *openai.ChatCompletionMessageToolCall
	Question      string
	Answers       []AIAssistantAnswer
	// contains filtered or unexported fields
}

func (*AIExecution) IsRoot

func (e *AIExecution) IsRoot() bool

func (*AIExecution) Trace

func (e *AIExecution) Trace() []*AIExecution

type ChanIO

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

func NewChanIO

func NewChanIO(chanBufSize int) *ChanIO

func (*ChanIO) Bytes

func (cio *ChanIO) Bytes() []byte

func (*ChanIO) Close

func (cio *ChanIO) Close() error

Close implements io.ReadWriteCloser.

func (*ChanIO) Read

func (cio *ChanIO) Read(p []byte) (n int, err error)

Read implements io.Reader.

func (*ChanIO) Write

func (cio *ChanIO) Write(p []byte) (n int, err error)

Write implements io.Writer.

type CommandExecution

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

func GetCommandExecution

func GetCommandExecution(ctx context.Context) (*CommandExecution, bool)

func (*CommandExecution) AnswerText

func (c *CommandExecution) AnswerText() string

func (*CommandExecution) AppendQA

func (c *CommandExecution) AppendQA(qa *AIExecution)

func (*CommandExecution) Buffer

func (c *CommandExecution) Buffer() *strings.Builder

func (*CommandExecution) Cancel

func (c *CommandExecution) Cancel()

func (*CommandExecution) ColorSupported

func (c *CommandExecution) ColorSupported() bool

func (*CommandExecution) Context

func (c *CommandExecution) Context() context.Context

func (*CommandExecution) Incomplete

func (c *CommandExecution) Incomplete() bool

func (*CommandExecution) Interactive

func (c *CommandExecution) Interactive() bool

func (*CommandExecution) NewSubCommandExecution

func (ce *CommandExecution) NewSubCommandExecution(fields []string, hc *interp.HandlerContext) *SubCommandExecution

func (*CommandExecution) QA

func (c *CommandExecution) QA() []*AIExecution

func (*CommandExecution) Terminated

func (c *CommandExecution) Terminated() bool

type ConfigName

type ConfigName string
const (
	ConfigOpenAIAPIKey     ConfigName = "openai.api_key"
	ConfigOpenAIModel      ConfigName = "openai.model"
	ConfigOpenAIBaseURL    ConfigName = "openai.base_url"
	ConfigMaxIterations    ConfigName = "max_iter"
	ConfigMaxHistory       ConfigName = "max_history"
	ConfigMaxMessageLength ConfigName = "max_message_length"
)

type DefinedTool

type DefinedTool struct {
	Name       string
	Usage      string
	Entrypoint string
}

func GetDefinedTool

func GetDefinedTool(name string) (tool *DefinedTool, ok bool)

type FragmentCompleter

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

func NewFragmentCompleter

func NewFragmentCompleter(do FragmentCompleterFunc) *FragmentCompleter

func (*FragmentCompleter) Do

func (c *FragmentCompleter) Do(line []rune, pos int) (newLine [][]rune, offset int)

type FragmentCompleterFunc

type FragmentCompleterFunc func(lastFragment []rune, rest []rune) (completions [][]rune)

type Shell

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

func NewShell

func NewShell(opts ...ShellOption) (*Shell, error)

func (*Shell) AbsoluteFileName

func (s *Shell) AbsoluteFileName() string

func (*Shell) Dir

func (s *Shell) Dir() string

func (*Shell) Eval

func (s *Shell) Eval(ce *CommandExecution, code []byte, modifierFunc func(sce *SubCommandExecution)) error

func (*Shell) FileName

func (s *Shell) FileName() string

func (*Shell) FindExecutableNames

func (s *Shell) FindExecutableNames() ([]string, error)

func (*Shell) LookPath

func (s *Shell) LookPath(file string) (string, error)

func (*Shell) PrintError

func (s *Shell) PrintError(writer io.Writer, err error)

func (*Shell) Start

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

func (*Shell) State

func (s *Shell) State() *ShellState

func (*Shell) Use

func (s *Shell) Use(plugin ...ShellPlugin) error

type ShellCompleter

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

func NewShellCompleter

func NewShellCompleter(shell *Shell) *ShellCompleter

func (*ShellCompleter) Do

func (s *ShellCompleter) Do(line []rune, pos int) (newLine [][]rune, offset int)

Do implements readline.AutoCompleter.

type ShellMode

type ShellMode int
const (
	ShellModeAuto ShellMode = iota
	ShellModeUser ShellMode = 1
	ShellModeAI   ShellMode = 2
)

type ShellOption

type ShellOption func(*Shell)

func WithEnviron

func WithEnviron(environ []string) ShellOption

func WithFileName

func WithFileName(fileName string, absoluteFileName string) ShellOption

func WithParams

func WithParams(params []string) ShellOption

func WithStdIO

func WithStdIO(stdin *os.File, stdout *os.File, stderr *os.File) ShellOption

type ShellPlugin

type ShellPlugin interface {
	ID() string

	// Shell related
	Install(shell *Shell) error
	AutoComplete(line []rune, pos int, shell *Shell) (newLine [][]rune, length int)

	// CommandExecution related
	PrepareContext(ce *CommandExecution, shell *Shell) (context.Context, error)
	GeneratePrompt(ce *CommandExecution, shell *Shell) (ok bool, prompt string, err error)
	End(ce *CommandExecution, shell *Shell) error

	// SubCommandExecution related
	BeforeExecute(ce *CommandExecution, sce *SubCommandExecution, shell *Shell) error
	Execute(ce *CommandExecution, sce *SubCommandExecution, shell *Shell) (ok bool, err error)
	AfterExecute(ce *CommandExecution, sce *SubCommandExecution, shell *Shell) error
}

type ShellState

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

func NewDefaultShellState

func NewDefaultShellState() (*ShellState, error)

func (*ShellState) Arch

func (s *ShellState) Arch() string

func (*ShellState) CurrentExecution

func (s *ShellState) CurrentExecution() *CommandExecution

func (*ShellState) Mode

func (s *ShellState) Mode() ShellMode

func (*ShellState) OS

func (s *ShellState) OS() string

func (*ShellState) SetCurrentExecution

func (s *ShellState) SetCurrentExecution(ce *CommandExecution)

func (*ShellState) SetMode

func (s *ShellState) SetMode(mode ShellMode)

func (*ShellState) User

func (s *ShellState) User() *user.User

type SubCommandExecution

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

func (*SubCommandExecution) Cmd

func (c *SubCommandExecution) Cmd() string

func (*SubCommandExecution) ColorSupported

func (c *SubCommandExecution) ColorSupported() bool

func (*SubCommandExecution) DefaultExecHandler

func (sce *SubCommandExecution) DefaultExecHandler() error

func (*SubCommandExecution) Error

func (c *SubCommandExecution) Error() error

func (*SubCommandExecution) Fields

func (c *SubCommandExecution) Fields() []string

func (*SubCommandExecution) Inherit

func (c *SubCommandExecution) Inherit(parent *SubCommandExecution)

func (*SubCommandExecution) Interactive

func (c *SubCommandExecution) Interactive() bool

func (*SubCommandExecution) Mode

func (c *SubCommandExecution) Mode() ShellMode

func (*SubCommandExecution) QA

func (*SubCommandExecution) SetFields

func (c *SubCommandExecution) SetFields(fields []string)

func (*SubCommandExecution) SetMode

func (c *SubCommandExecution) SetMode(mode ShellMode)

func (*SubCommandExecution) Stdai

func (c *SubCommandExecution) Stdai() io.Writer

Used to write content that only visible to AI

func (*SubCommandExecution) Stderr

func (c *SubCommandExecution) Stderr() io.Writer

Used to write error content that visible to both user and AI

func (*SubCommandExecution) Stdin

func (c *SubCommandExecution) Stdin() io.Reader

func (*SubCommandExecution) Stdout

func (c *SubCommandExecution) Stdout() io.Writer

Used to write content that visible to both user and AI

Jump to

Keyboard shortcuts

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