@@ -15,6 +15,7 @@ import (
15
15
"github.com/BurntSushi/locker"
16
16
"github.com/gptscript-ai/gptscript/pkg/config"
17
17
"github.com/gptscript-ai/gptscript/pkg/credentials"
18
+ "github.com/gptscript-ai/gptscript/pkg/hash"
18
19
"github.com/gptscript-ai/gptscript/pkg/loader/github"
19
20
"github.com/gptscript-ai/gptscript/pkg/repos/git"
20
21
"github.com/gptscript-ai/gptscript/pkg/repos/runtimes/golang"
@@ -51,13 +52,22 @@ type Manager struct {
51
52
credHelperDirs credentials.CredentialHelperDirs
52
53
runtimes []Runtime
53
54
credHelperConfig * credHelperConfig
55
+ supportLocal bool
54
56
}
55
57
56
58
type credHelperConfig struct {
57
59
lock sync.Mutex
58
60
initialized bool
59
61
cliCfg * config.CLIConfig
60
62
env []string
63
+ storageDir string
64
+ gitDir string
65
+ runtimeDir string
66
+ runtimes []Runtime
67
+ }
68
+
69
+ func (m * Manager ) SetSupportLocal () {
70
+ m .supportLocal = true
61
71
}
62
72
63
73
func New (cacheDir string , runtimes ... Runtime ) * Manager {
@@ -200,8 +210,14 @@ func (m *Manager) setup(ctx context.Context, runtime Runtime, tool types.Tool, e
200
210
_ = os .RemoveAll (doneFile )
201
211
_ = os .RemoveAll (target )
202
212
203
- if err := git .Checkout (ctx , m .gitDir , tool .Source .Repo .Root , tool .Source .Repo .Revision , target ); err != nil {
204
- return "" , nil , err
213
+ if tool .Source .Repo .VCS == "git" {
214
+ if err := git .Checkout (ctx , m .gitDir , tool .Source .Repo .Root , tool .Source .Repo .Revision , target ); err != nil {
215
+ return "" , nil , err
216
+ }
217
+ } else {
218
+ if err := os .MkdirAll (target , 0755 ); err != nil {
219
+ return "" , nil , err
220
+ }
205
221
}
206
222
207
223
newEnv , err := runtime .Setup (ctx , m .runtimeDir , targetFinal , env )
@@ -227,12 +243,25 @@ func (m *Manager) setup(ctx context.Context, runtime Runtime, tool types.Tool, e
227
243
}
228
244
229
245
func (m * Manager ) GetContext (ctx context.Context , tool types.Tool , cmd , env []string ) (string , []string , error ) {
230
- if tool .Source .Repo == nil {
231
- return tool .WorkingDir , env , nil
232
- }
246
+ var isLocal bool
247
+ if ! m .supportLocal {
248
+ if tool .Source .Repo == nil {
249
+ return tool .WorkingDir , env , nil
250
+ }
233
251
234
- if tool .Source .Repo .VCS != "git" {
235
- return "" , nil , fmt .Errorf ("only git is supported, found VCS %s for %s" , tool .Source .Repo .VCS , tool .ID )
252
+ if tool .Source .Repo .VCS != "git" {
253
+ return "" , nil , fmt .Errorf ("only git is supported, found VCS %s for %s" , tool .Source .Repo .VCS , tool .ID )
254
+ }
255
+ } else if tool .Source .Repo == nil {
256
+ isLocal = true
257
+ id := hash .Digest (tool )[:12 ]
258
+ tool .Source .Repo = & types.Repo {
259
+ VCS : "<local>" ,
260
+ Root : id ,
261
+ Path : "/" ,
262
+ Name : id ,
263
+ Revision : id ,
264
+ }
236
265
}
237
266
238
267
for _ , runtime := range m .runtimes {
@@ -242,5 +271,9 @@ func (m *Manager) GetContext(ctx context.Context, tool types.Tool, cmd, env []st
242
271
}
243
272
}
244
273
274
+ if isLocal {
275
+ return tool .WorkingDir , env , nil
276
+ }
277
+
245
278
return m .setup (ctx , & noopRuntime {}, tool , env )
246
279
}
0 commit comments