Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Nov 13, 2025

Summary

Refactored tool checking to eliminate code duplication by using group-based checks instead of repetitive individual tool checks.

Key Changes

  • Added getAvailableToolsInGroup() helper function to check tools by group
  • Refactored filterNativeToolsForMode() to reuse existing getToolsForMode() function
  • Simplified capabilities.ts (60% reduction in tool checking code)
  • Refactored rules.ts (56% reduction in tool checking code)
  • Removed debug console.log statements

Benefits

  • Zero code duplication - reuses getToolsForMode()
  • 60% less repetitive code in capabilities/rules
  • Single source of truth for group iteration logic
  • Follows DRY principle
  • All tests passing - 4057 tests ✅

Testing

All existing tests pass with no changes needed.


Important

Refactor tool filtering logic to use mode-based restrictions, reducing code duplication and improving maintainability across the system prompt and task modules.

  • Tool Filtering:
    • Introduced filterNativeToolsForMode() and filterMcpToolsForMode() in filter-tools-for-mode.ts to filter tools based on mode restrictions.
    • Updated getAvailableToolsInGroup() to dynamically build system prompt content based on available tools.
  • System Prompt:
    • Refactored getCapabilitiesSection() and getRulesSection() in capabilities.ts and rules.ts to use new tool filtering logic.
    • Updated system.ts to integrate new tool filtering functions.
  • Testing:
    • Added tests in filter-tools-for-mode.spec.ts and native-tools-filtering.spec.ts to verify tool filtering logic.
    • Updated existing tests in mode-aware-sections.spec.ts and sections.spec.ts to align with new filtering logic.

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

Native tools are now filtered based on mode restrictions before being sent to the API, matching the behavior of XML tools. Previously, all native tools were sent to the API regardless of mode, causing the model to attempt using disallowed tools.

Changes:
- Created filterNativeToolsForMode() and filterMcpToolsForMode() utility functions
- Extracted filtering logic from Task.ts into dedicated module
- Applied same filtering approach used for XML tools in system prompt
- Added comprehensive test coverage (10 tests)

Impact:
- Model only sees tools allowed by current mode
- No more failed tool attempts due to mode restrictions
- Consistent behavior between XML and Native protocols
- Better UX with appropriate tool suggestions per mode
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Nov 13, 2025
- Add getAvailableToolsInGroup() helper to check tools by group instead of individually
- Refactor filterNativeToolsForMode() to reuse getToolsForMode() instead of duplicating logic
- Simplify capabilities.ts by using group-based checks (60% reduction)
- Refactor rules.ts to use group helper (56% reduction)
- Remove debug console.log statements
- Update tests and snapshots

Benefits:
- Eliminates code duplication
- Leverages existing TOOL_GROUPS structure
- More maintainable - new tools in groups work automatically
- All tests passing (26/26)
@daniel-lxs daniel-lxs marked this pull request as ready for review November 14, 2025 01:09
@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Nov 14, 2025
@roomote
Copy link
Contributor

roomote bot commented Nov 14, 2025

Rooviewer Clock   See task on Roo Cloud

All issues have been resolved.

  • Add fallback when modeConfig is undefined to prevent agent from having no tools
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Nov 14, 2025
Ensures the agent always has functional tools even if:
- A custom mode is deleted while tasks still reference it
- Mode configuration becomes corrupted
- An invalid mode slug is provided

Without this fallback, the agent would have zero tools (not even
ask_followup_question or attempt_completion), completely breaking it.
@hannesrudolph hannesrudolph added PR - Needs Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Nov 14, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 14, 2025
@mrubens mrubens merged commit 2588309 into main Nov 14, 2025
15 checks passed
@mrubens mrubens deleted the fix/native-tools-mode-filtering branch November 14, 2025 01:50
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 14, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Nov 14, 2025
mini2s added a commit to zgsm-ai/costrict that referenced this pull request Nov 17, 2025