Documentation
¶
Overview ¶
Package events extracts AI candidate data from attribution event rows. It is a pure domain package with no database, blob store, or git dependencies. Callers load the input data and pass it in.
Index ¶
- func AddLines(m map[string]map[string]struct{}, filePath, text string)
- func BuildCandidatesFromRows(rows []EventRow, repoRoot string, eligibleFiles map[string]bool) (Candidates, EventStats)
- func ExtractClaudeActions(raw []byte, repoRoot string) (fileLines map[string]map[string]struct{}, bashCommands []string)
- func ExtractDeletedPaths(cmd, repoRoot string) []string
- func ExtractProviderFileTouches(toolUses string) []string
- func HasEditOrWrite(toolUses string) bool
- func HasProviderFileEdit(toolUses string) bool
- func NormalizePath(filePath, repoRoot string) string
- type Candidates
- type EventRow
- type EventStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddLines ¶
AddLines splits text into lines and inserts each trimmed, non-blank line into the set for the given file path.
func BuildCandidatesFromRows ¶
func BuildCandidatesFromRows(rows []EventRow, repoRoot string, eligibleFiles map[string]bool) (Candidates, EventStats)
BuildCandidatesFromRows extracts AI candidate data from event rows. It processes events in order, building the candidate maps and collecting diagnostic stats. Callers provide any pre-loaded payload bytes in each EventRow.
When eligibleFiles is non-nil, only files in the set contribute to candidate maps (used by carry-forward gating).
func ExtractClaudeActions ¶
func ExtractClaudeActions(raw []byte, repoRoot string) (fileLines map[string]map[string]struct{}, bashCommands []string)
ExtractClaudeActions parses a Claude-format assistant payload and extracts: - fileLines: map of repo-relative file paths to sets of trimmed lines (from Edit/Write tools) - bashCommands: shell commands from Bash tool calls
func ExtractDeletedPaths ¶
ExtractDeletedPaths extracts file paths from a shell command containing "rm". Returns repo-relative paths.
func ExtractProviderFileTouches ¶
ExtractProviderFileTouches parses the tool_uses JSON and returns repo-relative file paths that the AI touched.
func HasEditOrWrite ¶
HasEditOrWrite returns true if the tool_uses JSON contains an Edit or Write tool call. Used as a fast pre-filter before payload loading.
func HasProviderFileEdit ¶
HasProviderFileEdit returns true if the tool_uses JSON indicates a provider file edit event. Matches tool names from Cursor, Copilot, Kiro, and Gemini that represent file modifications without line-level payload content.
func NormalizePath ¶
NormalizePath converts an absolute file path to a repo-relative path using forward slashes, matching the format produced by "git diff". Handles MSYS-style paths (/c/workspace/...) from Claude Code on Windows.
Types ¶
type Candidates ¶
type Candidates struct {
AILines map[string]map[string]struct{} // file -> set of trimmed lines
ProviderTouchedFiles map[string]string // file -> provider (file-level, includes deletions)
FileProvider map[string]string // file -> provider (line-level)
ProviderModel map[string]string // provider -> model
}
Candidates holds the AI-authored text extracted from events. Deleted paths from bash `rm` commands are folded into ProviderTouchedFiles (they contribute to "AI touched this file", not a separate category).
type EventRow ¶
type EventRow struct {
Provider string
Role string // "assistant", "user", "tool", etc.
ToolUses string // raw JSON from the tool_uses column
PayloadHash string // CAS hash (for diagnostics, not used for loading)
Payload []byte // pre-loaded by the caller; nil if unavailable
Model string // LLM model name (e.g. "opus 4.6")
}
EventRow is a self-contained event for candidate building. Callers map source rows into this type and attach any pre-loaded payload bytes before calling BuildCandidatesFromRows.
type EventStats ¶
type EventStats struct {
EventsConsidered int
EventsAssistant int
PayloadsLoaded int
AIToolEvents int
}
EventStats collects diagnostic counters from event processing. Each counter is independently meaningful; callers combine EventStats with scoring stats to produce the full diagnostics.