Skip to content

Create a new tool that allows "edit then execute" #7607

@DayuanJiang

Description

@DayuanJiang

What specific problem does this solve?

Many common development and operations tasks involve a two-step process:

  1. creating or modifying: a script or configuration file
  2. executing a command to run or apply that file.

For example, creating a test file and running the test suite, patching a configuration and restarting a service, or adding a new function to a script and then executing it.

Currently, Roo Code handles this by making two separate tool calls: one to an edit tool (write_to_file, insert_content, etc.) and a subsequent one to execute_command. This approach introduces significant inefficiencies.

Additional context (optional)

No response

Roo Code Task Links (Optional)

No response

Request checklist

  • I've searched existing Issues and Discussions for duplicates
  • This describes a specific problem with clear impact and context

Interested in implementing this?

  • Yes, I'd like to help implement this feature

Implementation requirements

  • I understand this needs approval before implementation begins

How should this be solved? (REQUIRED if contributing, optional otherwise)

I propose creating a new composite tool named edit_and_execute. Instead of being a simple tool, it will act as a wrapper that accepts two structured arguments: an edit operation and an execute operation. This provides maximum flexibility by allowing any of the existing file editing tools to be paired with a command.

The agent will format its call as a nested structure, for example:

<tool_code>
<edit_and_execute>
    <edit>
        <search_and_replace>
            <path>config/settings.py</path>
            <search_pattern>DEBUG = True</search_pattern>
            <replace_pattern>DEBUG = False</replace_pattern>
        </search_and_replace>
    </edit>
    <execute>
        <execute_command>
            <command>./manage.py runserver</command>
        </execute_command>
    </execute>
</edit_and_execute>
</tool_code>

Execution Flow: edit the file based on the content inside <edit> block and then run the comand inside execute block.

Critical Error Handling: If the file edit operation fails (e.g., file not found, permission denied), the tool immediately stops and returns an error message detailing the failure. The <execute> command is not attempted.

How will we know it works? (Acceptance Criteria - REQUIRED if contributing, optional otherwise)

Given a task to create and run a shell script.
When the agent calls edit_and_execute with an inner <write_to_file> (path='run.sh', content='echo "OK"') and an inner <execute_command> (command='bash run.sh').
Then a file named run.sh is created with the correct content.
And the command bash run.sh is executed.
And the tool returns a result with stdout: "OK\n" and exit_code: 0.

(The same for other edit tools)

Technical considerations (REQUIRED if contributing, optional otherwise)

This tool should be a thin composition layer. It must delegate the actual work to the existing, battle-tested internal logic for write_to_file, search_and_replace, and execute_command. This minimizes new code and ensures consistent behavior.

Trade-offs and risks (REQUIRED if contributing, optional otherwise)

Alternative 1:

  • A general sequential task tool. I considered a tool that could execute an arbitrary list of other tools in sequence (e.g., <sequence><tool1/><tool2/><tool3/></sequence>).
  • risk: This is too powerful and prone to abuse. It dramatically increases the chances of complex, hard-to-debug failures.

Alternative 2:

  • Modify existing edit tools. I could have added an optional execute_after_edit parameter to write_to_file, insert_content, etc.
  • risk: This would create significant complexity and API pollution across multiple tools.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue/PR - TriageNew issue. Needs quick review to confirm validity and assign labels.enhancementNew feature or requestfeature requestFeature request, not a bugproposal

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions