codebase-context 1.2.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +144 -87
- package/dist/analyzers/angular/index.d.ts +1 -1
- package/dist/analyzers/angular/index.d.ts.map +1 -1
- package/dist/analyzers/angular/index.js +298 -309
- package/dist/analyzers/angular/index.js.map +1 -1
- package/dist/analyzers/generic/index.d.ts +1 -1
- package/dist/analyzers/generic/index.d.ts.map +1 -1
- package/dist/analyzers/generic/index.js +93 -47
- package/dist/analyzers/generic/index.js.map +1 -1
- package/dist/constants/codebase-context.d.ts +6 -0
- package/dist/constants/codebase-context.d.ts.map +1 -0
- package/dist/constants/codebase-context.js +8 -0
- package/dist/constants/codebase-context.js.map +1 -0
- package/dist/core/analyzer-registry.d.ts.map +1 -1
- package/dist/core/analyzer-registry.js +5 -7
- package/dist/core/analyzer-registry.js.map +1 -1
- package/dist/core/indexer.d.ts +9 -1
- package/dist/core/indexer.d.ts.map +1 -1
- package/dist/core/indexer.js +206 -139
- package/dist/core/indexer.js.map +1 -1
- package/dist/core/search.d.ts +1 -1
- package/dist/core/search.d.ts.map +1 -1
- package/dist/core/search.js +63 -59
- package/dist/core/search.js.map +1 -1
- package/dist/embeddings/openai.d.ts.map +1 -1
- package/dist/embeddings/openai.js +2 -2
- package/dist/embeddings/openai.js.map +1 -1
- package/dist/embeddings/transformers.d.ts +1 -1
- package/dist/embeddings/transformers.d.ts.map +1 -1
- package/dist/embeddings/transformers.js +19 -15
- package/dist/embeddings/transformers.js.map +1 -1
- package/dist/embeddings/types.d.ts +1 -1
- package/dist/embeddings/types.d.ts.map +1 -1
- package/dist/embeddings/types.js +3 -3
- package/dist/embeddings/types.js.map +1 -1
- package/dist/errors/index.d.ts +8 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +11 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +6 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +691 -335
- package/dist/index.js.map +1 -1
- package/dist/lib.d.ts +18 -18
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +23 -23
- package/dist/lib.js.map +1 -1
- package/dist/memory/store.d.ts +22 -0
- package/dist/memory/store.d.ts.map +1 -0
- package/dist/memory/store.js +97 -0
- package/dist/memory/store.js.map +1 -0
- package/dist/storage/lancedb.d.ts.map +1 -1
- package/dist/storage/lancedb.js +27 -31
- package/dist/storage/lancedb.js.map +1 -1
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/storage/types.js +2 -1
- package/dist/storage/types.js.map +1 -1
- package/dist/types/index.d.ts +27 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/utils/chunking.d.ts.map +1 -1
- package/dist/utils/chunking.js +10 -9
- package/dist/utils/chunking.js.map +1 -1
- package/dist/utils/dependency-detection.d.ts +18 -0
- package/dist/utils/dependency-detection.d.ts.map +1 -0
- package/dist/utils/dependency-detection.js +102 -0
- package/dist/utils/dependency-detection.js.map +1 -0
- package/dist/utils/git-dates.d.ts.map +1 -1
- package/dist/utils/git-dates.js +3 -3
- package/dist/utils/git-dates.js.map +1 -1
- package/dist/utils/language-detection.d.ts.map +1 -1
- package/dist/utils/language-detection.js +69 -17
- package/dist/utils/language-detection.js.map +1 -1
- package/dist/utils/usage-tracker.d.ts +2 -2
- package/dist/utils/usage-tracker.d.ts.map +1 -1
- package/dist/utils/usage-tracker.js +64 -32
- package/dist/utils/usage-tracker.js.map +1 -1
- package/dist/utils/workspace-detection.d.ts +32 -0
- package/dist/utils/workspace-detection.d.ts.map +1 -0
- package/dist/utils/workspace-detection.js +107 -0
- package/dist/utils/workspace-detection.js.map +1 -0
- package/package.json +114 -97
- package/dist/core/file-watcher.d.ts +0 -63
- package/dist/core/file-watcher.d.ts.map +0 -1
- package/dist/core/file-watcher.js +0 -210
- package/dist/core/file-watcher.js.map +0 -1
- package/dist/utils/logger.d.ts +0 -36
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -111
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/pattern-detector.d.ts +0 -41
- package/dist/utils/pattern-detector.d.ts.map +0 -1
- package/dist/utils/pattern-detector.js +0 -101
- package/dist/utils/pattern-detector.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 PatrickSys
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 PatrickSys
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,87 +1,144 @@
|
|
|
1
|
-
# codebase-context
|
|
2
|
-
|
|
3
|
-
**AI coding agents don't know your codebase. This MCP fixes that.**
|
|
4
|
-
|
|
5
|
-
Your team has internal libraries, naming conventions, and patterns that external AI models have never seen. This MCP server gives AI assistants real-time visibility into your codebase: which libraries your team actually uses, how often, and where to find canonical examples.
|
|
6
|
-
|
|
7
|
-
## Quick Start
|
|
8
|
-
|
|
9
|
-
Add this to your MCP client config (Claude Desktop, VS Code, Cursor, etc.).
|
|
10
|
-
|
|
11
|
-
```json
|
|
12
|
-
"mcpServers": {
|
|
13
|
-
"codebase-context": {
|
|
14
|
-
"command": "npx",
|
|
15
|
-
"args": ["codebase-context", "/path/to/your/project"]
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
- **
|
|
25
|
-
- **
|
|
26
|
-
- **
|
|
27
|
-
- **
|
|
28
|
-
- **
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
|
67
|
-
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
70
|
-
| `
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
1
|
+
# codebase-context
|
|
2
|
+
|
|
3
|
+
**AI coding agents don't know your codebase. This MCP fixes that.**
|
|
4
|
+
|
|
5
|
+
Your team has internal libraries, naming conventions, and patterns that external AI models have never seen. This MCP server gives AI assistants real-time visibility into your codebase: which libraries your team actually uses, how often, and where to find canonical examples.
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
Add this to your MCP client config (Claude Desktop, VS Code, Cursor, etc.).
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
"mcpServers": {
|
|
13
|
+
"codebase-context": {
|
|
14
|
+
"command": "npx",
|
|
15
|
+
"args": ["codebase-context", "/path/to/your/project"]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
If your environment prompts on first run, use `npx --yes ...` (or `npx -y ...`) to auto-confirm.
|
|
21
|
+
|
|
22
|
+
## What You Get
|
|
23
|
+
|
|
24
|
+
- **Internal library discovery** → `@mycompany/ui-toolkit`: 847 uses vs `primeng`: 3 uses
|
|
25
|
+
- **Pattern frequencies** → `inject()`: 97%, `constructor()`: 3%
|
|
26
|
+
- **Pattern momentum** → `Signals`: Rising (last used 2 days ago) vs `RxJS`: Declining (180+ days)
|
|
27
|
+
- **Golden file examples** → Real implementations showing all patterns together
|
|
28
|
+
- **Testing conventions** → `Jest`: 74%, `Playwright`: 6%
|
|
29
|
+
- **Framework patterns** → Angular signals, standalone components, etc.
|
|
30
|
+
- **Circular dependency detection** → Find toxic import cycles between files
|
|
31
|
+
- **Memory system** → Record "why" behind choices so AI doesn't repeat mistakes
|
|
32
|
+
|
|
33
|
+
## How It Works
|
|
34
|
+
|
|
35
|
+
When generating code, the agent checks your patterns first:
|
|
36
|
+
|
|
37
|
+
| Without MCP | With MCP |
|
|
38
|
+
| ---------------------------------------- | ------------------------------------ |
|
|
39
|
+
| Uses `constructor(private svc: Service)` | Uses `inject()` (97% team adoption) |
|
|
40
|
+
| Suggests `primeng/button` directly | Uses `@mycompany/ui-toolkit` wrapper |
|
|
41
|
+
| Generic Jest setup | Your team's actual test utilities |
|
|
42
|
+
|
|
43
|
+
### Tip: Auto-invoke in your rules
|
|
44
|
+
|
|
45
|
+
Add this to your `.cursorrules`, `CLAUDE.md`, or `AGENTS.md`:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
## Codebase Context
|
|
49
|
+
|
|
50
|
+
**At start of each task:** Call `get_memory` to load team conventions.
|
|
51
|
+
|
|
52
|
+
**CRITICAL:** When user says "remember this" or "record this":
|
|
53
|
+
- STOP immediately and call `remember` tool FIRST
|
|
54
|
+
- DO NOT proceed with other actions until memory is recorded
|
|
55
|
+
- This is a blocking requirement, not optional
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Now the agent checks patterns automatically instead of waiting for you to ask.
|
|
59
|
+
|
|
60
|
+
## Tools
|
|
61
|
+
|
|
62
|
+
| Tool | Purpose |
|
|
63
|
+
| ------------------------------ | --------------------------------------------- |
|
|
64
|
+
| `search_codebase` | Semantic + keyword hybrid search |
|
|
65
|
+
| `get_component_usage` | Find where a library/component is used |
|
|
66
|
+
| `get_team_patterns` | Pattern frequencies + canonical examples |
|
|
67
|
+
| `get_codebase_metadata` | Project structure overview |
|
|
68
|
+
| `get_indexing_status` | Indexing progress + last stats |
|
|
69
|
+
| `get_style_guide` | Query style guide rules |
|
|
70
|
+
| `detect_circular_dependencies` | Find import cycles between files |
|
|
71
|
+
| `remember` | Record memory (conventions/decisions/gotchas) |
|
|
72
|
+
| `get_memory` | Query recorded memory by category/keyword |
|
|
73
|
+
| `refresh_index` | Re-index the codebase |
|
|
74
|
+
|
|
75
|
+
## File Structure
|
|
76
|
+
|
|
77
|
+
The MCP creates the following structure in your project:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
.codebase-context/
|
|
81
|
+
├── memory.json # Team knowledge (commit this)
|
|
82
|
+
├── intelligence.json # Pattern analysis (generated)
|
|
83
|
+
├── index.json # Keyword index (generated)
|
|
84
|
+
└── index/ # Vector database (generated)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Recommended `.gitignore`:** The vector database and generated files can be large. Add this to your `.gitignore` to keep them local while sharing team memory:
|
|
88
|
+
|
|
89
|
+
```gitignore
|
|
90
|
+
# Codebase Context MCP - ignore generated files, keep memory
|
|
91
|
+
.codebase-context/*
|
|
92
|
+
!.codebase-context/memory.json
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Memory System
|
|
96
|
+
|
|
97
|
+
Patterns tell you _what_ the team does ("97% use inject"), but not _why_ ("standalone compatibility"). Use `remember` to capture rationale that prevents repeated mistakes:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
// AI won't change this again after recording the decision
|
|
101
|
+
remember({
|
|
102
|
+
type: 'decision',
|
|
103
|
+
category: 'dependencies',
|
|
104
|
+
memory: 'Use node-linker: hoisted, not isolated',
|
|
105
|
+
reason:
|
|
106
|
+
"Some packages don't declare transitive deps. Isolated forces manual package.json additions."
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Memories surface automatically in `search_codebase` results and `get_team_patterns` responses.
|
|
111
|
+
|
|
112
|
+
**Early baseline — known quirks:**
|
|
113
|
+
|
|
114
|
+
- Agents may bundle multiple things into one entry
|
|
115
|
+
- Duplicates can happen if you record the same thing twice
|
|
116
|
+
- Edit `.codebase-context/memory.json` directly to clean up
|
|
117
|
+
- Be explicit: "Remember this: use X not Y"
|
|
118
|
+
|
|
119
|
+
## Configuration
|
|
120
|
+
|
|
121
|
+
| Variable | Default | Description |
|
|
122
|
+
| ------------------------ | -------------- | ------------------------------------------------------------------------------ |
|
|
123
|
+
| `EMBEDDING_PROVIDER` | `transformers` | `openai` (fast, cloud) or `transformers` (local, private) |
|
|
124
|
+
| `OPENAI_API_KEY` | - | Required if provider is `openai` |
|
|
125
|
+
| `CODEBASE_ROOT` | - | Project root to index (CLI arg takes precedence) |
|
|
126
|
+
| `CODEBASE_CONTEXT_DEBUG` | - | Set to `1` to enable verbose logging (startup messages, analyzer registration) |
|
|
127
|
+
|
|
128
|
+
## Performance Note
|
|
129
|
+
|
|
130
|
+
This tool runs **locally** on your machine using your hardware.
|
|
131
|
+
|
|
132
|
+
- **Initial Indexing**: The first run works hard. It may take several minutes (e.g., ~2-5 mins for 30k files) to compute embeddings for your entire codebase.
|
|
133
|
+
- **Caching**: Subsequent queries are instant (milliseconds).
|
|
134
|
+
- **Updates**: Currently, `refresh_index` re-scans the codebase. True incremental indexing (processing only changed files) is on the roadmap.
|
|
135
|
+
|
|
136
|
+
## Links
|
|
137
|
+
|
|
138
|
+
- 📄 [Motivation](./MOTIVATION.md) — Why this exists, research, learnings
|
|
139
|
+
- 📋 [Changelog](./CHANGELOG.md) — Version history
|
|
140
|
+
- 🤝 [Contributing](./CONTRIBUTING.md) — How to add analyzers
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Understands components, services, directives, pipes, modules, guards, interceptors, etc.
|
|
4
4
|
* Detects state management patterns, architectural layers, and Angular-specific patterns
|
|
5
5
|
*/
|
|
6
|
-
import { FrameworkAnalyzer, AnalysisResult, CodebaseMetadata, CodeChunk } from
|
|
6
|
+
import { FrameworkAnalyzer, AnalysisResult, CodebaseMetadata, CodeChunk } from '../../types/index.js';
|
|
7
7
|
export declare class AngularAnalyzer implements FrameworkAnalyzer {
|
|
8
8
|
readonly name = "angular";
|
|
9
9
|
readonly version = "1.0.0";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/analyzers/angular/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/analyzers/angular/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,SAAS,EAKV,MAAM,sBAAsB,CAAC;AAQ9B,qBAAa,eAAgB,YAAW,iBAAiB;IACvD,QAAQ,CAAC,IAAI,aAAa;IAC1B,QAAQ,CAAC,OAAO,WAAW;IAC3B,QAAQ,CAAC,mBAAmB,WAA8D;IAC1F,QAAQ,CAAC,QAAQ,OAAO;IAExB,OAAO,CAAC,eAAe,CAYrB;IAEF,OAAO,CAAC,uBAAuB,CAM7B;IAEF,OAAO,CAAC,qBAAqB,CAa3B;IAEF,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO;IAqBjD,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;YA0B3D,qBAAqB;IAuNnC;;OAEG;IACH,OAAO,CAAC,2BAA2B;YAYrB,uBAAuB;IA+GrC,OAAO,CAAC,wBAAwB;IAgChC,OAAO,CAAC,qBAAqB;IA2B7B,OAAO,CAAC,uBAAuB;IAqB/B,OAAO,CAAC,aAAa;IA4CrB,OAAO,CAAC,cAAc;YAyCR,mBAAmB;YAiCnB,gBAAgB;IAwB9B,OAAO,CAAC,qBAAqB;IAS7B,OAAO,CAAC,cAAc;IA0DtB,OAAO,CAAC,oBAAoB;IA2BtB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAwJzE;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM;IA2FnC,OAAO,CAAC,uBAAuB;IAY/B,OAAO,CAAC,oBAAoB;IAU5B,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,mBAAmB;IAK3B,OAAO,CAAC,gBAAgB;CAMzB"}
|