diff --git a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx index 95361abb2..45faf550a 100644 --- a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx +++ b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx @@ -94,11 +94,21 @@ export default function StepContainerPreToolbar( return; } - const fileUri = await inferResolvedUriFromRelativePath( + let fileUri = await inferResolvedUriFromRelativePath( props.relativeFilepath, ideMessenger.ide, ); + // Sometimes the model will decide to only output the base name + // in which case we shouldn't create a new file if it matches the current file + const exists = await ideMessenger.ide.fileExists(fileUri); + if (!exists) { + const activeFile = await ideMessenger.ide.getCurrentFile(); + if (activeFile && activeFile.path.endsWith(props.relativeFilepath)) { + fileUri = activeFile.path; + } + } + ideMessenger.post("applyToFile", { streamId: streamIdRef.current, filepath: fileUri,