{"modulePath":"github.com/Agent-Field/codeaf","version":"v0.8.4","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package diffanalysis\n\nPackage diffanalysis ports src/sec\\_af/diff\\_analysis.py — the diff-aware file selection SEC-AF uses in PR mode.\n\nThe orchestrator builds one DiffAnalysis per run when the audit input is a PR (\\`is\\_pr\\` with a \\`base\\_commit\\_sha\\`) and feeds AllRelevantFiles to the hunt phase as \\`include\\_paths\\`, so the set of files this package computes decides what the hunters look at.\n\n\tself.diff_analysis = analyze_diff(\n\t    str(self.repo_path), input.base_commit_sha, input.commit_sha or \"HEAD\",\n\t)\n\nEverything here shells out to git and swallows failures the way Python does: a git that cannot be started, or that takes longer than 30 seconds, yields an EMPTY analysis (for the diff) or is skipped (for a blast-radius grep). A git that runs and exits non-zero is NOT a failure — Python passes check=False, so the (usually empty) stdout is used as-is.\n\n## Constants\n\n```go\nconst DefaultHeadSHA = \"HEAD\"\n```\nDefaultHeadSHA is the value Python's \\`head\\_sha\\` parameter defaults to:\n\n\tdef analyze_diff(repo_path: str, base_sha: str, head_sha: str = \"HEAD\")\n\nGo has no default arguments, so callers pass it explicitly. The only production caller (orchestrator.py) always supplies \\`input.commit\\_sha or \"HEAD\"\\`, i.e. this constant whenever the input carries no commit.\n\n## Functions\n\n```go\nfunc FileToModule(filePath string) string\n```\nFileToModule converts a file path to the importable module name used for the blast-radius grep.\n\nPorts diff\\_analysis.py \\_file\\_to\\_module. Exported for the same reason as IsScannable.\n\nPython parity — the three branches are literal transliterations, quirks included (VERIFIED against the venv interpreter):\n\n\t\"src/service/user.py\"      -\u003e \"user\"    (dots, drop \".py\", last segment)\n\t\"src/service/user.test.py\" -\u003e \"test\"    (same, so an infix dot wins)\n\t\"foo..py\"                  -\u003e \"\"        (empty last segment; callers skip it)\n\t\"a.js.ts\"                  -\u003e \"a\"       (\".ts\" stripped, then \".js\")\n\t\"a.ts.js\"                  -\u003e \"a.ts\"    (\".ts\" does not match, \".js\" does)\n\t\"a/b.tar.gz\"               -\u003e \"b\"       (fallback: basename up to first dot)\n\t\"a/.hidden\"                -\u003e \"\"        (fallback on a dotfile)\n\n```go\nfunc IsScannable(filePath string) bool\n```\nIsScannable reports whether a file should be included in security scanning.\n\nPorts diff\\_analysis.py \\_is\\_scannable. Exported because the orchestrator's PR-mode path and the hunt include\\_paths plumbing want the same predicate; Python keeps it private only because the module is self-contained.\n\nPython parity, two quirks worth stating out loud:\n\n  - The directory test is str.startswith, NOT a path-segment containment test. \"src/tests/x.py\" is scannable; only a TOP-LEVEL tests/ dir is skipped. (\"atests/x.py\" is likewise scannable — the prefix is \"tests/\", with the slash.)\n  - The extension test is str.endswith and therefore case-sensitive: \"a.lock\" is skipped, \"a.LOCK\" is not.\n\n## Types\n\n```go\ntype DiffAnalysis struct {\n\tChangedFiles     []string `json:\"changed_files\"`\n\tBlastRadiusFiles []string `json:\"blast_radius_files\"`\n\tAllRelevantFiles []string `json:\"all_relevant_files\"`\n\tBaseSHA          string   `json:\"base_sha\"`\n\tHeadSHA          string   `json:\"head_sha\"`\n}\n```\nDiffAnalysis is the result of analyzing the git diff between base and head.\n\nPorts the diff\\_analysis.py dataclass of the same name. The three list fields have \\`field(default\\_factory=list)\\`, so the zero value of a Go DiffAnalysis (nil slices) is NOT the Python default — use NewDiffAnalysis, which every constructor path in this package does, so the slices are always non-nil and marshal as \\`\\[]\\` rather than \\`null\\`.\n\n```go\nfunc AnalyzeDiff(ctx context.Context, repoPath, baseSHA, headSHA string) DiffAnalysis\n```\nAnalyzeDiff analyzes the git diff to find changed files and their blast radius.\n\nPorts src/sec\\_af/diff\\_analysis.py analyze\\_diff. Blast radius = files that import from, or are imported by, changed files — approximated by grepping the head tree for each changed file's module name.\n\nNever returns an error: every git failure degrades to an empty or partial result, exactly as the Python function does.\n\n```go\nfunc NewDiffAnalysis() DiffAnalysis\n```\nNewDiffAnalysis returns the dataclass defaults: three empty lists, base\\_sha \"\" and head\\_sha \"HEAD\".\n\n```go\nfunc (d DiffAnalysis) FileCount() int\n```\nFileCount ports the \\`file\\_count\\` property: the number of files the hunters will actually be pointed at.\n\n","path":"github.com/Agent-Field/codeaf/internal/secaf/diffanalysis","name":"diffanalysis","synopsis":"Package diffanalysis ports src/sec_af/diff_analysis.py — the diff-aware file selection SEC-AF uses in PR mode.","isRedistributable":true}
