Skip to content

fix: restore ctrl-1, ctrl-2... shortcuts for quick agent selection#1816

Merged
dgageot merged 1 commit intodocker:mainfrom
dgageot:agent-selection
Feb 23, 2026
Merged

fix: restore ctrl-1, ctrl-2... shortcuts for quick agent selection#1816
dgageot merged 1 commit intodocker:mainfrom
dgageot:agent-selection

Conversation

@dgageot
Copy link
Member

@dgageot dgageot commented Feb 21, 2026

These shortcuts were accidentally dropped during the parallel session support refactoring in commit 0069cad.

This re-adds the parseCtrlNumberKey utility and intercepts ctrl+1 through ctrl+9 in the global key press handler, delegating to a new handleSwitchToAgentByIndex function.

Assisted-By: cagent

These shortcuts were accidentally dropped during the parallel session support refactoring in commit 0069cad.

This re-adds the `parseCtrlNumberKey` utility and intercepts `ctrl+1` through `ctrl+9` in the global key press handler, delegating to a new `handleSwitchToAgentByIndex` function.

Assisted-By: cagent
@dgageot dgageot requested a review from a team as a code owner February 21, 2026 08:40
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

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

Review Summary

This PR successfully restores the ctrl+1-9 shortcuts for quick agent selection. The implementation is mostly sound, with one notable consideration about the key parsing approach.

Finding: 1 medium-severity issue about using a more robust key detection method.

// parseCtrlNumberKey checks if msg is ctrl+1 through ctrl+9 and returns the index (0-8), or -1 if not matched
func parseCtrlNumberKey(msg tea.KeyPressMsg) int {
s := msg.String()
if len(s) == 6 && s[:5] == "ctrl+" && s[5] >= '1' && s[5] <= '9' {
Copy link

Choose a reason for hiding this comment

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

parseCtrlNumberKey relies on fragile string format matching instead of direct key inspection

The function uses msg.String() with exact length and string prefix matching (len(s) == 6 && s[:5] == "ctrl+"), which is fragile. While Bubble Tea's String() method is generally consistent, a more robust approach would be to inspect the KeyPressMsg fields directly (such as Code, Runes, Alt, Ctrl).

If the string format ever changes across Bubble Tea versions or terminal configurations, ctrl+number shortcuts would be silently ignored. Consider using the structured fields of KeyPressMsg for more reliable key detection.

Severity: Medium - The feature works in practice, but could break silently with library updates.

@dgageot dgageot merged commit 29aff84 into docker:main Feb 23, 2026
8 checks passed
@dgageot dgageot deleted the agent-selection branch February 27, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants