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