Documentation
¶
Index ¶
- Constants
- func DefaultIndexPath(projectRoot string) string
- func DetectLanguage(filename string) string
- func DetectProjectLanguage(dir string) string
- func IsIndexableFile(filename string) bool
- func JaccardSimilarity(a, b MinHashSignature) float64
- func ShinglesForSymbol(sym Symbol, source []byte) []string
- func ShouldSkipPath(path string) bool
- type CodeSmell
- type CodeSmellKind
- type Edge
- type EdgeKind
- type FileEdge
- type FileRecord
- type FunctionEdgeInfo
- type GenericParser
- type GitignoreFilter
- type GoParser
- type Indexer
- func (idx *Indexer) Build() error
- func (idx *Indexer) Close() error
- func (idx *Indexer) FindCodeSmells(kinds []CodeSmellKind, maxResults int, includeTests bool) ([]CodeSmell, error)
- func (idx *Indexer) FindLazyRedirects(maxResults int, includeTests bool) ([]LazyRedirectResult, error)
- func (idx *Indexer) KeywordSearch(query string, limit int) ([]Symbol, error)
- func (idx *Indexer) PackageGraph() ([]PackageInfo, []PackageEdge, error)
- func (idx *Indexer) ProjectSummary() string
- func (idx *Indexer) SemanticSearch(query string, topK int) ([]SearchResult, error)
- func (idx *Indexer) Stats() (*StoreStats, error)
- func (idx *Indexer) Store() *Store
- func (idx *Indexer) Update() error
- type LazyRedirectCandidate
- type LazyRedirectResult
- type MinHashEntry
- type MinHashSignature
- type MinHasher
- type PackageEdge
- type PackageInfo
- type ParseResult
- type RawEdge
- type SearchResult
- type Store
- func (s *Store) AddEdge(sourceID, targetID int64, kind EdgeKind) error
- func (s *Store) Close() error
- func (s *Store) DeleteFile(path string) error
- func (s *Store) DeleteFileSymbols(file string) error
- func (s *Store) FindAllFunctionsWithEdges() ([]FunctionEdgeInfo, error)
- func (s *Store) FindLazyRedirectCandidates(includeTests bool) ([]LazyRedirectCandidate, error)
- func (s *Store) FindStubs(includeTests bool) ([]StubResult, error)
- func (s *Store) GetAllFiles() ([]FileRecord, error)
- func (s *Store) GetAllMinHashes() ([]MinHashEntry, error)
- func (s *Store) GetEdgesFrom(sourceID int64) ([]Edge, error)
- func (s *Store) GetEdgesTo(targetID int64) ([]Edge, error)
- func (s *Store) GetFile(path string) (*FileRecord, error)
- func (s *Store) GetFileGraph() ([]FileEdge, error)
- func (s *Store) GetMinHash(symbolID int64) (MinHashSignature, error)
- func (s *Store) GetPackageGraph() ([]PackageInfo, []PackageEdge, error)
- func (s *Store) GetSymbol(id int64) (*Symbol, error)
- func (s *Store) GetSymbolIDByName(name string) (int64, bool)
- func (s *Store) GetSymbolsByFile(file string) ([]Symbol, error)
- func (s *Store) GetSymbolsByPackage(pkg string) ([]Symbol, error)
- func (s *Store) SearchSymbolsByName(query string) ([]Symbol, error)
- func (s *Store) Stats() (*StoreStats, error)
- func (s *Store) UpdateMinHash(symbolID int64, sig MinHashSignature) error
- func (s *Store) UpsertFile(f FileRecord) error
- func (s *Store) UpsertSymbol(sym Symbol) (int64, error)
- type StoreStats
- type StubResult
- type Symbol
- type SymbolKind
Constants ¶
const DefaultNumHashes = 128
DefaultNumHashes is the number of hash functions used for MinHash signatures. 128 provides good accuracy with sub-10ms query time for 50k symbols.
Variables ¶
This section is empty.
Functions ¶
func DefaultIndexPath ¶ added in v1.8.3
DefaultIndexPath returns the path to the code graph database for a project. It stores the index under ~/.celeste/projects/<hash>/codegraph.db to avoid polluting the project directory.
func DetectLanguage ¶
DetectLanguage returns the language for a file based on its extension. Returns empty string if the language is not recognized.
func DetectProjectLanguage ¶
DetectProjectLanguage determines the primary language of a project by checking for manifest files in the given directory.
func IsIndexableFile ¶
IsIndexableFile returns true if the file's language has parser support.
func JaccardSimilarity ¶
func JaccardSimilarity(a, b MinHashSignature) float64
JaccardSimilarity estimates the Jaccard similarity between two MinHash signatures. Returns a value between 0.0 (completely different) and 1.0 (identical sets).
func ShinglesForSymbol ¶
ShinglesForSymbol generates enriched shingles for a symbol, used as input to MinHash for semantic similarity search. Each shingle is a lowercased token derived from the symbol's name, types, body references, package, and comments.
func ShouldSkipPath ¶
ShouldSkipPath returns true if the path should be excluded from indexing.
Types ¶
type CodeSmell ¶ added in v1.8.3
type CodeSmell struct {
Kind CodeSmellKind `json:"kind"`
Name string `json:"name"`
File string `json:"file"`
Line int `json:"line"`
FuncKind string `json:"func_kind"`
OutEdges int `json:"outgoing_edges"`
InEdges int `json:"incoming_edges"`
Score float64 `json:"score"`
Reason string `json:"reason"`
Signature string `json:"signature,omitempty"`
Snippet string `json:"snippet,omitempty"`
}
CodeSmell represents a structurally detected code issue.
type CodeSmellKind ¶ added in v1.8.3
type CodeSmellKind string
CodeSmellKind categorizes the type of code smell detected.
const ( SmellLazyRedirect CodeSmellKind = "LAZY_REDIRECT" SmellStub CodeSmellKind = "STUB" SmellPlaceholder CodeSmellKind = "PLACEHOLDER" SmellTodoFixme CodeSmellKind = "TODO_FIXME" SmellEmptyHandler CodeSmellKind = "EMPTY_HANDLER" SmellHardcoded CodeSmellKind = "HARDCODED" )
type FileRecord ¶
type FileRecord struct {
Path string
Language string
Size int64
ContentHash string
IndexedAt int64
}
FileRecord tracks indexed files for incremental updates.
type FunctionEdgeInfo ¶ added in v1.8.3
type FunctionEdgeInfo struct {
Name string
File string
Line int
Kind string
Signature string
OutEdges int
InEdges int
}
FunctionEdgeInfo holds a function's identity and edge counts for analysis.
type GenericParser ¶
type GenericParser struct {
// contains filtered or unexported fields
}
GenericParser extracts symbols from non-Go source files using regex patterns. Covers Python, JavaScript, TypeScript, and Rust. No call graph (would need tree-sitter / CGo). Focuses on declarations: functions, classes, imports.
func NewGenericParser ¶
func NewGenericParser(language string) *GenericParser
NewGenericParser creates a parser for the given language.
func (*GenericParser) ParseFile ¶
func (p *GenericParser) ParseFile(path string) (*ParseResult, error)
ParseFile parses a source file and extracts symbols using regex.
type GitignoreFilter ¶ added in v1.8.3
type GitignoreFilter struct {
// contains filtered or unexported fields
}
GitignoreFilter holds compiled gitignore patterns for matching.
func LoadGitignore ¶ added in v1.8.3
func LoadGitignore(projectRoot string) *GitignoreFilter
LoadGitignore reads a .gitignore file and returns a filter. Returns nil (no filter) if the file doesn't exist or can't be read.
func (*GitignoreFilter) ShouldSkip ¶ added in v1.8.3
func (f *GitignoreFilter) ShouldSkip(relPath string, isDir bool) bool
ShouldSkip returns true if the given relative path should be ignored. isDir indicates whether the path is a directory.
type GoParser ¶
type GoParser struct{}
GoParser extracts symbols and edges from Go source files using go/ast.
type Indexer ¶
type Indexer struct {
// contains filtered or unexported fields
}
Indexer manages the code graph lifecycle: build, update, and query.
func NewIndexer ¶
NewIndexer creates an indexer for the given workspace, using the specified SQLite database path.
func NewIndexerWithStore ¶ added in v1.8.3
NewIndexerWithStore creates an indexer using an existing store. This is useful for testing where the store is set up manually.
func (*Indexer) Build ¶
Build performs a full index of the workspace. Walks the file tree, parses source files, extracts symbols and edges, computes MinHash signatures, and stores everything in SQLite.
func (*Indexer) FindCodeSmells ¶ added in v1.8.3
func (idx *Indexer) FindCodeSmells(kinds []CodeSmellKind, maxResults int, includeTests bool) ([]CodeSmell, error)
FindCodeSmells performs a single-pass structural analysis over all functions in the graph, detecting multiple code smell patterns simultaneously. This is more efficient than separate queries and more powerful than grep because it combines graph structure (edges, connectivity) with body analysis.
func (*Indexer) FindLazyRedirects ¶ added in v1.8.3
func (idx *Indexer) FindLazyRedirects(maxResults int, includeTests bool) ([]LazyRedirectResult, error)
FindLazyRedirects uses structural analysis to detect functions whose names imply complex behavior but whose graph structure shows they're trivially simple. This goes beyond grep-based detection by measuring the divergence between a function's semantic vocabulary (shingles) and its actual call graph connectivity.
Scoring factors:
- Name complexity: action verbs in name suggest the function should DO work
- Edge poverty: fewer outgoing edges = less actual work done
- Shingle richness: domain-specific vocabulary in body that doesn't connect to edges
Returns results sorted by divergence score (highest = most suspicious).
func (*Indexer) KeywordSearch ¶
KeywordSearch finds symbols matching a keyword query using SQL LIKE.
func (*Indexer) PackageGraph ¶ added in v1.8.3
func (idx *Indexer) PackageGraph() ([]PackageInfo, []PackageEdge, error)
PackageGraph returns package-level connectivity for visualization.
func (*Indexer) ProjectSummary ¶
ProjectSummary returns a brief summary suitable for the system prompt.
func (*Indexer) SemanticSearch ¶
func (idx *Indexer) SemanticSearch(query string, topK int) ([]SearchResult, error)
SemanticSearch finds symbols semantically similar to the query string. The query is split into shingles, MinHashed, then compared against all symbol signatures using brute-force Jaccard similarity.
func (*Indexer) Stats ¶
func (idx *Indexer) Stats() (*StoreStats, error)
Stats returns aggregate stats for the indexed codebase.
type LazyRedirectCandidate ¶ added in v1.8.3
type LazyRedirectCandidate struct {
Name string
File string
Line int
Kind string
OutEdges int
InEdges int
Signature string
}
LazyRedirectCandidate represents a function whose name implies complex behavior but whose graph structure shows it's structurally trivial — a potential lazy redirect.
type LazyRedirectResult ¶ added in v1.8.3
type LazyRedirectResult struct {
Name string `json:"name"`
File string `json:"file"`
Line int `json:"line"`
Kind string `json:"kind"`
OutEdges int `json:"outgoing_edges"`
InEdges int `json:"incoming_edges"`
Score float64 `json:"divergence_score"`
Reason string `json:"reason"`
Signature string `json:"signature"`
}
LazyRedirectResult is a scored candidate for lazy redirect detection.
type MinHashEntry ¶
type MinHashEntry struct {
SymbolID int64
Signature MinHashSignature
}
MinHashEntry pairs a symbol ID with its MinHash signature for bulk queries.
type MinHashSignature ¶
type MinHashSignature []uint64
MinHashSignature is a fixed-length array of hash values for similarity search.
type MinHasher ¶
type MinHasher struct {
// contains filtered or unexported fields
}
MinHasher computes MinHash signatures for sets of shingles. Uses hash/maphash with different seeds to simulate N independent hash functions.
func NewMinHasher ¶
NewMinHasher creates a MinHasher with the specified number of hash functions.
func (*MinHasher) Signature ¶
func (m *MinHasher) Signature(shingles []string) MinHashSignature
Signature computes the MinHash signature for a set of shingles. Each element of the returned slice is the minimum hash value across all shingles for that hash function.
type PackageEdge ¶ added in v1.8.3
PackageEdge represents a connection between two packages.
type PackageInfo ¶ added in v1.8.3
PackageInfo holds package-level stats for visualization.
type ParseResult ¶
type ParseResult struct {
Symbols []Symbol
Edges []RawEdge
Source []byte // raw file content for shingle generation
}
ParseResult holds the symbols and edges extracted from a single file.
type RawEdge ¶
RawEdge is an unresolved edge that uses symbol names instead of IDs. Resolved to Edge (with IDs) when inserted into the store.
type SearchResult ¶
SearchResult pairs a symbol with its similarity score.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store manages the SQLite database for the code graph.
func NewStore ¶
NewStore opens (or creates) a SQLite database at the given path and initializes the schema.
func (*Store) DeleteFile ¶
DeleteFile removes a file record.
func (*Store) DeleteFileSymbols ¶
DeleteFileSymbols removes all symbols (and their edges) for a file.
func (*Store) FindAllFunctionsWithEdges ¶ added in v1.8.3
func (s *Store) FindAllFunctionsWithEdges() ([]FunctionEdgeInfo, error)
FindAllFunctionsWithEdges returns all functions/methods with their edge counts. Used by the unified code smell detector for single-pass analysis.
func (*Store) FindLazyRedirectCandidates ¶ added in v1.8.3
func (s *Store) FindLazyRedirectCandidates(includeTests bool) ([]LazyRedirectCandidate, error)
FindLazyRedirectCandidates returns functions/methods with low outgoing edges (0-2) that are NOT known leaf patterns (constructors, getters, interface impls). These are candidates for lazy redirect analysis via shingle/edge divergence.
func (*Store) FindStubs ¶ added in v1.8.3
func (s *Store) FindStubs(includeTests bool) ([]StubResult, error)
FindStubs returns functions/methods with zero outgoing call edges. These are likely stubs, placeholders, or dead code.
func (*Store) GetAllFiles ¶
func (s *Store) GetAllFiles() ([]FileRecord, error)
GetAllFiles returns all indexed file records.
func (*Store) GetAllMinHashes ¶
func (s *Store) GetAllMinHashes() ([]MinHashEntry, error)
GetAllMinHashes retrieves all symbol IDs and their MinHash signatures for similarity search. Symbols without a signature are skipped.
func (*Store) GetEdgesFrom ¶
GetEdgesFrom returns all outgoing edges from the given symbol.
func (*Store) GetEdgesTo ¶
GetEdgesTo returns all incoming edges to the given symbol.
func (*Store) GetFile ¶
func (s *Store) GetFile(path string) (*FileRecord, error)
GetFile retrieves a file record by path.
func (*Store) GetFileGraph ¶ added in v1.8.3
GetFileGraph returns file-level connectivity data for visualization. Works for all languages — shows which files call into other files.
func (*Store) GetMinHash ¶
func (s *Store) GetMinHash(symbolID int64) (MinHashSignature, error)
GetMinHash retrieves the MinHash signature for a symbol.
func (*Store) GetPackageGraph ¶ added in v1.8.3
func (s *Store) GetPackageGraph() ([]PackageInfo, []PackageEdge, error)
GetPackageGraph returns package-level connectivity data for visualization.
func (*Store) GetSymbolIDByName ¶ added in v1.8.2
GetSymbolIDByName returns the ID of a symbol by exact name match. If multiple symbols share the same name, returns the first found.
func (*Store) GetSymbolsByFile ¶
GetSymbolsByFile returns all symbols in the given file.
func (*Store) GetSymbolsByPackage ¶
GetSymbolsByPackage returns all symbols in the given package.
func (*Store) SearchSymbolsByName ¶
SearchSymbolsByName returns symbols whose name contains the query (case-insensitive).
func (*Store) Stats ¶
func (s *Store) Stats() (*StoreStats, error)
Stats returns aggregate counts for the indexed codebase.
func (*Store) UpdateMinHash ¶
func (s *Store) UpdateMinHash(symbolID int64, sig MinHashSignature) error
UpdateMinHash stores the MinHash signature for a symbol.
func (*Store) UpsertFile ¶
func (s *Store) UpsertFile(f FileRecord) error
UpsertFile inserts or updates a file record.
type StoreStats ¶
type StoreStats struct {
TotalSymbols int
TotalEdges int
TotalFiles int
SymbolsByKind map[SymbolKind]int
FilesByLang map[string]int
}
StoreStats holds aggregate counts for the indexed codebase.
type StubResult ¶ added in v1.8.3
StubResult represents a function/method with zero outgoing call edges.
type Symbol ¶
type Symbol struct {
ID int64
Name string
Kind SymbolKind
Package string
File string
Line int
Signature string
}
Symbol represents a code entity (function, type, interface, etc.).
type SymbolKind ¶
type SymbolKind string
SymbolKind identifies the kind of code symbol.
const ( SymbolFunction SymbolKind = "function" SymbolMethod SymbolKind = "method" SymbolType SymbolKind = "type" SymbolInterface SymbolKind = "interface" SymbolConst SymbolKind = "const" SymbolVar SymbolKind = "var" SymbolStruct SymbolKind = "struct" SymbolImport SymbolKind = "import" SymbolClass SymbolKind = "class" )