ai

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package ai provides AI provider clients (Ollama, OpenAI, Anthropic) for prose generation, description enhancement, and metric interpretation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildChunkPrompt

func BuildChunkPrompt(report render.Report, tone Tone, sections []templatedSection, breaking []render.Item, chunkIndex, chunkTotal int) string

func BuildChunkPromptLang

func BuildChunkPromptLang(report render.Report, tone Tone, sections []templatedSection, breaking []render.Item, chunkIndex, chunkTotal int, lang i18n.Lang) string

func BuildPrompt

func BuildPrompt(report render.Report, tone Tone) string

func BuildPromptLang

func BuildPromptLang(report render.Report, tone Tone, lang i18n.Lang) string

func BuildSummaryPrompt

func BuildSummaryPrompt(report render.Report, sm SummaryMetrics, lang i18n.Lang) string

func Disclosure

func Disclosure(purpose, endpoint string, maxChars int, exclusions []string) string

Disclosure describes the outbound AI data boundary without exposing a key.

func EnhanceReport

func EnhanceReport(ctx context.Context, report render.Report, aiClient Client) (render.Report, error)

func GenerateMetricInterpretations

func GenerateMetricInterpretations(ctx context.Context, sm SummaryMetrics, client Client, lang i18n.Lang) (map[string]string, error)

func GenerateMetricsNarrative

func GenerateMetricsNarrative(ctx context.Context, sm SummaryMetrics, client Client, lang i18n.Lang) (string, error)

func GenerateProse

func GenerateProse(ctx context.Context, report render.Report, tone Tone, aiClient Client) (string, error)

func GenerateProseLang

func GenerateProseLang(ctx context.Context, report render.Report, tone Tone, aiClient Client, lang i18n.Lang) (string, error)

func GenerateProseStream

func GenerateProseStream(ctx context.Context, report render.Report, tone Tone, aiClient Client, onToken func(string)) (string, error)

func GenerateProseStreamLang

func GenerateProseStreamLang(ctx context.Context, report render.Report, tone Tone, aiClient Client, onToken func(string), lang i18n.Lang) (string, error)

func GenerateSummary

func GenerateSummary(ctx context.Context, report render.Report, aiClient Client, sm SummaryMetrics) (string, error)

func GenerateSummaryLang

func GenerateSummaryLang(ctx context.Context, report render.Report, aiClient Client, sm SummaryMetrics, lang i18n.Lang) (string, error)

func IsRetryable

func IsRetryable(err error) bool

func PathExcluded

func PathExcluded(file string, patterns []string) bool

PathExcluded applies slash-separated glob patterns, including **, to a repository-relative path.

func RedactSecrets

func RedactSecrets(input string) string

RedactSecrets removes common credential formats from arbitrary AI input.

Types

type AIError

type AIError struct {
	Provider   string
	StatusCode int
	Kind       ErrorKind
	Message    string
	Raw        string
}

func (*AIError) Error

func (e *AIError) Error() string

type AnthropicClient

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

func (*AnthropicClient) Generate

func (c *AnthropicClient) Generate(ctx context.Context, prompt string) (string, error)

func (*AnthropicClient) StreamGenerate

func (c *AnthropicClient) StreamGenerate(ctx context.Context, prompt string, onToken func(string)) (string, error)

type Client

type Client interface {
	Generate(ctx context.Context, prompt string) (string, error)
	StreamGenerate(ctx context.Context, prompt string, onToken func(string)) (string, error)
}

Client is the interface for AI text generation providers.

func NewClient

func NewClient(cfg Config) (Client, error)

func WithInputPolicy

func WithInputPolicy(client Client, policy InputPolicy) Client

WithInputPolicy wraps a provider so every generation path shares the same redaction and volume controls.

type Config

type Config struct {
	Provider  string `yaml:"provider"`
	Model     string `yaml:"model"`
	APIKey    string `yaml:"api_key"`
	BaseURL   string `yaml:"base_url"`
	MaxTokens int    `yaml:"max_tokens"`
}

Config holds AI provider connection settings.

type ContributorStat

type ContributorStat struct {
	Name    string
	Commits int
}

type ErrorKind

type ErrorKind int
const (
	ErrKindUnknown ErrorKind = iota
	ErrKindAuth
	ErrKindRateLimit
	ErrKindServerError
	ErrKindNetwork
	ErrKindInvalidRequest
	ErrKindContextCanceled
	ErrKindEmptyResponse
)

type InputPolicy

type InputPolicy struct {
	MaxChars int
}

InputPolicy is enforced immediately before any prompt leaves the process.

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type OllamaClient

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

func (*OllamaClient) Generate

func (c *OllamaClient) Generate(ctx context.Context, prompt string) (string, error)

func (*OllamaClient) StreamGenerate

func (c *OllamaClient) StreamGenerate(ctx context.Context, prompt string, onToken func(string)) (string, error)

type OpenAIClient

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

func (*OpenAIClient) Generate

func (c *OpenAIClient) Generate(ctx context.Context, prompt string) (string, error)

func (*OpenAIClient) StreamGenerate

func (c *OpenAIClient) StreamGenerate(ctx context.Context, prompt string, onToken func(string)) (string, error)

type SummaryMetrics

type SummaryMetrics struct {
	TotalCommits                     int
	TotalAuthors                     int
	TopContributors                  []ContributorStat
	BreakingChanges                  int
	SignificanceCounts               map[string]int
	TypeCounts                       map[string]int
	DateRange                        string
	CommitsPerDay                    float64
	MostActiveDay                    string
	MostActiveDayCount               int
	FilesTouched                     int
	LinesAdded                       int
	LinesDeleted                     int
	NetLines                         int
	JiraTicketsLinked                int
	HotspotDensity                   float64
	ChurnFactor                      float64
	ComplexityPerFeat                float64
	ReleaseCommitSpanHours           float64
	ReleaseAgeHours                  float64
	OwnershipConc                    float64
	OwnershipEntropy                 float64
	ReleaseContributionConcentration int
	FixToFeatureRatio                float64
	TestToSourceRatio                float64
	RefactoringRatio                 float64
	APISurfaceChange                 int
	ReleaseRiskScore                 float64
	BatchFactor                      float64
	RevertRate                       float64
	ScopeIsolation                   float64
	CrossCuttingPct                  float64
	FileVolatility                   float64
	ChangeComplexityProxy            float64
	CrossCuttingChangeRisk           float64
	TechnicalDebtUSD                 float64
	TouchedTestFileRatio             float64
	HotspotScore                     float64
	CommitSizeSmall                  int
	CommitSizeMedium                 int
	CommitSizeLarge                  int
	CommitSizeHuge                   int
	ReviewLoad                       float64
	DeleteRatio                      float64
	CommitMsgQuality                 float64
	AuthorOverlap                    float64
	PeakHourSpread                   float64
	DirectoryBreadth                 float64
	ConfigChurnRate                  float64
	CodeFreshness                    float64
	RhythmConsistency                float64
	ReleaseCadenceDays               int
	DepUpdateFreq                    float64
	LanguageMix                      float64
}

type Tone

type Tone string

Tone controls the audience and style of AI-generated prose.

const (
	ToneDev      Tone = "dev"
	ToneCustomer Tone = "customer"
	ToneExec     Tone = "exec"
)

func ParseTone

func ParseTone(s string) (Tone, error)

Jump to

Keyboard shortcuts

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