-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
194 lines (164 loc) · 4.82 KB
/
options.go
File metadata and controls
194 lines (164 loc) · 4.82 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
package sight
import (
"github.com/GrayCodeAI/sight/internal/comment"
"github.com/GrayCodeAI/sight/internal/review"
)
// FilterMode re-exports the comment package's FilterMode for public use.
// It controls which lines are eligible for inline comment placement.
type FilterMode = comment.FilterMode
// Filter mode constants re-exported for public use.
const (
FilterAdded = comment.FilterAdded
FilterDiffContext = comment.FilterDiffContext
FilterFile = comment.FilterFile
FilterNone = comment.FilterNone
)
// Option configures a review operation.
type Option interface {
apply(*config)
}
type optFunc func(*config)
func (f optFunc) apply(c *config) { f(c) }
type config struct {
provider Provider
model string
concerns []string
customConcerns []review.Concern
maxTokens int
contextLines int
failOn Severity
filterMode comment.FilterMode
gitContext bool
symbols bool
parallel bool
reflection bool
exclude []string
minScore int
projectRules string
}
// defaultExclude is the default set of file patterns excluded from review.
// These are generated files, lock files, and minified assets that produce
// noise and waste tokens.
var defaultExclude = []string{
"go.sum",
"package-lock.json",
"yarn.lock",
"pnpm-lock.yaml",
"*.min.js",
"*.min.css",
"*.map",
"*.generated.*",
}
func defaultConfig() *config {
return &config{
concerns: []string{"security", "bugs", "performance", "correctness", "style"},
maxTokens: 4096,
contextLines: 10,
failOn: SeverityCritical,
gitContext: true,
symbols: true,
parallel: true,
exclude: defaultExclude,
minScore: 3,
}
}
func buildConfig(opts []Option) *config {
cfg := defaultConfig()
for _, o := range opts {
o.apply(cfg)
}
return cfg
}
// Presets
// Quick performs a fast single-pass review focusing on bugs and security only.
var Quick Option = optFunc(func(c *config) {
c.concerns = []string{"security", "bugs"}
c.contextLines = 5
c.parallel = false
c.gitContext = false
})
// Thorough performs a comprehensive multi-concern parallel review.
var Thorough Option = optFunc(func(c *config) {
c.concerns = []string{"security", "bugs", "performance", "correctness", "style"}
c.contextLines = 15
c.parallel = true
c.gitContext = true
c.symbols = true
})
// SecurityFocus limits review to security concerns with deeper analysis.
var SecurityFocus Option = optFunc(func(c *config) {
c.concerns = []string{"security"}
c.contextLines = 20
c.maxTokens = 8192
c.gitContext = true
})
// CI configures for continuous integration: thorough, fail on high.
var CI Option = optFunc(func(c *config) {
c.concerns = []string{"security", "bugs", "performance", "correctness"}
c.contextLines = 10
c.parallel = true
c.failOn = SeverityHigh
})
// Configuration functions
func WithProvider(p Provider) Option {
return optFunc(func(c *config) { c.provider = p })
}
func WithModel(model string) Option {
return optFunc(func(c *config) { c.model = model })
}
func WithConcerns(concerns ...string) Option {
return optFunc(func(c *config) { c.concerns = concerns })
}
func WithMaxTokens(n int) Option {
return optFunc(func(c *config) {
if n > 0 {
c.maxTokens = n
}
})
}
func WithContextLines(n int) Option {
return optFunc(func(c *config) {
if n >= 0 {
c.contextLines = n
}
})
}
func WithFailOn(sev Severity) Option {
return optFunc(func(c *config) { c.failOn = sev })
}
func WithGitContext(enabled bool) Option {
return optFunc(func(c *config) { c.gitContext = enabled })
}
func WithSymbols(enabled bool) Option {
return optFunc(func(c *config) { c.symbols = enabled })
}
func WithParallel(enabled bool) Option {
return optFunc(func(c *config) { c.parallel = enabled })
}
func WithReflection(enabled bool) Option {
return optFunc(func(c *config) { c.reflection = enabled })
}
// WithExclude sets file path patterns to exclude from review.
// Patterns support exact basenames ("go.sum") and glob wildcards ("*.min.js", "*.generated.*").
func WithExclude(patterns ...string) Option {
return optFunc(func(c *config) { c.exclude = patterns })
}
// WithMinScore sets the minimum reflection score threshold (1-10).
// Findings scoring below this are filtered out during the reflection pass.
func WithMinScore(n int) Option {
return optFunc(func(c *config) {
if n >= 1 && n <= 10 {
c.minScore = n
}
})
}
// WithProjectRules injects project-specific rules into the LLM system prompt.
func WithProjectRules(rules string) Option {
return optFunc(func(c *config) { c.projectRules = rules })
}
// WithFilterMode sets the diff filter mode that controls which findings
// are included as inline comments. See FilterAdded, FilterDiffContext,
// FilterFile, and FilterNone.
func WithFilterMode(mode FilterMode) Option {
return optFunc(func(c *config) { c.filterMode = mode })
}