troubleshoot

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package troubleshoot provides AI-powered error diagnosis and pattern recognition.

This package analyzes error messages using AI and known patterns to provide root cause analysis and remediation suggestions. Patterns are stored in a shared database for team-wide knowledge sharing.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyErrorMessage indicates error message is required
	ErrEmptyErrorMessage = errors.New("error message cannot be empty")

	// ErrInvalidConfidence indicates confidence score out of range
	ErrInvalidConfidence = errors.New("confidence must be between 0.0 and 1.0")
)

Functions

This section is empty.

Types

type AIClient

type AIClient interface {
	Generate(ctx context.Context, prompt string) (string, error)
}

AIClient defines the interface for AI text generation.

type Diagnosis

type Diagnosis struct {
	ErrorMessage    string       `json:"error_message"`
	RootCause       string       `json:"root_cause"`
	Hypotheses      []Hypothesis `json:"hypotheses"`
	Recommendations []string     `json:"recommendations"`
	RelatedPatterns []Pattern    `json:"related_patterns"`
	Confidence      float64      `json:"confidence"`
}

Diagnosis represents AI-powered error analysis.

type Hypothesis

type Hypothesis struct {
	Description string  `json:"description"`
	Likelihood  float64 `json:"likelihood"`
	Evidence    string  `json:"evidence"`
}

Hypothesis represents a possible cause of the error.

func (*Hypothesis) Validate

func (h *Hypothesis) Validate() error

Validate validates a hypothesis.

type Pattern

type Pattern struct {
	ID          string    `json:"id"`
	ErrorType   string    `json:"error_type"`
	Description string    `json:"description"`
	Solution    string    `json:"solution"`
	Frequency   int       `json:"frequency"`
	Confidence  float64   `json:"confidence"`
	CreatedAt   time.Time `json:"created_at"`
}

Pattern represents a known error pattern with solution.

func (*Pattern) Validate

func (p *Pattern) Validate() error

Validate validates a pattern.

type Service

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

Service provides AI-powered error diagnosis.

func NewService

func NewService(store VectorStore, logger *zap.Logger, aiClient AIClient) (*Service, error)

NewService creates a new troubleshoot service.

The service uses vector storage for pattern matching and an optional AI client for hypothesis generation. If aiClient is nil, the service will only use pattern-based diagnosis.

func (*Service) Diagnose

func (s *Service) Diagnose(ctx context.Context, errorMsg, errorContext string) (*Diagnosis, error)

Diagnose analyzes an error message and provides diagnosis.

The diagnosis process: 1. Search known patterns for similar errors 2. If high-confidence match (>0.8) found, return pattern-based diagnosis 3. Otherwise, query AI for hypothesis generation 4. Combine pattern matches with AI hypotheses 5. Generate recommendations

func (*Service) GetPatterns

func (s *Service) GetPatterns(ctx context.Context) ([]Pattern, error)

GetPatterns retrieves all known error patterns.

Patterns are sorted by frequency (most common first) and returned with their metadata.

func (*Service) SavePattern

func (s *Service) SavePattern(ctx context.Context, pattern *Pattern) error

SavePattern stores an error pattern for future matching.

Patterns are stored in the shared database with embeddings for semantic search. The pattern is validated before storage.

type VectorStore

type VectorStore interface {
	AddDocuments(ctx context.Context, docs []vectorstore.Document) error
	SearchWithFilters(ctx context.Context, query string, k int, filters map[string]interface{}) ([]vectorstore.SearchResult, error)
}

VectorStore defines the interface for vector database operations.

Jump to

Keyboard shortcuts

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