Skip to content

Commit 9c0d6dd

Browse files
thedadamsnjhale
authored andcommitted
fix: use shellwords instead of shlex
The shlex splitting was ruining Windows paths. The shellwords is nicer to Windows. Signed-off-by: Donnie Adams <[email protected]> Signed-off-by: Nick Hale <[email protected]>
1 parent 2bbe7bc commit 9c0d6dd

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ require (
77
github.com/AlecAivazis/survey/v2 v2.3.7
88
github.com/BurntSushi/locker v0.0.0-20171006230638-a6e239ea1c69
99
github.com/adrg/xdg v0.4.0
10+
github.com/buildkite/shellwords v0.0.0-20180315110454-59467a9b8e10
1011
github.com/chzyer/readline v1.5.1
1112
github.com/docker/cli v26.0.0+incompatible
1213
github.com/docker/docker-credential-helpers v0.8.1
1314
github.com/fatih/color v1.17.0
1415
github.com/getkin/kin-openapi v0.124.0
15-
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
1616
github.com/google/uuid v1.6.0
1717
github.com/gptscript-ai/broadcaster v0.0.0-20240625175512-c43682019b86
1818
github.com/gptscript-ai/chat-completion-client v0.0.0-20240531200700-af8e7ecf0379

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ github.com/bodgit/sevenzip v1.3.0 h1:1ljgELgtHqvgIp8W8kgeEGHIWP4ch3xGI8uOBZgLVKY
6161
github.com/bodgit/sevenzip v1.3.0/go.mod h1:omwNcgZTEooWM8gA/IJ2Nk/+ZQ94+GsytRzOJJ8FBlM=
6262
github.com/bodgit/windows v1.0.0 h1:rLQ/XjsleZvx4fR1tB/UxQrK+SJ2OFHzfPjLWWOhDIA=
6363
github.com/bodgit/windows v1.0.0/go.mod h1:a6JLwrB4KrTR5hBpp8FI9/9W9jJfeQ2h4XDXU74ZCdM=
64+
github.com/buildkite/shellwords v0.0.0-20180315110454-59467a9b8e10 h1:XwHQ5xDtYPdtBbVPyRO6UZoWZe8/mbKUb076f8x7RvI=
65+
github.com/buildkite/shellwords v0.0.0-20180315110454-59467a9b8e10/go.mod h1:gv0DYOzHEsKgo31lTCDGauIg4DTTGn41Bzp+t3wSOlk=
6466
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
6567
github.com/charmbracelet/glamour v0.7.0 h1:2BtKGZ4iVJCDfMF229EzbeR1QRKLWztO9dMtjmqZSng=
6668
github.com/charmbracelet/glamour v0.7.0/go.mod h1:jUMh5MeihljJPQbJ/wf4ldw2+yBP59+ctV36jASy7ps=
@@ -153,8 +155,6 @@ github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OI
153155
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
154156
github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
155157
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
156-
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
157-
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
158158
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
159159
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
160160
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=

pkg/engine/cmd.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"strings"
1818
"sync"
1919

20-
"github.com/google/shlex"
20+
"github.com/buildkite/shellwords"
2121
"github.com/gptscript-ai/gptscript/pkg/counter"
2222
"github.com/gptscript-ai/gptscript/pkg/env"
2323
"github.com/gptscript-ai/gptscript/pkg/types"
@@ -118,7 +118,7 @@ func (e *Engine) runCommand(ctx Context, tool types.Tool, input string, toolCate
118118
instructions = append(instructions, inputContext.Content)
119119
}
120120

121-
var extraEnv = []string{
121+
extraEnv := []string{
122122
strings.TrimSpace("GPTSCRIPT_CONTEXT=" + strings.Join(instructions, "\n")),
123123
}
124124
cmd, stop, err := e.newCommand(ctx.Ctx, extraEnv, tool, input)
@@ -254,7 +254,7 @@ func (e *Engine) newCommand(ctx context.Context, extraEnv []string, tool types.T
254254
interpreter, rest, _ := strings.Cut(tool.Instructions, "\n")
255255
interpreter = strings.TrimSpace(interpreter)[2:]
256256

257-
args, err := shlex.Split(interpreter)
257+
args, err := shellwords.Split(interpreter)
258258
if err != nil {
259259
return nil, nil, err
260260
}
@@ -332,15 +332,15 @@ func replaceVariablesForInterpreter(interpreter string, envMap map[string]string
332332
return envMap[s]
333333
})
334334
// We protect newly resolved env vars from getting replaced when we do the second Expand
335-
// after shlex. Yeah, crazy. I'm guessing this isn't secure, but just trying to avoid a foot gun.
335+
// after shellwords. Yeah, crazy. I'm guessing this isn't secure, but just trying to avoid a foot gun.
336336
part = os.Expand(part, func(s string) string {
337337
return "${__" + s + "}"
338338
})
339339
}
340340
parts = append(parts, part)
341341
}
342342

343-
parts, err := shlex.Split(strings.Join(parts, ""))
343+
parts, err := shellwords.Split(strings.Join(parts, ""))
344344
if err != nil {
345345
return nil, err
346346
}

pkg/types/tool.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"sort"
1010
"strings"
1111

12+
"github.com/buildkite/shellwords"
1213
"github.com/getkin/kin-openapi/openapi3"
13-
"github.com/google/shlex"
1414
"github.com/gptscript-ai/gptscript/pkg/system"
1515
"golang.org/x/exp/maps"
1616
)
@@ -22,9 +22,7 @@ const (
2222
CommandPrefix = "#!"
2323
)
2424

25-
var (
26-
DefaultFiles = []string{"agent.gpt", "tool.gpt"}
27-
)
25+
var DefaultFiles = []string{"agent.gpt", "tool.gpt"}
2826

2927
type ToolType string
3028

@@ -257,7 +255,7 @@ func ParseCredentialArgs(toolName string, input string) (string, string, map[str
257255
_ = json.Unmarshal([]byte(input), &inputMap)
258256
}
259257

260-
fields, err := shlex.Split(toolName)
258+
fields, err := shellwords.Split(toolName)
261259
if err != nil {
262260
return "", "", nil, err
263261
}

0 commit comments

Comments
 (0)