Skip to content

Conversation

@cannuri
Copy link
Contributor

@cannuri cannuri commented May 1, 2025

Context

Closes #2931.

This PR introduces a way to escape @ symbols in text inputs, allowing users to pass CLI-style arguments like @/foo literally without triggering file content expansion.

Many command-line tools (e.g., gcc, rsync, curl, dotnet, protoc, etc.) use @/file.txt as a common syntax to read arguments from a file. However, in our system, the @ symbol triggers immediate interpolation and file inclusion. This behavior breaks standard CLI usage and prevents passing such strings directly into tasks or subtasks.

The change allows prefixing the @ symbol with a backslash (\@) to bypass the mention system and pass the input unaltered.

Additionally, when such escaped mentions are passed from a parent task (e.g., orchestrator) to a subtask via the new_task tool, the escaping is correctly handled hierarchically. Each subtask level removes one layer of escaping, enabling correct mention behavior at the intended depth.

Implementation

  1. Mention Parsing (src/shared/context-mentions.ts)

    • The mention parser now includes a negative lookbehind (?<!\\) in the regex to ignore escaped @ symbols.
    • Tests updated to confirm that \@foo is ignored and \\@foo is interpreted as @foo.
  2. Subtask Unescaping (src/core/tools/newTaskTool.ts)

    • In newTaskTool, \\@ is converted to \@ before initializing the subtask.
    • This ensures each subtask layer peels off one escape level, preserving intended mentions.
  3. Tests (src/core/tools/__tests__/newTaskTool.test.ts)

    • Added tests to verify correct behavior with one or more levels of escaping (\@, \\@, \\\\@).
    • Confirms proper transformation and message integrity across nested tasks.

How to Test

Example 1:
Prompt: Return the content of \@/file.txt

  • Result: The file is not expanded directly. Roo uses read_file to load it.

Example 2:
Prompt: Create a new task for code mode and return the content of \@/file.txt

  • Result: The parent task skips mention expansion. The subtask receives @/file.txt and resolves it.

Important

Enhances context mention handling by allowing escaping with backslashes and supports hierarchical un-escaping in subtasks.

  • Behavior:
    • Allows escaping of context mentions by prefixing with \ in context-mentions.ts.
    • Hierarchical un-escaping in newTaskTool for subtasks, removing one level of escaping per subtask.
  • Regex:
    • Modified mentionRegex in context-mentions.ts to include negative lookbehind (?<!\\) to ignore escaped mentions.
  • Testing:
    • Added tests in context-mentions.test.ts for escaped mentions.
    • Added tests in newTaskTool.test.ts for hierarchical un-escaping logic.
  • Misc:
    • Updated newTaskTool to process messages with hierarchical un-escaping before task initialization.

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

@cannuri cannuri requested review from cte and mrubens as code owners May 1, 2025 08:32
@changeset-bot
Copy link

changeset-bot bot commented May 1, 2025

⚠️ No Changeset found

Latest commit: 46623124bdb2582682d2efab13ff33866f339b8d

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

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 1, 2025
@dosubot dosubot bot added the enhancement New feature or request label May 1, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding additional tests for error handling scenarios such as missing mode or message, invalid mode, and approval denial. This would improve test coverage and ensure robust error handling as per our standards.

This comment was generated because it violated the following rules: mrule_oAUXVfj5l9XxF01R and mrule_OR1S8PRRHcvbdFib.

@hannesrudolph hannesrudolph moved this from New to PR [Pre Approval Review] in Roo Code Roadmap May 1, 2025
@hannesrudolph hannesrudolph moved this from PR [Pre Approval Review] to PR [Greenlit] in Roo Code Roadmap May 5, 2025
@KJ7LNW
Copy link
Contributor

KJ7LNW commented May 12, 2025

does it remove the \ after processing the input?

\@foo must reach the model as @foo
\\@foo must reach the model as \@foo
\\\@foo must reach the model as \\@foo

etc.

@cannuri
Copy link
Contributor Author

cannuri commented May 12, 2025

does it remove the \ after processing the input?

\@foo must reach the model as @foo \\@foo must reach the model as \@foo \\\@foo must reach the model as \\@foo

etc.

it reaches the subtask with one \ subtracted

@hannesrudolph hannesrudolph moved this from New to PR [Greenlit] in Roo Code Roadmap May 20, 2025
@hannesrudolph hannesrudolph moved this from TEMP to Needs Preliminary Review in Roo Code Roadmap May 27, 2025
@daniel-lxs daniel-lxs added PR - Needs Preliminary Review Issue - Needs Approval Ready to move forward, but waiting on maintainer or team sign-off. PR - Needs Review and removed Issue - Needs Approval Ready to move forward, but waiting on maintainer or team sign-off. labels May 27, 2025
@daniel-lxs daniel-lxs moved this from Needs Preliminary Review to PR [Needs Review] in Roo Code Roadmap May 27, 2025
@daniel-lxs daniel-lxs added the documentation Improvements or additions to documentation label May 27, 2025
@hannesrudolph
Copy link
Collaborator

@cannuri
This PR acts as a band-aid and doesn’t address the underlying issue. The root cause is properly resolved by PR #3086. Closing this one in favor of that fix. Thanks for your effort here!

@github-project-automation github-project-automation bot moved this from PR [Greenlit] to Done in Roo Code Roadmap May 28, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap May 28, 2025
@KJ7LNW
Copy link
Contributor

KJ7LNW commented May 28, 2025

@cannuri This PR acts as a band-aid and doesn’t address the underlying issue. The root cause is properly resolved by PR #3086. Closing this one in favor of that fix. Thanks for your effort here!

I think you are missing something that this also fixes:

currently it is impossible to pass the following text directly to a model @foo which is especially important when users need to instruct the model to create mentions in things like pull requests and other purposes.

This PR is nice and simple and allows recursive escaping \@/foo ... \\@/foo ... \\\@/foo

I am fine with what #3086 does (I just reviewed it and I like it), but this pull request is fundamentally about making sure we do not prevent certain kinds of input from being passed to the model.

@KJ7LNW
Copy link
Contributor

KJ7LNW commented May 28, 2025

@hannesrudolph, please see the previous message: I am going to reopen this so it does not get lost.

if there have been recent changes and you really can not pass things like @/foo to a model without unexpected interpetation, then this could be closed but I do not believe that is the case.

@cannuri
Copy link
Contributor Author

cannuri commented May 31, 2025

Yes, documentation shouldn't be forgotten. Maybe add it to the Tips & Tricks section.
We could also add a Escape-Button to the popup when you type "@".

both of those are great ideas

Glad you like it. So is that decided then? @hannesrudolph fine for you?

@hannesrudolph
Copy link
Collaborator

Yes

@cannuri
Copy link
Contributor Author

cannuri commented Jun 3, 2025

@daniel-lxs I noticed that all the options in the menu (when typing @) are hard coded english strings. Shall I translate them on the way? or shall I hard code the new option as well?

@cannuri cannuri force-pushed the escape_context_mentions branch from 4662312 to 7cc9efe Compare June 3, 2025 18:54
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jun 3, 2025
cannuri added 2 commits June 3, 2025 21:17
Implements a new escape option in the context menu that allows users to escape @ symbols by converting them to \@ when they want to prevent mention expansion.

Key changes:
- Add Escape option type to ContextMenuOptionType enum
- Implement escape functionality in insertMention() utility function
- Add escape option rendering in ContextMenu component
- Handle escape selection in ChatTextArea component

The escape option appears at the bottom of context menus when @ symbols are present and converts @ to \@ with proper cursor positioning.
@cannuri cannuri force-pushed the escape_context_mentions branch from d331068 to a03f34b Compare June 3, 2025 19:19
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jun 3, 2025
@daniel-lxs
Copy link
Member

@cannuri

Do you think it would be too much work to create an issue and PR to translate them?
And maybe have that merged before this? If it is, then I think you can just hard code them like the rest for now.

@cannuri
Copy link
Contributor Author

cannuri commented Jun 3, 2025

@cannuri

Do you think it would be too much work to create an issue and PR to translate them? And maybe have that merged before this? If it is, then I think you can just hard code them like the rest for now.

@daniel-lxs Can do, but I would suggest to get this one merged first, no?

@mrubens
Copy link
Collaborator

mrubens commented Jun 4, 2025

Is the failing test legit?

@mrubens mrubens moved this from PR [Needs Review] to PR [Needs Prelim Review] in Roo Code Roadmap Jun 4, 2025
@hannesrudolph
Copy link
Collaborator

Yes

I thought you were just asking me if the overall PR was given the green light. The change to the UI blurs concerns and is not good practice as it strays from the original issue this was approved based off of.

@hannesrudolph hannesrudolph marked this pull request as draft June 4, 2025 21:59
@hannesrudolph hannesrudolph moved this from PR [Needs Prelim Review] to PR [Draft / In Progress] in Roo Code Roadmap Jun 4, 2025
@KJ7LNW
Copy link
Contributor

KJ7LNW commented Jun 5, 2025

As requested by @hannesrudolph, I have split off the core functionality for escaping context mentions into a separate PR #4362, which focuses solely on implementing the escaping mechanism without UI changes.

@cannuri, would you please create a new issue and pull request for the UI changes?

Closed by #4362 pending new issue+pr for UI.

@KJ7LNW KJ7LNW closed this Jun 5, 2025
@github-project-automation github-project-automation bot moved this from PR [Draft / In Progress] to Done in Roo Code Roadmap Jun 5, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jun 5, 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 PR - Draft / In Progress size:L This PR changes 100-499 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

6 participants