@milo4jo/contextkit 0.1.2 → 0.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/README.md +269 -72
- package/dist/commands/index-cmd.d.ts.map +1 -1
- package/dist/commands/index-cmd.js +10 -2
- package/dist/commands/index-cmd.js.map +1 -1
- package/dist/commands/mcp.d.ts +8 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +23 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/select.d.ts.map +1 -1
- package/dist/commands/select.js +15 -9
- package/dist/commands/select.js.map +1 -1
- package/dist/commands/watch.d.ts +8 -0
- package/dist/commands/watch.d.ts.map +1 -0
- package/dist/commands/watch.js +171 -0
- package/dist/commands/watch.js.map +1 -0
- package/dist/config/index.d.ts +11 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +11 -0
- package/dist/config/index.js.map +1 -1
- package/dist/config/validation.d.ts +33 -0
- package/dist/config/validation.d.ts.map +1 -0
- package/dist/config/validation.js +241 -0
- package/dist/config/validation.js.map +1 -0
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +11 -2
- package/dist/db/index.js.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/indexer/discovery.d.ts +7 -0
- package/dist/indexer/discovery.d.ts.map +1 -1
- package/dist/indexer/discovery.js +9 -0
- package/dist/indexer/discovery.js.map +1 -1
- package/dist/indexer/index.d.ts +17 -3
- package/dist/indexer/index.d.ts.map +1 -1
- package/dist/indexer/index.js +135 -24
- package/dist/indexer/index.js.map +1 -1
- package/dist/mcp/index.d.ts +7 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +7 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/server.d.ts +20 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +252 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp-server.d.ts +18 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +22 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/retrieval/imports.d.ts +76 -0
- package/dist/retrieval/imports.d.ts.map +1 -0
- package/dist/retrieval/imports.js +258 -0
- package/dist/retrieval/imports.js.map +1 -0
- package/dist/selector/budget.d.ts +2 -0
- package/dist/selector/budget.d.ts.map +1 -1
- package/dist/selector/budget.js +19 -6
- package/dist/selector/budget.js.map +1 -1
- package/dist/selector/formatter.d.ts +15 -0
- package/dist/selector/formatter.d.ts.map +1 -1
- package/dist/selector/formatter.js +139 -5
- package/dist/selector/formatter.js.map +1 -1
- package/dist/selector/index.d.ts +11 -4
- package/dist/selector/index.d.ts.map +1 -1
- package/dist/selector/index.js +67 -12
- package/dist/selector/index.js.map +1 -1
- package/dist/selector/scoring.d.ts +35 -5
- package/dist/selector/scoring.d.ts.map +1 -1
- package/dist/selector/scoring.js +290 -23
- package/dist/selector/scoring.js.map +1 -1
- package/dist/utils/streams.d.ts +4 -0
- package/dist/utils/streams.d.ts.map +1 -1
- package/dist/utils/streams.js +7 -0
- package/dist/utils/streams.js.map +1 -1
- package/package.json +18 -6
- package/dist/commands/source.d.ts +0 -3
- package/dist/commands/source.d.ts.map +0 -1
- package/dist/commands/source.js +0 -153
- package/dist/commands/source.js.map +0 -1
- package/dist/utils/output.d.ts +0 -42
- package/dist/utils/output.d.ts.map +0 -1
- package/dist/utils/output.js +0 -62
- package/dist/utils/output.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,17 +1,44 @@
|
|
|
1
1
|
# ContextKit 🎯
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> **Stop dumping your entire codebase into AI prompts.**
|
|
4
|
+
> ContextKit selects the *right* context for any query — saving tokens and improving answers.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
[](https://www.npmjs.com/package/@milo4jo/contextkit)
|
|
7
|
+
[](https://www.npmjs.com/package/@milo4jo/contextkit)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
**🆕 v0.5:** Import-aware scoring — files that import your selected code get boosted automatically!
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## The Problem
|
|
15
|
+
|
|
16
|
+
AI coding assistants are only as good as the context you give them. But:
|
|
17
|
+
|
|
18
|
+
- **Too much context** = expensive, slow, diluted focus
|
|
19
|
+
- **Too little context** = hallucinations, wrong answers
|
|
20
|
+
- **Manual selection** = tedious, doesn't scale
|
|
21
|
+
|
|
22
|
+
**ContextKit fixes this.** It indexes your code and intelligently selects the most relevant chunks for any query.
|
|
23
|
+
|
|
24
|
+
## How It Works
|
|
10
25
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
26
|
+
```
|
|
27
|
+
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
|
|
28
|
+
│ Your Code │ ──▶ │ Index │ ──▶ │ Select │
|
|
29
|
+
│ (files) │ │ (local db) │ │ (semantic) │
|
|
30
|
+
└──────────────┘ └──────────────┘ └──────────────┘
|
|
31
|
+
│
|
|
32
|
+
▼
|
|
33
|
+
┌──────────────┐
|
|
34
|
+
│ Optimized │
|
|
35
|
+
│ Context │
|
|
36
|
+
└──────────────┘
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
1. **Index** your codebase (embeddings stored locally)
|
|
40
|
+
2. **Query** in natural language
|
|
41
|
+
3. **Get** the most relevant code chunks, ready to paste
|
|
15
42
|
|
|
16
43
|
## Install
|
|
17
44
|
|
|
@@ -26,22 +53,76 @@ npm install -g @milo4jo/contextkit
|
|
|
26
53
|
cd your-project
|
|
27
54
|
contextkit init
|
|
28
55
|
|
|
29
|
-
# Add
|
|
56
|
+
# Add directories to index
|
|
30
57
|
contextkit source add ./src
|
|
31
58
|
contextkit source add ./lib
|
|
32
59
|
|
|
33
|
-
#
|
|
60
|
+
# Build the index
|
|
34
61
|
contextkit index
|
|
35
62
|
|
|
36
|
-
# Find relevant context
|
|
63
|
+
# Find relevant context for any query
|
|
37
64
|
contextkit select "How does authentication work?"
|
|
38
65
|
```
|
|
39
66
|
|
|
67
|
+
**Output:**
|
|
68
|
+
|
|
69
|
+
```markdown
|
|
70
|
+
## src/auth/middleware.ts (lines 1-45)
|
|
71
|
+
```typescript
|
|
72
|
+
export const authMiddleware = async (req, res, next) => {
|
|
73
|
+
const token = req.headers.authorization?.split(' ')[1];
|
|
74
|
+
if (!token) return res.status(401).json({ error: 'No token' });
|
|
75
|
+
// ...
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## src/auth/utils.ts (lines 12-30)
|
|
80
|
+
```typescript
|
|
81
|
+
export function validateToken(token: string): User | null {
|
|
82
|
+
// ...
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
📊 2,847 tokens | 6 chunks | 2 files
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Why ContextKit?
|
|
91
|
+
|
|
92
|
+
**Real example:** A 50k line codebase needs ~200k tokens to include everything. ContextKit gives you the **relevant 3-8k tokens** for any query. That's **96% token savings** and better answers.
|
|
93
|
+
|
|
94
|
+
| Approach | Problem |
|
|
95
|
+
|----------|---------|
|
|
96
|
+
| **Dump everything** | 💸 Expensive, hits token limits, dilutes focus |
|
|
97
|
+
| **Basic RAG** | Returns "similar" chunks, misses dependencies |
|
|
98
|
+
| **Manual selection** | Tedious, inconsistent, doesn't scale |
|
|
99
|
+
| **ContextKit** | ✅ Smart selection, import-aware, local-first |
|
|
100
|
+
|
|
101
|
+
### Why Not LSP-Based Tools?
|
|
102
|
+
|
|
103
|
+
Tools like [Serena](https://github.com/oramasearch/serena) use Language Server Protocol for deep code understanding. Great for complex refactoring, but:
|
|
104
|
+
|
|
105
|
+
- **Heavy setup** — requires language servers per language
|
|
106
|
+
- **Slow startup** — LSP initialization takes seconds
|
|
107
|
+
- **Complex** — more moving parts to configure
|
|
108
|
+
|
|
109
|
+
**ContextKit takes a different approach:** Semantic search + import graph analysis. Works instantly on any codebase, any language. No language servers needed.
|
|
110
|
+
|
|
111
|
+
### vs. LangChain / LlamaIndex
|
|
112
|
+
|
|
113
|
+
Those are full frameworks. ContextKit does **one thing well**: context selection. No lock-in, no complexity.
|
|
114
|
+
|
|
115
|
+
### vs. Vector Databases (Pinecone, Chroma)
|
|
116
|
+
|
|
117
|
+
They're storage. ContextKit adds the **intelligence layer** — scoring, budgeting, code-aware formatting.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
40
121
|
## Commands
|
|
41
122
|
|
|
42
123
|
### `contextkit init`
|
|
43
124
|
|
|
44
|
-
Initialize ContextKit in your project. Creates `.contextkit/` directory
|
|
125
|
+
Initialize ContextKit in your project. Creates `.contextkit/` directory.
|
|
45
126
|
|
|
46
127
|
```bash
|
|
47
128
|
contextkit init
|
|
@@ -49,31 +130,35 @@ contextkit init
|
|
|
49
130
|
|
|
50
131
|
### `contextkit source`
|
|
51
132
|
|
|
52
|
-
Manage
|
|
133
|
+
Manage which directories to index.
|
|
53
134
|
|
|
54
135
|
```bash
|
|
55
|
-
# Add a source
|
|
56
|
-
contextkit source
|
|
57
|
-
|
|
58
|
-
# List sources
|
|
59
|
-
contextkit source list
|
|
60
|
-
|
|
61
|
-
# Remove a source
|
|
62
|
-
contextkit source remove src
|
|
136
|
+
contextkit source add ./src # Add a source
|
|
137
|
+
contextkit source list # List all sources
|
|
138
|
+
contextkit source remove src # Remove a source
|
|
63
139
|
```
|
|
64
140
|
|
|
65
141
|
### `contextkit index`
|
|
66
142
|
|
|
67
|
-
|
|
143
|
+
Build or rebuild the index. Uses incremental indexing by default (only re-indexes changed files).
|
|
68
144
|
|
|
69
145
|
```bash
|
|
70
|
-
#
|
|
71
|
-
contextkit index
|
|
146
|
+
contextkit index # Incremental index (fast)
|
|
147
|
+
contextkit index --force # Full re-index
|
|
148
|
+
contextkit index --source src # Index specific source
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### `contextkit watch`
|
|
152
|
+
|
|
153
|
+
Watch sources and auto-reindex on changes.
|
|
72
154
|
|
|
73
|
-
|
|
74
|
-
contextkit
|
|
155
|
+
```bash
|
|
156
|
+
contextkit watch # Watch with 1s debounce
|
|
157
|
+
contextkit watch --debounce 2000 # Custom debounce (ms)
|
|
75
158
|
```
|
|
76
159
|
|
|
160
|
+
Press `Ctrl+C` to stop watching.
|
|
161
|
+
|
|
77
162
|
### `contextkit select`
|
|
78
163
|
|
|
79
164
|
Find relevant context for a query.
|
|
@@ -82,7 +167,7 @@ Find relevant context for a query.
|
|
|
82
167
|
# Basic usage
|
|
83
168
|
contextkit select "How does the auth middleware work?"
|
|
84
169
|
|
|
85
|
-
#
|
|
170
|
+
# Set token budget (default: 8000)
|
|
86
171
|
contextkit select "error handling" --budget 4000
|
|
87
172
|
|
|
88
173
|
# Filter to specific sources
|
|
@@ -91,38 +176,86 @@ contextkit select "database queries" --sources src,lib
|
|
|
91
176
|
# Show scoring details
|
|
92
177
|
contextkit select "user validation" --explain
|
|
93
178
|
|
|
94
|
-
#
|
|
95
|
-
contextkit select "
|
|
96
|
-
|
|
179
|
+
# Output formats
|
|
180
|
+
contextkit select "query" --format markdown # Default, with code blocks
|
|
181
|
+
contextkit select "query" --format xml # XML structure (Claude prefers this)
|
|
182
|
+
contextkit select "query" --format json # JSON for scripts/integrations
|
|
183
|
+
contextkit select "query" --format plain # Plain text, no formatting
|
|
97
184
|
|
|
98
|
-
|
|
185
|
+
# Include imported files (follows dependency graph)
|
|
186
|
+
contextkit select "query" --include-imports
|
|
99
187
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
```typescript
|
|
103
|
-
export const authMiddleware = async (req, res, next) => {
|
|
104
|
-
// ... relevant code
|
|
105
|
-
}
|
|
188
|
+
# Pipe to clipboard (macOS)
|
|
189
|
+
contextkit select "query" --format plain | pbcopy
|
|
106
190
|
```
|
|
107
191
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## 🤖 MCP Server (Claude Desktop Integration)
|
|
195
|
+
|
|
196
|
+
ContextKit includes an **MCP server** for seamless integration with Claude Desktop and other MCP-compatible AI assistants.
|
|
197
|
+
|
|
198
|
+
### What is MCP?
|
|
199
|
+
|
|
200
|
+
[Model Context Protocol](https://modelcontextprotocol.io/) is a standard for connecting AI assistants to external tools. With MCP, Claude can directly use ContextKit to find relevant code.
|
|
201
|
+
|
|
202
|
+
### Setup for Claude Desktop
|
|
203
|
+
|
|
204
|
+
**1. Find your config file:**
|
|
205
|
+
|
|
206
|
+
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
207
|
+
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
208
|
+
|
|
209
|
+
**2. Add ContextKit:**
|
|
210
|
+
|
|
211
|
+
```json
|
|
212
|
+
{
|
|
213
|
+
"mcpServers": {
|
|
214
|
+
"contextkit": {
|
|
215
|
+
"command": "contextkit-mcp",
|
|
216
|
+
"args": [],
|
|
217
|
+
"env": {
|
|
218
|
+
"CONTEXTKIT_PROJECT": "/path/to/your/project"
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
112
222
|
}
|
|
113
223
|
```
|
|
114
224
|
|
|
115
|
-
|
|
116
|
-
📊 3,847 tokens | 8 chunks | 2 files
|
|
117
|
-
```
|
|
225
|
+
**3. Restart Claude Desktop**
|
|
118
226
|
|
|
119
|
-
|
|
227
|
+
### Available Tools
|
|
228
|
+
|
|
229
|
+
Once configured, Claude can use these tools:
|
|
120
230
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
231
|
+
| Tool | Description |
|
|
232
|
+
|------|-------------|
|
|
233
|
+
| `contextkit_select` | Find relevant context for any query |
|
|
234
|
+
| `contextkit_index` | Re-index the codebase |
|
|
235
|
+
| `contextkit_status` | Check index status (files, chunks, etc.) |
|
|
236
|
+
|
|
237
|
+
### Example Conversation
|
|
238
|
+
|
|
239
|
+
> **You:** Find all code related to user authentication
|
|
240
|
+
>
|
|
241
|
+
> **Claude:** *[Uses contextkit_select]* I found the relevant code. Here's what handles authentication:
|
|
242
|
+
> - `src/auth/middleware.ts` - The main auth middleware
|
|
243
|
+
> - `src/auth/jwt.ts` - Token validation
|
|
244
|
+
> - ...
|
|
245
|
+
|
|
246
|
+
### Manual Server Start
|
|
247
|
+
|
|
248
|
+
For debugging or other MCP clients:
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
# Start the MCP server
|
|
252
|
+
contextkit mcp
|
|
253
|
+
|
|
254
|
+
# With a specific project
|
|
255
|
+
CONTEXTKIT_PROJECT=/path/to/project contextkit mcp
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
---
|
|
126
259
|
|
|
127
260
|
## Configuration
|
|
128
261
|
|
|
@@ -138,44 +271,108 @@ sources:
|
|
|
138
271
|
include:
|
|
139
272
|
- "**/*.ts"
|
|
140
273
|
- "**/*.js"
|
|
274
|
+
- "**/*.tsx"
|
|
141
275
|
exclude:
|
|
142
276
|
- "**/node_modules/**"
|
|
143
277
|
- "**/*.test.ts"
|
|
278
|
+
- "**/*.spec.ts"
|
|
144
279
|
|
|
145
280
|
settings:
|
|
146
|
-
chunk_size: 500
|
|
147
|
-
chunk_overlap: 50
|
|
281
|
+
chunk_size: 500 # Target tokens per chunk
|
|
282
|
+
chunk_overlap: 50 # Overlap between chunks
|
|
283
|
+
embedding_model: gte-small
|
|
148
284
|
```
|
|
149
285
|
|
|
150
|
-
|
|
286
|
+
---
|
|
151
287
|
|
|
152
|
-
|
|
288
|
+
## Privacy & Security
|
|
289
|
+
|
|
290
|
+
- ✅ **All processing is local** — nothing leaves your machine
|
|
291
|
+
- ✅ **Embeddings stored locally** in `.contextkit/index.db`
|
|
292
|
+
- ✅ **No API keys required** — uses local embedding model
|
|
293
|
+
- ✅ **`.contextkit` is gitignored** automatically
|
|
294
|
+
|
|
295
|
+
---
|
|
153
296
|
|
|
154
|
-
|
|
155
|
-
|--------|-------------|
|
|
156
|
-
| `--json` | Output as JSON |
|
|
157
|
-
| `--plain` | No colors (or set `NO_COLOR=1`) |
|
|
158
|
-
| `--quiet` | Suppress non-essential output |
|
|
297
|
+
## Technical Details
|
|
159
298
|
|
|
160
|
-
|
|
299
|
+
### How Selection Works
|
|
161
300
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
301
|
+
1. **Chunking** — Files split into ~500 token chunks with overlap
|
|
302
|
+
2. **Embedding** — Each chunk embedded with [gte-small](https://huggingface.co/thenlper/gte-small) (runs locally)
|
|
303
|
+
3. **Similarity** — Query embedded and compared via cosine similarity
|
|
304
|
+
4. **Import Analysis** — Parses ES6/CommonJS/dynamic imports to build dependency graph
|
|
305
|
+
5. **Multi-Factor Scoring** — Chunks ranked by:
|
|
306
|
+
- Semantic similarity (40%)
|
|
307
|
+
- Query term matches (25%)
|
|
308
|
+
- Path relevance (20%)
|
|
309
|
+
- Recency (10%)
|
|
310
|
+
- **Import boost** (5%) — files imported by selected code get boosted
|
|
311
|
+
6. **Budgeting** — Top chunks selected until token budget filled
|
|
166
312
|
|
|
167
|
-
|
|
313
|
+
### Requirements
|
|
168
314
|
|
|
169
315
|
- Node.js 18+
|
|
170
|
-
- ~500MB disk space
|
|
316
|
+
- ~500MB disk space (embedding model downloaded on first run)
|
|
171
317
|
|
|
172
|
-
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
## Try the Demo
|
|
321
|
+
|
|
322
|
+
Want to see ContextKit in action? Check out the [demo project](./examples/demo-project/):
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
cd examples/demo-project
|
|
326
|
+
contextkit init
|
|
327
|
+
contextkit source add ./src
|
|
328
|
+
contextkit index
|
|
329
|
+
contextkit select "How does authentication work?"
|
|
330
|
+
```
|
|
173
331
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
## Roadmap
|
|
335
|
+
|
|
336
|
+
- [x] CLI with init, source, index, select
|
|
337
|
+
- [x] MCP server for Claude Desktop
|
|
338
|
+
- [x] Incremental indexing (only changed files)
|
|
339
|
+
- [x] Watch mode (auto-reindex on save)
|
|
340
|
+
- [x] Multi-factor scoring algorithm
|
|
341
|
+
- [x] Multiple output formats (markdown, XML, JSON, plain)
|
|
342
|
+
- [x] **Import-aware scoring** — understands code dependencies
|
|
343
|
+
- [ ] Function/class boundary awareness
|
|
344
|
+
- [ ] VS Code extension
|
|
345
|
+
- [ ] Cursor integration
|
|
346
|
+
- [ ] Neovim plugin
|
|
347
|
+
|
|
348
|
+
---
|
|
349
|
+
|
|
350
|
+
## Contributing
|
|
351
|
+
|
|
352
|
+
Contributions welcome! Please read the [contributing guide](./CONTRIBUTING.md) first.
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
# Clone and setup
|
|
356
|
+
git clone https://github.com/milo4jo/contextkit.git
|
|
357
|
+
cd contextkit
|
|
358
|
+
npm install
|
|
359
|
+
npm run build
|
|
360
|
+
|
|
361
|
+
# Run tests
|
|
362
|
+
npm test
|
|
363
|
+
|
|
364
|
+
# Link for local development
|
|
365
|
+
npm link
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
---
|
|
178
369
|
|
|
179
370
|
## License
|
|
180
371
|
|
|
181
|
-
MIT
|
|
372
|
+
MIT © [Milo](https://github.com/milo4jo)
|
|
373
|
+
|
|
374
|
+
---
|
|
375
|
+
|
|
376
|
+
<p align="center">
|
|
377
|
+
Built with 🦊 by Milo
|
|
378
|
+
</p>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-cmd.d.ts","sourceRoot":"","sources":["../../src/commands/index-cmd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUpC,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"index-cmd.d.ts","sourceRoot":"","sources":["../../src/commands/index-cmd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUpC,eAAO,MAAM,YAAY,SA0IrB,CAAC"}
|
|
@@ -10,6 +10,7 @@ import { SourceNotFoundError } from '../errors/index.js';
|
|
|
10
10
|
export const indexCommand = new Command('index')
|
|
11
11
|
.description('Index all sources')
|
|
12
12
|
.option('-s, --source <name>', 'Index only a specific source')
|
|
13
|
+
.option('-f, --force', 'Force full re-index (ignore cached hashes)')
|
|
13
14
|
.action(async (options) => {
|
|
14
15
|
ensureInitialized();
|
|
15
16
|
const config = loadConfig();
|
|
@@ -81,7 +82,7 @@ export const indexCommand = new Command('index')
|
|
|
81
82
|
const stats = await indexSources(sourcesToIndex, process.cwd(), db, {
|
|
82
83
|
chunkSize: config.settings.chunk_size,
|
|
83
84
|
chunkOverlap: config.settings.chunk_overlap,
|
|
84
|
-
}, onProgress);
|
|
85
|
+
}, onProgress, { force: options.force });
|
|
85
86
|
// Stop progress bar
|
|
86
87
|
if (progressBar) {
|
|
87
88
|
progressBar.stop();
|
|
@@ -90,7 +91,14 @@ export const indexCommand = new Command('index')
|
|
|
90
91
|
if (!opts.quiet) {
|
|
91
92
|
writeMessage('');
|
|
92
93
|
const timeStr = (stats.timeMs / 1000).toFixed(1);
|
|
93
|
-
|
|
94
|
+
// Show incremental stats
|
|
95
|
+
if (stats.filesUnchanged > 0 || stats.filesRemoved > 0) {
|
|
96
|
+
writeSuccess(`Indexed ${stats.chunks} chunks from ${stats.files} files in ${timeStr}s`);
|
|
97
|
+
writeMessage(formatDim(` ${stats.filesChanged} changed, ${stats.filesUnchanged} unchanged, ${stats.filesRemoved} removed`));
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
writeSuccess(`Indexed ${stats.chunks} chunks from ${stats.files} files in ${timeStr}s`);
|
|
101
|
+
}
|
|
94
102
|
if (stats.skipped > 0) {
|
|
95
103
|
writeMessage(formatDim(` (${stats.skipped} files skipped - too large or binary)`));
|
|
96
104
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-cmd.js","sourceRoot":"","sources":["../../src/commands/index-cmd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAsB,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC;KAC7C,WAAW,CAAC,mBAAmB,CAAC;KAChC,MAAM,CAAC,qBAAqB,EAAE,8BAA8B,CAAC;KAC7D,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACxB,iBAAiB,EAAE,CAAC;IAEpB,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,MAAM,IAAI,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;IAEzC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,YAAY,CAAC,uBAAuB,CAAC,CAAC;QACtC,YAAY,CAAC,0BAA0B,aAAa,CAAC,8BAA8B,CAAC,EAAE,CAAC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H,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,UAAU,SAYnB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Command
|
|
3
|
+
*
|
|
4
|
+
* Start the Model Context Protocol server for AI assistant integration.
|
|
5
|
+
*/
|
|
6
|
+
import { Command } from "commander";
|
|
7
|
+
import { startMcpServer } from "../mcp/server.js";
|
|
8
|
+
import { writeMessage, writeError } from "../utils/streams.js";
|
|
9
|
+
export const mcpCommand = new Command("mcp")
|
|
10
|
+
.description("Start MCP server for AI assistant integration")
|
|
11
|
+
.option("--stdio", "Use stdio transport (default)")
|
|
12
|
+
.action(async () => {
|
|
13
|
+
try {
|
|
14
|
+
writeMessage("Starting ContextKit MCP server...");
|
|
15
|
+
await startMcpServer();
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
19
|
+
writeError(`Failed to start MCP server: ${message}`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAE/D,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC;KACzC,WAAW,CAAC,+CAA+C,CAAC;KAC5D,MAAM,CAAC,SAAS,EAAE,+BAA+B,CAAC;KAClD,MAAM,CAAC,KAAK,IAAI,EAAE;IACjB,IAAI,CAAC;QACH,YAAY,CAAC,mCAAmC,CAAC,CAAC;QAClD,MAAM,cAAc,EAAE,CAAC;IACzB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,UAAU,CAAC,+BAA+B,OAAO,EAAE,CAAC,CAAC;QACrD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/commands/select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/commands/select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAYpC,eAAO,MAAM,aAAa,SAqEtB,CAAC"}
|
package/dist/commands/select.js
CHANGED
|
@@ -6,13 +6,16 @@ import { writeData, writeMessage, writeWarning } from '../utils/streams.js';
|
|
|
6
6
|
import { formatCommand, formatDim } from '../utils/format.js';
|
|
7
7
|
import { getGlobalOpts } from '../utils/cli.js';
|
|
8
8
|
import { InvalidUsageError } from '../errors/index.js';
|
|
9
|
+
/** Valid output formats */
|
|
10
|
+
const VALID_FORMATS = ['markdown', 'xml', 'json', 'plain'];
|
|
9
11
|
export const selectCommand = new Command('select')
|
|
10
12
|
.description('Select context for a query')
|
|
11
13
|
.argument('<query>', 'The query to find context for')
|
|
12
14
|
.option('-b, --budget <tokens>', 'Maximum tokens to include', '8000')
|
|
13
|
-
.option('-f, --format <format>', 'Output format:
|
|
15
|
+
.option('-f, --format <format>', 'Output format: markdown, xml, json, plain', 'markdown')
|
|
14
16
|
.option('-s, --sources <sources>', 'Filter sources (comma-separated)')
|
|
15
17
|
.option('--explain', 'Show scoring details')
|
|
18
|
+
.option('--include-imports', 'Include files imported by selected chunks')
|
|
16
19
|
.action(async (query, options) => {
|
|
17
20
|
ensureInitialized();
|
|
18
21
|
const opts = getGlobalOpts(selectCommand);
|
|
@@ -20,6 +23,11 @@ export const selectCommand = new Command('select')
|
|
|
20
23
|
if (isNaN(budget) || budget <= 0) {
|
|
21
24
|
throw new InvalidUsageError('Budget must be a positive number.');
|
|
22
25
|
}
|
|
26
|
+
// Validate format
|
|
27
|
+
const format = options.format.toLowerCase();
|
|
28
|
+
if (!VALID_FORMATS.includes(format)) {
|
|
29
|
+
throw new InvalidUsageError(`Invalid format "${options.format}". Valid formats: ${VALID_FORMATS.join(', ')}`);
|
|
30
|
+
}
|
|
23
31
|
// Parse sources filter
|
|
24
32
|
const sources = options.sources
|
|
25
33
|
? options.sources.split(',').map((s) => s.trim())
|
|
@@ -27,12 +35,16 @@ export const selectCommand = new Command('select')
|
|
|
27
35
|
// Open database
|
|
28
36
|
const db = openDatabase();
|
|
29
37
|
try {
|
|
38
|
+
// Determine effective format (--json flag overrides -f)
|
|
39
|
+
const effectiveFormat = opts.json ? 'json' : format;
|
|
30
40
|
// Run selection
|
|
31
41
|
const result = await selectContext(db, {
|
|
32
42
|
query,
|
|
33
43
|
budget,
|
|
34
44
|
sources,
|
|
35
45
|
explain: options.explain,
|
|
46
|
+
format: effectiveFormat,
|
|
47
|
+
includeImports: options.includeImports,
|
|
36
48
|
});
|
|
37
49
|
// Handle empty index
|
|
38
50
|
if (result.isEmpty) {
|
|
@@ -48,14 +60,8 @@ export const selectCommand = new Command('select')
|
|
|
48
60
|
writeMessage('');
|
|
49
61
|
return;
|
|
50
62
|
}
|
|
51
|
-
// Output
|
|
52
|
-
|
|
53
|
-
writeData(JSON.stringify(result.output.data, null, 2));
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
// Text output goes to stdout (it's the data)
|
|
57
|
-
writeData(result.output.text);
|
|
58
|
-
}
|
|
63
|
+
// Output the formatted text
|
|
64
|
+
writeData(result.output.text);
|
|
59
65
|
}
|
|
60
66
|
finally {
|
|
61
67
|
db.close();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.js","sourceRoot":"","sources":["../../src/commands/select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"select.js","sourceRoot":"","sources":["../../src/commands/select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAqB,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,2BAA2B;AAC3B,MAAM,aAAa,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC;AAEpE,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC;KAC/C,WAAW,CAAC,4BAA4B,CAAC;KACzC,QA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