aiprovider

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const ModeAllowCopilotText = "allow"

ModeAllowCopilotText is the default permission mode for text-only completions.

Variables

This section is empty.

Functions

func AutoPickCandidate added in v0.0.14

func AutoPickCandidate(candidates []CommitCandidate) string

AutoPickCandidate chooses the best commit message without user interaction.

func BreakingChangeHint

func BreakingChangeHint(diff string) string

BreakingChangeHint returns a user-facing hint for breaking changes.

func CommitMessageFromDiff

func CommitMessageFromDiff(diff string) string

CommitMessageFromDiff builds a conventional-style message from a git diff.

func CopilotCLIExists

func CopilotCLIExists(cliPath string) bool

CopilotCLIExists reports whether a Copilot CLI binary appears available.

func DetectBreakingChange

func DetectBreakingChange(diff string) bool

DetectBreakingChange heuristically flags potentially breaking diffs.

func EnhanceText

func EnhanceText(ctx context.Context, provider Provider, system, user, fallback string) (string, bool, error)

EnhanceText runs a completion and returns trimmed text, or the original on failure.

func FormatCandidateLabel

func FormatCandidateLabel(c CommitCandidate) string

FormatCandidateLabel renders a select option label.

func FormatError

func FormatError(providerName string, err error) error

FormatError wraps provider errors for CLI output.

func MustEnhanceText

func MustEnhanceText(ctx context.Context, provider Provider, system, user, fallback string) string

MustEnhanceText returns enhanced text or fallback without error.

func RunCopilotSession

func RunCopilotSession(ctx context.Context, cfg CopilotConfig, prompt string, cb SessionCallbacks) error

RunCopilotSession executes a Copilot prompt and waits until the session is idle.

Types

type Chain

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

Chain tries providers in order until one succeeds.

func NewChain

func NewChain(providers ...Provider) *Chain

NewChain returns a provider chain.

func (*Chain) Available

func (c *Chain) Available() bool

func (*Chain) Complete

func (c *Chain) Complete(ctx context.Context, req CompleteRequest) (CompleteResponse, error)

func (*Chain) Name

func (c *Chain) Name() string

type CommitCandidate

type CommitCandidate struct {
	Style   string
	Message string
}

CommitCandidate is one generated commit message option.

func GenerateCommitCandidates

func GenerateCommitCandidates(ctx context.Context, provider Provider, diff string) ([]CommitCandidate, error)

GenerateCommitCandidates asks the provider for 3 commit message options.

type CompleteRequest

type CompleteRequest struct {
	System string
	User   string
	Model  string
}

CompleteRequest is a chat-style completion input.

type CompleteResponse

type CompleteResponse struct {
	Text     string
	Provider string
	Model    string
	Usage    any
	Fallback bool
}

CompleteResponse is a normalized completion output.

type CopilotConfig

type CopilotConfig struct {
	CLIPath         string
	LogLevel        string
	WorkingDir      string
	GitHubToken     string
	UseLoggedInUser bool
	Model           string
	ReasoningEffort string
	PermissionMode  string
	AutoUserAnswer  string
	Streaming       bool
}

CopilotConfig configures the Copilot SDK client.

func DefaultCopilotConfig

func DefaultCopilotConfig(workingDir string) CopilotConfig

DefaultCopilotConfig returns sensible defaults for programmatic Copilot use.

type CopilotProvider

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

CopilotProvider implements Provider using Copilot SDK text completion.

func NewCopilot

func NewCopilot(cfg CopilotConfig) *CopilotProvider

NewCopilot creates a Copilot-backed Provider.

func (*CopilotProvider) Available

func (p *CopilotProvider) Available() bool

func (*CopilotProvider) Complete

func (*CopilotProvider) Name

func (p *CopilotProvider) Name() string

type DiffCompactStats added in v0.0.13

type DiffCompactStats struct {
	OriginalBytes int
	CompactBytes  int
	FileCount     int
	KeptFiles     int
	SkippedFiles  int
	Truncated     bool
}

DiffCompactStats describes how a diff was reduced for AI prompts.

func CompactDiffForAI added in v0.0.13

func CompactDiffForAI(diff string) (string, DiffCompactStats)

CompactDiffForAI shrinks a git diff so commit/review prompts stay within model limits. It keeps a file list summary and truncated hunks, skipping lockfiles and binary patches.

type OpenAIProvider

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

OpenAIProvider implements Provider using an OpenAI-compatible API.

func NewOpenAI

func NewOpenAI(client *utils.OpenaiClient) *OpenAIProvider

NewOpenAI wraps an existing OpenaiClient.

func OpenAIProviderFromConfig

func OpenAIProviderFromConfig() *OpenAIProvider

OpenAIProviderFromConfig loads OpenAI settings from the fastgit config file and env.

func (*OpenAIProvider) Available

func (p *OpenAIProvider) Available() bool

func (*OpenAIProvider) Complete

func (*OpenAIProvider) Name

func (p *OpenAIProvider) Name() string

type Provider

type Provider interface {
	Name() string
	Available() bool
	Complete(ctx context.Context, req CompleteRequest) (CompleteResponse, error)
}

Provider is the unified AI completion interface for fastgit commands.

func Default

func Default(client *utils.OpenaiClient) Provider

Default builds the standard provider chain: OpenAI-compatible API, then rule fallback.

func ResolveProvider

func ResolveProvider(name, workingDir string) Provider

ResolveProvider picks a provider chain by name: auto|openai|copilot.

func WithCache

func WithCache(inner Provider) Provider

WithCache wraps a provider with a local disk cache keyed by prompt hash.

type RuleFallback

type RuleFallback struct{}

RuleFallback generates deterministic text when no AI provider is available.

func NewRuleFallback

func NewRuleFallback() *RuleFallback

func (*RuleFallback) Available

func (p *RuleFallback) Available() bool

func (*RuleFallback) Complete

func (*RuleFallback) Name

func (p *RuleFallback) Name() string

type SessionCallbacks

type SessionCallbacks struct {
	Stdout    io.Writer
	OnDelta   func(text string)
	OnMessage func(text string)
}

SessionCallbacks receives Copilot session events.

Jump to

Keyboard shortcuts

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