@@ -269,18 +269,14 @@ func ListTools() (result []types.Tool) {
269
269
270
270
sort .Strings (keys )
271
271
for _ , key := range keys {
272
- t , _ := Builtin (key )
272
+ t , _ := DefaultModel (key , "" )
273
273
result = append (result , t )
274
274
}
275
275
276
276
return
277
277
}
278
278
279
- func Builtin (name string ) (types.Tool , bool ) {
280
- return BuiltinWithDefaultModel (name , "" )
281
- }
282
-
283
- func BuiltinWithDefaultModel (name , defaultModel string ) (types.Tool , bool ) {
279
+ func DefaultModel (name , defaultModel string ) (types.Tool , bool ) {
284
280
// Legacy syntax not used anymore
285
281
name = strings .TrimSuffix (name , "?" )
286
282
t , ok := tools [name ]
@@ -332,7 +328,7 @@ func SysFind(_ context.Context, _ []string, input string, _ chan<- string) (stri
332
328
return strings .Join (result , "\n " ), nil
333
329
}
334
330
335
- func SysExec (_ context.Context , env []string , input string , progress chan <- string ) (string , error ) {
331
+ func SysExec (ctx context.Context , env []string , input string , progress chan <- string ) (string , error ) {
336
332
var params struct {
337
333
Command string `json:"command,omitempty"`
338
334
Directory string `json:"directory,omitempty"`
@@ -345,14 +341,20 @@ func SysExec(_ context.Context, env []string, input string, progress chan<- stri
345
341
params .Directory = "."
346
342
}
347
343
344
+ commandCtx , _ := engine .FromContext (ctx )
345
+
346
+ ctx , cancel := context .WithCancel (ctx )
347
+ defer cancel ()
348
+
349
+ commandCtx .OnUserCancel (ctx , cancel )
350
+
348
351
log .Debugf ("Running %s in %s" , params .Command , params .Directory )
349
352
350
353
var cmd * exec.Cmd
351
-
352
354
if runtime .GOOS == "windows" {
353
- cmd = exec .Command ( "cmd.exe" , "/c" , params .Command )
355
+ cmd = exec .CommandContext ( ctx , "cmd.exe" , "/c" , params .Command )
354
356
} else {
355
- cmd = exec .Command ( "/bin/sh" , "-c" , params .Command )
357
+ cmd = exec .CommandContext ( ctx , "/bin/sh" , "-c" , params .Command )
356
358
}
357
359
358
360
var (
@@ -371,7 +373,8 @@ func SysExec(_ context.Context, env []string, input string, progress chan<- stri
371
373
cmd .Dir = params .Directory
372
374
cmd .Stdout = combined
373
375
cmd .Stderr = combined
374
- if err := cmd .Run (); err != nil {
376
+ if err := cmd .Run (); err != nil && (ctx .Err () == nil || commandCtx .Ctx .Err () != nil ) {
377
+ // If the command failed and the context hasn't been canceled, then return the error.
375
378
return fmt .Sprintf ("ERROR: %s\n OUTPUT:\n %s" , err , & out ), nil
376
379
}
377
380
return out .String (), nil
@@ -420,7 +423,6 @@ func getWorkspaceEnvFileContents(envs []string) ([]string, error) {
420
423
}
421
424
422
425
return envContents , nil
423
-
424
426
}
425
427
426
428
func getWorkspaceDir (envs []string ) (string , error ) {
@@ -665,6 +667,7 @@ func DiscardProgress() (progress chan<- string, closeFunc func()) {
665
667
ch := make (chan string )
666
668
go func () {
667
669
for range ch {
670
+ continue
668
671
}
669
672
}()
670
673
return ch , func () {
0 commit comments