fix(file tools): resolve relative paths against WorkDir before workspace validation

When the agent supplies a relative path (e.g. "app.py"), filepath.Abs resolves
it against the process CWD, not the workspace — causing ValidatePathInWorkDir
to reject paths that are legitimately inside the workspace.

Join relative paths with WorkDir before resolution so the agent can use bare
filenames without hitting the outside-workspace error.
This commit is contained in:
sausheong committed 2026-05-12 17:10:32 +08:00
1 parent c2af8f389d
commit 65021e1fe2
3 files changed
+11

No files matched your search

+5
View File
@@ -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 != "" {
+3
View File
@@ -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 != "" {
+3
View File
@@ -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 {