remediation

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package remediation provides error fix pattern storage and retrieval with semantic search.

The package stores structured remediations (error patterns and their solutions) with confidence scoring and multi-tenant isolation. Remediations are searchable by semantic similarity, enabling AI agents to learn from past error resolutions.

Security

The package implements defense-in-depth security:

  • Multi-tenant isolation via scoped collections (org, team, project)
  • Tenant ID validation and enforcement
  • Confidence scoring to surface high-quality fixes
  • Feedback-based confidence adjustment
  • Support for both legacy single-store and StoreProvider isolation modes

Usage

Basic remediation recording and search:

svc := remediation.NewService(cfg, store, logger)

// Record a new fix pattern
rem, err := svc.Record(ctx, &remediation.RecordRequest{
    Title:       "Fix nil pointer in auth handler",
    Problem:     "Panic when user session is nil",
    Symptoms:    []string{"runtime panic", "nil pointer dereference"},
    RootCause:   "Missing session validation before access",
    Solution:    "Add nil check before accessing session fields",
    Category:    remediation.ErrorRuntime,
    Scope:       remediation.ScopeProject,
    TenantID:    "org-123",
    ProjectPath: "/path/to/project",
})

// Search for similar errors
results, err := svc.Search(ctx, &remediation.SearchRequest{
    Query:         "panic nil pointer session",
    Limit:         5,
    MinConfidence: 0.6,
    TenantID:      "org-123",
    Scope:         remediation.ScopeProject,
    ProjectPath:   "/path/to/project",
})

// Provide feedback to adjust confidence
err = svc.Feedback(ctx, &remediation.FeedbackRequest{
    RemediationID: rem.ID,
    TenantID:      "org-123",
    Rating:        remediation.RatingHelpful,
})

Scoping

Remediations support three scope levels:

  • ScopeOrg: Visible across entire organization
  • ScopeTeam: Visible to specific team
  • ScopeProject: Visible to specific project

Hierarchical search (IncludeHierarchy=true) searches parent scopes:

  • Project scope searches: project → team → org
  • Team scope searches: team → org
  • Org scope searches: org only

Confidence Scoring

Remediations start with default confidence (0.5) and are adjusted via feedback:

  • RatingHelpful: +0.1 confidence
  • RatingNotHelpful: -0.1 confidence
  • RatingOutdated: -0.2 confidence

Confidence is clamped to [0.1, 1.0] range. Use MinConfidence in search to filter low-quality remediations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// CollectionPrefix is the prefix for remediation collections (default: remediations)
	CollectionPrefix string

	// VectorSize is the dimension of embedding vectors (default: 1536)
	VectorSize uint64

	// DefaultConfidence is the initial confidence for new remediations (default: 0.5)
	DefaultConfidence float64

	// FeedbackDelta is how much feedback changes confidence (default: 0.1)
	FeedbackDelta float64

	// MinConfidence is the minimum confidence threshold (default: 0.1)
	MinConfidence float64

	// MaxConfidence is the maximum confidence (default: 1.0)
	MaxConfidence float64
}

Config configures the remediation service.

func DefaultServiceConfig

func DefaultServiceConfig() *Config

DefaultServiceConfig returns sensible defaults.

type ErrorCategory

type ErrorCategory string

ErrorCategory represents the category of error.

const (
	// ErrorCompile represents compile-time errors.
	ErrorCompile ErrorCategory = "compile"
	// ErrorRuntime represents runtime errors.
	ErrorRuntime ErrorCategory = "runtime"
	// ErrorTest represents test failures.
	ErrorTest ErrorCategory = "test"
	// ErrorLint represents linter errors.
	ErrorLint ErrorCategory = "lint"
	// ErrorSecurity represents security vulnerabilities.
	ErrorSecurity ErrorCategory = "security"
	// ErrorPerformance represents performance issues.
	ErrorPerformance ErrorCategory = "performance"
	// ErrorOther represents other errors.
	ErrorOther ErrorCategory = "other"
)

type FeedbackRating

type FeedbackRating string

FeedbackRating represents a feedback rating.

const (
	// RatingHelpful indicates the remediation was helpful.
	RatingHelpful FeedbackRating = "helpful"
	// RatingNotHelpful indicates the remediation was not helpful.
	RatingNotHelpful FeedbackRating = "not_helpful"
	// RatingOutdated indicates the remediation is outdated.
	RatingOutdated FeedbackRating = "outdated"
)

type FeedbackRequest

type FeedbackRequest struct {
	RemediationID string
	TenantID      string
	Rating        FeedbackRating
	SessionID     string
	Comment       string
}

FeedbackRequest represents parameters for providing feedback on a remediation.

type RecordRequest

type RecordRequest struct {
	Title         string
	Problem       string
	Symptoms      []string
	RootCause     string
	Solution      string
	CodeDiff      string
	AffectedFiles []string
	Category      ErrorCategory
	Tags          []string
	Scope         Scope
	TenantID      string
	TeamID        string
	ProjectPath   string
	SessionID     string
	Confidence    float64 // Initial confidence (default: 0.5)
}

RecordRequest represents parameters for recording a remediation.

type Remediation

type Remediation struct {
	// ID is the unique identifier for this remediation.
	ID string `json:"id"`

	// Title is a short title for the remediation.
	Title string `json:"title"`

	// Problem is a description of the error or issue.
	Problem string `json:"problem"`

	// Symptoms are observable symptoms of this error.
	Symptoms []string `json:"symptoms"`

	// RootCause is the underlying cause of the error.
	RootCause string `json:"root_cause"`

	// Solution is the fix that resolved the error.
	Solution string `json:"solution"`

	// CodeDiff is an optional code diff showing the fix.
	CodeDiff string `json:"code_diff,omitempty"`

	// AffectedFiles are files that were changed.
	AffectedFiles []string `json:"affected_files,omitempty"`

	// Category is the error category.
	Category ErrorCategory `json:"category"`

	// Confidence is the current confidence score (0.0 - 1.0).
	Confidence float64 `json:"confidence"`

	// UsageCount is how many times this remediation has been retrieved.
	UsageCount int64 `json:"usage_count"`

	// Tags are labels for categorization and filtering.
	Tags []string `json:"tags"`

	// Scope determines visibility (project, team, org).
	Scope Scope `json:"scope"`

	// TenantID is the organization this remediation belongs to.
	TenantID string `json:"tenant_id"`

	// TeamID is the team this remediation belongs to (for team scope).
	TeamID string `json:"team_id,omitempty"`

	// ProjectPath is the project this remediation belongs to (for project scope).
	ProjectPath string `json:"project_path,omitempty"`

	// SessionID is the session this remediation was extracted from.
	SessionID string `json:"session_id,omitempty"`

	// CreatedAt is when this remediation was created.
	CreatedAt time.Time `json:"created_at"`

	// UpdatedAt is when this remediation was last updated.
	UpdatedAt time.Time `json:"updated_at"`

	// Vector is the embedding vector for semantic search.
	Vector []float32 `json:"-"`
}

Remediation represents a stored error fix pattern.

type Scope

type Scope string

Scope represents the scope of a remediation.

const (
	// ScopeProject is project-level scope.
	ScopeProject Scope = "project"
	// ScopeTeam is team-level scope.
	ScopeTeam Scope = "team"
	// ScopeOrg is organization-level scope.
	ScopeOrg Scope = "org"
)

type ScoredRemediation

type ScoredRemediation struct {
	Remediation
	Score float64 `json:"score"`
}

ScoredRemediation is a remediation with a similarity score.

type SearchRequest

type SearchRequest struct {
	// Query is the error message or description to search for.
	Query string

	// Vector is an optional pre-computed embedding vector.
	Vector []float32

	// Limit is the maximum number of results to return.
	Limit int

	// MinConfidence is the minimum confidence threshold.
	MinConfidence float64

	// Category filters by error category (optional).
	Category ErrorCategory

	// Scope filters by scope (optional, searches all if empty).
	Scope Scope

	// TenantID is required for multi-tenant isolation.
	TenantID string

	// TeamID filters to a specific team (optional).
	TeamID string

	// ProjectPath filters to a specific project (optional).
	ProjectPath string

	// Tags filters by tags (optional, any match).
	Tags []string

	// IncludeHierarchy includes parent scopes in search.
	// If searching project scope, also searches team and org.
	IncludeHierarchy bool
}

SearchRequest represents parameters for remediation search.

type Service

type Service interface {
	// Search finds remediations by semantic similarity to error message/pattern.
	Search(ctx context.Context, req *SearchRequest) ([]*ScoredRemediation, error)

	// Record creates a new remediation.
	Record(ctx context.Context, req *RecordRequest) (*Remediation, error)

	// Get retrieves a remediation by ID.
	Get(ctx context.Context, tenantID, remediationID string) (*Remediation, error)

	// Feedback records feedback on a remediation, adjusting confidence.
	Feedback(ctx context.Context, req *FeedbackRequest) error

	// Delete removes a remediation.
	Delete(ctx context.Context, tenantID, remediationID string) error

	// Close closes the service.
	Close() error
}

Service provides remediation management operations.

func NewService

func NewService(cfg *Config, store vectorstore.Store, logger *zap.Logger) (Service, error)

NewService creates a new remediation service.

func NewServiceWithStoreProvider added in v0.3.0

func NewServiceWithStoreProvider(cfg *Config, stores vectorstore.StoreProvider, logger *zap.Logger) (Service, error)

NewServiceWithStoreProvider creates a remediation service using StoreProvider for database-per-scope isolation.

With StoreProvider, each scope level (org, team, project) gets its own chromem.DB instance at a unique filesystem path, providing physical isolation.

The collection naming within each store is simplified to just "remediations" since isolation is handled at the store/directory level.

Jump to

Keyboard shortcuts

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