coders

package
v0.13.1 Latest Latest
Warning

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

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

Documentation

Overview

Package coders provides interfaces and types for working with code editors.

Package coders provides command execution capabilities for the AI terminal. It handles commands like adding/removing files, asking questions, coding with AI, committing changes, and more.

Index

Constants

View Source
const (
	HEAD    = "<<<<<<< SEARCH"
	DIVIDER = "======="
	UPDATED = ">>>>>>> REPLACE"
)
View Source
const (
	FlagVerbose = "verbose"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoCoder

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

func NewAutoCoder

func NewAutoCoder(opts ...AutoCoderOption) *AutoCoder

func (*AutoCoder) Run added in v0.12.0

func (a *AutoCoder) Run() error

type AutoCoderOption added in v0.13.0

type AutoCoderOption func(*AutoCoder)

func WithCodeBasePath added in v0.13.0

func WithCodeBasePath(path string) AutoCoderOption

func WithConfig added in v0.13.0

func WithConfig(cfg *options.Config) AutoCoderOption

func WithEngine added in v0.13.0

func WithEngine(engine *ai.Engine) AutoCoderOption

func WithLoadedContexts added in v0.13.0

func WithLoadedContexts(contexts []*convo.LoadContext) AutoCoderOption

func WithPrompt added in v0.13.0

func WithPrompt(prompt string) AutoCoderOption

func WithRepo added in v0.13.0

func WithRepo(repo *git.Command) AutoCoderOption

func WithStore added in v0.13.0

func WithStore(store convo.Store) AutoCoderOption

type Coder

type Coder interface {
	// Name returns the name of the code editor.
	Name() string
	// Prompt returns the prompt template used by the code editor.
	Prompt() prompts.ChatPromptTemplate
	// FormatMessages formats the messages with the provided values and returns the formatted messages.
	FormatMessages(values map[string]any) ([]llms.ChatMessage, error)
	// GetEdits retrieves the list of edits made to the code.
	GetEdits(ctx context.Context) ([]PartialCodeBlock, error)
	// GetModifiedFiles retrieves the list of files that have been modified.
	GetModifiedFiles(ctx context.Context) ([]string, error)
	// UpdateCodeFences updates the code fence for the given code.
	UpdateCodeFences(ctx context.Context, code string) (string, string)
	// ApplyEdits applies the given list of edits to the code.
	ApplyEdits(ctx context.Context, edits []PartialCodeBlock) error
	// Execute runs the code editor with the specified input messages.
	Execute(ctx context.Context, messages []llms.ChatMessage) error
}

Coder defines the interface for a code editor.

type CoderContext added in v0.12.0

type CoderContext struct {
	context.Context
	// contains filtered or unexported fields
}

func NewCoderContext added in v0.12.0

func NewCoderContext(cfg *options.Config) (*CoderContext, error)

type CommandCompleter added in v0.12.0

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

func NewCommandCompleter added in v0.12.0

func NewCommandCompleter(repo *git.Command) CommandCompleter

func (CommandCompleter) Complete added in v0.12.0

func (c CommandCompleter) Complete(d prompt.Document) []prompt.Suggest

type CommandExecutor added in v0.12.0

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

func NewCommandExecutor added in v0.12.0

func NewCommandExecutor(coder *AutoCoder) *CommandExecutor

func (*CommandExecutor) Executor added in v0.12.0

func (c *CommandExecutor) Executor(input string)

Executor handles command execution. It parses the input, validates the command, and executes the corresponding handler function.

type EditBlockCoder

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

func NewEditBlockCoder

func NewEditBlockCoder(coder *AutoCoder, fence []string) *EditBlockCoder

func (*EditBlockCoder) ApplyEdits

func (e *EditBlockCoder) ApplyEdits(ctx context.Context, edits []PartialCodeBlock) error

func (*EditBlockCoder) Execute

func (e *EditBlockCoder) Execute(ctx context.Context, messages []llms.ChatMessage) error

func (*EditBlockCoder) FormatMessages

func (e *EditBlockCoder) FormatMessages(values map[string]any) ([]llms.ChatMessage, error)

func (*EditBlockCoder) GetEdits

func (e *EditBlockCoder) GetEdits(_ context.Context) ([]PartialCodeBlock, error)

func (*EditBlockCoder) GetModifiedFiles

func (e *EditBlockCoder) GetModifiedFiles(ctx context.Context) ([]string, error)

func (*EditBlockCoder) Name

func (e *EditBlockCoder) Name() string

func (*EditBlockCoder) Prompt

func (*EditBlockCoder) UpdateCodeFences

func (e *EditBlockCoder) UpdateCodeFences(_ context.Context, code string) (string, string)

type PartialCodeBlock

type PartialCodeBlock struct {
	// Path is the file path of the code block.
	Path string
	// OriginalText is the original text of the code block.
	OriginalText string
	// UpdatedText is the updated text of the code block.
	UpdatedText string
}

PartialCodeBlock represents a partial code block with its file path and original and updated text.

func (PartialCodeBlock) String

func (p PartialCodeBlock) String() string

type PromptMode

type PromptMode int

PromptMode represents the mode of the prompt.

const (
	ExecPromptMode    PromptMode = iota // ExecPromptMode represents the execution mode.
	ChatPromptMode                      // ChatPromptMode represents the chat mode.
	DefaultPromptMode                   // DefaultPromptMode represents the default mode.
)

Constants representing different prompt modes.

func GetPromptModeFromString

func GetPromptModeFromString(s string) PromptMode

GetPromptModeFromString returns the PromptMode corresponding to the given string.

func (PromptMode) String

func (m PromptMode) String() string

String returns the string representation of the PromptMode.

Jump to

Keyboard shortcuts

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