(opts scanOptions)
| 92 | } |
| 93 | |
| 94 | func executeScan(opts scanOptions) error { |
| 95 | cc, err := loadCommonContext(opts.repoDir, opts.rulePath, opts.maxTools, opts.maxGitProcs, false) |
| 96 | if err != nil { |
| 97 | return err |
| 98 | } |
| 99 | applyCLIExcludes(cc, splitPaths(opts.excludes)) |
| 100 | |
| 101 | // scan owns its own template (scan_template.json) independent from the |
| 102 | // diff-review template loaded by loadCommonContext above. Apply --max-tools |
| 103 | // as an "only raise" override to the scan template's per-file budget. |
| 104 | scanTpl, err := template.LoadScanDefault() |
| 105 | if err != nil { |
| 106 | return fmt.Errorf("load scan template: %w", err) |
| 107 | } |
| 108 | if err := scanTpl.Validate(); err != nil { |
| 109 | return fmt.Errorf("invalid scan template: %w", err) |
| 110 | } |
| 111 | if opts.maxTools > scanTpl.MaxToolRequestTimes { |
| 112 | scanTpl.MaxToolRequestTimes = opts.maxTools |
| 113 | } |
| 114 | if opts.batch != "" { |
| 115 | // CLI override of BATCH_STRATEGY; validated downstream by parseBatchStrategy |
| 116 | // (unknown values silently fall back to "none"). |
| 117 | scanTpl.BatchStrategy = opts.batch |
| 118 | } |
| 119 | // Token budget: --max-tokens-budget overrides the template value when set. |
| 120 | budget := scanTpl.MaxTokensBudget |
| 121 | if opts.maxTokensBudget > 0 { |
| 122 | budget = int64(opts.maxTokensBudget) |
| 123 | } |
| 124 | |
| 125 | scanPaths := splitPaths(opts.paths) |
| 126 | |
| 127 | if opts.preview { |
| 128 | return runScanPreview(cc, scanTpl, scanPaths) |
| 129 | } |
| 130 | |
| 131 | rt, err := loadLLMRuntime(cc.Template, opts.toolConfigPath, opts.model) |
| 132 | if err != nil { |
| 133 | return err |
| 134 | } |
| 135 | // Apply language to the scan template too (loadLLMRuntime only mutates |
| 136 | // the diff-review template it was handed). |
| 137 | if rt.AppCfg != nil { |
| 138 | scanTpl.ApplyLanguage(rt.AppCfg.Language) |
| 139 | } |
| 140 | |
| 141 | // file_read_diff is meaningless in scan mode (no diff exists). Hiding it |
| 142 | // from MainToolDefs stops the LLM from burning tool-call rounds probing |
| 143 | // for diff content that does not exist. |
| 144 | scanToolDefs := excludeToolDef(rt.MainToolDefs, "file_read_diff") |
| 145 | |
| 146 | // Scan mode always reads file contents from the working tree. |
| 147 | fileReader := &tool.FileReader{ |
| 148 | RepoDir: cc.RepoDir, |
| 149 | Mode: tool.ModeWorkspace, |
| 150 | Runner: cc.GitRunner, |
| 151 | } |
no test coverage detected