mirror of
https://github.com/mark3labs/kit.git
synced 2026-06-13 19:20:06 +00:00
add unrestricted stdlib symbols to Yaegi interpreter
os/exec lives in yaegi's stdlib/unrestricted package, not the default stdlib.Symbols. Without it, extensions importing os/exec fail with 'unable to find source'. This is needed for the /run command example and any extension that spawns subprocesses.
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/traefik/yaegi/interp"
|
||||
"github.com/traefik/yaegi/stdlib"
|
||||
"github.com/traefik/yaegi/stdlib/unrestricted"
|
||||
)
|
||||
|
||||
// Discovery paths searched in order (lowest to highest precedence):
|
||||
@@ -146,10 +147,14 @@ func loadSingleExtension(path string) (*LoadedExtension, error) {
|
||||
// Create a fresh interpreter.
|
||||
i := interp.New(interp.Options{})
|
||||
|
||||
// Expose a safe subset of the Go stdlib.
|
||||
// Expose the Go stdlib. The base set covers most packages; the
|
||||
// unrestricted set adds os/exec so extensions can spawn processes.
|
||||
if err := i.Use(stdlib.Symbols); err != nil {
|
||||
return nil, fmt.Errorf("loading stdlib symbols: %w", err)
|
||||
}
|
||||
if err := i.Use(unrestricted.Symbols); err != nil {
|
||||
return nil, fmt.Errorf("loading unrestricted symbols: %w", err)
|
||||
}
|
||||
|
||||
// Expose KIT's extension API types so the extension can
|
||||
// import "kit/ext" and use ext.ToolCall, ext.API, etc.
|
||||
|
||||
Reference in New Issue
Block a user