loadCommonContext validates the working directory, loads the embedded template, raises MaxToolRequestTimes when maxTools exceeds the default, resolves the absolute repo path, loads system review rules, and creates the global git subprocess limiter. Both review and scan callers go through this so the
(repoDirInput, rulePath string, maxTools, maxGitProcs int, requireGit bool)
| 70 | // path: diff concept requires git). requireGit=false allows non-git |
| 71 | // directories (scan path: provider falls back to filepath.Walk). |
| 72 | func loadCommonContext(repoDirInput, rulePath string, maxTools, maxGitProcs int, requireGit bool) (*commonContext, error) { |
| 73 | tpl, err := template.LoadDefault() |
| 74 | if err != nil { |
| 75 | return nil, fmt.Errorf("load default template: %w", err) |
| 76 | } |
| 77 | if maxTools > tpl.MaxToolRequestTimes { |
| 78 | tpl.MaxToolRequestTimes = maxTools |
| 79 | } |
| 80 | if err := tpl.Validate(); err != nil { |
| 81 | return nil, fmt.Errorf("invalid config: %w", err) |
| 82 | } |
| 83 | |
| 84 | repoDir, isGit, err := resolveWorkingDir(repoDirInput, requireGit) |
| 85 | if err != nil { |
| 86 | return nil, err |
| 87 | } |
| 88 | |
| 89 | resolver, fileFilter, err := rules.NewResolver(repoDir, rulePath) |
| 90 | if err != nil { |
| 91 | return nil, fmt.Errorf("load rules: %w", err) |
| 92 | } |
| 93 | |
| 94 | return &commonContext{ |
| 95 | Template: tpl, |
| 96 | RepoDir: repoDir, |
| 97 | Resolver: resolver, |
| 98 | FileFilter: fileFilter, |
| 99 | GitRunner: gitcmd.New(maxGitProcs), |
| 100 | IsGitRepo: isGit, |
| 101 | }, nil |
| 102 | } |
| 103 | |
| 104 | // resolveWorkingDir returns (absPath, isGitRepo, err). When requireGit is |
| 105 | // true, returns an error if the directory is not a git repo. When false, |