Documentation
¶
Overview ¶
Package repomap generates a lightweight code structure map of a repository by scanning files and extracting top-level symbols using regex-based parsers. The result is a token-budgeted summary suitable for injection into LLM prompts.
Index ¶
- func AutoFix(opp MigrationOpportunity, content string) (string, error)
- func CacheClear()
- func CacheSize() int
- func CoChangeAnalysisMap(projectDir string) map[string][]string
- func CompareScores(before, after *HealthScore) string
- func ComputeFileHash(path string) (string, error)
- func DetectFramework(dir string) string
- func EstimateRemovableLines(items []DeadCode) int
- func ExpandQuery(query string) []string
- func ExtractSnippet(doc *Document, queryTerms []string, maxLen int) string
- func FindEntryPoints(projectDir string) []string
- func FindKeyFiles(projectDir string, limit int) []string
- func FormatAPIMap(apiMap *APIMap) string
- func FormatDeadCode(items []DeadCode) string
- func FormatDefinition(def *Definition) string
- func FormatGroups(groups []FileGroup) string
- func FormatOpportunities(opps []MigrationOpportunity) string
- func FormatReferences(symbol string, refs []*Reference) string
- func FormatResults(query string, hits []SearchHit) string
- func FormatScore(score *HealthScore) string
- func FormatSmells(smells []CodeSmell) string
- func GenerateOpenAPI(apiMap *APIMap) string
- func GenerateRemovalPlan(items []DeadCode) string
- func IncrementalReindex(dir string, ignore []string, indexer CodeIndexer) (added, skipped, removed int, err error)
- func InferArchitecture(packages []SummaryPackageInfo) string
- func InferPurpose(pkgPath string, symbols []string) string
- func IsInterfaceImpl(name string, content string) bool
- func IsTestFunction(name string) bool
- func MaintainabilityIndex(fc FunctionComplexity) float64
- func RenderCompact(summary *CodebaseSummary) string
- func RenderForPrompt(summary *CodebaseSummary, budget int) string
- func RenderTreeContext(file string, symbols []Symbol, maxLines int) string
- type APIEndpoint
- func ScanChi(content, file string) []APIEndpoint
- func ScanEcho(content, file string) []APIEndpoint
- func ScanFiber(content, file string) []APIEndpoint
- func ScanGin(content, file string) []APIEndpoint
- func ScanGorilla(content, file string) []APIEndpoint
- func ScanNetHTTP(content, file string) []APIEndpoint
- type APIMap
- type APIScanner
- type CallGraph
- type ChangeSetContext
- type CoChangeAnalysis
- type CodeChunk
- type CodeIndexer
- type CodeSearchResult
- type CodeSmell
- type CodebaseSummary
- type ComplexityAnalyzer
- func (ca *ComplexityAnalyzer) AnalyzeFile(path, content string) (*ComplexityReport, error)
- func (ca *ComplexityAnalyzer) AnalyzeGeneric(content, language string) []FunctionComplexity
- func (ca *ComplexityAnalyzer) AnalyzeGoAST(content string) []FunctionComplexity
- func (ca *ComplexityAnalyzer) FindHotspots(dir string, limit int) []FunctionComplexity
- func (ca *ComplexityAnalyzer) FormatReport(report *ComplexityReport) string
- func (ca *ComplexityAnalyzer) SuggestRefactoring(fc FunctionComplexity) []string
- type ComplexityReport
- type Contributor
- type DeadCode
- type DeadCodeDetector
- type Declaration
- type Definition
- type DepEdge
- type DepGraph
- func (dg *DepGraph) AddEdge(edge DepEdge)
- func (dg *DepGraph) AddNode(node DepNode)
- func (dg *DepGraph) BuildFromGoMod(projectDir string) error
- func (dg *DepGraph) BuildFromPackageJSON(projectDir string) error
- func (dg *DepGraph) FindCycles() [][]string
- func (dg *DepGraph) HotPaths() [][]string
- func (dg *DepGraph) Layers() [][]string
- func (dg *DepGraph) RenderASCII(maxWidth int) string
- func (dg *DepGraph) RenderDOT() string
- func (dg *DepGraph) RenderMermaid() string
- func (dg *DepGraph) Stats() GraphStats
- func (dg *DepGraph) TopologicalSort() []string
- type DepNode
- type DocIssue
- type DocLintResult
- type DocLinter
- func (dl *DocLinter) CheckGoDoc(name, comment string) []DocIssue
- func (dl *DocLinter) CoverageReport(results []*DocLintResult) string
- func (dl *DocLinter) FormatReport(results []*DocLintResult) string
- func (dl *DocLinter) LintDirectory(dir string) ([]*DocLintResult, error)
- func (dl *DocLinter) LintFile(path, content string) (*DocLintResult, error)
- func (dl *DocLinter) SuggestDocComment(name, kind, signature string) string
- type DocStats
- type Document
- type EnhancedGoParser
- type EnhancedSymbol
- type FileCache
- type FileGroup
- type FileGrouper
- func (fg *FileGrouper) AnalyzeGroups() ([]FileGroup, error)
- func (fg *FileGrouper) FindByFeature(featureName string) []string
- func (fg *FileGrouper) FindRelated(file string) []string
- func (fg *FileGrouper) FindTestPair(file string) string
- func (fg *FileGrouper) SuggestEditGroup(targetFile string) []string
- type FileMap
- type FileOwnership
- type FileSummary
- type FileWatcher
- type FunctionComplexity
- type GitignoreRules
- type GraphStats
- type HealthIssue
- type HealthScore
- type HealthScorer
- func (hs *HealthScorer) Score(projectDir string) (*HealthScore, error)
- func (hs *HealthScorer) ScoreCodeQuality(dir string) (float64, []HealthIssue)
- func (hs *HealthScorer) ScoreComplexity(dir string) (float64, []HealthIssue)
- func (hs *HealthScorer) ScoreDependencies(dir string) (float64, []HealthIssue)
- func (hs *HealthScorer) ScoreDocumentation(dir string) (float64, []HealthIssue)
- func (hs *HealthScorer) ScoreMaintainability(dir string) (float64, []HealthIssue)
- func (hs *HealthScorer) ScoreSecurity(dir string) (float64, []HealthIssue)
- func (hs *HealthScorer) ScoreTestCoverage(dir string) (float64, []HealthIssue)
- type HierarchicalSummary
- type ImportGraph
- func (g *ImportGraph) DependenciesOf(filePath string, maxDepth int) []string
- func (g *ImportGraph) DependentsOf(filePath string, maxDepth int) []string
- func (g *ImportGraph) Edges() map[string][]string
- func (g *ImportGraph) ImpactSet(files []string, maxDepth int) []string
- func (g *ImportGraph) Reverse() map[string][]string
- type IncrementalMap
- type IndexPatterns
- type InterfaceExtraction
- type MigrationDetector
- type MigrationOpportunity
- type MigrationRule
- type NavIndex
- func (idx *NavIndex) BuildIndex(projectDir string) error
- func (idx *NavIndex) FindCallees(funcName string) []string
- func (idx *NavIndex) FindCallers(funcName string) []*Reference
- func (idx *NavIndex) FindImplementations(interfaceName string) []string
- func (idx *NavIndex) FindReferences(symbol string) []*Reference
- func (idx *NavIndex) GoToDefinition(symbol string) *Definition
- func (idx *NavIndex) SearchSymbols(query string, kind string) []*Definition
- func (idx *NavIndex) TypeHierarchy(typeName string) string
- type Options
- type OwnerRule
- type OwnershipMap
- func (om *OwnershipMap) BuildFromGitHistory(projectDir string) error
- func (om *OwnershipMap) DetectBusFactorRisk() []string
- func (om *OwnershipMap) FindExpertFor(path string) string
- func (om *OwnershipMap) FormatOwnership(limit int) string
- func (om *OwnershipMap) GetOwner(path string) *FileOwnership
- func (om *OwnershipMap) GetOwnersByDirectory(dir string) map[string]string
- func (om *OwnershipMap) LoadCodeowners(path string) error
- func (om *OwnershipMap) SuggestReviewers(changedFiles []string) []string
- type PackageSummary
- type PredictedFile
- type RecentEdit
- type RecentEditTracker
- type Reference
- type RelevancePrediction
- type RepoMap
- type RerankResult
- type SearchHit
- type SemanticIndex
- type SemanticSearchIndex
- func (si *SemanticSearchIndex) BM25Score(queryTerms []string, doc *Document) float64
- func (si *SemanticSearchIndex) IndexDirectory(dir string) error
- func (si *SemanticSearchIndex) IndexFile(path, content string)
- func (si *SemanticSearchIndex) RebuildIndex() error
- func (si *SemanticSearchIndex) Search(query string, limit int) []SearchHit
- func (si *SemanticSearchIndex) SearchByIntent(intent string) []SearchHit
- type ShapleyRanker
- type ShapleyScore
- type SmellDetector
- func (sd *SmellDetector) DetectDataClump(content string) []CodeSmell
- func (sd *SmellDetector) DetectFeatureEnvy(content string) []CodeSmell
- func (sd *SmellDetector) DetectGodObject(content string) []CodeSmell
- func (sd *SmellDetector) DetectInFile(path, content string) []CodeSmell
- func (sd *SmellDetector) DetectLongParamList(content string) []CodeSmell
- func (sd *SmellDetector) DetectPrimitiveObsession(content string) []CodeSmell
- func (sd *SmellDetector) ScanDirectory(dir string) []CodeSmell
- type SmellThresholds
- type SummaryGenerator
- type SummaryPackageInfo
- type Symbol
- type SymbolGraph
- type SymbolNode
- type TreeContextRenderer
- type TreeSitterParser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoFix ¶ added in v0.2.0
func AutoFix(opp MigrationOpportunity, content string) (string, error)
AutoFix applies the regex replacement for an auto-fixable opportunity.
func CoChangeAnalysisMap ¶ added in v0.2.0
CoChangeAnalysisMap returns a map of files to their frequently co-changed companions.
func CompareScores ¶ added in v0.2.0
func CompareScores(before, after *HealthScore) string
CompareScores produces a comparison between two health scores.
func ComputeFileHash ¶
ComputeFileHash returns the SHA-256 hex digest of a file's contents.
func DetectFramework ¶ added in v0.2.0
DetectFramework examines Go files in dir to determine which HTTP framework is used. Returns one of: "chi", "gin", "echo", "gorilla", "fiber", "net/http", or "unknown".
func EstimateRemovableLines ¶ added in v0.2.0
EstimateRemovableLines estimates the total number of lines that could be removed if all dead code items were eliminated.
func ExpandQuery ¶ added in v0.2.0
ExpandQuery expands a query term into related terms and synonyms.
func ExtractSnippet ¶ added in v0.2.0
ExtractSnippet finds the most relevant lines from a document containing query terms.
func FindEntryPoints ¶ added in v0.2.0
FindEntryPoints identifies program entry points in the project.
func FindKeyFiles ¶ added in v0.2.0
FindKeyFiles identifies the most important files in a project.
func FormatAPIMap ¶ added in v0.2.0
FormatAPIMap produces a formatted string representation of the API map.
func FormatDeadCode ¶ added in v0.2.0
FormatDeadCode formats the results into a human-readable report.
func FormatDefinition ¶ added in v0.2.0
func FormatDefinition(def *Definition) string
FormatDefinition formats a definition for display.
func FormatGroups ¶ added in v0.2.0
FormatGroups produces a human-readable summary of the file groups.
func FormatOpportunities ¶ added in v0.2.0
func FormatOpportunities(opps []MigrationOpportunity) string
FormatOpportunities produces a human-readable summary of migration opportunities.
func FormatReferences ¶ added in v0.2.0
FormatReferences formats a list of references for display.
func FormatResults ¶ added in v0.2.0
FormatResults produces a human-readable string of search results.
func FormatScore ¶ added in v0.2.0
func FormatScore(score *HealthScore) string
FormatScore produces a human-readable health report.
func FormatSmells ¶ added in v0.2.0
FormatSmells formats a list of code smells into a human-readable report.
func GenerateOpenAPI ¶ added in v0.2.0
GenerateOpenAPI produces a basic OpenAPI 3.0 YAML skeleton from the API map.
func GenerateRemovalPlan ¶ added in v0.2.0
GenerateRemovalPlan produces an ordered list of safe removals.
func IncrementalReindex ¶
func IncrementalReindex(dir string, ignore []string, indexer CodeIndexer) (added, skipped, removed int, err error)
IncrementalReindex walks dir, chunks supported source files, and stores them via the indexer. Files whose hash matches the stored hash are skipped. Files that have been removed from disk are cleared from the index. File processing is parallelized across available CPUs. Uses IndexPatterns for include/exclude glob filtering and GitignoreRules for nested .gitignore support.
func InferArchitecture ¶ added in v0.2.0
func InferArchitecture(packages []SummaryPackageInfo) string
InferArchitecture detects architectural patterns from the package layout. Returns one of: "layered", "flat", "monorepo", "microservices", "hexagonal".
func InferPurpose ¶ added in v0.2.0
InferPurpose infers a package's purpose from its path and exported symbols.
func IsInterfaceImpl ¶ added in v0.2.0
IsInterfaceImpl checks if a function with the given name might satisfy an interface by searching for interface declarations in the provided content.
func IsTestFunction ¶ added in v0.2.0
IsTestFunction returns true if name looks like a Go test, benchmark, or example function.
func MaintainabilityIndex ¶ added in v0.2.0
func MaintainabilityIndex(fc FunctionComplexity) float64
MaintainabilityIndex computes a simplified maintainability index. Based on the standard formula: 171 - 5.2*ln(HV) - 0.23*CC - 16.2*ln(LOC) Simplified using CC and LOC (Halstead volume approximated from LOC).
func RenderCompact ¶ added in v0.2.0
func RenderCompact(summary *CodebaseSummary) string
RenderCompact renders the summary as a single paragraph suitable for tight contexts.
func RenderForPrompt ¶ added in v0.2.0
func RenderForPrompt(summary *CodebaseSummary, budget int) string
RenderForPrompt renders a CodebaseSummary as a markdown-formatted overview suitable for injection into an LLM prompt, respecting the given token budget.
func RenderTreeContext ¶ added in v0.2.0
RenderTreeContext produces a tree-context rendering of symbols for a file. It groups symbols by their parent scope and renders them with proper indentation, similar to Aider's TreeContext. If maxLines <= 0, no truncation is applied.
Types ¶
type APIEndpoint ¶ added in v0.2.0
type APIEndpoint struct {
Method string
Path string
Handler string
File string
Line int
Middleware []string
Description string
}
APIEndpoint represents a single HTTP endpoint discovered in the codebase.
func ScanChi ¶ added in v0.2.0
func ScanChi(content, file string) []APIEndpoint
ScanChi extracts endpoints from chi router registrations. Patterns: r.Get("/path", handler), r.Post(...), r.Put(...), r.Delete(...), r.Route("/prefix", func(r chi.Router) { ... }), r.Group(func(r chi.Router) { ... })
func ScanEcho ¶ added in v0.2.0
func ScanEcho(content, file string) []APIEndpoint
ScanEcho extracts endpoints from echo framework registrations. Patterns: e.GET("/path", handler), e.POST(...), g := e.Group("/api")
func ScanFiber ¶ added in v0.2.0
func ScanFiber(content, file string) []APIEndpoint
ScanFiber extracts endpoints from gofiber/fiber registrations. Patterns: app.Get("/path", handler), app.Post(...), api := app.Group("/api")
func ScanGin ¶ added in v0.2.0
func ScanGin(content, file string) []APIEndpoint
ScanGin extracts endpoints from gin router registrations. Patterns: r.GET("/path", handler), r.POST(...), group := r.Group("/api")
func ScanGorilla ¶ added in v0.2.0
func ScanGorilla(content, file string) []APIEndpoint
ScanGorilla extracts endpoints from gorilla/mux registrations. Patterns: r.HandleFunc("/path", handler).Methods("GET")
func ScanNetHTTP ¶ added in v0.2.0
func ScanNetHTTP(content, file string) []APIEndpoint
ScanNetHTTP extracts endpoints from net/http standard library registrations. Patterns: http.HandleFunc("/path", handler), http.Handle("/path", handler), mux.HandleFunc("/path", handler), mux.Handle("/path", handler)
type APIMap ¶ added in v0.2.0
type APIMap struct {
Endpoints []APIEndpoint
BaseURL string
Version string
// contains filtered or unexported fields
}
APIMap holds all discovered endpoints and metadata about the API.
func (*APIMap) FindEndpointByPath ¶ added in v0.2.0
func (m *APIMap) FindEndpointByPath(path string) *APIEndpoint
FindEndpointByPath returns the first endpoint matching the given path, or nil.
type APIScanner ¶ added in v0.2.0
type APIScanner struct {
// contains filtered or unexported fields
}
APIScanner discovers HTTP endpoints in Go projects by analyzing router registrations.
func NewAPIScanner ¶ added in v0.2.0
func NewAPIScanner() *APIScanner
NewAPIScanner creates a new APIScanner instance.
func (*APIScanner) ScanProject ¶ added in v0.2.0
func (s *APIScanner) ScanProject(dir string) (*APIMap, error)
ScanProject walks Go files in dir looking for router registrations and returns an APIMap with all discovered endpoints. It auto-detects the framework in use.
type CallGraph ¶
type CallGraph struct {
// contains filtered or unexported fields
}
CallGraph maps functions to their callers and callees using Go AST analysis. No CGO required — uses go/parser for static analysis.
func BuildCallGraph ¶
BuildCallGraph parses Go files in root and extracts call relationships.
func (*CallGraph) CalleesOf ¶
CalleesOf returns functions called by the given function (depth levels down).
type ChangeSetContext ¶
type ChangeSetContext struct {
ChangedFiles []string
ImpactedFiles []string // files affected by the changes (dependents)
DependencyFiles []string // files needed to understand the changes (imports)
TotalFiles int
}
ChangeSetContext loads only the code context relevant to current changes. Instead of loading the entire repo map, it: 1. Parses `git diff --name-only` to get changed files 2. For each changed file, finds its imports and dependents 3. Returns a focused context set that's 70-90% smaller than full repo
Research: Change-set-aware loading typically reduces context by 70-90% compared to loading the entire repo-map.
func FromGitDiff ¶
func FromGitDiff(root string, graph *ImportGraph) (*ChangeSetContext, error)
FromGitDiff builds a ChangeSetContext from the current git working tree changes. This includes both staged and unstaged modifications.
func FromGitDiffRange ¶
func FromGitDiffRange(root string, baseRef string, graph *ImportGraph) (*ChangeSetContext, error)
FromGitDiffRange builds a ChangeSetContext from a specific git range (e.g., "main..HEAD").
func (*ChangeSetContext) FormatContext ¶
func (c *ChangeSetContext) FormatContext(maxTokens int) string
FormatContext produces a token-efficient representation of the change set suitable for injection into the system prompt.
type CoChangeAnalysis ¶
type CoChangeAnalysis struct {
// contains filtered or unexported fields
}
CoChangeAnalysis tracks which files frequently change together in git history.
func BuildCoChangeAnalysis ¶
func BuildCoChangeAnalysis(root string, commitLimit int) (*CoChangeAnalysis, error)
BuildCoChangeAnalysis parses the last N commits to find co-change patterns.
func (*CoChangeAnalysis) RelatedFiles ¶
func (ca *CoChangeAnalysis) RelatedFiles(filePath string, topK int) []string
RelatedFiles returns files that frequently co-change with the given file, sorted by co-change frequency.
type CodeChunk ¶
type CodeChunk struct {
Path string
StartLine int
EndLine int
Content string
Vector []float32 // embedding (if computed)
}
CodeChunk represents a chunk of source code for semantic search.
type CodeIndexer ¶
type CodeIndexer interface {
IndexCodeChunk(path, content, symbol, lang string, start, end, tokens int, hash string) error
SearchCode(query string, limit int) ([]CodeSearchResult, error)
GetFileHash(path string) (string, error)
ClearFileChunks(path string) error
ListIndexedPaths() ([]string, error)
}
CodeIndexer is the interface used by IncrementalReindex to store and query code chunks. The memory package's YaadBridge implements this interface.
type CodeSearchResult ¶
type CodeSearchResult struct {
Path string
StartLine int
EndLine int
Content string
Symbol string
Score float64
}
CodeSearchResult represents a code chunk returned by a search.
type CodeSmell ¶ added in v0.2.0
type CodeSmell struct {
ID string
Name string
File string
Line int
Severity string // "minor", "major", "critical"
Description string
RefactoringSuggestion string
Category string // "design", "complexity", "coupling", "naming"
}
CodeSmell represents a detected design issue in source code.
type CodebaseSummary ¶ added in v0.2.0
type CodebaseSummary struct {
ProjectName string
Description string
Language string
Packages []SummaryPackageInfo
EntryPoints []string
KeyFiles []string
Architecture string
TotalLOC int
TotalFiles int
GeneratedAt time.Time
}
CodebaseSummary holds the high-level overview of a repository.
type ComplexityAnalyzer ¶ added in v0.2.0
ComplexityAnalyzer computes complexity metrics with configurable thresholds.
func NewComplexityAnalyzer ¶ added in v0.2.0
func NewComplexityAnalyzer() *ComplexityAnalyzer
NewComplexityAnalyzer creates a ComplexityAnalyzer with default thresholds.
func (*ComplexityAnalyzer) AnalyzeFile ¶ added in v0.2.0
func (ca *ComplexityAnalyzer) AnalyzeFile(path, content string) (*ComplexityReport, error)
AnalyzeFile analyzes the complexity of a file given its path and content.
func (*ComplexityAnalyzer) AnalyzeGeneric ¶ added in v0.2.0
func (ca *ComplexityAnalyzer) AnalyzeGeneric(content, language string) []FunctionComplexity
AnalyzeGeneric performs regex-based complexity analysis for non-Go languages.
func (*ComplexityAnalyzer) AnalyzeGoAST ¶ added in v0.2.0
func (ca *ComplexityAnalyzer) AnalyzeGoAST(content string) []FunctionComplexity
AnalyzeGoAST performs full AST-based complexity analysis on Go source code.
func (*ComplexityAnalyzer) FindHotspots ¶ added in v0.2.0
func (ca *ComplexityAnalyzer) FindHotspots(dir string, limit int) []FunctionComplexity
FindHotspots walks all files under dir, analyzes them, and returns the top N most complex functions sorted by cyclomatic complexity descending.
func (*ComplexityAnalyzer) FormatReport ¶ added in v0.2.0
func (ca *ComplexityAnalyzer) FormatReport(report *ComplexityReport) string
FormatReport formats a ComplexityReport into a human-readable string.
func (*ComplexityAnalyzer) SuggestRefactoring ¶ added in v0.2.0
func (ca *ComplexityAnalyzer) SuggestRefactoring(fc FunctionComplexity) []string
SuggestRefactoring generates refactoring suggestions based on function metrics.
type ComplexityReport ¶ added in v0.2.0
type ComplexityReport struct {
File string
Functions []FunctionComplexity
FileComplexity float64
LOC int
CLOC int // comment lines
BlankLines int
}
ComplexityReport holds complexity metrics for a single file.
type Contributor ¶ added in v0.2.0
Contributor represents a person who has contributed to a file.
type DeadCode ¶ added in v0.2.0
type DeadCode struct {
File string
Line int
Name string
Kind string // "function", "type", "var", "const", "method"
Confidence float64 // 0.0 to 1.0
Reason string
}
DeadCode represents a detected dead code item.
type DeadCodeDetector ¶ added in v0.2.0
type DeadCodeDetector struct {
Declarations map[string]*Declaration
References map[string]int
// contains filtered or unexported fields
}
DeadCodeDetector scans Go projects to find unused declarations.
func NewDeadCodeDetector ¶ added in v0.2.0
func NewDeadCodeDetector() *DeadCodeDetector
NewDeadCodeDetector creates a new initialized DeadCodeDetector.
func (*DeadCodeDetector) FindUnused ¶ added in v0.2.0
func (d *DeadCodeDetector) FindUnused() []DeadCode
FindUnused returns declarations with zero references, filtering out known special functions (main, init, test functions, interface implementations).
func (*DeadCodeDetector) FindUnusedExports ¶ added in v0.2.0
func (d *DeadCodeDetector) FindUnusedExports(projectDir string) []DeadCode
FindUnusedExports finds exported symbols not referenced anywhere in the project.
func (*DeadCodeDetector) Scan ¶ added in v0.2.0
func (d *DeadCodeDetector) Scan(projectDir string) ([]DeadCode, error)
Scan walks all Go files in projectDir, collects declarations and references, and returns detected dead code items.
func (*DeadCodeDetector) ScanFile ¶ added in v0.2.0
func (d *DeadCodeDetector) ScanFile(path, content string)
ScanFile uses go/ast to extract declarations and references from a single file.
type Declaration ¶ added in v0.2.0
type Declaration struct {
Name string
Kind string
File string
Line int
Exported bool
Package string
}
Declaration represents a top-level declaration in a Go source file.
type Definition ¶ added in v0.2.0
type Definition struct {
Name string
Kind string // "func", "type", "var", "const", "method", "interface"
File string
Line int
Package string
Exported bool
Signature string
DocComment string
}
Definition represents a symbol definition in the codebase.
type DepEdge ¶ added in v0.2.0
type DepEdge struct {
From string
To string
Weight int // number of imports between these packages
}
DepEdge represents a directed edge from one package to another.
type DepGraph ¶ added in v0.2.0
type DepGraph struct {
Nodes map[string]*DepNode
Edges []DepEdge
Root string
// contains filtered or unexported fields
}
DepGraph represents a directed dependency graph of packages/modules.
func NewDepGraph ¶ added in v0.2.0
func NewDepGraph() *DepGraph
NewDepGraph creates and returns a new empty DepGraph.
func (*DepGraph) AddEdge ¶ added in v0.2.0
AddEdge adds a directed edge to the graph. If an edge between From and To already exists, its weight is incremented.
func (*DepGraph) AddNode ¶ added in v0.2.0
AddNode adds a node to the graph. If a node with the same ID already exists, it is overwritten.
func (*DepGraph) BuildFromGoMod ¶ added in v0.2.0
BuildFromGoMod reads go.mod and scans .go files to build the dependency graph.
func (*DepGraph) BuildFromPackageJSON ¶ added in v0.2.0
BuildFromPackageJSON reads package.json and scans JS/TS files to build the dependency graph.
func (*DepGraph) FindCycles ¶ added in v0.2.0
FindCycles detects circular dependencies and returns all cycles found.
func (*DepGraph) HotPaths ¶ added in v0.2.0
HotPaths finds the most-depended-on paths using a PageRank-like importance scoring. Returns paths sorted by importance (most critical first).
func (*DepGraph) Layers ¶ added in v0.2.0
Layers groups packages into layers based on dependency depth. Layer 0 contains packages with no dependencies, layer 1 depends only on layer 0, etc.
func (*DepGraph) RenderASCII ¶ added in v0.2.0
RenderASCII generates an ASCII art visualization of the dependency graph.
func (*DepGraph) RenderDOT ¶ added in v0.2.0
RenderDOT generates a Graphviz DOT format representation of the graph.
func (*DepGraph) RenderMermaid ¶ added in v0.2.0
RenderMermaid generates a Mermaid.js format representation for markdown rendering.
func (*DepGraph) Stats ¶ added in v0.2.0
func (dg *DepGraph) Stats() GraphStats
Stats returns summary statistics about the dependency graph.
func (*DepGraph) TopologicalSort ¶ added in v0.2.0
TopologicalSort returns packages in dependency order (leaves first). Packages with no dependencies appear first.
type DepNode ¶ added in v0.2.0
type DepNode struct {
ID string // package/module path
Name string // short name
Type string // "internal", "external", "stdlib"
FileCount int
LOC int
ImportedBy []string
Imports []string
}
DepNode represents a single package or module in the dependency graph.
type DocIssue ¶ added in v0.2.0
type DocIssue struct {
Line int
Symbol string
Type string // "missing", "outdated", "incomplete", "unclear"
Message string
Severity string // "error", "warning", "info"
Suggestion string
}
DocIssue represents a single documentation problem found in a file.
type DocLintResult ¶ added in v0.2.0
DocLintResult holds the documentation quality analysis for a single file.
type DocLinter ¶ added in v0.2.0
type DocLinter struct {
MinCommentLength int
RequireExported bool
// contains filtered or unexported fields
}
DocLinter performs documentation quality analysis on Go source files.
func NewDocLinter ¶ added in v0.2.0
func NewDocLinter() *DocLinter
NewDocLinter creates a DocLinter with sensible default configuration.
func (*DocLinter) CheckGoDoc ¶ added in v0.2.0
CheckGoDoc inspects a doc comment for an exported symbol and returns issues.
func (*DocLinter) CoverageReport ¶ added in v0.2.0
func (dl *DocLinter) CoverageReport(results []*DocLintResult) string
CoverageReport produces an overall documentation coverage summary.
func (*DocLinter) FormatReport ¶ added in v0.2.0
func (dl *DocLinter) FormatReport(results []*DocLintResult) string
FormatReport produces a human-readable documentation lint report.
func (*DocLinter) LintDirectory ¶ added in v0.2.0
func (dl *DocLinter) LintDirectory(dir string) ([]*DocLintResult, error)
LintDirectory walks all Go files in a directory and lints each one.
func (*DocLinter) LintFile ¶ added in v0.2.0
func (dl *DocLinter) LintFile(path, content string) (*DocLintResult, error)
LintFile analyzes the documentation quality of a single Go source file.
func (*DocLinter) SuggestDocComment ¶ added in v0.2.0
SuggestDocComment generates a suggested doc comment for a given symbol.
type DocStats ¶ added in v0.2.0
type DocStats struct {
TotalExported int
Documented int
Coverage float64
AvgLength int
MissingCount int
}
DocStats holds aggregate documentation statistics for a file.
type Document ¶ added in v0.2.0
type Document struct {
ID string
Path string
Content string
Terms map[string]int
Length int
Type string // "function", "type", "file", "block"
}
Document represents a single indexable unit (function, type, file, or block).
type EnhancedGoParser ¶
type EnhancedGoParser struct{}
EnhancedGoParser uses go/ast for accurate Go symbol extraction. Replaces regex-based parsing for Go files with zero-CGO AST parsing. This covers what tree-sitter would give us: method receivers, nested types, interface methods, embedded fields — without requiring CGO.
func (*EnhancedGoParser) ParseGoFile ¶
func (p *EnhancedGoParser) ParseGoFile(content, filePath string) []EnhancedSymbol
ParseGoFile extracts all symbols from a Go file using the standard library parser.
type EnhancedSymbol ¶
type EnhancedSymbol struct {
Name string
Kind string // function, method, type, interface, struct, field, variable, interface_method
Line int
File string
Exported bool
References []string // symbols this one references
}
EnhancedSymbol represents a richly-extracted code symbol with references.
func ParsePythonFile ¶
func ParsePythonFile(content, filePath string) []EnhancedSymbol
ParsePythonFile extracts symbols from Python using enhanced regex patterns. Handles: classes, methods (with self), decorators, nested classes.
type FileCache ¶
type FileCache struct {
Hash string `json:"hash"`
Mtime int64 `json:"mtime"`
Symbols []string `json:"symbols"`
}
FileCache holds the cached metadata for a single file.
type FileGroup ¶ added in v0.2.0
type FileGroup struct {
Name string
Files []string
Reason string
Confidence float64
Type string // "package", "feature", "layer", "test_pair", "config"
}
FileGroup represents a set of files that logically belong together.
type FileGrouper ¶ added in v0.2.0
type FileGrouper struct {
ProjectDir string
Groups []FileGroup
// contains filtered or unexported fields
}
FileGrouper identifies which files belong together and should be edited as a unit.
func NewFileGrouper ¶ added in v0.2.0
func NewFileGrouper(projectDir string) *FileGrouper
NewFileGrouper creates a new FileGrouper for the given project directory.
func (*FileGrouper) AnalyzeGroups ¶ added in v0.2.0
func (fg *FileGrouper) AnalyzeGroups() ([]FileGroup, error)
AnalyzeGroups runs multiple strategies to identify file groups in the project.
func (*FileGrouper) FindByFeature ¶ added in v0.2.0
func (fg *FileGrouper) FindByFeature(featureName string) []string
FindByFeature finds all files related to a feature by name.
func (*FileGrouper) FindRelated ¶ added in v0.2.0
func (fg *FileGrouper) FindRelated(file string) []string
FindRelated returns all files related to the given file.
func (*FileGrouper) FindTestPair ¶ added in v0.2.0
func (fg *FileGrouper) FindTestPair(file string) string
FindTestPair finds the corresponding test file for a source file or vice versa.
func (*FileGrouper) SuggestEditGroup ¶ added in v0.2.0
func (fg *FileGrouper) SuggestEditGroup(targetFile string) []string
SuggestEditGroup suggests related files that likely need updates when editing a target file.
type FileOwnership ¶ added in v0.2.0
type FileOwnership struct {
Path string
PrimaryOwner string
Contributors []Contributor
LastModified time.Time
TotalCommits int
}
FileOwnership represents the ownership metadata for a single file.
type FileSummary ¶
type FileSummary struct {
Path string
Functions []string // exported function signatures
Types []string // exported type names
LineCount int
}
FileSummary is a level-3 summary of a single file.
type FileWatcher ¶
type FileWatcher struct {
// contains filtered or unexported fields
}
FileWatcher monitors the project directory for changes and triggers re-indexing.
func NewFileWatcher ¶
func NewFileWatcher(root string, onChange func(path string)) (*FileWatcher, error)
NewFileWatcher creates a watcher for Go/Python/TS files in the given root.
func (*FileWatcher) Start ¶
func (fw *FileWatcher) Start()
Start begins watching for file changes in a goroutine.
type FunctionComplexity ¶ added in v0.2.0
type FunctionComplexity struct {
Name string
StartLine int
EndLine int
Cyclomatic int
Cognitive int
LOC int
Parameters int
Returns int
Nesting int // max depth
}
FunctionComplexity holds complexity metrics for a single function.
type GitignoreRules ¶
type GitignoreRules struct {
// contains filtered or unexported fields
}
GitignoreRules holds composed gitignore patterns from multiple levels.
func LoadGitignoreRules ¶
func LoadGitignoreRules(dir string) *GitignoreRules
LoadGitignoreRules walks from dir up to the filesystem root, loading all .gitignore files. Rules from deeper directories take precedence (are appended last). Also loads the global gitignore (~/.config/git/ignore) if it exists.
func (*GitignoreRules) ShouldIgnore ¶
func (gr *GitignoreRules) ShouldIgnore(path string) bool
ShouldIgnore checks if a path should be ignored according to gitignore rules. The path should be relative to the repository root.
type GraphStats ¶ added in v0.2.0
type GraphStats struct {
TotalNodes int
InternalNodes int
ExternalNodes int
StdlibNodes int
TotalEdges int
MaxDepth int
Cycles int
MostImported string
MostImporting string
}
GraphStats holds summary statistics about the dependency graph.
type HealthIssue ¶ added in v0.2.0
type HealthIssue struct {
Dimension string
Description string
Severity string
File string
Suggestion string
}
HealthIssue represents a specific health concern in a project.
type HealthScore ¶ added in v0.2.0
type HealthScore struct {
Overall float64
Dimensions map[string]float64
Issues []HealthIssue
Strengths []string
Grade string
}
HealthScore represents the overall health assessment of a project.
type HealthScorer ¶ added in v0.2.0
HealthScorer evaluates project health across multiple dimensions.
func NewHealthScorer ¶ added in v0.2.0
func NewHealthScorer() *HealthScorer
NewHealthScorer creates a HealthScorer with default dimension weights.
func (*HealthScorer) Score ¶ added in v0.2.0
func (hs *HealthScorer) Score(projectDir string) (*HealthScore, error)
Score evaluates the overall health of a project directory.
func (*HealthScorer) ScoreCodeQuality ¶ added in v0.2.0
func (hs *HealthScorer) ScoreCodeQuality(dir string) (float64, []HealthIssue)
ScoreCodeQuality evaluates overall code quality signals.
func (*HealthScorer) ScoreComplexity ¶ added in v0.2.0
func (hs *HealthScorer) ScoreComplexity(dir string) (float64, []HealthIssue)
ScoreComplexity evaluates code complexity across the project.
func (*HealthScorer) ScoreDependencies ¶ added in v0.2.0
func (hs *HealthScorer) ScoreDependencies(dir string) (float64, []HealthIssue)
ScoreDependencies evaluates dependency health.
func (*HealthScorer) ScoreDocumentation ¶ added in v0.2.0
func (hs *HealthScorer) ScoreDocumentation(dir string) (float64, []HealthIssue)
ScoreDocumentation evaluates documentation quality.
func (*HealthScorer) ScoreMaintainability ¶ added in v0.2.0
func (hs *HealthScorer) ScoreMaintainability(dir string) (float64, []HealthIssue)
ScoreMaintainability evaluates how maintainable the codebase is.
func (*HealthScorer) ScoreSecurity ¶ added in v0.2.0
func (hs *HealthScorer) ScoreSecurity(dir string) (float64, []HealthIssue)
ScoreSecurity evaluates basic security signals in the codebase.
func (*HealthScorer) ScoreTestCoverage ¶ added in v0.2.0
func (hs *HealthScorer) ScoreTestCoverage(dir string) (float64, []HealthIssue)
ScoreTestCoverage evaluates testing practices and coverage.
type HierarchicalSummary ¶
type HierarchicalSummary struct {
Root string
Packages []PackageSummary
}
HierarchicalSummary provides 3-level code summarization: Level 1: Project (all packages as one-liners) Level 2: Package (file list with exported symbols) Level 3: File (function signatures, no bodies)
func BuildHierarchy ¶
func BuildHierarchy(root string) (*HierarchicalSummary, error)
BuildHierarchy scans a Go project and builds a 3-level summary.
func (*HierarchicalSummary) FormatLevel1 ¶
func (h *HierarchicalSummary) FormatLevel1(maxTokens int) string
FormatLevel1 returns the project-level summary (one line per package).
func (*HierarchicalSummary) FormatLevel2 ¶
func (h *HierarchicalSummary) FormatLevel2(pkgPath string, maxTokens int) string
FormatLevel2 returns the package-level summary (files + exported symbols).
func (*HierarchicalSummary) FormatLevel3 ¶
func (h *HierarchicalSummary) FormatLevel3(filePath string) string
FormatLevel3 returns a file-level summary (full function signatures).
type ImportGraph ¶
type ImportGraph struct {
// contains filtered or unexported fields
}
ImportGraph builds and queries file-level import/dependency relationships. When file A is identified as relevant, this finds: - Files that A imports (its dependencies) - Files that import A (its dependents)
This is the cheapest cross-file signal. Research shows import graph traversal prevents "undefined symbol" errors by 30-40%.
func BuildImportGraph ¶
func BuildImportGraph(root string) (*ImportGraph, error)
BuildImportGraph scans source files in the given root directory and builds the import graph. For Go, this parses import statements and maps import paths to local files. Also supports basic Python and TypeScript/JavaScript.
func (*ImportGraph) DependenciesOf ¶
func (g *ImportGraph) DependenciesOf(filePath string, maxDepth int) []string
DependenciesOf returns files that the given file imports (up to maxDepth).
func (*ImportGraph) DependentsOf ¶
func (g *ImportGraph) DependentsOf(filePath string, maxDepth int) []string
DependentsOf returns files that import the given file (up to maxDepth).
func (*ImportGraph) Edges ¶
func (g *ImportGraph) Edges() map[string][]string
Edges returns the forward edge map (file -> imports). Useful for inspection.
func (*ImportGraph) ImpactSet ¶
func (g *ImportGraph) ImpactSet(files []string, maxDepth int) []string
ImpactSet returns the union of dependencies and dependents for a set of files. This is used for change-set-aware context: "what other files matter given these changes?"
func (*ImportGraph) Reverse ¶
func (g *ImportGraph) Reverse() map[string][]string
Reverse returns the reverse edge map (file -> dependents). Useful for inspection.
type IncrementalMap ¶
type IncrementalMap struct {
// contains filtered or unexported fields
}
IncrementalMap maintains a cached symbol index that only reprocesses changed files. It stores file hashes (SHA-256 of content) in a cache file (.hawk/repomap-cache.json). On regeneration, only files whose hash changed are re-parsed. Symbols from changed files are merged into the existing map, and symbols from deleted files are removed.
func NewIncrementalMap ¶
func NewIncrementalMap(cacheDir string) (*IncrementalMap, error)
NewIncrementalMap loads or creates a repomap cache. cacheDir is the directory where the cache file will be stored (typically ".hawk").
func (*IncrementalMap) AllSymbols ¶
func (im *IncrementalMap) AllSymbols() map[string][]string
AllSymbols returns every symbol across all cached files.
func (*IncrementalMap) Save ¶
func (im *IncrementalMap) Save() error
Save persists the cache to disk.
func (*IncrementalMap) Symbols ¶
func (im *IncrementalMap) Symbols(path string) []string
Symbols returns all cached symbols for a file.
type IndexPatterns ¶
type IndexPatterns struct {
Include []string `json:"include"` // if non-empty, ONLY files matching these are indexed
Exclude []string `json:"exclude"` // files matching these are NEVER indexed (overrides include)
}
IndexPatterns controls which files are indexed.
func DefaultIndexPatterns ¶
func DefaultIndexPatterns() IndexPatterns
DefaultIndexPatterns returns sensible defaults.
func LoadIndexPatterns ¶
func LoadIndexPatterns() IndexPatterns
LoadIndexPatterns reads from .hawk/index.json or uses defaults.
func (IndexPatterns) ShouldIndex ¶
func (p IndexPatterns) ShouldIndex(path string) bool
ShouldIndex checks if a path should be indexed based on include/exclude patterns.
type InterfaceExtraction ¶
type InterfaceExtraction struct {
Functions []string // "func Name(args) returns"
Types []string // "type Name struct/interface"
Constants []string // "const Name = ..."
Package string
}
InterfaceExtraction shows only exported signatures (no bodies). Uses ~100 tokens per file vs ~500+ for full content.
func ExtractInterface ¶
func ExtractInterface(filePath string) (*InterfaceExtraction, error)
ExtractInterface parses a Go file and returns only its exported API surface.
func (*InterfaceExtraction) Format ¶
func (ie *InterfaceExtraction) Format() string
Format returns the interface as a compact string.
func (*InterfaceExtraction) TokenEstimate ¶
func (ie *InterfaceExtraction) TokenEstimate() int
TokenEstimate returns approximate token count for this interface.
type MigrationDetector ¶ added in v0.2.0
type MigrationDetector struct {
Rules []MigrationRule
// contains filtered or unexported fields
}
MigrationDetector scans source files to identify migration opportunities.
func NewMigrationDetector ¶ added in v0.2.0
func NewMigrationDetector() *MigrationDetector
NewMigrationDetector creates a MigrationDetector with built-in rules.
func (*MigrationDetector) AddRule ¶ added in v0.2.0
func (md *MigrationDetector) AddRule(rule MigrationRule)
AddRule adds a custom migration rule to the detector.
func (*MigrationDetector) Scan ¶ added in v0.2.0
func (md *MigrationDetector) Scan(projectDir string) ([]MigrationOpportunity, error)
Scan walks projectDir and applies matching rules to each source file.
func (*MigrationDetector) ScanFile ¶ added in v0.2.0
func (md *MigrationDetector) ScanFile(path, content string) []MigrationOpportunity
ScanFile applies all matching rules to the given file content.
type MigrationOpportunity ¶ added in v0.2.0
type MigrationOpportunity struct {
File string
Line int
OldPattern string
NewPattern string
Reason string
Priority string // "high", "medium", "low"
AutoFixable bool
Category string // "deprecated", "idiom", "security", "performance"
}
MigrationOpportunity represents a detected code pattern that could be updated.
type MigrationRule ¶ added in v0.2.0
type MigrationRule struct {
ID string
Language string
OldPattern *regexp.Regexp
NewPattern string
Reason string
Priority string
AutoFixable bool
Category string
Since string // version when old pattern became deprecated
}
MigrationRule defines a pattern to detect and suggest replacement.
type NavIndex ¶ added in v0.2.0
type NavIndex struct {
// contains filtered or unexported fields
}
NavIndex provides code navigation capabilities (go-to-definition, find-references, find-implementations) without requiring an LSP server. It parses Go source files using go/ast and builds an in-memory index of definitions, references, and interface implementations.
func NewNavIndex ¶ added in v0.2.0
func NewNavIndex() *NavIndex
NewNavIndex creates a new empty navigation index.
func (*NavIndex) BuildIndex ¶ added in v0.2.0
BuildIndex parses all Go files under projectDir and populates the index with definitions, references, and implementation mappings.
func (*NavIndex) FindCallees ¶ added in v0.2.0
FindCallees returns all functions called by the given function.
func (*NavIndex) FindCallers ¶ added in v0.2.0
FindCallers returns all call sites of the given function.
func (*NavIndex) FindImplementations ¶ added in v0.2.0
FindImplementations returns all types that implement the given interface.
func (*NavIndex) FindReferences ¶ added in v0.2.0
FindReferences returns all references to the given symbol.
func (*NavIndex) GoToDefinition ¶ added in v0.2.0
func (idx *NavIndex) GoToDefinition(symbol string) *Definition
GoToDefinition returns the definition for the given symbol name.
func (*NavIndex) SearchSymbols ¶ added in v0.2.0
func (idx *NavIndex) SearchSymbols(query string, kind string) []*Definition
SearchSymbols performs a fuzzy search across all definitions, optionally filtered by kind.
func (*NavIndex) TypeHierarchy ¶ added in v0.2.0
TypeHierarchy shows the interface -> implementations tree for a type.
type OwnerRule ¶ added in v0.2.0
type OwnerRule struct {
Pattern string
Owners []string
Source string // "codeowners", "git_history", "config"
}
OwnerRule represents a code ownership rule from a CODEOWNERS file or config.
type OwnershipMap ¶ added in v0.2.0
type OwnershipMap struct {
Owners map[string]*FileOwnership
Rules []OwnerRule
// contains filtered or unexported fields
}
OwnershipMap tracks code ownership across a repository by combining git history analysis with CODEOWNERS-style rules. It identifies primary owners, contributors, and bus-factor risks for each file.
func NewOwnershipMap ¶ added in v0.2.0
func NewOwnershipMap() *OwnershipMap
NewOwnershipMap creates an empty OwnershipMap ready for population.
func (*OwnershipMap) BuildFromGitHistory ¶ added in v0.2.0
func (om *OwnershipMap) BuildFromGitHistory(projectDir string) error
BuildFromGitHistory populates the ownership map by analyzing git log output. It runs `git log --format=%an --name-only` to map files to contributors, calculates ownership percentages per file, and determines the primary owner.
func (*OwnershipMap) DetectBusFactorRisk ¶ added in v0.2.0
func (om *OwnershipMap) DetectBusFactorRisk() []string
DetectBusFactorRisk identifies files where only one person has ever committed. These files represent a "bus factor" risk: if that person becomes unavailable, no one else has context on the code.
func (*OwnershipMap) FindExpertFor ¶ added in v0.2.0
func (om *OwnershipMap) FindExpertFor(path string) string
FindExpertFor returns the best person to review changes to a given file path. It considers both git history and CODEOWNERS rules, preferring CODEOWNERS when available since those represent explicit ownership assignments.
func (*OwnershipMap) FormatOwnership ¶ added in v0.2.0
func (om *OwnershipMap) FormatOwnership(limit int) string
FormatOwnership produces a human-readable summary of code ownership. The limit parameter controls how many top owners to display.
func (*OwnershipMap) GetOwner ¶ added in v0.2.0
func (om *OwnershipMap) GetOwner(path string) *FileOwnership
GetOwner returns the FileOwnership for a given path, or nil if not tracked.
func (*OwnershipMap) GetOwnersByDirectory ¶ added in v0.2.0
func (om *OwnershipMap) GetOwnersByDirectory(dir string) map[string]string
GetOwnersByDirectory returns a mapping of directory path to the primary owner of that directory (the person with most commits in that directory).
func (*OwnershipMap) LoadCodeowners ¶ added in v0.2.0
func (om *OwnershipMap) LoadCodeowners(path string) error
LoadCodeowners parses a CODEOWNERS file and adds the rules to the ownership map. The file format follows GitHub's CODEOWNERS convention:
pattern @owner1 @owner2
Lines starting with # are comments. Blank lines are ignored.
func (*OwnershipMap) SuggestReviewers ¶ added in v0.2.0
func (om *OwnershipMap) SuggestReviewers(changedFiles []string) []string
SuggestReviewers returns a deduplicated list of suggested reviewers for a set of changed files, based on ownership data. Reviewers are ordered by relevance (number of files they own among the changed set).
type PackageSummary ¶
type PackageSummary struct {
Path string
Name string
Files []FileSummary
Symbols int
}
PackageSummary is a level-2 summary of a Go package.
type PredictedFile ¶
type PredictedFile struct {
Path string
Score float64
Reason string // why it was predicted relevant
}
PredictedFile is a file predicted to be relevant to the current task.
type RecentEdit ¶
RecentEdit tracks a file that was recently modified.
type RecentEditTracker ¶
type RecentEditTracker struct {
// contains filtered or unexported fields
}
RecentEditTracker maintains a list of recently edited files.
func NewRecentEditTracker ¶
func NewRecentEditTracker(max int) *RecentEditTracker
NewRecentEditTracker creates a tracker with a max capacity.
func (*RecentEditTracker) Recent ¶
func (t *RecentEditTracker) Recent(within time.Duration) []RecentEdit
Recent returns edits within the given duration.
func (*RecentEditTracker) Record ¶
func (t *RecentEditTracker) Record(path string)
Record adds a file edit event.
type Reference ¶ added in v0.2.0
type Reference struct {
File string
Line int
Context string // surrounding line text
Kind string // "call", "type_use", "import", "assignment"
}
Reference represents a usage of a symbol in the codebase.
type RelevancePrediction ¶
type RelevancePrediction struct {
Files []PredictedFile
}
RelevancePrediction holds predicted files with their relevance scores.
func PredictRelevantFiles ¶
func PredictRelevantFiles(prompt string, recentEdits []RecentEdit, graph *ImportGraph, symbols map[string]string) *RelevancePrediction
PredictRelevantFiles predicts which files are likely relevant given: - The user's prompt (keyword matching against repo map symbols) - Recently edited files (locality heuristic) - Import graph relationships - Co-change history
type RepoMap ¶
RepoMap is the full repository map result.
type RerankResult ¶
type RerankResult struct {
Chunk CodeSearchResult
Score float64
}
RerankResult pairs a search result with a re-ranking score.
func Rerank ¶
func Rerank(query string, candidates []CodeSearchResult, topK int) []RerankResult
Rerank re-scores candidates using BM25 (k1=1.2, b=0.75) against the query and returns the top-K results sorted by descending score.
type SearchHit ¶ added in v0.2.0
SearchHit represents a single search result with scoring information.
type SemanticIndex ¶
type SemanticIndex struct {
// contains filtered or unexported fields
}
SemanticIndex holds chunked source files and supports TF-IDF search.
func BuildSemanticIndex ¶
func BuildSemanticIndex(dir string, ignore []string, maxFiles int) (*SemanticIndex, error)
BuildSemanticIndex scans dir, chunks files into ~40-line blocks, and builds an index.
func LoadSemanticIndex ¶
func LoadSemanticIndex(path string) (*SemanticIndex, error)
LoadSemanticIndex decodes a previously saved index from a gob file.
func (*SemanticIndex) Save ¶
func (idx *SemanticIndex) Save(path string) error
Save encodes the index to a file using gob.
func (*SemanticIndex) Search ¶
func (idx *SemanticIndex) Search(query string, topK int) []CodeChunk
Search performs TF-IDF based search over the index, returning the top-K chunks.
func (*SemanticIndex) Size ¶
func (idx *SemanticIndex) Size() int
Size returns the number of chunks in the index.
type SemanticSearchIndex ¶ added in v0.2.0
type SemanticSearchIndex struct {
Documents map[string]*Document
IDF map[string]float64
AvgDocLen float64
TotalDocs int
// contains filtered or unexported fields
}
SemanticSearchIndex holds documents indexed for BM25 semantic search.
func NewSemanticSearchIndex ¶ added in v0.2.0
func NewSemanticSearchIndex() *SemanticSearchIndex
NewSemanticIndex creates a new empty SemanticSearchIndex ready for use.
func (*SemanticSearchIndex) BM25Score ¶ added in v0.2.0
func (si *SemanticSearchIndex) BM25Score(queryTerms []string, doc *Document) float64
BM25Score computes the BM25 score for a document given query terms. Uses standard BM25 with k1=1.5, b=0.75.
func (*SemanticSearchIndex) IndexDirectory ¶ added in v0.2.0
func (si *SemanticSearchIndex) IndexDirectory(dir string) error
IndexDirectory walks a directory and indexes all supported source files.
func (*SemanticSearchIndex) IndexFile ¶ added in v0.2.0
func (si *SemanticSearchIndex) IndexFile(path, content string)
IndexFile splits a file into documents (functions, types, blocks) and indexes them.
func (*SemanticSearchIndex) RebuildIndex ¶ added in v0.2.0
func (si *SemanticSearchIndex) RebuildIndex() error
RebuildIndex recalculates IDF values and average document length.
func (*SemanticSearchIndex) Search ¶ added in v0.2.0
func (si *SemanticSearchIndex) Search(query string, limit int) []SearchHit
Search tokenizes the query and returns the top-scoring documents using BM25.
func (*SemanticSearchIndex) SearchByIntent ¶ added in v0.2.0
func (si *SemanticSearchIndex) SearchByIntent(intent string) []SearchHit
SearchByIntent searches using expanded query terms to find code by meaning/intent. For example, "authentication" will find auth-related code even if the exact word isn't present.
type ShapleyRanker ¶
type ShapleyRanker struct {
// contains filtered or unexported fields
}
ShapleyRanker scores code chunks by their marginal contribution to generation quality using an approximate Shapley value approach.
func NewShapleyRanker ¶
func NewShapleyRanker(chunks []CodeChunk) *ShapleyRanker
NewShapleyRanker creates a ranker from the given code chunks.
func (*ShapleyRanker) ComputeScores ¶
func (sr *ShapleyRanker) ComputeScores(relevantPaths []string, query string) []ShapleyScore
ComputeScores calculates approximate Shapley values for each chunk.
Score = relevance_to_query * centrality_in_graph * recency_bonus - redundancy_penalty
- relevance: keyword overlap with query
- centrality: how many other chunks reference symbols in this chunk
- recency: files in relevantPaths get a boost
- redundancy: chunks similar to already-scored chunks get penalized
func (*ShapleyRanker) Format ¶
func (sr *ShapleyRanker) Format(chunks []CodeChunk) string
Format renders selected chunks as a text block for prompt injection.
func (*ShapleyRanker) SelectOptimalContext ¶
func (sr *ShapleyRanker) SelectOptimalContext(query string, tokenBudget int) []CodeChunk
SelectOptimalContext greedily selects chunks that maximize information within the token budget, recomputing redundancy penalties after each addition.
type ShapleyScore ¶
type ShapleyScore struct {
Path string
StartLine int
EndLine int
Score float64 // higher = more helpful in context
Content string
}
ShapleyScore represents the computed marginal contribution of a code chunk.
type SmellDetector ¶ added in v0.2.0
type SmellDetector struct {
Thresholds SmellThresholds
// contains filtered or unexported fields
}
SmellDetector identifies code smells using structural analysis.
func NewSmellDetector ¶ added in v0.2.0
func NewSmellDetector() *SmellDetector
NewSmellDetector creates a SmellDetector with default thresholds.
func (*SmellDetector) DetectDataClump ¶ added in v0.2.0
func (sd *SmellDetector) DetectDataClump(content string) []CodeSmell
DetectDataClump finds groups of parameters that appear together in multiple functions.
func (*SmellDetector) DetectFeatureEnvy ¶ added in v0.2.0
func (sd *SmellDetector) DetectFeatureEnvy(content string) []CodeSmell
DetectFeatureEnvy finds methods that use another type's fields more than their own.
func (*SmellDetector) DetectGodObject ¶ added in v0.2.0
func (sd *SmellDetector) DetectGodObject(content string) []CodeSmell
DetectGodObject finds types with too many methods or fields.
func (*SmellDetector) DetectInFile ¶ added in v0.2.0
func (sd *SmellDetector) DetectInFile(path, content string) []CodeSmell
DetectInFile runs all smell detectors on a file given its path and content.
func (*SmellDetector) DetectLongParamList ¶ added in v0.2.0
func (sd *SmellDetector) DetectLongParamList(content string) []CodeSmell
DetectLongParamList finds functions with too many parameters.
func (*SmellDetector) DetectPrimitiveObsession ¶ added in v0.2.0
func (sd *SmellDetector) DetectPrimitiveObsession(content string) []CodeSmell
DetectPrimitiveObsession finds functions taking too many string/int params.
func (*SmellDetector) ScanDirectory ¶ added in v0.2.0
func (sd *SmellDetector) ScanDirectory(dir string) []CodeSmell
ScanDirectory walks a directory and detects code smells in all Go files.
type SmellThresholds ¶ added in v0.2.0
type SmellThresholds struct {
MaxParams int
MaxMethodsPerType int
MaxFieldsPerStruct int
MaxImports int
MaxFileLines int
MaxFuncLines int
MinMethodCohesion float64
}
SmellThresholds defines configurable limits for code smell detection.
type SummaryGenerator ¶ added in v0.2.0
type SummaryGenerator struct {
ProjectDir string
MaxTokens int
// contains filtered or unexported fields
}
SummaryGenerator produces concise codebase overviews for context injection.
func NewSummaryGenerator ¶ added in v0.2.0
func NewSummaryGenerator(projectDir string, maxTokens int) *SummaryGenerator
NewSummaryGenerator creates a new SummaryGenerator for the given project directory.
func (*SummaryGenerator) Generate ¶ added in v0.2.0
func (sg *SummaryGenerator) Generate() (*CodebaseSummary, error)
Generate walks the project directory, analyzes packages, identifies entry points and key files, infers architecture, and produces a CodebaseSummary.
type SummaryPackageInfo ¶ added in v0.2.0
type SummaryPackageInfo struct {
Name string
Path string
Purpose string
PublicSymbols int
Files int
LOC int
Dependencies []string
Dependents []string
}
SummaryPackageInfo holds the overview of a single package/module for summaries.
type Symbol ¶
Symbol represents a top-level code symbol (function, type, class, etc.).
func ParseFileEnhanced ¶ added in v0.2.0
ParseFileEnhanced is the new default parser entry point. It dispatches to parseGoAST for .go files and enhanced regex parsers for Python, TypeScript, JavaScript, and Rust. For other languages, it falls back to the existing regex parsers.
func ParseSourceEnhanced ¶ added in v0.2.0
ParseSourceEnhanced parses source code directly without reading from disk. Useful for testing.
type SymbolGraph ¶
type SymbolGraph struct {
// contains filtered or unexported fields
}
SymbolGraph is a directed graph of symbol references used for PageRank computation over a codebase.
func BuildSymbolGraph ¶
func BuildSymbolGraph(dir string, opts Options) (*SymbolGraph, error)
BuildSymbolGraph scans the directory, extracts symbols using the existing repomap parsers, then builds a directed graph by grepping for references.
func (*SymbolGraph) ComputePageRank ¶
func (sg *SymbolGraph) ComputePageRank(iterations int, damping float64)
ComputePageRank runs the standard PageRank algorithm on the symbol graph.
rank[i] = (1-d) + d * sum(rank[j]/outlinks[j]) for all j->i
Default: iterations=20, damping=0.85.
func (*SymbolGraph) FormatMap ¶
func (sg *SymbolGraph) FormatMap(maxTokens int) string
FormatMap renders the ranked symbols as a repo map string, highest-rank first, stopping when the estimated token budget is reached.
func (*SymbolGraph) TopSymbols ¶
func (sg *SymbolGraph) TopSymbols(n int) []SymbolNode
TopSymbols returns the top-N symbols ordered by rank (descending).
type SymbolNode ¶
SymbolNode is a single node in the symbol graph.
type TreeContextRenderer ¶ added in v0.2.0
type TreeContextRenderer struct{}
TreeContextRenderer renders symbols with parent scope context, showing definition signatures indented under their parent scope like a tree outline.
type TreeSitterParser ¶ added in v0.2.0
type TreeSitterParser struct {
// IncludeUnexported controls whether unexported symbols are included.
// By default only exported/public symbols are returned for Go.
IncludeUnexported bool
}
TreeSitterParser provides language-aware structural parsing that replaces simple regex-based symbol extraction. For Go files, it uses the stdlib go/parser + go/ast for true AST-level parsing. For other languages, it uses enhanced regex patterns with scope-tracking to produce AST-like results.
This is a "tree-sitter-inspired" approach: it produces the same kinds of structured, scope-aware symbol extraction that tree-sitter would, without requiring any CGO dependencies.
func NewTreeSitterParser ¶ added in v0.2.0
func NewTreeSitterParser() *TreeSitterParser
NewTreeSitterParser creates a new parser with default settings.
func (*TreeSitterParser) ParseFile ¶ added in v0.2.0
func (p *TreeSitterParser) ParseFile(path string) ([]Symbol, error)
ParseFile dispatches to the appropriate language parser based on file extension.
func (*TreeSitterParser) ParseSource ¶ added in v0.2.0
func (p *TreeSitterParser) ParseSource(src, ext, path string) ([]Symbol, error)
ParseSource parses source code given its extension and optional path.
Source Files
¶
- api_scanner.go
- cache.go
- callgraph.go
- changeset.go
- cochange.go
- complexity.go
- dead_code.go
- depgraph.go
- doclint.go
- file_grouper.go
- gitignore.go
- health_score.go
- hierarchy.go
- imports.go
- incremental.go
- incremental_map.go
- interface_extract.go
- migration_detector.go
- navigation.go
- ownership.go
- pagerank.go
- parser.go
- parser_enhanced.go
- parser_langs.go
- patterns.go
- predict.go
- repomap.go
- rerank.go
- semantic.go
- semantic_search.go
- shapley.go
- smells.go
- summary.go
- treesitter.go
- watcher.go