@milo4jo/contextkit 0.1.0 → 0.3.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.
Files changed (56) hide show
  1. package/README.md +237 -72
  2. package/dist/commands/index-cmd.d.ts.map +1 -1
  3. package/dist/commands/index-cmd.js +10 -2
  4. package/dist/commands/index-cmd.js.map +1 -1
  5. package/dist/commands/mcp.d.ts +8 -0
  6. package/dist/commands/mcp.d.ts.map +1 -0
  7. package/dist/commands/mcp.js +23 -0
  8. package/dist/commands/mcp.js.map +1 -0
  9. package/dist/commands/watch.d.ts +8 -0
  10. package/dist/commands/watch.d.ts.map +1 -0
  11. package/dist/commands/watch.js +171 -0
  12. package/dist/commands/watch.js.map +1 -0
  13. package/dist/db/index.d.ts.map +1 -1
  14. package/dist/db/index.js +11 -2
  15. package/dist/db/index.js.map +1 -1
  16. package/dist/index.js +7 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/indexer/chunker.d.ts.map +1 -1
  19. package/dist/indexer/chunker.js +14 -15
  20. package/dist/indexer/chunker.js.map +1 -1
  21. package/dist/indexer/discovery.d.ts +7 -0
  22. package/dist/indexer/discovery.d.ts.map +1 -1
  23. package/dist/indexer/discovery.js +9 -0
  24. package/dist/indexer/discovery.js.map +1 -1
  25. package/dist/indexer/index.d.ts +17 -3
  26. package/dist/indexer/index.d.ts.map +1 -1
  27. package/dist/indexer/index.js +135 -24
  28. package/dist/indexer/index.js.map +1 -1
  29. package/dist/mcp/index.d.ts +7 -0
  30. package/dist/mcp/index.d.ts.map +1 -0
  31. package/dist/mcp/index.js +7 -0
  32. package/dist/mcp/index.js.map +1 -0
  33. package/dist/mcp/server.d.ts +20 -0
  34. package/dist/mcp/server.d.ts.map +1 -0
  35. package/dist/mcp/server.js +252 -0
  36. package/dist/mcp/server.js.map +1 -0
  37. package/dist/mcp-server.d.ts +18 -0
  38. package/dist/mcp-server.d.ts.map +1 -0
  39. package/dist/mcp-server.js +22 -0
  40. package/dist/mcp-server.js.map +1 -0
  41. package/dist/selector/budget.d.ts +2 -0
  42. package/dist/selector/budget.d.ts.map +1 -1
  43. package/dist/selector/budget.js +19 -6
  44. package/dist/selector/budget.js.map +1 -1
  45. package/dist/selector/formatter.d.ts.map +1 -1
  46. package/dist/selector/formatter.js +7 -5
  47. package/dist/selector/formatter.js.map +1 -1
  48. package/dist/selector/scoring.d.ts +15 -5
  49. package/dist/selector/scoring.d.ts.map +1 -1
  50. package/dist/selector/scoring.js +193 -19
  51. package/dist/selector/scoring.js.map +1 -1
  52. package/dist/utils/streams.d.ts +4 -0
  53. package/dist/utils/streams.d.ts.map +1 -1
  54. package/dist/utils/streams.js +7 -0
  55. package/dist/utils/streams.js.map +1 -1
  56. package/package.json +19 -7
@@ -2,18 +2,73 @@
2
2
  * Main Indexer Module
3
3
  *
4
4
  * Orchestrates file discovery, chunking, embedding, and storage.
5
+ * Supports incremental indexing via content hashing.
5
6
  */
7
+ import { createHash } from 'crypto';
6
8
  import { discoverFiles } from './discovery.js';
7
9
  import { chunkFiles } from './chunker.js';
8
10
  import { embedChunks } from './embeddings.js';
9
11
  /**
10
- * Index all sources
12
+ * Get all stored file hashes for a source
11
13
  */
12
- export async function indexSources(sources, baseDir, db, chunkOptions, onProgress) {
14
+ function getStoredFiles(db, sourceId) {
15
+ const rows = db.prepare('SELECT file_path, content_hash FROM files WHERE source_id = ?').all(sourceId);
16
+ const map = new Map();
17
+ for (const row of rows) {
18
+ map.set(row.file_path, row.content_hash);
19
+ }
20
+ return map;
21
+ }
22
+ /**
23
+ * Determine which files need to be indexed
24
+ */
25
+ function categorizeFiles(discovered, stored) {
26
+ const newFiles = [];
27
+ const changedFiles = [];
28
+ const unchangedFiles = [];
29
+ const currentPaths = new Set();
30
+ for (const file of discovered) {
31
+ currentPaths.add(file.relativePath);
32
+ const storedHash = stored.get(file.relativePath);
33
+ if (!storedHash) {
34
+ // New file
35
+ newFiles.push(file);
36
+ }
37
+ else if (storedHash !== file.contentHash) {
38
+ // Changed file
39
+ changedFiles.push(file);
40
+ }
41
+ else {
42
+ // Unchanged
43
+ unchangedFiles.push(file);
44
+ }
45
+ }
46
+ // Find removed files
47
+ const removedFiles = [];
48
+ for (const [path] of stored) {
49
+ if (!currentPaths.has(path)) {
50
+ removedFiles.push(path);
51
+ }
52
+ }
53
+ return {
54
+ new: newFiles,
55
+ changed: changedFiles,
56
+ unchanged: unchangedFiles,
57
+ removed: removedFiles,
58
+ };
59
+ }
60
+ /**
61
+ * Index all sources with incremental support
62
+ */
63
+ export async function indexSources(sources, baseDir, db, chunkOptions, onProgress, options) {
13
64
  const startTime = Date.now();
14
65
  let totalFiles = 0;
15
66
  let totalChunks = 0;
16
67
  let totalSkipped = 0;
68
+ let totalFilesChanged = 0;
69
+ let totalFilesUnchanged = 0;
70
+ let totalFilesRemoved = 0;
71
+ const forceReindex = options?.force ?? false;
17
72
  for (const source of sources) {
18
73
  // Phase 1: Discovery
19
74
  onProgress?.({
@@ -31,37 +86,48 @@ export async function indexSources(sources, baseDir, db, chunkOptions, onProgres
31
86
  current: discovered.files.length,
32
87
  total: discovered.files.length,
33
88
  });
34
- // Phase 2: Chunking
89
+ // Get stored file hashes for incremental indexing
90
+ const storedFiles = forceReindex ? new Map() : getStoredFiles(db, source.id);
91
+ const { new: newFiles, changed: changedFiles, unchanged: unchangedFiles, removed: removedFiles } = categorizeFiles(discovered.files, storedFiles);
92
+ // Files to process = new + changed
93
+ const filesToProcess = [...newFiles, ...changedFiles];
94
+ totalFilesChanged += filesToProcess.length;
95
+ totalFilesUnchanged += unchangedFiles.length;
96
+ totalFilesRemoved += removedFiles.length;
97
+ // Phase 2: Chunking (only for new/changed files)
35
98
  onProgress?.({
36
99
  phase: 'chunking',
37
100
  sourceId: source.id,
38
101
  current: 0,
39
- total: discovered.files.length,
102
+ total: filesToProcess.length,
40
103
  });
41
- const chunks = chunkFiles(discovered.files, chunkOptions);
104
+ const chunks = chunkFiles(filesToProcess, chunkOptions);
42
105
  onProgress?.({
43
106
  phase: 'chunking',
44
107
  sourceId: source.id,
45
- current: discovered.files.length,
46
- total: discovered.files.length,
108
+ current: filesToProcess.length,
109
+ total: filesToProcess.length,
47
110
  });
48
- // Phase 3: Embedding
49
- const embeddedChunks = await embedChunks(chunks, (current, total) => {
50
- onProgress?.({
51
- phase: 'embedding',
52
- sourceId: source.id,
53
- current,
54
- total,
111
+ // Phase 3: Embedding (only for new/changed files)
112
+ let embeddedChunks = [];
113
+ if (chunks.length > 0) {
114
+ embeddedChunks = await embedChunks(chunks, (current, total) => {
115
+ onProgress?.({
116
+ phase: 'embedding',
117
+ sourceId: source.id,
118
+ current,
119
+ total,
120
+ });
55
121
  });
56
- });
57
- // Phase 4: Store in database
122
+ }
123
+ // Phase 4: Store in database (incremental)
58
124
  onProgress?.({
59
125
  phase: 'storing',
60
126
  sourceId: source.id,
61
127
  current: 0,
62
128
  total: embeddedChunks.length,
63
129
  });
64
- storeChunks(db, source.id, source.path, embeddedChunks, discovered.files.length);
130
+ storeChunksIncremental(db, source.id, source.path, embeddedChunks, filesToProcess, removedFiles, discovered.files.length);
65
131
  totalChunks += embeddedChunks.length;
66
132
  onProgress?.({
67
133
  phase: 'storing',
@@ -75,18 +141,63 @@ export async function indexSources(sources, baseDir, db, chunkOptions, onProgres
75
141
  files: totalFiles,
76
142
  chunks: totalChunks,
77
143
  skipped: totalSkipped,
144
+ filesChanged: totalFilesChanged,
145
+ filesUnchanged: totalFilesUnchanged,
146
+ filesRemoved: totalFilesRemoved,
78
147
  timeMs: Date.now() - startTime,
79
148
  };
80
149
  }
81
150
  /**
82
- * Store chunks in the database
151
+ * Generate unique file ID
83
152
  */
84
- function storeChunks(db, sourceId, sourcePath, chunks, fileCount) {
153
+ function generateFileId(sourceId, filePath) {
154
+ const base = `${sourceId}:${filePath}`;
155
+ return createHash('sha256').update(base).digest('hex').slice(0, 16);
156
+ }
157
+ /**
158
+ * Store chunks incrementally (only for changed files)
159
+ */
160
+ function storeChunksIncremental(db, sourceId, sourcePath, chunks, processedFiles, removedFiles, totalFileCount) {
85
161
  // Begin transaction for performance
86
162
  const transaction = db.transaction(() => {
87
- // Clear existing chunks for this source
88
- db.prepare('DELETE FROM chunks WHERE source_id = ?').run(sourceId);
163
+ // FIRST: Ensure source exists (for foreign key constraints)
164
+ db.prepare(`
165
+ INSERT INTO sources (id, path, file_count, chunk_count, indexed_at)
166
+ VALUES (?, ?, 0, 0, datetime('now'))
167
+ ON CONFLICT(id) DO NOTHING
168
+ `).run(sourceId, sourcePath);
169
+ // Delete chunks for removed files
170
+ if (removedFiles.length > 0) {
171
+ const deleteChunks = db.prepare('DELETE FROM chunks WHERE source_id = ? AND file_path = ?');
172
+ const deleteFile = db.prepare('DELETE FROM files WHERE source_id = ? AND file_path = ?');
173
+ for (const filePath of removedFiles) {
174
+ deleteChunks.run(sourceId, filePath);
175
+ deleteFile.run(sourceId, filePath);
176
+ }
177
+ }
178
+ // Delete chunks for processed (changed) files - they'll be replaced
179
+ if (processedFiles.length > 0) {
180
+ const deleteChunks = db.prepare('DELETE FROM chunks WHERE source_id = ? AND file_path = ?');
181
+ for (const file of processedFiles) {
182
+ deleteChunks.run(sourceId, file.relativePath);
183
+ }
184
+ }
185
+ // Insert/update file records with new hashes
186
+ const upsertFile = db.prepare(`
187
+ INSERT INTO files (id, source_id, file_path, content_hash, indexed_at)
188
+ VALUES (?, ?, ?, ?, datetime('now'))
189
+ ON CONFLICT(source_id, file_path) DO UPDATE SET
190
+ content_hash = excluded.content_hash,
191
+ indexed_at = excluded.indexed_at
192
+ `);
193
+ for (const file of processedFiles) {
194
+ const fileId = generateFileId(sourceId, file.relativePath);
195
+ upsertFile.run(fileId, sourceId, file.relativePath, file.contentHash);
196
+ }
197
+ // Get current total chunk count for this source
198
+ const currentChunkCount = db.prepare('SELECT COUNT(*) as count FROM chunks WHERE source_id = ?').get(sourceId);
89
199
  // Update source record
200
+ const newChunkCount = currentChunkCount.count + chunks.length;
90
201
  db.prepare(`
91
202
  INSERT INTO sources (id, path, file_count, chunk_count, indexed_at)
92
203
  VALUES (?, ?, ?, ?, datetime('now'))
@@ -95,8 +206,8 @@ function storeChunks(db, sourceId, sourcePath, chunks, fileCount) {
95
206
  file_count = excluded.file_count,
96
207
  chunk_count = excluded.chunk_count,
97
208
  indexed_at = excluded.indexed_at
98
- `).run(sourceId, sourcePath, fileCount, chunks.length);
99
- // Insert chunks
209
+ `).run(sourceId, sourcePath, totalFileCount, newChunkCount);
210
+ // Insert new chunks
100
211
  const insertChunk = db.prepare(`
101
212
  INSERT INTO chunks (id, source_id, file_path, content, start_line, end_line, tokens, embedding)
102
213
  VALUES (?, ?, ?, ?, ?, ?, ?, ?)
@@ -117,7 +228,7 @@ export function readEmbedding(blob) {
117
228
  return Array.from(float32Array);
118
229
  }
119
230
  // Re-export types and functions
120
- export { discoverFiles } from './discovery.js';
231
+ export { discoverFiles, computeContentHash } from './discovery.js';
121
232
  export { chunkFiles, chunkFile, countTokens } from './chunker.js';
122
233
  export { embed, embedBatch, embedChunks, cosineSimilarity, EMBEDDING_DIM, } from './embeddings.js';
123
234
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/indexer/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAqB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAsB,MAAM,iBAAiB,CAAC;AAuBlE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAAiB,EACjB,OAAe,EACf,EAAqB,EACrB,YAA0B,EAC1B,UAAkC;IAElC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,YAAY,GAAG,CAAC,CAAC;IAEr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,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACrF,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAClC,CAAC;AAED,gCAAgC;AAChC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAA6C,MAAM,gBAAgB,CAAC;AAC9G,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAiC,MAAM,cAAc,CAAC;AACjG,OAAO,EACL,KAAK,EACL,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,aAAa,GAEd,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * MCP (Model Context Protocol) Server
3
+ *
4
+ * Exports the MCP server for use as a standalone server or embedded in other applications.
5
+ */
6
+ export { createMcpServer, startMcpServer } from "./server.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * MCP (Model Context Protocol) Server
3
+ *
4
+ * Exports the MCP server for use as a standalone server or embedded in other applications.
5
+ */
6
+ export { createMcpServer, startMcpServer } from "./server.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * ContextKit MCP Server
3
+ *
4
+ * Model Context Protocol server for ContextKit.
5
+ * Allows AI assistants (Claude Desktop, etc.) to use ContextKit for context selection.
6
+ *
7
+ * Usage:
8
+ * contextkit mcp # Start MCP server (stdio)
9
+ * contextkit-mcp # Standalone MCP server
10
+ */
11
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
12
+ /**
13
+ * Create and configure the MCP server
14
+ */
15
+ export declare function createMcpServer(): Server;
16
+ /**
17
+ * Start the MCP server with stdio transport
18
+ */
19
+ export declare function startMcpServer(): Promise<void>;
20
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAwCnE;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAuOxC;AAED;;GAEG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAIpD"}
@@ -0,0 +1,252 @@
1
+ /**
2
+ * ContextKit MCP Server
3
+ *
4
+ * Model Context Protocol server for ContextKit.
5
+ * Allows AI assistants (Claude Desktop, etc.) to use ContextKit for context selection.
6
+ *
7
+ * Usage:
8
+ * contextkit mcp # Start MCP server (stdio)
9
+ * contextkit-mcp # Standalone MCP server
10
+ */
11
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
12
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
13
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
14
+ import { readFileSync } from "fs";
15
+ import { fileURLToPath } from "url";
16
+ import { dirname, join } from "path";
17
+ import { isInitialized, loadConfig } from "../config/index.js";
18
+ import { openDatabase } from "../db/index.js";
19
+ import { selectContext } from "../selector/index.js";
20
+ import { indexSources } from "../indexer/index.js";
21
+ // Get version from package.json
22
+ const __dirname = dirname(fileURLToPath(import.meta.url));
23
+ const pkg = JSON.parse(readFileSync(join(__dirname, '..', '..', 'package.json'), 'utf-8'));
24
+ const VERSION = pkg.version;
25
+ /**
26
+ * Get index statistics from database
27
+ */
28
+ function getIndexStats(db) {
29
+ const chunkCount = db
30
+ .prepare("SELECT COUNT(*) as count FROM chunks")
31
+ .get();
32
+ const sourceCount = db
33
+ .prepare("SELECT COUNT(DISTINCT source_id) as count FROM chunks")
34
+ .get();
35
+ return {
36
+ totalChunks: chunkCount.count,
37
+ totalSources: sourceCount.count,
38
+ };
39
+ }
40
+ /**
41
+ * Create and configure the MCP server
42
+ */
43
+ export function createMcpServer() {
44
+ const server = new Server({
45
+ name: "contextkit",
46
+ version: VERSION,
47
+ }, {
48
+ capabilities: {
49
+ tools: {},
50
+ },
51
+ });
52
+ // List available tools
53
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
54
+ return {
55
+ tools: [
56
+ {
57
+ name: "contextkit_select",
58
+ description: "Select optimal context chunks for a query from indexed codebase. Returns the most relevant code and documentation for your task.",
59
+ inputSchema: {
60
+ type: "object",
61
+ properties: {
62
+ query: {
63
+ type: "string",
64
+ description: "What you need context for (e.g., 'How does authentication work?')",
65
+ },
66
+ budget: {
67
+ type: "number",
68
+ description: "Maximum tokens to return (default: 8000)",
69
+ },
70
+ sources: {
71
+ type: "string",
72
+ description: "Comma-separated list of sources to filter (optional)",
73
+ },
74
+ },
75
+ required: ["query"],
76
+ },
77
+ },
78
+ {
79
+ name: "contextkit_index",
80
+ description: "Index or re-index the codebase. Run this after making changes to ensure context is up to date.",
81
+ inputSchema: {
82
+ type: "object",
83
+ properties: {},
84
+ },
85
+ },
86
+ {
87
+ name: "contextkit_status",
88
+ description: "Get the current status of the ContextKit index, including chunk counts and source information.",
89
+ inputSchema: {
90
+ type: "object",
91
+ properties: {},
92
+ },
93
+ },
94
+ ],
95
+ };
96
+ });
97
+ // Handle tool calls
98
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
99
+ const { name, arguments: args } = request.params;
100
+ try {
101
+ switch (name) {
102
+ case "contextkit_select": {
103
+ if (!isInitialized()) {
104
+ return {
105
+ content: [
106
+ {
107
+ type: "text",
108
+ text: "ContextKit not initialized. Run `contextkit init` first.",
109
+ },
110
+ ],
111
+ isError: true,
112
+ };
113
+ }
114
+ const query = args?.query || "";
115
+ const budget = args?.budget || 8000;
116
+ const sourcesStr = args?.sources;
117
+ const sources = sourcesStr
118
+ ? sourcesStr.split(",").map((s) => s.trim())
119
+ : undefined;
120
+ if (!query) {
121
+ return {
122
+ content: [{ type: "text", text: "Error: query is required" }],
123
+ isError: true,
124
+ };
125
+ }
126
+ const db = openDatabase();
127
+ try {
128
+ const options = {
129
+ query,
130
+ budget,
131
+ sources,
132
+ };
133
+ const result = await selectContext(db, options);
134
+ if (result.isEmpty) {
135
+ return {
136
+ content: [
137
+ {
138
+ type: "text",
139
+ text: "No indexed content. Run `contextkit index` first.",
140
+ },
141
+ ],
142
+ };
143
+ }
144
+ if (result.output.data.chunks.length === 0) {
145
+ return {
146
+ content: [
147
+ {
148
+ type: "text",
149
+ text: `No relevant context found for query: "${query}"`,
150
+ },
151
+ ],
152
+ };
153
+ }
154
+ // Return formatted output
155
+ return {
156
+ content: [{ type: "text", text: result.output.text }],
157
+ };
158
+ }
159
+ finally {
160
+ db.close();
161
+ }
162
+ }
163
+ case "contextkit_index": {
164
+ if (!isInitialized()) {
165
+ return {
166
+ content: [
167
+ {
168
+ type: "text",
169
+ text: "ContextKit not initialized. Run `contextkit init` first.",
170
+ },
171
+ ],
172
+ isError: true,
173
+ };
174
+ }
175
+ const config = loadConfig();
176
+ const db = openDatabase();
177
+ try {
178
+ const stats = await indexSources(config.sources, process.cwd(), db, {
179
+ chunkSize: config.settings.chunk_size,
180
+ chunkOverlap: config.settings.chunk_overlap,
181
+ });
182
+ return {
183
+ content: [
184
+ {
185
+ type: "text",
186
+ text: `Indexed ${stats.chunks} chunks from ${stats.files} files.`,
187
+ },
188
+ ],
189
+ };
190
+ }
191
+ finally {
192
+ db.close();
193
+ }
194
+ }
195
+ case "contextkit_status": {
196
+ if (!isInitialized()) {
197
+ return {
198
+ content: [
199
+ {
200
+ type: "text",
201
+ text: "ContextKit not initialized in current directory.",
202
+ },
203
+ ],
204
+ };
205
+ }
206
+ const config = loadConfig();
207
+ const db = openDatabase();
208
+ try {
209
+ const stats = getIndexStats(db);
210
+ const statusText = [
211
+ "ContextKit Status",
212
+ "=================",
213
+ `Sources configured: ${config.sources.length}`,
214
+ `Chunks indexed: ${stats.totalChunks}`,
215
+ "",
216
+ "Sources:",
217
+ ...config.sources.map((s) => ` - ${s.id}: ${s.path}`),
218
+ ].join("\n");
219
+ return {
220
+ content: [{ type: "text", text: statusText }],
221
+ };
222
+ }
223
+ finally {
224
+ db.close();
225
+ }
226
+ }
227
+ default:
228
+ return {
229
+ content: [{ type: "text", text: `Unknown tool: ${name}` }],
230
+ isError: true,
231
+ };
232
+ }
233
+ }
234
+ catch (error) {
235
+ const message = error instanceof Error ? error.message : String(error);
236
+ return {
237
+ content: [{ type: "text", text: `Error: ${message}` }],
238
+ isError: true,
239
+ };
240
+ }
241
+ });
242
+ return server;
243
+ }
244
+ /**
245
+ * Start the MCP server with stdio transport
246
+ */
247
+ export async function startMcpServer() {
248
+ const server = createMcpServer();
249
+ const transport = new StdioServerTransport();
250
+ await server.connect(transport);
251
+ }
252
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;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AAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * ContextKit MCP Server (Standalone)
4
+ *
5
+ * Start the MCP server directly without the CLI wrapper.
6
+ * This is useful for Claude Desktop configuration.
7
+ *
8
+ * Usage in claude_desktop_config.json:
9
+ * {
10
+ * "mcpServers": {
11
+ * "contextkit": {
12
+ * "command": "contextkit-mcp"
13
+ * }
14
+ * }
15
+ * }
16
+ */
17
+ export {};
18
+ //# sourceMappingURL=mcp-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;GAcG"}
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * ContextKit MCP Server (Standalone)
4
+ *
5
+ * Start the MCP server directly without the CLI wrapper.
6
+ * This is useful for Claude Desktop configuration.
7
+ *
8
+ * Usage in claude_desktop_config.json:
9
+ * {
10
+ * "mcpServers": {
11
+ * "contextkit": {
12
+ * "command": "contextkit-mcp"
13
+ * }
14
+ * }
15
+ * }
16
+ */
17
+ import { startMcpServer } from "./mcp/server.js";
18
+ startMcpServer().catch((error) => {
19
+ console.error("Failed to start MCP server:", error);
20
+ process.exit(1);
21
+ });
22
+ //# sourceMappingURL=mcp-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,cAAc,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAC/B,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;IACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -21,6 +21,8 @@ export declare function fitToBudget(chunks: RankedChunk[], budget: number): Budg
21
21
  /**
22
22
  * Merge adjacent chunks from the same file
23
23
  * (Optional optimization for cleaner output)
24
+ *
25
+ * Handles overlapping chunks by removing duplicate lines.
24
26
  */
25
27
  export declare function mergeAdjacentChunks(chunks: RankedChunk[]): RankedChunk[];
26
28
  //# sourceMappingURL=budget.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"budget.d.ts","sourceRoot":"","sources":["../../src/selector/budget.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,uBAAuB;AACvB,MAAM,WAAW,YAAY;IAC3B,sBAAsB;IACtB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,wBAAwB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,CAsC/E;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,CA8BxE"}
1
+ {"version":3,"file":"budget.d.ts","sourceRoot":"","sources":["../../src/selector/budget.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,uBAAuB;AACvB,MAAM,WAAW,YAAY;IAC3B,sBAAsB;IACtB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,wBAAwB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,CAsC/E;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,CA8CxE"}