aboutsummaryrefslogtreecommitdiffstats
path: root/crates/atuin-ai/src/tui/view/turn.rs
diff options
context:
space:
mode:
authorMichelle Tilley <michelle@michelletilley.net>2026-04-21 10:53:31 -0700
committerGitHub <noreply@github.com>2026-04-21 10:53:31 -0700
commit33c779aa9894e1347aeaa4c73e536cf842aee684 (patch)
treebfe0f60252518798ccf4621c7bea06021e64d2f4 /crates/atuin-ai/src/tui/view/turn.rs
parentfeat: AI tool rendering overhaul + edit_file tool (#3423) (diff)
downloadatuin-33c779aa9894e1347aeaa4c73e536cf842aee684.zip
feat: Implement write_file tool with overwrite safety (#3432)
## Summary Implements the `write_file` client-side tool — creates new files or overwrites existing ones with an explicit `overwrite` flag for safety. - **Overwrite flag**: Writing to an existing file without `overwrite: true` returns an error directing the LLM to set the flag or use `edit_file` for targeted changes. Prevents accidental overwrites. - **Snapshots**: Existing files are backed up before overwriting (same infrastructure as `edit_file`). - **Content preview**: Completed writes show the first 10 lines in gray with line numbers, plus "+ N more lines" for longer files. - **Atomic writes**: Uses `tempfile` + fsync + rename (same as `edit_file`). - **File tracker update**: After writing, the file is registered in the tracker so subsequent `edit_file` calls work without a separate read. - **Permission**: Shares the `"Write"` rule with `edit_file` — one permission covers both tools.
Diffstat (limited to 'crates/atuin-ai/src/tui/view/turn.rs')
-rw-r--r--crates/atuin-ai/src/tui/view/turn.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/crates/atuin-ai/src/tui/view/turn.rs b/crates/atuin-ai/src/tui/view/turn.rs
index 1c19a6b2..6c3d5c29 100644
--- a/crates/atuin-ai/src/tui/view/turn.rs
+++ b/crates/atuin-ai/src/tui/view/turn.rs
@@ -141,7 +141,10 @@ pub(crate) enum ToolRenderData {
preview: Option<crate::diff::EditPreview>,
},
/// File write/create operation.
- FileWrite { path: PathBuf },
+ FileWrite {
+ path: PathBuf,
+ preview: Option<crate::diff::WritePreview>,
+ },
/// Atuin history search.
HistorySearch {
query: String,
@@ -449,6 +452,7 @@ impl<'a> TurnBuilder<'a> {
},
ClientToolCall::Write(write) => ToolRenderData::FileWrite {
path: write.path.clone(),
+ preview: tracked.write_preview.clone(),
},
ClientToolCall::AtuinHistory(history) => ToolRenderData::HistorySearch {
query: history.query.clone(),