Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/04-command-line-reference/gptscript.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ gptscript [flags] PROGRAM_FILE [INPUT...]
-q, --quiet No output logging (set --quiet=false to force on even when there is no TTY) ($GPTSCRIPT_QUIET)
--save-chat-state-file string A file to save the chat state to so that a conversation can be resumed with --chat-state ($GPTSCRIPT_SAVE_CHAT_STATE_FILE)
--sub-tool string Use tool of this name, not the first tool in file ($GPTSCRIPT_SUB_TOOL)
--system-tools-dir string Directory that contains system managed tool for which GPTScript will not manage the runtime ($GPTSCRIPT_SYSTEM_TOOLS_DIR)
--ui Launch the UI ($GPTSCRIPT_UI)
--workspace string Directory to use for the workspace, if specified it will not be deleted on exit ($GPTSCRIPT_WORKSPACE)
```
Expand Down
1 change: 1 addition & 0 deletions docs/docs/04-command-line-reference/gptscript_eval.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ gptscript eval [flags]
--openai-org-id string OpenAI organization ID ($OPENAI_ORG_ID)
-o, --output string Save output to a file, or - for stdout ($GPTSCRIPT_OUTPUT)
-q, --quiet No output logging (set --quiet=false to force on even when there is no TTY) ($GPTSCRIPT_QUIET)
--system-tools-dir string Directory that contains system managed tool for which GPTScript will not manage the runtime ($GPTSCRIPT_SYSTEM_TOOLS_DIR)
--workspace string Directory to use for the workspace, if specified it will not be deleted on exit ($GPTSCRIPT_WORKSPACE)
```

Expand Down
1 change: 1 addition & 0 deletions docs/docs/04-command-line-reference/gptscript_fmt.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ gptscript fmt [flags]
--openai-org-id string OpenAI organization ID ($OPENAI_ORG_ID)
-o, --output string Save output to a file, or - for stdout ($GPTSCRIPT_OUTPUT)
-q, --quiet No output logging (set --quiet=false to force on even when there is no TTY) ($GPTSCRIPT_QUIET)
--system-tools-dir string Directory that contains system managed tool for which GPTScript will not manage the runtime ($GPTSCRIPT_SYSTEM_TOOLS_DIR)
--workspace string Directory to use for the workspace, if specified it will not be deleted on exit ($GPTSCRIPT_WORKSPACE)
```

Expand Down
1 change: 1 addition & 0 deletions docs/docs/04-command-line-reference/gptscript_getenv.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ gptscript getenv [flags] KEY [DEFAULT]
--openai-org-id string OpenAI organization ID ($OPENAI_ORG_ID)
-o, --output string Save output to a file, or - for stdout ($GPTSCRIPT_OUTPUT)
-q, --quiet No output logging (set --quiet=false to force on even when there is no TTY) ($GPTSCRIPT_QUIET)
--system-tools-dir string Directory that contains system managed tool for which GPTScript will not manage the runtime ($GPTSCRIPT_SYSTEM_TOOLS_DIR)
--workspace string Directory to use for the workspace, if specified it will not be deleted on exit ($GPTSCRIPT_WORKSPACE)
```

Expand Down
1 change: 1 addition & 0 deletions docs/docs/04-command-line-reference/gptscript_parse.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ gptscript parse [flags]
--openai-org-id string OpenAI organization ID ($OPENAI_ORG_ID)
-o, --output string Save output to a file, or - for stdout ($GPTSCRIPT_OUTPUT)
-q, --quiet No output logging (set --quiet=false to force on even when there is no TTY) ($GPTSCRIPT_QUIET)
--system-tools-dir string Directory that contains system managed tool for which GPTScript will not manage the runtime ($GPTSCRIPT_SYSTEM_TOOLS_DIR)
--workspace string Directory to use for the workspace, if specified it will not be deleted on exit ($GPTSCRIPT_WORKSPACE)
```

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c *Credential) Run(cmd *cobra.Command, _ []string) error {
}
opts = gptscript.Complete(opts)
if opts.Runner.RuntimeManager == nil {
opts.Runner.RuntimeManager = runtimes.Default(opts.Cache.CacheDir)
opts.Runner.RuntimeManager = runtimes.Default(opts.Cache.CacheDir, opts.SystemToolsDir)
}

ctxs := opts.CredentialContexts
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/credential_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (c *Delete) Run(cmd *cobra.Command, args []string) error {

opts = gptscript.Complete(opts)
if opts.Runner.RuntimeManager == nil {
opts.Runner.RuntimeManager = runtimes.Default(opts.Cache.CacheDir)
opts.Runner.RuntimeManager = runtimes.Default(opts.Cache.CacheDir, opts.SystemToolsDir)
}

if err = opts.Runner.RuntimeManager.SetUpCredentialHelpers(cmd.Context(), cfg); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/credential_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (c *Show) Run(cmd *cobra.Command, args []string) error {

opts = gptscript.Complete(opts)
if opts.Runner.RuntimeManager == nil {
opts.Runner.RuntimeManager = runtimes.Default(opts.Cache.CacheDir)
opts.Runner.RuntimeManager = runtimes.Default(opts.Cache.CacheDir, opts.SystemToolsDir)
}

if err = opts.Runner.RuntimeManager.SetUpCredentialHelpers(cmd.Context(), cfg); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/gptscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type GPTScript struct {
CacheOptions
OpenAIOptions
DisplayOptions
SystemToolsDir string `usage:"Directory that contains system managed tool for which GPTScript will not manage the runtime"`
Color *bool `usage:"Use color in output (default true)" default:"true"`
Confirm bool `usage:"Prompt before running potentially dangerous commands"`
Debug bool `usage:"Enable debug logging"`
Expand Down Expand Up @@ -146,6 +147,7 @@ func (r *GPTScript) NewGPTScriptOpts() (gptscript.Options, error) {
Workspace: r.Workspace,
DisablePromptServer: r.UI,
DefaultModelProvider: r.DefaultModelProvider,
SystemToolsDir: r.SystemToolsDir,
}

if r.Confirm {
Expand Down
4 changes: 3 additions & 1 deletion pkg/gptscript/gptscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Options struct {
Quiet *bool
Workspace string
DisablePromptServer bool
SystemToolsDir string
Env []string
}

Expand All @@ -63,6 +64,7 @@ func Complete(opts ...Options) Options {
result.Runner = runner.Complete(result.Runner, opt.Runner)
result.OpenAI = openai.Complete(result.OpenAI, opt.OpenAI)

result.SystemToolsDir = types.FirstSet(opt.SystemToolsDir, result.SystemToolsDir)
result.CredentialContexts = opt.CredentialContexts
result.Quiet = types.FirstSet(opt.Quiet, result.Quiet)
result.Workspace = types.FirstSet(opt.Workspace, result.Workspace)
Expand Down Expand Up @@ -99,7 +101,7 @@ func New(ctx context.Context, o ...Options) (*GPTScript, error) {
}

if opts.Runner.RuntimeManager == nil {
opts.Runner.RuntimeManager = runtimes.Default(cacheClient.CacheDir())
opts.Runner.RuntimeManager = runtimes.Default(cacheClient.CacheDir(), opts.SystemToolsDir)
}

if err := opts.Runner.RuntimeManager.SetUpCredentialHelpers(context.Background(), cliCfg); err != nil {
Expand Down
23 changes: 17 additions & 6 deletions pkg/repos/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/fs"
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -58,7 +59,7 @@ type Manager struct {
storageDir string
gitDir string
runtimeDir string
systemDir string
systemDirs []string
runtimes []Runtime
credHelperConfig *credHelperConfig
}
Expand All @@ -69,14 +70,22 @@ type credHelperConfig struct {
cliCfg *config.CLIConfig
}

func New(cacheDir string, runtimes ...Runtime) *Manager {
root := filepath.Join(cacheDir, "repos")
func New(cacheDir, systemDir string, runtimes ...Runtime) *Manager {
var (
systemDirs []string
root = filepath.Join(cacheDir, "repos")
)

if strings.TrimSpace(systemDir) != "" {
systemDirs = regexp.MustCompile("[;:,]").Split(strings.TrimSpace(systemDir), -1)
}

return &Manager{
cacheDir: cacheDir,
storageDir: root,
gitDir: filepath.Join(root, "git"),
runtimeDir: filepath.Join(root, "runtimes"),
systemDir: filepath.Join(root, "system"),
systemDirs: systemDirs,
runtimes: runtimes,
}
}
Expand Down Expand Up @@ -273,8 +282,10 @@ func (m *Manager) setup(ctx context.Context, runtime Runtime, tool types.Tool, e
}

func (m *Manager) GetContext(ctx context.Context, tool types.Tool, cmd, env []string) (string, []string, error) {
if strings.HasPrefix(tool.WorkingDir, m.systemDir) {
return tool.WorkingDir, env, nil
for _, systemDir := range m.systemDirs {
if strings.HasPrefix(tool.WorkingDir, systemDir) {
return tool.WorkingDir, env, nil
}
}

var isLocal bool
Expand Down
2 changes: 1 addition & 1 deletion pkg/repos/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
)

func TestManager_GetContext(t *testing.T) {
m := New(testCacheHome, &python.Runtime{
m := New(testCacheHome, "", &python.Runtime{
Version: "3.11",
})
cwd, env, err := m.GetContext(context.Background(), types.Tool{
Expand Down
4 changes: 2 additions & 2 deletions pkg/repos/runtimes/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ var Runtimes = []repos.Runtime{
},
}

func Default(cacheDir string) engine.RuntimeManager {
return repos.New(cacheDir, Runtimes...)
func Default(cacheDir, systemDir string) engine.RuntimeManager {
return repos.New(cacheDir, systemDir, Runtimes...)
}
2 changes: 1 addition & 1 deletion pkg/sdkserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func run(ctx context.Context, listener net.Listener, opts Options) error {
workspaceTool: opts.WorkspaceTool,
client: g,
events: events,
runtimeManager: runtimes.Default(opts.Options.Cache.CacheDir), // TODO - do we always want to use runtimes.Default here?
runtimeManager: runtimes.Default(opts.Options.Cache.CacheDir, opts.SystemToolsDir),
waitingToConfirm: make(map[string]chan runner.AuthorizerResponse),
waitingToPrompt: make(map[string]chan map[string]string),
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/tester/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func NewRunner(t *testing.T) *Runner {
cacheDir, err := xdg.CacheFile("gptscript-test-cache/runtime")
require.NoError(t, err)

rm := runtimes.Default(cacheDir)
rm := runtimes.Default(cacheDir, "")

run, err := runner.New(c, credentials.NoopStore{}, runner.Options{
Sequential: true,
Expand Down