Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
Fix community issues #15, #17, #20 and add editor support #19
Martin Vogele292f875a9a9
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex e3c805abb..a12363189 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -67,8 +67,10 @@ jobs:env:VERSION: ${{ inputs.version }}run: |+ # Strip leading 'v' — version var should be bare semver (e.g. 0.4.0)+ CLEAN_VERSION="${VERSION#v}"CGO_ENABLED=1 go build \- -ldflags "-X main.version=$VERSION" \+ -ldflags "-X main.version=$CLEAN_VERSION" \-o codebase-memory-mcp \./cmd/codebase-memory-mcp/@@ -111,8 +113,10 @@ jobs:env:VERSION: ${{ inputs.version }}run: |+ # Strip leading 'v' — version var should be bare semver (e.g. 0.4.0)+ CLEAN_VERSION="${VERSION#v}"CGO_ENABLED=1 CC=gcc go build \- -ldflags "-X main.version=$VERSION" \+ -ldflags "-X main.version=$CLEAN_VERSION" \-o codebase-memory-mcp.exe \./cmd/codebase-memory-mcp/diff --git a/cmd/codebase-memory-mcp/install.go b/cmd/codebase-memory-mcp/install.goindex ec3e79df9..4379e0cc0 100644--- a/cmd/codebase-memory-mcp/install.go+++ b/cmd/codebase-memory-mcp/install.go@@ -70,7 +70,16 @@ func runInstall(args []string) int {// WindsurfinstallEditorMCP(binaryPath, windsurfConfigPath(), "Windsurf", cfg)- fmt.Println("\nDone. Restart Claude Code / Codex / Cursor / Windsurf to activate.")+ // Gemini CLI (same mcpServers format as Cursor/Windsurf)+ installEditorMCP(binaryPath, geminiConfigPath(), "Gemini CLI", cfg)++ // VS Code Copilot (uses "servers" key with "type" field)+ installVSCodeMCP(binaryPath, vscodeConfigPath(), cfg)++ // Zed (uses "context_servers" key with "source" field)+ installZedMCP(binaryPath, zedConfigPath(), cfg)++ fmt.Println("\nDone. Restart your editor/CLI to activate.")return 0}@@ -106,6 +115,15 @@ func runUninstall(args []string) int {// WindsurfremoveEditorMCP(windsurfConfigPath(), "Windsurf", cfg)+ // Gemini CLI+ removeEditorMCP(geminiConfigPath(), "Gemini CLI", cfg)++ // VS Code Copilot+ removeVSCodeMCP(vscodeConfigPath(), cfg)++ // Zed+ removeZedMCP(zedConfigPath(), cfg)+fmt.Println("\nDone. Binary and databases were NOT removed.")return 0}@@ -597,3 +615,235 @@ func removeEditorMCP(configPath, editorName string, cfg installConfig) {}fmt.Printf(" ✓ Removed %s from %s\n", mcpServerKey, configPath)}++// --- Gemini CLI ---++// geminiConfigPath returns the Gemini CLI settings path.+func geminiConfigPath() string {+ home, err := os.UserHomeDir()+ if err != nil {+ return ""+ }+ return filepath.Join(home, ".gemini", "settings.json")+}++// --- VS Code Copilot ---++// vscodeConfigPath returns the VS Code user-level MCP config path.+func vscodeConfigPath() string {+ home, err := os.UserHomeDir()+ if err != nil {+ return ""+ }+ switch runtime.GOOS {+ case "darwin":+ return filepath.Join(home, "Library", "Application Support", "Code", "User", "mcp.json")+ case "linux":+ return filepath.Join(home, ".config", "Code", "User", "mcp.json")+ case "windows":+ if appData := os.Getenv("APPDATA"); appData != "" {+ return filepath.Join(appData, "Code", "User", "mcp.json")+ }+ }+ return ""+}++// installVSCodeMCP upserts our MCP server in VS Code's mcp.json (uses "servers" key).+func installVSCodeMCP(binaryPath, configPath string, cfg installConfig) {+ if configPath == "" {+ return+ }++ fmt.Printf("[VS Code] MCP config: %s\n", configPath)++ if cfg.dryRun {+ fmt.Printf(" [dry-run] Would upsert %s in %s\n", mcpServerKey, configPath)+ return+ }++ root := make(map[string]any)+ if data, err := os.ReadFile(configPath); err == nil {+ if jsonErr := json.Unmarshal(data, &root); jsonErr != nil {+ fmt.Printf(" ⚠ Invalid JSON in %s, overwriting\n", configPath)+ root = make(map[string]any)+ }+ }++ servers, ok := root["servers"].(map[string]any)+ if !ok {+ servers = make(map[string]any)+ }++ servers[mcpServerKey] = map[string]any{+ "type": "stdio",+ "command": binaryPath,+ }+ root["servers"] = servers++ if err := os.MkdirAll(filepath.Dir(configPath), 0o750); err != nil {+ fmt.Printf(" ⚠ mkdir %s: %v\n", filepath.Dir(configPath), err)+ return+ }+ out, err := json.MarshalIndent(root, "", " ")+ if err != nil {+ fmt.Printf(" ⚠ marshal JSON: %v\n", err)+ return+ }+ if err := os.WriteFile(configPath, append(out, '\n'), 0o600); err != nil {+ fmt.Printf(" ⚠ write %s: %v\n", configPath, err)+ return+ }+ fmt.Printf(" ✓ MCP server registered in %s\n", configPath)+}++// removeVSCodeMCP removes our MCP server from VS Code's mcp.json.+func removeVSCodeMCP(configPath string, cfg installConfig) {+ if configPath == "" {+ return+ }++ data, err := os.ReadFile(configPath)+ if err != nil {+ return+ }++ var root map[string]any+ if err := json.Unmarshal(data, &root); err != nil {+ return+ }++ servers, ok := root["servers"].(map[string]any)+ if !ok {+ return+ }+ if _, exists := servers[mcpServerKey]; !exists {+ return+ }++ fmt.Printf("[VS Code] MCP config: %s\n", configPath)++ if cfg.dryRun {+ fmt.Printf(" [dry-run] Would remove %s from %s\n", mcpServerKey, configPath)+ return+ }++ delete(servers, mcpServerKey)+ root["servers"] = servers++ out, err := json.MarshalIndent(root, "", " ")+ if err != nil {+ fmt.Printf(" ⚠ marshal JSON: %v\n", err)+ return+ }+ if err := os.WriteFile(configPath, append(out, '\n'), 0o600); err != nil {+ fmt.Printf(" ⚠ write %s: %v\n", configPath, err)+ return+ }+ fmt.Printf(" ✓ Removed %s from %s\n", mcpServerKey, configPath)+}++// --- Zed ---++// zedConfigPath returns the Zed settings path.+func zedConfigPath() string {+ home, err := os.UserHomeDir()+ if err != nil {+ return ""+ }+ return filepath.Join(home, ".config", "zed", "settings.json")+}++// installZedMCP upserts our MCP server in Zed's settings.json under "context_servers".+func installZedMCP(binaryPath, configPath string, cfg installConfig) {+ if configPath == "" {+ return+ }++ fmt.Printf("[Zed] MCP config: %s\n", configPath)++ if cfg.dryRun {+ fmt.Printf(" [dry-run] Would upsert %s in %s\n", mcpServerKey, configPath)+ return+ }++ root := make(map[string]any)+ if data, err := os.ReadFile(configPath); err == nil {+ if jsonErr := json.Unmarshal(data, &root); jsonErr != nil {+ // Zed settings.json likely has other settings — don't overwrite on bad JSON+ fmt.Printf(" ⚠ Invalid JSON in %s, skipping\n", configPath)+ return+ }+ }++ servers, ok := root["context_servers"].(map[string]any)+ if !ok {+ servers = make(map[string]any)+ }++ servers[mcpServerKey] = map[string]any{+ "source": "custom",+ "command": binaryPath,+ }+ root["context_servers"] = servers++ if err := os.MkdirAll(filepath.Dir(configPath), 0o750); err != nil {+ fmt.Printf(" ⚠ mkdir %s: %v\n", filepath.Dir(configPath), err)+ return+ }+ out, err := json.MarshalIndent(root, "", " ")+ if err != nil {+ fmt.Printf(" ⚠ marshal JSON: %v\n", err)+ return+ }+ if err := os.WriteFile(configPath, append(out, '\n'), 0o600); err != nil {+ fmt.Printf(" ⚠ write %s: %v\n", configPath, err)+ return+ }+ fmt.Printf(" ✓ MCP server registered in %s\n", configPath)+}++// removeZedMCP removes our MCP server from Zed's settings.json.+func removeZedMCP(configPath string, cfg installConfig) {+ if configPath == "" {+ return+ }++ data, err := os.ReadFile(configPath)+ if err != nil {+ return+ }++ var root map[string]any+ if err := json.Unmarshal(data, &root); err != nil {+ return+ }++ servers, ok := root["context_servers"].(map[string]any)+ if !ok {+ return+ }+ if _, exists := servers[mcpServerKey]; !exists {+ return+ }++ fmt.Printf("[Zed] MCP config: %s\n", configPath)++ if cfg.dryRun {+ fmt.Printf(" [dry-run] Would remove %s from %s\n", mcpServerKey, configPath)+ return+ }++ delete(servers, mcpServerKey)+ root["context_servers"] = servers++ out, err := json.MarshalIndent(root, "", " ")+ if err != nil {+ fmt.Printf(" ⚠ marshal JSON: %v\n", err)+ return+ }+ if err := os.WriteFile(configPath, append(out, '\n'), 0o600); err != nil {+ fmt.Printf(" ⚠ write %s: %v\n", configPath, err)+ return+ }+ fmt.Printf(" ✓ Removed %s from %s\n", mcpServerKey, configPath)+}diff --git a/cmd/codebase-memory-mcp/install_test.go b/cmd/codebase-memory-mcp/install_test.goindex 8f764280a..0053c54bc 100644--- a/cmd/codebase-memory-mcp/install_test.go+++ b/cmd/codebase-memory-mcp/install_test.go@@ -440,6 +440,208 @@ func TestEditorMCPUninstall(t *testing.T) {}}+func TestGeminiConfigPath(t *testing.T) {+ home := t.TempDir()+ setTestHome(t, home)++ path := geminiConfigPath()+ if path == "" {+ t.Fatal("geminiConfigPath returned empty")+ }+ if !strings.HasSuffix(path, filepath.Join(".gemini", "settings.json")) {+ t.Fatalf("unexpected path: %s", path)+ }+}++func TestGeminiMCPInstall(t *testing.T) {+ home := t.TempDir()+ setTestHome(t, home)++ configPath := filepath.Join(home, ".gemini", "settings.json")+ binaryPath := "/usr/local/bin/codebase-memory-mcp"++ // Gemini uses same mcpServers format as Cursor+ installEditorMCP(binaryPath, configPath, "Gemini CLI", installConfig{})++ data, err := os.ReadFile(configPath)+ if err != nil {+ t.Fatalf("read config: %v", err)+ }+ var root map[string]any+ if err := json.Unmarshal(data, &root); err != nil {+ t.Fatalf("unmarshal: %v", err)+ }+ servers, ok := root["mcpServers"].(map[string]any)+ if !ok {+ t.Fatal("expected mcpServers key")+ }+ if _, ok := servers["codebase-memory-mcp"]; !ok {+ t.Fatal("codebase-memory-mcp not registered")+ }+}++func TestVSCodeMCPInstall(t *testing.T) {+ home := t.TempDir()+ setTestHome(t, home)++ configPath := filepath.Join(home, "Code", "User", "mcp.json")+ binaryPath := "/usr/local/bin/codebase-memory-mcp"++ installVSCodeMCP(binaryPath, configPath, installConfig{})++ data, err := os.ReadFile(configPath)+ if err != nil {+ t.Fatalf("read config: %v", err)+ }+ var root map[string]any+ if err := json.Unmarshal(data, &root); err != nil {+ t.Fatalf("unmarshal: %v", err)+ }+ servers, ok := root["servers"].(map[string]any)+ if !ok {+ t.Fatal("expected servers key")+ }+ entry, ok := servers["codebase-memory-mcp"].(map[string]any)+ if !ok {+ t.Fatal("codebase-memory-mcp not registered")+ }+ if entry["type"] != "stdio" {+ t.Fatalf("expected type=stdio, got %v", entry["type"])+ }+ if entry["command"] != binaryPath {+ t.Fatalf("expected command=%s, got %v", binaryPath, entry["command"])+ }+}++func TestVSCodeMCPUninstall(t *testing.T) {+ home := t.TempDir()+ setTestHome(t, home)++ configPath := filepath.Join(home, "Code", "User", "mcp.json")+ binaryPath := "/usr/local/bin/codebase-memory-mcp"++ installVSCodeMCP(binaryPath, configPath, installConfig{})+ removeVSCodeMCP(configPath, installConfig{})++ data, err := os.ReadFile(configPath)+ if err != nil {+ t.Fatal(err)+ }+ var root map[string]any+ if err := json.Unmarshal(data, &root); err != nil {+ t.Fatal(err)+ }+ servers, ok := root["servers"].(map[string]any)+ if !ok {+ t.Fatal("servers key missing")+ }+ if _, exists := servers["codebase-memory-mcp"]; exists {+ t.Fatal("codebase-memory-mcp should be removed")+ }+}++func TestZedMCPInstall(t *testing.T) {+ home := t.TempDir()+ setTestHome(t, home)++ configPath := filepath.Join(home, ".config", "zed", "settings.json")+ binaryPath := "/usr/local/bin/codebase-memory-mcp"++ installZedMCP(binaryPath, configPath, installConfig{})++ data, err := os.ReadFile(configPath)+ if err != nil {+ t.Fatalf("read config: %v", err)+ }+ var root map[string]any+ if err := json.Unmarshal(data, &root); err != nil {+ t.Fatalf("unmarshal: %v", err)+ }+ servers, ok := root["context_servers"].(map[string]any)+ if !ok {+ t.Fatal("expected context_servers key")+ }+ entry, ok := servers["codebase-memory-mcp"].(map[string]any)+ if !ok {+ t.Fatal("codebase-memory-mcp not registered")+ }+ if entry["source"] != "custom" {+ t.Fatalf("expected source=custom, got %v", entry["source"])+ }+ if entry["command"] != binaryPath {+ t.Fatalf("expected command=%s, got %v", binaryPath, entry["command"])+ }+}++func TestZedMCPPreservesSettings(t *testing.T) {+ home := t.TempDir()+ setTestHome(t, home)++ configPath := filepath.Join(home, ".config", "zed", "settings.json")+ if err := os.MkdirAll(filepath.Dir(configPath), 0o750); err != nil {+ t.Fatal(err)+ }++ // Pre-existing Zed settings+ existing := `{"theme": "One Dark", "vim_mode": true}`+ if err := os.WriteFile(configPath, []byte(existing), 0o600); err != nil {+ t.Fatal(err)+ }++ installZedMCP("/usr/local/bin/codebase-memory-mcp", configPath, installConfig{})++ data, err := os.ReadFile(configPath)+ if err != nil {+ t.Fatal(err)+ }+ var root map[string]any+ if err := json.Unmarshal(data, &root); err != nil {+ t.Fatal(err)+ }+ // Original settings preserved+ if root["theme"] != "One Dark" {+ t.Fatal("theme setting was lost")+ }+ if root["vim_mode"] != true {+ t.Fatal("vim_mode setting was lost")+ }+ // MCP server added+ servers, ok := root["context_servers"].(map[string]any)+ if !ok {+ t.Fatal("context_servers missing")+ }+ if _, ok := servers["codebase-memory-mcp"]; !ok {+ t.Fatal("codebase-memory-mcp not added")+ }+}++func TestZedMCPUninstall(t *testing.T) {+ home := t.TempDir()+ setTestHome(t, home)++ configPath := filepath.Join(home, ".config", "zed", "settings.json")+ binaryPath := "/usr/local/bin/codebase-memory-mcp"++ installZedMCP(binaryPath, configPath, installConfig{})+ removeZedMCP(configPath, installConfig{})++ data, err := os.ReadFile(configPath)+ if err != nil {+ t.Fatal(err)+ }+ var root map[string]any+ if err := json.Unmarshal(data, &root); err != nil {+ t.Fatal(err)+ }+ servers, ok := root["context_servers"].(map[string]any)+ if !ok {+ t.Fatal("context_servers key missing")+ }+ if _, exists := servers["codebase-memory-mcp"]; exists {+ t.Fatal("codebase-memory-mcp should be removed")+ }+}+func TestRemoveOldMonolithicSkill(t *testing.T) {home := t.TempDir()setTestHome(t, home)diff --git a/cmd/codebase-memory-mcp/update.go b/cmd/codebase-memory-mcp/update.goindex 524d13bf0..11716b585 100644--- a/cmd/codebase-memory-mcp/update.go+++ b/cmd/codebase-memory-mcp/update.go@@ -29,7 +29,7 @@ func runUpdate(args []string) int {}}- currentVersion := strings.TrimSuffix(version, "-dev")+ currentVersion := strings.TrimPrefix(strings.TrimSuffix(version, "-dev"), "v")fmt.Printf("\ncodebase-memory-mcp %s — checking for updates...\n", version)if runtime.GOOS == "windows" {@@ -87,7 +87,7 @@ func runUpdate(args []string) int {fmt.Println("Re-applying installation...")runInstall([]string{})- fmt.Printf("\nUpdated to v%s. Restart Claude Code / Codex to activate.\n", latest)+ fmt.Printf("\nUpdated to v%s. Restart your editor/CLI to activate.\n", latest)return 0}@@ -101,17 +101,11 @@ func downloadAndVerify(ctx context.Context, release *selfupdate.Release, assetNa}fmt.Printf("Downloading %s...\n", assetName)- body, _, err := selfupdate.DownloadAsset(ctx, asset.BrowserDownloadURL)+ tarballData, err := selfupdate.DownloadAsset(ctx, asset.BrowserDownloadURL)if err != nil {return nil, fmt.Errorf("download: %w", err)}- tarballData, err := io.ReadAll(body)- body.Close()- if err != nil {- return nil, fmt.Errorf("read download: %w", err)- }-if checksums != nil {if expected, ok := checksums[assetName]; ok {hash := sha256.Sum256(tarballData)diff --git a/internal/pipeline/pipeline.go b/internal/pipeline/pipeline.goindex 2281396dd..c2d5fe4f6 100644--- a/internal/pipeline/pipeline.go+++ b/internal/pipeline/pipeline.go@@ -67,10 +67,16 @@ func New(ctx context.Context, s *store.Store, repoPath string, mode discover.Ind// ProjectNameFromPath derives a unique project name from an absolute path// by replacing path separators with dashes and trimming the leading dash.func ProjectNameFromPath(absPath string) string {- // Clean and convert to slash-separated+ // Clean and normalize separators (backslash is not a separator on non-Windows)cleaned := filepath.ToSlash(filepath.Clean(absPath))- // Replace slashes with dashes+ cleaned = strings.ReplaceAll(cleaned, "\\", "/")+ // Replace slashes and colons with dashesname := strings.ReplaceAll(cleaned, "/", "-")+ name = strings.ReplaceAll(name, ":", "-")+ // Collapse consecutive dashes (e.g. C:/ → C--)+ for strings.Contains(name, "--") {+ name = strings.ReplaceAll(name, "--", "-")+ }// Trim leading dash (from leading /)name = strings.TrimLeft(name, "-")if name == "" {diff --git a/internal/pipeline/pipeline_test.go b/internal/pipeline/pipeline_test.goindex 845147c7d..0741c0e5e 100644--- a/internal/pipeline/pipeline_test.go+++ b/internal/pipeline/pipeline_test.go@@ -793,6 +793,10 @@ func TestProjectNameFromPath(t *testing.T) {{"/Users/martin/projects/myapp", "Users-martin-projects-myapp"},{"/home/user/repo", "home-user-repo"},{"/single", "single"},+ // Windows paths (#20)+ {"C:/Users/project", "C-Users-project"},+ {"D:\\Projects\\myapp", "D-Projects-myapp"},+ {"C:\\Temp\\codebase-memory-mcp", "C-Temp-codebase-memory-mcp"},}for _, tt := range tests {got := ProjectNameFromPath(tt.path)diff --git a/internal/selfupdate/selfupdate.go b/internal/selfupdate/selfupdate.goindex 0d0acd265..cf67d8363 100644--- a/internal/selfupdate/selfupdate.go+++ b/internal/selfupdate/selfupdate.go@@ -126,9 +126,9 @@ var AllowedDownloadPrefixes = []string{"https://api.github.com/",}-// DownloadAsset downloads a release asset and returns the body reader and content length.-// Caller must close the returned ReadCloser.-func DownloadAsset(ctx context.Context, rawURL string) (io.ReadCloser, int64, error) {+// DownloadAsset downloads a release asset and returns the full body as bytes.+// The response body is fully read before returning to avoid premature context cancellation.+func DownloadAsset(ctx context.Context, rawURL string) ([]byte, error) {allowed := falsefor _, prefix := range AllowedDownloadPrefixes {if strings.HasPrefix(rawURL, prefix) {@@ -137,7 +137,7 @@ func DownloadAsset(ctx context.Context, rawURL string) (io.ReadCloser, int64, er}}if !allowed {- return nil, 0, fmt.Errorf("refusing to download from non-GitHub URL: %s", rawURL)+ return nil, fmt.Errorf("refusing to download from non-GitHub URL: %s", rawURL)}ctx, cancel := context.WithTimeout(ctx, 5*time.Minute)@@ -145,20 +145,20 @@ func DownloadAsset(ctx context.Context, rawURL string) (io.ReadCloser, int64, erreq, err := http.NewRequestWithContext(ctx, "GET", rawURL, http.NoBody)if err != nil {- return nil, 0, fmt.Errorf("create request: %w", err)+ return nil, fmt.Errorf("create request: %w", err)}resp, err := http.DefaultClient.Do(req)if err != nil {- return nil, 0, fmt.Errorf("download: %w", err)+ return nil, fmt.Errorf("download: %w", err)}+ defer resp.Body.Close()if resp.StatusCode != 200 {- resp.Body.Close()- return nil, 0, fmt.Errorf("download status=%d", resp.StatusCode)+ return nil, fmt.Errorf("download status=%d", resp.StatusCode)}- return resp.Body, resp.ContentLength, nil+ return io.ReadAll(io.LimitReader(resp.Body, 500<<20)) // 500 MB safety limit}// DownloadChecksums downloads and parses the checksums.txt file from a release.@@ -169,16 +169,10 @@ func DownloadChecksums(ctx context.Context, release *Release) (map[string]stringreturn nil, fmt.Errorf("checksums.txt not found in release")}- body, _, err := DownloadAsset(ctx, asset.BrowserDownloadURL)+ data, err := DownloadAsset(ctx, asset.BrowserDownloadURL)if err != nil {return nil, fmt.Errorf("download checksums: %w", err)}- defer body.Close()-- data, err := io.ReadAll(io.LimitReader(body, 1<<16))- if err != nil {- return nil, fmt.Errorf("read checksums: %w", err)- }checksums := make(map[string]string)for _, line := range strings.Split(string(data), "\n") {diff --git a/internal/tools/tools.go b/internal/tools/tools.goindex 5126322c4..eeaf9a80c 100644--- a/internal/tools/tools.go+++ b/internal/tools/tools.go@@ -680,7 +680,7 @@ func (s *Server) registerProjectTools() {s.addTool(&mcp.Tool{Name: "list_projects",Description: "List all indexed projects with their indexed_at timestamp, root path, and node/edge counts.",- InputSchema: json.RawMessage(`{"type": "object"}`),+ InputSchema: json.RawMessage(`{"type": "object", "properties": {}}`),}, s.handleListProjects)s.addTool(&mcp.Tool{