Documentation
¶
Index ¶
- type CodePreprocessor
- func (p *CodePreprocessor) ExtractGoCode(text string) string
- func (p *CodePreprocessor) PrepareForExecution(code string, registryFuncName string) string
- func (p *CodePreprocessor) Process(rawCode string, registryFuncName string) string
- func (p *CodePreprocessor) ValidateBasicStructure(code string) string
- type ExecutionError
- type ExecutionResult
- type Executor
- func (e *Executor) Execute(ctx context.Context, sourceCode string, timeout time.Duration) (*ExecutionResult, error)
- func (e *Executor) ExecuteGeneratedCode(ctx context.Context, rawCode string, timeout time.Duration, ...) (*ExecutionResult, error)
- func (e *Executor) ExecuteSimple(sourceCode string) (*ExecutionResult, error)
- func (e *Executor) ExecuteWithSymbols(ctx context.Context, sourceCode string, timeout time.Duration, ...) (*ExecutionResult, error)
- func (e *Executor) SetCustomSymbols(symbols map[string]map[string]interface{})
- func (e *Executor) SetDefaultTimeout(timeout time.Duration)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CodePreprocessor ¶
type CodePreprocessor struct{}
CodePreprocessor handles preprocessing of LLM-generated Go code
func NewCodePreprocessor ¶
func NewCodePreprocessor() *CodePreprocessor
NewCodePreprocessor creates a new code preprocessor
func (*CodePreprocessor) ExtractGoCode ¶
func (p *CodePreprocessor) ExtractGoCode(text string) string
ExtractGoCode extracts Go code from markdown code blocks
func (*CodePreprocessor) PrepareForExecution ¶
func (p *CodePreprocessor) PrepareForExecution(code string, registryFuncName string) string
PrepareForExecution prepares code for execution with custom symbols This transforms registry.Call to the injected function name
func (*CodePreprocessor) Process ¶
func (p *CodePreprocessor) Process(rawCode string, registryFuncName string) string
Process performs full preprocessing of raw LLM output
func (*CodePreprocessor) ValidateBasicStructure ¶
func (p *CodePreprocessor) ValidateBasicStructure(code string) string
ValidateBasicStructure validates that the code has basic Go structure
type ExecutionError ¶
ExecutionError represents an error that occurred during code execution
func (*ExecutionError) Error ¶
func (e *ExecutionError) Error() string
type ExecutionResult ¶
type ExecutionResult struct {
Stdout string
Stderr string
Duration int64 // milliseconds
Success bool
Error string
RawCode string // Original code from LLM (for debugging)
ProcessedCode string // Code after preprocessing (for debugging)
}
ExecutionResult contains the result of executing code
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor runs Go code using the yaegi interpreter This provides a sandbox for executing LLM-generated code
func NewExecutor ¶
func NewExecutor() *Executor
NewExecutor creates a new interpreter-based executor
func (*Executor) Execute ¶
func (e *Executor) Execute(ctx context.Context, sourceCode string, timeout time.Duration) (*ExecutionResult, error)
Execute interprets and runs Go source code directly (no compilation)
func (*Executor) ExecuteGeneratedCode ¶
func (e *Executor) ExecuteGeneratedCode(ctx context.Context, rawCode string, timeout time.Duration, registryCall func(string, map[string]interface{}) (interface{}, error)) (*ExecutionResult, error)
ExecuteGeneratedCode is a high-level API for executing LLM-generated code It handles markdown extraction, code preprocessing, and registry injection
func (*Executor) ExecuteSimple ¶
func (e *Executor) ExecuteSimple(sourceCode string) (*ExecutionResult, error)
ExecuteSimple is a convenience method with default timeout
func (*Executor) ExecuteWithSymbols ¶
func (e *Executor) ExecuteWithSymbols(ctx context.Context, sourceCode string, timeout time.Duration, symbols map[string]map[string]interface{}) (*ExecutionResult, error)
ExecuteWithSymbols executes code with custom symbols injected This is useful for providing tool registries or other external dependencies
func (*Executor) SetCustomSymbols ¶
SetCustomSymbols sets custom symbols that will be available to executed code The symbols map should be: package path -> symbol name -> value Example: map[string]map[string]interface{}{"main/main": {"myFunc": myFunction}}
func (*Executor) SetDefaultTimeout ¶
SetDefaultTimeout sets the default execution timeout