Skip to content

Commit cc476dd

Browse files
authored
fix(amazonq): Normalize generated file paths in feature dev. (#5130)
The agent may generate files with or without a leading slash in the generated file path. In JetBrains, this results in an exception thrown when attempting to write to the root directory on MacOS. (Various other failure modes may occur due to lack of normalization, depending on OS.) This change normalized handling within /dev, to avoid breakage or other side effects of non-normalized file paths.
1 parent 32b4a8a commit cc476dd

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Amazon Q /dev: Fix error when accepting changes if leading slash is present."
4+
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/session/CodeGenerationState.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ private suspend fun CodeGenerationState.generateCode(
258258
fun registerNewFiles(newFileContents: Map<String, String>): List<NewFileZipInfo> =
259259
newFileContents.map {
260260
NewFileZipInfo(
261-
zipFilePath = it.key,
261+
// Note: When managing file state, we normalize file paths returned from the agent in order to ensure they are handled as relative paths.
262+
zipFilePath = it.key.removePrefix("/"),
262263
fileContent = it.value,
263264
rejected = false,
264265
changeApplied = false
@@ -268,7 +269,8 @@ fun registerNewFiles(newFileContents: Map<String, String>): List<NewFileZipInfo>
268269
fun registerDeletedFiles(deletedFiles: List<String>): List<DeletedFileInfo> =
269270
deletedFiles.map {
270271
DeletedFileInfo(
271-
zipFilePath = it,
272+
// Note: When managing file state, we normalize file paths returned from the agent in order to ensure they are handled as relative paths.
273+
zipFilePath = it.removePrefix("/"),
272274
rejected = false,
273275
changeApplied = false
274276
)

0 commit comments

Comments
 (0)