@@ -10,6 +10,7 @@ import (
10
10
"path/filepath"
11
11
12
12
"github.com/BurntSushi/locker"
13
+ "github.com/gptscript-ai/gptscript/pkg/hash"
13
14
"github.com/gptscript-ai/gptscript/pkg/repos/git"
14
15
"github.com/gptscript-ai/gptscript/pkg/types"
15
16
)
@@ -36,10 +37,15 @@ func (n noopRuntime) Setup(_ context.Context, _, _ string, _ []string) ([]string
36
37
}
37
38
38
39
type 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
43
49
}
44
50
45
51
func New (cacheDir string , runtimes ... Runtime ) * Manager {
@@ -74,8 +80,14 @@ func (m *Manager) setup(ctx context.Context, runtime Runtime, tool types.Tool, e
74
80
_ = os .RemoveAll (doneFile )
75
81
_ = os .RemoveAll (target )
76
82
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
+ }
79
91
}
80
92
81
93
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
101
113
}
102
114
103
115
func (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
+ }
107
121
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
+ }
110
135
}
111
136
112
137
for _ , runtime := range m .runtimes {
@@ -116,5 +141,9 @@ func (m *Manager) GetContext(ctx context.Context, tool types.Tool, cmd, env []st
116
141
}
117
142
}
118
143
144
+ if isLocal {
145
+ return tool .WorkingDir , env , nil
146
+ }
147
+
119
148
return m .setup (ctx , & noopRuntime {}, tool , env )
120
149
}
0 commit comments