MCPcopy Create free account
hub / github.com/alibaba/open-code-review / executeScan

Function executeScan

cmd/opencodereview/scan_cmd.go:104–225  ·  view source on GitHub ↗
(opts scanOptions)

Source from the content-addressed store, hash-verified

102}
103
104func executeScan(opts scanOptions) error {
105 cc, err := loadCommonContext(opts.repoDir, opts.rulePath, opts.maxTools, opts.maxGitProcs, false)
106 if err != nil {
107 return err
108 }
109 applyCLIExcludes(cc, splitPaths(opts.excludes))
110
111 // scan owns its own template (scan_template.json) independent from the
112 // diff-review template loaded by loadCommonContext above. Apply --max-tools
113 // as an "only raise" override to the scan template's per-file budget.
114 scanTpl, err := template.LoadScanDefault()
115 if err != nil {
116 return fmt.Errorf("load scan template: %w", err)
117 }
118 if err := scanTpl.Validate(); err != nil {
119 return fmt.Errorf("invalid scan template: %w", err)
120 }
121 if opts.maxTools > scanTpl.MaxToolRequestTimes {
122 scanTpl.MaxToolRequestTimes = opts.maxTools
123 }
124 if opts.batch != "" {
125 // CLI override of BATCH_STRATEGY; validated downstream by parseBatchStrategy
126 // (unknown values silently fall back to "none").
127 scanTpl.BatchStrategy = opts.batch
128 }
129 // Token budget: --max-tokens-budget overrides the template value when set.
130 budget := scanTpl.MaxTokensBudget
131 if opts.maxTokensBudget > 0 {
132 budget = int64(opts.maxTokensBudget)
133 }
134
135 scanPaths := splitPaths(opts.paths)
136
137 if opts.preview {
138 return runScanPreview(cc, scanTpl, scanPaths)
139 }
140
141 resumeState, err := loadScanResumeState(cc.RepoDir, opts, scanPaths)
142 if err != nil {
143 return err
144 }
145
146 rt, err := loadLLMRuntime(cc.Template, opts.toolConfigPath, llm.ResolveOptions{
147 Provider: opts.provider,
148 Model: opts.model,
149 })
150 if err != nil {
151 return err
152 }
153 llmIdentity := &jsonLLMIdentity{
154 Provider: rt.Provider,
155 Model: rt.Model,
156 }
157 // Apply language to the scan template too (loadLLMRuntime only mutates
158 // the diff-review template it was handed).
159 if rt.AppCfg != nil {
160 scanTpl.ApplyLanguage(rt.AppCfg.Language)
161 }

Callers 1

scan_cmd.goFile · 0.85

Calls 15

RunMethod · 0.95
SessionIDMethod · 0.95
LoadScanDefaultFunction · 0.92
NewAgentFunction · 0.92
NewCommentWorkerPoolFunction · 0.92
StartSpanFunction · 0.92
IsEnabledFunction · 0.92
TraceIDFromContextFunction · 0.92
loadCommonContextFunction · 0.85
applyCLIExcludesFunction · 0.85
splitPathsFunction · 0.85

Tested by

no test coverage detected