-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
99 lines (85 loc) · 2.62 KB
/
Copy pathmain.go
File metadata and controls
99 lines (85 loc) · 2.62 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
package main
import (
"flag"
"fmt"
"math"
"os"
"path/filepath"
tea "github.com/charmbracelet/bubbletea"
)
func main() {
// CLI flags
ralphDir := flag.String("ralph-dir", "", "Path to ralph directory containing prd.json and prompt.md (default: ./scripts/ralph)")
prdFile := flag.String("prd", "", "Path to prd.json (overrides --ralph-dir)")
promptFile := flag.String("prompt", "", "Path to prompt.md (overrides --ralph-dir)")
flag.Parse()
// Get current working directory (project root)
cwd, err := os.Getwd()
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting current directory: %v\n", err)
os.Exit(1)
}
// Determine paths
var prdPath, promptPath string
if *prdFile != "" && *promptFile != "" {
// Explicit file paths provided
prdPath = *prdFile
promptPath = *promptFile
if !filepath.IsAbs(prdPath) {
prdPath = filepath.Join(cwd, prdPath)
}
if !filepath.IsAbs(promptPath) {
promptPath = filepath.Join(cwd, promptPath)
}
} else if *ralphDir != "" {
// Custom ralph directory
dir := *ralphDir
if !filepath.IsAbs(dir) {
dir = filepath.Join(cwd, dir)
}
prdPath = filepath.Join(dir, "prd.json")
promptPath = filepath.Join(dir, "prompt.md")
} else {
// Default: scripts/ralph in current directory
prdPath = filepath.Join(cwd, "scripts", "ralph", "prd.json")
promptPath = filepath.Join(cwd, "scripts", "ralph", "prompt.md")
}
projectRoot := cwd
// Validate prd.json exists
if _, err := os.Stat(prdPath); os.IsNotExist(err) {
fmt.Fprintf(os.Stderr, "Error: prd.json not found at %s\n", prdPath)
fmt.Fprintf(os.Stderr, "\nUsage:\n")
fmt.Fprintf(os.Stderr, " ralphy # Uses ./scripts/ralph/\n")
fmt.Fprintf(os.Stderr, " ralphy --ralph-dir ./custom/path # Custom ralph directory\n")
fmt.Fprintf(os.Stderr, " ralphy --prd ./prd.json --prompt ./prompt.md\n")
os.Exit(1)
}
// Validate prompt.md exists
if _, err := os.Stat(promptPath); os.IsNotExist(err) {
fmt.Fprintf(os.Stderr, "Error: prompt.md not found at %s\n", promptPath)
os.Exit(1)
}
// Load PRD
prd, err := LoadPRD(prdPath)
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading prd.json: %v\n", err)
os.Exit(1)
}
// Calculate max iterations
pendingCount := CountPending(prd.UserStories)
maxIterations := int(math.Ceil(float64(pendingCount) * 1.3))
if maxIterations < 1 {
maxIterations = 1
}
// Create model and run
model := NewModel(prdPath, promptPath, projectRoot, maxIterations)
p := tea.NewProgram(
model,
tea.WithAltScreen(),
tea.WithMouseCellMotion(),
)
if _, err := p.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error running program: %v\n", err)
os.Exit(1)
}
}