shell: support Windows cmd /C; normalize date/time; allow all commands; add tests
This commit is contained in:
@@ -8,31 +8,42 @@ import (
|
||||
"laodingbot/internal/config"
|
||||
"laodingbot/internal/logger"
|
||||
"laodingbot/internal/tools"
|
||||
"laodingbot/internal/tools/filetool"
|
||||
"laodingbot/internal/tools/shelltool"
|
||||
"laodingbot/tools/fileoperation"
|
||||
"laodingbot/tools/shell"
|
||||
"laodingbot/tools/websearch"
|
||||
)
|
||||
|
||||
func RunChild(ctx context.Context, cfg config.Config, log *logger.Logger) error {
|
||||
var registryLog *logger.Logger
|
||||
var fileLog *logger.Logger
|
||||
var shellLog *logger.Logger
|
||||
var searchLog *logger.Logger
|
||||
var serverLog *logger.Logger
|
||||
if log != nil {
|
||||
log.Infof("toolhost child starting")
|
||||
registryLog = log.WithComponent("toolhost.registry")
|
||||
fileLog = log.WithComponent("toolhost.file")
|
||||
shellLog = log.WithComponent("toolhost.shell")
|
||||
searchLog = log.WithComponent("toolhost.websearch")
|
||||
serverLog = log.WithComponent("toolhost.server")
|
||||
}
|
||||
registry := tools.NewRegistry(registryLog)
|
||||
registry.Register(filetool.New(cfg.Security.AllowedDirs, cfg.ToolOutputMaxChars, fileLog))
|
||||
registry.Register(shelltool.New(
|
||||
registry.Register(fileoperation.New(cfg.Security.AllowedDirs, cfg.ToolOutputMaxChars, fileLog))
|
||||
registry.Register(shell.New(
|
||||
cfg.Security.AllowedCommands,
|
||||
cfg.Security.WorkDir,
|
||||
time.Duration(cfg.ToolCallTimeoutSec)*time.Second,
|
||||
cfg.ToolOutputMaxChars,
|
||||
shellLog,
|
||||
))
|
||||
registry.Register(websearch.New(
|
||||
websearch.Config{
|
||||
Engine: cfg.WebSearch.Engine,
|
||||
APIKey: cfg.WebSearch.APIKey,
|
||||
},
|
||||
cfg.ToolOutputMaxChars,
|
||||
searchLog,
|
||||
))
|
||||
|
||||
server := NewServer(registry, serverLog)
|
||||
if err := server.Serve(ctx, stdin(), stdout()); err != nil && ctx.Err() == nil {
|
||||
|
||||
Reference in New Issue
Block a user