Skip to main content

EditTool

Struct EditTool 

Source
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

Source

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.

Source

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.

Source

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

Source§

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,

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. Test: edit_replaces_unique_match, edit_errors_on_zero_matches, edit_applies_unified_diff, edit_applies_whole_file, etc.

Source§

fn name(&self) -> &str

The tool’s function name as exposed to the LLM.
Source§

fn restricted_tiers(&self) -> &[ServiceTier]

Access tiers that are blocked from calling this tool. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more