pub struct EditTool { /* private fields */ }Expand description
ToolExecutor that applies an edit using whichever wire format(s) the
caller supplied, in the calling model’s preferred order.
Why: Surgical in-place edits are the primary mutation primitive for coding
agents. Supporting all three #2068 formats behind one tool keeps the
registry/schema surface simple while letting the caller (or a future
repair loop) hand the model whichever format it is more likely to succeed
with.
What: Implements ToolExecutor with name = "edit". Reads the file,
builds the present EditPayloads, calls edit_format::select_and_apply
with self.model_slug, and writes the result back.
Test: cargo test -p trusty-code -- tools::fs::edit.
Implementations§
Source§impl EditTool
impl EditTool
Sourcepub fn new(working_dir: impl Into<PathBuf>) -> Self
pub fn new(working_dir: impl Into<PathBuf>) -> Self
Construct a new EditTool scoped to working_dir.
Why: The working directory is the security boundary set at construction.
What: Stores working_dir. model_slug defaults to None, which
selects the catch-all format order (see edit_format::format_order_for);
this has no effect on a call that supplies only one format.
Test: edit_replaces_unique_match, et al.
Sourcepub fn with_model_slug(self, slug: impl Into<String>) -> Self
pub fn with_model_slug(self, slug: impl Into<String>) -> Self
Set the model slug used to look up the per-model format fallback order.
Why: The registry factory resolves the calling agent’s model slug
(provider::resolve_model) once per delegation; threading it through
here lets edit_format::select_and_apply pick the best-fit format when
a tool call supplies more than one representation of the same edit.
What: Stores slug for use in execute.
Test: edit_falls_back_to_whole_file_when_search_replace_fails.
Sourcepub fn with_mode(self, mode: HarnessMode) -> Self
pub fn with_mode(self, mode: HarnessMode) -> Self
Set the resolved HarnessMode this tool’s owning run uses (#2073).
Why: HarnessMode::Parity must score a model’s raw diff-editing
ability, unforgivingly — without this the tool always used the
per-model fallback matrix even in Parity, letting a model “pass” an
edit via SEARCH/REPLACE or whole-file without ever demonstrating a
valid diff (owner decision, 2026-07-07: this would defeat M3’s model
bake-off). Every call site that does not opt in (mode stays None)
keeps the exact pre-#2073 behaviour.
What: Stores mode for use in execute/edit_inner.
Test: edit_under_parity_mode_applies_a_valid_diff,
edit_under_parity_mode_errors_without_a_diff_payload,
edit_under_daily_driver_mode_matches_legacy_model_based_order.
Trait Implementations§
Source§impl ToolExecutor for EditTool
impl ToolExecutor for EditTool
Source§fn schema(&self) -> Value
fn schema(&self) -> Value
OpenAI function-call schema for edit.
Why: The LLM uses this schema to construct its tool call. path is the
only unconditionally required field (#2068); exactly one edit format’s
fields must also be present, validated at execution time since JSON
Schema cannot express “one of these three field groups” cleanly here.
What: JSON object with path plus the three optional per-format field
groups: old_string+new_string (SEARCH/REPLACE), diff
(unified-diff), content (whole-file).
Test: schema_requires_only_path.
Source§fn execute<'life0, 'async_trait>(
&'life0 self,
args: Value,
) -> Pin<Box<dyn Future<Output = ToolResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
args: Value,
) -> Pin<Box<dyn Future<Output = ToolResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Execute an edit tool call.
Why: Applies whichever edit format(s) the caller supplied, in the
model’s preferred order.
What: Builds an EditPayload for each format present in args
(old_string+new_string, diff, content), errors if none are
present or old_string/new_string are only partially supplied, then
calls edit_inner and converts the result into a ToolResult. On
success, best-effort fires a mid-task incremental trusty-search index
update (issue: mid-task incremental re-indexing) for the edited path so
search_code reflects the edit within the same task — this never
affects the returned ToolResult; see
trusty_common::search_index::index_files_best_effort’s fail-open
contract.
Test: edit_replaces_unique_match, edit_errors_on_zero_matches,
edit_applies_unified_diff, edit_applies_whole_file, etc.
Source§fn restricted_tiers(&self) -> &[ServiceTier]
fn restricted_tiers(&self) -> &[ServiceTier]
Auto Trait Implementations§
impl Freeze for EditTool
impl RefUnwindSafe for EditTool
impl Send for EditTool
impl Sync for EditTool
impl Unpin for EditTool
impl UnsafeUnpin for EditTool
impl UnwindSafe for EditTool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more