Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented May 1, 2025

Add File Attachment Capability to new_task Tool

Closes: #2931

This PR introduces a new parameter to the new_task tool, enabling the parent agent to attach files by mimicking how users reference files in tasks.

Context

This enhancement adds a <files> parameter to the new_task tool. Files specified in this parameter will be processed using the same logic as the read_file function, including:

  • Application of the maximum line limit constraint
  • Inclusion of line numbers in file contents
  • Support for specifying line ranges using the format path:startLine:endLine

Purpose:

This allows tasks to be created with immediately available file context, which:

  • Avoids redundant file read requests from child agents
  • Reduces token consumption from sequential file operations
  • Encourages explicit file inclusion in task definitions
  • Improves overall task execution efficiency

Implementation Details

  1. File Specification Format:

    • Basic format: <file>path/to/file.ts</file>
    • With line range: <file>path/to/file.ts:10:50</file> (lines 10-50)
  2. Backend Changes:

    • Added AttachedFileSpec interface in shared/tools.ts
    • Enhanced newTaskTool.ts to parse file paths and extract line ranges
    • Updated ClineProvider.ts to pass file specifications to the Cline constructor
    • Refactored Cline.ts to process attached files with line ranges and format them appropriately in the initial prompt
  3. UI Enhancements:

    • Updated ChatRow.tsx to display attached files as badges within the task content block
    • Added support for showing line ranges in the badges (e.g., @filename:10-50)
    • Clicking the badge opens the file with a selection of the line range if specified
  4. Documentation:

    • Updated the tool description in new-task.ts to explain the new syntax and provide examples

Visual Comparison

Before: New tasks required the child agent to explicitly request files, leading to redundant operations and token usage.

image

After: Files are immediately available to the child agent, with badges showing attached files:

  • @filename for full files
  • @filename:10-50 for files with line ranges

image
image

Testing Protocol

  1. Basic Functionality:

    • Create a new task with a single attached file
    • Create a new task with multiple attached files
    • Verify files appear in the initial context of the child agent
  2. Line Range Testing:

    • Attach a file with a specific line range (e.g., src/core/Cline.ts:580:600)
    • Verify only the specified lines are included in the context
    • Test edge cases (start line > end line, line numbers beyond file length)
  3. UI Verification:

    • Confirm file badges appear correctly in the task approval message
    • Verify line ranges are displayed properly in the badges
    • Check that badges are displayed side-by-side in a flex container
    • Click on the badges to confirm the file opens correctly
  4. Error Handling:

    • Test with non-existent files
    • Test with invalid line ranges
    • Verify appropriate error messages are shown

Important

This PR adds file attachment capability with line range specifications to the new_task tool, updating backend processing and UI display.

  • Behavior:
    • Adds <files> parameter to new_task tool for attaching files with optional line ranges.
    • Files processed using read_file logic, including line limits and line numbers.
  • Backend Changes:
    • Introduces AttachedFileSpec interface in shared/tools.ts.
    • Updates newTaskTool.ts to parse and handle file paths and line ranges.
    • Modifies ClineProvider.ts to pass file specifications to Cline.
    • Refactors Cline.ts to format attached files for task prompts.
  • UI Enhancements:
    • Updates ChatRow.tsx to display attached files as badges with line ranges.
    • Clicking badges opens files with specified line selections.
  • Documentation:
    • Updates new-task.ts to include new syntax and examples for file attachments.

This description was created by Ellipsis for d5a1d4af904060bdb8e5bce3075e3acdf9740847. You can customize this summary. It will automatically update as commits are pushed.

@changeset-bot
Copy link

changeset-bot bot commented May 1, 2025

⚠️ No Changeset found

Latest commit: 6b9865ffffe1b095fc01c6af88dd067a30d910f2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@daniel-lxs daniel-lxs changed the title feat: add new param to the new_task tool to allow files to be attached by the parent Add File Attachment Capability to new_task Tool May 1, 2025
@hannesrudolph hannesrudolph moved this from New to PR [Pre Approval Review] in Roo Code Roadmap May 1, 2025
@daniel-lxs daniel-lxs marked this pull request as ready for review May 2, 2025 04:06
@daniel-lxs daniel-lxs requested review from cte and mrubens as code owners May 2, 2025 04:06
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. documentation Improvements or additions to documentation enhancement New feature or request labels May 2, 2025
@daniel-lxs
Copy link
Member Author

@cte @mrubens This test is unrelated to the feature but it still failed, it seems like a faulty test.

@adamhill
Copy link
Contributor

adamhill commented May 4, 2025

🚀

@jezweb
Copy link

jezweb commented May 5, 2025

this will be a brilliant time saver thank you

@mrubens
Copy link
Collaborator

mrubens commented May 5, 2025

We're focused on orchestrator improvements this week - @cte will be in touch about this

SmartManoj pushed a commit to SmartManoj/Raa-Code that referenced this pull request May 6, 2025
* base

* button callback

* prompt

* smol

* full truncate

* base 2

* changeset

* dup new task resp

* Update src/core/prompts/commands.ts

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

* comments

---------

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
@daniel-lxs daniel-lxs force-pushed the attach-files-new-task branch from b762aca to ac06efa Compare May 11, 2025 18:08
@daniel-lxs
Copy link
Member Author

Rebased, now it's up to date with the recent Cline.ts refactor

@hannesrudolph
Copy link
Collaborator

@mrubens @cte can we please review this tomorrow?

Copy link
Collaborator

@jr jr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea a lot.

It seems like it overlaps a lot with what readFileTool does. Is it practical to share most of that code, or are there reasons I'm not thinking of why that wouldn't work?

@daniel-lxs
Copy link
Member Author

daniel-lxs commented May 13, 2025

@jr
I agree with you, I will check if moving the read file logic makes sense in this case, it probably does.
I will definitely make the file content more like the read_file tool.

@daniel-lxs daniel-lxs force-pushed the attach-files-new-task branch from ac06efa to 37ccca4 Compare May 13, 2025 15:06
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels May 13, 2025
@daniel-lxs daniel-lxs force-pushed the attach-files-new-task branch from 38a0c3b to 6b9865f Compare May 13, 2025 22:12
@daniel-lxs
Copy link
Member Author

@jr
I refactored readFileTool.ts to extract the read file logic and put it on a shared file src/shared/fileReadUtils.ts, now this shared file works for both this new feature and the read_file tool.

I have also split the tests, now we test the file reading logic separately from the read_file tool, while keeping the same coverage from the previous tests.

@hannesrudolph hannesrudolph moved this from New to PR [Pre Approval Review] in Roo Code Roadmap May 20, 2025
@hannesrudolph hannesrudolph moved this from PR [Needs Review] to TEMP in Roo Code Roadmap May 26, 2025
@daniel-lxs daniel-lxs moved this from TEMP to PR [Needs Review] in Roo Code Roadmap May 27, 2025
@hannesrudolph hannesrudolph moved this from Needs Preliminary Review to PR [Changes Requested] in Roo Code Roadmap May 27, 2025
@hannesrudolph
Copy link
Collaborator

@daniel-lxs can you move over to experimental and fix conflicts?

@KJ7LNW
Copy link
Contributor

KJ7LNW commented May 28, 2025

@samhvw8 please review #3086 with respect to #2886:

It looks like this #3086 simply factors out processFileForReading, which may not affect #2886 at all, but I want to avoid any complications because #2886 has become quite mature.

Both PRs touch read_file and @samhvw8 (plus other users, including myself) have put a lot of testing into #2886 and it works quite well.

@daniel-lxs
Copy link
Member Author

Hey @KJ7LNW, the refactor to the read_file logic was made to unify the logic so it can be used in both places that is needed without duplicating the code.

The read_file tool unit tests were separated from the file reading logic, but I made sure to avoid modifying the tests themselves on both cases, if you see a case where a test no longer serves its original purpose please let me know.

Copy link
Contributor

@KJ7LNW KJ7LNW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I like the implementation and I think this will be very useful.

Most of my comments are about best practices and ways to minimize differences across the refactor.

Thank you for putting this together!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

processFileForReading is only used for tools, so it would be better placed in something like src/core/tools/toolHelpers.ts because fileReadUtils.ts is intended for file operations they have nothing to do with the user interface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as below, move the test to src/core/tools/__tests__

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure this function already exists somewhere else? or maybe it was just reordered?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function exists somewhere else, or maybe it was already here, but I do not understand why we see a bunch of + lines

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the stereotype need to be accessible by the user interface? if so put it in shared/ , otherwise it goes in toolHelpers.ts or maybe a file dedicated to tool structures if we do not have one yet

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably stay in readFileTool.ts and export it if you need it somewhere else.

someday functions like this will be in a tool base class to build xml without string concatenation with a proper xml builder library .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see #2886 and work with @samhvw8 so that are line range formats do not diverge; multiple range formats would probably confuse the model across tools.

Gemini and Claude have both been shown empirically tested that the following format used in #2886 works very well for the model. this is a real life example:

<read_file>
<args>
  <file>
    <path>src/core/config/__tests__/ContextProxy.test.ts</path>
    <line_range>130-140</line_range> <!-- Around line 134 -->
    <line_range>160-170</line_range> <!-- Around line 166 -->
  </file>
  <file>
    <path>src/exports/api.ts</path>
    <line_range>60-75</line_range> <!-- Around line 67 -->
  </file>
  <file>
    <path>src/exports/types.ts</path> <!-- To see RooCodeSettings definition -->
  </file>
  <file>
    <path>src/schemas/index.ts</path>
    <line_range>150-160</line_range> <!-- To see historyItemSchema definition -->
  </file>
</args>
</read_file>

standardizing XML representation will simplify it tool class refactors in the future

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where did access allowed go?

if it moved somewhere centralized, then great but I want to make sure we are not creating regressions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look like unnecessary variable rename that cause diff review bloat.

Unless there is a really good reason to rename variables let's not do that if we can avoid it, so we can tell what actually change for the pull request, and what is original .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a huge function hoist, and we need to make sure there are no hallucinations: please show the diff to a smart model (o4-high, etc) and ask it to validate that there is exactly no behavior change.

Especially, please validate around output formatting and file line endings, leading and trailing blank lines, etc, which have been validated in detail (and hopefully the tests will still enforce). If you were to look up the pull request related to XML output formatting, this was done meticulously for consistent output and help gemini with understanding things.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @KJ7LNW, the refactor to the read_file logic was made to unify the logic so it can be used in both places that is needed without duplicating the code.
The read_file tool unit tests were separated from the file reading logic, but I made sure to avoid modifying the tests themselves on both cases, if you see a case where a test no longer serves its original purpose please let me know.

If the test still pass, then hopefully it is fine. I only made this comment because I have seen models hallucinate during large code moves, so I always ask the model in a separate question showing only the diff and have it validate that the difference in behavior is identical.

It probably is identical but, I operate on the side of caution with these kinds of things.

@daniel-lxs daniel-lxs force-pushed the attach-files-new-task branch from 6b9865f to 533d9e9 Compare May 28, 2025 02:46
@daniel-lxs
Copy link
Member Author

This can potentially break power-steering and it's not something we want at the moment.

@daniel-lxs daniel-lxs closed this May 29, 2025
@github-project-automation github-project-automation bot moved this from PR [Changes Requested] to Done in Roo Code Roadmap May 29, 2025
@github-project-automation github-project-automation bot moved this from PR [Pre Approval Review] to Done in Roo Code Roadmap May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Need escape mechanism for '@' symbol to prevent unwanted file content expansion

7 participants