Documentation
¶
Index ¶
- Constants
- func LanguageFileExtensions(language string) []string
- type Cache
- type Detector
- type FileState
- type FileWatcher
- type Info
- type LanguageDetector
- type Manager
- func (m *Manager) DetectWorkspace(params map[string]interface{}) (*Info, error)
- func (m *Manager) EnsureWorkspaceIndexed(ctx context.Context, rootPath string) error
- func (m *Manager) GetAllIndexedCollectionNames() []string
- func (m *Manager) GetAllIndexedMemories() []memory.LongTermMemory
- func (m *Manager) GetMemoriesForAllLanguages(ctx context.Context, info *Info) (map[string]memory.LongTermMemory, error)
- func (m *Manager) GetMemoryForWorkspace(ctx context.Context, info *Info) (memory.LongTermMemory, error)
- func (m *Manager) GetMemoryForWorkspaceLanguage(ctx context.Context, info *Info, language string) (memory.LongTermMemory, error)
- func (m *Manager) IndexLanguage(ctx context.Context, info *Info, language string, collectionName string) error
- func (m *Manager) IsIndexing(workspaceID string) bool
- func (m *Manager) NeedsReindex(info *Info, language string) (bool, error)
- func (m *Manager) SearchAllWorkspaces(ctx context.Context, queryEmbedding []float64, limit int) ([]memory.Document, error)
- func (m *Manager) StartIndexing(ctx context.Context, info *Info, language string) error
- func (m *Manager) StartWatcher(root string)
- type Metadata
- type WorkspaceState
Examples ¶
Constants ¶
const ( StatusIndexed = "indexed" StatusIndexing = "indexing" StatusFailed = "failed" StatusPending = "pending" )
IndexingStatus represents possible indexing states
Variables ¶
This section is empty.
Functions ¶
func LanguageFileExtensions ¶
LanguageFileExtensions returns the file extensions for a given language
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache provides caching for workspace detection results
Example ¶
package main
import (
"fmt"
"time"
"github.com/doITmagic/rag-code-mcp/internal/workspace"
)
func main() {
// Create cache with 5 minute TTL
cache := workspace.NewCache(5 * time.Minute)
detector := workspace.NewDetector()
// Function to get or detect workspace
getWorkspace := func(filePath string) (*workspace.Info, error) {
// Try cache first
if cached := cache.Get(filePath); cached != nil {
return cached, nil
}
// Detect and cache
info, err := detector.DetectFromPath(filePath)
if err != nil {
return nil, err
}
cache.Set(filePath, info)
return info, nil
}
// First call - detects and caches
info1, _ := getWorkspace("/home/user/project/main.go")
fmt.Printf("First call: %s\n", info1.Root)
// Second call - from cache (fast)
info2, _ := getWorkspace("/home/user/project/main.go")
fmt.Printf("Second call (cached): %s\n", info2.Root)
// Periodic cleanup
go func() {
ticker := time.NewTicker(10 * time.Minute)
defer ticker.Stop()
for range ticker.C {
removed := cache.CleanExpired()
fmt.Printf("Cleaned %d expired entries\n", removed)
}
}()
}
func (*Cache) CleanExpired ¶
CleanExpired removes expired entries from cache
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
Detector detects workspace roots from file paths
func NewDetector ¶
func NewDetector() *Detector
NewDetector creates a new workspace detector with default markers
func NewDetectorWithConfig ¶
NewDetectorWithConfig creates a detector with configuration
func (*Detector) DetectFromParams ¶
DetectFromParams detects workspace from MCP tool parameters Looks for file paths in common parameter names
Example ¶
package main
import (
"fmt"
"log"
"github.com/doITmagic/rag-code-mcp/internal/workspace"
)
func main() {
detector := workspace.NewDetector()
// Simulate MCP tool parameters
params := map[string]interface{}{
"file_path": "/home/user/projects/my-app/internal/handlers/user.go",
"query": "user authentication",
}
info, err := detector.DetectFromParams(params)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Detected workspace: %s\n", info.Root)
fmt.Printf("Collection: %s\n", info.CollectionName())
}
func (*Detector) DetectFromPath ¶
DetectFromPath detects workspace from a file path
Example ¶
package main
import (
"fmt"
"log"
"github.com/doITmagic/rag-code-mcp/internal/workspace"
)
func main() {
detector := workspace.NewDetector()
// Detect workspace from a file path
info, err := detector.DetectFromPath("/home/user/projects/my-app/src/main.go")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Workspace root: %s\n", info.Root)
fmt.Printf("Workspace ID: %s\n", info.ID)
fmt.Printf("Project type: %s\n", info.ProjectType)
fmt.Printf("Collection name: %s\n", info.CollectionName())
}
func (*Detector) SetExcludePatterns ¶
SetExcludePatterns sets path patterns to exclude
func (*Detector) SetMarkers ¶
SetMarkers allows customizing workspace markers
Example ¶
package main
import (
"fmt"
"github.com/doITmagic/rag-code-mcp/internal/workspace"
)
func main() {
detector := workspace.NewDetector()
// Customize workspace markers for specific use case
detector.SetMarkers([]string{
".git",
"package.json",
"deno.json", // Add custom marker
})
// Set exclusion patterns
detector.SetExcludePatterns([]string{
"/node_modules/",
"/dist/",
"/.next/",
})
info, _ := detector.DetectFromPath("/home/user/deno-project/src/main.ts")
fmt.Printf("Custom detection: %s\n", info.Root)
}
type FileState ¶
type FileState struct {
// Test comment for incremental indexing
ModTime time.Time `json:"mod_time"`
Size int64 `json:"size"`
}
FileState represents the state of a single file
type FileWatcher ¶
type FileWatcher struct {
// contains filtered or unexported fields
}
FileWatcher handles file system notifications for a workspace
func NewFileWatcher ¶
func NewFileWatcher(root string, manager *Manager) (*FileWatcher, error)
NewFileWatcher creates a new file watcher for the given root directory
func (*FileWatcher) Stop ¶
func (fw *FileWatcher) Stop()
type Info ¶
type Info struct {
// Root is the absolute path to the workspace root directory
Root string `json:"root"`
// ID is a stable, unique identifier for this workspace (hash of Root)
ID string `json:"id"`
// ProjectType indicates the detected project type (go, node, python, etc.)
ProjectType string `json:"project_type,omitempty"`
// Languages is the list of programming languages detected in this workspace
// For polyglot workspaces (e.g., Go + Python microservices)
Languages []string `json:"languages,omitempty"`
// Markers are the workspace markers found (e.g., ".git", "go.mod")
Markers []string `json:"markers,omitempty"`
// DetectedAt is when this workspace was first detected
DetectedAt time.Time `json:"detected_at,omitempty"`
// CollectionPrefix is the prefix used for this workspace's collection
// Set by Manager based on config
CollectionPrefix string `json:"collection_prefix,omitempty"`
}
Info contains information about a detected workspace
func (*Info) CollectionName ¶
CollectionName returns the Qdrant collection name for this workspace Deprecated: Use CollectionNameForLanguage instead for multi-language support
func (*Info) CollectionNameForLanguage ¶
CollectionNameForLanguage returns the Qdrant collection name for a specific language in this workspace Format: {prefix}-{workspaceID}-{language} Example: ragcode-a1b2c3d4e5f6-go, ragcode-a1b2c3d4e5f6-python
type LanguageDetector ¶
type LanguageDetector struct{}
LanguageDetector detects programming languages in a workspace
func NewLanguageDetector ¶
func NewLanguageDetector() *LanguageDetector
NewLanguageDetector creates a new language detector
func (*LanguageDetector) DetectLanguages ¶
func (ld *LanguageDetector) DetectLanguages(rootPath string) ([]string, error)
DetectLanguages scans a workspace and returns detected programming languages Returns a slice of language identifiers (e.g., "go", "python", "php")
func (*LanguageDetector) GetPrimaryLanguage ¶
func (ld *LanguageDetector) GetPrimaryLanguage(rootPath string, markers []string) string
GetPrimaryLanguage returns the primary language based on project markers This is a heuristic-based approach for workspace-level detection
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages workspace detection, collection management, and indexing
func NewManager ¶
NewManager creates a new workspace manager
func (*Manager) DetectWorkspace ¶
DetectWorkspace detects workspace from tool parameters
func (*Manager) EnsureWorkspaceIndexed ¶
EnsureWorkspaceIndexed triggers indexing for all detected languages in the workspace
func (*Manager) GetAllIndexedCollectionNames ¶
GetAllIndexedCollectionNames returns the names of all indexed collections
func (*Manager) GetAllIndexedMemories ¶
func (m *Manager) GetAllIndexedMemories() []memory.LongTermMemory
GetAllIndexedMemories returns all indexed workspace memories This is useful for searching across all workspaces when no specific file_path is provided
func (*Manager) GetMemoriesForAllLanguages ¶
func (m *Manager) GetMemoriesForAllLanguages(ctx context.Context, info *Info) (map[string]memory.LongTermMemory, error)
GetMemoriesForAllLanguages returns memory instances for all detected languages in the workspace Creates collections and triggers indexing if needed
func (*Manager) GetMemoryForWorkspace ¶
func (m *Manager) GetMemoryForWorkspace(ctx context.Context, info *Info) (memory.LongTermMemory, error)
GetMemoryForWorkspace returns a memory instance for the workspace Creates collection and triggers indexing if needed Deprecated: Use GetMemoryForWorkspaceLanguage for multi-language support
func (*Manager) GetMemoryForWorkspaceLanguage ¶
func (m *Manager) GetMemoryForWorkspaceLanguage(ctx context.Context, info *Info, language string) (memory.LongTermMemory, error)
GetMemoryForWorkspaceLanguage returns a memory instance for a specific language in the workspace Creates collection and triggers indexing if needed
func (*Manager) IndexLanguage ¶
func (m *Manager) IndexLanguage(ctx context.Context, info *Info, language string, collectionName string) error
IndexLanguage indexes a specific language in a workspace It runs synchronously. Use StartIndexing for background execution.
func (*Manager) IsIndexing ¶
IsIndexing checks if a workspace is currently being indexed
func (*Manager) NeedsReindex ¶
NeedsReindex rescans the workspace and determines if tracked files changed for the language. Returns true when changes are detected or no previous fingerprint exists.
func (*Manager) SearchAllWorkspaces ¶
func (m *Manager) SearchAllWorkspaces(ctx context.Context, queryEmbedding []float64, limit int) ([]memory.Document, error)
SearchAllWorkspaces searches across all indexed workspace collections Returns aggregated results from all workspaces
func (*Manager) StartIndexing ¶
StartIndexing explicitly starts background indexing for a workspace language This is used by the index_workspace tool to manually trigger indexing
func (*Manager) StartWatcher ¶
StartWatcher starts the file watcher for a workspace if not already running
type Metadata ¶
type Metadata struct {
WorkspaceID string `json:"workspace_id"`
RootPath string `json:"root_path"`
Language string `json:"language"` // Programming language (go, python, php, etc.)
LastIndexed time.Time `json:"last_indexed"`
FileCount int `json:"file_count"`
ChunkCount int `json:"chunk_count"`
Status string `json:"status"` // "indexed", "indexing", "failed"
ProjectType string `json:"project_type,omitempty"`
Markers []string `json:"markers,omitempty"`
ErrorMessage string `json:"error_message,omitempty"`
}
Metadata represents workspace metadata stored in Qdrant
type WorkspaceState ¶
type WorkspaceState struct {
Files map[string]FileState `json:"files"`
LastIndexed time.Time `json:"last_indexed"`
// contains filtered or unexported fields
}
WorkspaceState tracks the state of files in a workspace
func LoadState ¶
func LoadState(path string) (*WorkspaceState, error)
LoadState loads workspace state from disk
func NewWorkspaceState ¶
func NewWorkspaceState() *WorkspaceState
NewWorkspaceState creates a new workspace state
func (*WorkspaceState) GetFileState ¶
func (s *WorkspaceState) GetFileState(path string) (FileState, bool)
GetFileState returns the state of a file
func (*WorkspaceState) RemoveFile ¶
func (s *WorkspaceState) RemoveFile(path string)
RemoveFile removes a file from the state
func (*WorkspaceState) Save ¶
func (s *WorkspaceState) Save(path string) error
SaveState saves workspace state to disk
func (*WorkspaceState) UpdateFile ¶
func (s *WorkspaceState) UpdateFile(path string, info os.FileInfo)
UpdateFile updates the state for a file