Skip to content

Commit ac91fe5

Browse files
committed
Create missing files when applying truncated edits instead of skipping them
- in 'truncated' edit format, new files are not handled correctly
1 parent da65160 commit ac91fe5

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

‎apps/editor/src/commands/apply-chat-response-command/handlers/truncated-handler.ts‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,32 @@ export const handle_truncated_edit = async (params: {
128128
}
129129

130130
if (!fs.existsSync(safe_path)) {
131-
// Cannot fill truncations for a file that doesn't exist
132-
failed_files.push(file)
133-
Logger.warn({
134-
function_name: 'handle_truncated_edit',
135-
message: 'File not found for truncated edit',
136-
data: safe_path
137-
})
131+
try {
132+
const directory = path.dirname(safe_path)
133+
if (!fs.existsSync(directory)) {
134+
await fs.promises.mkdir(directory, { recursive: true })
135+
}
136+
137+
const new_content = process_truncated_content(file.content, '')
138+
139+
await fs.promises.writeFile(safe_path, new_content, 'utf8')
140+
141+
original_states.push({
142+
file_path: file.file_path,
143+
content: '',
144+
file_state: 'new',
145+
workspace_name: file.workspace_name,
146+
ai_content: file.content,
147+
proposed_content: new_content
148+
})
149+
} catch (error: any) {
150+
Logger.error({
151+
function_name: 'handle_truncated_edit',
152+
message: 'Failed to create new file',
153+
data: { error: error.message, file_path: safe_path }
154+
})
155+
failed_files.push(file)
156+
}
138157
continue
139158
}
140159

0 commit comments

Comments
 (0)