(ctx context.Context, opts scanOptions)
| 112 | } |
| 113 | |
| 114 | func executeScanContext(ctx context.Context, opts scanOptions) (retErr error) { |
| 115 | out, closeOut, err := resolveOutputWriter(opts.outputPath, opts.outputFormat) |
| 116 | if err != nil { |
| 117 | return err |
| 118 | } |
| 119 | defer func() { |
| 120 | if cerr := closeOut(); cerr != nil { |
| 121 | retErr = errors.Join(retErr, fmt.Errorf("close output file: %w", cerr)) |
| 122 | } |
| 123 | }() |
| 124 | |
| 125 | cc, err := loadCommonContext(opts.repoDir, opts.rulePath, "", opts.maxTools, opts.maxGitProcs, false) |
| 126 | if err != nil { |
| 127 | return err |
| 128 | } |
| 129 | applyCLIExcludes(cc, splitPaths(opts.excludes)) |
| 130 | |
| 131 | // scan owns its own template (scan_template.json) independent from the |
| 132 | // diff-review template loaded by loadCommonContext above. Apply --max-tools |
| 133 | // as an "only raise" override to the scan template's per-file budget. |
| 134 | scanTpl, err := template.LoadScanDefault() |
| 135 | if err != nil { |
| 136 | return fmt.Errorf("load scan template: %w", err) |
| 137 | } |
| 138 | if err := scanTpl.Validate(); err != nil { |
| 139 | return fmt.Errorf("invalid scan template: %w", err) |
| 140 | } |
| 141 | if opts.maxTools > scanTpl.MaxToolRequestTimes { |
| 142 | scanTpl.MaxToolRequestTimes = opts.maxTools |
| 143 | } |
| 144 | if opts.batch != "" { |
| 145 | // CLI override of BATCH_STRATEGY; validated downstream by parseBatchStrategy |
| 146 | // (unknown values silently fall back to "none"). |
| 147 | scanTpl.BatchStrategy = opts.batch |
| 148 | } |
| 149 | // Token budget: --max-tokens-budget overrides the template value when set. |
| 150 | budget := scanTpl.MaxTokensBudget |
| 151 | if opts.maxTokensBudget > 0 { |
| 152 | budget = int64(opts.maxTokensBudget) |
| 153 | } |
| 154 | |
| 155 | scanPaths := splitPaths(opts.paths) |
| 156 | |
| 157 | if opts.preview { |
| 158 | maxTokens, err := previewMaxTokens(scanTpl.MaxTokens, opts.maxTokens) |
| 159 | if err != nil { |
| 160 | return err |
| 161 | } |
| 162 | scanTpl.MaxTokens = maxTokens |
| 163 | return runScanPreview(cc, scanTpl, scanPaths, opts.outputFormat, out) |
| 164 | |
| 165 | } |
| 166 | |
| 167 | resumeState, err := loadScanResumeState(cc.RepoDir, opts, scanPaths) |
| 168 | if err != nil { |
| 169 | return err |
| 170 | } |
| 171 |
no test coverage detected