Skip to content

Commit be4958b

Browse files
committed
fix: fix windows path issue for memory bank
1 parent 71c1099 commit be4958b

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/context/memorybank/memoryBankController.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { Features } from '@aws/language-server-runtimes/server-interface/server'
77
import { MemoryBankPrompts } from './memoryBankPrompts'
8+
import { normalizePathFromUri } from '../../tools/mcp/mcpUtils'
89

910
const MEMORY_BANK_DIRECTORY = '.amazonq/rules/memory-bank'
1011
const MEMORY_BANK_FILES = {
@@ -60,6 +61,8 @@ export class MemoryBankController {
6061
llmCallFunction: (prompt: string) => Promise<string>
6162
): Promise<string> {
6263
try {
64+
this.features.logging.info(`Memory Bank: Starting pre-processing for workspace: "${workspaceFolderUri}"`)
65+
6366
// Step 1: Clean directory
6467
await this.cleanMemoryBankDirectory(workspaceFolderUri)
6568

@@ -116,7 +119,11 @@ export class MemoryBankController {
116119
)
117120

118121
// Step 5: Create the comprehensive prompt with ranked files and workspace path
119-
const finalPrompt = MemoryBankPrompts.getCompleteMemoryBankPrompt(rankedFilesList, workspaceFolderUri)
122+
const normalizedWorkspacePath = normalizePathFromUri(workspaceFolderUri, this.features.logging)
123+
124+
this.features.logging.info(`Memory Bank: Generating final prompt with path: "${normalizedWorkspacePath}"`)
125+
const finalPrompt = MemoryBankPrompts.getCompleteMemoryBankPrompt(rankedFilesList, normalizedWorkspacePath)
126+
this.features.logging.info(`Memory Bank: Final prompt generated : ${finalPrompt})`)
120127
return finalPrompt
121128
} catch (error) {
122129
this.features.logging.error(`Memory Bank preparation failed: ${error}`)
@@ -144,7 +151,7 @@ export class MemoryBankController {
144151
}
145152
} catch (error) {
146153
// Ignore errors when removing files that don't exist
147-
this.features.logging.debug(`Could not remove ${fileName}: ${error}`)
154+
this.features.logging.info(`Could not remove ${fileName}: ${error}`)
148155
}
149156
}
150157

@@ -169,18 +176,23 @@ export class MemoryBankController {
169176
): Promise<Array<{ path: string; size: number }>> {
170177
try {
171178
// Recursively discover all source files
172-
const workspaceFolders = this.features.workspace
173-
.getAllWorkspaceFolders()
174-
?.map(({ uri }) => new URL(uri).pathname) ?? [workspaceFolderUri]
179+
const allWorkspaceFolders = this.features.workspace.getAllWorkspaceFolders()
180+
181+
const workspaceFolders = allWorkspaceFolders?.map(({ uri }) => {
182+
return normalizePathFromUri(uri, this.features.logging)
183+
}) ?? [normalizePathFromUri(workspaceFolderUri, this.features.logging)]
175184

176185
// Collect files from all workspace folders
177186
let allSourceFiles: string[] = []
178187

179188
for (const folder of workspaceFolders) {
180189
const sourceFiles = await this.discoverSourceFiles(folder, extensions)
190+
this.features.logging.info(`Found ${sourceFiles.length} files in "${folder}"`)
181191
allSourceFiles.push(...sourceFiles)
182192
}
183193

194+
this.features.logging.info(`Total files discovered: ${allSourceFiles.length}`)
195+
184196
// OPTIMIZATION: Parallel file size calculation with batching
185197
const batchSize = 10 // Process 10 files at a time
186198
const files: Array<{ path: string; size: number }> = []
@@ -500,7 +512,6 @@ export class MemoryBankController {
500512
*/
501513
private async discoverSourceFiles(workspaceFolderUri: string, extensions: string[]): Promise<string[]> {
502514
const sourceFiles: string[] = []
503-
504515
const traverseDirectory = async (dirPath: string): Promise<void> => {
505516
try {
506517
const entries = await this.features.workspace.fs.readdir(dirPath)
@@ -524,11 +535,12 @@ export class MemoryBankController {
524535
}
525536
}
526537
} catch (error) {
527-
this.features.logging.debug(`Could not read directory ${dirPath}: ${error}`)
538+
this.features.logging.error(`Could not read directory ${dirPath}: ${error}`)
528539
}
529540
}
530541

531542
await traverseDirectory(workspaceFolderUri)
543+
532544
return sourceFiles
533545
}
534546

0 commit comments

Comments
 (0)