@@ -5,6 +5,9 @@ import (
5 "path/filepath"
5 "path/filepath"
9+ "github.com/charmbracelet/crush/internal/config"
10+ "github.com/charmbracelet/crush/internal/env"
10type PromptID string
13type PromptID string
@@ -21,7 +24,7 @@ func GetPrompt(promptID PromptID, provider string, contextPaths ...string) strin
21 basePrompt := ""
24 basePrompt := ""
22 switch promptID {
25 switch promptID {
23 case PromptCoder:
26 case PromptCoder:
24− basePrompt = CoderPrompt(provider)
27+ basePrompt = CoderPrompt(provider, contextPaths...)
25 case PromptTitle:
28 case PromptTitle:
26 basePrompt = TitlePrompt()
29 basePrompt = TitlePrompt()
27 case PromptTask:
30 case PromptTask:
@@ -38,6 +41,32 @@ func getContextFromPaths(workingDir string, contextPaths []string) string {
38 return processContextPaths(workingDir, contextPaths)
41 return processContextPaths(workingDir, contextPaths)
44+// expandPath expands ~ and environment variables in file paths
45+func expandPath(path string) string {
46+ // Handle tilde expansion
47+ if strings.HasPrefix(path, "~/") {
48+ homeDir, err := os.UserHomeDir()
50+ path = filepath.Join(homeDir, path[2:])
52+ } else if path == "~" {
53+ homeDir, err := os.UserHomeDir()
59+ // Handle environment variable expansion using the same pattern as config
60+ if strings.HasPrefix(path, "$") {
61+ resolver := config.NewEnvironmentVariableResolver(env.New())
62+ if expanded, err := resolver.ResolveValue(path); err == nil {
41func processContextPaths(workDir string, paths []string) string {
70func processContextPaths(workDir string, paths []string) string {
43 wg sync.WaitGroup
72 wg sync.WaitGroup
@@ -53,8 +82,23 @@ func processContextPaths(workDir string, paths []string) string {
53 go func(p string) {
82 go func(p string) {
54 defer wg.Done()
83 defer wg.Done()
56− if strings.HasSuffix(p, "/") {
85+ // Expand ~ and environment variables before processing
88+ // Use absolute path if provided, otherwise join with workDir
90+ if !filepath.IsAbs(p) {
91+ fullPath = filepath.Join(workDir, p)
94+ // Check if the path is a directory using os.Stat
95+ info, err := os.Stat(fullPath)
97+ return // Skip if path doesn't exist or can't be accessed
57− filepath.WalkDir(filepath.Join(workDir, p), func(path string, d os.DirEntry, err error) error {
101+ filepath.WalkDir(fullPath, func(path string, d os.DirEntry, err error) error {
58 if err != nil {
102 if err != nil {
59 return err
103 return err
@@ -78,8 +122,7 @@ func processContextPaths(workDir string, paths []string) string {
78 return nil
122 return nil
81− fullPath := filepath.Join(workDir, p)
125+ // It's a file, process it directly
83 // Check if we've already processed this file (case-insensitive)
126 // Check if we've already processed this file (case-insensitive)
84 lowerPath := strings.ToLower(fullPath)
127 lowerPath := strings.ToLower(fullPath)