src-mcp 1.0.1 → 1.0.3
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 +8 -18
- package/dist/bin.d.mts +1 -0
- package/dist/bin.mjs +205 -0
- package/dist/bin.mjs.map +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +8 -0
- package/dist/index.mjs.map +1 -0
- package/dist/server-DL8hfycz.mjs +3791 -0
- package/dist/server-DL8hfycz.mjs.map +1 -0
- package/package.json +10 -9
- package/dist/bin.d.ts +0 -3
- package/dist/bin.d.ts.map +0 -1
- package/dist/bin.js +0 -4
- package/dist/bin.js.map +0 -1
- package/dist/cli/adapter.d.ts +0 -7
- package/dist/cli/adapter.d.ts.map +0 -1
- package/dist/cli/adapter.js +0 -39
- package/dist/cli/adapter.js.map +0 -1
- package/dist/cli/commands/index.d.ts +0 -24
- package/dist/cli/commands/index.d.ts.map +0 -1
- package/dist/cli/commands/index.js +0 -13
- package/dist/cli/commands/index.js.map +0 -1
- package/dist/cli/commands/serve.command.d.ts +0 -21
- package/dist/cli/commands/serve.command.d.ts.map +0 -1
- package/dist/cli/commands/serve.command.js +0 -62
- package/dist/cli/commands/serve.command.js.map +0 -1
- package/dist/cli/commands/version.command.d.ts +0 -2
- package/dist/cli/commands/version.command.d.ts.map +0 -1
- package/dist/cli/commands/version.command.js +0 -12
- package/dist/cli/commands/version.command.js.map +0 -1
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js +0 -15
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/parser.d.ts +0 -7
- package/dist/cli/parser.d.ts.map +0 -1
- package/dist/cli/parser.js +0 -99
- package/dist/cli/parser.js.map +0 -1
- package/dist/config/index.d.ts +0 -24
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -38
- package/dist/config/index.js.map +0 -1
- package/dist/core/ast/index.d.ts +0 -82
- package/dist/core/ast/index.d.ts.map +0 -1
- package/dist/core/ast/index.js +0 -204
- package/dist/core/ast/index.js.map +0 -1
- package/dist/core/ast/types.d.ts +0 -152
- package/dist/core/ast/types.d.ts.map +0 -1
- package/dist/core/ast/types.js +0 -5
- package/dist/core/ast/types.js.map +0 -1
- package/dist/core/constants.d.ts +0 -17
- package/dist/core/constants.d.ts.map +0 -1
- package/dist/core/constants.js +0 -49
- package/dist/core/constants.js.map +0 -1
- package/dist/core/embeddings/callgraph.d.ts +0 -98
- package/dist/core/embeddings/callgraph.d.ts.map +0 -1
- package/dist/core/embeddings/callgraph.js +0 -415
- package/dist/core/embeddings/callgraph.js.map +0 -1
- package/dist/core/embeddings/chunker.d.ts +0 -37
- package/dist/core/embeddings/chunker.d.ts.map +0 -1
- package/dist/core/embeddings/chunker.js +0 -298
- package/dist/core/embeddings/chunker.js.map +0 -1
- package/dist/core/embeddings/client.d.ts +0 -30
- package/dist/core/embeddings/client.d.ts.map +0 -1
- package/dist/core/embeddings/client.js +0 -65
- package/dist/core/embeddings/client.js.map +0 -1
- package/dist/core/embeddings/crossfile.d.ts +0 -58
- package/dist/core/embeddings/crossfile.d.ts.map +0 -1
- package/dist/core/embeddings/crossfile.js +0 -202
- package/dist/core/embeddings/crossfile.js.map +0 -1
- package/dist/core/embeddings/enricher.d.ts +0 -53
- package/dist/core/embeddings/enricher.d.ts.map +0 -1
- package/dist/core/embeddings/enricher.js +0 -308
- package/dist/core/embeddings/enricher.js.map +0 -1
- package/dist/core/embeddings/index.d.ts +0 -13
- package/dist/core/embeddings/index.d.ts.map +0 -1
- package/dist/core/embeddings/index.js +0 -20
- package/dist/core/embeddings/index.js.map +0 -1
- package/dist/core/embeddings/reranker.d.ts +0 -41
- package/dist/core/embeddings/reranker.d.ts.map +0 -1
- package/dist/core/embeddings/reranker.js +0 -117
- package/dist/core/embeddings/reranker.js.map +0 -1
- package/dist/core/embeddings/store.d.ts +0 -93
- package/dist/core/embeddings/store.d.ts.map +0 -1
- package/dist/core/embeddings/store.js +0 -304
- package/dist/core/embeddings/store.js.map +0 -1
- package/dist/core/embeddings/types.d.ts +0 -77
- package/dist/core/embeddings/types.d.ts.map +0 -1
- package/dist/core/embeddings/types.js +0 -5
- package/dist/core/embeddings/types.js.map +0 -1
- package/dist/core/embeddings/watcher.d.ts +0 -130
- package/dist/core/embeddings/watcher.d.ts.map +0 -1
- package/dist/core/embeddings/watcher.js +0 -448
- package/dist/core/embeddings/watcher.js.map +0 -1
- package/dist/core/fallback/index.d.ts +0 -26
- package/dist/core/fallback/index.d.ts.map +0 -1
- package/dist/core/fallback/index.js +0 -76
- package/dist/core/fallback/index.js.map +0 -1
- package/dist/core/parser/index.d.ts +0 -64
- package/dist/core/parser/index.d.ts.map +0 -1
- package/dist/core/parser/index.js +0 -205
- package/dist/core/parser/index.js.map +0 -1
- package/dist/core/parser/languages.d.ts +0 -26
- package/dist/core/parser/languages.d.ts.map +0 -1
- package/dist/core/parser/languages.js +0 -101
- package/dist/core/parser/languages.js.map +0 -1
- package/dist/core/queries/helpers.d.ts +0 -72
- package/dist/core/queries/helpers.d.ts.map +0 -1
- package/dist/core/queries/helpers.js +0 -101
- package/dist/core/queries/helpers.js.map +0 -1
- package/dist/core/queries/index.d.ts +0 -144
- package/dist/core/queries/index.d.ts.map +0 -1
- package/dist/core/queries/index.js +0 -396
- package/dist/core/queries/index.js.map +0 -1
- package/dist/core/queries/loader.d.ts +0 -46
- package/dist/core/queries/loader.d.ts.map +0 -1
- package/dist/core/queries/loader.js +0 -216
- package/dist/core/queries/loader.js.map +0 -1
- package/dist/core/queries/patterns.d.ts +0 -10
- package/dist/core/queries/patterns.d.ts.map +0 -1
- package/dist/core/queries/patterns.js +0 -112
- package/dist/core/queries/patterns.js.map +0 -1
- package/dist/core/symbols/index.d.ts +0 -70
- package/dist/core/symbols/index.d.ts.map +0 -1
- package/dist/core/symbols/index.js +0 -359
- package/dist/core/symbols/index.js.map +0 -1
- package/dist/core/unified/index.d.ts +0 -118
- package/dist/core/unified/index.d.ts.map +0 -1
- package/dist/core/unified/index.js +0 -428
- package/dist/core/unified/index.js.map +0 -1
- package/dist/core/utils/assets.d.ts +0 -34
- package/dist/core/utils/assets.d.ts.map +0 -1
- package/dist/core/utils/assets.js +0 -85
- package/dist/core/utils/assets.js.map +0 -1
- package/dist/core/utils/cache.d.ts +0 -43
- package/dist/core/utils/cache.d.ts.map +0 -1
- package/dist/core/utils/cache.js +0 -60
- package/dist/core/utils/cache.js.map +0 -1
- package/dist/core/utils/index.d.ts +0 -7
- package/dist/core/utils/index.d.ts.map +0 -1
- package/dist/core/utils/index.js +0 -10
- package/dist/core/utils/index.js.map +0 -1
- package/dist/core/utils/tsconfig.d.ts +0 -34
- package/dist/core/utils/tsconfig.d.ts.map +0 -1
- package/dist/core/utils/tsconfig.js +0 -173
- package/dist/core/utils/tsconfig.js.map +0 -1
- package/dist/features/analyze-file/index.d.ts +0 -15
- package/dist/features/analyze-file/index.d.ts.map +0 -1
- package/dist/features/analyze-file/index.js +0 -164
- package/dist/features/analyze-file/index.js.map +0 -1
- package/dist/features/get-call-graph/index.d.ts +0 -24
- package/dist/features/get-call-graph/index.d.ts.map +0 -1
- package/dist/features/get-call-graph/index.js +0 -246
- package/dist/features/get-call-graph/index.js.map +0 -1
- package/dist/features/get-index-status/index.d.ts +0 -20
- package/dist/features/get-index-status/index.d.ts.map +0 -1
- package/dist/features/get-index-status/index.js +0 -90
- package/dist/features/get-index-status/index.js.map +0 -1
- package/dist/features/index-codebase/index.d.ts +0 -24
- package/dist/features/index-codebase/index.d.ts.map +0 -1
- package/dist/features/index-codebase/index.js +0 -283
- package/dist/features/index-codebase/index.js.map +0 -1
- package/dist/features/index.d.ts +0 -15
- package/dist/features/index.d.ts.map +0 -1
- package/dist/features/index.js +0 -28
- package/dist/features/index.js.map +0 -1
- package/dist/features/info/index.d.ts +0 -19
- package/dist/features/info/index.d.ts.map +0 -1
- package/dist/features/info/index.js +0 -41
- package/dist/features/info/index.js.map +0 -1
- package/dist/features/list-symbols/index.d.ts +0 -22
- package/dist/features/list-symbols/index.d.ts.map +0 -1
- package/dist/features/list-symbols/index.js +0 -74
- package/dist/features/list-symbols/index.js.map +0 -1
- package/dist/features/parse-ast/index.d.ts +0 -12
- package/dist/features/parse-ast/index.d.ts.map +0 -1
- package/dist/features/parse-ast/index.js +0 -71
- package/dist/features/parse-ast/index.js.map +0 -1
- package/dist/features/query-code/index.d.ts +0 -23
- package/dist/features/query-code/index.d.ts.map +0 -1
- package/dist/features/query-code/index.js +0 -96
- package/dist/features/query-code/index.js.map +0 -1
- package/dist/features/search-code/index.d.ts +0 -39
- package/dist/features/search-code/index.d.ts.map +0 -1
- package/dist/features/search-code/index.js +0 -258
- package/dist/features/search-code/index.js.map +0 -1
- package/dist/features/types.d.ts +0 -14
- package/dist/features/types.d.ts.map +0 -1
- package/dist/features/types.js +0 -2
- package/dist/features/types.js.map +0 -1
- package/dist/features/update-index/index.d.ts +0 -24
- package/dist/features/update-index/index.d.ts.map +0 -1
- package/dist/features/update-index/index.js +0 -358
- package/dist/features/update-index/index.js.map +0 -1
- package/dist/features/utils/content.d.ts +0 -30
- package/dist/features/utils/content.d.ts.map +0 -1
- package/dist/features/utils/content.js +0 -49
- package/dist/features/utils/content.js.map +0 -1
- package/dist/features/utils/index.d.ts +0 -6
- package/dist/features/utils/index.d.ts.map +0 -1
- package/dist/features/utils/index.js +0 -8
- package/dist/features/utils/index.js.map +0 -1
- package/dist/features/utils/result.d.ts +0 -37
- package/dist/features/utils/result.d.ts.map +0 -1
- package/dist/features/utils/result.js +0 -53
- package/dist/features/utils/result.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +0 -1
- package/dist/prompts/index.d.ts +0 -9
- package/dist/prompts/index.d.ts.map +0 -1
- package/dist/prompts/index.js +0 -188
- package/dist/prompts/index.js.map +0 -1
- package/dist/resources/index.d.ts +0 -3
- package/dist/resources/index.d.ts.map +0 -1
- package/dist/resources/index.js +0 -17
- package/dist/resources/index.js.map +0 -1
- package/dist/server.d.ts +0 -4
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -24
- package/dist/server.js.map +0 -1
- package/dist/tools/adapter.d.ts +0 -4
- package/dist/tools/adapter.d.ts.map +0 -1
- package/dist/tools/adapter.js +0 -28
- package/dist/tools/adapter.js.map +0 -1
- package/dist/tools/index.d.ts +0 -5
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js +0 -9
- package/dist/tools/index.js.map +0 -1
- package/dist/types/index.d.ts +0 -20
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -2
- package/dist/types/index.js.map +0 -1
- package/dist/utils/colors.d.ts +0 -24
- package/dist/utils/colors.d.ts.map +0 -1
- package/dist/utils/colors.js +0 -30
- package/dist/utils/colors.js.map +0 -1
- package/dist/utils/index.d.ts +0 -4
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -4
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/logger.d.ts +0 -8
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -57
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/spinner.d.ts +0 -11
- package/dist/utils/spinner.d.ts.map +0 -1
- package/dist/utils/spinner.js +0 -36
- package/dist/utils/spinner.js.map +0 -1
package/README.md
CHANGED
|
@@ -51,7 +51,6 @@ SRC indexes your codebase into semantic, searchable chunks that LLMs actually un
|
|
|
51
51
|
| Feature | Description |
|
|
52
52
|
|---------|-------------|
|
|
53
53
|
| **Hybrid Search** | Vector + BM25 + RRF fusion for optimal results |
|
|
54
|
-
| **LLM Re-ranking** | AI-powered relevance optimization |
|
|
55
54
|
| **Call Graph** | Shows who calls what and what calls who |
|
|
56
55
|
| **Cross-file Context** | Resolves imports and path aliases automatically |
|
|
57
56
|
| **Incremental Updates** | SHA-256 hash detection for fast updates |
|
|
@@ -74,12 +73,11 @@ SRC indexes your codebase into semantic, searchable chunks that LLMs actually un
|
|
|
74
73
|
|
|
75
74
|
### 1. Install Ollama
|
|
76
75
|
|
|
77
|
-
SRC requires [Ollama](https://ollama.com) for embeddings
|
|
76
|
+
SRC requires [Ollama](https://ollama.com) for embeddings:
|
|
78
77
|
|
|
79
78
|
```bash
|
|
80
79
|
# Install from https://ollama.com, then:
|
|
81
80
|
ollama pull nomic-embed-text
|
|
82
|
-
ollama pull qwen2.5:1.5b
|
|
83
81
|
```
|
|
84
82
|
|
|
85
83
|
### 2. Install SRC
|
|
@@ -152,7 +150,6 @@ src-mcp get_index_status
|
|
|
152
150
|
|------|----------|---------|-------------|
|
|
153
151
|
| `search_code` | `--limit` | 10 | Max results |
|
|
154
152
|
| `search_code` | `--mode` | hybrid | `hybrid` / `vector` / `fts` |
|
|
155
|
-
| `search_code` | `--rerank` | true | LLM re-ranking |
|
|
156
153
|
| `index_codebase` | `--concurrency` | 4 | Parallel workers |
|
|
157
154
|
| `index_codebase` | `--force` | false | Re-index if exists |
|
|
158
155
|
|
|
@@ -234,7 +231,6 @@ Hybrid search with vector similarity, BM25 keyword matching, and RRF fusion.
|
|
|
234
231
|
| `limit` | number | No | `10` | Maximum results to return |
|
|
235
232
|
| `threshold` | number | No | — | Distance threshold (0-2, vector mode only) |
|
|
236
233
|
| `mode` | enum | No | `hybrid` | Search mode: `hybrid`, `vector`, or `fts` |
|
|
237
|
-
| `rerank` | boolean | No | `true` | Enable LLM re-ranking |
|
|
238
234
|
| `includeCallContext` | boolean | No | `true` | Include caller/callee information |
|
|
239
235
|
|
|
240
236
|
**Search Modes:**
|
|
@@ -405,7 +401,6 @@ All settings can be configured via environment variables:
|
|
|
405
401
|
| `CHUNK_SIZE` | Characters per chunk | `1000` |
|
|
406
402
|
| `CHUNK_OVERLAP` | Overlap between chunks | `200` |
|
|
407
403
|
| `EMBEDDING_BATCH_SIZE` | Batch size for embedding | `10` |
|
|
408
|
-
| `RERANK_MODEL` | Model for re-ranking | `qwen2.5:1.5b` |
|
|
409
404
|
| `LOG_LEVEL` | Log verbosity | `info` |
|
|
410
405
|
|
|
411
406
|
**Example:**
|
|
@@ -576,7 +571,7 @@ Source Files → Semantic Chunking → AST Enrichment → Cross-file Context →
|
|
|
576
571
|
|
|
577
572
|
```
|
|
578
573
|
Query → Embed Query → Vector Search ─┐
|
|
579
|
-
├→ RRF Fusion →
|
|
574
|
+
├→ RRF Fusion → Add Call Context → Results
|
|
580
575
|
Query → Tokenize ───→ BM25 Search ───┘
|
|
581
576
|
```
|
|
582
577
|
|
|
@@ -586,9 +581,8 @@ Query → Tokenize ───→ BM25 Search ───┘
|
|
|
586
581
|
2. **Vector Search** — Find semantically similar chunks (cosine similarity)
|
|
587
582
|
3. **BM25 Search** — Find keyword matches (term frequency)
|
|
588
583
|
4. **RRF Fusion** — Combine rankings with Reciprocal Rank Fusion (k=60)
|
|
589
|
-
5. **
|
|
590
|
-
6. **
|
|
591
|
-
7. **Return** — Ranked results with full context
|
|
584
|
+
5. **Call Context** — Add caller/callee information from call graph
|
|
585
|
+
6. **Return** — Ranked results with full context
|
|
592
586
|
|
|
593
587
|
### Technical Specifications
|
|
594
588
|
|
|
@@ -596,7 +590,6 @@ Query → Tokenize ───→ BM25 Search ───┘
|
|
|
596
590
|
|-----------|---------------|
|
|
597
591
|
| **Embedding Model** | nomic-embed-text (137M params) |
|
|
598
592
|
| **Vector Dimensions** | 768 |
|
|
599
|
-
| **Re-ranking Model** | qwen2.5:1.5b (1.5B params) |
|
|
600
593
|
| **Chunk Size** | 1000 characters |
|
|
601
594
|
| **Chunk Overlap** | 200 characters |
|
|
602
595
|
| **Batch Size** | 10 embeddings per request |
|
|
@@ -612,7 +605,6 @@ Query → Tokenize ───→ BM25 Search ───┘
|
|
|
612
605
|
| Feature | SRC | Basic MCPs |
|
|
613
606
|
|---------|-----|------------|
|
|
614
607
|
| **Search Method** | Hybrid (Vector + BM25 + RRF) | Keyword only or basic embedding |
|
|
615
|
-
| **Re-ranking** | LLM-powered | None |
|
|
616
608
|
| **Call Graph** | Full caller/callee context | None |
|
|
617
609
|
| **Cross-file Context** | Resolves imports & path aliases | None |
|
|
618
610
|
| **Incremental Updates** | SHA-256 hash detection | Full re-index required |
|
|
@@ -622,11 +614,10 @@ Query → Tokenize ───→ BM25 Search ───┘
|
|
|
622
614
|
### Key Advantages
|
|
623
615
|
|
|
624
616
|
1. **Hybrid Search** — Combines semantic understanding with keyword precision
|
|
625
|
-
2. **
|
|
626
|
-
3. **
|
|
627
|
-
4. **
|
|
628
|
-
5. **
|
|
629
|
-
6. **Semantic Chunking** — Splits at symbol boundaries, not arbitrary lines
|
|
617
|
+
2. **Call Graph** — Understand code relationships, not just content
|
|
618
|
+
3. **Cross-file Resolution** — Follows imports to provide complete context
|
|
619
|
+
4. **Incremental Updates** — Only re-index what changed
|
|
620
|
+
5. **Semantic Chunking** — Splits at symbol boundaries, not arbitrary lines
|
|
630
621
|
|
|
631
622
|
---
|
|
632
623
|
|
|
@@ -652,7 +643,6 @@ Error: model 'nomic-embed-text' not found
|
|
|
652
643
|
**Solution:**
|
|
653
644
|
```bash
|
|
654
645
|
ollama pull nomic-embed-text
|
|
655
|
-
ollama pull qwen2.5:1.5b
|
|
656
646
|
```
|
|
657
647
|
|
|
658
648
|
### Index Already Exists
|
package/dist/bin.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/bin.mjs
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { a as logger, i as colors, n as features, o as EMBEDDING_CONFIG, r as createIndexWatcher, s as config, t as startServer } from "./server-DL8hfycz.mjs";
|
|
3
|
+
import { defineCommand, runMain } from "citty";
|
|
4
|
+
|
|
5
|
+
//#region src/cli/parser.ts
|
|
6
|
+
/**
|
|
7
|
+
* Convert Zod schema to citty ArgsDef
|
|
8
|
+
*/
|
|
9
|
+
function zodToCittyArgs(schema) {
|
|
10
|
+
if ("shape" in schema && typeof schema.shape === "object") {
|
|
11
|
+
const shape = schema.shape;
|
|
12
|
+
const args = {};
|
|
13
|
+
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
14
|
+
const description = getZodDescription(fieldSchema);
|
|
15
|
+
const isOptional = isZodOptional(fieldSchema);
|
|
16
|
+
const defaultValue = getZodDefault(fieldSchema);
|
|
17
|
+
args[key] = createArgDef(getZodBaseType(fieldSchema), description, isOptional, defaultValue);
|
|
18
|
+
}
|
|
19
|
+
return args;
|
|
20
|
+
}
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
function createArgDef(zodType, description, isOptional, defaultValue) {
|
|
24
|
+
const required = !isOptional && defaultValue === void 0;
|
|
25
|
+
if (zodType === "boolean") {
|
|
26
|
+
const arg$1 = {
|
|
27
|
+
type: "boolean",
|
|
28
|
+
required
|
|
29
|
+
};
|
|
30
|
+
if (description !== void 0) arg$1.description = description;
|
|
31
|
+
if (defaultValue !== void 0) arg$1.default = defaultValue;
|
|
32
|
+
return arg$1;
|
|
33
|
+
}
|
|
34
|
+
const arg = {
|
|
35
|
+
type: "string",
|
|
36
|
+
required
|
|
37
|
+
};
|
|
38
|
+
if (description !== void 0) arg.description = description;
|
|
39
|
+
if (defaultValue !== void 0) arg.default = defaultValue;
|
|
40
|
+
return arg;
|
|
41
|
+
}
|
|
42
|
+
function getZodDescription(schema) {
|
|
43
|
+
if ("description" in schema && typeof schema.description === "string") return schema.description;
|
|
44
|
+
if ("_def" in schema) {
|
|
45
|
+
const def = schema._def;
|
|
46
|
+
if ("description" in def && typeof def.description === "string") return def.description;
|
|
47
|
+
if ("innerType" in def && def.innerType !== void 0) return getZodDescription(def.innerType);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function isZodOptional(schema) {
|
|
51
|
+
if ("_def" in schema) {
|
|
52
|
+
const def = schema._def;
|
|
53
|
+
if (def.type === "optional" || def.type === "default") return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
function getZodDefault(schema) {
|
|
58
|
+
if ("_def" in schema) {
|
|
59
|
+
const def = schema._def;
|
|
60
|
+
if (def.type === "default" && "defaultValue" in def) return def.defaultValue;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function getZodBaseType(schema) {
|
|
64
|
+
if ("_def" in schema) {
|
|
65
|
+
const def = schema._def;
|
|
66
|
+
const type = def.type;
|
|
67
|
+
if (type === "optional" || type === "default") {
|
|
68
|
+
if ("innerType" in def && def.innerType !== void 0) return getZodBaseType(def.innerType);
|
|
69
|
+
}
|
|
70
|
+
return type;
|
|
71
|
+
}
|
|
72
|
+
return "string";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/cli/adapter.ts
|
|
77
|
+
/**
|
|
78
|
+
* Convert a Feature to a citty CommandDef
|
|
79
|
+
*/
|
|
80
|
+
function featureToCittyCommand(feature) {
|
|
81
|
+
return defineCommand({
|
|
82
|
+
meta: {
|
|
83
|
+
name: feature.name,
|
|
84
|
+
description: feature.description
|
|
85
|
+
},
|
|
86
|
+
args: zodToCittyArgs(feature.schema),
|
|
87
|
+
run({ args }) {
|
|
88
|
+
const result = feature.execute(args);
|
|
89
|
+
const handleResult = (res) => {
|
|
90
|
+
if (res.success) {
|
|
91
|
+
const output = res.message ?? JSON.stringify(res.data, null, 2);
|
|
92
|
+
console.log(colors.formatSuccess(output));
|
|
93
|
+
} else {
|
|
94
|
+
console.error(colors.formatError(res.error ?? "Unknown error"));
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
if (result instanceof Promise) result.then(handleResult).catch((err) => {
|
|
99
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
100
|
+
console.error(colors.formatError(`Unexpected error: ${errorMsg}`));
|
|
101
|
+
process.exit(1);
|
|
102
|
+
});
|
|
103
|
+
else handleResult(result);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/cli/commands/serve.command.ts
|
|
110
|
+
const serveCommand = defineCommand({
|
|
111
|
+
meta: {
|
|
112
|
+
name: "serve",
|
|
113
|
+
description: "Start the MCP server"
|
|
114
|
+
},
|
|
115
|
+
args: {
|
|
116
|
+
transport: {
|
|
117
|
+
type: "string",
|
|
118
|
+
alias: "t",
|
|
119
|
+
description: "Transport type (stdio)",
|
|
120
|
+
default: "stdio"
|
|
121
|
+
},
|
|
122
|
+
directory: {
|
|
123
|
+
type: "string",
|
|
124
|
+
alias: "d",
|
|
125
|
+
description: "Directory to watch and index (defaults to current directory)",
|
|
126
|
+
default: "."
|
|
127
|
+
},
|
|
128
|
+
watch: {
|
|
129
|
+
type: "boolean",
|
|
130
|
+
alias: "w",
|
|
131
|
+
description: "Enable file watcher for automatic indexing",
|
|
132
|
+
default: true
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
async run({ args }) {
|
|
136
|
+
const { directory, watch } = args;
|
|
137
|
+
if (watch) {
|
|
138
|
+
const watcher = createIndexWatcher({
|
|
139
|
+
directory,
|
|
140
|
+
config: EMBEDDING_CONFIG,
|
|
141
|
+
onError: (error) => {
|
|
142
|
+
logger.error(`Watcher error: ${error.message}`);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
try {
|
|
146
|
+
await watcher.start();
|
|
147
|
+
} catch (err) {
|
|
148
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
149
|
+
logger.warn(`Watcher disabled: ${msg}`);
|
|
150
|
+
}
|
|
151
|
+
process.on("SIGINT", () => {
|
|
152
|
+
watcher.stop();
|
|
153
|
+
process.exit(0);
|
|
154
|
+
});
|
|
155
|
+
process.on("SIGTERM", () => {
|
|
156
|
+
watcher.stop();
|
|
157
|
+
process.exit(0);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
await startServer();
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/cli/commands/version.command.ts
|
|
166
|
+
const versionCommand = defineCommand({
|
|
167
|
+
meta: {
|
|
168
|
+
name: "version",
|
|
169
|
+
description: "Display version information"
|
|
170
|
+
},
|
|
171
|
+
run() {
|
|
172
|
+
console.log(`${config.name} v${config.version}`);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/cli/commands/index.ts
|
|
178
|
+
const featureCommands = Object.fromEntries(features.map((f) => [f.name, featureToCittyCommand(f)]));
|
|
179
|
+
const subCommands = {
|
|
180
|
+
serve: serveCommand,
|
|
181
|
+
version: versionCommand,
|
|
182
|
+
...featureCommands
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/cli/index.ts
|
|
187
|
+
const main = defineCommand({
|
|
188
|
+
meta: {
|
|
189
|
+
name: config.name,
|
|
190
|
+
version: config.version,
|
|
191
|
+
description: config.description ?? ""
|
|
192
|
+
},
|
|
193
|
+
subCommands
|
|
194
|
+
});
|
|
195
|
+
function runCLI() {
|
|
196
|
+
runMain(main);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/bin.ts
|
|
201
|
+
runCLI();
|
|
202
|
+
|
|
203
|
+
//#endregion
|
|
204
|
+
export { };
|
|
205
|
+
//# sourceMappingURL=bin.mjs.map
|
package/dist/bin.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.mjs","names":["arg"],"sources":["../src/cli/parser.ts","../src/cli/adapter.ts","../src/cli/commands/serve.command.ts","../src/cli/commands/version.command.ts","../src/cli/commands/index.ts","../src/cli/index.ts","../src/bin.ts"],"sourcesContent":["import type { ArgsDef, ArgDef } from \"citty\";\nimport type { z } from \"zod\";\n\n/**\n * Convert Zod schema to citty ArgsDef\n */\nexport function zodToCittyArgs(schema: z.ZodType): ArgsDef {\n // Handle ZodObject\n if (\"shape\" in schema && typeof schema.shape === \"object\") {\n const shape = schema.shape as Record<string, z.ZodType>;\n const args: ArgsDef = {};\n\n for (const [key, fieldSchema] of Object.entries(shape)) {\n const description = getZodDescription(fieldSchema);\n const isOptional = isZodOptional(fieldSchema);\n const defaultValue = getZodDefault(fieldSchema);\n const zodType = getZodBaseType(fieldSchema);\n\n args[key] = createArgDef(zodType, description, isOptional, defaultValue);\n }\n\n return args;\n }\n\n return {};\n}\n\nfunction createArgDef(\n zodType: string,\n description: string | undefined,\n isOptional: boolean,\n defaultValue: unknown,\n): ArgDef {\n const required = !isOptional && defaultValue === undefined;\n\n if (zodType === \"boolean\") {\n const arg: ArgDef = {\n type: \"boolean\" as const,\n required,\n };\n if (description !== undefined) {\n arg.description = description;\n }\n if (defaultValue !== undefined) {\n arg.default = defaultValue as boolean;\n }\n return arg;\n }\n\n // String, Number, Enum all become string in citty\n const arg: ArgDef = {\n type: \"string\" as const,\n required,\n };\n if (description !== undefined) {\n arg.description = description;\n }\n if (defaultValue !== undefined) {\n arg.default = defaultValue as string;\n }\n return arg;\n}\n\nfunction getZodDescription(schema: z.ZodType): string | undefined {\n if (\"description\" in schema && typeof schema.description === \"string\") {\n return schema.description;\n }\n // Check inner type for optional/default wrappers\n\n if (\"_def\" in schema) {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const def = schema._def as unknown as Record<string, unknown>;\n if (\"description\" in def && typeof def.description === \"string\") {\n return def.description;\n }\n if (\"innerType\" in def && def.innerType !== undefined) {\n return getZodDescription(def.innerType as z.ZodType);\n }\n }\n return undefined;\n}\n\nfunction isZodOptional(schema: z.ZodType): boolean {\n if (\"_def\" in schema) {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const def = schema._def as unknown as Record<string, unknown>;\n if (def.type === \"optional\" || def.type === \"default\") {\n return true;\n }\n }\n return false;\n}\n\nfunction getZodDefault(schema: z.ZodType): unknown {\n if (\"_def\" in schema) {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const def = schema._def as unknown as Record<string, unknown>;\n if (def.type === \"default\" && \"defaultValue\" in def) {\n return def.defaultValue;\n }\n }\n return undefined;\n}\n\nfunction getZodBaseType(schema: z.ZodType): string {\n if (\"_def\" in schema) {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const def = schema._def as unknown as Record<string, unknown>;\n const type = def.type as string;\n\n if (type === \"optional\" || type === \"default\") {\n if (\"innerType\" in def && def.innerType !== undefined) {\n return getZodBaseType(def.innerType as z.ZodType);\n }\n }\n\n return type;\n }\n return \"string\";\n}\n","import { defineCommand, type CommandDef } from \"citty\";\nimport type { Feature } from \"@features/types\";\nimport { zodToCittyArgs } from \"@cli/parser\";\nimport { colors } from \"@utils\";\n\n/**\n * Convert a Feature to a citty CommandDef\n */\nexport function featureToCittyCommand(feature: Feature): CommandDef {\n return defineCommand({\n meta: {\n name: feature.name,\n description: feature.description,\n },\n args: zodToCittyArgs(feature.schema),\n run({ args }) {\n const result = feature.execute(args);\n\n const handleResult = (\n res: Awaited<ReturnType<typeof feature.execute>>,\n ): void => {\n if (res.success) {\n const output = res.message ?? JSON.stringify(res.data, null, 2);\n console.log(colors.formatSuccess(output));\n } else {\n console.error(colors.formatError(res.error ?? \"Unknown error\"));\n process.exit(1);\n }\n };\n\n if (result instanceof Promise) {\n result.then(handleResult).catch((err: unknown) => {\n const errorMsg = err instanceof Error ? err.message : String(err);\n console.error(colors.formatError(`Unexpected error: ${errorMsg}`));\n process.exit(1);\n });\n } else {\n handleResult(result);\n }\n },\n });\n}\n","import { defineCommand } from \"citty\";\nimport { startServer } from \"@/server\";\nimport { createIndexWatcher } from \"@core/embeddings\";\nimport { EMBEDDING_CONFIG } from \"@config\";\nimport { logger } from \"@utils\";\n\nexport const serveCommand = defineCommand({\n meta: {\n name: \"serve\",\n description: \"Start the MCP server\",\n },\n args: {\n transport: {\n type: \"string\",\n alias: \"t\",\n description: \"Transport type (stdio)\",\n default: \"stdio\",\n },\n directory: {\n type: \"string\",\n alias: \"d\",\n description:\n \"Directory to watch and index (defaults to current directory)\",\n default: \".\",\n },\n watch: {\n type: \"boolean\",\n alias: \"w\",\n description: \"Enable file watcher for automatic indexing\",\n default: true,\n },\n },\n async run({ args }) {\n const { directory, watch } = args;\n\n // Start watcher if enabled\n if (watch) {\n const watcher = createIndexWatcher({\n directory,\n config: EMBEDDING_CONFIG,\n onError: (error) => {\n logger.error(`Watcher error: ${error.message}`);\n },\n });\n\n try {\n await watcher.start();\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n logger.warn(`Watcher disabled: ${msg}`);\n }\n\n // Cleanup on exit\n process.on(\"SIGINT\", () => {\n void watcher.stop();\n process.exit(0);\n });\n process.on(\"SIGTERM\", () => {\n void watcher.stop();\n process.exit(0);\n });\n }\n\n await startServer();\n },\n});\n","import { defineCommand } from \"citty\";\nimport { config } from \"@config\";\n\nexport const versionCommand = defineCommand({\n meta: {\n name: \"version\",\n description: \"Display version information\",\n },\n run() {\n console.log(`${config.name} v${config.version}`);\n },\n});\n","import { features } from \"@features\";\nimport { featureToCittyCommand } from \"@cli/adapter\";\nimport { serveCommand } from \"@cli/commands/serve.command\";\nimport { versionCommand } from \"@cli/commands/version.command\";\n\n// Feature commands converted from features\nconst featureCommands = Object.fromEntries(\n features.map((f) => [f.name, featureToCittyCommand(f)]),\n);\n\n// All subcommands\nexport const subCommands = {\n serve: serveCommand,\n version: versionCommand,\n ...featureCommands,\n};\n","import { defineCommand, runMain } from \"citty\";\nimport { config } from \"@config\";\nimport { subCommands } from \"@cli/commands\";\n\nconst main = defineCommand({\n meta: {\n name: config.name,\n version: config.version,\n description: config.description ?? \"\",\n },\n subCommands,\n});\n\nexport function runCLI(): void {\n void runMain(main);\n}\n","#!/usr/bin/env node\nimport { runCLI } from \"@cli\";\n\nrunCLI();\n"],"mappings":";;;;;;;;AAMA,SAAgB,eAAe,QAA4B;AAEzD,KAAI,WAAW,UAAU,OAAO,OAAO,UAAU,UAAU;EACzD,MAAM,QAAQ,OAAO;EACrB,MAAM,O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UAAU,mBAAmB;IACjC;IACA,QAAQ;IACR,UAAU,UAAU;AAClB,YAAO,MAAM,kBAAkB,MAAM,UAAU;;IAElD,CAAC;AAEF,OAAI;AACF,UAAM,QAAQ,OAAO;YACd,KAAK;IACZ,MAAM,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI;AAC5D,WAAO,KAAK,qBAAqB,MAAM;;AAIzC,WAAQ,GAAG,gBAAgB;AACzB,IAAK,QAAQ,MAAM;AACnB,YAAQ,KAAK,EAAE;KACf;AACF,WAAQ,GAAG,iBAAiB;AAC1B,IAAK,QAAQ,MAAM;AACnB,YAAQ,KAAK,EAAE;KACf;;AAGJ,QAAM,aAAa;;CAEtB,CAAC;;;;AC9DF,MAAa,iBAAiB,cAAc;CAC1C,MAAM;EACJ,MAAM;EACN,aAAa;EACd;CACD,MAAM;AACJ,UAAQ,IAAI,GAAG,OAAO,KAAK,IAAI,OAAO,UAAU;;CAEnD,CAAC;;;;ACLF,MAAM,kBAAkB,OAAO,YAC7B,SAAS,KAAK,MAAM,CAAC,EAAE,MAAM,sBAAsB,EAAE,CAAC,CAAC,CACxD;AAGD,MAAa,cAAc;CACzB,OAAO;CACP,SAAS;CACT,GAAG;CACJ;;;;ACXD,MAAM,OAAO,cAAc;CACzB,MAAM;EACJ,MAAM,OAAO;EACb,SAAS,OAAO;EAChB,aAAa,OAAO,eAAe;EACpC;CACD;CACD,CAAC;AAEF,SAAgB,SAAe;AAC7B,CAAK,QAAQ,KAAK;;;;;ACXpB,QAAQ"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["// Main entry point - starts the MCP server directly\nimport { startServer } from \"@/server\";\n\nstartServer().catch(console.error);\n"],"mappings":";;;AAGA,aAAa,CAAC,MAAM,QAAQ,MAAM"}
|