|
1 | | -# Motivation: Why This Exists |
| 1 | +# Why This Exists |
2 | 2 |
|
3 | 3 | > **TL;DR**: AI coding assistants increase throughput but often degrade stability. Without codebase context, they generate code that works but violates team conventions and architectural rules. This MCP provides structured pattern data and recorded rationale so agents produce code that fits. |
4 | 4 |
|
5 | | ---- |
| 5 | +The generated code compiles, passes basic tests, and completely ignores how your team does things or the business context. You fix it, correct the agent, and next session it starts from zero again. Even if you have curated instructions, you cannot note down every convention your team has and it is hard to maintain over time. |
6 | 6 |
|
7 | 7 | ## The Problem |
8 | 8 |
|
9 | | -### The "Stability Paradox" |
10 | | -AI drastically increases **Throughput** (more code/hour) but often kills **Stability** (more bugs/rework). |
| 9 | +AI agents don't fail because they lack "best practices." They fail because they don't know _your_ practices. |
11 | 10 |
|
12 | | -| Pain Point | Evidence | |
13 | | -|------------|----------| |
14 | | -| **"AI doesn't know my codebase"** | 64.7% of developers cite lack of codebase context as top AI challenge ([Stack Overflow 2024](https://survey.stackoverflow.co/2024/ai)) | |
15 | | -| **"Vibe coding" = Tech Debt** | Code churn doubled, rework increased. AI writes "working" code that breaks architectural rules ([GitClear 2024](https://www.gitclear.com/)) | |
16 | | -| **The "Mirror Problem"** | Semantic search just finds *similar* code. If 80% of your code is legacy/deprecated, AI will copy it. The tool becomes a mirror reflecting your bad habits. | |
17 | | -| **Trust gap** | Only 29% of developers trust AI output. Teams spend more time reviewing AI code than writing it. | |
| 11 | +| What happens | Why | |
| 12 | +| ------------------------------------------ | ----------------------------------------------------------------- | |
| 13 | +| Agent uses a deprecated pattern | Can't distinguish modern from legacy when exploring your codebase | |
| 14 | +| Agent ignores your internal wrappers | Doesn't know they exist — picks raw library imports | |
| 15 | +| Agent invents patterns that don't exist | Makes up variable names, component names, CSS tokens | |
| 16 | +| Agent repeats a mistake you corrected | No memory across sessions | |
| 17 | +| Agent edits confidently with weak evidence | No way to know when it doesn't know enough | |
18 | 18 |
|
19 | | -### What Existing Tools Don't Solve |
| 19 | +The root cause isn't the model. It's the context layer. Agents get raw code from search and generic rules from static files. No signal about what's current vs legacy, no team patterns, no memory. |
20 | 20 |
|
21 | | -| Tool Category | What They Do | The Gap | |
22 | | -|---------------|--------------|---------| |
23 | | -| **AGENTS.md / .cursorrules** | Static instructions (Intent) | Can't handle migration states (e.g., "Use A for new, B for old"). Static = brittle. | |
24 | | -| **Semantic Search (RAG)** | Finds *relevant* text | Blind to *quality*. Can't distinguish "High Churn Hotspot" from "Stable Core". | |
25 | | -| **Linters** | Complain *after* coding | Don't guide *during* generation. | |
| 21 | +## What Exists Today (and the missing context) |
26 | 22 |
|
27 | | ---- |
| 23 | +| Approach | What it does | What's missing | |
| 24 | +| ---------------------------- | --------------------------------------------------- | ------------------------------------------------------------------------------- | |
| 25 | +| `.cursorrules` / `AGENTS.md` | Static rules the agent may or may not always follow | Can't express migration states ("use A for new code, B for old"). Goes stale. | |
| 26 | +| Semantic search / RAG | Finds similar code | Blind to quality. Can't tell the best example to follow from hacky workarounds. | |
| 27 | +| Linters / formatters | Enforce static rules after writing | Don't guide before or during generation. Agent still writes wrong code first. | |
| 28 | +| Tool-heavy MCPs (50+ tools) | Expose everything | Agents don't know which tool to call. More tools = more confusion. | |
28 | 29 |
|
29 | | -## What This Does |
| 30 | +## What This MCP Does Differently |
30 | 31 |
|
31 | | -This MCP provides **active context** - not raw data, but structured intelligence derived from actual codebase state. |
| 32 | +### Active context, not passive instructions |
32 | 33 |
|
33 | | -### 1. Pattern Discovery (The "Map") |
34 | | -- **Frequency Detection**: "97% use `inject()`, 3% use `constructor`." (Consensus) |
35 | | -- **Internal Library Support**: "Use `@company/button`, not `p-button`." (Wrapper Detection) |
36 | | -- **Golden Files**: "Here is the *best* example of a Service, not just *any* example." |
| 34 | +When the agent searches, it doesn't get raw code. It gets code with codebase intelligence attached: |
37 | 35 |
|
38 | | -### 2. Temporal Wisdom (The "Compass") |
39 | | -- **Pattern Momentum**: "Use `Signals` (Rising), avoid `BehaviorSubject` (Declining)." |
40 | | -- **Health Context**: "⚠️ Careful, `UserService.ts` is a high-churn hotspot with circular dependencies. Add tests." |
| 36 | +- Is this file using a new or legacy pattern? |
| 37 | +- What other files import it? |
| 38 | +- What team decisions relate to this area? |
| 39 | +- Is the context evidence strong enough to edit? |
| 40 | +- What conventions should the Agent prefer and what to avoid? |
41 | 41 |
|
42 | | -### Works with AGENTS.md |
43 | | -- **AGENTS.md** defines intent: "Use functional patterns." |
44 | | -- **MCP** provides evidence: "Here are the 5 most recent functional patterns actually used." |
| 42 | +### Conventions from code, not from documentation |
45 | 43 |
|
46 | | ---- |
| 44 | +Pattern detection runs on the actual codebase, not only on rules someone wrote. If 97% of the team uses the (Angular) `inject()` function for DI over constructor DI and it's trending up, the agent knows - even if nobody documented it. |
47 | 45 |
|
48 | | -## Known Limitations |
| 46 | +### Memory that compounds |
49 | 47 |
|
50 | | -| Limitation | Mitigation | |
51 | | -|------------|--------| |
52 | | -| **Pattern frequency ≠ pattern quality** | **Pattern Momentum** (Rise/Fall trends) distinguishes adoption direction from raw count. | |
53 | | -| **Stale index risk** | Manual re-indexing required for now. | |
54 | | -| **Framework coverage** | Deep analysis for Angular. Generic analyzer covers 30+ languages. React/Vue specialized analyzers extensible. | |
55 | | -| **File-level trend detection** | Trend is based on file modification date, not line-by-line content. A recently modified file may still contain legacy patterns on specific lines. Future: AST-based line-level detection. | |
| 48 | +Correct the agent once. Record the decision. From then on, it surfaces in search results and the "preflight" cards - that safeguard AI Agents from generating code that "just compiles". Memories age with confidence decay so stale guidance gets flagged instead of blindly trusted. |
56 | 49 |
|
57 | | ---- |
| 50 | +### Evidence gating |
58 | 51 |
|
59 | | -## Key Learnings (The Journey) |
| 52 | +Before an edit, the agent gets a curated "preflight" check from three sources (code, patterns, memories). If evidence is thin or contradictory, the response tells the AI Agent to look for more evidence with a concrete next step. This is the difference between "confident assumption" and "informed decision." |
60 | 53 |
|
61 | | -1. **Context alone is dangerous**: Giving AI "all the context" just confuses it or teaches it bad habits (Search Contamination). |
62 | | -2. **Decisions > Data**: AI needs *guidance* ("Use X"), not just *options* ("Here is X and Y"). |
63 | | -3. **Governance through Discovery**: Blocking PRs is not required. If the AI sees that a pattern is "Declining" and "Dangerous," it self-corrects. |
| 54 | +## Key Design Decisions |
64 | 55 |
|
65 | | ---- |
| 56 | +1. **Fewer tools, richer responses.** 10 tools instead of 50. One search call that aggregates everything. |
| 57 | +2. **Local-first.** Embeddings default to a local model (Transformers.js). No cloud, no API key required - but absolutely optional. |
| 58 | +3. **Evidence over opinions.** Every signal has a source: adoption %, trend direction, confidence score. No "best practice" claims. |
| 59 | +4. **Graceful degradation.** If intelligence isn't available, search still works — just without enrichment. Preflight is additive, not required. |
66 | 60 |
|
67 | 61 | ## Sources |
68 | 62 |
|
69 | | -### Industry Research |
70 | | -1. [Stack Overflow 2024 Developer Survey](https://survey.stackoverflow.co/2024/ai) |
71 | | -2. [GitClear 2024 AI Code Quality Report](https://www.gitclear.com/) (The "Churn" problem) |
72 | | -3. [DORA State of DevOps 2024](https://dora.dev/research/2024/dora-report/) (Stability vs Throughput) |
73 | | - |
74 | | -### Internal Validation |
75 | | -- **Search Contamination**: Without MCP, models copied legacy patterns 40% of the time. |
76 | | -- **Momentum Success**: With "Trending" signals, models adopted modern patterns even when they were the minority (3%). |
77 | | - |
| 63 | +- [Stack Overflow 2024 Developer Survey](https://survey.stackoverflow.co/2024/ai) — 64.7% cite lack of codebase context as top AI challenge |
| 64 | +- [GitClear 2024](https://www.gitclear.com/) — Code churn correlation with AI adoption |
| 65 | +- [DORA State of DevOps 2024](https://dora.dev/research/2024/dora-report/) — Throughput vs stability tradeoff |
0 commit comments