@mcampa/claude-context-core 0.1.4 → 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,28 +1,33 @@
1
- # @zilliz/claude-context-core
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.
5
6
 
6
- [![npm version](https://img.shields.io/npm/v/@zilliz/claude-context-core.svg)](https://www.npmjs.com/package/@zilliz/claude-context-core)
7
- [![npm downloads](https://img.shields.io/npm/dm/@zilliz/claude-context-core.svg)](https://www.npmjs.com/package/@zilliz/claude-context-core)
7
+ [![npm version](https://img.shields.io/npm/v/@mcampa/claude-context-core.svg)](https://www.npmjs.com/package/@mcampa/claude-context-core)
8
+ [![npm downloads](https://img.shields.io/npm/dm/@mcampa/claude-context-core.svg)](https://www.npmjs.com/package/@mcampa/claude-context-core)
8
9
 
9
10
  > 📖 **New to Claude Context?** Check out the [main project README](../../README.md) for an overview and quick start guide.
10
11
 
11
12
  ## Installation
12
13
 
13
14
  ```bash
14
- npm install @zilliz/claude-context-core
15
+ 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,52 +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 '@zilliz/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({
75
+ name: "my-context",
70
76
  embedding,
71
- vectorDatabase
77
+ vectorDatabase,
72
78
  });
73
79
 
74
80
  // Index a codebase
75
- const stats = await context.indexCodebase('./my-project', (progress) => {
81
+ const stats = await context.indexCodebase("./my-project", (progress) => {
76
82
  console.log(`${progress.phase} - ${progress.percentage}%`);
77
83
  });
78
84
 
79
- console.log(`Indexed ${stats.indexedFiles} files with ${stats.totalChunks} chunks`);
85
+ console.log(
86
+ `Indexed ${stats.indexedFiles} files with ${stats.totalChunks} chunks`
87
+ );
80
88
 
81
89
  // Search the codebase
82
90
  const results = await context.semanticSearch(
83
- './my-project',
84
- 'function that handles user authentication',
91
+ "function that handles user authentication",
85
92
  5
86
93
  );
87
94
 
88
- results.forEach(result => {
95
+ results.forEach((result) => {
89
96
  console.log(`${result.relativePath}:${result.startLine}-${result.endLine}`);
90
97
  console.log(`Score: ${result.score}`);
91
98
  console.log(result.content);
@@ -124,12 +131,13 @@ results.forEach(result => {
124
131
 
125
132
  ```typescript
126
133
  interface ContextConfig {
127
- embedding?: Embedding; // Embedding provider
134
+ name?: string; // Context name (default: 'my-context')
135
+ embedding?: Embedding; // Embedding provider
128
136
  vectorDatabase?: VectorDatabase; // Vector database instance (required)
129
- codeSplitter?: Splitter; // Code splitting strategy
137
+ codeSplitter?: Splitter; // Code splitting strategy
130
138
  supportedExtensions?: string[]; // File extensions to index
131
- ignorePatterns?: string[]; // Patterns to ignore
132
- customExtensions?: string[]; // Custom extensions from MCP
139
+ ignorePatterns?: string[]; // Patterns to ignore
140
+ customExtensions?: string[]; // Custom extensions from MCP
133
141
  customIgnorePatterns?: string[]; // Custom ignore patterns from MCP
134
142
  }
135
143
  ```
@@ -139,11 +147,31 @@ interface ContextConfig {
139
147
  ```typescript
140
148
  [
141
149
  // Programming languages
142
- '.ts', '.tsx', '.js', '.jsx', '.py', '.java', '.cpp', '.c', '.h', '.hpp',
143
- '.cs', '.go', '.rs', '.php', '.rb', '.swift', '.kt', '.scala', '.m', '.mm',
144
- // Text and markup files
145
- '.md', '.markdown', '.ipynb'
146
- ]
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
+ ];
147
175
  ```
148
176
 
149
177
  ### Default Ignore Patterns
@@ -164,8 +192,8 @@ interface ContextConfig {
164
192
 
165
193
  - `indexCodebase(path, progressCallback?, forceReindex?)` - Index an entire codebase
166
194
  - `reindexByChange(path, progressCallback?)` - Incrementally re-index only changed files
167
- - `semanticSearch(path, query, topK?, threshold?, filterExpr?)` - Search indexed code semantically
168
- - `hasIndex(path)` - Check if codebase is already indexed
195
+ - `semanticSearch(query, topK?, threshold?, filterExpr?)` - Search indexed code semantically
196
+ - `hasIndex()` - Check if index exists
169
197
  - `clearIndex(path, progressCallback?)` - Remove index for a codebase
170
198
  - `updateIgnorePatterns(patterns)` - Update ignore patterns
171
199
  - `addCustomIgnorePatterns(patterns)` - Add custom ignore patterns
@@ -178,37 +206,41 @@ interface ContextConfig {
178
206
 
179
207
  ```typescript
180
208
  interface SemanticSearchResult {
181
- content: string; // Code content
209
+ content: string; // Code content
182
210
  relativePath: string; // File path relative to codebase root
183
- startLine: number; // Starting line number
184
- endLine: number; // Ending line number
185
- language: string; // Programming language
186
- 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)
187
215
  }
188
216
  ```
189
217
 
190
-
191
218
  ## Examples
192
219
 
193
220
  ### Using VoyageAI Embeddings
194
221
 
195
222
  ```typescript
196
- import { Context, MilvusVectorDatabase, VoyageAIEmbedding } from '@zilliz/claude-context-core';
223
+ import {
224
+ Context,
225
+ MilvusVectorDatabase,
226
+ VoyageAIEmbedding,
227
+ } from "@mcampa/claude-context-core";
197
228
 
198
229
  // Initialize with VoyageAI embedding provider
199
230
  const embedding = new VoyageAIEmbedding({
200
- apiKey: process.env.VOYAGEAI_API_KEY || 'your-voyageai-api-key',
201
- model: 'voyage-code-3'
231
+ apiKey: process.env.VOYAGEAI_API_KEY || "your-voyageai-api-key",
232
+ model: "voyage-code-3",
202
233
  });
203
234
 
204
235
  const vectorDatabase = new MilvusVectorDatabase({
205
- address: process.env.MILVUS_ADDRESS || 'localhost:19530',
206
- token: process.env.MILVUS_TOKEN || ''
236
+ address: process.env.MILVUS_ADDRESS || "localhost:19530",
237
+ token: process.env.MILVUS_TOKEN || "",
207
238
  });
208
239
 
209
240
  const context = new Context({
241
+ name: "my-context",
210
242
  embedding,
211
- vectorDatabase
243
+ vectorDatabase,
212
244
  });
213
245
  ```
214
246
 
@@ -216,18 +248,35 @@ const context = new Context({
216
248
 
217
249
  ```typescript
218
250
  const context = new Context({
251
+ name: "my-context",
219
252
  embedding,
220
253
  vectorDatabase,
221
- supportedExtensions: ['.ts', '.js', '.py', '.java'],
222
- ignorePatterns: [
223
- 'node_modules/**',
224
- 'dist/**',
225
- '*.spec.ts',
226
- '*.test.js'
227
- ]
254
+ supportedExtensions: [".ts", ".js", ".py", ".java"],
255
+ ignorePatterns: ["node_modules/**", "dist/**", "*.spec.ts", "*.test.js"],
228
256
  });
229
257
  ```
230
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
+
231
280
  ## File Synchronization Architecture
232
281
 
233
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.
@@ -239,21 +288,25 @@ Claude Context implements an intelligent file synchronization system that effici
239
288
  The file synchronization system uses a **Merkle tree-based approach** combined with SHA-256 file hashing to detect changes:
240
289
 
241
290
  #### 1. File Hashing
291
+
242
292
  - Each file in the codebase is hashed using SHA-256
243
293
  - File hashes are computed based on file content, not metadata
244
294
  - Hashes are stored with relative file paths for consistency across different environments
245
295
 
246
296
  #### 2. Merkle Tree Construction
297
+
247
298
  - All file hashes are organized into a Merkle tree structure
248
299
  - The tree provides a single root hash that represents the entire codebase state
249
300
  - Any change to any file will cause the root hash to change
250
301
 
251
302
  #### 3. Snapshot Management
303
+
252
304
  - File synchronization state is persisted to `~/.context/merkle/` directory
253
305
  - Each codebase gets a unique snapshot file based on its absolute path hash
254
306
  - Snapshots contain both file hashes and serialized Merkle tree data
255
307
 
256
308
  #### 4. Change Detection Process
309
+
257
310
  1. **Quick Check**: Compare current Merkle root hash with stored snapshot
258
311
  2. **Detailed Analysis**: If root hashes differ, perform file-by-file comparison
259
312
  3. **Change Classification**: Categorize changes into three types:
@@ -262,15 +315,16 @@ The file synchronization system uses a **Merkle tree-based approach** combined w
262
315
  - **Removed**: Files that were deleted from the codebase
263
316
 
264
317
  #### 5. Incremental Updates
318
+
265
319
  - Only process files that have actually changed
266
320
  - Update vector database entries only for modified chunks
267
321
  - Remove entries for deleted files
268
322
  - Add entries for new files
269
323
 
270
-
271
324
  ## Contributing
272
325
 
273
326
  This package is part of the Claude Context monorepo. Please see:
327
+
274
328
  - [Main Contributing Guide](../../CONTRIBUTING.md) - General contribution guidelines
275
329
  - [Core Package Contributing](CONTRIBUTING.md) - Specific development guide for this package
276
330
 
@@ -279,7 +333,6 @@ This package is part of the Claude Context monorepo. Please see:
279
333
  - **[@claude-context/mcp](../mcp)** - MCP server that uses this core engine
280
334
  - **[VSCode Extension](../vscode-extension)** - VSCode extension built on this core
281
335
 
282
-
283
336
  ## License
284
337
 
285
- MIT - See [LICENSE](../../LICENSE) for details
338
+ MIT - See [LICENSE](../../LICENSE) for details