diff --git a/docs/CLAUDE_INTEGRATION.md b/docs/CLAUDE_INTEGRATION.md index 8f6d69c..7abef40 100644 --- a/docs/CLAUDE_INTEGRATION.md +++ b/docs/CLAUDE_INTEGRATION.md @@ -3,6 +3,7 @@ ## The Problem Copilot instructions get **ignored in longer conversations** (15+ messages) and Claude falls back to: + - Reading files directly - Using grep patterns - Manual code analysis @@ -17,6 +18,7 @@ Copilot instructions get **ignored in longer conversations** (15+ messages) and ## The Solution: System Prompt Engineering Make the system prompt **enforce MCP at protocol level**: + - File reads become impossible (system block) - Grep becomes forbidden (protocol-level) - MCP becomes mandatory (only option) @@ -36,7 +38,7 @@ Edit `~/.claude_desktop_config.json`: "mcpServers": { "lxdig": { "command": "node", - "args": ["/home/alex_rod/code-graph-server/dist/server.js"], + "args": ["/home/alex_rod/projects/lxDIG-MCP/dist/server.js"], "env": { "MCP_TRANSPORT": "stdio", "MEMGRAPH_HOST": "localhost", @@ -53,19 +55,21 @@ Edit `~/.claude_desktop_config.json`: ### Step 2: Update VS Code Settings Create `.vscode/mcp.json`: + ```json { "servers": { "lxdig": { "type": "stdio", "command": "node", - "args": ["/home/alex_rod/code-graph-server/dist/server.js"] + "args": ["/home/alex_rod/projects/lxDIG-MCP/dist/server.js"] } } } ``` Create `.vscode/settings.json`: + ```json { "claude.alwaysUseMCP": true, @@ -82,6 +86,7 @@ Close and reopen Claude completely. Ask Claude: "How does src/main.ts work?" **Expected**: + - Claude calls `graph_set_workspace` - Claude calls `code_explain('main')` - NO file reads @@ -90,12 +95,12 @@ Ask Claude: "How does src/main.ts work?" ## Why This Works -| Before | After | -|--------|-------| -| Instructions fade in long chats | System prompt is protocol-level | -| Claude reads files anyway | File reads are system-blocked | -| Uses grep by default | Grep is forbidden | -| Context gets out of sync | Health checks re-anchor every 5 messages | +| Before | After | +| ------------------------------- | ---------------------------------------- | +| Instructions fade in long chats | System prompt is protocol-level | +| Claude reads files anyway | File reads are system-blocked | +| Uses grep by default | Grep is forbidden | +| Context gets out of sync | Health checks re-anchor every 5 messages | --- @@ -146,16 +151,19 @@ System Prompt: ## Troubleshooting ### Claude still reads files + - Check system prompt in Claude Desktop config - Verify "NEVER read files" is present - Restart Claude completely ### Long conversations break + - Ensure `graph_health()` re-anchoring is in system prompt - Test with 50+ message conversation - If fails at message N, check if `graph_health()` was called at N-5 ### MCP tools not available + - Verify MCP server running: `curl http://localhost:9000/health` - Check Docker: `docker-compose ps` - Restart Claude diff --git a/docs/GRAPH_STATE_QUICK_REF.txt b/docs/GRAPH_STATE_QUICK_REF.txt deleted file mode 100644 index 1f4e6aa..0000000 --- a/docs/GRAPH_STATE_QUICK_REF.txt +++ /dev/null @@ -1,231 +0,0 @@ -╔════════════════════════════════════════════════════════════════════════════╗ -║ GRAPH STATE ANALYSIS - QUICK REFERENCE ║ -╚════════════════════════════════════════════════════════════════════════════╝ - -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ -QUESTION 1: MULTIPLE PROJECTS SETUP -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - -Answer: ONE project per session, MULTIPLE isolated sessions - -Architecture: -┌─ Server Process (shared) -│ ├─ ToolContext.index (shared, never cleared) -│ ├─ Memgraph connection (shared) -│ └─ ToolHandlers (contains engines) -│ -└─ Per Session: - ├─ ProjectContext (workspace + projectId) - ├─ FileWatcher (monitoring workspace) - └─ SessionId header identification - -Session Usage (REQUIRED for multi-project): - POST /initialize → Returns mcp-session-id: "sess-a" - POST /tools/graph_set_workspace - Header: mcp-session-id: sess-a - Body: {projectId: "project-a"} - -Without session ID: All requests use defaultActiveProjectContext (global) - - -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ -QUESTION 2: CONTEXT SWITCHING (graph_set_workspace) -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - -What Changes: - ✅ ProjectContext (workspace, sourceDir, projectId) - ✅ FileWatcher (restarted for new directory) - -What DOESN'T Change (CRITICAL): - ❌ GraphIndexManager (NOT cleared - still has old project's data) - ❌ ProgressEngine (NOT reset - still has old project's tasks) - ❌ ArchitectureEngine (NOT reset - still references old index) - ❌ TestEngine (NOT reset - still references old index) - ❌ EmbeddingEngine (NOT reset - still references old index) - ❌ HybridRetriever (NOT reset - still references old index) - -Implementation (src/tools/tool-handlers.ts:1543-1615): - 1. Resolve new ProjectContext - 2. setActiveProjectContext(nextContext) - updates session/default context - 3. startActiveWatcher(nextContext) - restarts file watcher - 4. Return success - -PROBLEM: In-memory index accumulates data from multiple projects! - - -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ -QUESTION 3: GRAPH REBUILD BEHAVIOR -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - -Clear in-memory index first? - ❌ NO - Shared index is NOT cleared - -Append to existing index? - ❌ NO - Orchestrator creates NEW internal index for each build - -Load index from Memgraph? - ❌ NO - Parses files from scratch - -Actual Behavior (src/graph/orchestrator.ts:181-423): - 1. GraphOrchestrator creates NEW GraphIndexManager() [internal] - 2. Parses all source files - 3. For each file: addToIndex(parsed) → adds to orchestrator's internal index - 4. Generates Cypher statements - 5. Executes Cypher batch → Memgraph UPDATED ✓ - 6. Returns BuildResult - 7. Orchestrator.index is DISCARDED (not synced) - 8. ToolContext.index UNCHANGED (remains empty) ✗ - -Result: - • Memgraph database: UPDATED ✓ - • Shared in-memory index: UNCHANGED (empty) ❌ - • Orchestrator's internal index: WASTED (discarded) ❌ - - -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ -QUESTION 4: INDEX INITIALIZATION -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - -Where does GraphIndexManager get populated from? - -At Startup: - src/mcp-server.ts:618 → new GraphIndexManager() - Result: EMPTY ◯ - -After graph_rebuild: - Orchestrator.build() populates ITS internal index - But NEVER syncs to ToolContext.index - Result: Still EMPTY ◯ - -When queries run: - Tools query Memgraph directly (not index) → WORKS ✓ - Embedding engine queries index (EMPTY) → FAILS ❌ - Progress tracking reads index (EMPTY) → FAILS ❌ - -Sources of Potential Population: - ✓ Manual .addNode() calls (rarely used) - ✗ Memgraph database (never loaded at startup) - ✗ File system (never loaded directly) - ✗ Orchestrator rebuild (not synced) - -Summary: Started empty, usually stays empty. - - -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ -CORE ARCHITECTURE ISSUE -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - -TWO SEPARATE, UNSYNCED INDEX SYSTEMS: - - ┌─────────────────────────────────────┐ - │ ToolContext.index (Shared) │ - │ • Initialized: EMPTY │ - │ • Updated: NEVER │ - │ • Used by: ALL engines │ - │ • Status: Empty or stale │ - └─────────────────────────────────────┘ - - ┌─────────────────────────────────────┐ - │ GraphOrchestrator.index (Internal) │ - │ • Created: During build() │ - │ • Populated: YES (during parsing) │ - │ • Synced: NO (never goes back) │ - │ • Status: Temporary, discarded │ - └─────────────────────────────────────┘ - - ┌─────────────────────────────────────┐ - │ Memgraph Database (Source of Truth) │ - │ • Updated: By Orchestrator Cypher │ - │ • Queried: YES (by tools) │ - │ • Status: Current and accurate │ - └─────────────────────────────────────┘ - -Consequence: - • Tools using Memgraph directly: ✓ WORK - • Embedding engine: ❌ FAILS - • Progress tracking: ❌ FAILS - • Architecture validation: ❌ FAILS - • Multi-project support: ❌ RISKY - - -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ -QUICK FIXES (PRIORITY ORDER) -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - -1. CLEAR INDEX ON CONTEXT SWITCH (30 min) - File: src/tools/tool-handlers.ts:1543-1615 (graph_set_workspace) - Add: if (oldProjectId !== newProjectId) this.context.index.clear(); - Why: Prevents data accumulation from multiple projects - -2. SYNC ORCHESTRATOR INDEX (2 hours) - Files: src/graph/orchestrator.ts:70-176 (add getIndex method) - src/tools/tool-handlers.ts:1617-1776 (sync in graph_rebuild) - Why: Makes embedding and progress tracking work - -3. ADD PROJECTID FILTERS (1 hour) - Files: All Cypher queries in src/tools/tool-handlers.ts - Add: WHERE n.projectId = $projectId - Why: Ensures query results respect project boundaries - -4. PROJECT-SCOPED INDICES (1-2 days) - Files: Refactor entire index management system - Why: Future-proof, complete isolation - - -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ -KEY FILE LOCATIONS -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - -ToolContext Definition - src/tools/tool-handlers.ts:41-46 - -ProjectContext Definition - src/tools/tool-handlers.ts:48-52 - -Context Switching - src/tools/tool-handlers.ts:87-106 - -Session Management - src/tools/tool-handlers.ts:69-71 - -graph_set_workspace Implementation - src/tools/tool-handlers.ts:1543-1615 - -graph_rebuild Implementation - src/tools/tool-handlers.ts:1617-1776 - -GraphOrchestrator Constructor - src/graph/orchestrator.ts:86-176 - -GraphOrchestrator.build() - src/graph/orchestrator.ts:181-423 - -GraphIndexManager Implementation - src/graph/index.ts:35-178 - -ProgressEngine Construction - src/engines/progress-engine.ts:59-96 - -MCP Server Initialization - src/mcp-server.ts:618-623 - - -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ -RISK ASSESSMENT -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - -Single Project, Single Session: LOW RISK ✓ -Multiple Projects with SessionIds: MEDIUM RISK ⚠ (index contamination) -Multiple Projects without Sessions: HIGH RISK ✗ (complete data mixing) - - -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ -DOCUMENTATION FILES -━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - -GRAPH_STATE_ANALYSIS.md ← Full technical analysis (12 sections) -GRAPH_STATE_DIAGRAMS.md ← Architecture and data flow diagrams (8 diagrams) -GRAPH_STATE_FIXES.md ← Implementation guide with code examples -GRAPH_STATE_SUMMARY.md ← Executive summary (this addresses your questions) -GRAPH_STATE_QUICK_REF.txt ← This file - diff --git a/docs/INTEGRATION_SUMMARY.md b/docs/INTEGRATION_SUMMARY.md deleted file mode 100644 index fd4d9f6..0000000 --- a/docs/INTEGRATION_SUMMARY.md +++ /dev/null @@ -1,292 +0,0 @@ -# Integration Summary: MCP Server Documentation - -**All documentation consolidated into docs/ folder.** - ---- - -## 📚 Documentation Map - -``` -docs/ -├─ INTEGRATION_SUMMARY.md ........... This file -├─ MCP_INTEGRATION_GUIDE.md ......... Complete integration guide -├─ CLAUDE_INTEGRATION.md ........... Claude/Copilot system prompt solution -├─ TOOL_PATTERNS.md ............... Grep → MCP replacement patterns -├─ templates/copilot-instructions-template.md . Copy to .github/copilot-instructions.md -├─ templates/skill-mcp-template.md .. Skill prompt template -├─ templates/toolsets-template.jsonc . VS Code toolset template -├─ QUICK_REFERENCE.md ............. All 39 tools reference -├─ QUICK_START.md ................. Server deployment -└─ ARCHITECTURE.md ................ Technical deep dive -``` - ---- - -## 🎯 Quick Navigation - -### I want to... - -**Make Claude use MCP in long conversations (the main problem)** -→ Read: [docs/CLAUDE_INTEGRATION.md](CLAUDE_INTEGRATION.md) -→ Then: [docs/templates/copilot-instructions-template.md](templates/copilot-instructions-template.md) - -**Integrate MCP into my projects** -→ Read: [docs/MCP_INTEGRATION_GUIDE.md](MCP_INTEGRATION_GUIDE.md) - -**Replace grep with MCP tools** -→ Read: [docs/TOOL_PATTERNS.md](TOOL_PATTERNS.md) - -**See all 39 tools** -→ Read: [QUICK_REFERENCE.md](../QUICK_REFERENCE.md) - -**Deploy the server** -→ Read: [QUICK_START.md](../QUICK_START.md) - ---- - -## 🔑 Key Insights - -### Problem: Long Conversation Instruction Drift - -After ~15 messages, Copilot ignores instructions and falls back to: - -- Reading files directly -- Using grep patterns -- Manual code analysis - -### Root Cause - -Instructions are overlaid suggestions. They fade in long conversations. File reads are baked into training data (default behavior). - -### Solution: System Prompt Engineering - -Make the system prompt **enforce MCP at protocol level**: - -- File reads become impossible (system block) -- Grep becomes forbidden (protocol) -- MCP becomes mandatory (only option) - -Result: Even at message 100, Claude uses MCP because it's the **only option**. - -### Implementation - -Edit `~/.claude_desktop_config.json`: - -```json -{ - "systemPrompt": "NEVER read files. NEVER use grep. ALWAYS use MCP tools..." -} -``` - ---- - -## 📋 Setup Checklist - -### Infrastructure (One Time) - -- [ ] Docker + Docker Compose installed -- [ ] `docker-compose up -d memgraph qdrant` -- [ ] `npm run build && npm run start:http` -- [ ] Verify: `curl http://localhost:9000/health` - -### Claude Desktop - -- [ ] Edit `~/.claude_desktop_config.json` -- [ ] Add MCP server config -- [ ] Add system prompt (enforces MCP) -- [ ] Restart Claude - -### Per-Project - -- [ ] Copy [templates/copilot-instructions-template.md](templates/copilot-instructions-template.md) to `.github/copilot-instructions.md` -- [ ] Update project references -- [ ] Set `LXDIG_PROJECT_ID` in your environment or pass `projectId` to `graph_set_workspace` -- [ ] Commit `.github/copilot-instructions.md` - ---- - -## 🚀 Implementation Order - -### Phase 1: Foundation (15 min) - -1. Start Docker services -2. Build and start MCP server -3. Update Claude Desktop config -4. Restart Claude - -### Phase 2: Test (5 min) - -1. Ask Claude: "How does [file] work?" -2. Verify it calls MCP tools (not file reads) -3. Test long conversation (20+ messages) -4. Verify no degradation - -### Phase 3: Rollout (Per-Project) - -1. Copy copilot instructions to `.github/copilot-instructions.md` -2. Set `LXDIG_PROJECT_ID` or pass projectId to `graph_set_workspace` -3. Commit and push -4. Update team - ---- - -## 💡 Core Concepts - -### 39 MCP Tools Available - -``` -Essential 4: - • graph_query — Find code by natural language - • code_explain — Understand symbols with context - • impact_analyze — What breaks if I change X? - • test_select — Which tests should I run? - -Architecture 2: - • arch_validate — Check violations - • arch_suggest — Where should code go? - -Search 3: - • semantic_search — Search by meaning - • find_pattern — Detect violations - • find_similar_code — Find implementations - -Testing 3: - • test_categorize — Group tests - • suggest_tests — Tests needed for symbol - • test_run — Execute tests - -Memory 4: - • episode_add — Record decisions - • decision_query — Recall decisions - • reflect — Synthesize learnings - • [coordination tools] - -+ 18 more specialized tools -``` - -See [docs/TOOL_PATTERNS.md](TOOL_PATTERNS.md) for pattern matching. - -### Multi-Project Architecture - -``` -Claude → MCP Server → Memgraph + Qdrant - ↓ - Project A (isolated) - Project B (isolated) - Project C (isolated) -``` - -Each project: isolated by `projectId` + `workspaceRoot` -Shared: Memgraph + Qdrant infrastructure - -### Session Re-anchoring - -``` -Message 1: graph_set_workspace() → session starts -Message 1-4: Normal MCP queries -Message 5: graph_health() → verify still ready -Message 6-9: Normal MCP queries -Message 10: graph_health() → re-anchor -...continues indefinitely without degradation -``` - ---- - -## 📊 Performance Gains - -| Task | Grep/Manual | MCP | Improvement | -| ------------------- | ----------- | ----- | ------------ | -| Find symbol | 450ms | 50ms | 9x faster | -| Understand function | 5 min | 200ms | 1500x faster | -| Impact analysis | 10 min | 100ms | 6000x faster | -| Search by meaning | 2 min | 150ms | 800x faster | -| False positives | High | <1% | 100x better | - ---- - -## ✅ Success Criteria - -After full implementation: - -- ✅ Claude uses MCP in **every** conversation -- ✅ Long conversations (100+ messages) **never** degrade -- ✅ Zero file reads across entire session -- ✅ Zero grep patterns used -- ✅ Full dependency context always available -- ✅ All projects share MCP infrastructure -- ✅ Heavy MCP dependency, zero fallback - ---- - -## 🔍 Before vs After - -### Before (Grep/File Reads) - -``` -User: "How does auth work?" -Claude: - 1. Opens src/auth/service.ts - 2. Reads 200 lines - 3. Opens 5 imported files - 4. Manually traces dependencies - Result: Takes 1+ minutes, incomplete context - -User (message 20): "Refactor this" -Claude: - 1. Falls back to grep - 2. Misses some usages - 3. Suggests incomplete refactor - Result: Broken code, manual fixing needed -``` - -### After (MCP) - -``` -User: "How does auth work?" -Claude: - 1. graph_set_workspace() - 2. code_explain('AuthService') - 3. graph_query('show call graph') - Result: 200ms, complete dependency context, perfect - -User (message 20): "Refactor this" -Claude: - 1. graph_health() [re-anchor] - 2. impact_analyze(['src/auth/service.ts']) - 3. Suggests safe refactor with impact analysis - Result: Correct refactor, safe changes -``` - ---- - -## 📚 Related Files - -- **Root**: [QUICK_START.md](../QUICK_START.md), [QUICK_REFERENCE.md](../QUICK_REFERENCE.md), [ARCHITECTURE.md](../ARCHITECTURE.md) -- **Docs**: [MCP_INTEGRATION_GUIDE.md](MCP_INTEGRATION_GUIDE.md), [CLAUDE_INTEGRATION.md](CLAUDE_INTEGRATION.md), [TOOL_PATTERNS.md](TOOL_PATTERNS.md) -- **Template**: [templates/copilot-instructions-template.md](templates/copilot-instructions-template.md) - ---- - -## 🎓 For Your Team - -1. **Tech Lead**: Read [docs/CLAUDE_INTEGRATION.md](CLAUDE_INTEGRATION.md) + [docs/MCP_INTEGRATION_GUIDE.md](MCP_INTEGRATION_GUIDE.md) -2. **Developers**: Read [docs/templates/copilot-instructions-template.md](templates/copilot-instructions-template.md) + [docs/TOOL_PATTERNS.md](TOOL_PATTERNS.md) -3. **New Team Members**: Follow setup checklist + read `.github/copilot-instructions.md` - ---- - -## 🆘 Troubleshooting - -| Issue | Solution | Doc | -| ------------------------ | ------------------------ | ---------------------------------------------- | -| Claude reads files | Update system prompt | [CLAUDE_INTEGRATION.md](CLAUDE_INTEGRATION.md) | -| Long conversations break | Add graph_health() calls | [CLAUDE_INTEGRATION.md](CLAUDE_INTEGRATION.md) | -| Don't know which tool | Check TOOL_PATTERNS | [TOOL_PATTERNS.md](TOOL_PATTERNS.md) | -| Server won't start | Check Docker | [QUICK_START.md](../QUICK_START.md) | -| Need tool reference | See all 39 tools | [QUICK_REFERENCE.md](../QUICK_REFERENCE.md) | - ---- - -## 🎯 One-Liner Summary - -**System prompt engineering (not instructions) solves Copilot instruction drift. Use MCP exclusively for code intelligence. Scale to all projects with shared infrastructure. 🚀** diff --git a/docs/MCP_INTEGRATION_GUIDE.md b/docs/MCP_INTEGRATION_GUIDE.md index 880648b..d346ae5 100644 --- a/docs/MCP_INTEGRATION_GUIDE.md +++ b/docs/MCP_INTEGRATION_GUIDE.md @@ -7,7 +7,7 @@ Complete guide for integrating lxDIG MCP across projects. ### 1. Start Infrastructure ```bash -cd /home/alex_rod/code-graph-server +cd /home/alex_rod/projects/lxDIG-MCP docker-compose up -d memgraph qdrant npm install && npm run build npm run start:http # Listens on http://localhost:9000 @@ -22,7 +22,7 @@ Edit `~/.claude_desktop_config.json`: "mcpServers": { "lxdig": { "command": "node", - "args": ["/home/alex_rod/code-graph-server/dist/server.js"], + "args": ["/home/alex_rod/projects/lxDIG-MCP/dist/server.js"], "env": { "MCP_TRANSPORT": "stdio", "MEMGRAPH_HOST": "localhost", @@ -44,7 +44,7 @@ Create `.vscode/mcp.json`: "lxdig": { "type": "stdio", "command": "node", - "args": ["/home/alex_rod/code-graph-server/dist/server.js"] + "args": ["/home/alex_rod/projects/lxDIG-MCP/dist/server.js"] } } } @@ -81,7 +81,7 @@ For each project, add `.mcp-config.json`: } ``` -## 38 Tools Quick Reference +## 39 MCP Tools Quick Reference ### Essential (Use First) @@ -200,7 +200,7 @@ await mcp.initialize(); await mcp.query("find all HTTP handlers"); ``` -See docs/CLIENT_EXAMPLES.md for Python, bash, React. +See [QUICK_REFERENCE.md](../QUICK_REFERENCE.md) for all 39 tools. ## Rollout Phases @@ -232,6 +232,5 @@ See docs/CLIENT_EXAMPLES.md for Python, bash, React. - QUICK_START.md — Deployment details - QUICK_REFERENCE.md — All 39 tools - ARCHITECTURE.md — Technical deep dive -- docs/CLIENT_EXAMPLES.md — Code snippets - docs/CLAUDE_INTEGRATION.md — System prompt details - docs/TOOL_PATTERNS.md — Before/after examples diff --git a/docs/PROJECT_FEATURES_CAPABILITIES.md b/docs/PROJECT_FEATURES_CAPABILITIES.md index 977a077..0901fd1 100644 --- a/docs/PROJECT_FEATURES_CAPABILITIES.md +++ b/docs/PROJECT_FEATURES_CAPABILITIES.md @@ -2,7 +2,7 @@ ## Executive Summary -lexDIG-MCP is an MCP server focused on **architecture-aware code intelligence** and **agent-ready task coordination**. It combines: +lxDIG-MCP is an MCP server focused on **architecture-aware code intelligence** and **agent-ready task coordination**. It combines: - A graph plane for structural understanding. - A semantic retrieval plane for relevance ranking. diff --git a/docs/README.md b/docs/README.md index 3e5c493..305f059 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,149 +1,107 @@ -# Documentation Index +# Documentation -## Start Here 👇 +## Where to Start -**Your MCP server is production-ready. Here's how to use it.** +| Goal | Document | +| ---------------------------------------------- | ---------------------------------------------------- | +| Deploy the server | [QUICK_START.md](../QUICK_START.md) | +| See all 39 tools at a glance | [QUICK_REFERENCE.md](../QUICK_REFERENCE.md) | +| Integrate into a project | [MCP_INTEGRATION_GUIDE.md](MCP_INTEGRATION_GUIDE.md) | +| Stop Claude falling back to grep in long chats | [CLAUDE_INTEGRATION.md](CLAUDE_INTEGRATION.md) | +| Replace grep/file reads with MCP equivalents | [TOOL_PATTERNS.md](TOOL_PATTERNS.md) | +| Understand architecture and internals | [ARCHITECTURE.md](../ARCHITECTURE.md) | -### Quick Overview (5 min) +--- -→ [INTEGRATION_SUMMARY.md](INTEGRATION_SUMMARY.md) +## Guides -### Fix Copilot Instructions Drift (15 min) +### [MCP_INTEGRATION_GUIDE.md](MCP_INTEGRATION_GUIDE.md) -→ [CLAUDE_INTEGRATION.md](CLAUDE_INTEGRATION.md) ⭐ THE SOLUTION +Complete project integration: server setup, VS Code and Claude Desktop config, per-project +`.github/copilot-instructions.md`, multi-project architecture. -### Copy to Your Projects +### [CLAUDE_INTEGRATION.md](CLAUDE_INTEGRATION.md) -→ [templates/copilot-instructions-template.md](templates/copilot-instructions-template.md) +How to enforce MCP usage at the **system prompt level** so Claude never falls back to +grep or file reads — even in 100+ message conversations. Includes ready-to-paste config. -### Complete Integration Guide (30 min) +### [TOOL_PATTERNS.md](TOOL_PATTERNS.md) -→ [MCP_INTEGRATION_GUIDE.md](MCP_INTEGRATION_GUIDE.md) +Side-by-side before/after patterns: grep → `graph_query`, file reads → `code_explain`, +manual impact tracing → `impact_analyze`, test discovery → `test_select`, and more. -### Grep → MCP Patterns (15 min) +--- -→ [TOOL_PATTERNS.md](TOOL_PATTERNS.md) +## Reference -### Code Comment Conventions +### [TOOLS_INFORMATION_GUIDE.md](TOOLS_INFORMATION_GUIDE.md) -→ [CODE_COMMENT_STANDARD.md](CODE_COMMENT_STANDARD.md) +Full 39-tool inventory by category, tool-selection cheatsheet, runtime notes (session +scoping, rebuild async model, profile-driven output), and output contract reference. -### Consolidated Tool Information +### [PROJECT_FEATURES_CAPABILITIES.md](PROJECT_FEATURES_CAPABILITIES.md) -→ [TOOLS_INFORMATION_GUIDE.md](TOOLS_INFORMATION_GUIDE.md) +Feature overview by capability area: graph intelligence, semantic retrieval, testing and +change impact, architecture governance, agent coordination and memory. -### Project Features & Capabilities +--- -→ [PROJECT_FEATURES_CAPABILITIES.md](PROJECT_FEATURES_CAPABILITIES.md) +## Development Standards -### Audits & Evaluations Summary +### [CODE_COMMENT_STANDARD.md](CODE_COMMENT_STANDARD.md) -→ [AUDITS_EVALUATIONS_SUMMARY.md](AUDITS_EVALUATIONS_SUMMARY.md) +TSDoc format for file headers, exported APIs, and internal helpers. Required for all core +modules; includes scope guidance and style rules. + +--- -### Plans & Pending Actions +## Templates -→ [PLANS_PENDING_ACTIONS_SUMMARY.md](PLANS_PENDING_ACTIONS_SUMMARY.md) +| File | Usage | +| ---------------------------------------------------------------------------------------- | -------------------------------------------------------- | +| [templates/copilot-instructions-template.md](templates/copilot-instructions-template.md) | Copy to `.github/copilot-instructions.md` in any project | +| [templates/GRAPH_EXPERT_AGENT.md](templates/GRAPH_EXPERT_AGENT.md) | System prompt for an AI agent operating this repo | +| [templates/skill-mcp-template.md](templates/skill-mcp-template.md) | Skill prompt template for tool-specific tasks | +| [templates/toolsets-template.jsonc](templates/toolsets-template.jsonc) | VS Code toolset configuration | --- -## File Structure +## File Index ``` docs/ -├─ README.md (you are here) -├─ INTEGRATION_SUMMARY.md ........... Quick reference + navigation -├─ CLAUDE_INTEGRATION.md ........... System prompt solution ⭐ -├─ MCP_INTEGRATION_GUIDE.md ........ Complete setup guide -├─ TOOL_PATTERNS.md ............... Before/after patterns -├─ TOOLS_INFORMATION_GUIDE.md ...... Consolidated tool inventory -├─ PROJECT_FEATURES_CAPABILITIES.md Features and capability map -├─ AUDITS_EVALUATIONS_SUMMARY.md ... Consolidated findings -├─ PLANS_PENDING_ACTIONS_SUMMARY.md Prioritized execution plan -├─ templates/ -│ ├─ copilot-instructions-template.md Copy to projects -│ ├─ skill-mcp-template.md .......... Skill prompt template -│ └─ toolsets-template.jsonc ........ VS Code toolset template -└─ (other docs...) + README.md — This file (navigation hub) + CLAUDE_INTEGRATION.md — Enforce MCP via system prompt (fixes instruction drift) + CODE_COMMENT_STANDARD.md — TSDoc comment conventions + MCP_INTEGRATION_GUIDE.md — Full project setup and integration guide + PROJECT_FEATURES_CAPABILITIES.md — Feature and capability map + TOOL_PATTERNS.md — Grep → MCP replacement patterns + TOOLS_INFORMATION_GUIDE.md — 39-tool inventory, cheatsheet, runtime notes + templates/ + copilot-instructions-template.md — Copy to any project + GRAPH_EXPERT_AGENT.md — AI agent system prompt for this repo + skill-mcp-template.md — Skill prompt template + toolsets-template.jsonc — VS Code toolsets Root: -├─ .github/copilot-instructions.md . For this project (ready to use) -├─ QUICK_REFERENCE.md ............. All 39 tools -├─ QUICK_START.md ................. Server deployment -├─ ARCHITECTURE.md ................ Technical details -└─ README.md ...................... Project overview + QUICK_START.md — Server deployment (Docker + npm) + QUICK_REFERENCE.md — All 39 tools with params and examples + ARCHITECTURE.md — Technical deep dive (graph pipeline, parsers, engines) + README.md — Project overview and setup + .github/copilot-instructions.md — Active Copilot instructions for this repo ``` --- -## By Use Case - -### I need to fix "Copilot ignores my instructions" - -1. Read: **CLAUDE_INTEGRATION.md** (15 min) -2. Update: `~/.claude_desktop_config.json` -3. Restart: Claude Desktop -4. Test: Ask code question - -### I want to integrate into my projects - -1. Start: **INTEGRATION_SUMMARY.md** (5 min) -2. Copy: **templates/copilot-instructions-template.md** (1 min) -3. Setup: Follow checklist (10 min) -4. Test: Long conversation (5 min) - -### I want to replace grep with MCP - -1. Learn: **TOOL_PATTERNS.md** (15 min) -2. Apply: Use pattern in your code -3. Test: Verify faster + more accurate - -### I need complete integration details - -1. Read: **MCP_INTEGRATION_GUIDE.md** (30 min) -2. Follow: Setup phases -3. Deploy: To all projects - -### I need all tool references - -1. See: **QUICK_REFERENCE.md** (root) -2. See: **TOOL_PATTERNS.md** (quick lookup) - ---- - -## Key Insight - -**System Prompt Engineering (not instructions) solves instruction drift.** - -- Instructions fade in long conversations -- System prompt is protocol-level (never fades) -- File reads become impossible (not a suggestion) -- Grep becomes forbidden (not a suggestion) - -See: [CLAUDE_INTEGRATION.md](CLAUDE_INTEGRATION.md) - ---- - -## Performance Gains +## Performance Reference -| Task | Before | After | Gain | -| ----------------- | ------ | ----- | ------------ | -| Find symbol | 450ms | 50ms | 9x faster | -| Understand | 5 min | 200ms | 1500x faster | -| Impact analysis | 10 min | 100ms | 6000x faster | -| Search by concept | 2 min | 150ms | 800x faster | - ---- - -## 39 Tools at a Glance - -**Essential 4:** - -- `graph_query` - Find code -- `code_explain` - Understand symbols -- `impact_analyze` - What breaks? -- `test_select` - Which tests? - -**+ 35 more** (see QUICK_REFERENCE.md) +| Task | Manual | MCP | Improvement | +| ------------------- | ------ | ------ | ------------- | +| Find symbol | 450 ms | 50 ms | 9× faster | +| Understand function | 5 min | 200 ms | 1 500× faster | +| Impact analysis | 10 min | 100 ms | 6 000× faster | +| Search by concept | 2 min | 150 ms | 800× faster | +| False positive rate | High | < 1% | — | --- @@ -172,18 +130,3 @@ After implementation: ✅ Zero file reads or grep ✅ Full dependency context always ✅ Heavy MCP dependency, zero fallback - ---- - -## Start Now - -1. **5 min**: [INTEGRATION_SUMMARY.md](INTEGRATION_SUMMARY.md) -2. **15 min**: [CLAUDE_INTEGRATION.md](CLAUDE_INTEGRATION.md) -3. **10 min**: Setup using checklist -4. **5 min**: Test with code question - -**Total: 35 minutes to full setup** - ---- - -**Everything you need is here. Let's go! 🚀** diff --git a/docs/TOOLS_INFORMATION_GUIDE.md b/docs/TOOLS_INFORMATION_GUIDE.md index 1140080..cc131b9 100644 --- a/docs/TOOLS_INFORMATION_GUIDE.md +++ b/docs/TOOLS_INFORMATION_GUIDE.md @@ -20,10 +20,10 @@ Based on the built runtime registry (`dist/tools/registry.js`), the server curre | Category | Count | | ------------ | -----: | | graph | 4 | -| utility | 3 | +| utility | 2 | | code | 7 | | test | 5 | -| coordination | 5 | +| coordination | 6 | | setup | 2 | | arch | 2 | | docs | 2 | @@ -43,7 +43,6 @@ Based on the built runtime registry (`dist/tools/registry.js`), the server curre #### Utility -- `diff_since` - `tools_list` - `contract_validate` @@ -67,6 +66,7 @@ Based on the built runtime registry (`dist/tools/registry.js`), the server curre #### Coordination +- `diff_since` - `context_pack` - `agent_claim` - `agent_release` diff --git a/docs/TOOL_PATTERNS.md b/docs/TOOL_PATTERNS.md index fa8454f..7999065 100644 --- a/docs/TOOL_PATTERNS.md +++ b/docs/TOOL_PATTERNS.md @@ -5,6 +5,7 @@ Quick reference for replacing grep/file reads with MCP tools. ## Discovery: Find Code ### ❌ Grep Approach + ```bash grep -r "MyClass" src/ --include="*.ts" grep -r "import.*AuthService" src/ @@ -12,10 +13,11 @@ grep -r "function.*handle" src/api/ ``` ### ✅ MCP Approach + ```typescript -await mcp.query('find all references to MyClass'); -await mcp.query('find all imports of AuthService'); -await mcp.query('find all HTTP request handlers'); +await mcp.query("find all references to MyClass"); +await mcp.query("find all imports of AuthService"); +await mcp.query("find all HTTP request handlers"); ``` **Benefits**: 10x faster, zero false positives, full context @@ -25,6 +27,7 @@ await mcp.query('find all HTTP request handlers'); ## Understanding: Explain Code ### ❌ File Read Approach + ```bash cat src/auth/service.ts # Read entire file grep -n "class AuthService" src/auth/service.ts @@ -32,8 +35,9 @@ grep -n "validateToken" src/auth/service.ts ``` ### ✅ MCP Approach + ```typescript -await mcp.explain('AuthService'); +await mcp.explain("AuthService"); // Returns: definition + all methods + dependencies + callers ``` @@ -44,6 +48,7 @@ await mcp.explain('AuthService'); ## Impact: What Breaks? ### ❌ Manual Approach + ```bash git diff --name-only HEAD~1 # Then manually check affected files and tests @@ -52,9 +57,10 @@ git diff --name-only HEAD~1 ``` ### ✅ MCP Approach + ```typescript -await mcp.call('impact_analyze', { - changedFiles: ['src/auth/service.ts'] +await mcp.call("impact_analyze", { + changedFiles: ["src/auth/service.ts"], }); // Returns: direct dependents, indirect dependents, affected tests, risk level ``` @@ -66,6 +72,7 @@ await mcp.call('impact_analyze', { ## Testing: Which Tests to Run? ### ❌ Manual Approach + ```bash find . -name "*.test.ts" | xargs grep -l "AuthService" # Time: 5+ minutes @@ -73,9 +80,10 @@ find . -name "*.test.ts" | xargs grep -l "AuthService" ``` ### ✅ MCP Approach + ```typescript -await mcp.call('test_select', { - changedFiles: ['src/auth/service.ts'] +await mcp.call("test_select", { + changedFiles: ["src/auth/service.ts"], }); // Returns: exact test files affected ``` @@ -87,6 +95,7 @@ await mcp.call('test_select', { ## Patterns: Find Violations ### ❌ Grep Approach + ```bash grep -r "console\.log" src/ grep -r "\.any()" src/ @@ -94,8 +103,9 @@ grep -r "hardcoded.*password" src/ ``` ### ✅ MCP Approach + ```typescript -await mcp.call('arch_validate', { profile: 'strict' }); +await mcp.call("arch_validate", { profile: "strict" }); // Returns: architecture violations with severity ``` @@ -106,6 +116,7 @@ await mcp.call('arch_validate', { profile: 'strict' }); ## Search by Meaning ### ❌ Grep Approach + ```bash grep -r "validate" src/ # Returns 500+ results grep -r "error.*handling" src/ # Returns 1000+ results @@ -113,10 +124,11 @@ grep -r "error.*handling" src/ # Returns 1000+ results ``` ### ✅ MCP Approach + ```typescript -await mcp.call('semantic_search', { - query: 'input validation patterns', - limit: 10 +await mcp.call("semantic_search", { + query: "input validation patterns", + limit: 10, }); // Returns: 10 most relevant results by meaning ``` @@ -128,16 +140,18 @@ await mcp.call('semantic_search', { ## Similar Code: Find Patterns ### ❌ Manual Approach + ```bash grep -r "class.*Service" src/ # Manual comparison of 50+ results ``` ### ✅ MCP Approach + ```typescript -await mcp.call('find_similar_code', { - symbol: 'AuthService', - limit: 5 +await mcp.call("find_similar_code", { + symbol: "AuthService", + limit: 5, }); // Returns: 5 most similar implementations ``` @@ -149,6 +163,7 @@ await mcp.call('find_similar_code', { ## Architecture: Where Does Code Go? ### ❌ Manual Approach + ```bash # Read architecture docs # Manually check layer rules @@ -157,9 +172,10 @@ await mcp.call('find_similar_code', { ``` ### ✅ MCP Approach + ```typescript -await mcp.call('arch_suggest', { - filePath: 'new-feature.ts' +await mcp.call("arch_suggest", { + filePath: "new-feature.ts", }); // Returns: recommended layer + reasoning ``` @@ -168,56 +184,56 @@ await mcp.call('arch_suggest', { --- -## All 38 Tools Quick Lookup - -| Use Case | Tool | Example | -|----------|------|---------| -| **Find code** | `graph_query` | find all HTTP handlers | -| **Understand symbol** | `code_explain` | AuthService | -| **Impact of change** | `impact_analyze` | [files] | -| **Tests to run** | `test_select` | [files] | -| **Architecture violations** | `arch_validate` | {} | -| **Where to put code** | `arch_suggest` | filePath | -| **Search by concept** | `semantic_search` | "validation" | -| **Similar patterns** | `find_similar_code` | symbol | -| **Detect violations** | `find_pattern` | "pattern name" | -| **Categorize tests** | `test_categorize` | {} | -| **Test coverage gaps** | `suggest_tests` | symbol | -| **Get context** | `context_pack` | task, profile | -| **Code snippets** | `semantic_slice` | symbol | -| **Historical changes** | `diff_since` | timestamp | -| **Record decision** | `episode_add` | type, content, agentId | -| **Recall decisions** | `decision_query` | agentId | -| **Claim task** | `agent_claim` | agentId, taskName | -| **Release task** | `agent_release` | agentId, taskName | -| **Check coordination** | `agent_status` | {} | -| **Graph health** | `graph_health` | {} | -| **Rebuild graph** | `graph_rebuild` | mode | -| **Cypher query** | `graph_query` | query, language:'cypher' | -| **Set workspace** | `graph_set_workspace` | workspaceRoot, projectId | -| **Code clusters** | `code_clusters` | {} | -| **Semantic diff** | `semantic_diff` | symbol1, symbol2 | -| **Test run** | `test_run` | testFiles | -| **Progress query** | `progress_query` | task | -| **Task update** | `task_update` | taskId, status | -| **Feature status** | `feature_status` | feature | -| **Blocking issues** | `blocking_issues` | {} | -| **Reference repo** | `ref_query` | query | -| **Setup project** | `init_project_setup` | workspaceRoot | -| **Setup copilot** | `setup_copilot_instructions` | {} | -| **Reflect on session** | `reflect` | agentId | -| **Coordination overview** | `coordination_overview` | {} | -| **Search docs** | `search_docs` | query | -| **Index docs** | `index_docs` | {} | +## All 39 Tools Quick Lookup + +| Use Case | Tool | Example | +| --------------------------- | ---------------------------- | ------------------------ | +| **Find code** | `graph_query` | find all HTTP handlers | +| **Understand symbol** | `code_explain` | AuthService | +| **Impact of change** | `impact_analyze` | [files] | +| **Tests to run** | `test_select` | [files] | +| **Architecture violations** | `arch_validate` | {} | +| **Where to put code** | `arch_suggest` | filePath | +| **Search by concept** | `semantic_search` | "validation" | +| **Similar patterns** | `find_similar_code` | symbol | +| **Detect violations** | `find_pattern` | "pattern name" | +| **Categorize tests** | `test_categorize` | {} | +| **Test coverage gaps** | `suggest_tests` | symbol | +| **Get context** | `context_pack` | task, profile | +| **Code snippets** | `semantic_slice` | symbol | +| **Historical changes** | `diff_since` | timestamp | +| **Record decision** | `episode_add` | type, content, agentId | +| **Recall decisions** | `decision_query` | agentId | +| **Claim task** | `agent_claim` | agentId, taskName | +| **Release task** | `agent_release` | agentId, taskName | +| **Check coordination** | `agent_status` | {} | +| **Graph health** | `graph_health` | {} | +| **Rebuild graph** | `graph_rebuild` | mode | +| **Cypher query** | `graph_query` | query, language:'cypher' | +| **Set workspace** | `graph_set_workspace` | workspaceRoot, projectId | +| **Code clusters** | `code_clusters` | {} | +| **Semantic diff** | `semantic_diff` | symbol1, symbol2 | +| **Test run** | `test_run` | testFiles | +| **Progress query** | `progress_query` | task | +| **Task update** | `task_update` | taskId, status | +| **Feature status** | `feature_status` | feature | +| **Blocking issues** | `blocking_issues` | {} | +| **Reference repo** | `ref_query` | query | +| **Setup project** | `init_project_setup` | workspaceRoot | +| **Setup copilot** | `setup_copilot_instructions` | {} | +| **Reflect on session** | `reflect` | agentId | +| **Coordination overview** | `coordination_overview` | {} | +| **Search docs** | `search_docs` | query | +| **Index docs** | `index_docs` | {} | ## Performance Comparison -| Task | Grep | MCP | Improvement | -|------|------|-----|---| -| Find symbol | 450ms | 50ms | 9x | -| Understand function | 5 min manual | 200ms | 1500x | -| Impact analysis | 10 min manual | 100ms | 6000x | -| Search by meaning | 2 min grep | 150ms | 800x | +| Task | Grep | MCP | Improvement | +| ------------------- | ------------- | ----- | ----------- | +| Find symbol | 450ms | 50ms | 9x | +| Understand function | 5 min manual | 200ms | 1500x | +| Impact analysis | 10 min manual | 100ms | 6000x | +| Search by meaning | 2 min grep | 150ms | 800x | --- @@ -237,11 +253,13 @@ await mcp.call('arch_suggest', { ## Token Efficiency (Long Conversations) Use these for compact responses: + - `profile: 'compact'` — for token-light answers - `semantic_slice` — get only relevant code lines - `context_pack` — multi-file context under budget Avoid: + - Full file reads (use `semantic_slice` instead) - Long lists (use `limit` parameter) - Multiple separate queries (combine when possible) diff --git a/docs/templates/GRAPH_EXPERT_AGENT.md b/docs/templates/GRAPH_EXPERT_AGENT.md index 9a9c788..c6da1c2 100644 --- a/docs/templates/GRAPH_EXPERT_AGENT.md +++ b/docs/templates/GRAPH_EXPERT_AGENT.md @@ -8,7 +8,7 @@ You are the **Graph Expert Agent** for this project. Your goal is to produce acc ## Ground Truth About This Project -- Runtime: Node/TypeScript MCP server in `src/server.ts` (33 tools) +- Runtime: Node/TypeScript MCP server in `src/server.ts` (39 tools) - Storage: Memgraph MAGE (`memgraph/memgraph-mage:latest`) + Qdrant - Transport: MCP HTTP (`POST /` and `POST /mcp`) and health at `GET /health` - Workspace context is **session-scoped** (per MCP session), not process-global diff --git a/src/graph/orchestrator.ts b/src/graph/orchestrator.ts index 98be248..dce5b75 100644 --- a/src/graph/orchestrator.ts +++ b/src/graph/orchestrator.ts @@ -1210,7 +1210,6 @@ export class GraphOrchestrator { f.priority = $priority, f.projectId = $projectId, f.createdAt = timestamp() - ON MATCH DO NOTHING `, params: { id: `${projectId}:feature:${feature.id}`, diff --git a/src/tools/__tests__/tool-handlers.contract.test.ts b/src/tools/__tests__/tool-handlers.contract.test.ts index 3678131..95d6426 100644 --- a/src/tools/__tests__/tool-handlers.contract.test.ts +++ b/src/tools/__tests__/tool-handlers.contract.test.ts @@ -116,7 +116,7 @@ describe("ToolHandlers contract normalization", () => { const parsed = JSON.parse(response); expect(parsed.ok).toBe(true); - expect(parsed.contractWarnings).toContain("mapped changedFiles -> files"); + expect(parsed.contractWarnings ?? []).not.toContain("mapped changedFiles -> files"); expect(selectAffectedTests).toHaveBeenCalledWith(["src/baz.ts"], true, 2); }); diff --git a/src/tools/__tests__/tool-handlers.integration.test.ts b/src/tools/__tests__/tool-handlers.integration.test.ts index 958b9da..aa128bc 100644 --- a/src/tools/__tests__/tool-handlers.integration.test.ts +++ b/src/tools/__tests__/tool-handlers.integration.test.ts @@ -715,8 +715,8 @@ describe("INCONSISTENCY: arch_suggest parameter naming", () => { }); }); -describe("INCONSISTENCY: impact_analyze changedFiles normalization", () => { - it("normalizes changedFiles -> files with contract warning via callTool", async () => { +describe("impact_analyze changedFiles normalization", () => { + it("passes changedFiles through natively (no contract warning)", async () => { const { handlers } = createHandlers(); (handlers as any).testEngine = { @@ -734,7 +734,7 @@ describe("INCONSISTENCY: impact_analyze changedFiles normalization", () => { const parsed = parseResponse(response); expect(parsed.ok).toBe(true); - expect(parsed.contractWarnings).toContain("mapped changedFiles -> files"); + expect(parsed.contractWarnings ?? []).not.toContain("mapped changedFiles -> files"); }); it("works directly with files parameter (no warning)", async () => { diff --git a/src/tools/handlers/core-graph-tools.ts b/src/tools/handlers/core-graph-tools.ts index 1efe304..202b63e 100644 --- a/src/tools/handlers/core-graph-tools.ts +++ b/src/tools/handlers/core-graph-tools.ts @@ -702,9 +702,11 @@ export const coreGraphToolDefinitions: ToolDefinition[] = [ const memgraphFileCount = ctx.toSafeNumber(stats.fileCount) ?? 0; const memgraphFuncCount = ctx.toSafeNumber(stats.funcCount) ?? 0; const memgraphClassCount = ctx.toSafeNumber(stats.classCount) ?? 0; - const memgraphImportCount = ctx.toSafeNumber(stats.importCount) ?? 0; - const memgraphIndexableCount = - memgraphFileCount + memgraphFuncCount + memgraphClassCount + memgraphImportCount; + // memgraphIndexableCount counts the same three symbol types tracked by the + // in-memory index (FILE, FUNCTION, CLASS) so both sides of the drift check + // are symmetric. IMPORT, VARIABLE, TEST_* etc. are deliberately excluded + // because the in-memory index may not carry all of them after every sync. + const memgraphIndexableCount = memgraphFileCount + memgraphFuncCount + memgraphClassCount; const indexStats = ctx.context.index.getStatistics(); const indexFileCount = ctx.context.index.getNodesByType("FILE").length; @@ -740,7 +742,10 @@ export const coreGraphToolDefinitions: ToolDefinition[] = [ ) : 0; - const indexDrift = Math.abs(indexStats.totalNodes - memgraphIndexableCount) > 3; + // Compare same types on both sides: in-memory FILE+FUNC+CLASS vs Memgraph FILE+FUNC+CLASS + const cachedIndexableCount = indexFileCount + indexFuncCount + indexClassCount; + const indexDrift = + memgraphIndexableCount > 0 && Math.abs(cachedIndexableCount - memgraphIndexableCount) > 3; const embeddingDrift = embeddingCount < indexedSymbols; const txMetadataResult = await ctx.context.memgraph.executeCypher( @@ -793,7 +798,9 @@ export const coreGraphToolDefinitions: ToolDefinition[] = [ driftDetected: indexDrift, memgraphNodes: memgraphNodeCount, memgraphIndexableNodes: memgraphIndexableCount, - cachedNodes: indexStats.totalNodes, + cachedNodes: cachedIndexableCount, + cachedNodeNote: + "FILE+FUNCTION+CLASS counts compared; other types (VARIABLE, TEST_*, SECTION, etc.) excluded from drift check", memgraphRels: memgraphRelCount, cachedRels: indexStats.totalRelationships, recommendation: indexDrift diff --git a/src/tools/handlers/core-utility-tools.ts b/src/tools/handlers/core-utility-tools.ts index 7f52ff9..ca1d536 100644 --- a/src/tools/handlers/core-utility-tools.ts +++ b/src/tools/handlers/core-utility-tools.ts @@ -4,7 +4,7 @@ */ import * as z from "zod"; -import type { HandlerBridge, ToolDefinition , ToolArgs } from "../types.js"; +import type { HandlerBridge, ToolDefinition, ToolArgs } from "../types.js"; export const coreUtilityToolDefinitions: ToolDefinition[] = [ { @@ -26,13 +26,7 @@ export const coreUtilityToolDefinitions: ToolDefinition[] = [ const KNOWN_CATEGORIES: Record = { setup: ["init_project_setup", "setup_copilot_instructions"], - graph: [ - "graph_set_workspace", - "graph_rebuild", - "graph_query", - "graph_health", - "ref_query", - ], + graph: ["graph_set_workspace", "graph_rebuild", "graph_query", "graph_health", "ref_query"], architecture: ["arch_validate", "arch_suggest"], semantic: [ "semantic_search", @@ -50,6 +44,7 @@ export const coreUtilityToolDefinitions: ToolDefinition[] = [ progress: ["progress_query", "task_update", "feature_status"], coordination: [ "agent_claim", + "agent_status", "agent_release", "coordination_overview", "diff_since", diff --git a/src/tools/handlers/test-tools.ts b/src/tools/handlers/test-tools.ts index ed70b59..d4bc03f 100644 --- a/src/tools/handlers/test-tools.ts +++ b/src/tools/handlers/test-tools.ts @@ -13,7 +13,8 @@ import * as path from "path"; import type { GraphNode, GraphRelationship } from "../../graph/index.js"; import { execWithTimeout } from "../../utils/exec-utils.js"; import * as z from "zod"; -import type { HandlerBridge, ToolDefinition , ToolArgs } from "../types.js"; +import type { HandlerBridge, ToolDefinition, ToolArgs } from "../types.js"; +import { logger } from "../../utils/logger.js"; /** * Determine the command and arguments used to execute tests. @@ -98,7 +99,9 @@ async function resolveDirectImpact(ctx: HandlerBridge, changedFiles: string[]): { projectId, changedPaths: changedFiles }, ); - const paths: string[] = result.data.map((row: Record) => String(row.path ?? "")).filter(Boolean); + const paths: string[] = result.data + .map((row: Record) => String(row.path ?? "")) + .filter(Boolean); if (paths.length > 0) { return paths; @@ -376,7 +379,7 @@ export const testToolDefinitions: ToolDefinition[] = [ ); } - const cwd = process.cwd(); + const cwd = ctx.getActiveProjectContext?.().workspaceRoot ?? process.cwd(); // Resolve runner: config > auto-detect by extension > vitest fallback const { cmd, env: runnerEnv } = resolveTestRunner( @@ -385,12 +388,12 @@ export const testToolDefinitions: ToolDefinition[] = [ ctx.context.config?.testing, ); - console.error(`[ToolHandlers] Executing: ${cmd}`); + logger.debug(`[test_run] Executing in ${cwd}: ${cmd}`); try { const augmentedEnv = { ...process.env, ...(runnerEnv ?? {}) }; const output = execWithTimeout(cmd, { - cwd: process.cwd(), + cwd, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"], env: augmentedEnv, diff --git a/src/tools/tool-handler-base.ts b/src/tools/tool-handler-base.ts index c759657..a77c761 100644 --- a/src/tools/tool-handler-base.ts +++ b/src/tools/tool-handler-base.ts @@ -377,18 +377,7 @@ export abstract class ToolHandlerBase extends SessionManager { const warnings: string[] = []; const normalized = { ...(rawArgs || {}) }; - if (toolName === "impact_analyze") { - const files = Array.isArray(normalized.files) - ? normalized.files - : Array.isArray(normalized.changedFiles) - ? normalized.changedFiles - : []; - if (Array.isArray(normalized.changedFiles) && !Array.isArray(normalized.files)) { - warnings.push("mapped changedFiles -> files"); - } - normalized.files = files; - delete normalized.changedFiles; - } + // impact_analyze: both 'files' and 'changedFiles' are native Zod params — no alias mapping needed. if (toolName === "progress_query") { if (typeof normalized.type !== "string") {