events

package
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLines

func AddLines(m map[string]map[string]struct{}, filePath, text string)

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

func ExtractDeletedPaths(cmd, repoRoot string) []string

ExtractDeletedPaths extracts file paths from a shell command containing "rm". Returns repo-relative paths.

func ExtractProviderFileTouches

func ExtractProviderFileTouches(toolUses string) []string

ExtractProviderFileTouches parses the tool_uses JSON and returns repo-relative file paths that the AI touched.

func HasEditOrWrite

func HasEditOrWrite(toolUses string) bool

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

func HasProviderFileEdit(toolUses string) bool

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

func NormalizePath(filePath, repoRoot string) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL