ai

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultWorkers = 4

DefaultWorkers is the batch concurrency used when none is configured.

Variables

This section is empty.

Functions

func GetAvailableModels

func GetAvailableModels(provider Provider) []string

GetAvailableModels returns a list of available models for a given provider

func GetDefaultModel

func GetDefaultModel(provider Provider) string

GetDefaultModel returns the default model for a given provider

func GetSupportedProviders

func GetSupportedProviders() []string

GetSupportedProviders returns a list of supported AI providers

func PrintAISummary

func PrintAISummary(term *terminal.Terminal, summary AISummary, provider Provider, model string)

PrintAISummary prints a summary box of AI analysis results to the terminal.

func ShouldSkipAI

func ShouldSkipAI(f rules.Finding) (bool, string)

ShouldSkipAI returns (true, reason) when a finding does not need AI analysis. It subsumes the previous shouldSendToAI severity/rule-list gate — env-based filters (AI_MIN_SEVERITY, AI_INCLUDE_RULES, AI_EXCLUDE_RULES) run first.

func ValidateProvider

func ValidateProvider(provider string) error

ValidateProvider checks if the provider is supported

Types

type AISummary

type AISummary struct {
	TotalAnalyzed        int `json:"total_analyzed"`
	SuccessfullyAnalyzed int `json:"successfully_analyzed"`
	AnalysisErrors       int `json:"analysis_errors"`
	LikelyFalsePositives int `json:"likely_false_positives"`
	LikelyTruePositives  int `json:"likely_true_positives"`
	HighConfidence       int `json:"high_confidence"`   // >= 0.8
	MediumConfidence     int `json:"medium_confidence"` // >= 0.6 && < 0.8
	LowConfidence        int `json:"low_confidence"`    // < 0.6
	SkippedByFilter      int `json:"skipped_by_filter"`
}

AISummary provides statistics about AI analysis results

func GetSummary

func GetSummary(enhancedFindings []EnhancedFinding) AISummary

GetSummary returns a summary of AI analysis results

type Analyzer

type Analyzer struct {
	// contains filtered or unexported fields
}

Analyzer handles AI-powered analysis of findings

func NewAnalyzer

func NewAnalyzer(client Client, timeout time.Duration) *Analyzer

NewAnalyzer creates a new AI analyzer with default options.

func NewAnalyzerWithOptions added in v2.1.0

func NewAnalyzerWithOptions(client Client, opts Options) *Analyzer

NewAnalyzerWithOptions creates a new AI analyzer.

func (*Analyzer) AnalyzeFindings

func (a *Analyzer) AnalyzeFindings(ctx context.Context, findings []rules.Finding) ([]EnhancedFinding, error)

AnalyzeFindings analyzes multiple findings using AI

func (*Analyzer) AnalyzeSingleFinding

func (a *Analyzer) AnalyzeSingleFinding(ctx context.Context, finding rules.Finding) (*EnhancedFinding, error)

AnalyzeSingleFinding analyzes a single finding using AI

func (*Analyzer) Close

func (a *Analyzer) Close() error

Close cleans up the analyzer

type BatchVerificationResult

type BatchVerificationResult struct {
	Index  int                 `json:"index"`
	Result *VerificationResult `json:"result,omitempty"`
	Error  string              `json:"error,omitempty"`
}

BatchVerificationResult is one result from a VerifyBatch call. Index echoes the input finding's position for correct attribution.

type ClaudeClient

type ClaudeClient struct {
	// contains filtered or unexported fields
}

ClaudeClient implements the Client interface for Anthropic Claude API

func NewClaudeClient

func NewClaudeClient(config Config) (*ClaudeClient, error)

NewClaudeClient creates a new Claude client

func (*ClaudeClient) Close

func (c *ClaudeClient) Close() error

Close cleans up resources

func (*ClaudeClient) GetProvider

func (c *ClaudeClient) GetProvider() Provider

GetProvider returns the provider name

func (*ClaudeClient) VerifyBatch

func (c *ClaudeClient) VerifyBatch(ctx context.Context, class string, findings []ContextualFinding) ([]BatchVerificationResult, error)

VerifyBatch analyzes a batch of findings of the same class using Claude.

func (*ClaudeClient) VerifyFinding

func (c *ClaudeClient) VerifyFinding(ctx context.Context, finding rules.Finding) (*VerificationResult, error)

VerifyFinding analyzes a finding using Claude

type Client

type Client interface {
	// VerifyFinding analyzes a security finding and determines if it's likely a false positive
	VerifyFinding(ctx context.Context, finding rules.Finding) (*VerificationResult, error)

	// VerifyBatch analyses up to 5 findings of the same class in one API call.
	VerifyBatch(ctx context.Context, class string, findings []ContextualFinding) ([]BatchVerificationResult, error)

	// GetProvider returns the provider name
	GetProvider() Provider

	// Close cleans up any resources
	Close() error
}

Client interface for AI providers

func NewClient

func NewClient(config Config) (Client, error)

NewClient creates a new AI client based on the provider

type Config

type Config struct {
	Provider Provider `yaml:"provider"`
	APIKey   string   `yaml:"api_key"`
	BaseURL  string   `yaml:"base_url,omitempty"` // Custom endpoint for self-hosted models
	Model    string   `yaml:"model,omitempty"`    // Specific model to use

	// Request configuration
	MaxTokens   int     `yaml:"max_tokens,omitempty"`
	Temperature float64 `yaml:"temperature,omitempty"`
	Timeout     int     `yaml:"timeout,omitempty"` // seconds
}

Config holds configuration for AI clients

type ContextProvider added in v2.1.0

type ContextProvider struct {
	// contains filtered or unexported fields
}

ContextProvider resolves findings back to the workflow they came from.

func NewContextProvider added in v2.1.0

func NewContextProvider(files []parser.WorkflowFile) *ContextProvider

NewContextProvider indexes the scanned workflows for lookup by path.

func (*ContextProvider) For added in v2.1.0

For returns the context for a finding. A finding whose workflow cannot be resolved yields a zero context rather than an error: the analysis should still run, just with less evidence.

type ContextualFinding added in v2.1.0

type ContextualFinding struct {
	Finding rules.Finding
	Context FindingContext
}

ContextualFinding pairs a finding with the workflow evidence needed to judge it. Findings are never sent to a model without this.

type EnhancedFinding

type EnhancedFinding struct {
	rules.Finding
	AIVerification *VerificationResult `json:"ai_verification,omitempty"`
	AIError        string              `json:"ai_error,omitempty"`
	AISkipped      bool                `json:"ai_skipped,omitempty"`
	AISkipReason   string              `json:"ai_skip_reason,omitempty"`
}

EnhancedFinding represents a finding enhanced with AI verification

type FindingContext added in v2.1.0

type FindingContext struct {
	// Snippet is the workflow source around the finding, with line numbers.
	Snippet string
	// WorkflowTriggers lists the events that can start this workflow, which
	// determines whether an untrusted actor can reach the finding at all.
	WorkflowTriggers []string
	// WorkflowPermissions and JobPermissions describe the credentials in scope.
	// "not set" and "default" are meaningfully different, so both are rendered
	// explicitly rather than left empty.
	WorkflowPermissions string
	JobPermissions      string
	// JobNeeds records upstream jobs, since data can arrive through them.
	JobNeeds []string
	// JobRunsOn distinguishes hosted from self-hosted runners.
	JobRunsOn string
	// StepUses and StepRun are the full step definition, not the truncated
	// evidence fragment.
	StepUses string
	StepRun  string
}

FindingContext is the workflow evidence a model needs in order to judge a finding.

Without it a model is asked, for example, whether an action runs "in a privileged job" while being told nothing about the job's permissions. It can only guess, and a guessing model that is also asked for a confidence score produces confident fabrication. Every field here exists because one of the prompts depends on it.

type GeminiClient

type GeminiClient struct {
	// contains filtered or unexported fields
}

GeminiClient implements the Client interface for Google Gemini API

func NewGeminiClient

func NewGeminiClient(config Config) (*GeminiClient, error)

NewGeminiClient creates a new Gemini client

func (*GeminiClient) Close

func (c *GeminiClient) Close() error

Close cleans up resources

func (*GeminiClient) GetProvider

func (c *GeminiClient) GetProvider() Provider

GetProvider returns the provider name

func (*GeminiClient) VerifyBatch

func (c *GeminiClient) VerifyBatch(ctx context.Context, class string, findings []ContextualFinding) ([]BatchVerificationResult, error)

VerifyBatch analyzes a batch of findings of the same class using Gemini.

func (*GeminiClient) VerifyFinding

func (c *GeminiClient) VerifyFinding(ctx context.Context, finding rules.Finding) (*VerificationResult, error)

VerifyFinding analyzes a finding using Gemini

type GrokClient

type GrokClient struct {
	// contains filtered or unexported fields
}

GrokClient implements the Client interface for xAI Grok API

func NewGrokClient

func NewGrokClient(config Config) (*GrokClient, error)

NewGrokClient creates a new Grok client

func (*GrokClient) Close

func (c *GrokClient) Close() error

Close cleans up resources

func (*GrokClient) GetProvider

func (c *GrokClient) GetProvider() Provider

GetProvider returns the provider name

func (*GrokClient) VerifyBatch

func (c *GrokClient) VerifyBatch(ctx context.Context, class string, findings []ContextualFinding) ([]BatchVerificationResult, error)

VerifyBatch analyzes a batch of findings of the same class using Grok.

func (*GrokClient) VerifyFinding

func (c *GrokClient) VerifyFinding(ctx context.Context, finding rules.Finding) (*VerificationResult, error)

VerifyFinding analyzes a finding using Grok

type OpenAIClient

type OpenAIClient struct {
	// contains filtered or unexported fields
}

OpenAIClient implements the Client interface for OpenAI API

func NewOpenAIClient

func NewOpenAIClient(config Config) (*OpenAIClient, error)

NewOpenAIClient creates a new OpenAI client

func (*OpenAIClient) Close

func (c *OpenAIClient) Close() error

Close cleans up resources

func (*OpenAIClient) GetProvider

func (c *OpenAIClient) GetProvider() Provider

GetProvider returns the provider name

func (*OpenAIClient) VerifyBatch

func (c *OpenAIClient) VerifyBatch(ctx context.Context, class string, findings []ContextualFinding) ([]BatchVerificationResult, error)

VerifyBatch analyzes a batch of findings of the same class using OpenAI.

func (*OpenAIClient) VerifyFinding

func (c *OpenAIClient) VerifyFinding(ctx context.Context, finding rules.Finding) (*VerificationResult, error)

VerifyFinding analyzes a finding using OpenAI

type Options added in v2.1.0

type Options struct {
	// RequestTimeout bounds a single provider request. Defaults to 30s.
	RequestTimeout time.Duration
	// TotalTimeout optionally bounds the whole analysis. Zero means unbounded.
	TotalTimeout time.Duration
	// Workers is the number of batches dispatched concurrently. Defaults to 4,
	// which keeps throughput high without tripping provider rate limits.
	Workers int
	// Contexts supplies workflow evidence for each finding. May be nil, in
	// which case findings are sent without surrounding context.
	Contexts *ContextProvider
}

Options configures an Analyzer.

type PerplexityClient

type PerplexityClient struct {
	// contains filtered or unexported fields
}

PerplexityClient implements the Client interface for Perplexity AI API

func NewPerplexityClient

func NewPerplexityClient(config Config) (*PerplexityClient, error)

NewPerplexityClient creates a new Perplexity client

func (*PerplexityClient) Close

func (c *PerplexityClient) Close() error

Close cleans up resources

func (*PerplexityClient) GetProvider

func (c *PerplexityClient) GetProvider() Provider

GetProvider returns the provider name

func (*PerplexityClient) VerifyBatch

func (c *PerplexityClient) VerifyBatch(ctx context.Context, class string, findings []ContextualFinding) ([]BatchVerificationResult, error)

VerifyBatch analyzes a batch of findings of the same class using Perplexity.

func (*PerplexityClient) VerifyFinding

func (c *PerplexityClient) VerifyFinding(ctx context.Context, finding rules.Finding) (*VerificationResult, error)

VerifyFinding analyzes a finding using Perplexity

type Provider

type Provider string

Provider represents different AI providers

const (
	ProviderOpenAI     Provider = "openai"
	ProviderGemini     Provider = "gemini"
	ProviderClaude     Provider = "claude"
	ProviderGrok       Provider = "grok"
	ProviderPerplexity Provider = "perplexity"
)

type VerificationResult

type VerificationResult struct {
	IsLikelyFalsePositive bool    `json:"is_likely_false_positive"`
	Confidence            float64 `json:"confidence"` // 0.0 to 1.0
	Reasoning             string  `json:"reasoning"`
	Severity              string  `json:"suggested_severity,omitempty"`
	Remediation           string  `json:"remediation,omitempty"`
}

VerificationResult represents the AI's assessment of a finding

Jump to

Keyboard shortcuts

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