@@ -10,6 +10,7 @@ import (
1010 "path/filepath"
1111
1212 "github.com/BurntSushi/locker"
13+ "github.com/gptscript-ai/gptscript/pkg/hash"
1314 "github.com/gptscript-ai/gptscript/pkg/repos/git"
1415 "github.com/gptscript-ai/gptscript/pkg/types"
1516)
@@ -36,10 +37,15 @@ func (n noopRuntime) Setup(_ context.Context, _, _ string, _ []string) ([]string
3637}
3738
3839type Manager struct {
39- storageDir string
40- gitDir string
41- runtimeDir string
42- runtimes []Runtime
40+ storageDir string
41+ gitDir string
42+ runtimeDir string
43+ runtimes []Runtime
44+ supportLocal bool
45+ }
46+
47+ func (m * Manager ) SetSupportLocal () {
48+ m .supportLocal = true
4349}
4450
4551func New (cacheDir string , runtimes ... Runtime ) * Manager {
@@ -74,8 +80,14 @@ func (m *Manager) setup(ctx context.Context, runtime Runtime, tool types.Tool, e
7480 _ = os .RemoveAll (doneFile )
7581 _ = os .RemoveAll (target )
7682
77- if err := git .Checkout (ctx , m .gitDir , tool .Source .Repo .Root , tool .Source .Repo .Revision , target ); err != nil {
78- return "" , nil , err
83+ if tool .Source .Repo .VCS == "git" {
84+ if err := git .Checkout (ctx , m .gitDir , tool .Source .Repo .Root , tool .Source .Repo .Revision , target ); err != nil {
85+ return "" , nil , err
86+ }
87+ } else {
88+ if err := os .MkdirAll (target , 0755 ); err != nil {
89+ return "" , nil , err
90+ }
7991 }
8092
8193 newEnv , err := runtime .Setup (ctx , m .runtimeDir , targetFinal , env )
@@ -101,12 +113,25 @@ func (m *Manager) setup(ctx context.Context, runtime Runtime, tool types.Tool, e
101113}
102114
103115func (m * Manager ) GetContext (ctx context.Context , tool types.Tool , cmd , env []string ) (string , []string , error ) {
104- if tool .Source .Repo == nil {
105- return tool .WorkingDir , env , nil
106- }
116+ var isLocal bool
117+ if ! m .supportLocal {
118+ if tool .Source .Repo == nil {
119+ return tool .WorkingDir , env , nil
120+ }
107121
108- if tool .Source .Repo .VCS != "git" {
109- return "" , nil , fmt .Errorf ("only git is supported, found VCS %s for %s" , tool .Source .Repo .VCS , tool .ID )
122+ if tool .Source .Repo .VCS != "git" {
123+ return "" , nil , fmt .Errorf ("only git is supported, found VCS %s for %s" , tool .Source .Repo .VCS , tool .ID )
124+ }
125+ } else if tool .Source .Repo == nil {
126+ isLocal = true
127+ id := hash .Digest (tool )[:12 ]
128+ tool .Source .Repo = & types.Repo {
129+ VCS : "<local>" ,
130+ Root : id ,
131+ Path : "/" ,
132+ Name : id ,
133+ Revision : id ,
134+ }
110135 }
111136
112137 for _ , runtime := range m .runtimes {
@@ -116,5 +141,9 @@ func (m *Manager) GetContext(ctx context.Context, tool types.Tool, cmd, env []st
116141 }
117142 }
118143
144+ if isLocal {
145+ return tool .WorkingDir , env , nil
146+ }
147+
119148 return m .setup (ctx , & noopRuntime {}, tool , env )
120149}
0 commit comments