summaryrefslogtreecommitdiff
path: root/tools.go
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2026-02-18 22:00:52 +0300
committerGrail Finder <wohilas@gmail.com>2026-02-18 22:00:52 +0300
commit931b646c303af84192c36b2825293b86524dd6f3 (patch)
treeb05c79f4688a639ab71fa6a861f42c6137ca0e45 /tools.go
parentf560ecf70baa163b7f384b4d8162bf41026e80f9 (diff)
Enha: codingdir for coding assistant
Diffstat (limited to 'tools.go')
-rw-r--r--tools.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/tools.go b/tools.go
index dbf1f89..dcf0632 100644
--- a/tools.go
+++ b/tools.go
@@ -9,6 +9,7 @@ import (
"io"
"os"
"os/exec"
+ "path/filepath"
"regexp"
"strconv"
"strings"
@@ -377,6 +378,8 @@ func fileCreate(args map[string]string) []byte {
return []byte(msg)
}
+ path = resolvePath(path)
+
content, ok := args["content"]
if !ok {
content = ""
@@ -400,6 +403,8 @@ func fileRead(args map[string]string) []byte {
return []byte(msg)
}
+ path = resolvePath(path)
+
content, err := readStringFromFile(path)
if err != nil {
msg := "failed to read file; error: " + err.Error()
@@ -428,6 +433,7 @@ func fileWrite(args map[string]string) []byte {
logger.Error(msg)
return []byte(msg)
}
+ path = resolvePath(path)
content, ok := args["content"]
if !ok {
content = ""
@@ -448,6 +454,7 @@ func fileWriteAppend(args map[string]string) []byte {
logger.Error(msg)
return []byte(msg)
}
+ path = resolvePath(path)
content, ok := args["content"]
if !ok {
content = ""
@@ -469,6 +476,8 @@ func fileDelete(args map[string]string) []byte {
return []byte(msg)
}
+ path = resolvePath(path)
+
if err := removeFile(path); err != nil {
msg := "failed to delete file; error: " + err.Error()
logger.Error(msg)
@@ -486,6 +495,7 @@ func fileMove(args map[string]string) []byte {
logger.Error(msg)
return []byte(msg)
}
+ src = resolvePath(src)
dst, ok := args["dst"]
if !ok || dst == "" {
@@ -493,6 +503,7 @@ func fileMove(args map[string]string) []byte {
logger.Error(msg)
return []byte(msg)
}
+ dst = resolvePath(dst)
if err := moveFile(src, dst); err != nil {
msg := "failed to move file; error: " + err.Error()
@@ -511,6 +522,7 @@ func fileCopy(args map[string]string) []byte {
logger.Error(msg)
return []byte(msg)
}
+ src = resolvePath(src)
dst, ok := args["dst"]
if !ok || dst == "" {
@@ -518,6 +530,7 @@ func fileCopy(args map[string]string) []byte {
logger.Error(msg)
return []byte(msg)
}
+ dst = resolvePath(dst)
if err := copyFile(src, dst); err != nil {
msg := "failed to copy file; error: " + err.Error()
@@ -535,6 +548,8 @@ func fileList(args map[string]string) []byte {
path = "." // default to current directory
}
+ path = resolvePath(path)
+
files, err := listDirectory(path)
if err != nil {
msg := "failed to list directory; error: " + err.Error()
@@ -558,6 +573,13 @@ func fileList(args map[string]string) []byte {
// Helper functions for file operations
+func resolvePath(p string) string {
+ if filepath.IsAbs(p) {
+ return p
+ }
+ return filepath.Join(cfg.CodingDir, p)
+}
+
func readStringFromFile(filename string) (string, error) {
data, err := os.ReadFile(filename)
if err != nil {