turboprop 0.1.2

Fast semantic code search and indexing tool
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
# TurboProp MCP Server User Guide

## Overview

### What is MCP?

MCP (Model Context Protocol) is a standard way for AI coding agents to access external tools and data sources. Think of it as a bridge that allows your AI assistant to interact with tools beyond their built-in capabilities.

**Before MCP**: Your coding agent could only work with information you directly provide or share with it.
**With MCP**: Your coding agent can actively search, query, and interact with your entire codebase in real-time.

### Why TurboProp's MCP Server?

TurboProp's MCP server transforms your coding agent into a semantic code search expert. Instead of just reading the files you show it, your agent can:

- 🔍 **Search your entire codebase** using natural language queries
- 🎯 **Find relevant code instantly** based on meaning, not just keywords  
- 🔄 **Stay synchronized** with your changes through real-time file watching
- 🚀 **Work across any programming language** or file type in your project

**Example**: Ask your agent *"Find the JWT authentication implementation"* and it will search through your entire codebase, locate the relevant code, and explain how it works - all without you having to find and share the files manually.

### How It Works

The MCP server acts like a librarian for your codebase:

1. **📚 Catalogs Your Code**: Indexes all files in your repository with semantic embeddings
2. **👀 Watches for Changes**: Monitors file changes and updates the index automatically  
3. **🔍 Provides Search Tool**: Exposes a `search` tool that agents can use via MCP protocol
4. **⚡ Returns Smart Results**: Finds code based on meaning and context, not just keyword matching

This guide covers everything you need to know to set up, configure, and use the MCP server effectively with your preferred coding agent.

## Table of Contents

1. [Installation and Setup]#installation-and-setup
2. [Basic Usage]#basic-usage
3. [Agent Integration]#agent-integration
4. [Configuration]#configuration
5. [Advanced Features]#advanced-features
6. [Troubleshooting]#troubleshooting
7. [Performance Optimization]#performance-optimization

## Installation and Setup

### Prerequisites

- TurboProp installed and available in PATH
- A git repository or directory with code files
- A compatible coding agent (Claude Code, Cursor, GitHub Copilot, etc.)

### Quick Setup

1. **Navigate to your project directory:**
   ```bash
   cd /path/to/your/project
   ```

2. **Start the MCP server:**
   ```bash
   tp mcp --repo .
   ```

3. **Configure your coding agent** (see [Agent Integration]#agent-integration)

4. **Start coding!** Your agent can now search your codebase semantically.

## Basic Usage

### Starting the Server

```bash
# Basic usage - index current directory
tp mcp --repo .

# Specify a different directory
tp mcp --repo /path/to/project

# Use custom model
tp mcp --repo . --model sentence-transformers/all-MiniLM-L12-v2

# Set file size limit
tp mcp --repo . --max-filesize 5mb

# Force rebuild of index
tp mcp --repo . --force-rebuild

# Enable verbose logging
tp mcp --repo . --verbose
```

### Server Lifecycle

When you start the MCP server:

1. **Initial Indexing**: Scans all files and builds semantic index
2. **File Watching**: Monitors directory for changes
3. **Real-time Updates**: Updates index when files change
4. **Ready State**: Accepts search requests from agents

The server runs until you stop it (Ctrl+C) or the agent disconnects.

### Understanding the Output

```bash
$ tp mcp --repo .
🚀 TurboProp MCP Server Started
────────────────────────────────
Repository: /Users/you/project
Configuration summary:
  Repository: /Users/you/project
  Model: sentence-transformers/all-MiniLM-L6-v2
  Max file size: 2mb
  Batch size: 32

MCP server ready and listening on stdio...
```

## Agent Integration

### Claude Code

**Method 1: Global Configuration** (applies to all projects)

Add to `~/.claude/mcp.json`:
```json
{
  "mcpServers": {
    "turboprop": {
      "command": "tp",
      "args": ["mcp", "--repo", "."],
      "env": {}
    }
  }
}
```

**Method 2: Project-specific Configuration** (recommended)

Add to your project's `.claude.json`:
```json
{
  "mcpServers": {
    "turboprop": {
      "command": "tp",
      "args": ["mcp", "--repo", "."]
    }
  }
}
```

**✓ Verify Setup**: Restart Claude Code and ask: *"Search for error handling code in this project"*

### Cursor

**Standard Configuration**

Add to `.cursor/mcp.json` in your project root:
```json
{
  "mcpServers": {
    "turboprop": {
      "command": "tp",
      "args": ["mcp", "--repo", "."],
      "cwd": "."
    }
  }
}
```

**Advanced Configuration** (with custom settings):
```json
{
  "mcpServers": {
    "turboprop": {
      "command": "tp",
      "args": ["mcp", "--repo", ".", "--verbose", "--max-filesize", "3mb"],
      "cwd": ".",
      "env": {
        "RUST_LOG": "info"
      }
    }
  }
}
```

**✓ Verify Setup**: Use Cursor's command palette and ask the AI to search your codebase

### GitHub Copilot

**VS Code Configuration**

Add to your VS Code `settings.json`:
```json
{
  "github.copilot.mcp.servers": [
    {
      "name": "turboprop",
      "command": "tp",
      "args": ["mcp", "--repo", "."],
      "env": {}
    }
  ]
}
```

**JetBrains IDEs** (IntelliJ, PyCharm, WebStorm)

Add to your IDE's MCP configuration:
```json
{
  "mcpServers": {
    "turboprop": {
      "command": "tp",
      "args": ["mcp", "--repo", "."]
    }
  }
}
```

### Windsurf

**Project Configuration**

Add to your Windsurf project configuration:
```json
{
  "mcp": {
    "servers": {
      "turboprop": {
        "command": "tp",
        "args": ["mcp", "--repo", "."]
      }
    }
  }
}
```

### Replit Agent

**Replit Configuration**

Add to your `.replit` file:
```toml
[mcp]
servers.turboprop.command = "tp"
servers.turboprop.args = ["mcp", "--repo", "."]
```

### Aider

**Standard Configuration**

Aider supports MCP through its `--mcp-server` flag. Start Aider with TurboProp MCP server:

```bash
# Basic setup - run from your project root
aider --mcp-server "tp mcp --repo ."
```

**Advanced Configuration** (with custom settings):

```bash
# With custom file size limits and verbose output
aider --mcp-server "tp mcp --repo . --verbose --max-filesize 5mb"
```

**Configuration File** (`.aider.conf.yml`):

```yaml
mcp-servers:
  - name: "turboprop"
    command: "tp"
    args: ["mcp", "--repo", "."]
    description: "Semantic code search for your project"
```

**Usage Examples**:
- *"Use the turboprop tool to find authentication code in this project"*
- *"Search for error handling patterns and show me the most relevant examples"*
- *"Find database connection logic and explain how it works"*

**✓ Verify Setup**: Ask Aider to search your codebase: *"Search for configuration files and explain the project structure"*

### Continue.dev

**VS Code Extension Configuration**

Add to your Continue configuration file (`~/.continue/config.json`):

```json
{
  "models": [
    {
      "title": "GPT-4",
      "provider": "openai",
      "model": "gpt-4"
    }
  ],
  "mcpServers": {
    "turboprop": {
      "command": "tp",
      "args": ["mcp", "--repo", "."],
      "env": {}
    }
  }
}
```

**JetBrains Plugin Configuration**

Add to your Continue settings in JetBrains IDEs:

```json
{
  "mcpServers": {
    "turboprop": {
      "command": "tp", 
      "args": ["mcp", "--repo", ".", "--verbose"],
      "workingDirectory": "."
    }
  }
}
```

**Project-specific Configuration** (`.continue/config.json` in project root):

```json
{
  "mcpServers": {
    "turboprop": {
      "command": "tp",
      "args": ["mcp", "--repo", ".", "--max-filesize", "3mb"],
      "description": "Semantic search for this specific project"
    }
  }
}
```

**Usage Examples**:
- Right-click in editor → Continue → *"Search this codebase for similar functions"*  
- Chat: *"Use turboprop to find all tests related to user authentication"*
- Chat: *"Search for TODO comments and prioritize them by complexity"*

**✓ Verify Setup**: Use Continue's chat and ask: *"Search the codebase for API endpoints and list them"*

### Development Environment Integration

#### VS Code (Multiple Agents)

For VS Code with various AI extensions, add to `settings.json`:
```json
{
  "mcp.servers": {
    "turboprop": {
      "command": "tp",
      "args": ["mcp", "--repo", "."],
      "description": "TurboProp semantic code search"
    }
  }
}
```

#### Neovim

For Neovim with MCP-compatible plugins:
```lua
-- In your Neovim config
require('mcp').setup({
  servers = {
    turboprop = {
      command = 'tp',
      args = {'mcp', '--repo', '.'},
      filetypes = {'*'}
    }
  }
})
```

#### Emacs

For Emacs with LSP/MCP integration:
```elisp
;; In your Emacs config
(setq mcp-servers
  '((turboprop . (:command "tp"
                  :args ("mcp" "--repo" ".")))))
```

### Team Configuration Templates

#### Shared Team Config (`.turboprop-mcp.json`)

Create a shared configuration file for your team:
```json
{
  "mcpServers": {
    "turboprop": {
      "command": "tp",
      "args": ["mcp", "--repo", ".", "--model", "sentence-transformers/all-MiniLM-L12-v2"],
      "env": {
        "TURBOPROP_CACHE_DIR": "./.turboprop-cache"
      }
    }
  }
}
```

Then team members can reference it in their agent configs:
```json
{
  "mcpServers": {
    "$ref": "./.turboprop-mcp.json#/mcpServers"
  }
}
```

### Troubleshooting Agent Integration

**Problem**: Agent can't find the `tp` command
- **Solution**: Ensure TurboProp is in your PATH: `which tp`
- **Alternative**: Use absolute path: `"/usr/local/bin/tp"`

**Problem**: Server starts but agent can't connect
- **Solution**: Check agent logs for specific MCP protocol errors
- **Alternative**: Try starting server manually: `tp mcp --repo . --verbose`

**Problem**: Configuration file not loading
- **Solution**: Verify JSON syntax and file permissions
- **Alternative**: Test with minimal configuration first

## Configuration

### Command Line Options

| Option | Description | Example |
|--------|-------------|---------|
| `--repo` | Repository path to index | `--repo /path/to/project` |
| `--model` | Embedding model to use | `--model sentence-transformers/all-MiniLM-L12-v2` |
| `--max-filesize` | Maximum file size to index | `--max-filesize 5mb` |
| `--filter` | Glob pattern for files to include | `--filter "src/**/*.rs"` |
| `--filetype` | Filter by file type | `--filetype rust` |
| `--force-rebuild` | Force rebuild of existing index | `--force-rebuild` |
| `--verbose` | Enable verbose logging | `--verbose` |
| `--debug` | Enable debug logging | `--debug` |

### Configuration Hierarchy

TurboProp follows this configuration priority order (highest to lowest):

1. **Command line arguments** (highest priority)
2. **Environment variables**
3. **Project `.turboprop.yml`** (in repository root)
4. **Global config** (`~/.turboprop/config.yml`)
5. **Built-in defaults** (lowest priority)

Example:
```bash
# Command line overrides config file
tp mcp --repo . --model "sentence-transformers/all-MiniLM-L12-v2"  # Uses L12 model
# Even if .turboprop.yml specifies L6 model
```

### Configuration File Examples

#### Basic Configuration (`.turboprop.yml`)

```yaml
# Model configuration
model: "sentence-transformers/all-MiniLM-L6-v2"
cache_dir: "~/.turboprop-cache"

# File discovery settings
max_filesize: "2mb"
file_discovery:
  include_patterns:
    - "**/*.rs"
    - "**/*.js" 
    - "**/*.ts"
    - "**/*.py"
    - "**/*.java"
    - "**/*.go"
    - "**/*.md"
  exclude_patterns:
    - "target/**"
    - "node_modules/**"
    - ".git/**"
    - "*.log"
  
# Search settings  
search:
  default_limit: 10
  similarity_threshold: 0.3

# Embedding settings
embedding:
  batch_size: 32
  cache_embeddings: true

# MCP server settings
mcp:
  enable_file_watching: true
  update_debounce_ms: 500
  max_concurrent_searches: 10
```

#### Monorepo Configuration

For large monorepos with multiple services/packages:

```yaml
# Monorepo-optimized configuration
model: "sentence-transformers/all-MiniLM-L12-v2"
max_filesize: "3mb"

# Service-based file discovery
file_discovery:
  include_patterns:
    - "services/*/src/**/*.{rs,py,js,ts}"
    - "libs/*/src/**/*.{rs,py,js,ts}"
    - "packages/*/src/**/*.{js,ts,tsx,jsx}"
    - "apps/*/src/**/*.{js,ts,tsx,jsx}"
    - "docs/**/*.md"
  exclude_patterns:
    - "**/target/**"
    - "**/node_modules/**"
    - "**/dist/**"
    - "**/build/**"
    - "**/*.test.*"
    - "**/*.spec.*"
    - "**/coverage/**"

# Performance optimization for large repos
embedding:
  batch_size: 16  # Reduce for stability
  worker_threads: 8
  cache_embeddings: true

mcp:
  update_debounce_ms: 1000  # Reduce update frequency
  max_concurrent_searches: 5
  
search:
  similarity_threshold: 0.4  # Higher threshold for better precision
```

#### Language-Specific Configurations

**Rust Project**:
```yaml
model: "nomic-embed-code.Q5_K_S.gguf"  # Code-specific model
max_filesize: "5mb"

file_discovery:
  include_patterns:
    - "src/**/*.rs"
    - "lib/**/*.rs"
    - "benches/**/*.rs"
    - "examples/**/*.rs"
    - "Cargo.toml"
    - "README.md"
  exclude_patterns:
    - "target/**"
    - "**/*_generated.rs"

search:
  similarity_threshold: 0.35
```

**JavaScript/TypeScript Project**:
```yaml
model: "sentence-transformers/all-MiniLM-L12-v2"
max_filesize: "2mb"

file_discovery:
  include_patterns:
    - "src/**/*.{js,ts,jsx,tsx}"
    - "lib/**/*.{js,ts}"
    - "pages/**/*.{js,ts,jsx,tsx}"
    - "components/**/*.{js,ts,jsx,tsx}"
    - "package.json"
    - "tsconfig.json"
    - "*.md"
  exclude_patterns:
    - "node_modules/**"
    - "dist/**"
    - "build/**"
    - "**/*.min.js"
    - "**/*.bundle.js"
    - "coverage/**"
```

**Python Project**:
```yaml
model: "sentence-transformers/all-MiniLM-L6-v2"
max_filesize: "3mb"

file_discovery:
  include_patterns:
    - "src/**/*.py"
    - "lib/**/*.py"
    - "scripts/**/*.py"
    - "tests/**/*.py"
    - "requirements*.txt"
    - "pyproject.toml"
    - "setup.py"
    - "*.md"
  exclude_patterns:
    - "__pycache__/**"
    - "*.pyc"
    - "venv/**"
    - ".env/**"
    - "build/**"
    - "dist/**"
```

#### Performance Profiles

**High Performance** (for fast machines):
```yaml
embedding:
  batch_size: 64
  worker_threads: 12
  cache_embeddings: true

mcp:
  update_debounce_ms: 200
  max_concurrent_searches: 15
```

**Memory Constrained** (for limited resources):
```yaml
embedding:
  batch_size: 8
  worker_threads: 2
  cache_embeddings: false

file_discovery:
  max_filesize: "500kb"
  
mcp:
  update_debounce_ms: 2000
  max_concurrent_searches: 3
```

#### Team Configuration

**Shared Team Standards**:
```yaml
# Team configuration - commit this file
model: "sentence-transformers/all-MiniLM-L12-v2"  # Team standard
cache_dir: "./.turboprop-cache"  # Project-local cache
max_filesize: "2mb"

file_discovery:
  include_patterns:
    - "src/**/*.{rs,py,js,ts}"
    - "docs/**/*.md"
  exclude_patterns:
    - "target/**"
    - "node_modules/**"
    - "**/*.generated.*"
    - "**/test-fixtures/**"

search:
  default_limit: 10
  similarity_threshold: 0.35

# Consistent performance settings
embedding:
  batch_size: 32
  cache_embeddings: true

mcp:
  enable_file_watching: true
  update_debounce_ms: 500
  max_concurrent_searches: 8
```

### Environment Variables

| Variable | Description | Default |
|----------|-------------|---------|
| `TURBOPROP_CACHE_DIR` | Cache directory for models | `~/.turboprop-cache` |
| `TURBOPROP_LOG_LEVEL` | Log level (error, warn, info, debug) | `info` |
| `RUST_LOG` | Rust logging configuration | - |

## Advanced Features

### Model Selection

Choose the right model for your use case:

```bash
# Fast, lightweight (default)
tp mcp --repo . --model sentence-transformers/all-MiniLM-L6-v2

# Better accuracy
tp mcp --repo . --model sentence-transformers/all-MiniLM-L12-v2

# Code-specific model (when available)
tp mcp --repo . --model nomic-embed-code.Q5_K_S.gguf

# Multilingual support (when available)
tp mcp --repo . --model Qwen/Qwen3-Embedding-0.6B
```

### File Filtering

Control which files are indexed:

```bash
# Only Rust files
tp mcp --repo . --filter "**/*.rs"

# Multiple patterns in config file
# .turboprop.yml:
file_discovery:
  include_patterns:
    - "src/**/*.rs"
    - "lib/**/*.rs" 
    - "tests/**/*.rs"
  exclude_patterns:
    - "target/**"
    - "**/*_generated.rs"
```

### Performance Tuning

For large repositories:

```yaml
# .turboprop.yml
embedding:
  batch_size: 16  # Reduce for lower memory usage
  
file_discovery:
  max_filesize: "1mb"  # Skip very large files
  
mcp:
  update_debounce_ms: 1000  # Reduce update frequency
```

### Docker Environment Setup

Deploy TurboProp MCP server in Docker for consistent team development or production use.

#### Basic Docker Setup

**Dockerfile** for TurboProp MCP server:

```dockerfile
FROM rust:1.75 as builder

# Install TurboProp
RUN cargo install turboprop --version latest

FROM debian:bookworm-slim

# Install runtime dependencies
RUN apt-get update && \
    apt-get install -y git ca-certificates && \
    rm -rf /var/lib/apt/lists/*

# Copy TurboProp binary from builder stage
COPY --from=builder /usr/local/cargo/bin/tp /usr/local/bin/tp

# Set working directory
WORKDIR /workspace

# Default command runs MCP server
CMD ["tp", "mcp", "--repo", "/workspace", "--verbose"]
```

**Build and run**:

```bash
# Build the image
docker build -t turboprop-mcp .

# Run with your code mounted
docker run -it --rm \
  -v "$(pwd):/workspace" \
  -p 3000:3000 \
  turboprop-mcp
```

#### Docker Compose Setup

**docker-compose.yml** for development environment:

```yaml
version: '3.8'
services:
  turboprop-mcp:
    build: .
    volumes:
      - .:/workspace:ro
      - turboprop-cache:/root/.turboprop-cache
    environment:
      - RUST_LOG=info
      - TURBOPROP_CACHE_DIR=/root/.turboprop-cache
    command: tp mcp --repo /workspace --max-filesize 5mb --verbose
    restart: unless-stopped
    
  # Optional: Development agent that uses the MCP server
  dev-agent:
    image: cursor/dev:latest
    depends_on:
      - turboprop-mcp
    volumes:
      - .:/workspace
    environment:
      - MCP_SERVER_URL=http://turboprop-mcp:3000
      
volumes:
  turboprop-cache:
```

**Start the environment**:

```bash
# Start all services
docker-compose up -d

# View logs
docker-compose logs -f turboprop-mcp

# Stop services
docker-compose down
```

#### Production Docker Setup

**Multi-stage production Dockerfile**:

```dockerfile
FROM rust:1.75-alpine as builder

# Install dependencies for building
RUN apk add --no-cache musl-dev git

# Install TurboProp
RUN cargo install turboprop --version latest

FROM alpine:latest

# Install runtime dependencies
RUN apk add --no-cache git ca-certificates

# Create non-root user for security
RUN addgroup -g 1000 turboprop && \
    adduser -D -s /bin/sh -u 1000 -G turboprop turboprop

# Copy binary and set ownership
COPY --from=builder /usr/local/cargo/bin/tp /usr/local/bin/tp
RUN chown turboprop:turboprop /usr/local/bin/tp

# Switch to non-root user
USER turboprop
WORKDIR /workspace

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
  CMD tp --version || exit 1

# Expose port for HTTP API (if enabled)
EXPOSE 3000

# Run MCP server
ENTRYPOINT ["tp", "mcp"]
CMD ["--repo", "/workspace", "--verbose"]
```

#### Kubernetes Deployment

**turboprop-mcp-deployment.yaml**:

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: turboprop-mcp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: turboprop-mcp
  template:
    metadata:
      labels:
        app: turboprop-mcp
    spec:
      containers:
      - name: turboprop-mcp
        image: your-registry/turboprop-mcp:latest
        ports:
        - containerPort: 3000
        env:
        - name: RUST_LOG
          value: "info"
        - name: TURBOPROP_CACHE_DIR
          value: "/cache"
        volumeMounts:
        - name: source-code
          mountPath: /workspace
          readOnly: true
        - name: cache-volume
          mountPath: /cache
        resources:
          requests:
            memory: "256Mi"
            cpu: "200m"
          limits:
            memory: "512Mi"
            cpu: "500m"
        livenessProbe:
          exec:
            command:
            - tp
            - --version
          initialDelaySeconds: 30
          periodSeconds: 30
      volumes:
      - name: source-code
        persistentVolumeClaim:
          claimName: source-code-pvc
      - name: cache-volume
        emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: turboprop-mcp-service
spec:
  selector:
    app: turboprop-mcp
  ports:
  - protocol: TCP
    port: 3000
    targetPort: 3000
```

**Deploy to Kubernetes**:

```bash
# Apply the deployment
kubectl apply -f turboprop-mcp-deployment.yaml

# Check status
kubectl get pods -l app=turboprop-mcp

# View logs
kubectl logs -l app=turboprop-mcp -f
```

#### Docker Environment Tips

**Performance Optimization**:

```bash
# Use bind mounts for better I/O performance
docker run -it --rm \
  --mount type=bind,source="$(pwd)",target=/workspace,readonly \
  --mount type=volume,source=turboprop-cache,target=/root/.turboprop-cache \
  turboprop-mcp

# Allocate more memory for large repositories
docker run -it --rm \
  --memory=2g \
  --cpus=2 \
  -v "$(pwd):/workspace" \
  turboprop-mcp tp mcp --repo /workspace --max-filesize 10mb
```

**Development Workflow**:

```bash
# Create a development alias
alias turboprop-dev='docker run -it --rm -v "$(pwd):/workspace" turboprop-mcp'

# Use in any project
cd /path/to/your/project
turboprop-dev tp mcp --repo /workspace
```

**Multi-Project Setup**:

```bash
# Run multiple instances for different projects
docker run -d --name project1-mcp \
  -v "/path/to/project1:/workspace" \
  turboprop-mcp

docker run -d --name project2-mcp \
  -v "/path/to/project2:/workspace" \
  turboprop-mcp tp mcp --repo /workspace --model all-MiniLM-L12-v2
```

### CI/CD Pipeline Integration

Integrate TurboProp indexing and search capabilities into your continuous integration workflows.

#### GitHub Actions

**Basic CI Pipeline** (`.github/workflows/turboprop-ci.yml`):

```yaml
name: TurboProp CI Integration

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main ]

jobs:
  turboprop-analysis:
    runs-on: ubuntu-latest
    
    steps:
    - name: Checkout code
      uses: actions/checkout@v4
      with:
        fetch-depth: 0  # Full history for better analysis
        
    - name: Install TurboProp
      run: |
        curl -L https://github.com/your-org/turboprop/releases/latest/download/turboprop-linux-x64.tar.gz | tar xz
        sudo mv tp /usr/local/bin/
        tp --version
        
    - name: Cache TurboProp embeddings
      uses: actions/cache@v3
      with:
        path: ~/.turboprop-cache
        key: turboprop-${{ runner.os }}-${{ hashFiles('**/*.rs', '**/*.py', '**/*.js') }}
        restore-keys: |
          turboprop-${{ runner.os }}-
          
    - name: Build semantic index
      run: |
        tp index --repo . --max-filesize 5mb --verbose
        
    - name: Run code analysis
      run: |
        # Search for common code quality issues
        tp search "TODO" --limit 50 > analysis/todos.txt
        tp search "FIXME" --limit 50 > analysis/fixmes.txt
        tp search "deprecated" --limit 20 > analysis/deprecated.txt
        
        # Find security-related code
        tp search "password" --limit 10 > analysis/security-review.txt
        tp search "secret key" --limit 10 >> analysis/security-review.txt
        
    - name: Generate code insights
      run: |
        # Find test coverage gaps
        tp search "untested" --limit 30 > analysis/test-gaps.txt
        
        # Analyze error handling patterns
        tp search "error handling" --limit 20 > analysis/error-patterns.txt
        
    - name: Upload analysis artifacts
      uses: actions/upload-artifact@v3
      with:
        name: turboprop-analysis
        path: analysis/
        retention-days: 30
        
    - name: Comment on PR (if applicable)
      if: github.event_name == 'pull_request'
      uses: actions/github-script@v6
      with:
        script: |
          const fs = require('fs');
          const todoCount = fs.readFileSync('analysis/todos.txt', 'utf8').split('\n').length - 1;
          const fixmeCount = fs.readFileSync('analysis/fixmes.txt', 'utf8').split('\n').length - 1;
          
          const comment = `## 🔍 TurboProp Code Analysis
          
          - **TODO items**: ${todoCount}
          - **FIXME items**: ${fixmeCount}
          
          [View detailed analysis artifacts](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})`;
          
          github.rest.issues.createComment({
            issue_number: context.issue.number,
            owner: context.repo.owner,
            repo: context.repo.repo,
            body: comment
          });
```

**Advanced GitHub Actions** with semantic diff analysis:

```yaml
name: Semantic Code Change Analysis

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  semantic-diff:
    runs-on: ubuntu-latest
    
    steps:
    - name: Checkout PR head
      uses: actions/checkout@v4
      with:
        ref: ${{ github.event.pull_request.head.sha }}
        
    - name: Checkout PR base
      uses: actions/checkout@v4
      with:
        ref: ${{ github.event.pull_request.base.sha }}
        path: base-branch
        
    - name: Install TurboProp
      run: |
        wget https://github.com/your-org/turboprop/releases/latest/download/turboprop-linux-x64.tar.gz
        tar -xzf turboprop-linux-x64.tar.gz
        sudo mv tp /usr/local/bin/
        
    - name: Index both versions
      run: |
        # Index current PR
        tp index --repo . --output-dir .turboprop-head
        
        # Index base branch
        cd base-branch
        tp index --repo . --output-dir ../.turboprop-base
        cd ..
        
    - name: Semantic change detection
      run: |
        # Find functions that changed semantically
        tp search "function" --repo . --index-dir .turboprop-head > head-functions.txt
        tp search "function" --repo base-branch --index-dir .turboprop-base > base-functions.txt
        
        # Compare and generate insights
        python scripts/compare-semantic-changes.py head-functions.txt base-functions.txt > semantic-diff-report.md
        
    - name: Post semantic diff report
      uses: actions/github-script@v6
      with:
        script: |
          const fs = require('fs');
          const report = fs.readFileSync('semantic-diff-report.md', 'utf8');
          
          github.rest.issues.createComment({
            issue_number: context.issue.number,
            owner: context.repo.owner,
            repo: context.repo.repo,
            body: `## 🧠 Semantic Change Analysis\n\n${report}`
          });
```

#### GitLab CI

**GitLab CI Pipeline** (`.gitlab-ci.yml`):

```yaml
stages:
  - setup
  - analysis
  - report

variables:
  TURBOPROP_CACHE_DIR: ".turboprop-cache"

cache:
  paths:
    - .turboprop-cache/
    - .turboprop/

install-turboprop:
  stage: setup
  image: ubuntu:22.04
  before_script:
    - apt-get update && apt-get install -y curl wget
  script:
    - curl -L https://github.com/your-org/turboprop/releases/latest/download/turboprop-linux-x64.tar.gz | tar xz
    - mv tp /usr/local/bin/
    - tp --version
  artifacts:
    paths:
      - /usr/local/bin/tp
    expire_in: 1 hour

semantic-analysis:
  stage: analysis
  image: ubuntu:22.04
  dependencies:
    - install-turboprop
  script:
    - tp index --repo . --verbose
    
    # Code quality analysis
    - mkdir -p reports
    - tp search "TODO" --limit 100 --output-format json > reports/todos.json
    - tp search "FIXME" --limit 50 --output-format json > reports/fixmes.json
    - tp search "hack" --limit 20 --output-format json > reports/hacks.json
    
    # Security analysis
    - tp search "password" --limit 10 --output-format json > reports/security.json
    - tp search "hardcoded" --limit 15 --output-format json >> reports/security.json
    
    # Architecture analysis
    - tp search "dependency injection" --limit 30 > reports/architecture.txt
    - tp search "design pattern" --limit 25 > reports/patterns.txt
    
  artifacts:
    paths:
      - reports/
    expire_in: 1 week
    reports:
      junit: reports/turboprop-junit.xml

merge-request-analysis:
  stage: analysis
  image: ubuntu:22.04
  dependencies:
    - install-turboprop
  only:
    - merge_requests
  script:
    # Analyze only changed files
    - git diff --name-only $CI_MERGE_REQUEST_TARGET_BRANCH_SHA HEAD > changed-files.txt
    
    # Build focused index on changed files
    - tp index --repo . --filter-file changed-files.txt --verbose
    
    # Analyze changes
    - tp search "new feature" --limit 10 > reports/new-features.txt
    - tp search "breaking change" --limit 5 > reports/breaking-changes.txt
    - tp search "performance" --limit 15 > reports/performance-impact.txt
    
  artifacts:
    paths:
      - reports/
    expire_in: 3 days

generate-report:
  stage: report
  image: python:3.9
  dependencies:
    - semantic-analysis
  script:
    - pip install jinja2 json2html
    - python scripts/generate-turboprop-report.py reports/ > turboprop-report.html
    
  artifacts:
    paths:
      - turboprop-report.html
    expire_in: 1 month
  only:
    - main
    - develop
```

#### Jenkins Pipeline

**Jenkinsfile** for TurboProp integration:

```groovy
pipeline {
    agent any
    
    environment {
        TURBOPROP_CACHE_DIR = "${WORKSPACE}/.turboprop-cache"
    }
    
    stages {
        stage('Setup') {
            steps {
                script {
                    // Install TurboProp
                    sh '''
                        if ! command -v tp &> /dev/null; then
                            curl -L https://github.com/your-org/turboprop/releases/latest/download/turboprop-linux-x64.tar.gz | tar xz
                            sudo mv tp /usr/local/bin/
                        fi
                        tp --version
                    '''
                }
            }
        }
        
        stage('Semantic Indexing') {
            steps {
                // Cache embeddings between builds
                cache(maxCacheSize: 250, caches: [
                    arbitraryFileCache(
                        path: '.turboprop-cache',
                        includes: '**/*',
                        fingerprinting: true
                    )
                ]) {
                    sh 'tp index --repo . --max-filesize 5mb --verbose'
                }
            }
        }
        
        stage('Code Analysis') {
            parallel {
                stage('Quality Analysis') {
                    steps {
                        sh '''
                            mkdir -p analysis
                            tp search "TODO" --limit 100 > analysis/todos.txt
                            tp search "FIXME" --limit 50 > analysis/fixmes.txt
                            tp search "deprecated" --limit 25 > analysis/deprecated.txt
                        '''
                    }
                }
                
                stage('Security Scan') {
                    steps {
                        sh '''
                            mkdir -p analysis
                            tp search "password" --limit 10 > analysis/security-concerns.txt
                            tp search "secret" --limit 10 >> analysis/security-concerns.txt
                            tp search "hardcoded" --limit 15 >> analysis/security-concerns.txt
                        '''
                    }
                }
                
                stage('Architecture Review') {
                    steps {
                        sh '''
                            mkdir -p analysis
                            tp search "architecture" --limit 20 > analysis/architecture.txt
                            tp search "design decision" --limit 15 > analysis/design-decisions.txt
                            tp search "technical debt" --limit 30 > analysis/tech-debt.txt
                        '''
                    }
                }
            }
        }
        
        stage('Generate Reports') {
            steps {
                script {
                    // Generate summary report
                    sh '''
                        python3 << EOF
import os
import json

def count_lines(filename):
    try:
        with open(filename, 'r') as f:
            return len([line for line in f if line.strip()])
    except:
        return 0

report = {
    "todos": count_lines("analysis/todos.txt"),
    "fixmes": count_lines("analysis/fixmes.txt"),
    "deprecated": count_lines("analysis/deprecated.txt"),
    "security_concerns": count_lines("analysis/security-concerns.txt"),
    "tech_debt": count_lines("analysis/tech-debt.txt")
}

with open("analysis/summary.json", "w") as f:
    json.dump(report, f, indent=2)

print(f"Analysis Summary:")
print(f"- TODOs: {report['todos']}")
print(f"- FIXMEs: {report['fixmes']}")  
print(f"- Deprecated: {report['deprecated']}")
print(f"- Security concerns: {report['security_concerns']}")
print(f"- Technical debt items: {report['tech_debt']}")
EOF
                    '''
                }
            }
        }
    }
    
    post {
        always {
            archiveArtifacts artifacts: 'analysis/**/*', fingerprint: true
            publishHTML([
                allowMissing: false,
                alwaysLinkToLastBuild: true,
                keepAll: true,
                reportDir: 'analysis',
                reportFiles: '*.txt,*.json',
                reportName: 'TurboProp Analysis Report'
            ])
        }
        
        success {
            echo 'TurboProp analysis completed successfully!'
        }
        
        failure {
            emailext (
                subject: "TurboProp Analysis Failed: ${env.JOB_NAME} - ${env.BUILD_NUMBER}",
                body: "The TurboProp semantic analysis failed. Check ${env.BUILD_URL} for details.",
                to: "${env.CHANGE_AUTHOR_EMAIL}"
            )
        }
    }
}
```

#### Azure DevOps Pipeline

**azure-pipelines.yml**:

```yaml
trigger:
  branches:
    include:
      - main
      - develop
      - feature/*

pool:
  vmImage: 'ubuntu-latest'

variables:
  TURBOPROP_CACHE_DIR: '$(Pipeline.Workspace)/.turboprop-cache'

stages:
- stage: Setup
  displayName: 'Setup TurboProp'
  jobs:
  - job: InstallTurboProp
    displayName: 'Install TurboProp'
    steps:
    - script: |
        curl -L https://github.com/your-org/turboprop/releases/latest/download/turboprop-linux-x64.tar.gz | tar xz
        sudo mv tp /usr/local/bin/
        tp --version
      displayName: 'Install TurboProp binary'
      
    - task: Cache@2
      inputs:
        key: 'turboprop | "$(Agent.OS)" | $(Build.SourcesDirectory)/**/*.rs'
        restoreKeys: |
          turboprop | "$(Agent.OS)"
        path: $(TURBOPROP_CACHE_DIR)
      displayName: 'Cache TurboProp embeddings'

- stage: Analysis
  displayName: 'Semantic Code Analysis'
  dependsOn: Setup
  jobs:
  - job: SemanticAnalysis
    displayName: 'Run Semantic Analysis'
    steps:
    - script: |
        tp index --repo . --max-filesize 5mb --verbose
      displayName: 'Build semantic index'
      
    - script: |
        mkdir -p $(Build.ArtifactStagingDirectory)/analysis
        
        # Code quality analysis
        tp search "TODO" --limit 100 > $(Build.ArtifactStagingDirectory)/analysis/todos.txt
        tp search "FIXME" --limit 50 > $(Build.ArtifactStagingDirectory)/analysis/fixmes.txt
        tp search "hack" --limit 25 > $(Build.ArtifactStagingDirectory)/analysis/hacks.txt
        
        # Security analysis
        tp search "password" --limit 10 > $(Build.ArtifactStagingDirectory)/analysis/security.txt
        tp search "secret" --limit 10 >> $(Build.ArtifactStagingDirectory)/analysis/security.txt
        
        # Generate summary
        echo "# TurboProp Analysis Summary" > $(Build.ArtifactStagingDirectory)/analysis/README.md
        echo "Generated on: $(date)" >> $(Build.ArtifactStagingDirectory)/analysis/README.md
        echo "" >> $(Build.ArtifactStagingDirectory)/analysis/README.md
        echo "## Statistics" >> $(Build.ArtifactStagingDirectory)/analysis/README.md
        echo "- TODOs: $(wc -l < $(Build.ArtifactStagingDirectory)/analysis/todos.txt)" >> $(Build.ArtifactStagingDirectory)/analysis/README.md
        echo "- FIXMEs: $(wc -l < $(Build.ArtifactStagingDirectory)/analysis/fixmes.txt)" >> $(Build.ArtifactStagingDirectory)/analysis/README.md
        echo "- Security concerns: $(wc -l < $(Build.ArtifactStagingDirectory)/analysis/security.txt)" >> $(Build.ArtifactStagingDirectory)/analysis/README.md
      displayName: 'Run semantic code analysis'
      
    - task: PublishBuildArtifacts@1
      inputs:
        pathToPublish: '$(Build.ArtifactStagingDirectory)/analysis'
        artifactName: 'turboprop-analysis'
        publishLocation: 'Container'
      displayName: 'Publish analysis artifacts'

- stage: Report
  displayName: 'Generate Reports'
  dependsOn: Analysis
  condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
  jobs:
  - job: GenerateReport
    displayName: 'Generate HTML Report'
    steps:
    - task: DownloadBuildArtifacts@0
      inputs:
        buildType: 'current'
        downloadType: 'single'
        artifactName: 'turboprop-analysis'
        downloadPath: '$(System.ArtifactsDirectory)'
        
    - script: |
        python3 -c "
import os
import glob

analysis_dir = '$(System.ArtifactsDirectory)/turboprop-analysis'
html_content = '''
<!DOCTYPE html>
<html>
<head>
    <title>TurboProp Analysis Report</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 40px; }
        .section { margin: 20px 0; }
        .count { font-weight: bold; color: #d73a49; }
        pre { background: #f6f8fa; padding: 15px; border-radius: 6px; overflow-x: auto; }
    </style>
</head>
<body>
    <h1>🔍 TurboProp Semantic Analysis Report</h1>
    <p>Build: $(Build.BuildNumber) | Date: $(date)</p>
'''

for filename in glob.glob(f'{analysis_dir}/*.txt'):
    name = os.path.basename(filename).replace('.txt', '').replace('-', ' ').title()
    with open(filename, 'r') as f:
        lines = [line.strip() for line in f if line.strip()]
        count = len(lines)
        
    html_content += f'''
    <div class='section'>
        <h2>{name} <span class='count'>({count} items)</span></h2>
        <details>
            <summary>View details</summary>
            <pre>{''.join(lines[:20])}</pre>
        </details>
    </div>
'''

html_content += '''
</body>
</html>
'''

with open('$(Build.ArtifactStagingDirectory)/turboprop-report.html', 'w') as f:
    f.write(html_content)
        "
      displayName: 'Generate HTML report'
      
    - task: PublishBuildArtifacts@1
      inputs:
        pathToPublish: '$(Build.ArtifactStagingDirectory)/turboprop-report.html'
        artifactName: 'turboprop-html-report'
        publishLocation: 'Container'
      displayName: 'Publish HTML report'
```

#### Integration Tips

**Best Practices for CI/CD Integration**:

1. **Caching Strategy**:
   ```bash
   # Cache embeddings based on code content hash
   cache_key="turboprop-$(find . -name '*.rs' -o -name '*.py' | xargs sha256sum | sha256sum | cut -d' ' -f1)"
   ```

2. **Incremental Analysis**:
   ```bash
   # Only analyze changed files in PRs
   git diff --name-only origin/main..HEAD | xargs tp index --files-from-stdin
   ```

3. **Parallel Processing**:
   ```bash
   # Split large repositories for parallel analysis
   tp index --repo . --worker-threads 4 --batch-size 16
   ```

4. **Quality Gates**:
   ```bash
   # Fail builds based on analysis results
   TODO_COUNT=$(tp search "TODO" --count-only)
   if [ "$TODO_COUNT" -gt 100 ]; then
     echo "Too many TODOs ($TODO_COUNT). Please address some before merging."
     exit 1
   fi
   ```

## Troubleshooting

### Quick Diagnostics (5-minute health check)

Run these commands to quickly identify issues:

```bash
# 1. Check if TurboProp is installed and accessible
tp --version

# 2. Test basic functionality
tp mcp --repo . --verbose --debug 2>debug.log &
MCP_PID=$!

# 3. Wait a moment, then check if server is running
sleep 5
ps aux | grep "tp mcp"

# 4. Stop the test server
kill $MCP_PID

# 5. Check the debug log for errors
grep -i error debug.log
```

### Troubleshooting by Symptom

#### 🚫 "My agent says MCP server not available"

**What you're seeing**:
- Agent reports "MCP server not available"
- "Connection refused" errors
- "Server timeout" messages
- Agent can't find TurboProp tool

**Diagnostic steps**:

1. **Verify server is running**:
   ```bash
   ps aux | grep "tp mcp"
   ```
   - **If nothing found**: Server isn't running, start it with `tp mcp --repo .`
   - **If found**: Server is running, check agent configuration

2. **Test server manually**:
   ```bash
   tp mcp --repo . --verbose
   ```
   - **Look for**: "MCP server ready and listening on stdio..."
   - **If error**: Fix the server startup issue first

3. **Check agent configuration**:
   - **JSON syntax**: Validate with a JSON validator
   - **Command path**: Use absolute path if needed: `"/usr/local/bin/tp"`
   - **Working directory**: Make sure `"cwd": "."` is set if needed

4. **Verify PATH**:
   ```bash
   which tp
   echo $PATH
   ```
   - **If not found**: Add TurboProp installation directory to PATH

#### 🔍 "Search returns no results" 

**What you're seeing**:
- Agent searches return empty results
- "No matches found" even for known code
- Search works but results seem irrelevant

**Diagnostic steps**:

1. **Wait for indexing to complete**:
   ```bash
   tp mcp --repo . --verbose
   ```
   - **Look for**: "Index initialization completed" message
   - **If indexing**: Wait for completion (can take 1-5 minutes)

2. **Test with known content**:
   - **Search for exact strings** that exist in your code
   - **Try broader queries**: "function" instead of "specific function name"
   - **Check different file types**: Search in files you know exist

3. **Check file filters**:
   ```bash
   tp mcp --repo . --debug 2>debug.log
   # Check debug.log for file discovery logs
   grep -i "discovered.*files" debug.log
   ```
   - **If few files discovered**: Check include/exclude patterns in `.turboprop.yml`
   - **Try without filters**: `tp mcp --repo . --force-rebuild`

4. **Verify search parameters**:
   - **Lower similarity threshold**: Try `threshold: 0.2` in config
   - **Increase result limit**: Ask agent to search with higher limits
   - **Different model**: Try `sentence-transformers/all-MiniLM-L12-v2`

#### 💾 "Server uses too much memory/CPU"

**What you're seeing**:
- Server uses > 2GB RAM
- High CPU usage (> 80%)
- System becomes slow or unresponsive
- Out of memory errors

**Diagnostic steps**:

1. **Monitor resource usage**:
   ```bash
   # Check current memory usage
   ps aux | grep "tp mcp"
   
   # Monitor over time
   while true; do
     ps -o pid,rss,vsz,pcpu,comm -p $(pgrep "tp")
     sleep 5
   done
   ```

2. **Reduce batch size** (most effective):
   ```yaml
   # .turboprop.yml
   embedding:
     batch_size: 8  # Default is 32, try 8 or 16
     worker_threads: 2  # Reduce if needed
   ```

3. **Limit file size and count**:
   ```bash
   tp mcp --repo . --max-filesize 500kb --filter "src/**/*.rs"
   ```

4. **Use restrictive patterns**:
   ```yaml
   file_discovery:
     include_patterns:
       - "src/**/*.{rs,py,js,ts}"  # Only source files
     exclude_patterns:
       - "target/**"    # Build artifacts
       - "node_modules/**"  # Dependencies
       - "**/*.log"     # Log files
       - "**/*.min.*"   # Minified files
   ```

#### ⚡ "Search is very slow"

**What you're seeing**:
- Search takes > 5 seconds to respond
- Agent seems to "hang" during searches
- High CPU usage during searches

**Diagnostic steps**:

1. **Use smaller/faster model**:
   ```bash
   tp mcp --repo . --model sentence-transformers/all-MiniLM-L6-v2
   ```

2. **Limit concurrent searches**:
   ```yaml
   # .turboprop.yml
   mcp:
     max_concurrent_searches: 3  # Default is 10
   ```

3. **Optimize queries** (advise your agent):
   - **Use specific terms**: "JWT authentication" not just "auth"
   - **Set result limits**: Ask for 5 results instead of 10+
   - **Filter by file type**: Only search `.rs` files when looking for Rust code

4. **Check system resources**:
   ```bash
   # Ensure adequate resources
   free -h  # Memory
   df -h    # Disk space
   ```

#### 📁 "Index doesn't update when I change files"

**What you're seeing**:
- Changes to code don't appear in search results
- Agent finds old versions of code
- File watching seems broken

**Diagnostic steps**:

1. **Check file watching logs**:
   ```bash
   tp mcp --repo . --debug 2>&1 | grep -i watch
   ```
   - **Look for**: "File change detected" messages
   - **If none**: File watching may be disabled or failing

2. **Test file changes**:
   - Make a simple change to a tracked file
   - Check if server logs show the change
   - Wait 1-2 seconds for index update

3. **Verify file patterns**:
   - Ensure changed files match include patterns
   - Check that files aren't excluded by exclude patterns
   - Try with minimal filters first

4. **Manual index rebuild**:
   ```bash
   tp mcp --repo . --force-rebuild
   ```

#### 🔧 "Server won't start at all"

**What you're seeing**:
- `tp mcp` command fails immediately
- Error messages about paths, permissions, or dependencies
- Server never reaches "ready" state

**Diagnostic steps**:

1. **Check repository path**:
   ```bash
   ls -la /path/to/project  # Verify path exists
   ls -ld /path/to/project  # Check permissions
   ```
   - **Use absolute paths** if relative paths fail
   - **Check permissions**: Ensure read access to directory

2. **Check file descriptor limits**:
   ```bash
   ulimit -n  # Should be > 1024
   ```
   - **If low**: Increase with `ulimit -n 4096`
   - **On macOS**: Check system limits with `launchctl limit maxfiles`

3. **Test with minimal configuration**:
   ```bash
   tp mcp --repo . --verbose  # Check detailed output
   ```
   - **Look for specific error messages**
   - **Try different repository**: Test with empty directory

4. **Check dependencies**:
   ```bash
   tp --version  # Verify installation
   rustc --version  # Check Rust installation if building from source
   ```

### Debug Mode

Enable detailed logging:

```bash
# Enable debug logging
tp mcp --repo . --debug

# Enable Rust debug logging
RUST_LOG=debug tp mcp --repo .

# Log to file (stderr only, stdout is used for MCP)
tp mcp --repo . --verbose 2> mcp-server.log
```

### Performance Issues

**Symptoms**:
- Slow search responses
- High CPU usage
- Frequent index updates

**Solutions**:
1. **Optimize file patterns**:
   ```yaml
   file_discovery:
     exclude_patterns:
       - "target/**"      # Build artifacts
       - "node_modules/**" # Dependencies
       - "*.log"          # Log files
       - "**/*.min.js"    # Minified files
   ```

2. **Adjust update settings**:
   ```yaml
   mcp:
     update_debounce_ms: 2000  # Wait longer before updates
     max_concurrent_searches: 5  # Limit concurrent operations
   ```

3. **Use appropriate model**:
   - Smaller models for faster responses
   - Larger models for better accuracy

### Getting Help

If you encounter issues not covered here:

1. **Check server logs** with `--verbose` or `--debug`
2. **Search existing issues** on GitHub
3. **Create a new issue** with:
   - TurboProp version (`tp --version`)
   - Operating system
   - Agent type and version
   - Configuration files
   - Server logs
   - Steps to reproduce

## Performance Optimization

### Repository Size Guidelines

| Repository Size | Recommended Settings |
|----------------|---------------------|
| Small (< 1k files) | Default settings |
| Medium (1k-10k files) | `batch_size: 16`, `max_filesize: "1mb"` |
| Large (10k+ files) | `batch_size: 8`, aggressive filtering, consider watchman |

### Memory Usage

Monitor memory usage and adjust:

```bash
# Monitor memory usage
ps aux | grep "tp mcp"

# Reduce memory usage
tp mcp --repo . --max-filesize 500kb --filter "src/**/*.rs"
```

### Search Performance

Optimize search performance:

1. **Set appropriate similarity thresholds**
2. **Use specific file type filters**
3. **Limit result counts**
4. **Use targeted queries**

Example optimized search parameters:
```json
{
  "query": "authentication JWT validation",
  "limit": 5,
  "threshold": 0.6,
  "filetype": ".rs",
  "filter": "src/**/*.rs"
}
```

## Best Practices

### 1. Repository Organization

- Keep code organized in clear directory structures
- Use meaningful file names and comments
- Avoid deeply nested directory structures

### 2. Configuration Management

- Use `.turboprop.yml` for project-specific settings
- Version control your configuration
- Document any special configuration requirements

### 3. Agent Integration

- Test integration with a simple query first
- Use descriptive search queries for better results
- Take advantage of file type and pattern filtering

### 4. Maintenance

- Regularly update TurboProp to get latest improvements
- Monitor server performance and adjust configuration as needed
- Keep an eye on disk usage for cache and index files

### 5. Team Usage

- Share configuration files with team members
- Document any special setup requirements
- Consider using consistent model choices across team

## FAQ

**Q: Can I run multiple MCP servers for different projects?**
A: Yes, each server operates independently. Start each with its own `--repo` path.

**Q: Does the server work with remote repositories?**
A: The server indexes local files only. Clone the repository locally first.

**Q: Can I exclude certain file types?**
A: Yes, use `exclude_patterns` in your configuration file.

**Q: How often does the index update?**
A: The server watches for file changes and updates incrementally, typically within 1-2 seconds.

**Q: What happens if I modify a file while the server is running?**
A: The server automatically detects changes and updates the relevant parts of the index.

**Q: Can I use custom models?**
A: Currently, TurboProp supports specific pre-trained models. Check the model documentation for available options.

**Q: Is there a limit to repository size?**
A: No hard limit, but performance depends on your system resources. Use filtering for very large repositories.

For more questions, see the [main TurboProp documentation](../README.md) or [file an issue](https://github.com/turboprop-org/turboprop/issues).