summaryrefslogtreecommitdiffhomepage
path: root/internal/llm/tools/edit.go
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-04-21 14:29:03 +0200
committerKujtim Hoxha <[email protected]>2025-04-21 14:29:28 +0200
commita8d5787e8ef561037f73b669128f46ae1b1e8553 (patch)
treeb606adbc85069d60cc518c74508a7ecbc87c051b /internal/llm/tools/edit.go
parent9ae6af8856ca6a13d575ec6a8989a5f6ee4297b1 (diff)
downloadopencode-a8d5787e8ef561037f73b669128f46ae1b1e8553.tar.gz
opencode-a8d5787e8ef561037f73b669128f46ae1b1e8553.zip
config validation
Diffstat (limited to 'internal/llm/tools/edit.go')
-rw-r--r--internal/llm/tools/edit.go27
1 files changed, 21 insertions, 6 deletions
diff --git a/internal/llm/tools/edit.go b/internal/llm/tools/edit.go
index b7b813ca7..23c44399b 100644
--- a/internal/llm/tools/edit.go
+++ b/internal/llm/tools/edit.go
@@ -196,11 +196,16 @@ func (e *editTool) createNewFile(ctx context.Context, filePath, content string)
content,
filePath,
)
+ rootDir := config.WorkingDirectory()
+ permissionPath := filepath.Dir(filePath)
+ if strings.HasPrefix(filePath, rootDir) {
+ permissionPath = rootDir
+ }
p := e.permissions.Request(
permission.CreatePermissionRequest{
- Path: filepath.Dir(filePath),
+ Path: permissionPath,
ToolName: EditToolName,
- Action: "create",
+ Action: "write",
Description: fmt.Sprintf("Create file %s", filePath),
Params: EditPermissionsParams{
FilePath: filePath,
@@ -301,11 +306,16 @@ func (e *editTool) deleteContent(ctx context.Context, filePath, oldString string
filePath,
)
+ rootDir := config.WorkingDirectory()
+ permissionPath := filepath.Dir(filePath)
+ if strings.HasPrefix(filePath, rootDir) {
+ permissionPath = rootDir
+ }
p := e.permissions.Request(
permission.CreatePermissionRequest{
- Path: filepath.Dir(filePath),
+ Path: permissionPath,
ToolName: EditToolName,
- Action: "delete",
+ Action: "write",
Description: fmt.Sprintf("Delete content from file %s", filePath),
Params: EditPermissionsParams{
FilePath: filePath,
@@ -415,11 +425,16 @@ func (e *editTool) replaceContent(ctx context.Context, filePath, oldString, newS
newContent,
filePath,
)
+ rootDir := config.WorkingDirectory()
+ permissionPath := filepath.Dir(filePath)
+ if strings.HasPrefix(filePath, rootDir) {
+ permissionPath = rootDir
+ }
p := e.permissions.Request(
permission.CreatePermissionRequest{
- Path: filepath.Dir(filePath),
+ Path: permissionPath,
ToolName: EditToolName,
- Action: "replace",
+ Action: "write",
Description: fmt.Sprintf("Replace content in file %s", filePath),
Params: EditPermissionsParams{
FilePath: filePath,