chore: align slurp config and scaffolding

This commit is contained in:
anthonyrawlins
2025-09-27 21:03:12 +10:00
parent acc4361463
commit 4a77862289
47 changed files with 5133 additions and 4274 deletions

View File

@@ -1,7 +1,6 @@
package intelligence
import (
"bufio"
"bytes"
"context"
"fmt"
@@ -33,12 +32,12 @@ type CodeStructureAnalyzer struct {
// LanguagePatterns contains regex patterns for different language constructs
type LanguagePatterns struct {
Functions []*regexp.Regexp
Classes []*regexp.Regexp
Variables []*regexp.Regexp
Imports []*regexp.Regexp
Comments []*regexp.Regexp
TODOs []*regexp.Regexp
Functions []*regexp.Regexp
Classes []*regexp.Regexp
Variables []*regexp.Regexp
Imports []*regexp.Regexp
Comments []*regexp.Regexp
TODOs []*regexp.Regexp
}
// MetadataExtractor extracts file system metadata
@@ -65,66 +64,66 @@ func NewLanguageDetector() *LanguageDetector {
// Map file extensions to languages
extensions := map[string]string{
".go": "go",
".py": "python",
".js": "javascript",
".jsx": "javascript",
".ts": "typescript",
".tsx": "typescript",
".java": "java",
".c": "c",
".cpp": "cpp",
".cc": "cpp",
".cxx": "cpp",
".h": "c",
".hpp": "cpp",
".cs": "csharp",
".php": "php",
".rb": "ruby",
".rs": "rust",
".kt": "kotlin",
".swift": "swift",
".m": "objective-c",
".mm": "objective-c",
".scala": "scala",
".clj": "clojure",
".hs": "haskell",
".ex": "elixir",
".exs": "elixir",
".erl": "erlang",
".lua": "lua",
".pl": "perl",
".r": "r",
".sh": "shell",
".bash": "shell",
".zsh": "shell",
".fish": "shell",
".sql": "sql",
".html": "html",
".htm": "html",
".css": "css",
".scss": "scss",
".sass": "sass",
".less": "less",
".xml": "xml",
".json": "json",
".yaml": "yaml",
".yml": "yaml",
".toml": "toml",
".ini": "ini",
".cfg": "ini",
".conf": "config",
".md": "markdown",
".rst": "rst",
".tex": "latex",
".proto": "protobuf",
".tf": "terraform",
".hcl": "hcl",
".dockerfile": "dockerfile",
".go": "go",
".py": "python",
".js": "javascript",
".jsx": "javascript",
".ts": "typescript",
".tsx": "typescript",
".java": "java",
".c": "c",
".cpp": "cpp",
".cc": "cpp",
".cxx": "cpp",
".h": "c",
".hpp": "cpp",
".cs": "csharp",
".php": "php",
".rb": "ruby",
".rs": "rust",
".kt": "kotlin",
".swift": "swift",
".m": "objective-c",
".mm": "objective-c",
".scala": "scala",
".clj": "clojure",
".hs": "haskell",
".ex": "elixir",
".exs": "elixir",
".erl": "erlang",
".lua": "lua",
".pl": "perl",
".r": "r",
".sh": "shell",
".bash": "shell",
".zsh": "shell",
".fish": "shell",
".sql": "sql",
".html": "html",
".htm": "html",
".css": "css",
".scss": "scss",
".sass": "sass",
".less": "less",
".xml": "xml",
".json": "json",
".yaml": "yaml",
".yml": "yaml",
".toml": "toml",
".ini": "ini",
".cfg": "ini",
".conf": "config",
".md": "markdown",
".rst": "rst",
".tex": "latex",
".proto": "protobuf",
".tf": "terraform",
".hcl": "hcl",
".dockerfile": "dockerfile",
".dockerignore": "dockerignore",
".gitignore": "gitignore",
".vim": "vim",
".emacs": "emacs",
".gitignore": "gitignore",
".vim": "vim",
".emacs": "emacs",
}
for ext, lang := range extensions {
@@ -383,11 +382,11 @@ func (fa *DefaultFileAnalyzer) AnalyzeContent(ctx context.Context, filePath stri
// DetectLanguage detects programming language from content and file extension
func (fa *DefaultFileAnalyzer) DetectLanguage(ctx context.Context, filePath string, content []byte) (string, float64, error) {
ext := strings.ToLower(filepath.Ext(filePath))
// First try extension-based detection
if lang, exists := fa.languageDetector.extensionMap[ext]; exists {
confidence := 0.8 // High confidence for extension-based detection
// Verify with content signatures
if signatures, hasSignatures := fa.languageDetector.signatureRegexs[lang]; hasSignatures {
matches := 0
@@ -396,7 +395,7 @@ func (fa *DefaultFileAnalyzer) DetectLanguage(ctx context.Context, filePath stri
matches++
}
}
// Adjust confidence based on signature matches
if matches > 0 {
confidence = 0.9 + float64(matches)/float64(len(signatures))*0.1
@@ -404,14 +403,14 @@ func (fa *DefaultFileAnalyzer) DetectLanguage(ctx context.Context, filePath stri
confidence = 0.6 // Lower confidence if no signatures match
}
}
return lang, confidence, nil
}
// Fall back to content-based detection
bestLang := "unknown"
bestScore := 0
for lang, signatures := range fa.languageDetector.signatureRegexs {
score := 0
for _, regex := range signatures {
@@ -419,7 +418,7 @@ func (fa *DefaultFileAnalyzer) DetectLanguage(ctx context.Context, filePath stri
score++
}
}
if score > bestScore {
bestScore = score
bestLang = lang
@@ -499,9 +498,9 @@ func (fa *DefaultFileAnalyzer) IdentifyPurpose(ctx context.Context, analysis *Fi
filenameUpper := strings.ToUpper(filename)
// Configuration files
if strings.Contains(filenameUpper, "CONFIG") ||
strings.Contains(filenameUpper, "CONF") ||
analysis.FileType == ".ini" || analysis.FileType == ".toml" {
if strings.Contains(filenameUpper, "CONFIG") ||
strings.Contains(filenameUpper, "CONF") ||
analysis.FileType == ".ini" || analysis.FileType == ".toml" {
purpose = "Configuration management"
confidence = 0.9
return purpose, confidence, nil
@@ -509,9 +508,9 @@ func (fa *DefaultFileAnalyzer) IdentifyPurpose(ctx context.Context, analysis *Fi
// Test files
if strings.Contains(filenameUpper, "TEST") ||
strings.Contains(filenameUpper, "SPEC") ||
strings.HasSuffix(filenameUpper, "_TEST.GO") ||
strings.HasSuffix(filenameUpper, "_TEST.PY") {
strings.Contains(filenameUpper, "SPEC") ||
strings.HasSuffix(filenameUpper, "_TEST.GO") ||
strings.HasSuffix(filenameUpper, "_TEST.PY") {
purpose = "Testing and quality assurance"
confidence = 0.9
return purpose, confidence, nil
@@ -519,8 +518,8 @@ func (fa *DefaultFileAnalyzer) IdentifyPurpose(ctx context.Context, analysis *Fi
// Documentation files
if analysis.FileType == ".md" || analysis.FileType == ".rst" ||
strings.Contains(filenameUpper, "README") ||
strings.Contains(filenameUpper, "DOC") {
strings.Contains(filenameUpper, "README") ||
strings.Contains(filenameUpper, "DOC") {
purpose = "Documentation and guidance"
confidence = 0.9
return purpose, confidence, nil
@@ -528,8 +527,8 @@ func (fa *DefaultFileAnalyzer) IdentifyPurpose(ctx context.Context, analysis *Fi
// API files
if strings.Contains(filenameUpper, "API") ||
strings.Contains(filenameUpper, "ROUTER") ||
strings.Contains(filenameUpper, "HANDLER") {
strings.Contains(filenameUpper, "ROUTER") ||
strings.Contains(filenameUpper, "HANDLER") {
purpose = "API endpoint management"
confidence = 0.8
return purpose, confidence, nil
@@ -537,9 +536,9 @@ func (fa *DefaultFileAnalyzer) IdentifyPurpose(ctx context.Context, analysis *Fi
// Database files
if strings.Contains(filenameUpper, "DB") ||
strings.Contains(filenameUpper, "DATABASE") ||
strings.Contains(filenameUpper, "MODEL") ||
strings.Contains(filenameUpper, "SCHEMA") {
strings.Contains(filenameUpper, "DATABASE") ||
strings.Contains(filenameUpper, "MODEL") ||
strings.Contains(filenameUpper, "SCHEMA") {
purpose = "Data storage and management"
confidence = 0.8
return purpose, confidence, nil
@@ -547,9 +546,9 @@ func (fa *DefaultFileAnalyzer) IdentifyPurpose(ctx context.Context, analysis *Fi
// UI/Frontend files
if analysis.Language == "javascript" || analysis.Language == "typescript" ||
strings.Contains(filenameUpper, "COMPONENT") ||
strings.Contains(filenameUpper, "VIEW") ||
strings.Contains(filenameUpper, "UI") {
strings.Contains(filenameUpper, "COMPONENT") ||
strings.Contains(filenameUpper, "VIEW") ||
strings.Contains(filenameUpper, "UI") {
purpose = "User interface component"
confidence = 0.7
return purpose, confidence, nil
@@ -557,8 +556,8 @@ func (fa *DefaultFileAnalyzer) IdentifyPurpose(ctx context.Context, analysis *Fi
// Service/Business logic
if strings.Contains(filenameUpper, "SERVICE") ||
strings.Contains(filenameUpper, "BUSINESS") ||
strings.Contains(filenameUpper, "LOGIC") {
strings.Contains(filenameUpper, "BUSINESS") ||
strings.Contains(filenameUpper, "LOGIC") {
purpose = "Business logic implementation"
confidence = 0.7
return purpose, confidence, nil
@@ -566,8 +565,8 @@ func (fa *DefaultFileAnalyzer) IdentifyPurpose(ctx context.Context, analysis *Fi
// Utility files
if strings.Contains(filenameUpper, "UTIL") ||
strings.Contains(filenameUpper, "HELPER") ||
strings.Contains(filenameUpper, "COMMON") {
strings.Contains(filenameUpper, "HELPER") ||
strings.Contains(filenameUpper, "COMMON") {
purpose = "Utility and helper functions"
confidence = 0.7
return purpose, confidence, nil
@@ -591,7 +590,7 @@ func (fa *DefaultFileAnalyzer) IdentifyPurpose(ctx context.Context, analysis *Fi
// GenerateSummary generates a concise summary of file content
func (fa *DefaultFileAnalyzer) GenerateSummary(ctx context.Context, analysis *FileAnalysis) (string, error) {
summary := strings.Builder{}
// Language and type
if analysis.Language != "unknown" {
summary.WriteString(fmt.Sprintf("%s", strings.Title(analysis.Language)))
@@ -643,23 +642,23 @@ func (fa *DefaultFileAnalyzer) ExtractTechnologies(ctx context.Context, analysis
// Extract from file patterns
filename := strings.ToLower(filepath.Base(analysis.FilePath))
// Framework detection
frameworks := map[string]string{
"react": "React",
"vue": "Vue.js",
"angular": "Angular",
"express": "Express.js",
"django": "Django",
"flask": "Flask",
"spring": "Spring",
"gin": "Gin",
"echo": "Echo",
"fastapi": "FastAPI",
"bootstrap": "Bootstrap",
"tailwind": "Tailwind CSS",
"material": "Material UI",
"antd": "Ant Design",
"react": "React",
"vue": "Vue.js",
"angular": "Angular",
"express": "Express.js",
"django": "Django",
"flask": "Flask",
"spring": "Spring",
"gin": "Gin",
"echo": "Echo",
"fastapi": "FastAPI",
"bootstrap": "Bootstrap",
"tailwind": "Tailwind CSS",
"material": "Material UI",
"antd": "Ant Design",
}
for pattern, tech := range frameworks {
@@ -778,7 +777,7 @@ func (fa *DefaultFileAnalyzer) analyzeCodeStructure(analysis *FileAnalysis, cont
func (fa *DefaultFileAnalyzer) calculateComplexity(analysis *FileAnalysis) float64 {
complexity := 0.0
// Base complexity from structure
complexity += float64(len(analysis.Functions)) * 1.5
complexity += float64(len(analysis.Classes)) * 2.0
@@ -799,7 +798,7 @@ func (fa *DefaultFileAnalyzer) calculateComplexity(analysis *FileAnalysis) float
func (fa *DefaultFileAnalyzer) analyzeArchitecturalPatterns(analysis *StructureAnalysis, content []byte, patterns *LanguagePatterns, language string) {
contentStr := string(content)
// Detect common architectural patterns
if strings.Contains(contentStr, "interface") && language == "go" {
analysis.Patterns = append(analysis.Patterns, "Interface Segregation")
@@ -813,7 +812,7 @@ func (fa *DefaultFileAnalyzer) analyzeArchitecturalPatterns(analysis *StructureA
if strings.Contains(contentStr, "Observer") {
analysis.Patterns = append(analysis.Patterns, "Observer Pattern")
}
// Architectural style detection
if strings.Contains(contentStr, "http.") || strings.Contains(contentStr, "router") {
analysis.Architecture = "REST API"
@@ -832,13 +831,13 @@ func (fa *DefaultFileAnalyzer) mapImportToTechnology(importPath, language string
// Technology mapping based on common imports
techMap := map[string]string{
// Go
"gin-gonic/gin": "Gin",
"labstack/echo": "Echo",
"gorilla/mux": "Gorilla Mux",
"gorm.io/gorm": "GORM",
"github.com/redis": "Redis",
"go.mongodb.org": "MongoDB",
"gin-gonic/gin": "Gin",
"labstack/echo": "Echo",
"gorilla/mux": "Gorilla Mux",
"gorm.io/gorm": "GORM",
"github.com/redis": "Redis",
"go.mongodb.org": "MongoDB",
// Python
"django": "Django",
"flask": "Flask",
@@ -849,15 +848,15 @@ func (fa *DefaultFileAnalyzer) mapImportToTechnology(importPath, language string
"numpy": "NumPy",
"tensorflow": "TensorFlow",
"torch": "PyTorch",
// JavaScript/TypeScript
"react": "React",
"vue": "Vue.js",
"angular": "Angular",
"express": "Express.js",
"axios": "Axios",
"lodash": "Lodash",
"moment": "Moment.js",
"react": "React",
"vue": "Vue.js",
"angular": "Angular",
"express": "Express.js",
"axios": "Axios",
"lodash": "Lodash",
"moment": "Moment.js",
"socket.io": "Socket.IO",
}
@@ -868,4 +867,4 @@ func (fa *DefaultFileAnalyzer) mapImportToTechnology(importPath, language string
}
return ""
}
}