Documentation
¶
Overview ¶
Package evidence ports pr_af/evidence.py: ground-truth code extraction that grounds each finding in the actual repository source. It shells out to the same `grep` binary with the same arguments Python uses (so caller/import discovery is byte-identical regardless of the grep flavor installed), reads snippets around finding lines, and pre-reads a review dimension's target files into a primed context pack.
Divergences from Python (all output-neutral or unreachable in practice):
- The Python (abspath, mtime) file-read cache (_FILE_CACHE) is a pure performance optimization ("zero quality cost") and is NOT ported; files are read fresh. Output is identical.
- Python opens files with errors="ignore" (dropping undecodable bytes); Go reads raw bytes. This only differs on non-UTF-8 text files, where the regex/line-number logic is unaffected in practice.
- _extract_diff_hunk's fallback scan over diff_patches follows Python's dict INSERTION order to pick the first key that normalizes to the target; Go maps have no order, so the scan uses SORTED key order. This only matters when two distinct keys normalize identically with differing patch values — a pathological input that does not occur for real diff maps.
Index ¶
- func BuildDimensionPack(ctx context.Context, repoPath string, targetFiles []string, ...) string
- func BuildImportContext(ctx context.Context, repoPath, filePath string) string
- func ExtractDiffHunk(diffPatches map[string]string, filePath string, line *int) string
- func ExtractEvidenceForFindings(ctx context.Context, findings []schemas.ReviewFinding, repoPath string, ...) (map[string]EvidencePackage, error)
- func FindFunctionCallers(ctx context.Context, repoPath, functionName, excludeFile string) []string
- func ReadCodeSnippet(repoPath, filePath string, line, contextLines int) string
- type EvidencePackage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildDimensionPack ¶
func BuildDimensionPack(ctx context.Context, repoPath string, targetFiles []string, diffPatches map[string]string) string
BuildDimensionPack ports build_dimension_pack. diffPatches is accepted for call-site parity but is unused by the Python implementation too.
func BuildImportContext ¶
BuildImportContext exposes _build_import_context.
func ExtractDiffHunk ¶
ExtractDiffHunk exposes _extract_diff_hunk. A nil line reproduces Python's line=None (return the whole patch, capped at 200 lines).
func ExtractEvidenceForFindings ¶
func ExtractEvidenceForFindings( ctx context.Context, findings []schemas.ReviewFinding, repoPath string, diffPatches map[string]string, blastRadius []string, ) (map[string]EvidencePackage, error)
ExtractEvidenceForFindings ports extract_evidence_for_findings. It processes findings concurrently, bounded by a weighted semaphore of 10, and returns a map keyed by finding title. Results are written into a PRE-INDEXED slice (never appended on completion) so that on a title collision the last finding in input order wins, exactly as Python's {p.finding_title: p for p in gather}.
func FindFunctionCallers ¶
FindFunctionCallers exposes _find_function_callers.
func ReadCodeSnippet ¶
ReadCodeSnippet exposes _read_code_snippet (±context_lines around line).
Types ¶
type EvidencePackage ¶
type EvidencePackage struct {
FindingTitle string `json:"finding_title"`
PrimaryCode string `json:"primary_code"`
CallerSnippets []string `json:"caller_snippets"`
CrossRefSnippets []string `json:"cross_ref_snippets"`
DiffHunk string `json:"diff_hunk"`
ImportContext string `json:"import_context"`
RelatedCode string `json:"related_code"`
}
EvidencePackage ports the pydantic EvidencePackage: ground-truth code evidence for a single finding. Slice fields default to non-nil empty slices (Field(default_factory=list)) so they marshal to [] rather than null.