Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
111 lines (88 loc) · 2.21 KB
/
Copy pathmain.go
File metadata and controls
111 lines (88 loc) · 2.21 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
package main
import (
"bufio"
"context"
"flag"
"fmt"
"log"
"os"
"strings"
"github.com/Aneeshie/zerrcode/internal/agent"
"github.com/Aneeshie/zerrcode/internal/client"
"github.com/Aneeshie/zerrcode/internal/permissions"
"github.com/Aneeshie/zerrcode/internal/tools"
"github.com/Aneeshie/zerrcode/internal/tui"
"github.com/joho/godotenv"
)
func main() {
useTUI := flag.Bool("tui", false, "Start with interactive Bubble Tea TUI")
flag.Parse()
if err := godotenv.Load(); err != nil {
log.Printf("Warning: .env file not loaded: %v", err)
}
apiKey := os.Getenv("OPENROUTER_API_KEY")
if apiKey == "" {
log.Fatal("OPENROUTER_API_KEY is not set")
}
var clnt client.LLMClient = client.NewOpenRouterClient(apiKey)
registry := tools.NewRegistry()
registry.Register(tools.NewReadFileTool("."))
registry.Register(tools.NewListFilesTool("."))
registry.Register(tools.NewWriteFileTool("."))
registry.Register(tools.NewDeleteFileTool("."))
registry.Register(tools.NewSearchCodeTool("."))
registry.Register(tools.NewEditFileTool("."))
registry.Register(tools.NewGitDiffTool("."))
codingAgent := agent.NewAgent(clnt, registry)
history := []client.Message{
{
Role: client.RoleSystem,
Content: agent.SystemPrompt,
},
}
if *useTUI {
if err := tui.Run(codingAgent, history); err != nil {
log.Fatalf("TUI error: %v", err)
}
return
}
// For standard REPL, allow all changes without interactive TUI prompts
codingAgent.SetApprover(permissions.AllowAll{})
ctx := context.Background()
scanner := bufio.NewScanner(os.Stdin)
fmt.Println("zerrcode — type 'exit' to quit.")
for {
fmt.Print("\nzerrcode > ")
if !scanner.Scan() {
break
}
input := strings.TrimSpace(scanner.Text())
if input == "exit" {
fmt.Println("Goodbye!")
break
}
if input == "" {
continue
}
history = append(history, client.Message{
Role: client.RoleUser,
Content: input,
})
updatedHistory, err := codingAgent.Run(
ctx,
history,
func(chunk string) {
fmt.Print(chunk)
},
)
if err != nil {
fmt.Printf("\nRequest failed: %v\n", err)
continue
}
history = updatedHistory
fmt.Println()
}
if err := scanner.Err(); err != nil {
log.Printf("Input error: %v", err)
}
}