Documentation
¶
Overview ¶
*
- Copyright © 2025 Magdiel Campelo <github.com/MagdielCAS/magi-cli>
- This file is part of the magi-cli *
*
- Copyright © 2025 Magdiel Campelo <github.com/MagdielCAS/magi-cli>
- This file is part of the magi-cli
*
Package llm centralizes AI service construction for magi commands. The service builder enforces shared defaults (timeouts, provider selection, base URL overrides, and hardened HTTP clients) that are consumed by cmd/commit.go, cmd/pr.go, and future commands that need to talk to LLMs.
*
- Copyright © 2025 Magdiel Campelo <github.com/MagdielCAS/magi-cli>
- This file is part of the magi-cli *
*
- Copyright © 2025 Magdiel Campelo <github.com/MagdielCAS/magi-cli>
- This file is part of the magi-cli *
*
- Copyright © 2025 Magdiel Campelo <github.com/MagdielCAS/magi-cli>
- This file is part of the magi-cli *
*
- Copyright © 2025 Magdiel Campelo <github.com/MagdielCAS/magi-cli>
- This file is part of the magi-cli *
*
- Copyright © 2025 Magdiel Campelo <github.com/MagdielCAS/magi-cli>
- This file is part of the magi-cli *
*
- Copyright © 2025 Magdiel Campelo <github.com/MagdielCAS/magi-cli>
- This file is part of the magi-cli *
*
- Copyright © 2025 Magdiel Campelo <github.com/MagdielCAS/magi-cli>
- This file is part of the magi-cli
*
Index ¶
- Constants
- Variables
- func FixCommitMessage(ctx context.Context, runtime *shared.RuntimeContext, ...) (string, error)
- func GenerateCommitMessage(ctx context.Context, runtime *shared.RuntimeContext, diff string) (string, error)
- func RegisterCapability(c Capability)
- func RegisterProvider(name string, p IntelligenceProvider)
- type Agent
- type Capability
- type CapabilityContext
- type ChatCompletionRequest
- type ChatMessage
- type ClaudeCodeProvider
- type CompletionRequest
- type CopilotCLIProvider
- type ExecutionOptions
- type ExecutionRequest
- type ExecutionResponse
- type FixCommitMessageCapability
- type GenerateCommitMessageCapability
- type IntelligenceProvider
- type MCPAgent
- type MCPAgentConfig
- type MCPClient
- type MCPError
- type MCPRequest
- type MCPResponse
- type MCPTool
- type ModelVariant
- type OpenAIProvider
- type Registry
- type Service
- type ServiceBuilder
- func (b *ServiceBuilder) Build() (*Service, error)
- func (b *ServiceBuilder) UseFallbackModel() *ServiceBuilder
- func (b *ServiceBuilder) UseHeavyModel() *ServiceBuilder
- func (b *ServiceBuilder) UseLightModel() *ServiceBuilder
- func (b *ServiceBuilder) WithAPIKey(key string) *ServiceBuilder
- func (b *ServiceBuilder) WithBaseURL(baseURL string) *ServiceBuilder
- func (b *ServiceBuilder) WithHTTPClient(client *http.Client) *ServiceBuilder
- func (b *ServiceBuilder) WithModel(model string) *ServiceBuilder
Constants ¶
const ( AIModelKey_HEAVY = "heavy" DefaultHeavyModel = "gpt-4" )
Variables ¶
var ( CommitSchema = &openai.ChatCompletionNewParamsResponseFormatUnion{ OfJSONSchema: &openaiShared.ResponseFormatJSONSchemaParam{ JSONSchema: openaiShared.ResponseFormatJSONSchemaJSONSchemaParam{ Name: "commit_message", Description: openai.String("A conventional commit message"), Schema: interface{}(map[string]interface{}{ "type": "object", "properties": map[string]interface{}{ "type": map[string]interface{}{"type": "string", "enum": []string{"feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert"}}, "scope": map[string]interface{}{"type": "string"}, "gitmoji": map[string]interface{}{"type": "string"}, "description": map[string]interface{}{"type": "string"}, }, "required": []string{"type", "scope", "gitmoji", "description"}, "additionalProperties": false, }), Strict: openai.Bool(true), }, }, } )
Functions ¶
func FixCommitMessage ¶
func FixCommitMessage(ctx context.Context, runtime *shared.RuntimeContext, diff, previousMessage string, validationErr error) (string, error)
FixCommitMessage reparses the diff with guidance about the validation failure and returns a corrected message.
func GenerateCommitMessage ¶
func GenerateCommitMessage(ctx context.Context, runtime *shared.RuntimeContext, diff string) (string, error)
GenerateCommitMessage requests an AI-generated conventional commit message for the supplied diff.
func RegisterCapability ¶ added in v0.9.0
func RegisterCapability(c Capability)
RegisterCapability registers a task/intent capability.
func RegisterProvider ¶ added in v0.9.0
func RegisterProvider(name string, p IntelligenceProvider)
RegisterProvider registers a static provider.
Types ¶
type Agent ¶ added in v0.6.0
type Agent struct {
Name string
Task string
Personality string
CompletionRequest CompletionRequest
Runtime *shared.RuntimeContext
}
Agent represents a generic AI agent
type Capability ¶ added in v0.9.0
type Capability interface {
Name() string
BuildPrompt(ctx CapabilityContext) (string, error)
SystemPrompt() string
}
Capability defines the interface for specific LLM tasks/intents.
func GetCapability ¶ added in v0.9.0
func GetCapability(name string) (Capability, error)
GetCapability retrieves a registered capability by name.
type CapabilityContext ¶ added in v0.9.0
type CapabilityContext struct {
Diff string
PreviousMessage string
ValidationError string
RepoRoot string
}
CapabilityContext provides the parameters needed to render prompts.
type ChatCompletionRequest ¶
type ChatCompletionRequest struct {
Messages []ChatMessage
Temperature float64
MaxTokens float64
TopP float64
FrequencyPenalty float64
PresencePenalty float64
ResponseFormat *openai.ChatCompletionNewParamsResponseFormatUnion
}
ChatCompletionRequest represents a chat completion call.
type ChatMessage ¶
ChatMessage represents a message in a chat completion request.
type ClaudeCodeProvider ¶ added in v0.9.0
type ClaudeCodeProvider struct {
// contains filtered or unexported fields
}
ClaudeCodeProvider runs local Claude Code tasks.
func NewClaudeCodeProvider ¶ added in v0.9.0
func NewClaudeCodeProvider(runtime *shared.RuntimeContext) *ClaudeCodeProvider
NewClaudeCodeProvider creates a new instance of ClaudeCodeProvider.
func (*ClaudeCodeProvider) Execute ¶ added in v0.9.0
func (p *ClaudeCodeProvider) Execute(ctx context.Context, req *ExecutionRequest) (*ExecutionResponse, error)
Execute runs the local claude binary using non-interactive print mode.
func (*ClaudeCodeProvider) Name ¶ added in v0.9.0
func (p *ClaudeCodeProvider) Name() string
Name returns the provider identifier.
type CompletionRequest ¶ added in v0.6.0
type CompletionRequest struct {
ChatCompletionRequest
ApiKey string
}
CompletionRequest wraps ChatCompletionRequest with additional fields
type CopilotCLIProvider ¶ added in v0.9.0
type CopilotCLIProvider struct {
// contains filtered or unexported fields
}
CopilotCLIProvider runs local Copilot CLI tasks.
func NewCopilotCLIProvider ¶ added in v0.9.0
func NewCopilotCLIProvider(runtime *shared.RuntimeContext) *CopilotCLIProvider
NewCopilotCLIProvider creates a new instance of CopilotCLIProvider.
func (*CopilotCLIProvider) Execute ¶ added in v0.9.0
func (p *CopilotCLIProvider) Execute(ctx context.Context, req *ExecutionRequest) (*ExecutionResponse, error)
Execute runs the local copilot binary using non-interactive mode.
func (*CopilotCLIProvider) Name ¶ added in v0.9.0
func (p *CopilotCLIProvider) Name() string
Name returns the provider identifier.
type ExecutionOptions ¶ added in v0.9.0
ExecutionOptions provides tuning parameters for the model execution.
type ExecutionRequest ¶ added in v0.9.0
type ExecutionRequest struct {
Capability string
Prompt string
Context map[string]string
Options ExecutionOptions
}
ExecutionRequest represents a standardized intent execution request.
type ExecutionResponse ¶ added in v0.9.0
ExecutionResponse standardizes output returned by any provider.
type FixCommitMessageCapability ¶ added in v0.9.0
type FixCommitMessageCapability struct{}
FixCommitMessageCapability implements Capability for repairing a rejected commit message.
func (*FixCommitMessageCapability) BuildPrompt ¶ added in v0.9.0
func (c *FixCommitMessageCapability) BuildPrompt(ctx CapabilityContext) (string, error)
func (*FixCommitMessageCapability) Name ¶ added in v0.9.0
func (c *FixCommitMessageCapability) Name() string
func (*FixCommitMessageCapability) SystemPrompt ¶ added in v0.9.0
func (c *FixCommitMessageCapability) SystemPrompt() string
type GenerateCommitMessageCapability ¶ added in v0.9.0
type GenerateCommitMessageCapability struct{}
GenerateCommitMessageCapability implements Capability for commit message generation.
func (*GenerateCommitMessageCapability) BuildPrompt ¶ added in v0.9.0
func (c *GenerateCommitMessageCapability) BuildPrompt(ctx CapabilityContext) (string, error)
func (*GenerateCommitMessageCapability) Name ¶ added in v0.9.0
func (c *GenerateCommitMessageCapability) Name() string
func (*GenerateCommitMessageCapability) SystemPrompt ¶ added in v0.9.0
func (c *GenerateCommitMessageCapability) SystemPrompt() string
type IntelligenceProvider ¶ added in v0.9.0
type IntelligenceProvider interface {
Name() string
Execute(ctx context.Context, req *ExecutionRequest) (*ExecutionResponse, error)
}
IntelligenceProvider defines the common contract for all AI runtime executors, whether they are REST APIs (like OpenAI) or command-line agents (like Copilot CLI or Claude Code).
func ResolveProvider ¶ added in v0.9.0
func ResolveProvider(runtime *shared.RuntimeContext) (IntelligenceProvider, error)
ResolveProvider dynamically resolves the active provider based on runtime context.
type MCPAgent ¶ added in v0.6.0
type MCPAgent struct {
Agent
MCPClient *MCPClient
Tools []string // Available MCP tools for this agent
}
MCPAgent represents an agent that can use MCP tools
func NewMCPAgent ¶ added in v0.6.0
func NewMCPAgent(config MCPAgentConfig, mcpClient *MCPClient, runtime *shared.RuntimeContext) *MCPAgent
NewMCPAgent creates a new MCP-enabled agent
func (*MCPAgent) AnalyzeWithMCP ¶ added in v0.6.0
AnalyzeWithMCP performs analysis using both LLM and MCP tools
type MCPAgentConfig ¶ added in v0.6.0
type MCPAgentConfig struct {
Name string
Task string
Personality string
Tools []string
MaxTokens int
UseTextFormat bool
}
MCPAgentConfig configuration for MCP-enabled agents
type MCPClient ¶ added in v0.6.0
type MCPClient struct {
ServerURL string
HTTPClient *http.Client
SessionID string
Tools map[string]MCPTool
}
MCPClient represents a Model Context Protocol client
func NewMCPClient ¶ added in v0.6.0
NewMCPClient creates a new MCP client
func (*MCPClient) CallTool ¶ added in v0.6.0
func (c *MCPClient) CallTool(toolName string, arguments map[string]interface{}) (interface{}, error)
CallTool executes a tool on the MCP server
type MCPRequest ¶ added in v0.6.0
type MCPRequest struct {
Method string `json:"method"`
Params interface{} `json:"params"`
}
MCPRequest represents a request to an MCP server
type MCPResponse ¶ added in v0.6.0
type MCPResponse struct {
Result interface{} `json:"result"`
Error *MCPError `json:"error,omitempty"`
}
MCPResponse represents a response from an MCP server
type MCPTool ¶ added in v0.6.0
type MCPTool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema map[string]interface{} `json:"inputSchema"`
}
MCPTool represents an available MCP tool
type ModelVariant ¶
type ModelVariant int
ModelVariant defines the logical model buckets (light/heavy/fallback) available to commands.
const ( ModelVariantHeavy ModelVariant = iota ModelVariantLight ModelVariantFallback )
type OpenAIProvider ¶ added in v0.9.0
type OpenAIProvider struct {
// contains filtered or unexported fields
}
OpenAIProvider executes tasks against OpenAI-compatible APIs.
func NewOpenAIProvider ¶ added in v0.9.0
func NewOpenAIProvider(runtime *shared.RuntimeContext) *OpenAIProvider
NewOpenAIProvider creates a new instance of OpenAIProvider.
func (*OpenAIProvider) Execute ¶ added in v0.9.0
func (p *OpenAIProvider) Execute(ctx context.Context, req *ExecutionRequest) (*ExecutionResponse, error)
Execute performs the chat completion and returns the response.
func (*OpenAIProvider) Name ¶ added in v0.9.0
func (p *OpenAIProvider) Name() string
Name returns the provider identifier.
type Registry ¶ added in v0.9.0
type Registry struct {
// contains filtered or unexported fields
}
Registry holds the registered capabilities and providers.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service executes LLM requests using the resolved configuration.
func (*Service) ChatCompletion ¶
ChatCompletion sends a chat completion request and returns the assistant response text.
type ServiceBuilder ¶
type ServiceBuilder struct {
// contains filtered or unexported fields
}
ServiceBuilder lets commands configure which model tier, API key, and endpoint should be used.
func NewServiceBuilder ¶
func NewServiceBuilder(runtime *shared.RuntimeContext) *ServiceBuilder
NewServiceBuilder creates a builder tied to the given runtime context.
func (*ServiceBuilder) Build ¶
func (b *ServiceBuilder) Build() (*Service, error)
Build resolves the requested configuration and returns a ready-to-use LLM service.
func (*ServiceBuilder) UseFallbackModel ¶
func (b *ServiceBuilder) UseFallbackModel() *ServiceBuilder
UseFallbackModel selects the configured fallback model tier.
func (*ServiceBuilder) UseHeavyModel ¶
func (b *ServiceBuilder) UseHeavyModel() *ServiceBuilder
UseHeavyModel selects the heavy model tier (default).
func (*ServiceBuilder) UseLightModel ¶
func (b *ServiceBuilder) UseLightModel() *ServiceBuilder
UseLightModel selects the light model tier configured in the runtime context.
func (*ServiceBuilder) WithAPIKey ¶
func (b *ServiceBuilder) WithAPIKey(key string) *ServiceBuilder
WithAPIKey overrides the API key used for the service.
func (*ServiceBuilder) WithBaseURL ¶
func (b *ServiceBuilder) WithBaseURL(baseURL string) *ServiceBuilder
WithBaseURL overrides the base URL used for the service.
func (*ServiceBuilder) WithHTTPClient ¶
func (b *ServiceBuilder) WithHTTPClient(client *http.Client) *ServiceBuilder
WithHTTPClient overrides the HTTP client (otherwise RuntimeContext HTTP client is reused).
func (*ServiceBuilder) WithModel ¶
func (b *ServiceBuilder) WithModel(model string) *ServiceBuilder
WithModel overrides the model identifier entirely.