summaryrefslogtreecommitdiffhomepage
path: root/internal/llm/tools
diff options
context:
space:
mode:
authorJay V <[email protected]>2025-05-21 15:01:25 -0400
committerJay V <[email protected]>2025-05-21 15:01:25 -0400
commit9049295cc961b250be6144585dde322e778534d7 (patch)
treec8a2f09ed6cea54eb9587243eb7dbe298fef1b20 /internal/llm/tools
parent4526b14b17dc49f3ef4f3b1a1d02eff5c6b6b59f (diff)
parentdff8e77eb6d1709fa1ddeb52d0d9c19afd13d385 (diff)
downloadopencode-9049295cc961b250be6144585dde322e778534d7.tar.gz
opencode-9049295cc961b250be6144585dde322e778534d7.zip
Merge branch 'dev' into docs
Diffstat (limited to 'internal/llm/tools')
-rw-r--r--internal/llm/tools/edit.go21
-rw-r--r--internal/llm/tools/shell/shell.go24
-rw-r--r--internal/llm/tools/write.go8
3 files changed, 24 insertions, 29 deletions
diff --git a/internal/llm/tools/edit.go b/internal/llm/tools/edit.go
index 5516db5d7..9837c018d 100644
--- a/internal/llm/tools/edit.go
+++ b/internal/llm/tools/edit.go
@@ -196,16 +196,11 @@ 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(
ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
- Path: permissionPath,
+ Path: filePath,
ToolName: EditToolName,
Action: "write",
Description: fmt.Sprintf("Create file %s", filePath),
@@ -308,16 +303,11 @@ 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(
ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
- Path: permissionPath,
+ Path: filePath,
ToolName: EditToolName,
Action: "write",
Description: fmt.Sprintf("Delete content from file %s", filePath),
@@ -429,16 +419,11 @@ 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(
ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
- Path: permissionPath,
+ Path: filePath,
ToolName: EditToolName,
Action: "write",
Description: fmt.Sprintf("Replace content in file %s", filePath),
diff --git a/internal/llm/tools/shell/shell.go b/internal/llm/tools/shell/shell.go
index efbd5ddb6..a59ee4207 100644
--- a/internal/llm/tools/shell/shell.go
+++ b/internal/llm/tools/shell/shell.go
@@ -12,6 +12,7 @@ import (
"syscall"
"time"
+ "github.com/sst/opencode/internal/config"
"github.com/sst/opencode/internal/status"
)
@@ -59,12 +60,27 @@ func GetPersistentShell(workingDir string) *PersistentShell {
}
func newPersistentShell(cwd string) *PersistentShell {
- shellPath := os.Getenv("SHELL")
- if shellPath == "" {
- shellPath = "/bin/bash"
+ cfg := config.Get()
+
+ // Use shell from config if specified
+ shellPath := ""
+ shellArgs := []string{"-l"}
+
+ if cfg != nil && cfg.Shell.Path != "" {
+ shellPath = cfg.Shell.Path
+ if len(cfg.Shell.Args) > 0 {
+ shellArgs = cfg.Shell.Args
+ }
+ } else {
+ // Fall back to environment variable
+ shellPath = os.Getenv("SHELL")
+ if shellPath == "" {
+ // Default to bash if neither config nor environment variable is set
+ shellPath = "/bin/bash"
+ }
}
- cmd := exec.Command(shellPath, "-l")
+ cmd := exec.Command(shellPath, shellArgs...)
cmd.Dir = cwd
stdinPipe, err := cmd.StdinPipe()
diff --git a/internal/llm/tools/write.go b/internal/llm/tools/write.go
index f99b3b789..caefc556f 100644
--- a/internal/llm/tools/write.go
+++ b/internal/llm/tools/write.go
@@ -6,7 +6,6 @@ import (
"fmt"
"os"
"path/filepath"
- "strings"
"time"
"github.com/sst/opencode/internal/config"
@@ -161,16 +160,11 @@ func (w *writeTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
filePath,
)
- rootDir := config.WorkingDirectory()
- permissionPath := filepath.Dir(filePath)
- if strings.HasPrefix(filePath, rootDir) {
- permissionPath = rootDir
- }
p := w.permissions.Request(
ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
- Path: permissionPath,
+ Path: filePath,
ToolName: WriteToolName,
Action: "write",
Description: fmt.Sprintf("Create file %s", filePath),