Documentation
¶
Index ¶
- func FormatCoverageResponse(report *CoverageReport) string
- func FormatSymbolDrift(drifts []SymbolDrift) string
- func IsExcludedDir(name string) bool
- func RenderRepoMap(rm *RepoMap, maxTokens int) string
- type CCppLang
- type CoverageReport
- type CoverageStatus
- type FileSymbols
- type GoLang
- type IgnoreChecker
- type ImportEdge
- type ImportParser
- type JSTSLang
- type Module
- type ModuleCoverage
- type ModuleDetector
- type ModuleGovernanceGap
- type ModuleImpactInfo
- type PythonLang
- type Registry
- type RepoMap
- type RustLang
- type Scanner
- func (s *Scanner) GetDependents(ctx context.Context, moduleID string) ([]string, error)
- func (s *Scanner) GetModules(ctx context.Context) ([]Module, error)
- func (s *Scanner) ModulesLastScanned(ctx context.Context) time.Time
- func (s *Scanner) ResolveFileToModule(ctx context.Context, filePath string) (string, error)
- func (s *Scanner) ScanDependencies(ctx context.Context, projectRoot string) ([]ImportEdge, error)
- func (s *Scanner) ScanModules(ctx context.Context, projectRoot string) ([]Module, error)
- type Symbol
- type SymbolDrift
- type SymbolSnapshot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatCoverageResponse ¶
func FormatCoverageResponse(report *CoverageReport) string
FormatCoverageResponse formats the coverage report for MCP output.
func FormatSymbolDrift ¶
func FormatSymbolDrift(drifts []SymbolDrift) string
FormatSymbolDrift renders drift report for display.
func IsExcludedDir ¶
IsExcludedDir checks if a directory should be skipped during walking. Uses the IgnoreChecker if available, otherwise falls back to the dir name check.
func RenderRepoMap ¶
RenderRepoMap formats the repo map for injection into the system prompt. Shows directory tree with exported symbols, kinds, and line counts. Files sorted by modification time (recent first) for relevance. Respects a token budget (approximate: 4 chars ≈ 1 token).
Types ¶
type CCppLang ¶
type CCppLang struct{}
CCppLang implements ModuleDetector and ImportParser for C/C++ projects.
func (*CCppLang) DetectModules ¶
DetectModules discovers C/C++ modules by reading compile_commands.json, falling back to directory-based heuristics with Makefile/CMakeLists.txt markers.
func (*CCppLang) Extensions ¶
func (*CCppLang) ParseImports ¶
func (c *CCppLang) ParseImports(filePath string, projectRoot string) ([]ImportEdge, error)
ParseImports extracts #include "..." edges from a C/C++ source file. System includes (#include <...>) are skipped since they're external.
type CoverageReport ¶
type CoverageReport struct {
TotalModules int
CoveredCount int
PartialCount int
BlindCount int
Modules []ModuleCoverage
}
CoverageReport is the full coverage report for a project.
func ComputeCoverage ¶
ComputeCoverage calculates decision coverage for all modules. It joins codebase_modules with affected_files via path prefix matching.
type CoverageStatus ¶
type CoverageStatus string
CoverageStatus represents how well a module is governed by decisions.
const ( CoverageCovered CoverageStatus = "covered" // ≥1 active decision covers files in this module CoveragePartial CoverageStatus = "partial" // has decisions but they're stale or low R_eff CoverageBlind CoverageStatus = "blind" // no decisions reference files in this module )
type FileSymbols ¶
type FileSymbols struct {
Path string // relative path from project root
Language string // "go", "python", "javascript", "typescript", "rust", "c", "cpp"
Lines int // total line count
Symbols []Symbol // extracted symbols, sorted by line
ModTime int64 // modification time (unix nano) for recency sorting
}
FileSymbols holds symbols extracted from a single file.
type GoLang ¶
type GoLang struct{}
GoLang implements ModuleDetector and ImportParser for Go projects.
func (*GoLang) DetectModules ¶
DetectModules discovers Go packages by walking directories for .go files. Each directory containing .go files (excluding _test.go-only dirs) is a module.
func (*GoLang) Extensions ¶
func (*GoLang) ParseImports ¶
func (g *GoLang) ParseImports(filePath string, projectRoot string) ([]ImportEdge, error)
ParseImports extracts import edges from a Go source file using go/parser.
type IgnoreChecker ¶
type IgnoreChecker struct {
// contains filtered or unexported fields
}
IgnoreChecker determines if paths should be excluded from scanning. It respects .gitignore (local + global), .haftignore, and a minimal set of hardcoded dirs that should always be skipped (.git, .haft).
func GetIgnoreChecker ¶
func GetIgnoreChecker(projectRoot string) *IgnoreChecker
GetIgnoreChecker returns a cached IgnoreChecker for the given project root.
func NewIgnoreChecker ¶
func NewIgnoreChecker(projectRoot string) *IgnoreChecker
NewIgnoreChecker builds an IgnoreChecker for the given project root. Reads .gitignore, global git ignore files, and .haftignore.
func (*IgnoreChecker) IsIgnored ¶
func (ic *IgnoreChecker) IsIgnored(relPath string) bool
IsIgnored returns true if the relative path should be excluded.
type ImportEdge ¶
type ImportEdge struct {
SourceModule string // module that imports
TargetModule string // module being imported
SourceFile string // file containing the import
ImportPath string // raw import path as written in source
}
ImportEdge represents a dependency between two modules.
type ImportParser ¶
type ImportParser interface {
// ParseImports extracts import edges from a single source file.
// Returns edges with raw import paths. Caller resolves to modules.
ParseImports(filePath string, projectRoot string) ([]ImportEdge, error)
// Extensions returns file extensions this parser handles.
Extensions() []string
}
ImportParser extracts import/dependency edges from source files.
type JSTSLang ¶
type JSTSLang struct{}
JSTSLang implements ModuleDetector and ImportParser for JavaScript/TypeScript.
func (*JSTSLang) DetectModules ¶
DetectModules discovers JS/TS packages by looking for package.json files. Handles monorepo workspaces.
func (*JSTSLang) Extensions ¶
func (*JSTSLang) ParseImports ¶
func (j *JSTSLang) ParseImports(filePath string, projectRoot string) ([]ImportEdge, error)
ParseImports extracts import/require edges from a JS/TS file.
type Module ¶
type Module struct {
ID string // auto-generated from path, e.g., "mod-internal-auth"
Path string // relative path from project root
Name string // human-readable name, e.g., "auth"
Lang string // go, js, ts, python, rust, mixed, unknown
FileCount int // number of source files
}
Module represents a detected module/package in the codebase.
type ModuleCoverage ¶
type ModuleCoverage struct {
Module Module
Status CoverageStatus
DecisionCount int
DecisionIDs []string
}
ModuleCoverage describes the decision coverage for a single module.
type ModuleDetector ¶
type ModuleDetector interface {
// DetectModules walks the project and returns discovered modules.
DetectModules(projectRoot string) ([]Module, error)
// Language returns the language this detector handles.
Language() string
}
ModuleDetector discovers module/package boundaries in a project.
type ModuleGovernanceGap ¶
ModuleGovernanceGap reports that a module touched by a new decision has no prior active decision coverage.
func FindFirstDecisionModules ¶
func FindFirstDecisionModules(ctx context.Context, db *sql.DB, affectedFiles []string) ([]ModuleGovernanceGap, error)
FindFirstDecisionModules returns touched modules that currently have no active decision coverage. The caller can use this to warn that a decision is establishing the first explicit architectural context for a module.
type ModuleImpactInfo ¶
type ModuleImpactInfo struct {
ModuleID string
ModulePath string
DecisionIDs []string
IsBlind bool
}
ModuleImpactInfo describes a module affected by dependency propagation.
func EnrichDriftWithImpact ¶
func EnrichDriftWithImpact(ctx context.Context, db *sql.DB, driftFiles []string) ([]ModuleImpactInfo, error)
EnrichDriftWithImpact adds dependency propagation to drift reports. For each drifted file, resolves to a module, finds dependents, and looks up their decisions.
type PythonLang ¶
type PythonLang struct{}
PythonLang implements ModuleDetector and ImportParser for Python projects.
func (*PythonLang) DetectModules ¶
func (p *PythonLang) DetectModules(projectRoot string) ([]Module, error)
DetectModules discovers Python packages by looking for __init__.py or pyproject.toml.
func (*PythonLang) Extensions ¶
func (p *PythonLang) Extensions() []string
func (*PythonLang) Language ¶
func (p *PythonLang) Language() string
func (*PythonLang) ParseImports ¶
func (p *PythonLang) ParseImports(filePath string, projectRoot string) ([]ImportEdge, error)
ParseImports extracts import edges from a Python source file.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maps file extensions to language detectors and import parsers.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates a registry with all supported languages.
func (*Registry) Detectors ¶
func (r *Registry) Detectors() []ModuleDetector
Detectors returns all registered module detectors.
func (*Registry) ParserForFile ¶
func (r *Registry) ParserForFile(path string) ImportParser
ParserForFile returns the import parser for a file, or nil if unsupported.
type RepoMap ¶
type RepoMap struct {
Files []FileSymbols
TotalFiles int
TotalSyms int
}
RepoMap is the complete symbol map for a repository.
type RustLang ¶
type RustLang struct{}
RustLang implements ModuleDetector and ImportParser for Rust projects.
func (*RustLang) DetectModules ¶
DetectModules discovers Rust crates/modules by looking for Cargo.toml and mod.rs/lib.rs.
func (*RustLang) Extensions ¶
func (*RustLang) ParseImports ¶
func (r *RustLang) ParseImports(filePath string, projectRoot string) ([]ImportEdge, error)
ParseImports extracts use/mod edges from a Rust source file.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner detects modules and builds the dependency graph for a project.
func (*Scanner) GetDependents ¶
GetDependents returns modules that depend on the given module (1-hop).
func (*Scanner) GetModules ¶
GetModules returns all stored modules.
func (*Scanner) ModulesLastScanned ¶
ModulesLastScanned returns the time of the last module scan, or zero if never scanned.
func (*Scanner) ResolveFileToModule ¶
ResolveFileToModule finds the most specific module for a file path (longest prefix match).
func (*Scanner) ScanDependencies ¶
ScanDependencies parses imports across all modules and builds the dependency graph.
type Symbol ¶
type Symbol struct {
Name string // symbol name
Kind string // "func", "type", "interface", "class", "method", "const"
Line int // 1-based line number
Exported bool // starts with uppercase (Go) or is exported
}
Symbol represents an extracted code symbol (function, type, class, etc.)
type SymbolDrift ¶
type SymbolDrift struct {
FilePath string `json:"file_path"`
SymbolName string `json:"symbol_name"`
SymbolKind string `json:"symbol_kind"`
Status string `json:"status"` // "unchanged", "modified", "added", "removed"
OldLine int `json:"old_line,omitempty"`
NewLine int `json:"new_line,omitempty"`
}
SymbolDrift describes how a single symbol changed between baseline and current.
func CompareSymbolSnapshots ¶
func CompareSymbolSnapshots(baseline []SymbolSnapshot, current []SymbolSnapshot) []SymbolDrift
CompareSymbolSnapshots compares baseline snapshots against current state.
type SymbolSnapshot ¶
type SymbolSnapshot struct {
FilePath string `json:"file_path"`
SymbolName string `json:"symbol_name"`
SymbolKind string `json:"symbol_kind"` // func, type, class, interface, method
Line int `json:"line"` // 1-based start line
EndLine int `json:"end_line"` // 1-based end line
Hash string `json:"hash"` // SHA256 of the symbol's source text
}
SymbolSnapshot captures a symbol's identity and content hash at a point in time.
func ExtractSymbolSnapshots ¶
func ExtractSymbolSnapshots(projectRoot, relPath string) ([]SymbolSnapshot, error)
ExtractSymbolSnapshots extracts symbol-level hashes from a file using tree-sitter. Returns one snapshot per symbol, each with a content hash of the symbol's source text.