Skip to content

Commit 2d1632c

Browse files
feat: add system-tools-dir for system managed tools
1 parent 519883a commit 2d1632c

File tree

15 files changed

+35
-15
lines changed

15 files changed

+35
-15
lines changed

docs/docs/04-command-line-reference/gptscript.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ gptscript [flags] PROGRAM_FILE [INPUT...]
4343
-q, --quiet No output logging (set --quiet=false to force on even when there is no TTY) ($GPTSCRIPT_QUIET)
4444
--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)
4545
--sub-tool string Use tool of this name, not the first tool in file ($GPTSCRIPT_SUB_TOOL)
46+
--system-tools-dir string Directory that contains system managed tool for which GPTScript will not manage the runtime ($GPTSCRIPT_SYSTEM_TOOLS_DIR)
4647
--ui Launch the UI ($GPTSCRIPT_UI)
4748
--workspace string Directory to use for the workspace, if specified it will not be deleted on exit ($GPTSCRIPT_WORKSPACE)
4849
```

docs/docs/04-command-line-reference/gptscript_eval.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ gptscript eval [flags]
4646
--openai-org-id string OpenAI organization ID ($OPENAI_ORG_ID)
4747
-o, --output string Save output to a file, or - for stdout ($GPTSCRIPT_OUTPUT)
4848
-q, --quiet No output logging (set --quiet=false to force on even when there is no TTY) ($GPTSCRIPT_QUIET)
49+
--system-tools-dir string Directory that contains system managed tool for which GPTScript will not manage the runtime ($GPTSCRIPT_SYSTEM_TOOLS_DIR)
4950
--workspace string Directory to use for the workspace, if specified it will not be deleted on exit ($GPTSCRIPT_WORKSPACE)
5051
```
5152

docs/docs/04-command-line-reference/gptscript_fmt.md

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ gptscript fmt [flags]
4040
--openai-org-id string OpenAI organization ID ($OPENAI_ORG_ID)
4141
-o, --output string Save output to a file, or - for stdout ($GPTSCRIPT_OUTPUT)
4242
-q, --quiet No output logging (set --quiet=false to force on even when there is no TTY) ($GPTSCRIPT_QUIET)
43+
--system-tools-dir string Directory that contains system managed tool for which GPTScript will not manage the runtime ($GPTSCRIPT_SYSTEM_TOOLS_DIR)
4344
--workspace string Directory to use for the workspace, if specified it will not be deleted on exit ($GPTSCRIPT_WORKSPACE)
4445
```
4546

docs/docs/04-command-line-reference/gptscript_getenv.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ gptscript getenv [flags] KEY [DEFAULT]
3939
--openai-org-id string OpenAI organization ID ($OPENAI_ORG_ID)
4040
-o, --output string Save output to a file, or - for stdout ($GPTSCRIPT_OUTPUT)
4141
-q, --quiet No output logging (set --quiet=false to force on even when there is no TTY) ($GPTSCRIPT_QUIET)
42+
--system-tools-dir string Directory that contains system managed tool for which GPTScript will not manage the runtime ($GPTSCRIPT_SYSTEM_TOOLS_DIR)
4243
--workspace string Directory to use for the workspace, if specified it will not be deleted on exit ($GPTSCRIPT_WORKSPACE)
4344
```
4445

docs/docs/04-command-line-reference/gptscript_parse.md

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ gptscript parse [flags]
4040
--openai-org-id string OpenAI organization ID ($OPENAI_ORG_ID)
4141
-o, --output string Save output to a file, or - for stdout ($GPTSCRIPT_OUTPUT)
4242
-q, --quiet No output logging (set --quiet=false to force on even when there is no TTY) ($GPTSCRIPT_QUIET)
43+
--system-tools-dir string Directory that contains system managed tool for which GPTScript will not manage the runtime ($GPTSCRIPT_SYSTEM_TOOLS_DIR)
4344
--workspace string Directory to use for the workspace, if specified it will not be deleted on exit ($GPTSCRIPT_WORKSPACE)
4445
```
4546

pkg/cli/credential.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (c *Credential) Run(cmd *cobra.Command, _ []string) error {
4848
}
4949
opts = gptscript.Complete(opts)
5050
if opts.Runner.RuntimeManager == nil {
51-
opts.Runner.RuntimeManager = runtimes.Default(opts.Cache.CacheDir)
51+
opts.Runner.RuntimeManager = runtimes.Default(opts.Cache.CacheDir, opts.SystemToolsDir)
5252
}
5353

5454
ctxs := opts.CredentialContexts

pkg/cli/credential_delete.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (c *Delete) Run(cmd *cobra.Command, args []string) error {
3535

3636
opts = gptscript.Complete(opts)
3737
if opts.Runner.RuntimeManager == nil {
38-
opts.Runner.RuntimeManager = runtimes.Default(opts.Cache.CacheDir)
38+
opts.Runner.RuntimeManager = runtimes.Default(opts.Cache.CacheDir, opts.SystemToolsDir)
3939
}
4040

4141
if err = opts.Runner.RuntimeManager.SetUpCredentialHelpers(cmd.Context(), cfg); err != nil {

pkg/cli/credential_show.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (c *Show) Run(cmd *cobra.Command, args []string) error {
3737

3838
opts = gptscript.Complete(opts)
3939
if opts.Runner.RuntimeManager == nil {
40-
opts.Runner.RuntimeManager = runtimes.Default(opts.Cache.CacheDir)
40+
opts.Runner.RuntimeManager = runtimes.Default(opts.Cache.CacheDir, opts.SystemToolsDir)
4141
}
4242

4343
if err = opts.Runner.RuntimeManager.SetUpCredentialHelpers(cmd.Context(), cfg); err != nil {

pkg/cli/gptscript.go

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type GPTScript struct {
4747
CacheOptions
4848
OpenAIOptions
4949
DisplayOptions
50+
SystemToolsDir string `usage:"Directory that contains system managed tool for which GPTScript will not manage the runtime"`
5051
Color *bool `usage:"Use color in output (default true)" default:"true"`
5152
Confirm bool `usage:"Prompt before running potentially dangerous commands"`
5253
Debug bool `usage:"Enable debug logging"`
@@ -146,6 +147,7 @@ func (r *GPTScript) NewGPTScriptOpts() (gptscript.Options, error) {
146147
Workspace: r.Workspace,
147148
DisablePromptServer: r.UI,
148149
DefaultModelProvider: r.DefaultModelProvider,
150+
SystemToolsDir: r.SystemToolsDir,
149151
}
150152

151153
if r.Confirm {

pkg/gptscript/gptscript.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type Options struct {
5252
Quiet *bool
5353
Workspace string
5454
DisablePromptServer bool
55+
SystemToolsDir string
5556
Env []string
5657
}
5758

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

67+
result.SystemToolsDir = types.FirstSet(opt.SystemToolsDir, result.SystemToolsDir)
6668
result.CredentialContexts = opt.CredentialContexts
6769
result.Quiet = types.FirstSet(opt.Quiet, result.Quiet)
6870
result.Workspace = types.FirstSet(opt.Workspace, result.Workspace)
@@ -99,7 +101,7 @@ func New(ctx context.Context, o ...Options) (*GPTScript, error) {
99101
}
100102

101103
if opts.Runner.RuntimeManager == nil {
102-
opts.Runner.RuntimeManager = runtimes.Default(cacheClient.CacheDir())
104+
opts.Runner.RuntimeManager = runtimes.Default(cacheClient.CacheDir(), opts.SystemToolsDir)
103105
}
104106

105107
if err := opts.Runner.RuntimeManager.SetUpCredentialHelpers(context.Background(), cliCfg); err != nil {

pkg/repos/get.go

+17-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io/fs"
99
"os"
1010
"path/filepath"
11+
"regexp"
1112
"runtime"
1213
"strings"
1314
"sync"
@@ -58,7 +59,7 @@ type Manager struct {
5859
storageDir string
5960
gitDir string
6061
runtimeDir string
61-
systemDir string
62+
systemDirs []string
6263
runtimes []Runtime
6364
credHelperConfig *credHelperConfig
6465
}
@@ -69,14 +70,22 @@ type credHelperConfig struct {
6970
cliCfg *config.CLIConfig
7071
}
7172

72-
func New(cacheDir string, runtimes ...Runtime) *Manager {
73-
root := filepath.Join(cacheDir, "repos")
73+
func New(cacheDir, systemDir string, runtimes ...Runtime) *Manager {
74+
var (
75+
systemDirs []string
76+
root = filepath.Join(cacheDir, "repos")
77+
)
78+
79+
if strings.TrimSpace(systemDir) != "" {
80+
systemDirs = regexp.MustCompile("[;:,]").Split(strings.TrimSpace(systemDir), -1)
81+
}
82+
7483
return &Manager{
7584
cacheDir: cacheDir,
7685
storageDir: root,
7786
gitDir: filepath.Join(root, "git"),
7887
runtimeDir: filepath.Join(root, "runtimes"),
79-
systemDir: filepath.Join(root, "system"),
88+
systemDirs: systemDirs,
8089
runtimes: runtimes,
8190
}
8291
}
@@ -273,8 +282,10 @@ func (m *Manager) setup(ctx context.Context, runtime Runtime, tool types.Tool, e
273282
}
274283

275284
func (m *Manager) GetContext(ctx context.Context, tool types.Tool, cmd, env []string) (string, []string, error) {
276-
if strings.HasPrefix(tool.WorkingDir, m.systemDir) {
277-
return tool.WorkingDir, env, nil
285+
for _, systemDir := range m.systemDirs {
286+
if strings.HasPrefix(tool.WorkingDir, systemDir) {
287+
return tool.WorkingDir, env, nil
288+
}
278289
}
279290

280291
var isLocal bool

pkg/repos/get_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
)
2020

2121
func TestManager_GetContext(t *testing.T) {
22-
m := New(testCacheHome, &python.Runtime{
22+
m := New(testCacheHome, "", &python.Runtime{
2323
Version: "3.11",
2424
})
2525
cwd, env, err := m.GetContext(context.Background(), types.Tool{

pkg/repos/runtimes/default.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ var Runtimes = []repos.Runtime{
3030
},
3131
}
3232

33-
func Default(cacheDir string) engine.RuntimeManager {
34-
return repos.New(cacheDir, Runtimes...)
33+
func Default(cacheDir, systemDir string) engine.RuntimeManager {
34+
return repos.New(cacheDir, systemDir, Runtimes...)
3535
}

pkg/sdkserver/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func run(ctx context.Context, listener net.Listener, opts Options) error {
111111
workspaceTool: opts.WorkspaceTool,
112112
client: g,
113113
events: events,
114-
runtimeManager: runtimes.Default(opts.Options.Cache.CacheDir), // TODO - do we always want to use runtimes.Default here?
114+
runtimeManager: runtimes.Default(opts.Options.Cache.CacheDir, opts.SystemToolsDir),
115115
waitingToConfirm: make(map[string]chan runner.AuthorizerResponse),
116116
waitingToPrompt: make(map[string]chan map[string]string),
117117
}

pkg/tests/tester/runner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func NewRunner(t *testing.T) *Runner {
196196
cacheDir, err := xdg.CacheFile("gptscript-test-cache/runtime")
197197
require.NoError(t, err)
198198

199-
rm := runtimes.Default(cacheDir)
199+
rm := runtimes.Default(cacheDir, "")
200200

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

0 commit comments

Comments
 (0)