diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index c6b01eec34..e52a286e7a 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -1288,15 +1288,18 @@ export class Config implements McpContext, AgentLoopContext { // Initialize centralized FileDiscoveryService const discoverToolsHandle = startupProfiler.start('discover_tools'); this.getFileService(); + if (this.getCheckpointingEnabled()) { + await this.getGitService(); + } this._promptRegistry = new PromptRegistry(); this._resourceRegistry = new ResourceRegistry(); this.agentRegistry = new AgentRegistry(this); - const agentInitPromise = this.agentRegistry.initialize(); + await this.agentRegistry.initialize(); coreEvents.on(CoreEvent.AgentsRefreshed, this.onAgentsRefreshed); - this._toolRegistry = await this.createToolRegistry(agentInitPromise); + this._toolRegistry = await this.createToolRegistry(); discoverToolsHandle?.end(); this.mcpClientManager = new McpClientManager( this.clientVersion, @@ -3154,33 +3157,13 @@ export class Config implements McpContext, AgentLoopContext { ); } - async createToolRegistry( - agentInitPromise: Promise = Promise.resolve(), - ): Promise { + async createToolRegistry(): Promise { const registry = new ToolRegistry( this, this.messageBus, /* isMainRegistry= */ true, ); - // 1. Kick off concurrent background checks and external processes - const discoverAllToolsPromise = registry.discoverAllTools(); - const useRipgrepPromise = this.getUseRipgrep() - ? canUseRipgrep() - .then((res) => ({ useRipgrep: res, errorString: undefined })) - .catch((error: unknown) => ({ - useRipgrep: false, - errorString: String(error), - })) - : Promise.resolve({ useRipgrep: false, errorString: undefined }); - - // 2. Synchronize all heavy operations before registering dependent tools - const [_, rgResult] = await Promise.all([ - agentInitPromise, - useRipgrepPromise, - discoverAllToolsPromise, - ]); - // helper to create & register core tools that are enabled const maybeRegister = ( toolClass: { name: string; Name?: string }, @@ -3216,17 +3199,19 @@ export class Config implements McpContext, AgentLoopContext { ); if (this.getUseRipgrep()) { - if (rgResult.useRipgrep) { + let useRipgrep = false; + let errorString: undefined | string = undefined; + try { + useRipgrep = await canUseRipgrep(); + } catch (error: unknown) { + errorString = String(error); + } + if (useRipgrep) { maybeRegister(RipGrepTool, () => registry.registerTool(new RipGrepTool(this, this.messageBus)), ); } else { - if (rgResult.errorString !== undefined) { - logRipgrepFallback( - this, - new RipgrepFallbackEvent(rgResult.errorString), - ); - } + logRipgrepFallback(this, new RipgrepFallbackEvent(errorString)); maybeRegister(GrepTool, () => registry.registerTool(new GrepTool(this, this.messageBus)), ); @@ -3306,6 +3291,7 @@ export class Config implements McpContext, AgentLoopContext { // Register Subagents as Tools this.registerSubAgentTools(registry); + await registry.discoverAllTools(); registry.sortTools(); return registry; }