@@ -851,19 +851,77 @@ export class AgenticChatController implements ChatHandlers {
851851
852852 IdleWorkspaceManager . recordActivityTimestamp ( )
853853
854- // Memory Bank Creation Flow - Step 1: First 3 Files Only
854+ // Memory Bank Creation Flow - Delegate everything to MemoryBankController
855855 if ( this . #memoryBankController. isMemoryBankCreationRequest ( params . prompt . prompt ) ) {
856856 this . #features. logging . info ( `[Memory Bank] Detected memory bank request for tabId: ${ params . tabId } ` )
857857
858- // Step 1: Create first 3 files using standard agent analysis
859- params . prompt . prompt = this . #memoryBankController. getFirst3FilesPrompt ( )
858+ // Delegate the entire workflow to MemoryBankController
859+ const workspaceFolders = workspaceUtils . getWorkspaceFolderPaths ( this . #features. workspace )
860+ const workspaceUri = workspaceFolders . length > 0 ? workspaceFolders [ 0 ] : ''
861+ params . prompt . prompt = await this . #memoryBankController. prepareComprehensiveMemoryBankPrompt (
862+ workspaceUri ,
863+ async ( message : string ) => {
864+ await this . #features. chat . sendChatUpdate ( {
865+ tabId : params . tabId ,
866+ data : {
867+ messages : [
868+ {
869+ messageId : `memory-bank-status-${ Date . now ( ) } ` ,
870+ body : message ,
871+ } ,
872+ ] ,
873+ } ,
874+ } )
875+ } ,
876+ async ( prompt : string ) => {
877+ // Direct LLM call for ranking - no agentic loop, just a simple API call
878+ this . #features. logging . info ( `[Memory Bank] Making direct LLM call for file ranking` )
860879
861- this . #features. logging . info (
862- `[Memory Bank] Step 1: Creating first 3 memory bank files (product.md, structure.md, tech.md)`
880+ try {
881+ if ( ! this . #serviceManager) {
882+ throw new Error ( 'amazonQServiceManager is not initialized' )
883+ }
884+
885+ const client = this . #serviceManager. getStreamingClient ( )
886+
887+ // Create a simple message request for ranking
888+ const requestInput : SendMessageCommandInput = {
889+ conversationState : {
890+ chatTriggerType : ChatTriggerType . MANUAL ,
891+ currentMessage : {
892+ userInputMessage : {
893+ content : prompt ,
894+ } ,
895+ } ,
896+ } ,
897+ }
898+
899+ this . #features. logging . info ( `[Memory Bank] Sending ranking request to LLM` )
900+ const response = await client . sendMessage ( requestInput )
901+
902+ // Extract the response content from the streaming response
903+ let responseContent = ''
904+ if ( response . sendMessageResponse ) {
905+ for await ( const chatEvent of response . sendMessageResponse ) {
906+ if ( chatEvent . assistantResponseEvent ?. content ) {
907+ responseContent += chatEvent . assistantResponseEvent . content
908+ }
909+ }
910+ }
911+
912+ this . #features. logging . info (
913+ `[Memory Bank] LLM ranking response received: ${ responseContent . length } characters`
914+ )
915+ return responseContent . trim ( )
916+ } catch ( error ) {
917+ this . #features. logging . error ( `[Memory Bank] LLM ranking failed: ${ error } ` )
918+ this . #features. logging . info ( `[Memory Bank] Falling back to TF-IDF ranking` )
919+ return '' // Empty string triggers TF-IDF fallback
920+ }
921+ }
863922 )
864923
865- // Mark this session for memory bank completion detection
866- this . #markSessionForMemoryBankCompletion( params . tabId )
924+ this . #features. logging . info ( `[Memory Bank] Starting comprehensive memory bank creation` )
867925 }
868926
869927 const maybeDefaultResponse = ! params . prompt . command && getDefaultChatResponse ( params . prompt . prompt )
@@ -942,7 +1000,8 @@ export class AgenticChatController implements ChatHandlers {
9421000 const additionalContext = await this . #additionalContextProvider. getAdditionalContext (
9431001 triggerContext ,
9441002 params . tabId ,
945- params . context
1003+ params . context ,
1004+ params . prompt . prompt
9461005 )
9471006 // Add active file to context list if it's not already there
9481007 const activeFile =
@@ -4387,10 +4446,7 @@ export class AgenticChatController implements ChatHandlers {
43874446 if ( chatEvent . assistantResponseEvent || chatEvent . codeReferenceEvent ) {
43884447 await streamWriter . write ( result . data . chatResult )
43894448
4390- // Memory Bank completion detection
4391- if ( chatEvent . assistantResponseEvent && result . data . chatResult . body ) {
4392- await this . #checkMemoryBankCompletion( tabId , result . data . chatResult . body )
4393- }
4449+ // Memory Bank completion detection - removed from here to avoid timing issues
43944450 }
43954451
43964452 if ( chatEvent . toolUseEvent ) {
@@ -4418,6 +4474,8 @@ export class AgenticChatController implements ChatHandlers {
44184474 }
44194475 await streamWriter . close ( )
44204476
4477+ // No special completion detection needed - single agentic loop completes naturally
4478+
44214479 metric . mergeWith ( {
44224480 cwsprChatFullResponseLatency : metric . getTimeElapsed ( ) ,
44234481 cwsprChatFollowUpCount : chatEventParser . totalEvents . followupPromptEvent ,
@@ -4749,94 +4807,7 @@ export class AgenticChatController implements ChatHandlers {
47494807 return value
47504808 }
47514809
4752- // Memory Bank Completion Detection
4753- #memoryBankPendingSessions = new Set < string > ( )
4754-
4755- /**
4756- * Mark a session for memory bank completion detection
4757- */
4758- #markSessionForMemoryBankCompletion( tabId : string ) : void {
4759- this . #memoryBankPendingSessions. add ( tabId )
4760- this . #features. logging . info ( `[Memory Bank] Marked session ${ tabId } for completion detection` )
4761- }
4762-
4763- /**
4764- * Check if a session is pending memory bank completion
4765- */
4766- #isMemoryBankPendingCompletion( tabId : string ) : boolean {
4767- return this . #memoryBankPendingSessions. has ( tabId )
4768- }
4769-
4770- /**
4771- * Detect memory bank completion and trigger guidelines generation
4772- */
4773- async #checkMemoryBankCompletion( tabId : string , messageContent : string ) : Promise < void > {
4774- if ( ! this . #isMemoryBankPendingCompletion( tabId ) ) {
4775- return
4776- }
4777-
4778- // Check if the agent has completed creating the first 3 files
4779- const completionIndicators = [
4780- 'product.md' ,
4781- 'structure.md' ,
4782- 'tech.md' ,
4783- 'memory bank' ,
4784- 'created successfully' ,
4785- 'files have been created' ,
4786- ]
4787-
4788- const hasCompletionIndicators = completionIndicators . some ( indicator =>
4789- messageContent . toLowerCase ( ) . includes ( indicator . toLowerCase ( ) )
4790- )
4791-
4792- if ( hasCompletionIndicators ) {
4793- this . #features. logging . info ( `[Memory Bank] Step 1 completion detected for session ${ tabId } ` )
4794-
4795- // Remove from pending set
4796- this . #memoryBankPendingSessions. delete ( tabId )
4797-
4798- // Trigger Steps 2-5: Guidelines generation
4799- await this . #triggerGuidelinesGeneration( tabId )
4800- }
4801- }
4802-
4803- /**
4804- * Trigger guidelines.md generation (Steps 2-5)
4805- */
4806- async #triggerGuidelinesGeneration( tabId : string ) : Promise < void > {
4807- try {
4808- this . #features. logging . info ( `[Memory Bank] Starting guidelines generation for session ${ tabId } ` )
4810+ // Memory Bank logic moved to MemoryBankController
48094811
4810- // Get workspace folder URI - use empty string as default for root workspace
4811- const workspaceFolderUri = ''
4812-
4813- // Create LLM call function that uses the chat system
4814- const llmCallFunction = async ( prompt : string ) : Promise < string > => {
4815- // TODO: Implement actual LLM call using the chat system
4816- // For now, return a placeholder response
4817- return 'LLM response placeholder'
4818- }
4819-
4820- // Delegate all complex logic to MemoryBankController
4821- const result = await this . #memoryBankController. executeCompleteMemoryBankCreationWithLLM (
4822- workspaceFolderUri ,
4823- llmCallFunction
4824- )
4825-
4826- // Send message to chat
4827- await this . #features. chat . sendChatUpdate ( {
4828- tabId,
4829- data : {
4830- messages : [
4831- {
4832- messageId : `memory-bank-complete-${ Date . now ( ) } ` ,
4833- body : result . message ,
4834- } ,
4835- ] ,
4836- } ,
4837- } )
4838- } catch ( error ) {
4839- this . #features. logging . error ( `[Memory Bank] Error in guidelines generation: ${ error } ` )
4840- }
4841- }
4812+ // All Memory Bank methods moved to MemoryBankController and MemoryBankPrompts
48424813}
0 commit comments