feat(extension): expose tab group control via hub WS protocol#440
Open
ykswang wants to merge 1 commit intoalibaba:mainfrom
Open
feat(extension): expose tab group control via hub WS protocol#440ykswang wants to merge 1 commit intoalibaba:mainfrom
ykswang wants to merge 1 commit intoalibaba:mainfrom
Conversation
The hub creates a new tab group per task (`PageAgent(task)`) but never
cleans it up. Callers that run many tasks in a row end up with a long
list of visually identical groups and no way to tell which one is
running, nor to free them afterwards.
Extend the hub protocol so that callers own the policy:
Outbound:
`result` now carries `tabGroupId?: number`.
Inbound (new):
`{ type: "tab_group", groupId, action }` where action is one of
`close` | `ungroup` | `collapse` | `expand`.
The hub itself still takes no opinion on what to do with groups on
task completion — callers choose whatever fits their flow (close on
success / keep on failure, collapse non-active groups, etc.). Existing
callers that don't read `tabGroupId` or send `tab_group` see zero
behavior change; the new message types are purely additive.
Implementation notes:
- `TabsController` exposes `activeTabGroupId`; `MultiPageAgent` and
`useAgent` forward it up so `useHubWs` can read it without peeking
into the agent internals.
- `applyTabGroupAction` uses `chrome.tabs` / `chrome.tabGroups`
directly from the hub extension page (already permissioned).
- `tab_group` actions are fire-and-forget; failures are logged on the
hub side and do not emit `error`, which stays reserved for
task-scoped errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Every call to the hub's
executecreates a new tab group namedPageAgent(${task})with a random color. The hub never cleans these up on its own, so callers that drive many tasks in a row end up with a long list of visually-identical groups and:Instead of baking a specific cleanup / visibility policy into the extension (auto-collapse? auto-ungroup? keep forever?), this PR exposes the underlying mechanism over the existing hub WS protocol and lets callers decide policy.
Protocol additions
Outbound:
resultcarriestabGroupIdtabGroupIdis the id of the tab group created for the task that just finished, orundefinedif no group was created (e.g.includeInitialTab: falsewith no new tabs opened).Inbound: new
tab_groupactionclose— close every tab in the group (the empty group disappears)ungroup— detach tabs from the group, keep them opencollapse/expand— change visual collapsed stateFire-and-forget: the hub applies the action best-effort and does not reply. Failures are logged on the hub side only;
errorstays reserved for task-scoped errors.Compatibility
Purely additive. Callers that don't read
tabGroupIdor sendtab_groupsee zero behavior change. The reference callerpackages/mcp/src/hub-bridge.jsignores unknown message types and doesn't break.Example (caller policy)
Implementation notes
TabsControllerexposesactiveTabGroupId;MultiPageAgentanduseAgentforward it up souseHubWscan read it without peeking into agent internals.applyTabGroupActionuseschrome.tabs/chrome.tabGroupsdirectly from the hub extension page —tabGroupspermission already exists inwxt.config.js.tabGroupIdonTabsControllerstays private; a read-only getteractiveTabGroupIdis added so no internal code paths change.Test plan
npm run typecheckpassesnpx eslintclean on all touched filesresult.tabGroupIdis presentclose/ungroup/collapse/expandand verify the corresponding Chrome behaviorresult/error) still works unchanged