@@ -7,7 +7,7 @@ use std::{
77 } ,
88} ;
99
10- use anyhow:: { Context , Result , anyhow} ;
10+ use anyhow:: { Context , Result , anyhow, bail } ;
1111use diffy:: { PatchFormatter , create_patch} ;
1212use rmcp:: {
1313 ErrorData as McpError , ServerHandler ,
@@ -178,15 +178,15 @@ impl FsTools {
178178 } ) ;
179179
180180 if truncated && let Some ( obj) = meta. as_object_mut ( ) {
181- obj. insert ( "next_line" . to_string ( ) , json ! ( end_line. saturating_add( 1 ) ) ) ;
181+ obj. insert ( "next_line" . into ( ) , json ! ( end_line. saturating_add( 1 ) ) ) ;
182182 }
183183
184184 if truncated_by_bytes && let Some ( obj) = meta. as_object_mut ( ) {
185- obj. insert ( "max_bytes" . to_string ( ) , json ! ( MAX_READ_BYTES ) ) ;
185+ obj. insert ( "max_bytes" . into ( ) , json ! ( MAX_READ_BYTES ) ) ;
186186 }
187187
188188 let mut meta_obj = Meta :: new ( ) ;
189- meta_obj. insert ( "codex_fs_read" . to_string ( ) , meta) ;
189+ meta_obj. insert ( "codex_fs_read" . into ( ) , meta) ;
190190 let content = RawContent :: Text ( RawTextContent {
191191 text,
192192 meta : Some ( meta_obj) ,
@@ -310,9 +310,9 @@ impl ServerHandler for FsTools {
310310 protocol_version : ProtocolVersion :: default ( ) ,
311311 capabilities : caps,
312312 server_info : Implementation {
313- name : "codex-acp-fs" . to_string ( ) ,
314- title : Some ( "Codex ACP Filesystem" . to_string ( ) ) ,
315- version : env ! ( "CARGO_PKG_VERSION" ) . to_string ( ) ,
313+ name : "codex-acp-fs" . into ( ) ,
314+ title : Some ( "Codex ACP Filesystem" . into ( ) ) ,
315+ version : env ! ( "CARGO_PKG_VERSION" ) . into ( ) ,
316316 icons : None ,
317317 website_url : None ,
318318 } ,
@@ -429,7 +429,7 @@ async fn stage_edits(
429429 )
430430 } ) ?;
431431
432- staged_edits. stage ( path. to_string ( ) , write_content) . await ;
432+ staged_edits. stage ( path. to_owned ( ) , write_content) . await ;
433433 info ! ( file = %path, bytes = staged_bytes, "Staged edits committed" ) ;
434434
435435 let ( new_ranges, old_ranges) = parse_diff_line_ranges ( & diff_text) ;
@@ -440,7 +440,7 @@ async fn stage_edits(
440440 } ) ;
441441
442442 let mut meta_obj = Meta :: new ( ) ;
443- meta_obj. insert ( "codex_fs_diff" . to_string ( ) , diff_meta) ;
443+ meta_obj. insert ( "codex_fs_diff" . into ( ) , diff_meta) ;
444444 let diff_content = RawContent :: Text ( RawTextContent {
445445 text : diff_text,
446446 meta : Some ( meta_obj) ,
@@ -453,27 +453,25 @@ async fn stage_edits(
453453}
454454
455455fn apply_edits ( base : & str , edits : & [ EditInstruction ] ) -> Result < String > {
456- let mut content = base. to_string ( ) ;
456+ let mut content = base. to_owned ( ) ;
457457 for edit in edits {
458458 if edit. old_text . is_empty ( ) {
459- return Err ( anyhow ! (
460- "the provided `old_string` is empty. No edits were applied."
461- ) ) ;
459+ bail ! ( "the provided `old_string` is empty. No edits were applied." )
462460 }
463461
464462 if edit. replace_all {
465463 let replaced = content. replace ( & edit. old_text , & edit. new_text ) ;
466464 if replaced == content {
467- return Err ( anyhow ! (
465+ bail ! (
468466 "The provided `old_string` does not appear in the file. No edits were applied."
469- ) ) ;
467+ )
470468 }
471469 content = replaced;
472470 } else {
473471 let Some ( index) = content. find ( & edit. old_text ) else {
474- return Err ( anyhow ! (
472+ bail ! (
475473 "The provided `old_string` does not appear in the file. No edits were applied."
476- ) ) ;
474+ )
477475 } ;
478476 let end = index + edit. old_text . len ( ) ;
479477 content. replace_range ( index..end, & edit. new_text ) ;
0 commit comments