(opts scanOptions)
| 102 | } |
| 103 | |
| 104 | func 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 | } |
no test coverage detected