@sharc-code/mcp 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +134 -0
  2. package/dist/backend-client.d.ts +251 -0
  3. package/dist/backend-client.d.ts.map +1 -0
  4. package/dist/backend-client.js +269 -0
  5. package/dist/backend-client.js.map +1 -0
  6. package/dist/backend-handlers.d.ts +243 -0
  7. package/dist/backend-handlers.d.ts.map +1 -0
  8. package/dist/backend-handlers.js +1453 -0
  9. package/dist/backend-handlers.js.map +1 -0
  10. package/dist/config.d.ts +47 -0
  11. package/dist/config.d.ts.map +1 -0
  12. package/dist/config.js +94 -0
  13. package/dist/config.js.map +1 -0
  14. package/dist/index.d.ts +3 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +344 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/project-detector.d.ts +42 -0
  19. package/dist/project-detector.d.ts.map +1 -0
  20. package/dist/project-detector.js +135 -0
  21. package/dist/project-detector.js.map +1 -0
  22. package/dist/utils/env-manager.d.ts +19 -0
  23. package/dist/utils/env-manager.d.ts.map +1 -0
  24. package/dist/utils/env-manager.js +99 -0
  25. package/dist/utils/env-manager.js.map +1 -0
  26. package/dist/utils.d.ts +10 -0
  27. package/dist/utils.d.ts.map +1 -0
  28. package/dist/utils.js +27 -0
  29. package/dist/utils.js.map +1 -0
  30. package/dist/watcher/file-watcher.d.ts +64 -0
  31. package/dist/watcher/file-watcher.d.ts.map +1 -0
  32. package/dist/watcher/file-watcher.js +263 -0
  33. package/dist/watcher/file-watcher.js.map +1 -0
  34. package/dist/watcher/incremental-indexer.d.ts +68 -0
  35. package/dist/watcher/incremental-indexer.d.ts.map +1 -0
  36. package/dist/watcher/incremental-indexer.js +254 -0
  37. package/dist/watcher/incremental-indexer.js.map +1 -0
  38. package/dist/watcher/index.d.ts +10 -0
  39. package/dist/watcher/index.d.ts.map +1 -0
  40. package/dist/watcher/index.js +10 -0
  41. package/dist/watcher/index.js.map +1 -0
  42. package/dist/watcher/processing-queue.d.ts +79 -0
  43. package/dist/watcher/processing-queue.d.ts.map +1 -0
  44. package/dist/watcher/processing-queue.js +150 -0
  45. package/dist/watcher/processing-queue.js.map +1 -0
  46. package/dist/watcher/syntax-guard.d.ts +59 -0
  47. package/dist/watcher/syntax-guard.d.ts.map +1 -0
  48. package/dist/watcher/syntax-guard.js +136 -0
  49. package/dist/watcher/syntax-guard.js.map +1 -0
  50. package/package.json +52 -0
@@ -0,0 +1,243 @@
1
+ /**
2
+ * Backend-aware Tool Handlers
3
+ * These handlers use the SHARC backend for embedding, search, and sync operations.
4
+ * File scanning and chunking still happen locally.
5
+ * Snapshot/status data is persisted in the backend database.
6
+ */
7
+ import type { ContextMcpConfig } from "./config.js";
8
+ interface ChunkTier {
9
+ name: string;
10
+ extensions: string[];
11
+ maxSize: number;
12
+ overlap: number;
13
+ useAst: boolean;
14
+ }
15
+ declare const CHUNK_TIERS: ChunkTier[];
16
+ declare function getTierForExtension(ext: string): ChunkTier;
17
+ declare const DEFAULT_FILE_EXTENSIONS: string[];
18
+ export { CHUNK_TIERS, DEFAULT_FILE_EXTENSIONS, ChunkTier, getTierForExtension };
19
+ export declare class BackendToolHandlers {
20
+ private backendClient;
21
+ private currentWorkspace;
22
+ private config;
23
+ private cachedSnapshot;
24
+ private cacheTimestamp;
25
+ private fileWatcherService;
26
+ private incrementalIndexers;
27
+ private syntaxGuard;
28
+ private splitterCache;
29
+ constructor(config: ContextMcpConfig);
30
+ /**
31
+ * Load snapshot from backend with caching
32
+ */
33
+ private getSnapshot;
34
+ /**
35
+ * Invalidate local cache to force refresh on next access
36
+ */
37
+ private invalidateCache;
38
+ /**
39
+ * Get list of indexed codebases
40
+ */
41
+ private getIndexedCodebases;
42
+ /**
43
+ * Get list of codebases currently being indexed
44
+ */
45
+ private getIndexingCodebases;
46
+ /**
47
+ * Get codebase status
48
+ */
49
+ private getCodebaseStatus;
50
+ /**
51
+ * Get complete codebase info
52
+ */
53
+ private getCodebaseInfo;
54
+ /**
55
+ * Get indexing progress for a codebase
56
+ */
57
+ private getIndexingProgress;
58
+ /**
59
+ * Set codebase to indexing status
60
+ */
61
+ private setCodebaseIndexing;
62
+ /**
63
+ * Set codebase to indexed status
64
+ */
65
+ private setCodebaseIndexed;
66
+ /**
67
+ * Set codebase to failed status
68
+ */
69
+ private setCodebaseIndexFailed;
70
+ /**
71
+ * Remove codebase from snapshot completely
72
+ */
73
+ private removeCodebaseFromSnapshot;
74
+ /**
75
+ * Generate a collection name from a codebase path
76
+ * Must match the backend's expectation (URL-safe, unique per path)
77
+ * Uses SHA-256 for better collision resistance
78
+ */
79
+ private generateCollectionName;
80
+ /**
81
+ * Sync indexed codebases from backend collections
82
+ * Compares snapshot data with actual vector collections and removes stale entries
83
+ */
84
+ private syncIndexedCodebasesFromBackend;
85
+ /**
86
+ * Initialize the file watcher service (lazy initialization)
87
+ */
88
+ private initializeFileWatcher;
89
+ /**
90
+ * Process a single file change (used by FileWatcherService)
91
+ */
92
+ private processFileChange;
93
+ /**
94
+ * Create an incremental indexer for a codebase
95
+ */
96
+ private createIncrementalIndexer;
97
+ /**
98
+ * Start watching a codebase for file changes
99
+ */
100
+ private startWatching;
101
+ /**
102
+ * Stop watching a codebase
103
+ */
104
+ private stopWatching;
105
+ /**
106
+ * Get list of watched codebases
107
+ */
108
+ getWatchedCodebases(): string[];
109
+ /**
110
+ * Check if a codebase is being watched
111
+ */
112
+ isWatching(codebasePath: string): boolean;
113
+ /**
114
+ * Graceful shutdown of all watchers and cleanup resources
115
+ */
116
+ shutdown(): Promise<void>;
117
+ /**
118
+ * Get a splitter for a given tier (cached for reuse)
119
+ */
120
+ private getSplitterForTier;
121
+ /**
122
+ * Check if a path exists (async replacement for fs.existsSync)
123
+ */
124
+ private pathExists;
125
+ /**
126
+ * Scan and chunk files from a codebase directory
127
+ * Uses async file I/O to avoid blocking the event loop
128
+ */
129
+ private scanAndChunkFiles;
130
+ private shouldIgnore;
131
+ private static readonly MAX_FILE_SIZE;
132
+ /**
133
+ * Generate SHA-256 hashes for all supported files in the codebase
134
+ */
135
+ private generateFileHashes;
136
+ /**
137
+ * Compare old and new file hashes to detect changes
138
+ */
139
+ private compareFileHashes;
140
+ /**
141
+ * Apply incremental changes to the index (Merkle diff)
142
+ * Only indexes added/modified files, deletes removed file vectors
143
+ */
144
+ private applyIncrementalChanges;
145
+ /**
146
+ * Chunk a single file using the tier strategy (helper for incremental indexing)
147
+ */
148
+ private chunkFileWithTier;
149
+ private getLanguageFromExtension;
150
+ handleIndexCodebase(args: any): Promise<{
151
+ content: {
152
+ type: string;
153
+ text: string;
154
+ }[];
155
+ isError: boolean;
156
+ } | {
157
+ content: {
158
+ type: string;
159
+ text: string;
160
+ }[];
161
+ isError?: undefined;
162
+ }>;
163
+ private startBackgroundIndexing;
164
+ handleSearchCode(args: any): Promise<{
165
+ content: {
166
+ type: string;
167
+ text: string;
168
+ }[];
169
+ isError: boolean;
170
+ } | {
171
+ content: {
172
+ type: string;
173
+ text: string;
174
+ }[];
175
+ isError?: undefined;
176
+ }>;
177
+ handleClearIndex(args: any): Promise<{
178
+ content: {
179
+ type: string;
180
+ text: string;
181
+ }[];
182
+ isError?: undefined;
183
+ } | {
184
+ content: {
185
+ type: string;
186
+ text: string;
187
+ }[];
188
+ isError: boolean;
189
+ }>;
190
+ handleGetIndexingStatus(args: any): Promise<{
191
+ content: {
192
+ type: string;
193
+ text: string;
194
+ }[];
195
+ isError: boolean;
196
+ } | {
197
+ content: {
198
+ type: string;
199
+ text: string;
200
+ }[];
201
+ isError?: undefined;
202
+ }>;
203
+ handleStartWatch(args: any): Promise<{
204
+ content: {
205
+ type: string;
206
+ text: string;
207
+ }[];
208
+ isError: boolean;
209
+ } | {
210
+ content: {
211
+ type: string;
212
+ text: string;
213
+ }[];
214
+ isError?: undefined;
215
+ }>;
216
+ handleStopWatch(args: any): Promise<{
217
+ content: {
218
+ type: string;
219
+ text: string;
220
+ }[];
221
+ isError?: undefined;
222
+ } | {
223
+ content: {
224
+ type: string;
225
+ text: string;
226
+ }[];
227
+ isError: boolean;
228
+ }>;
229
+ handleGetWatchStatus(_args: any): Promise<{
230
+ content: {
231
+ type: string;
232
+ text: string;
233
+ }[];
234
+ isError?: undefined;
235
+ } | {
236
+ content: {
237
+ type: string;
238
+ text: string;
239
+ }[];
240
+ isError: boolean;
241
+ }>;
242
+ }
243
+ //# sourceMappingURL=backend-handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend-handlers.d.ts","sourceRoot":"","sources":["../src/backend-handlers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6BH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAWpD,UAAU,SAAS;IACf,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;CACnB;AAED,QAAA,MAAM,WAAW,EAAE,SAAS,EAiC3B,CAAC;AAmBF,iBAAS,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAEnD;AAGD,QAAA,MAAM,uBAAuB,UAA+C,CAAC;AAG7E,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,SAAS,EAAE,mBAAmB,EAAE,CAAC;AAKhF,qBAAa,mBAAmB;IAC5B,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,MAAM,CAAmB;IAGjC,OAAO,CAAC,cAAc,CAAmC;IACzD,OAAO,CAAC,cAAc,CAAa;IAGnC,OAAO,CAAC,kBAAkB,CAAmC;IAC7D,OAAO,CAAC,mBAAmB,CAA8C;IACzE,OAAO,CAAC,WAAW,CAAc;IAGjC,OAAO,CAAC,aAAa,CAAmE;gBAE5E,MAAM,EAAE,gBAAgB;IAcpC;;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