-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
272 lines (231 loc) · 6.83 KB
/
Copy pathoptions.go
File metadata and controls
272 lines (231 loc) · 6.83 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
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
preAnalysis bool
exclude []string
minScore int
projectRules string
graphEnabled bool
auditMode AuditMode
auditTargets []AuditTarget
}
// 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
})
// AuditMode represents the audit mode for code review.
type AuditMode int
const (
// AuditModeNone disables security audit.
AuditModeNone AuditMode = iota
// AuditModeHooks audits hooks only.
AuditModeHooks
// AuditModeMCP audits MCP servers only.
AuditModeMCP
// AuditModeFull performs comprehensive audit.
AuditModeFull
)
// AuditTargetType represents a type of audit target.
type AuditTargetType int
const (
AuditTargetHooks AuditTargetType = iota
AuditTargetMCP
AuditTargetPermissions
AuditTargetSecrets
)
// AuditTarget represents a target to audit in the codebase.
type AuditTarget struct {
Type AuditTargetType
Path string
Recurse bool
}
// AuditOption configures security audit options.
type AuditOption struct {
Mode AuditMode
Targets []AuditTarget
}
// Configuration functions
func WithProvider(p Provider) Option {
return optFunc(func(c *config) { c.provider = p })
}
// WithAuditTargets specifies audit targets for security auditing.
func WithAuditTargets(targets ...AuditTarget) Option {
return optFunc(func(c *config) { c.auditTargets = targets })
}
// WithAuditMode sets the audit mode.
func WithAuditMode(mode AuditMode) Option {
return optFunc(func(c *config) { c.auditMode = mode })
}
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 })
}
// WithPreAnalysis enables or disables static analysis and taint analysis
// as a pre-pass before the LLM review. When enabled, pattern-based static rules
// and data-flow taint analysis are run on the diff, and their findings are
// included in the review results alongside LLM findings.
func WithPreAnalysis(enabled bool) Option {
return optFunc(func(c *config) { c.preAnalysis = 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 })
}
// WithGraph enables structural dependency graph for blast-radius analysis.
func WithGraph(enabled bool) Option {
return optFunc(func(c *config) { c.graphEnabled = enabled })
}
// ParseAuditMode converts a string audit mode to AuditMode.
func ParseAuditMode(s string) AuditMode {
switch s {
case "full":
return AuditModeFull
case "mcp":
return AuditModeMCP
case "hooks":
return AuditModeHooks
default:
return AuditModeNone
}
}