diff --git a/tools/file/editfile.go b/tools/file/editfile.go index d136b6a..c1f43d7 100644 --- a/tools/file/editfile.go +++ b/tools/file/editfile.go @@ -5,7 +5,9 @@ import ( "encoding/json" "fmt" "os" + "path/filepath" "strings" + "github.com/sausheong/harness/tool" ) @@ -61,6 +63,9 @@ func (t *EditFileTool) Execute(_ context.Context, input json.RawMessage) (tool.T } in.Path = tool.ExpandHome(in.Path) + if t.WorkDir != "" && !filepath.IsAbs(in.Path) { + in.Path = filepath.Join(t.WorkDir, in.Path) + } in.Path = tool.ResolveExistingPath(in.Path) if t.WorkDir != "" { diff --git a/tools/file/readfile.go b/tools/file/readfile.go index 8b8d33f..8a6c793 100644 --- a/tools/file/readfile.go +++ b/tools/file/readfile.go @@ -82,6 +82,9 @@ func (t *ReadFileTool) Execute(_ context.Context, input json.RawMessage) (tool.T } in.Path = tool.ExpandHome(in.Path) + if t.WorkDir != "" && !filepath.IsAbs(in.Path) { + in.Path = filepath.Join(t.WorkDir, in.Path) + } in.Path = tool.ResolveExistingPath(in.Path) if t.WorkDir != "" { diff --git a/tools/file/writefile.go b/tools/file/writefile.go index 058855a..1a63b81 100644 --- a/tools/file/writefile.go +++ b/tools/file/writefile.go @@ -56,6 +56,9 @@ func (t *WriteFileTool) Execute(_ context.Context, input json.RawMessage) (tool. } in.Path = tool.ExpandHome(in.Path) + if t.WorkDir != "" && !filepath.IsAbs(in.Path) { + in.Path = filepath.Join(t.WorkDir, in.Path) + } if t.WorkDir != "" { if err := tool.ValidatePathInWorkDir(in.Path, t.WorkDir); err != nil {