@mcampa/claude-context-core 0.2.0 → 0.2.1

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/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # @mcampa/claude-context-core
2
+
2
3
  ![](../../assets/claude-context.png)
3
4
 
4
5
  The core indexing engine for Claude Context - a powerful tool for semantic search and analysis of codebases using vector embeddings and AI.
@@ -15,14 +16,18 @@ npm install @mcampa/claude-context-core
15
16
  ```
16
17
 
17
18
  ### Prepare Environment Variables
19
+
18
20
  #### OpenAI API key
21
+
19
22
  See [OpenAI Documentation](https://platform.openai.com/docs/api-reference) for more details to get your API key.
23
+
20
24
  ```bash
21
25
  OPENAI_API_KEY=your-openai-api-key
22
26
  ```
23
27
 
24
28
  #### Zilliz Cloud configuration
25
- Get a free Milvus vector database on Zilliz Cloud.
29
+
30
+ Get a free Milvus vector database on Zilliz Cloud.
26
31
 
27
32
  Claude Context needs a vector database. You can [sign up](https://cloud.zilliz.com/signup?utm_source=github&utm_medium=referral&utm_campaign=2507-codecontext-readme) on Zilliz Cloud to get a free Serverless cluster.
28
33
 
@@ -40,53 +45,54 @@ If you need help creating your free vector database or finding these values, see
40
45
  ```bash
41
46
  MILVUS_ADDRESS=your-zilliz-cloud-public-endpoint
42
47
  MILVUS_TOKEN=your-zilliz-cloud-api-key
43
- ```
48
+ ```
44
49
 
45
50
  > 💡 **Tip**: For easier configuration management across different usage scenarios, consider using [global environment variables](../../docs/getting-started/environment-variables.md).
46
51
 
47
52
  ## Quick Start
48
53
 
49
54
  ```typescript
50
- import {
51
- Context,
52
- OpenAIEmbedding,
53
- MilvusVectorDatabase
54
- } from '@mcampa/claude-context-core';
55
+ import {
56
+ Context,
57
+ OpenAIEmbedding,
58
+ MilvusVectorDatabase,
59
+ } from "@mcampa/claude-context-core";
55
60
 
56
61
  // Initialize embedding provider
57
62
  const embedding = new OpenAIEmbedding({
58
- apiKey: process.env.OPENAI_API_KEY || 'your-openai-api-key',
59
- model: 'text-embedding-3-small'
63
+ apiKey: process.env.OPENAI_API_KEY || "your-openai-api-key",
64
+ model: "text-embedding-3-small",
60
65
  });
61
66
 
62
67
  // Initialize vector database
63
68
  const vectorDatabase = new MilvusVectorDatabase({
64
- address: process.env.MILVUS_ADDRESS || 'localhost:19530',
65
- token: process.env.MILVUS_TOKEN || ''
69
+ address: process.env.MILVUS_ADDRESS || "localhost:19530",
70
+ token: process.env.MILVUS_TOKEN || "",
66
71
  });
67
72
 
68
73
  // Create context instance
69
74
  const context = new Context({
70
- name: 'my-context',
75
+ name: "my-context",
71
76
  embedding,
72
- vectorDatabase
77
+ vectorDatabase,
73
78
  });
74
79
 
75
80
  // Index a codebase
76
- const stats = await context.indexCodebase('./my-project', (progress) => {
81
+ const stats = await context.indexCodebase("./my-project", (progress) => {
77
82
  console.log(`${progress.phase} - ${progress.percentage}%`);
78
83
  });
79
84
 
80
- console.log(`Indexed ${stats.indexedFiles} files with ${stats.totalChunks} chunks`);
85
+ console.log(
86
+ `Indexed ${stats.indexedFiles} files with ${stats.totalChunks} chunks`
87
+ );
81
88
 
82
89
  // Search the codebase
83
90
  const results = await context.semanticSearch(
84
- './my-project',
85
- 'function that handles user authentication',
91
+ "function that handles user authentication",
86
92
  5
87
93
  );
88
94
 
89
- results.forEach(result => {
95
+ results.forEach((result) => {
90
96
  console.log(`${result.relativePath}:${result.startLine}-${result.endLine}`);
91
97
  console.log(`Score: ${result.score}`);
92
98
  console.log(result.content);
@@ -125,12 +131,13 @@ results.forEach(result => {
125
131
 
126
132
  ```typescript
127
133
  interface ContextConfig {
128
- embedding?: Embedding; // Embedding provider
134
+ name?: string; // Context name (default: 'my-context')
135
+ embedding?: Embedding; // Embedding provider
129
136
  vectorDatabase?: VectorDatabase; // Vector database instance (required)
130
- codeSplitter?: Splitter; // Code splitting strategy
137
+ codeSplitter?: Splitter; // Code splitting strategy
131
138
  supportedExtensions?: string[]; // File extensions to index
132
- ignorePatterns?: string[]; // Patterns to ignore
133
- customExtensions?: string[]; // Custom extensions from MCP
139
+ ignorePatterns?: string[]; // Patterns to ignore
140
+ customExtensions?: string[]; // Custom extensions from MCP
134
141
  customIgnorePatterns?: string[]; // Custom ignore patterns from MCP
135
142
  }
136
143
  ```
@@ -140,11 +147,31 @@ interface ContextConfig {
140
147
  ```typescript
141
148
  [
142
149
  // Programming languages
143
- '.ts', '.tsx', '.js', '.jsx', '.py', '.java', '.cpp', '.c', '.h', '.hpp',
144
- '.cs', '.go', '.rs', '.php', '.rb', '.swift', '.kt', '.scala', '.m', '.mm',
145
- // Text and markup files
146
- '.md', '.markdown', '.ipynb'
147
- ]
150
+ ".ts",
151
+ ".tsx",
152
+ ".js",
153
+ ".jsx",
154
+ ".py",
155
+ ".java",
156
+ ".cpp",
157
+ ".c",
158
+ ".h",
159
+ ".hpp",
160
+ ".cs",
161
+ ".go",
162
+ ".rs",
163
+ ".php",
164
+ ".rb",
165
+ ".swift",
166
+ ".kt",
167
+ ".scala",
168
+ ".m",
169
+ ".mm",
170
+ // Text and markup files
171
+ ".md",
172
+ ".markdown",
173
+ ".ipynb",
174
+ ];
148
175
  ```
149
176
 
150
177
  ### Default Ignore Patterns
@@ -165,8 +192,8 @@ interface ContextConfig {
165
192
 
166
193
  - `indexCodebase(path, progressCallback?, forceReindex?)` - Index an entire codebase
167
194
  - `reindexByChange(path, progressCallback?)` - Incrementally re-index only changed files
168
- - `semanticSearch(path, query, topK?, threshold?, filterExpr?)` - Search indexed code semantically
169
- - `hasIndex(path)` - Check if codebase is already indexed
195
+ - `semanticSearch(query, topK?, threshold?, filterExpr?)` - Search indexed code semantically
196
+ - `hasIndex()` - Check if index exists
170
197
  - `clearIndex(path, progressCallback?)` - Remove index for a codebase
171
198
  - `updateIgnorePatterns(patterns)` - Update ignore patterns
172
199
  - `addCustomIgnorePatterns(patterns)` - Add custom ignore patterns
@@ -179,38 +206,41 @@ interface ContextConfig {
179
206
 
180
207
  ```typescript
181
208
  interface SemanticSearchResult {
182
- content: string; // Code content
209
+ content: string; // Code content
183
210
  relativePath: string; // File path relative to codebase root
184
- startLine: number; // Starting line number
185
- endLine: number; // Ending line number
186
- language: string; // Programming language
187
- score: number; // Similarity score (0-1)
211
+ startLine: number; // Starting line number
212
+ endLine: number; // Ending line number
213
+ language: string; // Programming language
214
+ score: number; // Similarity score (0-1)
188
215
  }
189
216
  ```
190
217
 
191
-
192
218
  ## Examples
193
219
 
194
220
  ### Using VoyageAI Embeddings
195
221
 
196
222
  ```typescript
197
- import { Context, MilvusVectorDatabase, VoyageAIEmbedding } from '@mcampa/claude-context-core';
223
+ import {
224
+ Context,
225
+ MilvusVectorDatabase,
226
+ VoyageAIEmbedding,
227
+ } from "@mcampa/claude-context-core";
198
228
 
199
229
  // Initialize with VoyageAI embedding provider
200
230
  const embedding = new VoyageAIEmbedding({
201
- apiKey: process.env.VOYAGEAI_API_KEY || 'your-voyageai-api-key',
202
- model: 'voyage-code-3'
231
+ apiKey: process.env.VOYAGEAI_API_KEY || "your-voyageai-api-key",
232
+ model: "voyage-code-3",
203
233
  });
204
234
 
205
235
  const vectorDatabase = new MilvusVectorDatabase({
206
- address: process.env.MILVUS_ADDRESS || 'localhost:19530',
207
- token: process.env.MILVUS_TOKEN || ''
236
+ address: process.env.MILVUS_ADDRESS || "localhost:19530",
237
+ token: process.env.MILVUS_TOKEN || "",
208
238
  });
209
239
 
210
240
  const context = new Context({
211
- name: 'my-context',
241
+ name: "my-context",
212
242
  embedding,
213
- vectorDatabase
243
+ vectorDatabase,
214
244
  });
215
245
  ```
216
246
 
@@ -218,19 +248,35 @@ const context = new Context({
218
248
 
219
249
  ```typescript
220
250
  const context = new Context({
221
- name: 'my-context',
251
+ name: "my-context",
222
252
  embedding,
223
253
  vectorDatabase,
224
- supportedExtensions: ['.ts', '.js', '.py', '.java'],
225
- ignorePatterns: [
226
- 'node_modules/**',
227
- 'dist/**',
228
- '*.spec.ts',
229
- '*.test.js'
230
- ]
254
+ supportedExtensions: [".ts", ".js", ".py", ".java"],
255
+ ignorePatterns: ["node_modules/**", "dist/**", "*.spec.ts", "*.test.js"],
231
256
  });
232
257
  ```
233
258
 
259
+ ### Relative Path Indexing
260
+
261
+ File paths are indexed relative to the `codebasePath` parameter you provide when indexing:
262
+
263
+ ```typescript
264
+ // Index a codebase - paths will be relative to this directory
265
+ await context.indexCodebase("/Users/username/projects/my-workspace");
266
+
267
+ // Search returns results with relative paths
268
+ const results = await context.semanticSearch("user authentication function");
269
+
270
+ // Results show paths relative to the indexed codebase path, e.g.:
271
+ // "packages/app/src/auth.ts" instead of full absolute path
272
+ ```
273
+
274
+ This makes search results:
275
+
276
+ - More readable and concise
277
+ - Portable across different machines
278
+ - Consistent in monorepo environments
279
+
234
280
  ## File Synchronization Architecture
235
281
 
236
282
  Claude Context implements an intelligent file synchronization system that efficiently tracks and processes only the files that have changed since the last indexing operation. This dramatically improves performance when working with large codebases.
@@ -242,21 +288,25 @@ Claude Context implements an intelligent file synchronization system that effici
242
288
  The file synchronization system uses a **Merkle tree-based approach** combined with SHA-256 file hashing to detect changes:
243
289
 
244
290
  #### 1. File Hashing
291
+
245
292
  - Each file in the codebase is hashed using SHA-256
246
293
  - File hashes are computed based on file content, not metadata
247
294
  - Hashes are stored with relative file paths for consistency across different environments
248
295
 
249
296
  #### 2. Merkle Tree Construction
297
+
250
298
  - All file hashes are organized into a Merkle tree structure
251
299
  - The tree provides a single root hash that represents the entire codebase state
252
300
  - Any change to any file will cause the root hash to change
253
301
 
254
302
  #### 3. Snapshot Management
303
+
255
304
  - File synchronization state is persisted to `~/.context/merkle/` directory
256
305
  - Each codebase gets a unique snapshot file based on its absolute path hash
257
306
  - Snapshots contain both file hashes and serialized Merkle tree data
258
307
 
259
308
  #### 4. Change Detection Process
309
+
260
310
  1. **Quick Check**: Compare current Merkle root hash with stored snapshot
261
311
  2. **Detailed Analysis**: If root hashes differ, perform file-by-file comparison
262
312
  3. **Change Classification**: Categorize changes into three types:
@@ -265,15 +315,16 @@ The file synchronization system uses a **Merkle tree-based approach** combined w
265
315
  - **Removed**: Files that were deleted from the codebase
266
316
 
267
317
  #### 5. Incremental Updates
318
+
268
319
  - Only process files that have actually changed
269
320
  - Update vector database entries only for modified chunks
270
321
  - Remove entries for deleted files
271
322
  - Add entries for new files
272
323
 
273
-
274
324
  ## Contributing
275
325
 
276
326
  This package is part of the Claude Context monorepo. Please see:
327
+
277
328
  - [Main Contributing Guide](../../CONTRIBUTING.md) - General contribution guidelines
278
329
  - [Core Package Contributing](CONTRIBUTING.md) - Specific development guide for this package
279
330
 
@@ -282,7 +333,6 @@ This package is part of the Claude Context monorepo. Please see:
282
333
  - **[@claude-context/mcp](../mcp)** - MCP server that uses this core engine
283
334
  - **[VSCode Extension](../vscode-extension)** - VSCode extension built on this core
284
335
 
285
-
286
336
  ## License
287
337
 
288
- MIT - See [LICENSE](../../LICENSE) for details
338
+ MIT - See [LICENSE](../../LICENSE) for details