@@ -8,6 +8,7 @@ import { CodeIndexServiceFactory } from "./service-factory"
88import { CodeIndexSearchService } from "./search-service"
99import { CodeIndexOrchestrator } from "./orchestrator"
1010import { CacheManager } from "./cache-manager"
11+ import { SembleProvider } from "./semble"
1112import { RooIgnoreController } from "../../core/ignore/RooIgnoreController"
1213import fs from "fs/promises"
1314import ignore from "ignore"
@@ -27,6 +28,7 @@ export class CodeIndexManager {
2728 private _orchestrator : CodeIndexOrchestrator | undefined
2829 private _searchService : CodeIndexSearchService | undefined
2930 private _cacheManager : CacheManager | undefined
31+ private _sembleProvider : SembleProvider | undefined
3032
3133 // Flag to prevent race conditions during error recovery
3234 private _isRecoveringFromError = false
@@ -125,6 +127,10 @@ export class CodeIndexManager {
125127 }
126128
127129 private assertInitialized ( ) {
130+ if ( this . _sembleProvider ) {
131+ // When semble is active, we don't need orchestrator/searchService
132+ return
133+ }
128134 if ( ! this . _configManager || ! this . _orchestrator || ! this . _searchService || ! this . _cacheManager ) {
129135 throw new Error ( "CodeIndexManager not initialized. Call initialize() first." )
130136 }
@@ -134,6 +140,9 @@ export class CodeIndexManager {
134140 if ( ! this . isFeatureEnabled ) {
135141 return "Standby"
136142 }
143+ if ( this . _sembleProvider ) {
144+ return this . _sembleProvider . state
145+ }
137146 this . assertInitialized ( )
138147 return this . _orchestrator ! . state
139148 }
@@ -173,6 +182,9 @@ export class CodeIndexManager {
173182 if ( this . _orchestrator ) {
174183 this . _orchestrator . stopWatcher ( )
175184 }
185+ if ( this . _sembleProvider ) {
186+ this . _sembleProvider . stopIndexing ( )
187+ }
176188 return { requiresRestart }
177189 }
178190
@@ -196,19 +208,27 @@ export class CodeIndexManager {
196208 }
197209
198210 // 6. Determine if Core Services Need Recreation
199- const needsServiceRecreation = ! this . _serviceFactory || requiresRestart
211+ const needsServiceRecreation = ( ! this . _serviceFactory && ! this . _sembleProvider ) || requiresRestart
200212
201213 if ( needsServiceRecreation ) {
202214 await this . _recreateServices ( )
203215 }
204216
205217 // 7. Handle Indexing Start/Restart
206- const shouldStartOrRestartIndexing =
207- requiresRestart ||
208- ( needsServiceRecreation && ( ! this . _orchestrator || this . _orchestrator . state !== "Indexing" ) )
218+ if ( this . _sembleProvider ) {
219+ // For semble, start indexing if needed
220+ const shouldStartIndexing = requiresRestart || needsServiceRecreation
221+ if ( shouldStartIndexing ) {
222+ await this . _sembleProvider . startIndexing ( )
223+ }
224+ } else {
225+ const shouldStartOrRestartIndexing =
226+ requiresRestart ||
227+ ( needsServiceRecreation && ( ! this . _orchestrator || this . _orchestrator . state !== "Indexing" ) )
209228
210- if ( shouldStartOrRestartIndexing ) {
211- this . _orchestrator ?. startIndexing ( )
229+ if ( shouldStartOrRestartIndexing ) {
230+ this . _orchestrator ?. startIndexing ( )
231+ }
212232 }
213233
214234 return { requiresRestart }
@@ -226,6 +246,12 @@ export class CodeIndexManager {
226246 return
227247 }
228248
249+ // Delegate to semble provider if active
250+ if ( this . _sembleProvider ) {
251+ await this . _sembleProvider . startIndexing ( )
252+ return
253+ }
254+
229255 // Check if we're in error state and recover if needed
230256 const currentStatus = this . getCurrentStatus ( )
231257 if ( currentStatus . systemStatus === "Error" ) {
@@ -244,6 +270,10 @@ export class CodeIndexManager {
244270 * Stops any in-progress indexing operation and the file watcher.
245271 */
246272 public stopIndexing ( ) : void {
273+ if ( this . _sembleProvider ) {
274+ this . _sembleProvider . stopIndexing ( )
275+ return
276+ }
247277 if ( this . _orchestrator ) {
248278 this . _orchestrator . stopIndexing ( )
249279 }
@@ -295,6 +325,7 @@ export class CodeIndexManager {
295325 this . _serviceFactory = undefined
296326 this . _orchestrator = undefined
297327 this . _searchService = undefined
328+ this . _sembleProvider = undefined
298329
299330 // Reset the flag after recovery is complete
300331 this . _isRecoveringFromError = false
@@ -306,6 +337,10 @@ export class CodeIndexManager {
306337 */
307338 public dispose ( ) : void {
308339 this . stopIndexing ( )
340+ if ( this . _sembleProvider ) {
341+ this . _sembleProvider . dispose ( )
342+ this . _sembleProvider = undefined
343+ }
309344 this . _stateManager . dispose ( )
310345 }
311346
@@ -317,6 +352,10 @@ export class CodeIndexManager {
317352 if ( ! this . isFeatureEnabled ) {
318353 return
319354 }
355+ if ( this . _sembleProvider ) {
356+ await this . _sembleProvider . clearIndexData ( )
357+ return
358+ }
320359 this . assertInitialized ( )
321360 await this . _orchestrator ! . clearIndexData ( )
322361 await this . _cacheManager ! . clearCacheFile ( )
@@ -338,6 +377,9 @@ export class CodeIndexManager {
338377 if ( ! this . isFeatureEnabled ) {
339378 return [ ]
340379 }
380+ if ( this . _sembleProvider ) {
381+ return this . _sembleProvider . searchIndex ( query , directoryPrefix )
382+ }
341383 this . assertInitialized ( )
342384 return this . _searchService ! . searchIndex ( query , directoryPrefix )
343385 }
@@ -351,11 +393,28 @@ export class CodeIndexManager {
351393 if ( this . _orchestrator ) {
352394 this . stopWatcher ( )
353395 }
396+ // Dispose existing semble provider if switching away
397+ if ( this . _sembleProvider ) {
398+ this . _sembleProvider . dispose ( )
399+ this . _sembleProvider = undefined
400+ }
354401 // Clear existing services to ensure clean state
355402 this . _orchestrator = undefined
356403 this . _searchService = undefined
357404
358- // (Re)Initialize service factory
405+ // Branch: if provider is "semble", create SembleProvider instead of external services
406+ if ( this . _configManager ! . currentEmbedderProvider === "semble" ) {
407+ this . _sembleProvider = new SembleProvider (
408+ this . workspacePath ,
409+ this . context ,
410+ this . _stateManager ,
411+ this . _configManager ! . currentSemblePath ,
412+ )
413+ await this . _sembleProvider . initialize ( )
414+ return
415+ }
416+
417+ // (Re)Initialize service factory for external providers
359418 this . _serviceFactory = new CodeIndexServiceFactory (
360419 this . _configManager ! ,
361420 this . workspacePath ,
0 commit comments