-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
253 lines (225 loc) Β· 7.68 KB
/
main.go
File metadata and controls
253 lines (225 loc) Β· 7.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/drpaneas/codesearch/internal/config"
"github.com/drpaneas/codesearch/pkg/analysis"
"github.com/drpaneas/codesearch/pkg/errors"
)
func main() {
// Parse command line arguments first to determine verbosity
mode, query, projectPath, analysisConfig := parseArgs()
// Show header based on verbosity level
if analysisConfig.VerbosityLevel >= config.VerbosityNormal {
fmt.Println("π― CODESEARCH - Advanced Code Analysis Tool")
fmt.Println("==========================================")
}
// Check for API key
apiKey := os.Getenv("ANTHROPIC_API_KEY")
if apiKey == "" {
if analysisConfig.VerbosityLevel >= config.VerbosityNormal {
fmt.Println("β οΈ No ANTHROPIC_API_KEY found. Running in offline mode (limited functionality).")
fmt.Println(" Set your API key: export ANTHROPIC_API_KEY='your-key-here'")
}
} else {
if analysisConfig.VerbosityLevel >= config.VerbosityNormal {
fmt.Printf("β
Claude API configured (key: %s...%s)\n", apiKey[:8], apiKey[len(apiKey)-4:])
}
}
switch mode {
case "interactive":
runInteractiveMode(apiKey, projectPath, analysisConfig)
case "query":
runSingleQuery(apiKey, query, projectPath, analysisConfig)
case "help":
showHelp()
default:
showHelp()
}
}
func parseArgs() (string, string, string, *config.AnalysisConfig) {
if len(os.Args) < 2 {
return "help", "", ".", &config.AnalysisConfig{
VerbosityLevel: config.VerbosityNormal,
ShowPrompts: false,
ConfidenceThreshold: config.DefaultConfidenceThreshold,
MaxFilesToAnalyze: config.MaxFilesToAnalyze,
MaxLinesPerFile: config.MaxLinesPerFile,
}
}
// Default values
projectPath := "."
var query string
mode := "interactive" // Default to interactive mode
// Default analysis configuration
analysisConfig := &config.AnalysisConfig{
VerbosityLevel: config.VerbosityNormal,
ShowPrompts: false,
ConfidenceThreshold: config.DefaultConfidenceThreshold,
MaxFilesToAnalyze: config.MaxFilesToAnalyze,
MaxLinesPerFile: config.MaxLinesPerFile,
}
// Parse arguments
for i, arg := range os.Args[1:] {
switch arg {
case "--ask", "-q":
mode = "query"
if i+2 < len(os.Args) {
query = os.Args[i+2]
}
case "--path", "-p":
if i+2 < len(os.Args) {
projectPath = os.Args[i+2]
}
case "--interactive", "-i":
mode = "interactive"
case "--show-prompts", "--debug-prompts":
analysisConfig.ShowPrompts = true
if analysisConfig.VerbosityLevel >= config.VerbosityNormal {
fmt.Println("π Debug mode: Will show detailed prompt information")
}
case "--quiet", "-quiet":
analysisConfig.VerbosityLevel = config.VerbosityQuiet
case "--verbose", "-verbose":
analysisConfig.VerbosityLevel = config.VerbosityVerbose
case "--simple":
complexity := config.ComplexitySimple
analysisConfig.ForceComplexity = &complexity
case "--complex":
complexity := config.ComplexityComplex
analysisConfig.ForceComplexity = &complexity
case "--help", "-h":
mode = "help"
default:
// If it's not a flag and no query is set, treat it as project path
if !strings.HasPrefix(arg, "-") && query == "" && mode == "interactive" {
projectPath = arg
}
}
}
return mode, query, projectPath, analysisConfig
}
func runSingleQuery(apiKey, query, projectPath string, analysisConfig *config.AnalysisConfig) {
if strings.TrimSpace(query) == "" {
err := errors.NewValidationError(errors.ErrCodeEmptyQuery, "--ask parameter is required for query mode")
fmt.Printf("β Error: %v\n", err)
os.Exit(1)
}
if analysisConfig.VerbosityLevel >= config.VerbosityNormal {
fmt.Printf("\nπ― Single Query Mode: %s\n", query)
fmt.Printf("π Project: %s\n", filepath.Clean(projectPath))
}
// Create analyzer with configuration
analyzer := analysis.NewCursorStyleAnalyzerWithConfig(apiKey, analysisConfig)
// Run analysis
result, err := analyzer.Ask(query, projectPath)
if err != nil {
if analysisConfig.VerbosityLevel >= config.VerbosityQuiet {
fmt.Printf("β Analysis failed: %v\n", err)
}
os.Exit(1)
}
// Output results based on verbosity level
switch analysisConfig.VerbosityLevel {
case config.VerbosityQuiet:
fmt.Println(result)
case config.VerbosityNormal:
fmt.Println("\n" + strings.Repeat("=", 80))
fmt.Println("π ANALYSIS RESULT:")
fmt.Println(strings.Repeat("=", 80))
fmt.Println(result)
case config.VerbosityVerbose:
fmt.Println("\n" + strings.Repeat("=", 80))
fmt.Println("π COMPREHENSIVE ANALYSIS:")
fmt.Println(strings.Repeat("=", 80))
fmt.Println(result)
}
}
func runInteractiveMode(apiKey, projectPath string, analysisConfig *config.AnalysisConfig) {
if analysisConfig.VerbosityLevel >= config.VerbosityNormal {
fmt.Println("\nπ Starting Interactive Analysis Mode...")
fmt.Printf("π Project: %s\n", filepath.Clean(projectPath))
fmt.Println("\n㪠Interactive Mode (type 'exit' to quit, 'help' for commands)")
fmt.Println("Ask comprehensive questions about your codebase:")
}
// Create analyzer with configuration
analyzer := analysis.NewCursorStyleAnalyzerWithConfig(apiKey, analysisConfig)
// Simple interactive loop - just ask questions and get comprehensive answers
for {
fmt.Print("\nβ Query: ")
var query string
if _, err := fmt.Scanln(&query); err != nil {
// Handle input error gracefully - continue with empty query
query = ""
}
if query == "" {
continue
}
if query == "exit" || query == "quit" {
if analysisConfig.VerbosityLevel >= config.VerbosityNormal {
fmt.Println("π Goodbye!")
}
break
}
if query == "help" {
showInteractiveHelp()
continue
}
// Process the query
if analysisConfig.VerbosityLevel >= config.VerbosityNormal {
fmt.Println("π€ Analyzing...")
}
result, err := analyzer.Ask(query, projectPath)
if err != nil {
fmt.Printf("β Error: %v\n", err)
continue
}
// Display result based on verbosity level
switch analysisConfig.VerbosityLevel {
case config.VerbosityQuiet:
fmt.Println(result)
default:
fmt.Println("\n" + strings.Repeat("β", 80))
fmt.Println("π ANALYSIS RESULT:")
fmt.Println(strings.Repeat("β", 80))
fmt.Println(result)
fmt.Println(strings.Repeat("β", 80))
}
}
}
func showHelp() {
fmt.Println("\nπ CODESEARCH - Advanced Code Analysis Tool")
fmt.Println("==========================================")
fmt.Println()
fmt.Println("OPTIONS:")
fmt.Println(" --quiet Minimal output (results only)")
fmt.Println(" --verbose Detailed progress information")
fmt.Println(" --simple Force simple analysis (faster)")
fmt.Println(" --complex Force deep multi-pass analysis")
fmt.Println(" --show-prompts Show detailed prompt information")
fmt.Println(" --path PATH Specify project path")
fmt.Println()
fmt.Println("EXAMPLES:")
fmt.Println(" go run main.go --ask \"Is this 2D or 3D?\"")
fmt.Println(" go run main.go --ask \"How does auth work?\" --quiet")
fmt.Println(" go run main.go --ask \"Analyze architecture\" --verbose")
fmt.Println(" go run main.go --ask \"Find bugs\" --simple --path /project")
fmt.Println()
fmt.Println("ENVIRONMENT:")
fmt.Println(" export ANTHROPIC_API_KEY='your-key-here'")
fmt.Println(" Get your key: https://console.anthropic.com/")
}
func showInteractiveHelp() {
fmt.Println("\nπ Interactive Commands:")
fmt.Println(" help - Show this help")
fmt.Println(" exit - Exit the program")
fmt.Println()
fmt.Println("π‘ Example queries:")
fmt.Println(" β’ How does authentication work?")
fmt.Println(" β’ Explain the registration service")
fmt.Println(" β’ What are the main components?")
fmt.Println(" β’ Show me error handling patterns")
fmt.Println(" β’ Analyze the architecture")
}