8000 Add mode permissions for new_task, switch_mode and ask_followup_questions by cannuri · Pull Request #3171 · RooCodeInc/Roo-Code · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add mode permissions for new_task, switch_mode and ask_followup_questions #3171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

cannuri
Copy link
@cannuri cannuri commented May 4, 2025

Context

This PR introduces a more granular permission system for specific tools (new_task, switch_mode, ask_followup_question) and adds a mechanism (slugRegex) to restrict which modes can be targeted by new_task and switch_mode.

It is now possible to restrict a mode's ability to create subtasks, switch modes or ask followup question. Furthermore you can also define which modes are available for a subtask or for switching by defining slugRegex (just like defining fileRegex)

WHY:

  • Allows users to define more precisely how modes can interact with each other. This allows to define workflows since you can tell Code mode for example that it has to call Test mode afterwards. Also you can restrict Architect mode from switching to Coding for example.
  • Now it is possible to force Orchestrator to create a subtask instead of switching modes (as it would do that from time to time which unnecessarily bloats the context window)
  • Sometimes you don't want to be asked any followup questions but let Roo Code run on auto pilot. You can turn off follow up questions for specific modes now.
  • Aligns permissions for mode interaction tools with existing patterns like fileRegex for file editing.

Implementation

This feature was implemented by introducing new permission groups (subtask, switch, followup) in the schema and shared tool configurations. The corresponding tools (new_task, switch_mode, ask_followup_question) were moved under these groups, removing them from being always available.

The core permission checking logic in isToolAllowedForMode was updated to handle these new groups. For the subtask and switch groups, an optional slugRegex property was added to the schema (groupOptionsSchema) and the checking logic was enhanced to parse tool parameters (mode or mode_slug) and validate them against the provided regex, denying the tool use if the target mode slug doesn't match.

The Prompts UI (PromptsView.tsx) was updated to display checkboxes for the new permissions. Logic was added to interpret the slugRegex and display the names of allowed modes in the UI, formatted differently for collapsed (Names...) and expanded Allowed modes: ... views (just like "Edit Files" is styled). This required accessing the list of all available modes within the component.

Localization keys were added to prompts.json files for the new permission names and the "Allowed modes:" text. Default permissions were enabled for built-in modes. Comprehensive tests (logic, UI, schema) were added and updated throughout the process, following TDD principles where appropriate. External documentation was also updated.

Screenshots

Before
Screenshot 2025-05-05 at 00 47 39

After
Screenshot 2025-05-05 at 00 51 22

How to Test

  1. Check UI:
    • Open the Prompts settings view.
    • Select a custom mode (or create one).
    • Verify the new checkboxes "Create Subtasks", "Switch Modes", and "Ask Follow-up Questions" appear.
  2. Test slugRegex:
    • Edit the .roomodes file for a custom mode.
    • Add the subtask permission using the tuple format with a slugRegex, e.g., [ "subtask", { "slugRegex": "^(code|test)$" } ].
    • Save the file.
    • Go back to the Prompts UI and view the custom mode's details.
    • Verify Collapsed View: Check that "Create Subtasks" now shows (Code, Test) next to it.
    • Click "Edit tools".
    • Verify Expanded View: Check that Allowed modes: Code, Test appears below the "Create Subtasks" checkbox.
    • Start a chat using this custom mode.
    • Try creating a subtask:
      • Use <new_task><mode>code</mode>...</new_task>. This should succeed.
      • Use <new_task><mode>ask</mode>...</new_task>. This should fail (the tool use should be rejected by the backend based on isToolAllowedForMode).
    • Repeat the process for the switch permission and the switch_mode tool.

Get in Touch

Discord: can.nuri


Important

This PR adds a granular permission system for specific tools, updates the UI to support these changes, and includes tests and localization updates.

  • Permissions:
    • Introduces new permission groups subtask, switch, followup in schemas/index.ts.
    • Updates isToolAllowedForMode in modes.ts to handle new groups and slugRegex.
  • UI:
    • Updates PromptsView.tsx to display new permissions with checkboxes and interpret slugRegex.
    • Adds localization keys for new permissions in prompts.json files.
  • Tests:
    • Adds tests for new permissions and slugRegex logic in modes.test.ts and PromptsView.test.tsx.
  • Misc:
    • Updates toolGroups in tools.ts to include new groups.
    • Removes new_task, switch_mode, ask_followup_question from ALWAYS_AVAILABLE_TOOLS.

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

Copy link
changeset-bot bot commented May 4, 2025

⚠️ No Changeset found

Latest commit: 66fa269

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

@cannuri
Copy link
Author
cannuri commented May 4, 2025

I had to change the layout structure from a grid to a flex column to prevent layout issues.
When the "Allowed modes: ..." list become too long, it broke the styling. See:

Screenshot 2025-05-05 at 01 11 57

@cannuri cannuri marked this pull request as ready for review May 4, 2025 23:31
@cannuri cannuri requested review from mrubens and cte as code owners May 4, 2025 23:31
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. enhancement New feature or request labels May 4, 2025
"toolNames": {
"read": "Dosyaları Oku",
"edit": "Dosyaları Düzenle",
"browser": "Tarayıcı Kullan",
"command": "Komutları Çalıştır",
"mcp": "MCP Kullan"
"mcp": "MCP Kullan",
"subtask": "Alt görevler oluştur",
Copy link

Choose a reason for hiding this comment

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

For consistency with the other tool name translations (e.g., 'Dosyaları Oku', 'Dosyaları Düzenle', 'Tarayıcı Kullan', 'MCP Kullan'), consider capitalizing the first letters of each word in the newly added strings. For example, change 'Alt görevler oluştur' to 'Alt Görevler Oluştur', 'Modları değiştir' to 'Modları Değiştir', and 'Takip soruları sor' to 'Takip Soruları Sor'. This way, all similar UI labels use the same style.

Suggested change
"subtask": "Alt görevler oluştur",
"subtask": "Alt Görevler Oluştur",

@mrubens mrubens self-assigned this May 5, 2025
@hannesrudolph hannesrudolph moved this from New to PR [Greenlit] in Roo Code Roadmap May 5, 2025
{
fileRegex?: string | undefined
slugRegex?: string | undefined
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let me see if I change my mind after reading the whole diff, but I think an array of slugs might make more sense than a regex here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, still think an array of slugs would be easier to manage.

const currentMode = getCurrentMode()
const isCustomMode = findModeBySlug(visualMode, customModes)
const customMode = isCustomMode
const isGroupEnabled = isCustomMode
? customMode?.groups?.some((g) => getGroupName(g) === group)
: currentMode?.groups?.some((g) => getGroupName(g) === group)

// Check if the group should be always available and thus potentially non-editable
// For now, we allow editing all for custom modes as per test requirements
const isDisabled = !isCustomMode // || TOOL_GROUPS[group].alwaysAvailable;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const isDisabled = !isCustomMode // || TOOL_GROUPS[group].alwaysAvailable;
const isDisabled = !isCustomMode

const matchingNames = getMatchingModeNames(options.slugRegex, modes)
if (matchingNames.length > 0) {
// Format for expanded view: Allowed modes: Name1, Name2
description = `${t("prompts:tools.allowedModes")}: ${matchingNames.join(", ")}`
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should either remove the colon from the end of the translations or from here - it's showing up as a double colon currently.

Copy link
Collaborator
@mrubens mrubens left a comment

Choose a reason for hiding this comment

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

I think we also need to update the system prompt to remove the tools if they're not allowed in the mode, and probably also to tell the model which modes it can switch to / start a new task with.

"mcp": "Use MCP",
"subtask": "Create Subtasks",
"switch": "Switch Modes",
"followup": "Ask Follow-up Questions"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think "Ask Questions" is a more obvious label here

@mrubens
Copy link
Collaborator
mrubens commented May 5, 2025

I wonder if we should start by just adding the 3 new checkboxes without the allowed modes and get that solid, and then do the mode restrictions in a follow-up PR?

@cannuri
Copy link
Author
cannuri commented May 5, 2025

I wonder if we should start by just adding the 3 new checkboxes without the allowed modes and get that solid, and then do the mode restrictions in a follow-up PR?

Sure, I can take that out. Which option do you prefer? The array or to leave it out for now?

@mrubens
Copy link
Collaborator
mrubens commented May 5, 2025

I wonder if we should start by just adding the 3 new checkboxes without the allowed modes and get that solid, and then do the mode restrictions in a follow-up PR?

Sure, I can take that out. Which option do you prefer? The array or to leave it out for now?

I think leave it out for now, since I think there’s a little prompt engineering involved to make sure the model knows what it’s allowed to do

@cannuri
Copy link
Author
cannuri commented May 5, 2025

I wonder if we should start by just adding the 3 new checkboxes without the allowed modes and get that solid, and then do the mode restrictions in a follow-up PR?

Sure, I can take that out. Which option do you prefer? The array or to leave it out for now?

I think leave it out for now, since I think there’s a little prompt engineering involved to make sure the model knows what it’s allowed to do

Wouldn't be so hard to add that and I was thinking about it but decided against because file restrictions are also not mentioned in the prompt and also I tried to avoid adding more token.

Alright, will remove it.

SmartManoj pushed a commit to SmartManoj/Roo-Code that referenced this pull request May 6, 2025
* refactor to not pass message for showMcpView

* changeset
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels May 8, 2025
@cannuri
Copy link
Author
cannuri commented May 8, 2025

@mrubens please wait with your review until I give you a go

@mrubens
Copy link
Collaborator
mrubens commented May 13, 2025

How do you think we should handle backwards compatibility on this? For instance the custom orchestrators that people have written?

@daniel-lxs
Copy link
Collaborator

@cannuri @mrubens

Would it make sense to switch from a whitelist to a blacklist for available tools and migrate the custom modes as well? This approach would allow us to infer which tools the user expects to be available while also enabling users to exclude tools they don't want enabled for any mode. The UI would not require any changes.

@hannesrudolph hannesrudolph moved this from New to PR [Greenlit] in Roo Code Roadmap May 20, 2025
@cannuri
Copy link
Author
cannuri commented May 23, 2025

How do you think we should handle backwards compatibility on this? For instance the custom orchestrators that people have written?

I will have a look into that. pretty busy these days, sorry.

@cannuri
Copy link
Author
cannuri commented May 23, 2025

@cannuri @mrubens

Would it make sense to switch from a whitelist to a blacklist for available tools and migrate the custom modes as well? This approach would allow us to infer which tools the user expects to be available while also enabling users to exclude tools they don't want enabled for any mode. The UI would not require any changes.

So you mean we should extend it and allow blacklisting any available tool? Actually I would also prefer the ability to disable any tool, even read_file if someone likes to. @mrubens what do you think about that?

@daniel-lxs
Copy link
Collaborator

@cannuri
The main issue is backwards compatibility, if the user is currently expecting new_task and switch_mode to be available, then you'll have to manually add them to the available tools list by default, basically migrating the settings so nothing breaks.

@cannuri
Copy link
Author
cannuri commented May 23, 2025

@cannuri The main issue is backwards compatibility, if the user is currently expecting new_task and switch_mode to be available, then you'll have to manually add them to the available tools list by default, basically migrating the settings so nothing breaks.

Yeah get u. Therefore u meant blacklisting instead of whitelisting. But we could also auto migrate their .roomodes

@daniel-lxs daniel-lxs moved this from PR [Ready to Merge] to PR [Changes Requested] in Roo Code Roadmap May 27, 2025
@github-project-automation github-project-automation bot moved this from PR [Changes Requested] to Done in Roo Code Roadmap May 27, 2025
@github-project-automation github-project-automation bot moved this from PR [Greenlit] to Done in Roo Code Roadmap May 27, 2025
@hannesrudolph hannesrudolph reopened this May 27, 2025
@github-project-automation github-project-automation bot moved this from Done to Triage in Roo Code Roadmap May 27, 2025
@github-project-automation github-project-automation bot moved this from Done to New in Roo Code Roadmap May 27, 2025
@hannesrudolph hannesrudolph moved this from Triage to PR [Changes Requested] in Roo Code Roadmap May 27, 2025
@hannesrudolph
Copy link
Collaborator

Thanks for your patience on this PR.

We need to either land the plane on this soon or shift the discussion back to an issue to clearly agree on the scope and details before implementation. Given the time elapsed since the changes were requested, let's determine whether to wrap this up quickly or close it and revisit through our issue-first approach.

Let us know how you'd like to proceed.

@hannesrudolph hannesrudolph marked this pull request as draft May 27, 2025 18:08
@hannesrudolph hannesrudolph moved this from PR [Changes Requested] to PR [Draft / In Progress] in Roo Code Roadmap May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PR - Draft / In Progress size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
Status: PR [Draft / In Progress]
Development

Successfully merging this pull request may close these issues.

4 participants
0