summaryrefslogtreecommitdiffhomepage
path: root/internal/llm
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-04-21 19:48:36 +0200
committerKujtim Hoxha <[email protected]>2025-04-21 19:53:55 +0200
commit3a6a26981a8074b6ab0eaadb520db986e04799ff (patch)
tree4fe2c022305f13775f2cab3cdd80cd808259765b /internal/llm
parentd7569d79c6da1437fe46343ed13810df6c8cae1f (diff)
downloadopencode-3a6a26981a8074b6ab0eaadb520db986e04799ff.tar.gz
opencode-3a6a26981a8074b6ab0eaadb520db986e04799ff.zip
init command
Diffstat (limited to 'internal/llm')
-rw-r--r--internal/llm/agent/mcp-tools.go5
-rw-r--r--internal/llm/prompt/prompt.go16
-rw-r--r--internal/llm/prompt/title.go1
-rw-r--r--internal/llm/tools/bash.go8
-rw-r--r--internal/llm/tools/edit.go3
-rw-r--r--internal/llm/tools/fetch.go6
-rw-r--r--internal/llm/tools/patch.go3
-rw-r--r--internal/llm/tools/write.go1
8 files changed, 37 insertions, 6 deletions
diff --git a/internal/llm/agent/mcp-tools.go b/internal/llm/agent/mcp-tools.go
index 16dddc1ba..53aada33f 100644
--- a/internal/llm/agent/mcp-tools.go
+++ b/internal/llm/agent/mcp-tools.go
@@ -80,9 +80,14 @@ func runTool(ctx context.Context, c MCPClient, toolName string, input string) (t
}
func (b *mcpTool) Run(ctx context.Context, params tools.ToolCall) (tools.ToolResponse, error) {
+ sessionID, messageID := tools.GetContextValues(ctx)
+ if sessionID == "" || messageID == "" {
+ return tools.ToolResponse{}, fmt.Errorf("session ID and message ID are required for creating a new file")
+ }
permissionDescription := fmt.Sprintf("execute %s with the following parameters: %s", b.Info().Name, params.Input)
p := b.permissions.Request(
permission.CreatePermissionRequest{
+ SessionID: sessionID,
Path: config.WorkingDirectory(),
ToolName: b.Info().Name,
Action: "execute",
diff --git a/internal/llm/prompt/prompt.go b/internal/llm/prompt/prompt.go
index cf4d9a7e7..a6b4c03fb 100644
--- a/internal/llm/prompt/prompt.go
+++ b/internal/llm/prompt/prompt.go
@@ -14,8 +14,13 @@ var contextFiles = []string{
".github/copilot-instructions.md",
".cursorrules",
"CLAUDE.md",
+ "CLAUDE.local.md",
"opencode.md",
+ "opencode.local.md",
"OpenCode.md",
+ "OpenCode.local.md",
+ "OPENCODE.md",
+ "OPENCODE.local.md",
}
func GetAgentPrompt(agentName config.AgentName, provider models.ModelProvider) string {
@@ -31,12 +36,13 @@ func GetAgentPrompt(agentName config.AgentName, provider models.ModelProvider) s
basePrompt = "You are a helpful assistant"
}
- // Add context from project-specific instruction files if they exist
- contextContent := getContextFromFiles()
- if contextContent != "" {
- return fmt.Sprintf("%s\n\n# Project-Specific Context\n%s", basePrompt, contextContent)
+ if agentName == config.AgentCoder || agentName == config.AgentTask {
+ // Add context from project-specific instruction files if they exist
+ contextContent := getContextFromFiles()
+ if contextContent != "" {
+ return fmt.Sprintf("%s\n\n# Project-Specific Context\n%s", basePrompt, contextContent)
+ }
}
-
return basePrompt
}
diff --git a/internal/llm/prompt/title.go b/internal/llm/prompt/title.go
index 6e5289b24..5656360da 100644
--- a/internal/llm/prompt/title.go
+++ b/internal/llm/prompt/title.go
@@ -6,6 +6,7 @@ func TitlePrompt(_ models.ModelProvider) string {
return `you will generate a short title based on the first message a user begins a conversation with
- ensure it is not more than 50 characters long
- the title should be a summary of the user's message
+- it should be one line long
- do not use quotes or colons
- the entire text you return will be used as the title`
}
diff --git a/internal/llm/tools/bash.go b/internal/llm/tools/bash.go
index 18533b761..a17506197 100644
--- a/internal/llm/tools/bash.go
+++ b/internal/llm/tools/bash.go
@@ -51,7 +51,7 @@ var safeReadOnlyCommands = []string{
"git status", "git log", "git diff", "git show", "git branch", "git tag", "git remote", "git ls-files", "git ls-remote",
"git rev-parse", "git config --get", "git config --list", "git describe", "git blame", "git grep", "git shortlog",
- "go version", "go list", "go env", "go doc", "go vet", "go fmt", "go mod", "go test", "go build", "go run", "go install", "go clean",
+ "go version", "go help", "go list", "go env", "go doc", "go vet", "go fmt", "go mod", "go test", "go build", "go run", "go install", "go clean",
}
func bashDescription() string {
@@ -261,9 +261,15 @@ func (b *bashTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
}
}
}
+
+ sessionID, messageID := GetContextValues(ctx)
+ if sessionID == "" || messageID == "" {
+ return ToolResponse{}, fmt.Errorf("session ID and message ID are required for creating a new file")
+ }
if !isSafeReadOnly {
p := b.permissions.Request(
permission.CreatePermissionRequest{
+ SessionID: sessionID,
Path: config.WorkingDirectory(),
ToolName: BashToolName,
Action: "execute",
diff --git a/internal/llm/tools/edit.go b/internal/llm/tools/edit.go
index 23c44399b..e2e257875 100644
--- a/internal/llm/tools/edit.go
+++ b/internal/llm/tools/edit.go
@@ -203,6 +203,7 @@ func (e *editTool) createNewFile(ctx context.Context, filePath, content string)
}
p := e.permissions.Request(
permission.CreatePermissionRequest{
+ SessionID: sessionID,
Path: permissionPath,
ToolName: EditToolName,
Action: "write",
@@ -313,6 +314,7 @@ func (e *editTool) deleteContent(ctx context.Context, filePath, oldString string
}
p := e.permissions.Request(
permission.CreatePermissionRequest{
+ SessionID: sessionID,
Path: permissionPath,
ToolName: EditToolName,
Action: "write",
@@ -432,6 +434,7 @@ func (e *editTool) replaceContent(ctx context.Context, filePath, oldString, newS
}
p := e.permissions.Request(
permission.CreatePermissionRequest{
+ SessionID: sessionID,
Path: permissionPath,
ToolName: EditToolName,
Action: "write",
diff --git a/internal/llm/tools/fetch.go b/internal/llm/tools/fetch.go
index 827755863..47ff03e57 100644
--- a/internal/llm/tools/fetch.go
+++ b/internal/llm/tools/fetch.go
@@ -116,8 +116,14 @@ func (t *fetchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
return NewTextErrorResponse("URL must start with http:// or https://"), nil
}
+ sessionID, messageID := GetContextValues(ctx)
+ if sessionID == "" || messageID == "" {
+ return ToolResponse{}, fmt.Errorf("session ID and message ID are required for creating a new file")
+ }
+
p := t.permissions.Request(
permission.CreatePermissionRequest{
+ SessionID: sessionID,
Path: config.WorkingDirectory(),
ToolName: FetchToolName,
Action: "fetch",
diff --git a/internal/llm/tools/patch.go b/internal/llm/tools/patch.go
index 903404497..7e20e378e 100644
--- a/internal/llm/tools/patch.go
+++ b/internal/llm/tools/patch.go
@@ -194,6 +194,7 @@ func (p *patchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
patchDiff, _, _ := diff.GenerateDiff("", *change.NewContent, path)
p := p.permissions.Request(
permission.CreatePermissionRequest{
+ SessionID: sessionID,
Path: dir,
ToolName: PatchToolName,
Action: "create",
@@ -220,6 +221,7 @@ func (p *patchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
dir := filepath.Dir(path)
p := p.permissions.Request(
permission.CreatePermissionRequest{
+ SessionID: sessionID,
Path: dir,
ToolName: PatchToolName,
Action: "update",
@@ -238,6 +240,7 @@ func (p *patchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
patchDiff, _, _ := diff.GenerateDiff(*change.OldContent, "", path)
p := p.permissions.Request(
permission.CreatePermissionRequest{
+ SessionID: sessionID,
Path: dir,
ToolName: PatchToolName,
Action: "delete",
diff --git a/internal/llm/tools/write.go b/internal/llm/tools/write.go
index 3a94b47b6..ec6fc1dc4 100644
--- a/internal/llm/tools/write.go
+++ b/internal/llm/tools/write.go
@@ -168,6 +168,7 @@ func (w *writeTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
}
p := w.permissions.Request(
permission.CreatePermissionRequest{
+ SessionID: sessionID,
Path: permissionPath,
ToolName: WriteToolName,
Action: "write",