on main help sign in
fix duplicate context
bce2ec5Kujtim Hoxha
internal/llm/prompt/prompt.go+33−6
@@ -9,6 +9,7 @@ import (
9
9
10 "github.com/opencode-ai/opencode/internal/config"
10 "github.com/opencode-ai/opencode/internal/config"
11 "github.com/opencode-ai/opencode/internal/llm/models"
11 "github.com/opencode-ai/opencode/internal/llm/models"
12+ "github.com/opencode-ai/opencode/internal/logging"
12)
13)
13
14
14func GetAgentPrompt(agentName config.AgentName, provider models.ModelProvider) string {
15func GetAgentPrompt(agentName config.AgentName, provider models.ModelProvider) string {
@@ -27,6 +28,7 @@ func GetAgentPrompt(agentName config.AgentName, provider models.ModelProvider) s
27 if agentName == config.AgentCoder || agentName == config.AgentTask {
28 if agentName == config.AgentCoder || agentName == config.AgentTask {
28 // Add context from project-specific instruction files if they exist
29 // Add context from project-specific instruction files if they exist
29 contextContent := getContextFromPaths()
30 contextContent := getContextFromPaths()
31+ logging.Debug("Context content", "Context", contextContent)
30 if contextContent != "" {
32 if contextContent != "" {
31 return fmt.Sprintf("%s\n\n# Project-Specific Context\n Make sure to follow the instructions in the context below\n%s", basePrompt, contextContent)
33 return fmt.Sprintf("%s\n\n# Project-Specific Context\n Make sure to follow the instructions in the context below\n%s", basePrompt, contextContent)
32 }
34 }
@@ -59,6 +61,10 @@ func processContextPaths(workDir string, paths []string) string {
59 resultCh = make(chan string)
61 resultCh = make(chan string)
60 )
62 )
61
63
64+ // Track processed files to avoid duplicates
65+ processedFiles := make(map[string]bool)
66+ var processedMutex sync.Mutex
67+
62 for _, path := range paths {
68 for _, path := range paths {
63 wg.Add(1)
69 wg.Add(1)
64 go func(p string) {
70 go func(p string) {
@@ -70,16 +76,38 @@ func processContextPaths(workDir string, paths []string) string {
70 return err
76 return err
71 }
77 }
72 if !d.IsDir() {
78 if !d.IsDir() {
79+ // Check if we've already processed this file (case-insensitive)
80+ processedMutex.Lock()
81+ lowerPath := strings.ToLower(path)
82+ if !processedFiles[lowerPath] {
83+ processedFiles[lowerPath] = true
84+ processedMutex.Unlock()
85+
73− if result := processFile(path); result != "" {
86+ if result := processFile(path); result != "" {
74− resultCh <- result
87+ resultCh <- result
88+ }
89+ } else {
90+ processedMutex.Unlock()
75 }
91 }
76 }
92 }
77 return nil
93 return nil
78 })
94 })
79 } else {
95 } else {
80− result := processFile(filepath.Join(workDir, p))
96+ fullPath := filepath.Join(workDir, p)
97+
98+ // Check if we've already processed this file (case-insensitive)
99+ processedMutex.Lock()
100+ lowerPath := strings.ToLower(fullPath)
101+ if !processedFiles[lowerPath] {
102+ processedFiles[lowerPath] = true
103+ processedMutex.Unlock()
104+
105+ result := processFile(fullPath)
81− if result != "" {
106+ if result != "" {
82− resultCh <- result
107+ resultCh <- result
108+ }
109+ } else {
110+ processedMutex.Unlock()
83 }
111 }
84 }
112 }
85 }(path)
113 }(path)
@@ -105,4 +133,3 @@ func processFile(filePath string) string {
105 }
133 }
106 return "# From:" + filePath + "\n" + string(content)
134 return "# From:" + filePath + "\n" + string(content)
107}
135}
108−