feat: structured context handoff between parent and child tasks (Phase 3c)#12340
feat: structured context handoff between parent and child tasks (Phase 3c)#12340roomote-v0[bot] wants to merge 8 commits into
Conversation
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 Please fix the Code QA Roo Code / check-translations (pull_request) |
Added missing i18n translations for 11 new keys ( |
|
@roomote find the reason and fix the failed unit test Code QA Roo Code / platform-unit-test (ubuntu-latest) |
Fixed the 10 failing unit tests by adding the missing |
|
Thanks for quickly fixing the translation and unit test issues as I requested. Appreciate the fast follow-up. I've reviewed the current state of this Phase 3c PR. Overall the direction of adding structured context handoff looks good and addresses a real pain point (currently the parent only gets a freeform string from the child). A few detailed questions and observations:
Please share your thoughts on the above points and your recommendation on how we should proceed with this PR. |
Thanks for the detailed review questions, @easonLiangWorldedtech. I've gone through the codebase to give informed answers on each point. 1. ContextHandoffSummary field sufficiencyThe current set of fields ( Fields like "important decisions made" or "todos status" are inherently subjective and would need to come from the child's own That said, the schema is designed to be extensible -- adding new fields later is backward-compatible since the Zod schema uses 2. Automatic collection logic robustnessThe collection in For very long conversations, the scan is O(n) over messages and only extracts lightweight metadata (tool names, file paths, command strings), so performance should not be a concern. The main edge case is if
3. UI visibilityCurrently the structured context is shown inside the A short inline summary (e.g., "Modified 3 files, ran 2 commands") directly in the chat flow could be a nice UX improvement. That would be a small follow-up -- adding a one-liner before the detailed breakdown. Happy to add that if reviewers think it's valuable. 4. Backward compatibility / fallback testingYes, the fallback is tested through multiple paths:
The 5. Next stepsThe translation and unit test issues are resolved, types pass, and the 21 new tests all pass. The PR is ready for code review from maintainers. The remaining items that could be addressed in follow-ups (not blocking):
Happy to hear if any of these should be addressed in this PR rather than follow-ups. |
|
Thanks for the very detailed and thoughtful answers. I appreciate you taking the time to go through the codebase and explain the design decisions clearly. Your explanations make sense to me:
I'm comfortable with moving the following items to follow-up PRs instead of blocking this one:
Next step question: Since you mentioned the PR is now ready for code review (translation fixed, all tests passing, types clean), do you recommend we mark this PR as ready for review from the maintainers? Or would you prefer to make any small improvements first before requesting review? Please let me know your recommendation. I'm good with whatever you think is the better flow. |
Marked the PR as ready for review. The draft status has been removed and the PR is now visible to maintainers for review. |
Checked all phase PRs for #12330 and marked them as ready for review. Here's the current status:
All 5 phase PRs are now in a clean state for review with passing CI. |
|
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. |
Related GitHub Issue
Addresses: #12330
Description
This PR attempts to address Issue #12330 Phase 3c: structured context handoff between parent and child tasks. Feedback and guidance are welcome.
Problem solved: When a subtask completes and returns to the parent (Orchestrator), the parent previously only received a freeform text string from
attempt_completion. There was no structured data about what the child actually did -- which files it modified, commands it ran, or tools it used. This made context handoff opaque and forced the Orchestrator to rely entirely on the child self-reporting.What this adds:
ContextHandoffSummarytype (packages/types/src/context-handoff.ts): A Zod-validated schema for structured task execution summaries, capturing:filesModified-- files created or editedfilesRead-- files read (but not modified)commandsExecuted-- shell commands executedtoolUsageCounts-- counts per tool typeapiRequestCount-- total API requests mademode-- mode the subtask ran inresult-- the freeform completion textContext collection utility (
src/core/context-handoff/collectContextSummary.ts): Scans a child task'sclineMessagesto automatically extract structured data. Also providesformatContextSummaryForParent()for human-readable formatting in API messages.Enhanced parent write-back (
src/core/webview/ClineProvider.ts):reopenParentFromDelegation()now:contextHandoffSummaryin the parent's HistoryItem for persistenceUI visibility (
webview-ui/src/components/chat/ChatRow.tsx): Thesubtask_resultdisplay now renders structured context when available, showing files modified, files read, commands executed, and API request count in a collapsible panel.Orchestrator prompt guidance (
packages/types/src/mode.ts): Added instruction Updating Roo-Cline with the latest cline/cline (11/14) #9 explaining how to use structured context from completed subtasks to verify work, pass context forward, and identify conflicts.i18n translations for the new context handoff UI labels.
Backward compatible: If context collection fails for any reason, the system falls back to the previous freeform-only behavior. Old subtask results (plain text) are rendered as before.
Test Procedure
ContextHandoffSummaryschema validation (context-handoff.spec.ts)orchestrator-context-handoff-prompt.spec.ts)collectContextSummary.spec.ts)Files Changed
packages/types/src/context-handoff.tsContextHandoffSummarytype and schemapackages/types/src/index.tspackages/types/src/history.tscontextHandoffSummaryto HistoryItempackages/types/src/mode.tssrc/core/context-handoff/collectContextSummary.tssrc/core/webview/ClineProvider.tsreopenParentFromDelegationwith structured contextwebview-ui/src/components/chat/ChatRow.tsxwebview-ui/src/i18n/locales/en/chat.jsonPre-Submission Checklist
Interactively review PR in Roo Code Cloud