99
1010 "github.com/opencode-ai/opencode/internal/config"
1111 "github.com/opencode-ai/opencode/internal/llm/models"
12+ "github.com/opencode-ai/opencode/internal/logging"
1213)
1314
1415func GetAgentPrompt (agentName config.AgentName , provider models.ModelProvider ) string {
@@ -27,6 +28,7 @@ func GetAgentPrompt(agentName config.AgentName, provider models.ModelProvider) s
2728 if agentName == config .AgentCoder || agentName == config .AgentTask {
2829 // Add context from project-specific instruction files if they exist
2930 contextContent := getContextFromPaths ()
31+ logging .Debug ("Context content" , "Context" , contextContent )
3032 if contextContent != "" {
3133 return fmt .Sprintf ("%s\n \n # Project-Specific Context\n Make sure to follow the instructions in the context below\n %s" , basePrompt , contextContent )
3234 }
@@ -59,6 +61,10 @@ func processContextPaths(workDir string, paths []string) string {
5961 resultCh = make (chan string )
6062 )
6163
64+ // Track processed files to avoid duplicates
65+ processedFiles := make (map [string ]bool )
66+ var processedMutex sync.Mutex
67+
6268 for _ , path := range paths {
6369 wg .Add (1 )
6470 go func (p string ) {
@@ -70,16 +76,38 @@ func processContextPaths(workDir string, paths []string) string {
7076 return err
7177 }
7278 if ! d .IsDir () {
73- if result := processFile (path ); result != "" {
74- resultCh <- result
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+
86+ if result := processFile (path ); result != "" {
87+ resultCh <- result
88+ }
89+ } else {
90+ processedMutex .Unlock ()
7591 }
7692 }
7793 return nil
7894 })
7995 } else {
80- result := processFile (filepath .Join (workDir , p ))
81- if result != "" {
82- resultCh <- result
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 )
106+ if result != "" {
107+ resultCh <- result
108+ }
109+ } else {
110+ processedMutex .Unlock ()
83111 }
84112 }
85113 }(path )
@@ -105,4 +133,3 @@ func processFile(filePath string) string {
105133 }
106134 return "# From:" + filePath + "\n " + string (content )
107135}
108-
0 commit comments