Skip to main content

winx_code_agent/tools/
undo_edit.rs

1//! Implementation of the `UndoEdit` tool.
2//!
3//! Reverts a file to the content it had before the last `FileWriteOrEdit` /
4//! `MultiFileEdit` in this session, using the in-memory checkpoint those tools
5//! record (see `bash_state::EditCheckpoint`). Per-file LIFO: repeated undos on
6//! one file walk its edits back. A brand-new file's creation has no prior content
7//! and is not undoable.
8
9use std::sync::Arc;
10
11use tokio::sync::Mutex;
12use tracing::instrument;
13
14use crate::errors::Result;
15use crate::state::bash_state::BashState;
16use crate::types::UndoEdit;
17
18#[instrument(level = "info", skip(bash_state_arc, undo))]
19pub async fn handle_tool_call(
20    bash_state_arc: &Arc<Mutex<Option<BashState>>>,
21    undo: UndoEdit,
22) -> Result<String> {
23    crate::tools::edit_files::handle_legacy_tool(
24        bash_state_arc,
25        crate::tools::edit_files::EditSurface::UndoEdit,
26        undo,
27    )
28    .await
29    .map(|outcome| outcome.text)
30}