Documentation
¶
Index ¶
- func ContentHash(data []byte) string
- func EstimateTokens(text string) int
- func InitLanguageMap(settingsPaths []string)
- func InitLanguageMapFromConfigs(configs []lsp.LanguageConfig)
- func LanguageForExt(ext string) string
- func ListMarkdownFiles(brainDir, subdir string) []string
- func LogError(format string, args ...any)
- func LogInfo(format string, args ...any)
- func LogWarn(format string, args ...any)
- func ParseDependencies(root string) []string
- func ParseFile(filePath string, root string, language string) ([]SymbolInfo, []CallInfo)
- func ReadMarkdown(brainDir, relativePath string) string
- func RegisterBrainHandlers(register func(string, func(map[string]any) (map[string]any, error)), ...)
- func ReloadLanguageMap(languagesPaths []string)
- func RunPhase2(ctx context.Context, cred config.Credential, root string, index *BrainIndex, ...) error
- func SymbolID(filePath, name, kind string) string
- func TruncateToTokens(text string, maxTokens int) string
- func WriteMarkdown(brainDir, relativePath, content string) error
- type BrainIndex
- type CallInfo
- type DeepDiveMeta
- type FileInfo
- type FrameworkResult
- type HubFile
- type ImportInfo
- type ProjectMeta
- type SymbolInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContentHash ¶
ContentHash returns the SHA-256 hex digest of data.
func EstimateTokens ¶
EstimateTokens gives a rough token count (~4 chars per token).
func InitLanguageMap ¶
func InitLanguageMap(settingsPaths []string)
InitLanguageMap loads the extension→language mapping from the given settings.json paths (in load order, later entries override earlier by language Name). Must be called before LanguageForExt (typically at brain init or daemon startup). Safe to call multiple times; only the first call takes effect.
func InitLanguageMapFromConfigs ¶
func InitLanguageMapFromConfigs(configs []lsp.LanguageConfig)
InitLanguageMapFromConfigs initializes the ext→language map directly from configs. Useful in tests where settings.json may not be available.
func LanguageForExt ¶
LanguageForExt returns the language name for a file extension (e.g. ".go" → "go"). Returns "" if the extension is not recognized. Uses the LSP pool if initialized, otherwise falls back to the pre-loaded ext map.
func ListMarkdownFiles ¶
ListMarkdownFiles lists all .md files in a subdirectory of the brain dir.
func ParseDependencies ¶
ParseDependencies extracts external dependency names from common config files.
func ParseFile ¶
func ParseFile(filePath string, root string, language string) ([]SymbolInfo, []CallInfo)
ParseFile extracts symbols from a single file via LSP. Returns symbols and nil calls.
func ReadMarkdown ¶
ReadMarkdown reads a markdown file from the brain directory. Returns "" if missing.
func RegisterBrainHandlers ¶
func RegisterBrainHandlers(register func(string, func(map[string]any) (map[string]any, error)), cred config.Credential, ctx context.Context)
RegisterBrainHandlers registers brain.* command handlers with the daemon.
func ReloadLanguageMap ¶ added in v0.4.2
func ReloadLanguageMap(languagesPaths []string)
ReloadLanguageMap rebuilds the ext→language map from the given paths, unconditionally replacing any previously-loaded map. Unlike InitLanguageMap it is not one-shot — the daemon config watcher calls it when config/languages.json changes on disk.
func RunPhase2 ¶
func RunPhase2(ctx context.Context, cred config.Credential, root string, index *BrainIndex, brainDir string) error
RunPhase2 runs all Phase 2 semantic analysis.
func TruncateToTokens ¶
TruncateToTokens truncates text to approximately maxTokens.
func WriteMarkdown ¶
WriteMarkdown writes a markdown file within the brain directory.
Types ¶
type BrainIndex ¶
type BrainIndex struct {
Project ProjectMeta `json:"project"`
Files []FileInfo `json:"files"`
Symbols []SymbolInfo `json:"symbols"`
Imports []ImportInfo `json:"imports"`
Calls []CallInfo `json:"calls"`
HubFiles []HubFile `json:"hub_files"`
}
BrainIndex is the root model serialized to index.json.
type CallInfo ¶
type CallInfo struct {
CallerID string `json:"caller_id"`
CalleeName string `json:"callee_name"`
FilePath string `json:"file_path"`
}
CallInfo represents a function/method call.
type DeepDiveMeta ¶
DeepDiveMeta holds the frontmatter metadata from a deep dive file.
func ReadMarkdownFrontmatter ¶
func ReadMarkdownFrontmatter(brainDir, relativePath string) (DeepDiveMeta, string)
ReadMarkdownFrontmatter reads a markdown file and parses YAML frontmatter. Returns the parsed meta and the body (everything after the closing ---). If no frontmatter is present, returns empty meta and the full content as body.
type FileInfo ¶
type FileInfo struct {
Path string `json:"path"`
Language string `json:"language"`
SizeBytes int `json:"size_bytes"`
LineCount int `json:"line_count"`
SHA256 string `json:"sha256"`
IsEntryPoint bool `json:"is_entry_point"`
IsConfig bool `json:"is_config"`
IsTest bool `json:"is_test"`
}
FileInfo holds metadata for a single project file.
func ScanProject ¶
ScanProject crawls the project directory and returns FileInfo for every source file.
func ScanSingleFile ¶
ScanSingleFile scans a single file and returns its FileInfo, or nil if not valid.
type FrameworkResult ¶
type FrameworkResult struct {
Frameworks []string `json:"frameworks"`
Patterns []string `json:"patterns"`
Testing []string `json:"testing"`
CICD []string `json:"ci_cd"`
}
FrameworkResult holds detection results for frameworks, patterns, testing, and CI/CD.
func DetectFrameworks ¶
func DetectFrameworks(root string, files []FileInfo, externalDeps []string) FrameworkResult
DetectFrameworks heuristically detects frameworks, patterns, testing, and CI/CD.
type HubFile ¶
HubFile represents a highly-imported file.
func FindHubFiles ¶
func FindHubFiles(imports []ImportInfo, topN int) []HubFile
FindHubFiles returns the top N most-imported internal files.
type ImportInfo ¶
type ImportInfo struct {
SourceFile string `json:"source_file"`
TargetFile string `json:"target_file"`
Module string `json:"module"`
IsExternal bool `json:"is_external"`
}
ImportInfo represents an import edge in the dependency graph.
func BuildImportGraph ¶
func BuildImportGraph(root string, files []FileInfo) []ImportInfo
BuildImportGraph extracts import statements and resolves internal targets via LSP.
func ExtractFileImports ¶
func ExtractFileImports(source, filePath string, filePaths map[string]bool, root, language string) []ImportInfo
ExtractFileImports extracts imports from a single file's source.
type ProjectMeta ¶
type ProjectMeta struct {
Name string `json:"name"`
RootPath string `json:"root_path"`
TotalFiles int `json:"total_files"`
TotalLines int `json:"total_lines"`
Languages map[string]int `json:"languages"`
EntryPoints []string `json:"entry_points"`
ConfigFiles []string `json:"config_files"`
ExternalDeps []string `json:"external_deps"`
Frameworks []string `json:"frameworks"`
Patterns []string `json:"patterns"`
TestingFrameworks []string `json:"testing_frameworks"`
CICD []string `json:"ci_cd"`
}
ProjectMeta holds project-level metadata.
type SymbolInfo ¶
type SymbolInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Kind string `json:"kind"` // LSP SymbolKind name: "Function", "Method", "Class", "Struct", "Interface", etc.
FilePath string `json:"file_path"`
LineStart int `json:"line_start"`
LineEnd int `json:"line_end"`
Parameters []string `json:"parameters"`
ReturnType string `json:"return_type"`
Decorators []string `json:"decorators"`
Docstring string `json:"docstring"`
Complexity int `json:"complexity"`
Parent string `json:"parent"`
}
SymbolInfo represents an extracted symbol (function, class, method).