core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultContextLimitBytes = 2 * 1024 * 1024
View Source
const DefaultContextPackBudgetBytes = 12 * 1024
View Source
const DefaultMaxIndexFileBytes int64 = 1024 * 1024
View Source
const DefaultMaxKnowledgeContentBytes = 64 * 1024
View Source
const DefaultProjectConfigTOML = `` /* 421-byte string literal not displayed */
View Source
const MaxContextPackBudgetBytes = 200 * 1024
View Source
const MinContextPackBudgetBytes = 512

Variables

View Source
var DBPath string

Functions

func AddFeedback

func AddFeedback(db *sql.DB, userInput, botResponse string) (bool, error)

AddFeedback inserts a feedback record when negative sentiment is detected.

func AddKnowledge

func AddKnowledge(db *sql.DB, language, topic, content string) error

AddKnowledge inserts a new codebase template or config note into SQLite and the FTS5 index

func AddKnowledgeContent

func AddKnowledgeContent(db *sql.DB, language, topic, path string, content []byte, maxContentBytes int, sourceMTime int64) (int, error)

func AddKnowledgeEntry

func AddKnowledgeEntry(db *sql.DB, entry KnowledgeEntry) (bool, error)

func CalculateQND

func CalculateQND(comp Compressor, prompt string, content string) float64

CalculateQND computes the Query-Normalized Compression Distance between a prompt and document content

func CalculateQNDWithPromptSize

func CalculateQNDWithPromptSize(comp Compressor, prompt string, content string, promptCompressedSize int) float64

func CanCheckCompilation

func CanCheckCompilation(filename string) bool

func CheckCompilation

func CheckCompilation(code string, filename string) (bool, bool)

func DBFilePath

func DBFilePath(dir string) string

func DetectLanguage

func DetectLanguage(prompt string) string

DetectLanguage parses terms in a query to find the target programming language

func DetectNegativeFeedback

func DetectNegativeFeedback(input string) string

func ExpandQueryForPackMode

func ExpandQueryForPackMode(query, mode string) string

func IndexDirectory

func IndexDirectory(db *sql.DB, root string, filter LanguageFilter) (int, error)

func IndexDirectoryWithOptions

func IndexDirectoryWithOptions(db *sql.DB, root string, filter LanguageFilter, options IndexOptions) (int, error)

func IndexFileWithOptions

func IndexFileWithOptions(db *sql.DB, root, path string, filter LanguageFilter, options IndexOptions) (int, error)

func IndexFilesWithOptions

func IndexFilesWithOptions(db *sql.DB, root string, paths []string, filter LanguageFilter, options IndexOptions) (int, error)

func InitDB

func InitDB(dir string) (*sql.DB, error)

InitDB sets up the main SQLite database and virtual FTS5 index tables

func LanguageFromPath

func LanguageFromPath(path string) string

func LoadSnapZipIgnore

func LoadSnapZipIgnore(root string) ([]string, error)

func NormalizeLanguage

func NormalizeLanguage(value string) string

func ProjectConfigPath

func ProjectConfigPath(root string) string

func RenderContextPack

func RenderContextPack(pack ContextPack) string

func RenderDependencyGraph

func RenderDependencyGraph(graph DependencyGraph) string

func RenderImportContext

func RenderImportContext(context ImportContext) string

func RenderRepoMap

func RenderRepoMap(repoMap RepoMap) string

func RenderSearchResult

func RenderSearchResult(result SearchResult) string

func RenderSymbolContext

func RenderSymbolContext(context SymbolContext) string

func ReplaceImportsForFile

func ReplaceImportsForFile(db *sql.DB, language, path string, content []byte) error

func ReplaceSymbolReferencesForFile

func ReplaceSymbolReferencesForFile(db *sql.DB, language, path string, content []byte) error

func ReplaceSymbolsForFile

func ReplaceSymbolsForFile(db *sql.DB, language, path string, content []byte) error

func ResetDB

func ResetDB(dir string) error

func ResolveImportTargets

func ResolveImportTargets(db *sql.DB) error

func VerifyCompilation

func VerifyCompilation(code string, filename string) bool

VerifyCompilation runs the compiler/linter check on a temporary file

func WriteDefaultProjectConfig

func WriteDefaultProjectConfig(root string, force bool) (string, bool, error)

Types

type AffectedFile

type AffectedFile struct {
	Path       string   `json:"path"`
	Language   string   `json:"language,omitempty"`
	Confidence float64  `json:"confidence"`
	Reasons    []string `json:"reasons"`
}

type AffectedReport

type AffectedReport struct {
	InputPaths []string       `json:"input_paths"`
	Tests      []AffectedFile `json:"tests"`
	Related    []AffectedFile `json:"related,omitempty"`
}

func FindAffectedTests

func FindAffectedTests(db *sql.DB, paths []string, limit int) (AffectedReport, error)

type BCAConfig

type BCAConfig struct {
	MaxIterations int     `json:"max_iterations"`
	Temperature   float64 `json:"temperature"`
	PriorWeight   float64 `json:"prior_weight"`
}

type BCAOptimizer

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

BCAOptimizer implements the Bayesian Compression Agent optimization loop

func NewBCAOptimizer

func NewBCAOptimizer(cfg BCAConfig, dictBytes []byte, vocab []string) (*BCAOptimizer, error)

func (*BCAOptimizer) CompressDraft

func (o *BCAOptimizer) CompressDraft(draft []byte) int

CompressDraft calculates compressed size C(X | Y) using the pre-primed dictionary

func (*BCAOptimizer) Mutate

func (o *BCAOptimizer) Mutate(draft []byte, r *rand.Rand) []byte

Mutate proposes a conservative code transition X -> X' by replacing one identifier with an identifier observed in local context.

func (*BCAOptimizer) Optimize

func (o *BCAOptimizer) Optimize(seedCode string, filename string) string

Optimize runs the Metropolis-Hastings MCMC sampling loop

func (*BCAOptimizer) PriorScore

func (o *BCAOptimizer) PriorScore(draft []byte) float64

PriorScore evaluates the syntax/grammar penalty score of a draft. Lower score is better (representing fewer syntactic violations).

type Compressor

type Compressor interface {
	Compress(data []byte) int
	Name() string
}

type ContextBundle

type ContextBundle struct {
	Data       []byte
	Vocabulary []string
	FileCount  int
}

func LoadContextDirectory

func LoadContextDirectory(root string, filter LanguageFilter, maxBytes int) (ContextBundle, error)

type ContextPack

type ContextPack struct {
	Query         string           `json:"query"`
	ExpandedQuery string           `json:"expanded_query,omitempty"`
	Mode          string           `json:"mode,omitempty"`
	BudgetBytes   int              `json:"budget_bytes"`
	UsedBytes     int              `json:"used_bytes"`
	Truncated     bool             `json:"truncated"`
	Quality       ContextQuality   `json:"quality"`
	Snippets      []Snippet        `json:"snippets"`
	Receipts      []ContextReceipt `json:"receipts,omitempty"`
	Feedback      []Feedback       `json:"feedback,omitempty"`
}

func BuildContextPack

func BuildContextPack(db *sql.DB, comp Compressor, query string, limit int, budgetBytes int, feedbackLimit int) (ContextPack, error)

func BuildContextPackWithMode

func BuildContextPackWithMode(db *sql.DB, comp Compressor, query, mode string, limit int, budgetBytes int, feedbackLimit int) (ContextPack, error)

func BuildRepairContextPack

func BuildRepairContextPack(db *sql.DB, comp Compressor, failureOutput, extraQuery, mode string, limit int, budgetBytes int, feedbackLimit int) (ContextPack, error)

type ContextQuality

type ContextQuality struct {
	Score     float64               `json:"score"`
	Grade     string                `json:"grade"`
	Summary   string                `json:"summary"`
	Metrics   ContextQualityMetrics `json:"metrics"`
	Strengths []string              `json:"strengths,omitempty"`
	Warnings  []string              `json:"warnings,omitempty"`
}

func ScoreContextPack

func ScoreContextPack(pack ContextPack) ContextQuality

type ContextQualityMetrics

type ContextQualityMetrics struct {
	SnippetCount           int     `json:"snippet_count"`
	SourceSnippetCount     int     `json:"source_snippet_count"`
	TestSnippetCount       int     `json:"test_snippet_count"`
	DependencySnippetCount int     `json:"dependency_snippet_count"`
	DefinitionCount        int     `json:"definition_count"`
	ReferenceCount         int     `json:"reference_count"`
	ReceiptCount           int     `json:"receipt_count"`
	ReceiptCoverage        float64 `json:"receipt_coverage"`
	EvidenceCount          int     `json:"evidence_count"`
	EvidenceDensity        float64 `json:"evidence_density"`
	UniquePathCount        int     `json:"unique_path_count"`
	UniquePathRatio        float64 `json:"unique_path_ratio"`
	DuplicatePathCount     int     `json:"duplicate_path_count"`
	FeedbackCount          int     `json:"feedback_count"`
	BudgetUtilization      float64 `json:"budget_utilization"`
	Truncated              bool    `json:"truncated"`
}

type ContextReceipt

type ContextReceipt struct {
	Rank       int      `json:"rank"`
	Path       string   `json:"path,omitempty"`
	StartLine  int      `json:"start_line,omitempty"`
	EndLine    int      `json:"end_line,omitempty"`
	Topic      string   `json:"topic,omitempty"`
	Language   string   `json:"language,omitempty"`
	Score      float64  `json:"score"`
	Confidence float64  `json:"confidence"`
	Reasons    []string `json:"reasons"`
	Evidence   []string `json:"evidence,omitempty"`
}

type DatabaseStats

type DatabaseStats struct {
	KnowledgeRows       int            `json:"knowledge_rows"`
	FeedbackRows        int            `json:"feedback_rows"`
	SymbolRows          int            `json:"symbol_rows"`
	SymbolReferenceRows int            `json:"symbol_reference_rows"`
	ImportRows          int            `json:"import_rows"`
	Languages           []LanguageStat `json:"languages"`
}

func GetDatabaseStats

func GetDatabaseStats(db *sql.DB) (DatabaseStats, error)

type DependencyGraph

type DependencyGraph struct {
	Path       string            `json:"path"`
	Language   string            `json:"language,omitempty"`
	Imports    []ImportReference `json:"imports,omitempty"`
	ImportedBy []ImportReference `json:"imported_by,omitempty"`
}

func BuildDependencyGraph

func BuildDependencyGraph(db *sql.DB, path string, limit int) (DependencyGraph, error)

type FailureAnalysis

type FailureAnalysis struct {
	Query       string           `json:"query"`
	FileRefs    []FailureFileRef `json:"file_refs,omitempty"`
	Symbols     []string         `json:"symbols,omitempty"`
	Identifiers []string         `json:"identifiers,omitempty"`
}

func AnalyzeFailureOutput

func AnalyzeFailureOutput(output, extra string) FailureAnalysis

type FailureFileRef

type FailureFileRef struct {
	Path     string `json:"path"`
	Line     int    `json:"line,omitempty"`
	Function string `json:"function,omitempty"`
}

type Feedback

type Feedback struct {
	ID          int    `json:"id"`
	Sentiment   string `json:"sentiment"`
	UserInput   string `json:"user_input"`
	BotResponse string `json:"bot_response"`
	CreatedAt   string `json:"created_at"`
}

Feedback represents a logged negative feedback entry.

func RetrieveNegativeFeedback

func RetrieveNegativeFeedback(db *sql.DB, limit int) ([]Feedback, error)

RetrieveNegativeFeedback returns recent negative feedback entries to guide the AI.

type ImportContext

type ImportContext struct {
	Query   string            `json:"query"`
	Imports []ImportReference `json:"imports"`
}

func BuildImportContext

func BuildImportContext(db *sql.DB, query string, limit int) (ImportContext, error)

type ImportReference

type ImportReference struct {
	ID         int    `json:"id,omitempty"`
	ImportPath string `json:"import_path"`
	Alias      string `json:"alias,omitempty"`
	Language   string `json:"language"`
	Path       string `json:"path"`
	TargetPath string `json:"target_path,omitempty"`
	Line       int    `json:"line"`
	Context    string `json:"context,omitempty"`
}

func ExtractImports

func ExtractImports(language, path, content string) []ImportReference

func SearchImports

func SearchImports(db *sql.DB, query string, limit int) ([]ImportReference, error)

type IndexOptions

type IndexOptions struct {
	MaxFileBytes    int64
	MaxContentBytes int
	SkipDirs        map[string]bool
	SkipFiles       map[string]bool
	IgnorePatterns  []string
}

func DefaultIndexOptions

func DefaultIndexOptions() IndexOptions

type KnowledgeEntry

type KnowledgeEntry struct {
	Language    string
	Topic       string
	Path        string
	StartLine   int
	EndLine     int
	Content     string
	ContentHash string
	SourceMTime int64
}

type LanguageFilter

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

func NewLanguageFilter

func NewLanguageFilter(input string) LanguageFilter

func (LanguageFilter) Description

func (f LanguageFilter) Description() string

func (LanguageFilter) Matches

func (f LanguageFilter) Matches(language string) bool

type LanguageStat

type LanguageStat struct {
	Language string `json:"language"`
	Count    int    `json:"count"`
}

type ProjectConfig

type ProjectConfig struct {
	Path       string                  `json:"path,omitempty"`
	Found      bool                    `json:"found"`
	Validation ProjectValidationConfig `json:"validation,omitempty"`
}

func LoadProjectConfig

func LoadProjectConfig(root string) (ProjectConfig, error)

func ParseProjectConfig

func ParseProjectConfig(content string) (ProjectConfig, error)

type ProjectValidationConfig

type ProjectValidationConfig struct {
	Command  string            `json:"command,omitempty"`
	Commands map[string]string `json:"commands,omitempty"`
}

type RepoMap

type RepoMap struct {
	Files []RepoMapFile `json:"files"`
}

func BuildRepoMap

func BuildRepoMap(db *sql.DB, limit int) (RepoMap, error)

type RepoMapFile

type RepoMapFile struct {
	Path     string   `json:"path"`
	Language string   `json:"language"`
	Symbols  []Symbol `json:"symbols,omitempty"`
}

func RelatedFiles

func RelatedFiles(db *sql.DB, path string, limit int) ([]RepoMapFile, error)

type SearchResult

type SearchResult struct {
	Query         string           `json:"query"`
	ExpandedQuery string           `json:"expanded_query,omitempty"`
	Mode          string           `json:"mode,omitempty"`
	Snippets      []Snippet        `json:"snippets"`
	Receipts      []ContextReceipt `json:"receipts,omitempty"`
	Feedback      []Feedback       `json:"feedback,omitempty"`
}

func SearchMemory

func SearchMemory(db *sql.DB, comp Compressor, query string, limit int, feedbackLimit int) (SearchResult, error)

func SearchMemoryWithMode

func SearchMemoryWithMode(db *sql.DB, comp Compressor, query, mode string, limit int, feedbackLimit int) (SearchResult, error)

type Snippet

type Snippet struct {
	ID          int     `json:"id"`
	Language    string  `json:"language"`
	Topic       string  `json:"topic"`
	Path        string  `json:"path,omitempty"`
	StartLine   int     `json:"start_line,omitempty"`
	EndLine     int     `json:"end_line,omitempty"`
	Content     string  `json:"content"`
	ContentHash string  `json:"content_hash,omitempty"`
	SourceMTime int64   `json:"source_mtime,omitempty"`
	Score       float64 `json:"score"`
}

func RetrieveSimilarSnippets

func RetrieveSimilarSnippets(db *sql.DB, comp Compressor, prompt string, limit int) ([]Snippet, error)

RetrieveSimilarSnippets executes FTS5 full-text lookup and then parallel compression-aware re-ranking.

type SuggestedValidationCommand

type SuggestedValidationCommand struct {
	Command    string  `json:"command"`
	Reason     string  `json:"reason"`
	Confidence float64 `json:"confidence"`
}

func ConfiguredValidationCommands

func ConfiguredValidationCommands(config ProjectConfig, report AffectedReport) []SuggestedValidationCommand

func MergeValidationCommands

func MergeValidationCommands(groups ...[]SuggestedValidationCommand) []SuggestedValidationCommand

func SuggestValidationCommands

func SuggestValidationCommands(report AffectedReport) []SuggestedValidationCommand

type Symbol

type Symbol struct {
	ID        int    `json:"id,omitempty"`
	Name      string `json:"name"`
	Kind      string `json:"kind"`
	Signature string `json:"signature"`
	Language  string `json:"language"`
	Path      string `json:"path"`
	Line      int    `json:"line"`
}

func ExtractSymbols

func ExtractSymbols(language, path, content string) []Symbol

func SearchSymbols

func SearchSymbols(db *sql.DB, query string, limit int) ([]Symbol, error)

type SymbolContext

type SymbolContext struct {
	Query       string            `json:"query"`
	Definitions []Symbol          `json:"definitions"`
	References  []SymbolReference `json:"references"`
}

func BuildSymbolContext

func BuildSymbolContext(db *sql.DB, query string, limit int) (SymbolContext, error)

type SymbolReference

type SymbolReference struct {
	ID       int    `json:"id,omitempty"`
	Name     string `json:"name"`
	Language string `json:"language"`
	Path     string `json:"path"`
	Line     int    `json:"line"`
	Context  string `json:"context,omitempty"`
}

func ExtractSymbolReferences

func ExtractSymbolReferences(language, path, content string) []SymbolReference

func SearchSymbolReferences

func SearchSymbolReferences(db *sql.DB, query string, limit int) ([]SymbolReference, error)

type ValidationPlan

type ValidationPlan struct {
	InputPaths        []string                     `json:"input_paths"`
	Affected          AffectedReport               `json:"affected"`
	SuggestedCommands []SuggestedValidationCommand `json:"suggested_commands,omitempty"`
}

func BuildValidationPlan

func BuildValidationPlan(db *sql.DB, paths []string, limit int) (ValidationPlan, error)

type ZlibCompressor

type ZlibCompressor struct{}

ZlibCompressor wraps the standard zlib library using a recycled pool of writers

func (ZlibCompressor) Compress

func (zc ZlibCompressor) Compress(data []byte) int

func (ZlibCompressor) Name

func (zc ZlibCompressor) Name() string

type ZstdCompressor

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

ZstdCompressor wraps a Klauspost Zstd encoder for high-performance, allocation-free compression

func NewZstdCompressor

func NewZstdCompressor(level zstd.EncoderLevel) (*ZstdCompressor, error)

func (*ZstdCompressor) Compress

func (zc *ZstdCompressor) Compress(data []byte) int

func (*ZstdCompressor) Name

func (zc *ZstdCompressor) Name() string

Jump to

Keyboard shortcuts

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