Skip to content

feat: complete Phase 3b - permission control with prompt guidance and UI visibility#12339

Closed
roomote-v0[bot] wants to merge 6 commits into
mainfrom
feature/orchestrator-permissions-prompt
Closed

feat: complete Phase 3b - permission control with prompt guidance and UI visibility#12339
roomote-v0[bot] wants to merge 6 commits into
mainfrom
feature/orchestrator-permissions-prompt

Conversation

@roomote-v0
Copy link
Copy Markdown
Contributor

@roomote-v0 roomote-v0 Bot commented May 12, 2026

Related GitHub Issue

Addresses: #12330

Description

This PR is the single final PR for Phase 3b of Issue #12330, consolidating all permission control work. It supersedes #12337 (now closed) and includes everything needed for model-driven permission control for subtasks.

What this includes (from #12337 core + prompt/UI additions):

  1. TaskPermissions type (packages/types/src/task-permissions.ts): Defines four permission boundary fields:

    • filePatterns - regex patterns for allowed file paths
    • commandPatterns - regex patterns for allowed shell commands
    • allowedTools - explicit tool allowlist
    • deniedTools - explicit tool blocklist
  2. Most-restrictive-wins merging (mergeTaskPermissions): When nested subtasks are created, permissions are merged so a child can never grant itself more access than its parent.

  3. Runtime enforcement in validateToolUse(): All permission types are checked at tool execution time with clear TaskPermissionError messages.

  4. ReDoS mitigation - isSafeRegex() heuristic rejects dangerous patterns.

  5. Permission persistence - taskPermissions saved to history_item.json and restored on task reopen.

  6. Orchestrator prompt guidance - New instruction in Orchestrator mode explaining when/how to use each permission type.

  7. Permission visibility in approval UI - ChatRow shows permission boundaries when approving subtask creation.

  8. i18n translations for permission display labels.

Optional by default: When permissions is omitted from new_task, behavior is identical to today -- zero friction for normal users.

Test Procedure

  • 21 tests: Schema validation, merge logic, pattern matching (task-permissions.spec.ts)
  • 13 tests: Runtime enforcement of all permission types (taskPermissionsEnforcement.spec.ts)
  • 4 tests: Orchestrator prompt contains permissions guidance (orchestrator-permissions-prompt.spec.ts)
  • 4 tests: Permission display rendering (ChatRow.permissions.spec.tsx)
  • All existing tests continue to pass
  • Full lint and type-check pass across all packages

Pre-Submission Checklist

This PR attempts to address Issue #12330 Phase 3b. Feedback and guidance are welcome.

Interactively review PR in Roo Code Cloud

roomote added 5 commits May 12, 2026 05:30
Adds an optional `permissions` parameter to the `new_task` tool, allowing
the Orchestrator (or any parent task) to dynamically set permission
boundaries for subtasks:

- New `TaskPermissions` type with filePatterns, commandPatterns,
  allowedTools, and deniedTools
- Permission merging with most-restrictive-wins semantics for nested
  subtask delegation
- Runtime enforcement in validateToolUse() for all permission types
- Full test coverage for merging logic and enforcement

Addresses Issue #12330 (Phase 3b)
…pattern merging

1. NativeToolCallParser: Remove permissions from update_todo_list cases
   (was erroneously added to wrong tool case, should only be on new_task)

2. deniedTools: Exempt ALWAYS_AVAILABLE_TOOLS (attempt_completion, etc.)
   from deniedTools check, matching the existing allowedTools behavior.
   Prevents parent from trapping subtask by denying completion tools.

3. Pattern merging: Replace broken exact-string intersection with layered
   enforcement. filePatterns/commandPatterns from parent and child are
   kept as separate layers (AND between layers, OR within each layer).
   This correctly handles narrowing: parent ["src/.*"] + child
   ["src/components/.*"] now allows only files matching BOTH patterns,
   instead of producing an empty intersection.
…ema level, simplify validation code

1. Anchor regex patterns in matchesAnyPattern with ^(?:...)$ wrapping so
   patterns like "src/.*" require full-path matching instead of substring
   matching. Prevents "evil/src/foo" from matching a "src/.*" permission.

2. Add regex validation at schema level (regexString refinement) so
   invalid patterns are rejected at parse time rather than silently
   failing at runtime.

3. Simplify duplicate file/command pattern validation in validateToolUse
   by unifying layered and flat code paths into a single branch that
   falls back to wrapping flat patterns as a single layer.

4. Remove unused matchesAnyPattern import from validateToolUse.ts.

5. Add tests for anchoring behavior, pre-anchored patterns, and
   invalid regex rejection at schema level.
1. Persist taskPermissions in HistoryItem so permissions survive task
   restarts. Added taskPermissions field to historyItemSchema, included
   it in taskMetadata output, and restored it in the Task constructor
   when loading from history.

2. Add ReDoS mitigation for model-provided regex patterns:
   - isSafeRegex() heuristic rejects nested quantifiers like (a+)+
     and overlapping alternations in repeated groups like (a|a)+
   - Max pattern length capped at 200 characters
   - Both checks enforced at schema validation time via Zod refinements
   - 11 new tests covering ReDoS detection and persistence round-trips
- Enhance Orchestrator customInstructions with guidance on using the
  permissions parameter (filePatterns, commandPatterns, allowedTools,
  deniedTools) including example use cases and most-restrictive-wins
  semantics explanation
- Add permission boundaries display in the ChatRow newTask approval
  message so users can see what restrictions are being set before
  approving subtask creation
- Add i18n translation keys for permission display
- Add 8 new tests across packages/types and webview-ui
@roomote-v0 roomote-v0 Bot changed the title feat: Orchestrator prompt guidance for permissions and UI visibility (Phase 3b completion) feat: complete Phase 3b - permission control with prompt guidance and UI visibility May 12, 2026
@easonLiangWorldedtech
Copy link
Copy Markdown

@roomote can you pick the commit https://github.com/RooCodeInc/Roo-Code/pull/12340/commits/d74971acfe38079be58140ac4ee15724c83ad01f to fix the translation?

@roomote-v0
Copy link
Copy Markdown
Contributor Author

roomote-v0 Bot commented May 12, 2026

Fixaroo Clock   See task

Cherry-picked commit d74971a from PR #12340 to add missing i18n translations for permission boundaries and context handoff keys.

View commit | Revert commit

@roomote-v0 roomote-v0 Bot marked this pull request as ready for review May 12, 2026 08:38
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. Enhancement New feature or request labels May 12, 2026
@roomote-v0
Copy link
Copy Markdown
Contributor Author

roomote-v0 Bot commented May 12, 2026

Closing as part of PR restructuring per issue #12330. This work will be combined into a new Phase 2+3 PR with proper stacked branching.

@roomote-v0 roomote-v0 Bot closed this May 12, 2026
@github-project-automation github-project-automation Bot moved this from New to Done in Roo Code Roadmap May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants