| 93 | } |
| 94 | |
| 95 | func loadDelegateContext(opts delegateOptions) (*delegateContext, error) { |
| 96 | cc, err := loadCommonContext(opts.repoDir, opts.rulePath, 0, opts.maxGitProcs, true) |
| 97 | if err != nil { |
| 98 | return nil, err |
| 99 | } |
| 100 | applyCLIExcludes(cc, splitPaths(opts.excludes)) |
| 101 | |
| 102 | // Security: reject ref-option injection. |
| 103 | reviewOpts := reviewOptions{from: opts.from, to: opts.to, commit: opts.commit} |
| 104 | if err := validateReviewRefs(cc.RepoDir, reviewOpts); err != nil { |
| 105 | return nil, err |
| 106 | } |
| 107 | |
| 108 | // Resolve background from --background-file if set. |
| 109 | if opts.backgroundFile != "" { |
| 110 | bgPath := resolveBackgroundFilePath(cc.RepoDir, opts.backgroundFile) |
| 111 | fileBackground, err := loadBackgroundFile(bgPath) |
| 112 | if err != nil { |
| 113 | return nil, err |
| 114 | } |
| 115 | opts.background = mergeBackground(opts.background, fileBackground) |
| 116 | } |
| 117 | |
| 118 | // Auto-fill background from commit message when reviewing a single commit. |
| 119 | if opts.commit != "" && opts.background == "" { |
| 120 | if msg, err := getCommitMessage(cc.RepoDir, opts.commit); err == nil && msg != "" { |
| 121 | opts.background = msg |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | return &delegateContext{cc: cc, opts: opts}, nil |
| 126 | } |
| 127 | |
| 128 | // preview runs the agent's file-selection logic and returns the preview result. |
| 129 | func (dc *delegateContext) preview(ctx context.Context) (*agent.DiffPreview, error) { |