Skip to main content

winx_code_agent/tools/
multi_file_edit.rs

1//! Implementation of the `MultiFileEdit` tool.
2//!
3//! Applies edits across several files all-or-nothing at the COMPUTE stage: every
4//! file is validated and its new content computed in memory first (reusing
5//! `file_write_or_edit::plan_edit`), and only if ALL succeed is anything written.
6//! So a SEARCH block that fails to match in the last file leaves the earlier
7//! files untouched, instead of the half-edited tree N separate `FileWriteOrEdit`
8//! calls would leave.
9//!
10//! The write stage is a sequence of individually-atomic single-file renames
11//! (`commit_edit` -> preconditioned atomic replacement). It stops at the first I/O failure and
12//! reports which files were already written; it does NOT roll them back (each is
13//! already crash-safe on its own, and a second write pass could fail and corrupt
14//! more state).
15
16use std::sync::Arc;
17
18use tokio::sync::Mutex;
19use tracing::instrument;
20
21use crate::errors::Result;
22use crate::state::bash_state::BashState;
23use crate::types::MultiFileEdit;
24
25#[instrument(level = "info", skip(bash_state_arc, multi))]
26pub async fn handle_tool_call(
27    bash_state_arc: &Arc<Mutex<Option<BashState>>>,
28    multi: MultiFileEdit,
29) -> Result<String> {
30    crate::tools::edit_files::handle_legacy_tool(
31        bash_state_arc,
32        crate::tools::edit_files::EditSurface::MultiFileEdit,
33        multi,
34    )
35    .await
36    .map(|outcome| outcome.text)
37}