feat: add newline at end of file writes (#2221)
This commit is contained in:
@@ -753,21 +753,27 @@ impl DeveloperRouter {
|
|||||||
file_text: &str,
|
file_text: &str,
|
||||||
) -> Result<Vec<Content>, ToolError> {
|
) -> Result<Vec<Content>, ToolError> {
|
||||||
// Normalize line endings based on platform
|
// Normalize line endings based on platform
|
||||||
let normalized_text = normalize_line_endings(file_text);
|
let mut normalized_text = normalize_line_endings(file_text); // Make mutable
|
||||||
|
|
||||||
|
// Ensure the text ends with a newline
|
||||||
|
if !normalized_text.ends_with('\n') {
|
||||||
|
normalized_text.push('\n');
|
||||||
|
}
|
||||||
|
|
||||||
// Write to the file
|
// Write to the file
|
||||||
std::fs::write(path, normalized_text)
|
std::fs::write(path, &normalized_text) // Write the potentially modified text
|
||||||
.map_err(|e| ToolError::ExecutionError(format!("Failed to write file: {}", e)))?;
|
.map_err(|e| ToolError::ExecutionError(format!("Failed to write file: {}", e)))?;
|
||||||
|
|
||||||
// Try to detect the language from the file extension
|
// Try to detect the language from the file extension
|
||||||
let language = lang::get_language_identifier(path);
|
let language = lang::get_language_identifier(path);
|
||||||
|
|
||||||
// The assistant output does not show the file again because the content is already in the tool request
|
// The assistant output does not show the file again because the content is already in the tool request
|
||||||
// but we do show it to the user here
|
// but we do show it to the user here, using the final written content
|
||||||
Ok(vec![
|
Ok(vec![
|
||||||
Content::text(format!("Successfully wrote to {}", path.display()))
|
Content::text(format!("Successfully wrote to {}", path.display()))
|
||||||
.with_audience(vec![Role::Assistant]),
|
.with_audience(vec![Role::Assistant]),
|
||||||
Content::text(formatdoc! {r#"
|
Content::text(formatdoc! {
|
||||||
|
r#"
|
||||||
### {path}
|
### {path}
|
||||||
```{language}
|
```{language}
|
||||||
{content}
|
{content}
|
||||||
@@ -775,7 +781,7 @@ impl DeveloperRouter {
|
|||||||
"#,
|
"#,
|
||||||
path=path.display(),
|
path=path.display(),
|
||||||
language=language,
|
language=language,
|
||||||
content=file_text,
|
content=&normalized_text // Use the final normalized_text for user feedback
|
||||||
})
|
})
|
||||||
.with_audience(vec![Role::User])
|
.with_audience(vec![Role::User])
|
||||||
.with_priority(0.2),
|
.with_priority(0.2),
|
||||||
|
|||||||
Reference in New Issue
Block a user